Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java

Issue 1694673002: Replace update menu badge (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes from second self-review Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.omnibox; 5 package org.chromium.chrome.browser.omnibox;
6 6
7 import android.animation.Animator;
8 import android.animation.AnimatorListenerAdapter;
9 import android.animation.AnimatorSet;
7 import android.animation.ObjectAnimator; 10 import android.animation.ObjectAnimator;
8 import android.annotation.SuppressLint; 11 import android.annotation.SuppressLint;
9 import android.content.Context; 12 import android.content.Context;
10 import android.content.res.ColorStateList; 13 import android.content.res.ColorStateList;
11 import android.graphics.Canvas; 14 import android.graphics.Canvas;
12 import android.graphics.Rect; 15 import android.graphics.Rect;
13 import android.text.Selection; 16 import android.text.Selection;
14 import android.text.TextUtils; 17 import android.text.TextUtils;
15 import android.util.AttributeSet; 18 import android.util.AttributeSet;
16 import android.view.KeyEvent; 19 import android.view.KeyEvent;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 private TintedImageButton mMenuButton; 51 private TintedImageButton mMenuButton;
49 private ImageView mMenuBadge; 52 private ImageView mMenuBadge;
50 private View mMenuButtonWrapper; 53 private View mMenuButtonWrapper;
51 private int mIncognitoBadgePadding; 54 private int mIncognitoBadgePadding;
52 private boolean mVoiceSearchEnabled; 55 private boolean mVoiceSearchEnabled;
53 private boolean mUrlFocusChangeInProgress; 56 private boolean mUrlFocusChangeInProgress;
54 private float mUrlFocusChangePercent; 57 private float mUrlFocusChangePercent;
55 private Runnable mKeyboardResizeModeTask; 58 private Runnable mKeyboardResizeModeTask;
56 private ObjectAnimator mOmniboxBackgroundAnimator; 59 private ObjectAnimator mOmniboxBackgroundAnimator;
57 60
61 private boolean mShowMenuBadge;
62 private AnimatorSet mMenuBadgeAnimatorSet;
63 private boolean mIsMenuBadgeAnimationRunning;
64
58 /** 65 /**
59 * Constructor used to inflate from XML. 66 * Constructor used to inflate from XML.
60 */ 67 */
61 public LocationBarPhone(Context context, AttributeSet attrs) { 68 public LocationBarPhone(Context context, AttributeSet attrs) {
62 super(context, attrs); 69 super(context, attrs);
63 } 70 }
64 71
65 @Override 72 @Override
66 protected void onFinishInflate() { 73 protected void onFinishInflate() {
67 super.onFinishInflate(); 74 super.onFinishInflate();
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 @Override 350 @Override
344 public void updateVisualsForState() { 351 public void updateVisualsForState() {
345 super.updateVisualsForState(); 352 super.updateVisualsForState();
346 353
347 Tab tab = getCurrentTab(); 354 Tab tab = getCurrentTab();
348 boolean isIncognito = tab != null && tab.isIncognito(); 355 boolean isIncognito = tab != null && tab.isIncognito();
349 mIncognitoBadge.setVisibility(isIncognito ? VISIBLE : GONE); 356 mIncognitoBadge.setVisibility(isIncognito ? VISIBLE : GONE);
350 updateIncognitoBadgePadding(); 357 updateIncognitoBadgePadding();
351 358
352 if (showMenuButtonInOmnibox()) { 359 if (showMenuButtonInOmnibox()) {
353 boolean useLightDrawables = isIncognito; 360 boolean useLightDrawables = shouldUseLightDrawables();
354 if (getToolbarDataProvider().isUsingBrandColor()) {
355 int currentPrimaryColor = getToolbarDataProvider().getPrimaryCol or();
356 useLightDrawables |=
357 ColorUtils.shoudUseLightForegroundOnBackground(currentPr imaryColor);
358 }
359 ColorStateList dark = ApiCompatibilityUtils.getColorStateList(getRes ources(), 361 ColorStateList dark = ApiCompatibilityUtils.getColorStateList(getRes ources(),
360 R.color.dark_mode_tint); 362 R.color.dark_mode_tint);
361 ColorStateList white = ApiCompatibilityUtils.getColorStateList(getRe sources(), 363 ColorStateList white = ApiCompatibilityUtils.getColorStateList(getRe sources(),
362 R.color.light_mode_tint); 364 R.color.light_mode_tint);
363 mMenuButton.setTint(useLightDrawables ? white : dark); 365 mMenuButton.setTint(useLightDrawables ? white : dark);
366
367 if (mShowMenuBadge) {
368 mMenuBadge.setImageResource(useLightDrawables ? R.drawable.badge _update_light
369 : R.drawable.badge_update_dark);
370 }
364 } 371 }
365 } 372 }
366 373
367 @Override 374 @Override
368 protected boolean shouldAnimateIconChanges() { 375 protected boolean shouldAnimateIconChanges() {
369 return super.shouldAnimateIconChanges() || mUrlFocusChangeInProgress; 376 return super.shouldAnimateIconChanges() || mUrlFocusChangeInProgress;
370 } 377 }
371 378
372 @Override 379 @Override
373 public void setLayoutDirection(int layoutDirection) { 380 public void setLayoutDirection(int layoutDirection) {
374 super.setLayoutDirection(layoutDirection); 381 super.setLayoutDirection(layoutDirection);
375 updateIncognitoBadgePadding(); 382 updateIncognitoBadgePadding();
376 } 383 }
377 384
378 /** 385 /**
379 * Displays the update app menu badge. 386 * Displays the update app menu badge.
380 */ 387 */
381 public void showAppMenuUpdateBadge() { 388 public void showAppMenuUpdateBadge(boolean animate) {
389 if (!showMenuButtonInOmnibox()) return;
390
391 mShowMenuBadge = true;
392 if (shouldUseLightDrawables()) {
393 mMenuBadge.setImageResource(R.drawable.badge_update_light);
gone 2016/02/13 00:26:15 Maybe this should mimic what's above, where it use
Theresa 2016/02/16 18:21:53 Done.
394 }
395
396 if (!animate || mIsMenuBadgeAnimationRunning) {
397 mMenuBadge.setVisibility(View.VISIBLE);
398 return;
399 }
400
401 // Set initial states.
402 mMenuBadge.setAlpha(0.f);
382 mMenuBadge.setVisibility(View.VISIBLE); 403 mMenuBadge.setVisibility(View.VISIBLE);
383 mMenuButton.setImageBitmap( 404
384 UpdateMenuItemHelper.getInstance().getBadgedMenuButtonBitmap(get Context())); 405 mMenuBadgeAnimatorSet = UpdateMenuItemHelper.createShowUpdateBadgeAnimat ion(
406 mMenuButton, mMenuBadge);
407
408 mMenuBadgeAnimatorSet.addListener(new AnimatorListenerAdapter() {
409 @Override
410 public void onAnimationStart(Animator animation) {
411 mIsMenuBadgeAnimationRunning = true;
412 }
413
414 @Override
415 public void onAnimationEnd(Animator animation) {
416 mIsMenuBadgeAnimationRunning = false;
417 }
418
419 @Override
420 public void onAnimationCancel(Animator animation) {
421 mIsMenuBadgeAnimationRunning = false;
422 }
423 });
424
425 mMenuBadgeAnimatorSet.start();
385 } 426 }
386 427
387 /** 428 /**
388 * Remove the update menu app menu badge. 429 * Remove the update menu app menu badge.
389 */ 430 */
390 public void removeAppMenuUpdateBadge() { 431 public void removeAppMenuUpdateBadge(boolean animate) {
391 mMenuBadge.setVisibility(View.GONE); 432 boolean wasShowingMenuBadge = mShowMenuBadge;
433 mShowMenuBadge = false;
434 if (!animate || !wasShowingMenuBadge) {
435 if (!mIsMenuBadgeAnimationRunning && showMenuButtonInOmnibox()) {
Theresa 2016/02/16 18:21:53 To document this change from patchset 3, if the an
436 mMenuBadge.setVisibility(View.GONE);
437 }
438 return;
439 }
440
441 if (mIsMenuBadgeAnimationRunning) {
442 mMenuBadgeAnimatorSet.cancel();
443 }
444
445 // Set initial states.
446 mMenuButton.setAlpha(0.f);
447
448 mMenuBadgeAnimatorSet = UpdateMenuItemHelper.createHideUpdateBadgeAnimat ion(
449 mMenuButton, mMenuBadge);
450
451 mMenuBadgeAnimatorSet.addListener(new AnimatorListenerAdapter() {
gone 2016/02/13 00:26:15 Can this be combined with the three other Animator
Theresa 2016/02/16 18:21:53 LocationBarPhone isn't a Toolbar subclass which is
452 @Override
453 public void onAnimationStart(Animator animation) {
454 mIsMenuBadgeAnimationRunning = true;
455 }
456
457 @Override
458 public void onAnimationEnd(Animator animation) {
459 mIsMenuBadgeAnimationRunning = false;
460 }
461
462 @Override
463 public void onAnimationCancel(Animator animation) {
464 mIsMenuBadgeAnimationRunning = false;
465 }
466 });
467
468 mMenuBadgeAnimatorSet.start();
469 }
470
471 public void cancelAppMenuUpdateBadgeAnimation() {
472 if (mIsMenuBadgeAnimationRunning) {
473 mMenuBadgeAnimatorSet.cancel();
474 }
475 }
476
477 private boolean shouldUseLightDrawables() {
478 Tab tab = getCurrentTab();
479 boolean isIncognito = tab != null && tab.isIncognito();
480 boolean useLightDrawables = isIncognito;
481 if (getToolbarDataProvider().isUsingBrandColor()) {
482 int currentPrimaryColor = getToolbarDataProvider().getPrimaryColor() ;
483 useLightDrawables |=
484 ColorUtils.shoudUseLightForegroundOnBackground(currentPrimar yColor);
485 }
486 return useLightDrawables;
392 } 487 }
393 } 488 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698