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.content.Context; | 10 import android.content.Context; |
| 11 import android.content.res.ColorStateList; | 11 import android.content.res.ColorStateList; |
| 12 import android.graphics.Bitmap; | 12 import android.graphics.Bitmap; |
| 13 import android.graphics.Canvas; | 13 import android.graphics.Canvas; |
| 14 import android.graphics.Rect; | 14 import android.graphics.Rect; |
| 15 import android.graphics.drawable.Drawable; | 15 import android.graphics.drawable.Drawable; |
| 16 import android.os.SystemClock; | 16 import android.os.SystemClock; |
| 17 import android.util.AttributeSet; | 17 import android.util.AttributeSet; |
| 18 import android.view.Gravity; | 18 import android.view.Gravity; |
| 19 import android.view.View; | 19 import android.view.View; |
| 20 import android.view.ViewGroup; | 20 import android.view.ViewGroup; |
| 21 import android.widget.FrameLayout; | 21 import android.widget.FrameLayout; |
| 22 import android.widget.ImageView; | 22 import android.widget.ImageView; |
| 23 import android.widget.ProgressBar; | 23 import android.widget.ProgressBar; |
| 24 | 24 |
| 25 import org.chromium.base.ApiCompatibilityUtils; | 25 import org.chromium.base.ApiCompatibilityUtils; |
| 26 import org.chromium.base.VisibleForTesting; | 26 import org.chromium.base.VisibleForTesting; |
| 27 import org.chromium.chrome.R; | 27 import org.chromium.chrome.R; |
| 28 import org.chromium.chrome.browser.appmenu.AppMenuButtonHelper; | 28 import org.chromium.chrome.browser.appmenu.AppMenuButtonHelper; |
| 29 import org.chromium.chrome.browser.appmenu.PulseDrawable; | |
| 30 import org.chromium.chrome.browser.appmenu.PulseDrawableFactory; | |
| 29 import org.chromium.chrome.browser.compositor.Invalidator; | 31 import org.chromium.chrome.browser.compositor.Invalidator; |
| 30 import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost; | 32 import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost; |
| 31 import org.chromium.chrome.browser.fullscreen.BrowserStateBrowserControlsVisibil ityDelegate; | 33 import org.chromium.chrome.browser.fullscreen.BrowserStateBrowserControlsVisibil ityDelegate; |
| 32 import org.chromium.chrome.browser.ntp.NewTabPage; | 34 import org.chromium.chrome.browser.ntp.NewTabPage; |
| 33 import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper; | 35 import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper; |
| 34 import org.chromium.chrome.browser.omnibox.LocationBar; | 36 import org.chromium.chrome.browser.omnibox.LocationBar; |
| 35 import org.chromium.chrome.browser.tab.Tab; | 37 import org.chromium.chrome.browser.tab.Tab; |
| 36 import org.chromium.chrome.browser.util.ViewUtils; | 38 import org.chromium.chrome.browser.util.ViewUtils; |
| 37 import org.chromium.chrome.browser.widget.TintedImageButton; | 39 import org.chromium.chrome.browser.widget.TintedImageButton; |
| 38 import org.chromium.chrome.browser.widget.ToolbarProgressBar; | 40 import org.chromium.chrome.browser.widget.ToolbarProgressBar; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 @Nullable | 72 @Nullable |
| 71 protected ToolbarProgressBar mProgressBar; | 73 protected ToolbarProgressBar mProgressBar; |
| 72 | 74 |
| 73 private boolean mNativeLibraryReady; | 75 private boolean mNativeLibraryReady; |
| 74 private boolean mUrlHasFocus; | 76 private boolean mUrlHasFocus; |
| 75 | 77 |
| 76 private long mFirstDrawTimeMs; | 78 private long mFirstDrawTimeMs; |
| 77 | 79 |
| 78 private boolean mFindInPageToolbarShowing; | 80 private boolean mFindInPageToolbarShowing; |
| 79 | 81 |
| 82 protected boolean mHighlightingMenu; | |
| 83 private PulseDrawable mHighlightDrawable; | |
| 84 | |
| 80 protected boolean mShowMenuBadge; | 85 protected boolean mShowMenuBadge; |
| 81 private AnimatorSet mMenuBadgeAnimatorSet; | 86 private AnimatorSet mMenuBadgeAnimatorSet; |
| 82 private boolean mIsMenuBadgeAnimationRunning; | 87 private boolean mIsMenuBadgeAnimationRunning; |
| 83 | 88 |
| 84 /** | 89 /** |
| 85 * Basic constructor for {@link ToolbarLayout}. | 90 * Basic constructor for {@link ToolbarLayout}. |
| 86 */ | 91 */ |
| 87 public ToolbarLayout(Context context, AttributeSet attrs) { | 92 public ToolbarLayout(Context context, AttributeSet attrs) { |
| 88 super(context, attrs); | 93 super(context, attrs); |
| 89 mDarkModeTint = | 94 mDarkModeTint = |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 */ | 651 */ |
| 647 protected boolean isIncognito() { | 652 protected boolean isIncognito() { |
| 648 return mToolbarDataProvider.isIncognito(); | 653 return mToolbarDataProvider.isIncognito(); |
| 649 } | 654 } |
| 650 | 655 |
| 651 /** | 656 /** |
| 652 * @return {@link LocationBar} object this {@link ToolbarLayout} contains. | 657 * @return {@link LocationBar} object this {@link ToolbarLayout} contains. |
| 653 */ | 658 */ |
| 654 public abstract LocationBar getLocationBar(); | 659 public abstract LocationBar getLocationBar(); |
| 655 | 660 |
| 661 public abstract boolean useLightDrawables(); | |
|
Ted C
2017/04/12 18:05:57
javadoc
David Trainor- moved to gerrit
2017/04/12 18:59:37
Done.
| |
| 662 | |
| 656 /** | 663 /** |
| 657 * Navigates the current Tab back. | 664 * Navigates the current Tab back. |
| 658 * @return Whether or not the current Tab did go back. | 665 * @return Whether or not the current Tab did go back. |
| 659 */ | 666 */ |
| 660 protected boolean back() { | 667 protected boolean back() { |
| 661 getLocationBar().hideSuggestions(); | 668 getLocationBar().hideSuggestions(); |
| 662 return mToolbarTabController != null ? mToolbarTabController.back() : fa lse; | 669 return mToolbarTabController != null ? mToolbarTabController.back() : fa lse; |
| 663 } | 670 } |
| 664 | 671 |
| 665 /** | 672 /** |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 684 | 691 |
| 685 /** | 692 /** |
| 686 * Opens hompage in the current tab. | 693 * Opens hompage in the current tab. |
| 687 */ | 694 */ |
| 688 protected void openHomepage() { | 695 protected void openHomepage() { |
| 689 getLocationBar().hideSuggestions(); | 696 getLocationBar().hideSuggestions(); |
| 690 if (mToolbarTabController != null) mToolbarTabController.openHomepage(); | 697 if (mToolbarTabController != null) mToolbarTabController.openHomepage(); |
| 691 } | 698 } |
| 692 | 699 |
| 693 @Override | 700 @Override |
| 701 public void setMenuButtonHighlight(boolean highlight) { | |
| 702 mHighlightingMenu = highlight; | |
| 703 setMenuButtonHighlightDrawable(mHighlightingMenu); | |
| 704 } | |
| 705 | |
| 706 @Override | |
| 694 public void showAppMenuUpdateBadge() { | 707 public void showAppMenuUpdateBadge() { |
| 695 mShowMenuBadge = true; | 708 mShowMenuBadge = true; |
| 696 } | 709 } |
| 697 | 710 |
| 698 @Override | 711 @Override |
| 699 public boolean isShowingAppMenuUpdateBadge() { | 712 public boolean isShowingAppMenuUpdateBadge() { |
| 700 return mShowMenuBadge; | 713 return mShowMenuBadge; |
| 701 } | 714 } |
| 702 | 715 |
| 703 @Override | 716 @Override |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 /** | 801 /** |
| 789 * Sets the update menu badge drawable to the light or dark asset. | 802 * Sets the update menu badge drawable to the light or dark asset. |
| 790 * @param useLightDrawable Whether the light drawable should be used. | 803 * @param useLightDrawable Whether the light drawable should be used. |
| 791 */ | 804 */ |
| 792 protected void setAppMenuUpdateBadgeDrawable(boolean useLightDrawable) { | 805 protected void setAppMenuUpdateBadgeDrawable(boolean useLightDrawable) { |
| 793 mMenuBadge.setImageResource(useLightDrawable ? R.drawable.badge_update_l ight | 806 mMenuBadge.setImageResource(useLightDrawable ? R.drawable.badge_update_l ight |
| 794 : R.drawable.badge_update_dark); | 807 : R.drawable.badge_update_dark); |
| 795 } | 808 } |
| 796 | 809 |
| 797 /** | 810 /** |
| 811 * Sets the menu button's background depending on whether or not we are high lighting and whether | |
| 812 * or not we are using light or dark assets. | |
| 813 * @param highlighting Whether or not the menu button should be highligh ted. | |
|
Ted C
2017/04/12 18:05:57
too much space after highlighting
David Trainor- moved to gerrit
2017/04/12 18:59:37
Done.
| |
| 814 */ | |
| 815 protected void setMenuButtonHighlightDrawable(boolean highlighting) { | |
| 816 if (highlighting) { | |
| 817 if (mHighlightDrawable == null) { | |
| 818 mHighlightDrawable = PulseDrawableFactory.createCircle(); | |
| 819 mHighlightDrawable.setInset(ApiCompatibilityUtils.getPaddingStar t(mMenuButton), | |
| 820 mMenuButton.getPaddingTop(), | |
| 821 ApiCompatibilityUtils.getPaddingEnd(mMenuButton), | |
| 822 mMenuButton.getPaddingBottom()); | |
| 823 } | |
| 824 int colorRes = useLightDrawables() ? R.color.google_grey_100 : R.col or.google_blue_500; | |
| 825 int color = ApiCompatibilityUtils.getColor(getResources(), colorRes) ; | |
| 826 mHighlightDrawable.setColor(color); | |
|
Ted C
2017/04/12 18:05:57
ah...so we already use different colors. Can we j
David Trainor- moved to gerrit
2017/04/12 18:59:37
Yeah good idea
| |
| 827 mMenuButtonWrapper.setBackground(mHighlightDrawable); | |
| 828 mHighlightDrawable.start(); | |
| 829 } else { | |
| 830 mMenuButtonWrapper.setBackground(null); | |
| 831 } | |
| 832 } | |
| 833 | |
| 834 /** | |
| 798 * Sets the content description for the menu button. | 835 * Sets the content description for the menu button. |
| 799 * @param isUpdateBadgeVisible Whether the update menu badge is visible. | 836 * @param isUpdateBadgeVisible Whether the update menu badge is visible. |
| 800 */ | 837 */ |
| 801 protected void setMenuButtonContentDescription(boolean isUpdateBadgeVisible) { | 838 protected void setMenuButtonContentDescription(boolean isUpdateBadgeVisible) { |
| 802 if (isUpdateBadgeVisible) { | 839 if (isUpdateBadgeVisible) { |
| 803 mMenuButton.setContentDescription(getResources().getString( | 840 mMenuButton.setContentDescription(getResources().getString( |
| 804 R.string.accessibility_toolbar_btn_menu_update)); | 841 R.string.accessibility_toolbar_btn_menu_update)); |
| 805 } else { | 842 } else { |
| 806 mMenuButton.setContentDescription(getResources().getString( | 843 mMenuButton.setContentDescription(getResources().getString( |
| 807 R.string.accessibility_toolbar_btn_menu)); | 844 R.string.accessibility_toolbar_btn_menu)); |
| 808 } | 845 } |
| 809 } | 846 } |
| 810 | 847 |
| 811 @Override | 848 @Override |
| 812 public void setBottomSheet(BottomSheet sheet) {} | 849 public void setBottomSheet(BottomSheet sheet) {} |
| 813 } | 850 } |
| OLD | NEW |