Commit f22258d2 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Commit Bot

[Autofill Assistant] Highlight chips if necessary.

Bug: 806868
Change-Id: I3948803d43dfd91ccec1e6fe0fa57b4d197de1e6
Reviewed-on: https://chromium-review.googlesource.com/c/1286148
Commit-Queue: Jordan Demeulenaere <jdemeulenaere@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600710}
parent 3fab20f2
......@@ -168,12 +168,17 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
}
@CalledByNative
private void onUpdateScripts(String[] scriptNames, String[] scriptPaths) {
private void onUpdateScripts(
String[] scriptNames, String[] scriptPaths, boolean[] scriptsHighlightFlags) {
assert scriptNames.length == scriptPaths.length;
assert scriptNames.length == scriptsHighlightFlags.length;
ArrayList<AutofillAssistantUiDelegate.ScriptHandle> scriptHandles = new ArrayList<>();
// Note that scriptNames and scriptPaths are one-on-one matched by index.
// Note that scriptNames, scriptPaths and scriptsHighlightFlags are one-on-one matched by
// index.
for (int i = 0; i < scriptNames.length; i++) {
scriptHandles.add(
new AutofillAssistantUiDelegate.ScriptHandle(scriptNames[i], scriptPaths[i]));
scriptHandles.add(new AutofillAssistantUiDelegate.ScriptHandle(
scriptNames[i], scriptPaths[i], scriptsHighlightFlags[i]));
}
mUiDelegate.updateScripts(scriptHandles);
}
......
......@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.autofill_assistant;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.media.ThumbnailUtils;
import android.os.AsyncTask;
import android.support.annotation.Nullable;
......@@ -112,11 +113,14 @@ class AutofillAssistantUiDelegate {
private final String mName;
/** The script path. */
private final String mPath;
/** Whether the script should be highlighted. */
private final boolean mHighlight;
/** Constructor. */
public ScriptHandle(String name, String path) {
public ScriptHandle(String name, String path, boolean highlight) {
mName = name;
mPath = path;
mHighlight = highlight;
}
/** Returns the display name. */
......@@ -128,6 +132,11 @@ class AutofillAssistantUiDelegate {
public String getPath() {
return mPath;
}
/** Returns whether the script should be highlighted. */
public boolean isHighlight() {
return mHighlight;
}
}
/**
......@@ -240,6 +249,17 @@ class AutofillAssistantUiDelegate {
clearChipsViewContainer();
mClient.onScriptSelected(scriptHandle.getPath());
});
if (scriptHandle.isHighlight()) {
int highlightColor = mActivity.getResources().getColor(
org.chromium.chrome.R.color.modern_blue_600);
int strokeWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1,
mActivity.getResources().getDisplayMetrics());
((GradientDrawable) chipView.getBackground().getCurrent())
.setStroke(strokeWidth, highlightColor);
chipView.setTextColor(highlightColor);
}
addChipViewToContainer(chipView);
}
......
......@@ -103,15 +103,21 @@ void UiControllerAndroid::UpdateScripts(
const std::vector<ScriptHandle>& scripts) {
std::vector<std::string> script_paths;
std::vector<std::string> script_names;
for (const auto& script : scripts) {
bool* script_highlights = new bool[scripts.size()];
for (size_t i = 0; i < scripts.size(); ++i) {
const auto& script = scripts[i];
script_paths.emplace_back(script.path);
script_names.emplace_back(script.name);
script_highlights[i] = script.highlight;
}
JNIEnv* env = AttachCurrentThread();
Java_AutofillAssistantUiController_onUpdateScripts(
env, java_autofill_assistant_ui_controller_,
base::android::ToJavaArrayOfStrings(env, script_names),
base::android::ToJavaArrayOfStrings(env, script_paths));
base::android::ToJavaArrayOfStrings(env, script_paths),
base::android::ToJavaBooleanArray(env, script_highlights,
scripts.size()));
delete[] script_highlights;
}
void UiControllerAndroid::OnScriptSelected(
......
......@@ -84,6 +84,7 @@ bool ProtocolUtils::ParseScripts(
script->handle.name = presentation.name();
script->handle.autostart = presentation.autostart();
script->handle.initial_prompt = presentation.initial_prompt();
script->handle.highlight = presentation.highlight();
script->precondition = ScriptPrecondition::FromProto(
script_proto.path(), presentation.precondition());
script->priority = presentation.priority();
......
......@@ -25,6 +25,7 @@ struct ScriptHandle {
// When set to true this script can be run in 'autostart mode'. Script won't
// be shown.
bool autostart;
bool highlight;
};
// Script represents a sequence of actions.
......
......@@ -58,6 +58,9 @@ message SupportedScriptProto {
// priority 1.
optional int32 priority = 5;
// Whether the script should be highlighted.
optional bool highlight = 7;
// When set to true this script can be run in 'autostart mode'. Script won't
// be shown.
optional bool autostart = 8;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment