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 ...@@ -72,6 +72,11 @@ public class AutocompleteCoordinator implements UrlFocusChangeListener, UrlTextC
*/ */
void onUrlFocusChange(boolean hasFocus); void onUrlFocusChange(boolean hasFocus);
/**
* Signals that native initialization has completed.
*/
void onNativeInitialized();
/** /**
* Create a model for a suggestion at the specified position. * Create a model for a suggestion at the specified position.
* @param suggestion The suggestion to create the model for. * @param suggestion The suggestion to create the model for.
...@@ -185,6 +190,8 @@ public class AutocompleteCoordinator implements UrlFocusChangeListener, UrlTextC ...@@ -185,6 +190,8 @@ public class AutocompleteCoordinator implements UrlFocusChangeListener, UrlTextC
list.setClipToPadding(false); list.setClipToPadding(false);
// Register a view type for a default omnibox suggestion. // 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( adapter.registerType(
OmniboxSuggestionUiType.DEFAULT, OmniboxSuggestionUiType.DEFAULT,
() -> new SuggestionView(mListView.getContext()), () -> new SuggestionView(mListView.getContext()),
...@@ -194,6 +201,7 @@ public class AutocompleteCoordinator implements UrlFocusChangeListener, UrlTextC ...@@ -194,6 +201,7 @@ public class AutocompleteCoordinator implements UrlFocusChangeListener, UrlTextC
OmniboxSuggestionUiType.EDIT_URL_SUGGESTION, OmniboxSuggestionUiType.EDIT_URL_SUGGESTION,
() -> EditUrlSuggestionProcessor.createView(mListView.getContext()), () -> EditUrlSuggestionProcessor.createView(mListView.getContext()),
EditUrlSuggestionViewBinder::bind); EditUrlSuggestionViewBinder::bind);
// clang-format on
mHolder = new SuggestionListViewHolder(container, list, adapter); mHolder = new SuggestionListViewHolder(container, list, adapter);
......
...@@ -266,6 +266,8 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, SuggestionH ...@@ -266,6 +266,8 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, SuggestionH
} }
mDeferredNativeRunnables.clear(); mDeferredNativeRunnables.clear();
mAnswerSuggestionProcessor.onNativeInitialized(); mAnswerSuggestionProcessor.onNativeInitialized();
mBasicSuggestionProcessor.onNativeInitialized();
if (mEditUrlProcessor != null) mEditUrlProcessor.onNativeInitialized();
} }
/** /**
......
...@@ -52,9 +52,7 @@ public class AnswerSuggestionProcessor implements SuggestionProcessor { ...@@ -52,9 +52,7 @@ public class AnswerSuggestionProcessor implements SuggestionProcessor {
return suggestion.hasAnswer(); return suggestion.hasAnswer();
} }
/** @Override
* Signals that native initialization has completed.
*/
public void onNativeInitialized() { public void onNativeInitialized() {
// Experiment: controls presence of certain answer icon types. // Experiment: controls presence of certain answer icon types.
mEnableNewAnswerLayout = mEnableNewAnswerLayout =
......
...@@ -13,6 +13,9 @@ import android.util.Pair; ...@@ -13,6 +13,9 @@ import android.util.Pair;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; 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.MatchClassificationStyle;
import org.chromium.chrome.browser.omnibox.OmniboxSuggestionType; import org.chromium.chrome.browser.omnibox.OmniboxSuggestionType;
import org.chromium.chrome.browser.omnibox.UrlBarEditingTextStateProvider; import org.chromium.chrome.browser.omnibox.UrlBarEditingTextStateProvider;
...@@ -32,6 +35,7 @@ public class BasicSuggestionProcessor implements SuggestionProcessor { ...@@ -32,6 +35,7 @@ public class BasicSuggestionProcessor implements SuggestionProcessor {
private final Context mContext; private final Context mContext;
private final SuggestionHost mSuggestionHost; private final SuggestionHost mSuggestionHost;
private final UrlBarEditingTextStateProvider mUrlBarEditingTextProvider; private final UrlBarEditingTextStateProvider mUrlBarEditingTextProvider;
private boolean mEnableNewAnswerLayout;
/** /**
* @param context An Android context. * @param context An Android context.
...@@ -73,6 +77,16 @@ public class BasicSuggestionProcessor implements SuggestionProcessor { ...@@ -73,6 +77,16 @@ public class BasicSuggestionProcessor implements SuggestionProcessor {
@Override @Override
public void onUrlFocusChange(boolean hasFocus) {} 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) { private void setStateForSuggestion(PropertyModel model, OmniboxSuggestion suggestion) {
int suggestionType = suggestion.getType(); int suggestionType = suggestion.getType();
@SuggestionIcon @SuggestionIcon
...@@ -95,8 +109,10 @@ public class BasicSuggestionProcessor implements SuggestionProcessor { ...@@ -95,8 +109,10 @@ public class BasicSuggestionProcessor implements SuggestionProcessor {
urlHighlighted = applyHighlightToMatchRegions( urlHighlighted = applyHighlightToMatchRegions(
str, suggestion.getDisplayTextClassifications()); str, suggestion.getDisplayTextClassifications());
textLine2 = str; textLine2 = str;
textLine2Color = SuggestionViewViewBinder.getStandardUrlColor( textLine2Color = ApiCompatibilityUtils.getColor(mContext.getResources(),
mContext, model.get(SuggestionCommonProperties.USE_DARK_COLORS)); model.get(SuggestionCommonProperties.USE_DARK_COLORS)
? R.color.suggestion_url_dark_modern
: R.color.suggestion_url_light_modern);
textLine2Direction = View.TEXT_DIRECTION_LTR; textLine2Direction = View.TEXT_DIRECTION_LTR;
} else { } else {
textLine2 = null; textLine2 = null;
...@@ -118,6 +134,15 @@ public class BasicSuggestionProcessor implements SuggestionProcessor { ...@@ -118,6 +134,15 @@ public class BasicSuggestionProcessor implements SuggestionProcessor {
textLine2Color = SuggestionViewViewBinder.getStandardFontColor( textLine2Color = SuggestionViewViewBinder.getStandardFontColor(
mContext, model.get(SuggestionCommonProperties.USE_DARK_COLORS)); mContext, model.get(SuggestionCommonProperties.USE_DARK_COLORS));
textLine2Direction = View.TEXT_DIRECTION_INHERIT; 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 { } else {
textLine2 = null; textLine2 = null;
} }
...@@ -204,6 +229,16 @@ public class BasicSuggestionProcessor implements SuggestionProcessor { ...@@ -204,6 +229,16 @@ public class BasicSuggestionProcessor implements SuggestionProcessor {
new OmniboxSuggestion.MatchClassification( new OmniboxSuggestion.MatchClassification(
0, MatchClassificationStyle.NONE)); 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); Spannable str = SpannableString.valueOf(suggestedQuery);
......
...@@ -207,18 +207,4 @@ public class SuggestionViewViewBinder { ...@@ -207,18 +207,4 @@ public class SuggestionViewViewBinder {
: R.color.url_emphasis_light_default_text; : R.color.url_emphasis_light_default_text;
return ApiCompatibilityUtils.getColor(context.getResources(), res); 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 ...@@ -172,6 +172,9 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
model.set(EditUrlSuggestionProperties.URL_TEXT, mLastProcessedSuggestion.getUrl()); model.set(EditUrlSuggestionProperties.URL_TEXT, mLastProcessedSuggestion.getUrl());
} }
@Override
public void onNativeInitialized() {}
/** /**
* @param provider A means of accessing the activity's tab. * @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