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.widget; | 5 package org.chromium.chrome.browser.widget; |
6 | 6 |
7 import android.animation.TimeAnimator; | 7 import android.animation.TimeAnimator; |
8 import android.animation.TimeAnimator.TimeListener; | 8 import android.animation.TimeAnimator.TimeListener; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.graphics.Color; | 10 import android.graphics.Color; |
11 import android.os.Build; | 11 import android.os.Build; |
12 import android.support.v4.view.ViewCompat; | 12 import android.support.v4.view.ViewCompat; |
13 import android.text.TextUtils; | 13 import android.text.TextUtils; |
14 import android.view.ViewGroup; | 14 import android.view.ViewGroup; |
15 import android.view.accessibility.AccessibilityEvent; | 15 import android.view.accessibility.AccessibilityEvent; |
16 import android.widget.FrameLayout.LayoutParams; | 16 import android.widget.FrameLayout.LayoutParams; |
17 import android.widget.ProgressBar; | 17 import android.widget.ProgressBar; |
18 | 18 |
19 import org.chromium.base.ApiCompatibilityUtils; | 19 import org.chromium.base.ApiCompatibilityUtils; |
20 import org.chromium.base.CommandLine; | 20 import org.chromium.base.CommandLine; |
21 import org.chromium.base.VisibleForTesting; | 21 import org.chromium.base.VisibleForTesting; |
22 import org.chromium.base.metrics.RecordHistogram; | |
23 import org.chromium.chrome.R; | 22 import org.chromium.chrome.R; |
24 import org.chromium.chrome.browser.ChromeSwitches; | 23 import org.chromium.chrome.browser.ChromeSwitches; |
25 import org.chromium.chrome.browser.util.ColorUtils; | 24 import org.chromium.chrome.browser.util.ColorUtils; |
26 import org.chromium.components.variations.VariationsAssociatedData; | 25 import org.chromium.components.variations.VariationsAssociatedData; |
27 import org.chromium.ui.UiUtils; | 26 import org.chromium.ui.UiUtils; |
28 import org.chromium.ui.interpolators.BakedBezierInterpolator; | 27 import org.chromium.ui.interpolators.BakedBezierInterpolator; |
29 | 28 |
30 /** | 29 /** |
31 * Progress bar for use in the Toolbar view. | 30 * Progress bar for use in the Toolbar view. |
32 */ | 31 */ |
33 public class ToolbarProgressBar extends ClipDrawableProgressBar { | 32 public class ToolbarProgressBar extends ClipDrawableProgressBar { |
34 | 33 |
35 private static final String ANIMATION_FIELD_TRIAL_NAME = "ProgressBarAnimati
onAndroid"; | 34 private static final String ANIMATION_FIELD_TRIAL_NAME = "ProgressBarAnimati
onAndroid"; |
36 private static final String PROGRESS_BAR_UPDATE_COUNT_HISTOGRAM = | |
37 "Omnibox.ProgressBarUpdateCount"; | |
38 private static final String PROGRESS_BAR_BREAK_POINT_UPDATE_COUNT_HISTOGRAM
= | |
39 "Omnibox.ProgressBarBreakPointUpdateCount"; | |
40 | 35 |
41 /** | 36 /** |
42 * Interface for progress bar animation interpolation logics. | 37 * Interface for progress bar animation interpolation logics. |
43 */ | 38 */ |
44 interface AnimationLogic { | 39 interface AnimationLogic { |
45 /** | 40 /** |
46 * Resets internal data. It must be called on every loading start. | 41 * Resets internal data. It must be called on every loading start. |
47 * @param startProgress The progress for the animation to start at. This
is used when the | 42 * @param startProgress The progress for the animation to start at. This
is used when the |
48 * animation logic switches. | 43 * animation logic switches. |
49 */ | 44 */ |
(...skipping 15 matching lines...) Expand all Loading... |
65 | 60 |
66 private static final float THEMED_BACKGROUND_WHITE_FRACTION = 0.2f; | 61 private static final float THEMED_BACKGROUND_WHITE_FRACTION = 0.2f; |
67 private static final float ANIMATION_WHITE_FRACTION = 0.4f; | 62 private static final float ANIMATION_WHITE_FRACTION = 0.4f; |
68 | 63 |
69 private static final long PROGRESS_FRAME_TIME_CAP_MS = 50; | 64 private static final long PROGRESS_FRAME_TIME_CAP_MS = 50; |
70 private long mAlphaAnimationDurationMs = 140; | 65 private long mAlphaAnimationDurationMs = 140; |
71 private long mHidingDelayMs = 100; | 66 private long mHidingDelayMs = 100; |
72 | 67 |
73 private boolean mIsStarted; | 68 private boolean mIsStarted; |
74 private float mTargetProgress; | 69 private float mTargetProgress; |
75 private int mTargetProgressUpdateCount; | |
76 private AnimationLogic mAnimationLogic; | 70 private AnimationLogic mAnimationLogic; |
77 private boolean mAnimationInitialized; | 71 private boolean mAnimationInitialized; |
78 private int mMarginTop; | 72 private int mMarginTop; |
79 private ViewGroup mProgressBarContainer; | 73 private ViewGroup mProgressBarContainer; |
80 private int mProgressStartCount; | 74 private int mProgressStartCount; |
81 private int mThemeColor; | 75 private int mThemeColor; |
82 | 76 |
83 /** Whether or not to use the status bar color as the background of the tool
bar. */ | 77 /** Whether or not to use the status bar color as the background of the tool
bar. */ |
84 private boolean mUseStatusBarColorAsBackground; | 78 private boolean mUseStatusBarColorAsBackground; |
85 | 79 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 public void start() { | 249 public void start() { |
256 mIsStarted = true; | 250 mIsStarted = true; |
257 mProgressStartCount++; | 251 mProgressStartCount++; |
258 | 252 |
259 if (mIsUsingSmoothIndeterminate) { | 253 if (mIsUsingSmoothIndeterminate) { |
260 removeCallbacks(mStartSmoothIndeterminate); | 254 removeCallbacks(mStartSmoothIndeterminate); |
261 postDelayed(mStartSmoothIndeterminate, ANIMATION_START_THRESHOLD); | 255 postDelayed(mStartSmoothIndeterminate, ANIMATION_START_THRESHOLD); |
262 } | 256 } |
263 | 257 |
264 mIsRunningSmoothIndeterminate = false; | 258 mIsRunningSmoothIndeterminate = false; |
265 mTargetProgressUpdateCount = 0; | |
266 resetProgressUpdateCount(); | |
267 super.setProgress(0.0f); | 259 super.setProgress(0.0f); |
268 if (mAnimationLogic != null) mAnimationLogic.reset(0.0f); | 260 if (mAnimationLogic != null) mAnimationLogic.reset(0.0f); |
269 removeCallbacks(mHideRunnable); | 261 removeCallbacks(mHideRunnable); |
270 animateAlphaTo(1.0f); | 262 animateAlphaTo(1.0f); |
271 } | 263 } |
272 | 264 |
273 /** | 265 /** |
274 * @return True if the progress bar is showing and started. | 266 * @return True if the progress bar is showing and started. |
275 */ | 267 */ |
276 public boolean isStarted() { | 268 public boolean isStarted() { |
277 return mIsStarted; | 269 return mIsStarted; |
278 } | 270 } |
279 | 271 |
280 /** | 272 /** |
281 * Start hiding progress bar animation. | 273 * Start hiding progress bar animation. |
282 * @param delayed Whether a delayed fading out animation should be posted. | 274 * @param delayed Whether a delayed fading out animation should be posted. |
283 */ | 275 */ |
284 public void finish(boolean delayed) { | 276 public void finish(boolean delayed) { |
285 mIsStarted = false; | 277 mIsStarted = false; |
286 | 278 |
287 if (delayed) { | 279 if (delayed) { |
288 updateVisibleProgress(); | 280 updateVisibleProgress(); |
289 RecordHistogram.recordCount1000Histogram(PROGRESS_BAR_UPDATE_COUNT_H
ISTOGRAM, | |
290 getProgressUpdateCount()); | |
291 RecordHistogram.recordCount100Histogram( | |
292 PROGRESS_BAR_BREAK_POINT_UPDATE_COUNT_HISTOGRAM, | |
293 mTargetProgressUpdateCount); | |
294 } else { | 281 } else { |
295 removeCallbacks(mHideRunnable); | 282 removeCallbacks(mHideRunnable); |
296 animate().cancel(); | 283 animate().cancel(); |
297 if (mAnimatingView != null) { | 284 if (mAnimatingView != null) { |
298 removeCallbacks(mStartSmoothIndeterminate); | 285 removeCallbacks(mStartSmoothIndeterminate); |
299 mAnimatingView.cancelAnimation(); | 286 mAnimatingView.cancelAnimation(); |
300 mTargetProgress = 0; | 287 mTargetProgress = 0; |
301 } | 288 } |
302 mIsRunningSmoothIndeterminate = false; | 289 mIsRunningSmoothIndeterminate = false; |
303 setAlpha(0.0f); | 290 setAlpha(0.0f); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // If the progress bar was updated, reset the callback that triggers
the | 366 // If the progress bar was updated, reset the callback that triggers
the |
380 // smooth-indeterminate animation. | 367 // smooth-indeterminate animation. |
381 removeCallbacks(mStartSmoothIndeterminate); | 368 removeCallbacks(mStartSmoothIndeterminate); |
382 if (progress == 1.0) { | 369 if (progress == 1.0) { |
383 if (mAnimatingView != null) mAnimatingView.cancelAnimation(); | 370 if (mAnimatingView != null) mAnimatingView.cancelAnimation(); |
384 } else if (mAnimatingView != null && !mAnimatingView.isRunning()) { | 371 } else if (mAnimatingView != null && !mAnimatingView.isRunning()) { |
385 postDelayed(mStartSmoothIndeterminate, ANIMATION_START_THRESHOLD
); | 372 postDelayed(mStartSmoothIndeterminate, ANIMATION_START_THRESHOLD
); |
386 } | 373 } |
387 } | 374 } |
388 | 375 |
389 mTargetProgressUpdateCount += 1; | |
390 mTargetProgress = progress; | 376 mTargetProgress = progress; |
391 updateVisibleProgress(); | 377 updateVisibleProgress(); |
392 } | 378 } |
393 | 379 |
394 @Override | 380 @Override |
395 public void setVisibility(int visibility) { | 381 public void setVisibility(int visibility) { |
396 super.setVisibility(visibility); | 382 super.setVisibility(visibility); |
397 if (mAnimatingView != null) mAnimatingView.setVisibility(visibility); | 383 if (mAnimatingView != null) mAnimatingView.setVisibility(visibility); |
398 } | 384 } |
399 | 385 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 return ProgressBar.class.getName(); | 435 return ProgressBar.class.getName(); |
450 } | 436 } |
451 | 437 |
452 @Override | 438 @Override |
453 public void onInitializeAccessibilityEvent(AccessibilityEvent event) { | 439 public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
454 super.onInitializeAccessibilityEvent(event); | 440 super.onInitializeAccessibilityEvent(event); |
455 event.setCurrentItemIndex((int) (mTargetProgress * 100)); | 441 event.setCurrentItemIndex((int) (mTargetProgress * 100)); |
456 event.setItemCount(100); | 442 event.setItemCount(100); |
457 } | 443 } |
458 } | 444 } |
OLD | NEW |