Chromium Code Reviews| 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.toolbar; | 5 package org.chromium.chrome.browser.toolbar; |
| 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.annotation.SuppressLint; | 10 import android.annotation.SuppressLint; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 private ToolbarDataProvider mToolbarDataProvider; | 70 private ToolbarDataProvider mToolbarDataProvider; |
| 71 private ToolbarTabController mToolbarTabController; | 71 private ToolbarTabController mToolbarTabController; |
| 72 @Nullable | 72 @Nullable |
| 73 protected ToolbarProgressBar mProgressBar; | 73 protected ToolbarProgressBar mProgressBar; |
| 74 | 74 |
| 75 private boolean mNativeLibraryReady; | 75 private boolean mNativeLibraryReady; |
| 76 private boolean mUrlHasFocus; | 76 private boolean mUrlHasFocus; |
| 77 | 77 |
| 78 private long mFirstDrawTimeMs; | 78 private long mFirstDrawTimeMs; |
| 79 | 79 |
| 80 protected final int mToolbarHeightWithoutShadow; | |
| 81 | |
| 82 private boolean mFindInPageToolbarShowing; | 80 private boolean mFindInPageToolbarShowing; |
| 83 | 81 |
| 84 protected boolean mShowMenuBadge; | 82 protected boolean mShowMenuBadge; |
| 85 private AnimatorSet mMenuBadgeAnimatorSet; | 83 private AnimatorSet mMenuBadgeAnimatorSet; |
| 86 private boolean mIsMenuBadgeAnimationRunning; | 84 private boolean mIsMenuBadgeAnimationRunning; |
| 87 | 85 |
| 88 /** | 86 /** |
| 89 * Basic constructor for {@link ToolbarLayout}. | 87 * Basic constructor for {@link ToolbarLayout}. |
| 90 */ | 88 */ |
| 91 public ToolbarLayout(Context context, AttributeSet attrs) { | 89 public ToolbarLayout(Context context, AttributeSet attrs) { |
| 92 super(context, attrs); | 90 super(context, attrs); |
| 93 mToolbarHeightWithoutShadow = getResources().getDimensionPixelOffset( | |
| 94 getToolbarHeightWithoutShadowResId()); | |
| 95 mDarkModeTint = | 91 mDarkModeTint = |
| 96 ApiCompatibilityUtils.getColorStateList(getResources(), R.color. dark_mode_tint); | 92 ApiCompatibilityUtils.getColorStateList(getResources(), R.color. dark_mode_tint); |
| 97 mLightModeTint = | 93 mLightModeTint = |
| 98 ApiCompatibilityUtils.getColorStateList(getResources(), R.color. light_mode_tint); | 94 ApiCompatibilityUtils.getColorStateList(getResources(), R.color. light_mode_tint); |
| 99 } | 95 } |
| 100 | 96 |
| 101 /** | 97 /** |
| 102 * Get the top margin of the progress bar relative to the toolbar layout. Th is is used to set | 98 * Get the top margin of the progress bar relative to the toolbar layout. Th is is used to set |
| 103 * the position of the progress bar (either top or bottom of the toolbar). | 99 * the position of the progress bar (either top or bottom of the toolbar). |
| 104 * @return The top margin of the progress bar. | 100 * @return The top margin of the progress bar. |
| 105 */ | 101 */ |
| 106 protected int getProgressBarTopMargin() { | 102 protected int getProgressBarTopMargin() { |
| 107 return mToolbarHeightWithoutShadow | 103 return getHeight() |
| 108 - getResources().getDimensionPixelSize(R.dimen.toolbar_progress_ bar_height); | 104 - getResources().getDimensionPixelSize(R.dimen.toolbar_progress_ bar_height); |
| 109 } | 105 } |
| 110 | 106 |
| 111 @Override | 107 @Override |
| 108 protected void onLayout(boolean changed, int left, int top, int right, int b ottom) { | |
| 109 super.onLayout(changed, left, top, right, bottom); | |
| 110 | |
| 111 if (mProgressBar == null) { | |
|
gone
2017/03/14 22:38:40
Does this really have to be here? onLayout seems
mdjones
2017/03/15 17:26:12
This is the result of a bad rebase. The latest pat
| |
| 112 mProgressBar = new ToolbarProgressBar(getContext(), getProgressBarTo pMargin()); | |
| 113 if (isNativeLibraryReady()) mProgressBar.initializeAnimation(); | |
| 114 addProgressBarToHierarchy(); | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 @Override | |
| 112 protected void onFinishInflate() { | 119 protected void onFinishInflate() { |
| 113 super.onFinishInflate(); | 120 super.onFinishInflate(); |
| 114 | 121 |
| 115 mProgressBar = new ToolbarProgressBar(getContext(), getProgressBarTopMar gin()); | |
| 116 | |
| 117 if (isNativeLibraryReady()) mProgressBar.initializeAnimation(); | |
| 118 | |
| 119 mMenuButton = (TintedImageButton) findViewById(R.id.menu_button); | 122 mMenuButton = (TintedImageButton) findViewById(R.id.menu_button); |
| 120 mMenuBadge = (ImageView) findViewById(R.id.menu_badge); | 123 mMenuBadge = (ImageView) findViewById(R.id.menu_badge); |
| 121 mMenuButtonWrapper = findViewById(R.id.menu_button_wrapper); | 124 mMenuButtonWrapper = findViewById(R.id.menu_button_wrapper); |
| 122 | 125 |
| 123 // Initialize the provider to an empty version to avoid null checking ev erywhere. | 126 // Initialize the provider to an empty version to avoid null checking ev erywhere. |
| 124 mToolbarDataProvider = new ToolbarDataProvider() { | 127 mToolbarDataProvider = new ToolbarDataProvider() { |
| 125 @Override | 128 @Override |
| 126 public boolean isIncognito() { | 129 public boolean isIncognito() { |
| 127 return false; | 130 return false; |
| 128 } | 131 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 /** | 165 /** |
| 163 * Quick getter for LayoutParams for a View inside a FrameLayout. | 166 * Quick getter for LayoutParams for a View inside a FrameLayout. |
| 164 * @param view {@link View} to fetch the layout params for. | 167 * @param view {@link View} to fetch the layout params for. |
| 165 * @return {@link LayoutParams} the given {@link View} is currently using. | 168 * @return {@link LayoutParams} the given {@link View} is currently using. |
| 166 */ | 169 */ |
| 167 protected FrameLayout.LayoutParams getFrameLayoutParams(View view) { | 170 protected FrameLayout.LayoutParams getFrameLayoutParams(View view) { |
| 168 return ((FrameLayout.LayoutParams) view.getLayoutParams()); | 171 return ((FrameLayout.LayoutParams) view.getLayoutParams()); |
| 169 } | 172 } |
| 170 | 173 |
| 171 /** | 174 /** |
| 172 * @return The resource id to be used while getting the toolbar height with no shadow. | |
| 173 */ | |
| 174 protected int getToolbarHeightWithoutShadowResId() { | |
| 175 return R.dimen.toolbar_height_no_shadow; | |
| 176 } | |
| 177 | |
| 178 /** | |
| 179 * Initialize the external dependencies required for view interaction. | 175 * Initialize the external dependencies required for view interaction. |
| 180 * @param toolbarDataProvider The provider for toolbar data. | 176 * @param toolbarDataProvider The provider for toolbar data. |
| 181 * @param tabController The controller that handles interactions with the tab. | 177 * @param tabController The controller that handles interactions with the tab. |
| 182 * @param appMenuButtonHelper The helper for managing menu button interactio ns. | 178 * @param appMenuButtonHelper The helper for managing menu button interactio ns. |
| 183 */ | 179 */ |
| 184 public void initialize(ToolbarDataProvider toolbarDataProvider, | 180 public void initialize(ToolbarDataProvider toolbarDataProvider, |
| 185 ToolbarTabController tabController, AppMenuButtonHelper appMenuButto nHelper) { | 181 ToolbarTabController tabController, AppMenuButtonHelper appMenuButto nHelper) { |
| 186 mToolbarDataProvider = toolbarDataProvider; | 182 mToolbarDataProvider = toolbarDataProvider; |
| 187 mToolbarTabController = tabController; | 183 mToolbarTabController = tabController; |
| 188 | 184 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 if (mProgressBar == null) return; | 252 if (mProgressBar == null) return; |
| 257 | 253 |
| 258 ViewGroup controlContainer = | 254 ViewGroup controlContainer = |
| 259 (ViewGroup) getRootView().findViewById(R.id.control_container); | 255 (ViewGroup) getRootView().findViewById(R.id.control_container); |
| 260 int progressBarPosition = UiUtils.insertAfter( | 256 int progressBarPosition = UiUtils.insertAfter( |
| 261 controlContainer, mProgressBar, (View) getParent()); | 257 controlContainer, mProgressBar, (View) getParent()); |
| 262 assert progressBarPosition >= 0; | 258 assert progressBarPosition >= 0; |
| 263 mProgressBar.setProgressBarContainer(controlContainer); | 259 mProgressBar.setProgressBarContainer(controlContainer); |
| 264 } | 260 } |
| 265 | 261 |
| 266 @Override | |
| 267 protected void onAttachedToWindow() { | |
| 268 super.onAttachedToWindow(); | |
| 269 addProgressBarToHierarchy(); | |
| 270 } | |
| 271 | |
| 272 /** | 262 /** |
| 273 * Shows the content description toast for items on the toolbar. | 263 * Shows the content description toast for items on the toolbar. |
| 274 * @param view The view to anchor the toast. | 264 * @param view The view to anchor the toast. |
| 275 * @param description The string shown in the toast. | 265 * @param description The string shown in the toast. |
| 276 * @return Whether a toast has been shown successfully. | 266 * @return Whether a toast has been shown successfully. |
| 277 */ | 267 */ |
| 278 protected boolean showAccessibilityToast(View view, CharSequence description ) { | 268 protected boolean showAccessibilityToast(View view, CharSequence description ) { |
| 279 if (description == null) return false; | 269 if (description == null) return false; |
| 280 | 270 |
| 281 final int screenWidth = getResources().getDisplayMetrics().widthPixels; | 271 final int screenWidth = getResources().getDisplayMetrics().widthPixels; |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 R.string.accessibility_toolbar_btn_menu_update)); | 793 R.string.accessibility_toolbar_btn_menu_update)); |
| 804 } else { | 794 } else { |
| 805 mMenuButton.setContentDescription(getResources().getString( | 795 mMenuButton.setContentDescription(getResources().getString( |
| 806 R.string.accessibility_toolbar_btn_menu)); | 796 R.string.accessibility_toolbar_btn_menu)); |
| 807 } | 797 } |
| 808 } | 798 } |
| 809 | 799 |
| 810 @Override | 800 @Override |
| 811 public void setBottomSheet(BottomSheet sheet) {} | 801 public void setBottomSheet(BottomSheet sheet) {} |
| 812 } | 802 } |
| OLD | NEW |