| 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.ValueAnimator; | 9 import android.animation.ValueAnimator; |
| 10 import android.animation.ValueAnimator.AnimatorUpdateListener; | 10 import android.animation.ValueAnimator.AnimatorUpdateListener; |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 super.onNavigatedToDifferentPage(); | 335 super.onNavigatedToDifferentPage(); |
| 336 setTitleToPageTitle(); | 336 setTitleToPageTitle(); |
| 337 if (mState == STATE_TITLE_ONLY) { | 337 if (mState == STATE_TITLE_ONLY) { |
| 338 if (TextUtils.isEmpty(mFirstUrl)) { | 338 if (TextUtils.isEmpty(mFirstUrl)) { |
| 339 mFirstUrl = getToolbarDataProvider().getTab().getUrl(); | 339 mFirstUrl = getToolbarDataProvider().getTab().getUrl(); |
| 340 } else { | 340 } else { |
| 341 if (mFirstUrl.equals(getToolbarDataProvider().getTab().getUrl())
) return; | 341 if (mFirstUrl.equals(getToolbarDataProvider().getTab().getUrl())
) return; |
| 342 setUrlBarHidden(false); | 342 setUrlBarHidden(false); |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 showOfflineBoltIfNecessary(); | 345 updateSecurityIcon(getSecurityLevel()); |
| 346 } | 346 } |
| 347 | 347 |
| 348 @Override | 348 @Override |
| 349 public void setUrlToPageUrl() { | 349 public void setUrlToPageUrl() { |
| 350 if (getCurrentTab() == null) { | 350 if (getCurrentTab() == null) { |
| 351 mUrlBar.setUrl("", null); | 351 mUrlBar.setUrl("", null); |
| 352 return; | 352 return; |
| 353 } | 353 } |
| 354 | 354 |
| 355 String url = getCurrentTab().getUrl().trim(); | 355 String url = getCurrentTab().getUrl().trim(); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 if (getCurrentTab() == null) return ConnectionSecurityLevel.NONE; | 490 if (getCurrentTab() == null) return ConnectionSecurityLevel.NONE; |
| 491 return getCurrentTab().getSecurityLevel(); | 491 return getCurrentTab().getSecurityLevel(); |
| 492 } | 492 } |
| 493 | 493 |
| 494 @Override | 494 @Override |
| 495 public void updateSecurityIcon(int securityLevel) { | 495 public void updateSecurityIcon(int securityLevel) { |
| 496 if (mState == STATE_TITLE_ONLY) return; | 496 if (mState == STATE_TITLE_ONLY) return; |
| 497 | 497 |
| 498 mSecurityIconType = securityLevel; | 498 mSecurityIconType = securityLevel; |
| 499 | 499 |
| 500 boolean isOfflinePage = getCurrentTab() != null && getCurrentTab().isOff
linePage(); |
| 501 boolean showSecurityButton = securityLevel != ConnectionSecurityLevel.NO
NE || isOfflinePage; |
| 502 |
| 500 if (securityLevel == ConnectionSecurityLevel.NONE) { | 503 if (securityLevel == ConnectionSecurityLevel.NONE) { |
| 501 mAnimDelegate.hideSecurityButton(); | 504 if (isOfflinePage && mShowsOfflinePage != isOfflinePage) { |
| 505 TintedDrawable bolt = TintedDrawable.constructTintedDrawable( |
| 506 getResources(), R.drawable.offline_pin); |
| 507 bolt.setTint(mUseDarkColors ? mDarkModeTint : mLightModeTint); |
| 508 mSecurityButton.setImageDrawable(bolt); |
| 509 } |
| 502 } else { | 510 } else { |
| 503 boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext()); | 511 boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext()); |
| 504 int id = LocationBarLayout.getSecurityIconResource(securityLevel, is
SmallDevice); | 512 int id = LocationBarLayout.getSecurityIconResource(securityLevel, is
SmallDevice); |
| 505 if (id == 0) { | 513 if (id == 0) { |
| 506 mSecurityButton.setImageDrawable(null); | 514 // Hide the button if we don't have an actual icon to display. |
| 515 showSecurityButton = false; |
| 507 } else { | 516 } else { |
| 508 // ImageView#setImageResource is no-op if given resource is the
current one. | 517 // ImageView#setImageResource is no-op if given resource is the
current one. |
| 509 mSecurityButton.setImageResource(id); | 518 mSecurityButton.setImageResource(id); |
| 510 mSecurityButton.setTint( | 519 mSecurityButton.setTint( |
| 511 LocationBarLayout.getColorStateList(securityLevel, getTo
olbarDataProvider(), | 520 LocationBarLayout.getColorStateList(securityLevel, getTo
olbarDataProvider(), |
| 512 getResources(), false /* omnibox is not opaque *
/)); | 521 getResources(), false /* omnibox is not opaque *
/)); |
| 513 } | 522 } |
| 523 } |
| 524 |
| 525 mShowsOfflinePage = isOfflinePage; |
| 526 |
| 527 if (showSecurityButton) { |
| 514 mAnimDelegate.showSecurityButton(); | 528 mAnimDelegate.showSecurityButton(); |
| 529 } else { |
| 530 mAnimDelegate.hideSecurityButton(); |
| 515 } | 531 } |
| 532 |
| 516 mUrlBar.emphasizeUrl(); | 533 mUrlBar.emphasizeUrl(); |
| 517 mUrlBar.invalidate(); | 534 mUrlBar.invalidate(); |
| 518 } | 535 } |
| 519 | 536 |
| 520 private void showOfflineBoltIfNecessary() { | |
| 521 boolean isOfflinePage = getCurrentTab() != null && getCurrentTab().isOff
linePage(); | |
| 522 if (isOfflinePage == mShowsOfflinePage) return; | |
| 523 | |
| 524 mShowsOfflinePage = isOfflinePage; | |
| 525 if (mShowsOfflinePage) { | |
| 526 // If we are showing an offline page, immediately update icon to off
line bolt. | |
| 527 TintedDrawable bolt = TintedDrawable.constructTintedDrawable( | |
| 528 getResources(), R.drawable.offline_pin); | |
| 529 bolt.setTint(mUseDarkColors ? mDarkModeTint : mLightModeTint); | |
| 530 mSecurityButton.setImageDrawable(bolt); | |
| 531 mAnimDelegate.showSecurityButton(); | |
| 532 } else { | |
| 533 // We are hiding the offline page so connection security information
will change. | |
| 534 mSecurityIconType = ConnectionSecurityLevel.NONE; | |
| 535 mAnimDelegate.hideSecurityButton(); | |
| 536 } | |
| 537 } | |
| 538 | |
| 539 /** | 537 /** |
| 540 * For extending classes to override and carry out the changes related with
the primary color | 538 * For extending classes to override and carry out the changes related with
the primary color |
| 541 * for the current tab changing. | 539 * for the current tab changing. |
| 542 */ | 540 */ |
| 543 @Override | 541 @Override |
| 544 protected void onPrimaryColorChanged(boolean shouldAnimate) { | 542 protected void onPrimaryColorChanged(boolean shouldAnimate) { |
| 545 if (mBrandColorTransitionActive) mBrandColorTransitionAnimation.cancel()
; | 543 if (mBrandColorTransitionActive) mBrandColorTransitionAnimation.cancel()
; |
| 546 | 544 |
| 547 final ColorDrawable background = getBackground(); | 545 final ColorDrawable background = getBackground(); |
| 548 final int initialColor = background.getColor(); | 546 final int initialColor = background.getColor(); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 | 762 |
| 765 @Override | 763 @Override |
| 766 protected void setAppMenuUpdateBadgeToVisible(boolean animate) {} | 764 protected void setAppMenuUpdateBadgeToVisible(boolean animate) {} |
| 767 | 765 |
| 768 @Override | 766 @Override |
| 769 public View getMenuButtonWrapper() { | 767 public View getMenuButtonWrapper() { |
| 770 // This class has no menu button wrapper, so return the menu button inst
ead. | 768 // This class has no menu button wrapper, so return the menu button inst
ead. |
| 771 return mMenuButton; | 769 return mMenuButton; |
| 772 } | 770 } |
| 773 } | 771 } |
| OLD | NEW |