Commit 0c3e3062 authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

Styling for new answer layout, part 2.

This provides styling for mathematical equations.

Bug: 920396
Change-Id: I7c11f2a55da20d69d4697094072f9596be8d6298
Reviewed-on: https://chromium-review.googlesource.com/c/1422298Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Ender <ender@google.com>
Auto-Submit: Ender <ender@google.com>
Cr-Commit-Position: refs/heads/master@{#625444}
parent 780f6874
......@@ -72,6 +72,11 @@ public class AutocompleteCoordinator implements UrlFocusChangeListener, UrlTextC
*/
void onUrlFocusChange(boolean hasFocus);
/**
* Signals that native initialization has completed.
*/
void onNativeInitialized();
/**
* Create a model for a suggestion at the specified position.
* @param suggestion The suggestion to create the model for.
......@@ -185,6 +190,8 @@ public class AutocompleteCoordinator implements UrlFocusChangeListener, UrlTextC
list.setClipToPadding(false);
// Register a view type for a default omnibox suggestion.
// Note: clang-format does a bad job formatting lambdas so we turn it off here.
// clang-format off
adapter.registerType(
OmniboxSuggestionUiType.DEFAULT,
() -> new SuggestionView(mListView.getContext()),
......@@ -194,6 +201,7 @@ public class AutocompleteCoordinator implements UrlFocusChangeListener, UrlTextC
OmniboxSuggestionUiType.EDIT_URL_SUGGESTION,
() -> EditUrlSuggestionProcessor.createView(mListView.getContext()),
EditUrlSuggestionViewBinder::bind);
// clang-format on
mHolder = new SuggestionListViewHolder(container, list, adapter);
......
......@@ -266,6 +266,8 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, SuggestionH
}
mDeferredNativeRunnables.clear();
mAnswerSuggestionProcessor.onNativeInitialized();
mBasicSuggestionProcessor.onNativeInitialized();
if (mEditUrlProcessor != null) mEditUrlProcessor.onNativeInitialized();
}
/**
......
......@@ -52,9 +52,7 @@ public class AnswerSuggestionProcessor implements SuggestionProcessor {
return suggestion.hasAnswer();
}
/**
* Signals that native initialization has completed.
*/
@Override
public void onNativeInitialized() {
// Experiment: controls presence of certain answer icon types.
mEnableNewAnswerLayout =
......
......@@ -13,6 +13,9 @@ import android.util.Pair;
import android.util.TypedValue;
import android.view.View;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.omnibox.MatchClassificationStyle;
import org.chromium.chrome.browser.omnibox.OmniboxSuggestionType;
import org.chromium.chrome.browser.omnibox.UrlBarEditingTextStateProvider;
......@@ -32,6 +35,7 @@ public class BasicSuggestionProcessor implements SuggestionProcessor {
private final Context mContext;
private final SuggestionHost mSuggestionHost;
private final UrlBarEditingTextStateProvider mUrlBarEditingTextProvider;
private boolean mEnableNewAnswerLayout;
/**
* @param context An Android context.
......@@ -73,6 +77,16 @@ public class BasicSuggestionProcessor implements SuggestionProcessor {
@Override
public void onUrlFocusChange(boolean hasFocus) {}
/**
* Signals that native initialization has completed.
*/
@Override
public void onNativeInitialized() {
// Experiment: controls presence of certain answer icon types.
mEnableNewAnswerLayout =
ChromeFeatureList.isEnabled(ChromeFeatureList.OMNIBOX_NEW_ANSWER_LAYOUT);
}
private void setStateForSuggestion(PropertyModel model, OmniboxSuggestion suggestion) {
int suggestionType = suggestion.getType();
@SuggestionIcon
......@@ -95,8 +109,10 @@ public class BasicSuggestionProcessor implements SuggestionProcessor {
urlHighlighted = applyHighlightToMatchRegions(
str, suggestion.getDisplayTextClassifications());
textLine2 = str;
textLine2Color = SuggestionViewViewBinder.getStandardUrlColor(
mContext, model.get(SuggestionCommonProperties.USE_DARK_COLORS));
textLine2Color = ApiCompatibilityUtils.getColor(mContext.getResources(),
model.get(SuggestionCommonProperties.USE_DARK_COLORS)
? R.color.suggestion_url_dark_modern
: R.color.suggestion_url_light_modern);
textLine2Direction = View.TEXT_DIRECTION_LTR;
} else {
textLine2 = null;
......@@ -118,6 +134,15 @@ public class BasicSuggestionProcessor implements SuggestionProcessor {
textLine2Color = SuggestionViewViewBinder.getStandardFontColor(
mContext, model.get(SuggestionCommonProperties.USE_DARK_COLORS));
textLine2Direction = View.TEXT_DIRECTION_INHERIT;
} else if (mEnableNewAnswerLayout
&& suggestionType == OmniboxSuggestionType.CALCULATOR) {
suggestionIcon = SuggestionIcon.CALCULATOR;
textLine2 = SpannableString.valueOf(
mUrlBarEditingTextProvider.getTextWithAutocomplete());
textLine2Color = ApiCompatibilityUtils.getColor(
mContext.getResources(), R.color.answers_answer_text);
textLine2Direction = View.TEXT_DIRECTION_INHERIT;
} else {
textLine2 = null;
}
......@@ -204,6 +229,16 @@ public class BasicSuggestionProcessor implements SuggestionProcessor {
new OmniboxSuggestion.MatchClassification(
0, MatchClassificationStyle.NONE));
}
} else if (mEnableNewAnswerLayout
&& suggestion.getType() == OmniboxSuggestionType.CALCULATOR) {
// Trim preceding equal sign since we're going to present an icon instead.
// This is probably best placed in search_suggestion_parser.cc file, but at this point
// this would affect other devices that still want to present the sign (eg. iOS) so
// until these devices adopt the new entities we need to manage this here.
if (suggestedQuery.subSequence(0, 2).equals("= ")) {
suggestedQuery = suggestedQuery.substring(2);
}
shouldHighlight = false;
}
Spannable str = SpannableString.valueOf(suggestedQuery);
......
......@@ -207,18 +207,4 @@ public class SuggestionViewViewBinder {
: R.color.url_emphasis_light_default_text;
return ApiCompatibilityUtils.getColor(context.getResources(), res);
}
/**
* Get the appropriate font color to be used for URL text in suggestions.
* @param context The context to load the color.
* @param useDarkColors Whether dark colors should be used.
* @return The font color to be used.
*/
@ColorInt
public static int getStandardUrlColor(Context context, boolean useDarkColors) {
@ColorRes
int res = useDarkColors ? R.color.suggestion_url_dark_modern
: R.color.suggestion_url_light_modern;
return ApiCompatibilityUtils.getColor(context.getResources(), res);
}
}
......@@ -172,6 +172,9 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
model.set(EditUrlSuggestionProperties.URL_TEXT, mLastProcessedSuggestion.getUrl());
}
@Override
public void onNativeInitialized() {}
/**
* @param provider A means of accessing the activity's tab.
*/
......
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