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.animation.ObjectAnimator; | 10 import android.animation.ObjectAnimator; |
| 11 import android.animation.ValueAnimator; | 11 import android.animation.ValueAnimator; |
| 12 import android.animation.ValueAnimator.AnimatorUpdateListener; | 12 import android.animation.ValueAnimator.AnimatorUpdateListener; |
| 13 import android.annotation.SuppressLint; | 13 import android.annotation.SuppressLint; |
| 14 import android.content.Context; | 14 import android.content.Context; |
| 15 import android.content.res.ColorStateList; | |
| 16 import android.content.res.Resources; | 15 import android.content.res.Resources; |
| 17 import android.graphics.Canvas; | 16 import android.graphics.Canvas; |
| 18 import android.graphics.Color; | 17 import android.graphics.Color; |
| 19 import android.graphics.Point; | 18 import android.graphics.Point; |
| 20 import android.graphics.PorterDuff; | 19 import android.graphics.PorterDuff; |
| 21 import android.graphics.Rect; | 20 import android.graphics.Rect; |
| 22 import android.graphics.drawable.BitmapDrawable; | 21 import android.graphics.drawable.BitmapDrawable; |
| 23 import android.graphics.drawable.ColorDrawable; | 22 import android.graphics.drawable.ColorDrawable; |
| 24 import android.graphics.drawable.Drawable; | 23 import android.graphics.drawable.Drawable; |
| 25 import android.graphics.drawable.TransitionDrawable; | 24 import android.graphics.drawable.TransitionDrawable; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 private boolean mUnfocusedLocationBarUsesTransparentBg; | 155 private boolean mUnfocusedLocationBarUsesTransparentBg; |
| 157 | 156 |
| 158 private int mUrlBackgroundAlpha = 255; | 157 private int mUrlBackgroundAlpha = 255; |
| 159 private float mNtpSearchBoxScrollPercent = UNINITIALIZED_PERCENT; | 158 private float mNtpSearchBoxScrollPercent = UNINITIALIZED_PERCENT; |
| 160 private ColorDrawable mToolbarBackground; | 159 private ColorDrawable mToolbarBackground; |
| 161 private Drawable mLocationBarBackground; | 160 private Drawable mLocationBarBackground; |
| 162 private boolean mForceDrawLocationBarBackground; | 161 private boolean mForceDrawLocationBarBackground; |
| 163 private TabSwitcherDrawable mTabSwitcherButtonDrawable; | 162 private TabSwitcherDrawable mTabSwitcherButtonDrawable; |
| 164 private TabSwitcherDrawable mTabSwitcherButtonDrawableLight; | 163 private TabSwitcherDrawable mTabSwitcherButtonDrawableLight; |
| 165 | 164 |
| 165 private final int mLightModeDefaultColor; | |
| 166 private final int mDarkModeDefaultColor; | |
| 167 | |
| 166 private final Rect mUrlViewportBounds = new Rect(); | 168 private final Rect mUrlViewportBounds = new Rect(); |
| 167 private final Rect mUrlBackgroundPadding = new Rect(); | 169 private final Rect mUrlBackgroundPadding = new Rect(); |
| 168 private final Rect mBackgroundOverlayBounds = new Rect(); | 170 private final Rect mBackgroundOverlayBounds = new Rect(); |
| 169 private final Rect mLocationBarBackgroundOffset = new Rect(); | 171 private final Rect mLocationBarBackgroundOffset = new Rect(); |
| 170 | 172 |
| 171 private final Rect mNtpSearchBoxOriginalBounds = new Rect(); | 173 private final Rect mNtpSearchBoxOriginalBounds = new Rect(); |
| 172 private final Rect mNtpSearchBoxTransformedBounds = new Rect(); | 174 private final Rect mNtpSearchBoxTransformedBounds = new Rect(); |
| 173 | 175 |
| 174 private final int mLocationBarInsets; | 176 private final int mLocationBarInsets; |
| 175 private final int mToolbarSidePadding; | 177 private final int mToolbarSidePadding; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 * @param context The Context in which this View object is created. | 234 * @param context The Context in which this View object is created. |
| 233 * @param attrs The AttributeSet that was specified with this View. | 235 * @param attrs The AttributeSet that was specified with this View. |
| 234 */ | 236 */ |
| 235 public ToolbarPhone(Context context, AttributeSet attrs) { | 237 public ToolbarPhone(Context context, AttributeSet attrs) { |
| 236 super(context, attrs); | 238 super(context, attrs); |
| 237 mToolbarSidePadding = getResources().getDimensionPixelOffset( | 239 mToolbarSidePadding = getResources().getDimensionPixelOffset( |
| 238 R.dimen.toolbar_edge_padding); | 240 R.dimen.toolbar_edge_padding); |
| 239 // Insets used for the PhoneLocatioBar background drawable. | 241 // Insets used for the PhoneLocatioBar background drawable. |
| 240 mLocationBarInsets = getResources().getDimensionPixelSize(R.dimen.locati on_bar_margin_top) | 242 mLocationBarInsets = getResources().getDimensionPixelSize(R.dimen.locati on_bar_margin_top) |
| 241 + getResources().getDimensionPixelSize(R.dimen.location_bar_marg in_bottom); | 243 + getResources().getDimensionPixelSize(R.dimen.location_bar_marg in_bottom); |
| 244 mLightModeDefaultColor = | |
| 245 ApiCompatibilityUtils.getColor(getResources(), R.color.light_mod e_tint); | |
| 246 mDarkModeDefaultColor = | |
| 247 ApiCompatibilityUtils.getColor(getResources(), R.color.dark_mode _tint); | |
| 242 } | 248 } |
| 243 | 249 |
| 244 @Override | 250 @Override |
| 245 public void onFinishInflate() { | 251 public void onFinishInflate() { |
| 246 super.onFinishInflate(); | 252 super.onFinishInflate(); |
| 247 mPhoneLocationBar = (LocationBarPhone) findViewById(R.id.location_bar); | 253 mPhoneLocationBar = (LocationBarPhone) findViewById(R.id.location_bar); |
| 248 | 254 |
| 249 mToolbarButtonsContainer = (ViewGroup) findViewById(R.id.toolbar_buttons ); | 255 mToolbarButtonsContainer = (ViewGroup) findViewById(R.id.toolbar_buttons ); |
| 250 | 256 |
| 251 mHomeButton = (TintedImageButton) findViewById(R.id.home_button); | 257 mHomeButton = (TintedImageButton) findViewById(R.id.home_button); |
| (...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 929 // Draw the menu button if necessary. | 935 // Draw the menu button if necessary. |
| 930 if (mTabSwitcherAnimationMenuDrawable != null | 936 if (mTabSwitcherAnimationMenuDrawable != null |
| 931 && mUrlExpansionPercent != 1f) { | 937 && mUrlExpansionPercent != 1f) { |
| 932 mTabSwitcherAnimationMenuDrawable.setBounds( | 938 mTabSwitcherAnimationMenuDrawable.setBounds( |
| 933 mMenuButton.getPaddingLeft(), mMenuButton.getPaddingTop(), | 939 mMenuButton.getPaddingLeft(), mMenuButton.getPaddingTop(), |
| 934 mMenuButton.getWidth() - mMenuButton.getPaddingRight(), | 940 mMenuButton.getWidth() - mMenuButton.getPaddingRight(), |
| 935 mMenuButton.getHeight() - mMenuButton.getPaddingBottom()); | 941 mMenuButton.getHeight() - mMenuButton.getPaddingBottom()); |
| 936 translateCanvasToView(mToolbarButtonsContainer, mMenuButton, canvas) ; | 942 translateCanvasToView(mToolbarButtonsContainer, mMenuButton, canvas) ; |
| 937 mTabSwitcherAnimationMenuDrawable.setAlpha(rgbAlpha); | 943 mTabSwitcherAnimationMenuDrawable.setAlpha(rgbAlpha); |
| 938 int color = mUseLightToolbarDrawables | 944 int color = mUseLightToolbarDrawables |
| 939 ? ApiCompatibilityUtils.getColor(getResources(), R.color.lig ht_mode_tint) | 945 ? mLightModeDefaultColor |
| 940 : ApiCompatibilityUtils.getColor(getResources(), R.color.dar k_mode_tint); | 946 : mDarkModeDefaultColor; |
| 941 mTabSwitcherAnimationMenuDrawable.setColorFilter(color, PorterDuff.M ode.SRC_IN); | 947 mTabSwitcherAnimationMenuDrawable.setColorFilter(color, PorterDuff.M ode.SRC_IN); |
| 942 mTabSwitcherAnimationMenuDrawable.draw(canvas); | 948 mTabSwitcherAnimationMenuDrawable.draw(canvas); |
| 943 } | 949 } |
| 944 | 950 |
| 945 canvas.restore(); | 951 canvas.restore(); |
| 946 } | 952 } |
| 947 | 953 |
| 948 @Override | 954 @Override |
| 949 public void doInvalidate() { | 955 public void doInvalidate() { |
| 950 postInvalidateOnAnimation(); | 956 postInvalidateOnAnimation(); |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1359 if (!visualStateChanged) return; | 1365 if (!visualStateChanged) return; |
| 1360 | 1366 |
| 1361 mOverlayDrawablesVisualState = overlayState; | 1367 mOverlayDrawablesVisualState = overlayState; |
| 1362 mTabSwitcherAnimationBgOverlay.setColor(getToolbarColorForVisualState( | 1368 mTabSwitcherAnimationBgOverlay.setColor(getToolbarColorForVisualState( |
| 1363 mOverlayDrawablesVisualState)); | 1369 mOverlayDrawablesVisualState)); |
| 1364 | 1370 |
| 1365 if (shouldShowMenuButton()) { | 1371 if (shouldShowMenuButton()) { |
| 1366 Resources res = getResources(); | 1372 Resources res = getResources(); |
| 1367 mTabSwitcherAnimationMenuDrawable = ApiCompatibilityUtils.getDrawabl e( | 1373 mTabSwitcherAnimationMenuDrawable = ApiCompatibilityUtils.getDrawabl e( |
| 1368 res, R.drawable.btn_menu).mutate(); | 1374 res, R.drawable.btn_menu).mutate(); |
| 1369 mTabSwitcherAnimationMenuDrawable.setColorFilter(isIncognito() ? Col or.WHITE | 1375 mTabSwitcherAnimationMenuDrawable.setColorFilter( |
| 1370 : ApiCompatibilityUtils.getColor(res, R.color.light_normal_c olor), | 1376 isIncognito() ? mLightModeDefaultColor : mDarkModeDefaultCol or, |
| 1371 PorterDuff.Mode.SRC_IN); | 1377 PorterDuff.Mode.SRC_IN); |
| 1372 ((BitmapDrawable) mTabSwitcherAnimationMenuDrawable).setGravity(Grav ity.CENTER); | 1378 ((BitmapDrawable) mTabSwitcherAnimationMenuDrawable).setGravity(Grav ity.CENTER); |
| 1373 } | 1379 } |
| 1374 } | 1380 } |
| 1375 | 1381 |
| 1376 @Override | 1382 @Override |
| 1377 public void setOnTabSwitcherClickHandler(OnClickListener listener) { | 1383 public void setOnTabSwitcherClickHandler(OnClickListener listener) { |
| 1378 mTabSwitcherListener = listener; | 1384 mTabSwitcherListener = listener; |
| 1379 } | 1385 } |
| 1380 | 1386 |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1853 mUnfocusedLocationBarUsesTransparentBg = | 1859 mUnfocusedLocationBarUsesTransparentBg = |
| 1854 !ColorUtils.shouldUseOpaqueTextboxBackground(currentPrimaryC olor); | 1860 !ColorUtils.shouldUseOpaqueTextboxBackground(currentPrimaryC olor); |
| 1855 mUrlBackgroundAlpha = mUnfocusedLocationBarUsesTransparentBg | 1861 mUrlBackgroundAlpha = mUnfocusedLocationBarUsesTransparentBg |
| 1856 ? LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA : 255; | 1862 ? LOCATION_BAR_TRANSPARENT_BACKGROUND_ALPHA : 255; |
| 1857 progressBarBackgroundColorResource = mUseLightToolbarDrawables | 1863 progressBarBackgroundColorResource = mUseLightToolbarDrawables |
| 1858 ? R.color.progress_bar_background_white : R.color.progress_b ar_background; | 1864 ? R.color.progress_bar_background_white : R.color.progress_b ar_background; |
| 1859 } | 1865 } |
| 1860 | 1866 |
| 1861 getProgressBar().setBackgroundColor( | 1867 getProgressBar().setBackgroundColor( |
| 1862 ApiCompatibilityUtils.getColor(getResources(), progressBarBackgr oundColorResource)); | 1868 ApiCompatibilityUtils.getColor(getResources(), progressBarBackgr oundColorResource)); |
| 1863 ColorStateList dark = | |
| 1864 ApiCompatibilityUtils.getColorStateList(getResources(), R.color. dark_mode_tint); | |
| 1865 ColorStateList white = | |
| 1866 ApiCompatibilityUtils.getColorStateList(getResources(), R.color. light_mode_tint); | |
| 1867 | 1869 |
| 1868 if (mToggleTabStackButton != null) { | 1870 if (mToggleTabStackButton != null) { |
| 1869 mToggleTabStackButton.setImageDrawable(mUseLightToolbarDrawables | 1871 mToggleTabStackButton.setImageDrawable(mUseLightToolbarDrawables |
| 1870 ? mTabSwitcherButtonDrawableLight : mTabSwitcherButtonDrawab le); | 1872 ? mTabSwitcherButtonDrawableLight : mTabSwitcherButtonDrawab le); |
| 1871 if (mTabSwitcherAnimationTabStackDrawable != null) { | 1873 if (mTabSwitcherAnimationTabStackDrawable != null) { |
| 1872 mTabSwitcherAnimationTabStackDrawable.setTint( | 1874 mTabSwitcherAnimationTabStackDrawable.setTint( |
| 1873 mUseLightToolbarDrawables ? white : dark); | 1875 mUseLightToolbarDrawables ? mLightModeTint : mDarkModeTi nt); |
|
Yusuf
2015/09/28 17:20:26
setTint(int color) is API 21+. There is a Drawable
aurimas (slooooooooow)
2015/09/28 20:32:56
Filed a bug for investigating that crbug.com/53692
| |
| 1874 } | 1876 } |
| 1875 } | 1877 } |
| 1876 | 1878 |
| 1877 if (shouldShowMenuButton()) { | 1879 if (shouldShowMenuButton()) { |
| 1878 mMenuButton.setTint(mUseLightToolbarDrawables ? white : dark); | 1880 mMenuButton.setTint(mUseLightToolbarDrawables ? mLightModeTint : mDa rkModeTint); |
| 1879 } | 1881 } |
| 1880 if (mHomeButton.getVisibility() != GONE) { | 1882 if (mHomeButton.getVisibility() != GONE) { |
| 1881 mHomeButton.setTint(mUseLightToolbarDrawables ? white : dark); | 1883 mHomeButton.setTint(mUseLightToolbarDrawables ? mLightModeTint : mDa rkModeTint); |
| 1882 } | 1884 } |
| 1883 | 1885 |
| 1884 mPhoneLocationBar.updateVisualsForState(); | 1886 mPhoneLocationBar.updateVisualsForState(); |
| 1885 // Remove the side padding for incognito to ensure the badge icon aligns correctly with the | 1887 // Remove the side padding for incognito to ensure the badge icon aligns correctly with the |
| 1886 // background of the location bar. | 1888 // background of the location bar. |
| 1887 if (isIncognito) { | 1889 if (isIncognito) { |
| 1888 mPhoneLocationBar.setPadding( | 1890 mPhoneLocationBar.setPadding( |
| 1889 0, mUrlBackgroundPadding.top, 0, mUrlBackgroundPadding.botto m); | 1891 0, mUrlBackgroundPadding.top, 0, mUrlBackgroundPadding.botto m); |
| 1890 } else { | 1892 } else { |
| 1891 mPhoneLocationBar.setPadding( | 1893 mPhoneLocationBar.setPadding( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1912 | 1914 |
| 1913 getMenuButton().setVisibility(shouldShowMenuButton() ? View.VISIBLE : Vi ew.GONE); | 1915 getMenuButton().setVisibility(shouldShowMenuButton() ? View.VISIBLE : Vi ew.GONE); |
| 1914 } | 1916 } |
| 1915 | 1917 |
| 1916 @Override | 1918 @Override |
| 1917 public LocationBar getLocationBar() { | 1919 public LocationBar getLocationBar() { |
| 1918 return mPhoneLocationBar; | 1920 return mPhoneLocationBar; |
| 1919 } | 1921 } |
| 1920 } | 1922 } |
| 1921 | 1923 |
| OLD | NEW |