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; |
| 9 import android.animation.AnimatorSet; |
8 import android.animation.ObjectAnimator; | 10 import android.animation.ObjectAnimator; |
9 import android.annotation.SuppressLint; | 11 import android.annotation.SuppressLint; |
10 import android.content.Context; | 12 import android.content.Context; |
11 import android.content.res.ColorStateList; | 13 import android.content.res.ColorStateList; |
12 import android.content.res.Configuration; | 14 import android.content.res.Configuration; |
13 import android.content.res.Resources; | 15 import android.content.res.Resources; |
14 import android.graphics.Bitmap; | 16 import android.graphics.Bitmap; |
15 import android.graphics.drawable.BitmapDrawable; | 17 import android.graphics.drawable.BitmapDrawable; |
16 import android.graphics.drawable.ColorDrawable; | 18 import android.graphics.drawable.ColorDrawable; |
17 import android.text.TextUtils; | 19 import android.text.TextUtils; |
(...skipping 26 matching lines...) Expand all Loading... |
44 import org.chromium.chrome.browser.omnibox.LocationBarLayout; | 46 import org.chromium.chrome.browser.omnibox.LocationBarLayout; |
45 import org.chromium.chrome.browser.omnibox.UrlBar; | 47 import org.chromium.chrome.browser.omnibox.UrlBar; |
46 import org.chromium.chrome.browser.omnibox.UrlFocusChangeListener; | 48 import org.chromium.chrome.browser.omnibox.UrlFocusChangeListener; |
47 import org.chromium.chrome.browser.profiles.Profile; | 49 import org.chromium.chrome.browser.profiles.Profile; |
48 import org.chromium.chrome.browser.ssl.ConnectionSecurityLevel; | 50 import org.chromium.chrome.browser.ssl.ConnectionSecurityLevel; |
49 import org.chromium.chrome.browser.tab.ChromeTab; | 51 import org.chromium.chrome.browser.tab.ChromeTab; |
50 import org.chromium.chrome.browser.widget.TintedImageButton; | 52 import org.chromium.chrome.browser.widget.TintedImageButton; |
51 import org.chromium.components.dom_distiller.core.DomDistillerService; | 53 import org.chromium.components.dom_distiller.core.DomDistillerService; |
52 import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils; | 54 import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils; |
53 import org.chromium.ui.base.WindowAndroid; | 55 import org.chromium.ui.base.WindowAndroid; |
| 56 import org.chromium.ui.interpolators.BakedBezierInterpolator; |
54 | 57 |
55 /** | 58 /** |
56 * The Toolbar layout to be used for a custom tab. This is used for both phone a
nd tablet UIs. | 59 * The Toolbar layout to be used for a custom tab. This is used for both phone a
nd tablet UIs. |
57 */ | 60 */ |
58 public class CustomTabToolbar extends ToolbarLayout implements LocationBar { | 61 public class CustomTabToolbar extends ToolbarLayout implements LocationBar { |
| 62 private static final int CUSTOM_TAB_TOOLBAR_SLIDE_DURATION_MS = 200; |
| 63 private static final int CUSTOM_TAB_TOOLBAR_FADE_DURATION_MS = 150; |
59 private View mUrlInfoContainer; | 64 private View mUrlInfoContainer; |
60 private UrlBar mUrlBar; | 65 private UrlBar mUrlBar; |
61 private TextView mTitleBar; | 66 private TextView mTitleBar; |
62 private ImageView mSecurityButton; | 67 private ImageView mSecurityButton; |
63 private ImageButton mCustomActionButton; | 68 private ImageButton mCustomActionButton; |
64 private int mSecurityIconType; | 69 private int mSecurityIconType; |
65 private boolean mUseDarkColors; | 70 private boolean mUseDarkColors; |
66 private TintedImageButton mCloseButton; | 71 private TintedImageButton mCloseButton; |
67 private Animator mSecurityButtonShowAnimator; | 72 |
| 73 private AnimatorSet mSecurityButtonShowAnimator; |
68 private boolean mBackgroundColorSet; | 74 private boolean mBackgroundColorSet; |
69 | 75 |
70 /** | 76 /** |
71 * Constructor for getting this class inflated from an xml layout file. | 77 * Constructor for getting this class inflated from an xml layout file. |
72 */ | 78 */ |
73 public CustomTabToolbar(Context context, AttributeSet attrs) { | 79 public CustomTabToolbar(Context context, AttributeSet attrs) { |
74 super(context, attrs); | 80 super(context, attrs); |
75 } | 81 } |
76 | 82 |
77 @Override | 83 @Override |
78 protected void onFinishInflate() { | 84 protected void onFinishInflate() { |
79 super.onFinishInflate(); | 85 super.onFinishInflate(); |
80 setBackground(new ColorDrawable(getResources().getColor(R.color.default_
primary_color))); | 86 setBackground(new ColorDrawable(getResources().getColor(R.color.default_
primary_color))); |
81 mUrlBar = (UrlBar) findViewById(R.id.url_bar); | 87 mUrlBar = (UrlBar) findViewById(R.id.url_bar); |
82 mUrlBar.setHint(""); | 88 mUrlBar.setHint(""); |
83 mUrlBar.setDelegate(this); | 89 mUrlBar.setDelegate(this); |
84 mUrlBar.setEnabled(false); | 90 mUrlBar.setEnabled(false); |
85 mUrlBar.setAllowFocus(false); | 91 mUrlBar.setAllowFocus(false); |
86 mTitleBar = (TextView) findViewById(R.id.title_bar); | 92 mTitleBar = (TextView) findViewById(R.id.title_bar); |
87 mUrlInfoContainer = findViewById(R.id.url_info_container); | 93 mUrlInfoContainer = findViewById(R.id.url_info_container); |
88 mSecurityButton = (ImageButton) findViewById(R.id.security_button); | 94 mSecurityButton = (ImageButton) findViewById(R.id.security_button); |
89 mSecurityIconType = ConnectionSecurityLevel.NONE; | 95 mSecurityIconType = ConnectionSecurityLevel.NONE; |
90 mCustomActionButton = (ImageButton) findViewById(R.id.action_button); | 96 mCustomActionButton = (ImageButton) findViewById(R.id.action_button); |
91 mCloseButton = (TintedImageButton) findViewById(R.id.close_button); | 97 mCloseButton = (TintedImageButton) findViewById(R.id.close_button); |
92 mSecurityButtonShowAnimator = ObjectAnimator.ofFloat(mSecurityButton, AL
PHA, 1); | 98 populateToolbarAnimations(); |
93 mSecurityButtonShowAnimator | 99 } |
94 .setDuration(ToolbarPhone.URL_FOCUS_CHANGE_ANIMATION_DURATION_MS
); | 100 |
| 101 private void populateToolbarAnimations() { |
| 102 mSecurityButtonShowAnimator = new AnimatorSet(); |
| 103 int securityIconButtonWidth = |
| 104 getResources().getDimensionPixelSize(R.dimen.location_bar_icon_w
idth); |
| 105 Animator urlInfoContainerTranslateAnimator = |
| 106 ObjectAnimator.ofFloat(mUrlInfoContainer, TRANSLATION_X, securit
yIconButtonWidth); |
| 107 urlInfoContainerTranslateAnimator.setInterpolator(BakedBezierInterpolato
r.TRANSFORM_CURVE); |
| 108 urlInfoContainerTranslateAnimator.setDuration(CUSTOM_TAB_TOOLBAR_SLIDE_D
URATION_MS); |
| 109 |
| 110 Animator securityButtonAlphaAnimator = ObjectAnimator.ofFloat(mSecurityB
utton, ALPHA, 1); |
| 111 securityButtonAlphaAnimator.setInterpolator(BakedBezierInterpolator.FADE
_IN_CURVE); |
| 112 securityButtonAlphaAnimator.setDuration(CUSTOM_TAB_TOOLBAR_FADE_DURATION
_MS); |
| 113 securityButtonAlphaAnimator.addListener(new AnimatorListenerAdapter() { |
| 114 @Override |
| 115 public void onAnimationStart(Animator animation) { |
| 116 mSecurityButton.setVisibility(VISIBLE); |
| 117 mUrlInfoContainer.setTranslationX(0); |
| 118 } |
| 119 }); |
| 120 |
| 121 mSecurityButtonShowAnimator.playSequentially( |
| 122 urlInfoContainerTranslateAnimator, securityButtonAlphaAnimator); |
95 } | 123 } |
96 | 124 |
97 @Override | 125 @Override |
98 protected int getToolbarHeightWithoutShadowResId() { | 126 protected int getToolbarHeightWithoutShadowResId() { |
99 return R.dimen.custom_tabs_control_container_height; | 127 return R.dimen.custom_tabs_control_container_height; |
100 } | 128 } |
101 | 129 |
102 @Override | 130 @Override |
103 public void initialize(ToolbarDataProvider toolbarDataProvider, | 131 public void initialize(ToolbarDataProvider toolbarDataProvider, |
104 ToolbarTabController tabController, AppMenuButtonHelper appMenuButto
nHelper) { | 132 ToolbarTabController tabController, AppMenuButtonHelper appMenuButto
nHelper) { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 securityLevel, !shouldEmphasizeHttpsScheme())); | 365 securityLevel, !shouldEmphasizeHttpsScheme())); |
338 | 366 |
339 if (mSecurityIconType == securityLevel) return; | 367 if (mSecurityIconType == securityLevel) return; |
340 mSecurityIconType = securityLevel; | 368 mSecurityIconType = securityLevel; |
341 | 369 |
342 if (securityLevel == ConnectionSecurityLevel.NONE) { | 370 if (securityLevel == ConnectionSecurityLevel.NONE) { |
343 // TODO(yusufo): Add an animator for hiding as well. | 371 // TODO(yusufo): Add an animator for hiding as well. |
344 mSecurityButton.setVisibility(GONE); | 372 mSecurityButton.setVisibility(GONE); |
345 } else { | 373 } else { |
346 if (mSecurityButtonShowAnimator.isRunning()) mSecurityButtonShowAnim
ator.cancel(); | 374 if (mSecurityButtonShowAnimator.isRunning()) mSecurityButtonShowAnim
ator.cancel(); |
347 mSecurityButton.setVisibility(VISIBLE); | |
348 mSecurityButtonShowAnimator.start(); | 375 mSecurityButtonShowAnimator.start(); |
349 mUrlBar.deEmphasizeUrl(); | 376 mUrlBar.deEmphasizeUrl(); |
350 } | 377 } |
351 mUrlBar.emphasizeUrl(); | 378 mUrlBar.emphasizeUrl(); |
352 mUrlBar.invalidate(); | 379 mUrlBar.invalidate(); |
353 } | 380 } |
354 | 381 |
355 /** | 382 /** |
356 * For extending classes to override and carry out the changes related with
the primary color | 383 * For extending classes to override and carry out the changes related with
the primary color |
357 * for the current tab changing. | 384 * for the current tab changing. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 public void onTabLoadingNTP(NewTabPage ntp) { | 529 public void onTabLoadingNTP(NewTabPage ntp) { |
503 } | 530 } |
504 | 531 |
505 @Override | 532 @Override |
506 public void setAutocompleteProfile(Profile profile) { | 533 public void setAutocompleteProfile(Profile profile) { |
507 } | 534 } |
508 | 535 |
509 @Override | 536 @Override |
510 public void backKeyPressed() { } | 537 public void backKeyPressed() { } |
511 } | 538 } |
OLD | NEW |