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