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.animation.Animator; | 7 import android.animation.Animator; |
8 import android.animation.AnimatorListenerAdapter; | 8 import android.animation.AnimatorListenerAdapter; |
9 import android.animation.AnimatorSet; | 9 import android.animation.AnimatorSet; |
10 import android.animation.ObjectAnimator; | 10 import android.animation.ObjectAnimator; |
11 import android.annotation.SuppressLint; | 11 import android.annotation.SuppressLint; |
12 import android.content.Context; | 12 import android.content.Context; |
13 import android.graphics.Canvas; | 13 import android.graphics.Canvas; |
14 import android.graphics.Rect; | 14 import android.graphics.Rect; |
| 15 import android.support.v4.view.animation.FastOutLinearInInterpolator; |
15 import android.text.Selection; | 16 import android.text.Selection; |
16 import android.util.AttributeSet; | 17 import android.util.AttributeSet; |
17 import android.view.KeyEvent; | 18 import android.view.KeyEvent; |
18 import android.view.MotionEvent; | 19 import android.view.MotionEvent; |
19 import android.view.TouchDelegate; | 20 import android.view.TouchDelegate; |
20 import android.view.View; | 21 import android.view.View; |
21 import android.view.ViewGroup; | 22 import android.view.ViewGroup; |
22 import android.view.WindowManager; | 23 import android.view.WindowManager; |
| 24 import android.view.animation.Interpolator; |
| 25 import android.widget.FrameLayout; |
23 import android.widget.ImageView; | 26 import android.widget.ImageView; |
24 | 27 |
25 import org.chromium.base.ApiCompatibilityUtils; | 28 import org.chromium.base.ApiCompatibilityUtils; |
26 import org.chromium.chrome.R; | 29 import org.chromium.chrome.R; |
| 30 import org.chromium.chrome.browser.ChromeFeatureList; |
27 import org.chromium.chrome.browser.WindowDelegate; | 31 import org.chromium.chrome.browser.WindowDelegate; |
28 import org.chromium.chrome.browser.appmenu.AppMenuButtonHelper; | 32 import org.chromium.chrome.browser.appmenu.AppMenuButtonHelper; |
29 import org.chromium.chrome.browser.ntp.NewTabPage; | 33 import org.chromium.chrome.browser.ntp.NewTabPage; |
30 import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper; | 34 import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper; |
31 import org.chromium.chrome.browser.tab.Tab; | 35 import org.chromium.chrome.browser.tab.Tab; |
| 36 import org.chromium.chrome.browser.util.MathUtils; |
32 import org.chromium.chrome.browser.widget.TintedImageButton; | 37 import org.chromium.chrome.browser.widget.TintedImageButton; |
33 import org.chromium.ui.UiUtils; | 38 import org.chromium.ui.UiUtils; |
34 | 39 |
35 /** | 40 /** |
36 * A location bar implementation specific for smaller/phone screens. | 41 * A location bar implementation specific for smaller/phone screens. |
37 */ | 42 */ |
38 public class LocationBarPhone extends LocationBarLayout { | 43 public class LocationBarPhone extends LocationBarLayout { |
39 private static final int KEYBOARD_MODE_CHANGE_DELAY_MS = 300; | 44 private static final int KEYBOARD_MODE_CHANGE_DELAY_MS = 300; |
40 private static final int KEYBOARD_HIDE_DELAY_MS = 150; | 45 private static final int KEYBOARD_HIDE_DELAY_MS = 150; |
41 | 46 |
42 private static final int ACTION_BUTTON_TOUCH_OVERFLOW_LEFT = 15; | 47 private static final int ACTION_BUTTON_TOUCH_OVERFLOW_LEFT = 15; |
43 | 48 |
| 49 private static final Interpolator GOOGLE_G_FADE_INTERPOLATOR = |
| 50 new FastOutLinearInInterpolator(); |
| 51 |
44 private View mFirstVisibleFocusedView; | 52 private View mFirstVisibleFocusedView; |
45 private View mIncognitoBadge; | 53 private View mIncognitoBadge; |
| 54 private View mGoogleGContainer; |
| 55 private View mGoogleG; |
46 private View mUrlActionsContainer; | 56 private View mUrlActionsContainer; |
47 private TintedImageButton mMenuButton; | 57 private TintedImageButton mMenuButton; |
48 private ImageView mMenuBadge; | 58 private ImageView mMenuBadge; |
49 private View mMenuButtonWrapper; | 59 private View mMenuButtonWrapper; |
50 private int mIncognitoBadgePadding; | 60 private int mIncognitoBadgePadding; |
| 61 private int mGoogleGWidth; |
| 62 private int mGoogleGMargin; |
51 private float mUrlFocusChangePercent; | 63 private float mUrlFocusChangePercent; |
52 private Runnable mKeyboardResizeModeTask; | 64 private Runnable mKeyboardResizeModeTask; |
53 private ObjectAnimator mOmniboxBackgroundAnimator; | 65 private ObjectAnimator mOmniboxBackgroundAnimator; |
54 | 66 |
55 private boolean mShowMenuBadge; | 67 private boolean mShowMenuBadge; |
56 private AnimatorSet mMenuBadgeAnimatorSet; | 68 private AnimatorSet mMenuBadgeAnimatorSet; |
57 private boolean mIsMenuBadgeAnimationRunning; | 69 private boolean mIsMenuBadgeAnimationRunning; |
58 | 70 |
59 /** | 71 /** |
60 * Constructor used to inflate from XML. | 72 * Constructor used to inflate from XML. |
61 */ | 73 */ |
62 public LocationBarPhone(Context context, AttributeSet attrs) { | 74 public LocationBarPhone(Context context, AttributeSet attrs) { |
63 super(context, attrs); | 75 super(context, attrs); |
64 } | 76 } |
65 | 77 |
66 @Override | 78 @Override |
67 protected void onFinishInflate() { | 79 protected void onFinishInflate() { |
68 super.onFinishInflate(); | 80 super.onFinishInflate(); |
69 | 81 |
70 mFirstVisibleFocusedView = findViewById(R.id.url_bar); | 82 mFirstVisibleFocusedView = findViewById(R.id.url_bar); |
71 mIncognitoBadge = findViewById(R.id.incognito_badge); | 83 mIncognitoBadge = findViewById(R.id.incognito_badge); |
72 mIncognitoBadgePadding = | 84 mIncognitoBadgePadding = |
73 getResources().getDimensionPixelSize(R.dimen.location_bar_incogn
ito_badge_padding); | 85 getResources().getDimensionPixelSize(R.dimen.location_bar_incogn
ito_badge_padding); |
74 | 86 |
| 87 mGoogleGContainer = findViewById(R.id.google_g_container); |
| 88 mGoogleG = findViewById(R.id.google_g); |
| 89 mGoogleGWidth = getResources().getDimensionPixelSize(R.dimen.location_ba
r_google_g_width); |
| 90 mGoogleGMargin = getResources().getDimensionPixelSize(R.dimen.location_b
ar_google_g_margin); |
| 91 |
75 mUrlActionsContainer = findViewById(R.id.url_action_container); | 92 mUrlActionsContainer = findViewById(R.id.url_action_container); |
76 Rect delegateArea = new Rect(); | 93 Rect delegateArea = new Rect(); |
77 mUrlActionsContainer.getHitRect(delegateArea); | 94 mUrlActionsContainer.getHitRect(delegateArea); |
78 delegateArea.left -= ACTION_BUTTON_TOUCH_OVERFLOW_LEFT; | 95 delegateArea.left -= ACTION_BUTTON_TOUCH_OVERFLOW_LEFT; |
79 TouchDelegate touchDelegate = new TouchDelegate(delegateArea, mUrlAction
sContainer); | 96 TouchDelegate touchDelegate = new TouchDelegate(delegateArea, mUrlAction
sContainer); |
80 assert mUrlActionsContainer.getParent() == this; | 97 assert mUrlActionsContainer.getParent() == this; |
81 setTouchDelegate(touchDelegate); | 98 setTouchDelegate(touchDelegate); |
82 | 99 |
83 mMenuButton = (TintedImageButton) findViewById(R.id.document_menu_button
); | 100 mMenuButton = (TintedImageButton) findViewById(R.id.document_menu_button
); |
84 mMenuBadge = (ImageView) findViewById(R.id.document_menu_badge); | 101 mMenuBadge = (ImageView) findViewById(R.id.document_menu_badge); |
(...skipping 21 matching lines...) Expand all Loading... |
106 return false; | 123 return false; |
107 } | 124 } |
108 }); | 125 }); |
109 } | 126 } |
110 | 127 |
111 @Override | 128 @Override |
112 public View getMenuAnchor() { | 129 public View getMenuAnchor() { |
113 return mMenuButton; | 130 return mMenuButton; |
114 } | 131 } |
115 | 132 |
116 @Override | |
117 public void getContentRect(Rect outRect) { | |
118 super.getContentRect(outRect); | |
119 if (mIncognitoBadge.getVisibility() == View.GONE) return; | |
120 | |
121 if (!ApiCompatibilityUtils.isLayoutRtl(this)) { | |
122 outRect.left += mIncognitoBadge.getWidth(); | |
123 } else { | |
124 outRect.right -= mIncognitoBadge.getWidth(); | |
125 } | |
126 } | |
127 | |
128 /** | 133 /** |
129 * @return The first view visible when the location bar is focused. | 134 * @return The first view visible when the location bar is focused. |
130 */ | 135 */ |
131 public View getFirstViewVisibleWhenFocused() { | 136 public View getFirstViewVisibleWhenFocused() { |
132 return mFirstVisibleFocusedView; | 137 return mFirstVisibleFocusedView; |
133 } | 138 } |
134 | 139 |
135 /** | 140 /** |
136 * Updates percentage of current the URL focus change animation. | 141 * Updates percentage of current the URL focus change animation. |
137 * @param percent 1.0 is 100% focused, 0 is completely unfocused. | 142 * @param percent 1.0 is 100% focused, 0 is completely unfocused. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 268 |
264 NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab(); | 269 NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab(); |
265 if (hasFocus && ntp != null && ntp.isLocationBarShownInNTP() && mBottomS
heet == null) { | 270 if (hasFocus && ntp != null && ntp.isLocationBarShownInNTP() && mBottomS
heet == null) { |
266 mFadingView.showFadingOverlay(); | 271 mFadingView.showFadingOverlay(); |
267 } | 272 } |
268 } | 273 } |
269 | 274 |
270 @Override | 275 @Override |
271 protected void updateButtonVisibility() { | 276 protected void updateButtonVisibility() { |
272 updateDeleteButtonVisibility(); | 277 updateDeleteButtonVisibility(); |
273 updateMicButtonVisiblity(mUrlFocusChangePercent); | 278 updateMicButtonVisibility(mUrlFocusChangePercent); |
| 279 updateGoogleG(); |
| 280 } |
| 281 |
| 282 private void updateGoogleG() { |
| 283 NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab(); |
| 284 |
| 285 // If the default search engine is not Google, isLocationBarShownInNTP()
will return false. |
| 286 if (ntp == null || !ntp.isLocationBarShownInNTP() |
| 287 || !ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SHOW_GOOGL
E_G_IN_OMNIBOX)) { |
| 288 mGoogleGContainer.setVisibility(View.GONE); |
| 289 return; |
| 290 } |
| 291 |
| 292 mGoogleGContainer.setVisibility(View.VISIBLE); |
| 293 float animationProgress = |
| 294 GOOGLE_G_FADE_INTERPOLATOR.getInterpolation(mUrlFocusChangePerce
nt); |
| 295 mGoogleG.setAlpha(1 - animationProgress); |
| 296 |
| 297 // Shrink the width down to zero, and the end margin down to half of its
starting value. |
| 298 FrameLayout.LayoutParams layoutParams = |
| 299 (FrameLayout.LayoutParams) mGoogleG.getLayoutParams(); |
| 300 layoutParams.width = Math.round(mGoogleGWidth * (1 - animationProgress))
; |
| 301 ApiCompatibilityUtils.setMarginEnd( |
| 302 layoutParams, Math.round(MathUtils.interpolate( |
| 303 mGoogleGMargin, mGoogleGMargin / 2f, anima
tionProgress))); |
| 304 |
| 305 // Just calling requestLayout() would not resolve the end margin. |
| 306 mGoogleG.setLayoutParams(layoutParams); |
274 } | 307 } |
275 | 308 |
276 @Override | 309 @Override |
277 protected void updateLocationBarIconContainerVisibility() { | 310 protected void updateLocationBarIconContainerVisibility() { |
278 super.updateLocationBarIconContainerVisibility(); | 311 super.updateLocationBarIconContainerVisibility(); |
279 updateIncognitoBadgePadding(); | 312 updateIncognitoBadgePadding(); |
280 } | 313 } |
281 | 314 |
282 private void updateIncognitoBadgePadding() { | 315 private void updateIncognitoBadgePadding() { |
283 // This can be triggered in the super.onFinishInflate, so we need to nul
l check in this | 316 // This can be triggered in the super.onFinishInflate, so we need to nul
l check in this |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 386 |
354 mMenuBadgeAnimatorSet.start(); | 387 mMenuBadgeAnimatorSet.start(); |
355 } | 388 } |
356 | 389 |
357 public void cancelAppMenuUpdateBadgeAnimation() { | 390 public void cancelAppMenuUpdateBadgeAnimation() { |
358 if (mIsMenuBadgeAnimationRunning && mMenuBadgeAnimatorSet != null) { | 391 if (mIsMenuBadgeAnimationRunning && mMenuBadgeAnimatorSet != null) { |
359 mMenuBadgeAnimatorSet.cancel(); | 392 mMenuBadgeAnimatorSet.cancel(); |
360 } | 393 } |
361 } | 394 } |
362 } | 395 } |
OLD | NEW |