OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.widget; |
| 6 |
| 7 /** |
| 8 * Progress bar animation logic that starts fast at the beginning and slows down
approaching to the |
| 9 * end. |
| 10 */ |
| 11 class ProgressAnimationFastStart implements ToolbarProgressBar.AnimationLogic { |
| 12 // The speed unit is progress per second where 0 <= progress <= 1. |
| 13 private static final float NORMALIZED_INITIAL_SPEED = 1.5f; |
| 14 private static final float FINISHING_SPEED = 2.0f; |
| 15 |
| 16 private float mProgress; |
| 17 |
| 18 @Override |
| 19 public void reset() { |
| 20 mProgress = 0.0f; |
| 21 } |
| 22 |
| 23 @Override |
| 24 public float updateProgress(float targetProgress, float frameTimeSec, int re
solution) { |
| 25 assert mProgress <= targetProgress; |
| 26 |
| 27 float progressChange; |
| 28 if (targetProgress == 1.0f) { |
| 29 progressChange = FINISHING_SPEED * frameTimeSec; |
| 30 } else { |
| 31 progressChange = (targetProgress - mProgress) |
| 32 * (1.0f - (float) Math.exp(-frameTimeSec * NORMALIZED_INITIA
L_SPEED)); |
| 33 } |
| 34 |
| 35 mProgress = Math.min(mProgress + progressChange, targetProgress); |
| 36 if (targetProgress - mProgress < 0.5f / resolution) mProgress = targetPr
ogress; |
| 37 |
| 38 return mProgress; |
| 39 } |
| 40 } |
OLD | NEW |