| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.omnibox; | 5 package org.chromium.chrome.browser.omnibox; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
| 10 import android.content.res.TypedArray; | 10 import android.content.res.TypedArray; |
| 11 import android.graphics.Bitmap; | 11 import android.graphics.Bitmap; |
| 12 import android.graphics.Canvas; | 12 import android.graphics.Canvas; |
| 13 import android.graphics.Color; | 13 import android.graphics.Color; |
| 14 import android.graphics.PorterDuff; | 14 import android.graphics.PorterDuff; |
| 15 import android.graphics.drawable.Drawable; | 15 import android.graphics.drawable.Drawable; |
| 16 import android.support.annotation.IntDef; |
| 16 import android.support.v4.view.ViewCompat; | 17 import android.support.v4.view.ViewCompat; |
| 17 import android.support.v7.app.AlertDialog; | 18 import android.support.v7.app.AlertDialog; |
| 18 import android.text.Spannable; | 19 import android.text.Spannable; |
| 19 import android.text.SpannableString; | 20 import android.text.SpannableString; |
| 20 import android.text.TextPaint; | 21 import android.text.TextPaint; |
| 21 import android.text.TextUtils; | 22 import android.text.TextUtils; |
| 22 import android.text.style.StyleSpan; | 23 import android.text.style.StyleSpan; |
| 23 import android.util.TypedValue; | 24 import android.util.TypedValue; |
| 24 import android.view.MotionEvent; | 25 import android.view.MotionEvent; |
| 25 import android.view.View; | 26 import android.view.View; |
| 26 import android.view.ViewGroup; | 27 import android.view.ViewGroup; |
| 27 import android.widget.ImageView; | 28 import android.widget.ImageView; |
| 28 import android.widget.TextView; | 29 import android.widget.TextView; |
| 29 import android.widget.TextView.BufferType; | 30 import android.widget.TextView.BufferType; |
| 30 | 31 |
| 31 import org.chromium.base.ApiCompatibilityUtils; | 32 import org.chromium.base.ApiCompatibilityUtils; |
| 32 import org.chromium.base.metrics.RecordUserAction; | 33 import org.chromium.base.metrics.RecordUserAction; |
| 33 import org.chromium.chrome.R; | 34 import org.chromium.chrome.R; |
| 34 import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxResultIt
em; | 35 import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxResultIt
em; |
| 35 import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxSuggesti
onDelegate; | 36 import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxSuggesti
onDelegate; |
| 36 import org.chromium.chrome.browser.omnibox.OmniboxSuggestion.MatchClassification
; | 37 import org.chromium.chrome.browser.omnibox.OmniboxSuggestion.MatchClassification
; |
| 37 import org.chromium.chrome.browser.widget.TintedDrawable; | 38 import org.chromium.chrome.browser.widget.TintedDrawable; |
| 38 import org.chromium.ui.base.DeviceFormFactor; | 39 import org.chromium.ui.base.DeviceFormFactor; |
| 39 | 40 |
| 41 import java.lang.annotation.Retention; |
| 42 import java.lang.annotation.RetentionPolicy; |
| 40 import java.util.ArrayList; | 43 import java.util.ArrayList; |
| 41 import java.util.List; | 44 import java.util.List; |
| 42 | 45 |
| 43 /** | 46 /** |
| 44 * Container view for omnibox suggestions made very specific for omnibox suggest
ions to minimize | 47 * Container view for omnibox suggestions made very specific for omnibox suggest
ions to minimize |
| 45 * any unnecessary measures and layouts. | 48 * any unnecessary measures and layouts. |
| 46 */ | 49 */ |
| 47 class SuggestionView extends ViewGroup { | 50 class SuggestionView extends ViewGroup { |
| 51 @Retention(RetentionPolicy.SOURCE) |
| 52 @IntDef({ |
| 53 SUGGESTION_ICON_UNDEFINED, |
| 54 SUGGESTION_ICON_BOOKMARK, |
| 55 SUGGESTION_ICON_HISTORY, |
| 56 SUGGESTION_ICON_GLOBE, |
| 57 SUGGESTION_ICON_MAGNIFIER, |
| 58 SUGGESTION_ICON_VOICE |
| 59 }) |
| 60 private @interface SuggestionIcon {} |
| 61 |
| 48 private static final int SUGGESTION_ICON_UNDEFINED = -1; | 62 private static final int SUGGESTION_ICON_UNDEFINED = -1; |
| 49 private static final int SUGGESTION_ICON_BOOKMARK = 0; | 63 private static final int SUGGESTION_ICON_BOOKMARK = 0; |
| 50 private static final int SUGGESTION_ICON_HISTORY = 1; | 64 private static final int SUGGESTION_ICON_HISTORY = 1; |
| 51 private static final int SUGGESTION_ICON_GLOBE = 2; | 65 private static final int SUGGESTION_ICON_GLOBE = 2; |
| 52 private static final int SUGGESTION_ICON_MAGNIFIER = 3; | 66 private static final int SUGGESTION_ICON_MAGNIFIER = 3; |
| 53 private static final int SUGGESTION_ICON_VOICE = 4; | 67 private static final int SUGGESTION_ICON_VOICE = 4; |
| 54 | 68 |
| 55 private static final int FIRST_LINE_TEXT_SIZE_SP = 17; | |
| 56 private static final int SECOND_LINE_TEXT_SIZE_SP = 14; | |
| 57 | |
| 58 private static final long RELAYOUT_DELAY_MS = 20; | 69 private static final long RELAYOUT_DELAY_MS = 20; |
| 59 | 70 |
| 60 static final int TITLE_COLOR_STANDARD_FONT_DARK = 0xFF333333; | 71 static final int TITLE_COLOR_STANDARD_FONT_DARK = 0xFF333333; |
| 61 private static final int TITLE_COLOR_STANDARD_FONT_LIGHT = 0xFFFFFFFF; | 72 private static final int TITLE_COLOR_STANDARD_FONT_LIGHT = 0xFFFFFFFF; |
| 62 private static final int URL_COLOR = 0xFF5595FE; | 73 private static final int URL_COLOR = 0xFF5595FE; |
| 63 | 74 |
| 64 private static final int ANSWER_LINE2_VERTICAL_SPACING_DP = 3; | |
| 65 private static final int ANSWER_IMAGE_VERTICAL_SPACING_DP = | |
| 66 ANSWER_LINE2_VERTICAL_SPACING_DP + 2; | |
| 67 private static final int ANSWER_IMAGE_HORIZONTAL_SPACING_DP = 4; | |
| 68 private static final float ANSWER_IMAGE_SCALING_FACTOR = 1.15f; | 75 private static final float ANSWER_IMAGE_SCALING_FACTOR = 1.15f; |
| 69 | 76 |
| 70 private LocationBar mLocationBar; | 77 private final LocationBar mLocationBar; |
| 71 private UrlBar mUrlBar; | 78 private UrlBar mUrlBar; |
| 72 private ImageView mNavigationButton; | 79 private ImageView mNavigationButton; |
| 73 | 80 |
| 74 private int mSuggestionHeight; | 81 private final int mSuggestionHeight; |
| 75 private int mSuggestionAnswerHeight; | 82 private final int mSuggestionAnswerHeight; |
| 76 | 83 |
| 77 private OmniboxResultItem mSuggestionItem; | 84 private OmniboxResultItem mSuggestionItem; |
| 78 private OmniboxSuggestion mSuggestion; | 85 private OmniboxSuggestion mSuggestion; |
| 79 private OmniboxSuggestionDelegate mSuggestionDelegate; | 86 private OmniboxSuggestionDelegate mSuggestionDelegate; |
| 80 private Boolean mUseDarkColors; | 87 private Boolean mUseDarkColors; |
| 81 private int mPosition; | 88 private int mPosition; |
| 82 | 89 |
| 83 private SuggestionContentsContainer mContentsView; | 90 private final SuggestionContentsContainer mContentsView; |
| 84 | 91 |
| 85 private int mRefineWidth; | 92 private final int mRefineWidth; |
| 86 private View mRefineView; | 93 private final View mRefineView; |
| 87 private TintedDrawable mRefineIcon; | 94 private TintedDrawable mRefineIcon; |
| 88 | 95 |
| 89 private final int[] mViewPositionHolder = new int[2]; | 96 private final int[] mViewPositionHolder = new int[2]; |
| 90 | 97 |
| 91 // The offset for the phone's suggestions left-alignment. | |
| 92 private static final int PHONE_URL_BAR_LEFT_OFFSET_DP = 10; | |
| 93 private static final int PHONE_URL_BAR_LEFT_OFFSET_RTL_DP = 46; | |
| 94 // Pre-computed offsets in px. | 98 // Pre-computed offsets in px. |
| 95 private final int mPhoneUrlBarLeftOffsetPx; | 99 private final int mPhoneUrlBarLeftOffsetPx; |
| 96 private final int mPhoneUrlBarLeftOffsetRtlPx; | 100 private final int mPhoneUrlBarLeftOffsetRtlPx; |
| 97 | 101 |
| 98 /** | 102 /** |
| 99 * Constructs a new omnibox suggestion view. | 103 * Constructs a new omnibox suggestion view. |
| 100 * | 104 * |
| 101 * @param context The context used to construct the suggestion view. | 105 * @param context The context used to construct the suggestion view. |
| 102 * @param locationBar The location bar showing these suggestions. | 106 * @param locationBar The location bar showing these suggestions. |
| 103 */ | 107 */ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // Although this has the same background as the suggestion view, it can
not be shared as | 165 // Although this has the same background as the suggestion view, it can
not be shared as |
| 162 // it will result in the state of the drawable being shared and always s
howing up in the | 166 // it will result in the state of the drawable being shared and always s
howing up in the |
| 163 // refine view. | 167 // refine view. |
| 164 mRefineView.setBackground(itemBackground.getConstantState().newDrawable(
)); | 168 mRefineView.setBackground(itemBackground.getConstantState().newDrawable(
)); |
| 165 mRefineView.setId(R.id.refine_view_id); | 169 mRefineView.setId(R.id.refine_view_id); |
| 166 mRefineView.setClickable(true); | 170 mRefineView.setClickable(true); |
| 167 mRefineView.setFocusable(true); | 171 mRefineView.setFocusable(true); |
| 168 mRefineView.setLayoutParams(new LayoutParams(0, 0)); | 172 mRefineView.setLayoutParams(new LayoutParams(0, 0)); |
| 169 addView(mRefineView); | 173 addView(mRefineView); |
| 170 | 174 |
| 171 mRefineWidth = (int) (getResources().getDisplayMetrics().density * 48); | 175 mRefineWidth = getResources() |
| 176 .getDimensionPixelSize(R.dimen.omnibox_suggestion_refine_width); |
| 172 | 177 |
| 173 mUrlBar = (UrlBar) locationBar.getContainerView().findViewById(R.id.url_
bar); | 178 mUrlBar = (UrlBar) locationBar.getContainerView().findViewById(R.id.url_
bar); |
| 174 | 179 |
| 175 mPhoneUrlBarLeftOffsetPx = Math.round(TypedValue.applyDimension(TypedVal
ue.COMPLEX_UNIT_DIP, | 180 mPhoneUrlBarLeftOffsetPx = getResources().getDimensionPixelOffset( |
| 176 PHONE_URL_BAR_LEFT_OFFSET_DP, | 181 R.dimen.omnibox_suggestion_phone_url_bar_left_offset); |
| 177 getContext().getResources().getDisplayMetrics())); | 182 mPhoneUrlBarLeftOffsetRtlPx = getResources().getDimensionPixelOffset( |
| 178 mPhoneUrlBarLeftOffsetRtlPx = Math.round(TypedValue.applyDimension( | 183 R.dimen.omnibox_suggestion_phone_url_bar_left_offset_rtl); |
| 179 TypedValue.COMPLEX_UNIT_DIP, | |
| 180 PHONE_URL_BAR_LEFT_OFFSET_RTL_DP, | |
| 181 getContext().getResources().getDisplayMetrics())); | |
| 182 } | 184 } |
| 183 | 185 |
| 184 @Override | 186 @Override |
| 185 protected void onLayout(boolean changed, int left, int top, int right, int b
ottom) { | 187 protected void onLayout(boolean changed, int left, int top, int right, int b
ottom) { |
| 186 if (getMeasuredWidth() == 0) return; | 188 if (getMeasuredWidth() == 0) return; |
| 187 | 189 |
| 188 if (mSuggestion.getType() != OmniboxSuggestionType.SEARCH_SUGGEST_TAIL)
{ | 190 if (mSuggestion.getType() != OmniboxSuggestionType.SEARCH_SUGGEST_TAIL)
{ |
| 189 mContentsView.resetTextWidths(); | 191 mContentsView.resetTextWidths(); |
| 190 } | 192 } |
| 191 | 193 |
| 192 boolean refineVisible = mRefineView.getVisibility() == VISIBLE; | 194 boolean refineVisible = mRefineView.getVisibility() == VISIBLE; |
| 193 boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this); | 195 boolean isRtl = ApiCompatibilityUtils.isLayoutRtl(this); |
| 194 int contentsViewOffsetX = isRtl ? mRefineWidth : 0; | 196 int contentsViewOffsetX = isRtl && refineVisible ? mRefineWidth : 0; |
| 195 if (!refineVisible) contentsViewOffsetX = 0; | |
| 196 mContentsView.layout( | 197 mContentsView.layout( |
| 197 contentsViewOffsetX, | 198 contentsViewOffsetX, |
| 198 0, | 199 0, |
| 199 contentsViewOffsetX + mContentsView.getMeasuredWidth(), | 200 contentsViewOffsetX + mContentsView.getMeasuredWidth(), |
| 200 mContentsView.getMeasuredHeight()); | 201 mContentsView.getMeasuredHeight()); |
| 201 int refineViewOffsetX = isRtl ? 0 : getMeasuredWidth() - mRefineWidth; | 202 int refineViewOffsetX = isRtl ? 0 : getMeasuredWidth() - mRefineWidth; |
| 202 mRefineView.layout( | 203 mRefineView.layout( |
| 203 refineViewOffsetX, | 204 refineViewOffsetX, |
| 204 0, | 205 0, |
| 205 refineViewOffsetX + mRefineWidth, | 206 refineViewOffsetX + mRefineWidth, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 mSuggestionItem = suggestionItem; | 276 mSuggestionItem = suggestionItem; |
| 276 mSuggestion = suggestionItem.getSuggestion(); | 277 mSuggestion = suggestionItem.getSuggestion(); |
| 277 mSuggestionDelegate = suggestionDelegate; | 278 mSuggestionDelegate = suggestionDelegate; |
| 278 // Reset old computations. | 279 // Reset old computations. |
| 279 mContentsView.resetTextWidths(); | 280 mContentsView.resetTextWidths(); |
| 280 mContentsView.mAnswerImage.setVisibility(GONE); | 281 mContentsView.mAnswerImage.setVisibility(GONE); |
| 281 mContentsView.mAnswerImage.getLayoutParams().height = 0; | 282 mContentsView.mAnswerImage.getLayoutParams().height = 0; |
| 282 mContentsView.mAnswerImage.getLayoutParams().width = 0; | 283 mContentsView.mAnswerImage.getLayoutParams().width = 0; |
| 283 mContentsView.mAnswerImage.setImageDrawable(null); | 284 mContentsView.mAnswerImage.setImageDrawable(null); |
| 284 mContentsView.mAnswerImageMaxSize = 0; | 285 mContentsView.mAnswerImageMaxSize = 0; |
| 285 mContentsView.mTextLine1.setTextSize(FIRST_LINE_TEXT_SIZE_SP); | 286 mContentsView.mTextLine1.setTextSize(TypedValue.COMPLEX_UNIT_PX, getReso
urces() |
| 286 mContentsView.mTextLine2.setTextSize(SECOND_LINE_TEXT_SIZE_SP); | 287 .getDimension(R.dimen.omnibox_suggestion_first_line_text_size)); |
| 288 mContentsView.mTextLine2.setTextSize(TypedValue.COMPLEX_UNIT_PX, getReso
urces() |
| 289 .getDimension(R.dimen.omnibox_suggestion_second_line_text_size))
; |
| 287 | 290 |
| 288 // Suggestions with attached answers are rendered with rich results rega
rdless of which | 291 // Suggestions with attached answers are rendered with rich results rega
rdless of which |
| 289 // suggestion type they are. | 292 // suggestion type they are. |
| 290 if (mSuggestion.hasAnswer()) { | 293 if (mSuggestion.hasAnswer()) { |
| 291 setAnswer(mSuggestion.getAnswer()); | 294 setAnswer(mSuggestion.getAnswer()); |
| 292 mContentsView.setSuggestionIcon(SUGGESTION_ICON_MAGNIFIER, colorsCha
nged); | 295 mContentsView.setSuggestionIcon(SUGGESTION_ICON_MAGNIFIER, colorsCha
nged); |
| 293 mContentsView.mTextLine2.setVisibility(VISIBLE); | 296 mContentsView.mTextLine2.setVisibility(VISIBLE); |
| 294 setRefinable(true); | 297 setRefinable(true); |
| 295 return; | 298 return; |
| 296 } | 299 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 309 boolean urlShown = !TextUtils.isEmpty(mSuggestion.getUrl()); | 312 boolean urlShown = !TextUtils.isEmpty(mSuggestion.getUrl()); |
| 310 boolean urlHighlighted = false; | 313 boolean urlHighlighted = false; |
| 311 if (urlShown) { | 314 if (urlShown) { |
| 312 urlHighlighted = setUrlText(suggestionItem); | 315 urlHighlighted = setUrlText(suggestionItem); |
| 313 } else { | 316 } else { |
| 314 mContentsView.mTextLine2.setVisibility(INVISIBLE); | 317 mContentsView.mTextLine2.setVisibility(INVISIBLE); |
| 315 } | 318 } |
| 316 setSuggestedQuery(suggestionItem, true, urlShown, urlHighlighted); | 319 setSuggestedQuery(suggestionItem, true, urlShown, urlHighlighted); |
| 317 setRefinable(!sameAsTyped); | 320 setRefinable(!sameAsTyped); |
| 318 } else { | 321 } else { |
| 319 int suggestionIcon = SUGGESTION_ICON_MAGNIFIER; | 322 @SuggestionIcon int suggestionIcon = SUGGESTION_ICON_MAGNIFIER; |
| 320 if (suggestionType == OmniboxSuggestionType.VOICE_SUGGEST) { | 323 if (suggestionType == OmniboxSuggestionType.VOICE_SUGGEST) { |
| 321 suggestionIcon = SUGGESTION_ICON_VOICE; | 324 suggestionIcon = SUGGESTION_ICON_VOICE; |
| 322 } else if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_P
ERSONALIZED) | 325 } else if ((suggestionType == OmniboxSuggestionType.SEARCH_SUGGEST_P
ERSONALIZED) |
| 323 || (suggestionType == OmniboxSuggestionType.SEARCH_HISTORY))
{ | 326 || (suggestionType == OmniboxSuggestionType.SEARCH_HISTORY))
{ |
| 324 // Show history icon for suggestions based on user queries. | 327 // Show history icon for suggestions based on user queries. |
| 325 suggestionIcon = SUGGESTION_ICON_HISTORY; | 328 suggestionIcon = SUGGESTION_ICON_HISTORY; |
| 326 } | 329 } |
| 327 mContentsView.setSuggestionIcon(suggestionIcon, colorsChanged); | 330 mContentsView.setSuggestionIcon(suggestionIcon, colorsChanged); |
| 328 setRefinable(!sameAsTyped); | 331 setRefinable(!sameAsTyped); |
| 329 setSuggestedQuery(suggestionItem, false, false, false); | 332 setSuggestedQuery(suggestionItem, false, false, false); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 | 574 |
| 572 /** | 575 /** |
| 573 * Container view for the contents of the suggestion (the search query, URL,
and suggestion type | 576 * Container view for the contents of the suggestion (the search query, URL,
and suggestion type |
| 574 * icon). | 577 * icon). |
| 575 */ | 578 */ |
| 576 private class SuggestionContentsContainer extends ViewGroup implements OnLay
outChangeListener { | 579 private class SuggestionContentsContainer extends ViewGroup implements OnLay
outChangeListener { |
| 577 private int mSuggestionIconLeft = Integer.MIN_VALUE; | 580 private int mSuggestionIconLeft = Integer.MIN_VALUE; |
| 578 private int mTextLeft = Integer.MIN_VALUE; | 581 private int mTextLeft = Integer.MIN_VALUE; |
| 579 private int mTextRight = Integer.MIN_VALUE; | 582 private int mTextRight = Integer.MIN_VALUE; |
| 580 private Drawable mSuggestionIcon; | 583 private Drawable mSuggestionIcon; |
| 584 @SuggestionIcon |
| 581 private int mSuggestionIconType = SUGGESTION_ICON_UNDEFINED; | 585 private int mSuggestionIconType = SUGGESTION_ICON_UNDEFINED; |
| 582 | 586 |
| 583 private final TextView mTextLine1; | 587 private final TextView mTextLine1; |
| 584 private final TextView mTextLine2; | 588 private final TextView mTextLine2; |
| 585 private final ImageView mAnswerImage; | 589 private final ImageView mAnswerImage; |
| 586 | 590 |
| 587 private int mAnswerImageMaxSize; // getMaxWidth() is API 16+, so store
it locally. | 591 private int mAnswerImageMaxSize; // getMaxWidth() is API 16+, so store
it locally. |
| 588 private float mRequiredWidth; | 592 private float mRequiredWidth; |
| 589 private float mMatchContentsWidth; | 593 private float mMatchContentsWidth; |
| 590 private boolean mForceIsFocused; | 594 private boolean mForceIsFocused; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 } else { | 729 } else { |
| 726 verticalOffset = height - line2Height; | 730 verticalOffset = height - line2Height; |
| 727 } | 731 } |
| 728 } else { | 732 } else { |
| 729 // The text lines fit comfortably, so vertically center them. | 733 // The text lines fit comfortably, so vertically center them. |
| 730 verticalOffset = (height - line1Height - line2Height) / 2; | 734 verticalOffset = (height - line1Height - line2Height) / 2; |
| 731 if (child == mTextLine2) { | 735 if (child == mTextLine2) { |
| 732 verticalOffset += line1Height; | 736 verticalOffset += line1Height; |
| 733 if (mSuggestion.hasAnswer() | 737 if (mSuggestion.hasAnswer() |
| 734 && mSuggestion.getAnswer().getSecondLine().hasImage(
)) { | 738 && mSuggestion.getAnswer().getSecondLine().hasImage(
)) { |
| 735 verticalOffset += ANSWER_LINE2_VERTICAL_SPACING_DP | 739 verticalOffset += getResources().getDimensionPixelOffset
( |
| 736 * getResources().getDisplayMetrics().density; | 740 R.dimen.omnibox_suggestion_answer_line2_vertical
_spacing); |
| 737 } | 741 } |
| 738 } | 742 } |
| 739 // When one line is larger than the other, it contains extra ver
tical padding. This | 743 // When one line is larger than the other, it contains extra ver
tical padding. This |
| 740 // produces more apparent whitespace above or below the text lin
es. Add a small | 744 // produces more apparent whitespace above or below the text lin
es. Add a small |
| 741 // offset to compensate. | 745 // offset to compensate. |
| 742 if (line1Height != line2Height) { | 746 if (line1Height != line2Height) { |
| 743 verticalOffset += (line2Height - line1Height) / 10; | 747 verticalOffset += (line2Height - line1Height) / 10; |
| 744 } | 748 } |
| 745 | 749 |
| 746 // The image is positioned vertically aligned with the second te
xt line but | 750 // The image is positioned vertically aligned with the second te
xt line but |
| 747 // requires a small additional offset to align with the ascent o
f the text instead | 751 // requires a small additional offset to align with the ascent o
f the text instead |
| 748 // of the top of the text which includes some whitespace. | 752 // of the top of the text which includes some whitespace. |
| 749 if (child == mAnswerImage) { | 753 if (child == mAnswerImage) { |
| 750 verticalOffset += ANSWER_IMAGE_VERTICAL_SPACING_DP | 754 verticalOffset += getResources().getDimensionPixelOffset( |
| 751 * getResources().getDisplayMetrics().density; | 755 R.dimen.omnibox_suggestion_answer_line2_vertical_spa
cing); |
| 752 } | 756 } |
| 753 } | 757 } |
| 754 | 758 |
| 755 canvas.save(); | 759 canvas.save(); |
| 756 canvas.translate(0, verticalOffset); | 760 canvas.translate(0, verticalOffset); |
| 757 boolean retVal = super.drawChild(canvas, child, drawingTime); | 761 boolean retVal = super.drawChild(canvas, child, drawingTime); |
| 758 canvas.restore(); | 762 canvas.restore(); |
| 759 return retVal; | 763 return retVal; |
| 760 } | 764 } |
| 761 | 765 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 785 : Math.max(textWidth - maxMatchContentsWidth, 0); | 789 : Math.max(textWidth - maxMatchContentsWidth, 0); |
| 786 ApiCompatibilityUtils.setPaddingRelative( | 790 ApiCompatibilityUtils.setPaddingRelative( |
| 787 mTextLine1, (int) paddingStart, mTextLine1.getPaddingTop
(), | 791 mTextLine1, (int) paddingStart, mTextLine1.getPaddingTop
(), |
| 788 0, // TODO(skanuj) : Change to ApiCompatibilityUtils.get
PaddingEnd(...). | 792 0, // TODO(skanuj) : Change to ApiCompatibilityUtils.get
PaddingEnd(...). |
| 789 mTextLine1.getPaddingBottom()); | 793 mTextLine1.getPaddingBottom()); |
| 790 } | 794 } |
| 791 | 795 |
| 792 int imageWidth = mAnswerImageMaxSize; | 796 int imageWidth = mAnswerImageMaxSize; |
| 793 int imageSpacing = 0; | 797 int imageSpacing = 0; |
| 794 if (mAnswerImage.getVisibility() == VISIBLE && imageWidth > 0) { | 798 if (mAnswerImage.getVisibility() == VISIBLE && imageWidth > 0) { |
| 795 float density = getResources().getDisplayMetrics().density; | 799 imageSpacing = getResources().getDimensionPixelOffset( |
| 796 imageSpacing = (int) (ANSWER_IMAGE_HORIZONTAL_SPACING_DP * densi
ty); | 800 R.dimen.omnibox_suggestion_answer_image_horizontal_spaci
ng); |
| 797 } | 801 } |
| 798 if (isRTL) { | 802 if (isRTL) { |
| 799 mTextLine1.layout(0, t, mTextRight, b); | 803 mTextLine1.layout(0, t, mTextRight, b); |
| 800 mAnswerImage.layout(mTextRight - imageWidth , t, mTextRight, b); | 804 mAnswerImage.layout(mTextRight - imageWidth , t, mTextRight, b); |
| 801 mTextLine2.layout(0, t, mTextRight - (imageWidth + imageSpacing)
, b); | 805 mTextLine2.layout(0, t, mTextRight - (imageWidth + imageSpacing)
, b); |
| 802 } else { | 806 } else { |
| 803 mTextLine1.layout(mTextLeft, t, r - l, b); | 807 mTextLine1.layout(mTextLeft, t, r - l, b); |
| 804 mAnswerImage.layout(mTextLeft, t, mTextLeft + imageWidth, b); | 808 mAnswerImage.layout(mTextLeft, t, mTextLeft + imageWidth, b); |
| 805 mTextLine2.layout(mTextLeft + imageWidth + imageSpacing, t, r -
l, b); | 809 mTextLine2.layout(mTextLeft + imageWidth + imageSpacing, t, r -
l, b); |
| 806 } | 810 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 // When creating the drawable states, treat selected as focused to g
et the proper | 914 // When creating the drawable states, treat selected as focused to g
et the proper |
| 911 // highlight when in non-touch mode (i.e. physical keyboard). This
is because only | 915 // highlight when in non-touch mode (i.e. physical keyboard). This
is because only |
| 912 // a single view in a window can have focus, and the these will only
appear if | 916 // a single view in a window can have focus, and the these will only
appear if |
| 913 // the omnibox has focus, so we trick the drawable state into believ
ing it has it. | 917 // the omnibox has focus, so we trick the drawable state into believ
ing it has it. |
| 914 mForceIsFocused = isSelected() && !isInTouchMode(); | 918 mForceIsFocused = isSelected() && !isInTouchMode(); |
| 915 int[] drawableState = super.onCreateDrawableState(extraSpace); | 919 int[] drawableState = super.onCreateDrawableState(extraSpace); |
| 916 mForceIsFocused = false; | 920 mForceIsFocused = false; |
| 917 return drawableState; | 921 return drawableState; |
| 918 } | 922 } |
| 919 | 923 |
| 920 private void setSuggestionIcon(int type, boolean invalidateCurrentIcon)
{ | 924 private void setSuggestionIcon(@SuggestionIcon int type, boolean invalid
ateCurrentIcon) { |
| 921 if (mSuggestionIconType == type && !invalidateCurrentIcon) return; | 925 if (mSuggestionIconType == type && !invalidateCurrentIcon) return; |
| 922 assert type != SUGGESTION_ICON_UNDEFINED; | 926 assert type != SUGGESTION_ICON_UNDEFINED; |
| 923 | 927 |
| 924 int drawableId = R.drawable.ic_omnibox_page; | 928 int drawableId = R.drawable.ic_omnibox_page; |
| 925 switch (type) { | 929 switch (type) { |
| 926 case SUGGESTION_ICON_BOOKMARK: | 930 case SUGGESTION_ICON_BOOKMARK: |
| 927 drawableId = R.drawable.btn_star; | 931 drawableId = R.drawable.btn_star; |
| 928 break; | 932 break; |
| 929 case SUGGESTION_ICON_MAGNIFIER: | 933 case SUGGESTION_ICON_MAGNIFIER: |
| 930 drawableId = R.drawable.ic_suggestion_magnifier; | 934 drawableId = R.drawable.ic_suggestion_magnifier; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 if (mUrlBar != null) mUrlBar.removeOnLayoutChangeListener(this); | 997 if (mUrlBar != null) mUrlBar.removeOnLayoutChangeListener(this); |
| 994 if (mLocationBar != null) { | 998 if (mLocationBar != null) { |
| 995 mLocationBar.getContainerView().removeOnLayoutChangeListener(thi
s); | 999 mLocationBar.getContainerView().removeOnLayoutChangeListener(thi
s); |
| 996 } | 1000 } |
| 997 getRootView().removeOnLayoutChangeListener(this); | 1001 getRootView().removeOnLayoutChangeListener(this); |
| 998 | 1002 |
| 999 super.onDetachedFromWindow(); | 1003 super.onDetachedFromWindow(); |
| 1000 } | 1004 } |
| 1001 } | 1005 } |
| 1002 } | 1006 } |
| OLD | NEW |