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 import android.content.Context; |
| 8 import android.util.AttributeSet; |
| 9 import android.widget.ImageView; |
| 10 |
| 11 /** |
| 12 * An alternative progress bar implemented using ClipDrawable. We're experimenti
ng with this for |
| 13 * faster performance. http://crbug.com/455891 |
| 14 */ |
| 15 public class ClipDrawableProgressBar extends ImageView { |
| 16 private static final long PROGRESS_CLEARING_DELAY_MS = 200; |
| 17 |
| 18 private final Runnable mClearLoadProgressRunnable = new Runnable() { |
| 19 @Override |
| 20 public void run() { |
| 21 setProgress(0); |
| 22 } |
| 23 }; |
| 24 |
| 25 /** |
| 26 * Constructor for inflating from XML. |
| 27 */ |
| 28 public ClipDrawableProgressBar(Context context, AttributeSet attrs) { |
| 29 super(context, attrs); |
| 30 } |
| 31 |
| 32 /** |
| 33 * Set the current progress to the specified value. |
| 34 * @param progress The new progress, between 0 and 10000. |
| 35 */ |
| 36 public void setProgress(int progress) { |
| 37 getDrawable().setLevel(progress); |
| 38 |
| 39 removeCallbacks(mClearLoadProgressRunnable); |
| 40 if (progress == 10000) postDelayed(mClearLoadProgressRunnable, PROGRESS_
CLEARING_DELAY_MS); |
| 41 } |
| 42 |
| 43 /** |
| 44 * Get the progress bar's current level of progress. |
| 45 * @return The current progress, between 0 and getMax(). |
| 46 */ |
| 47 public int getProgress() { |
| 48 return getDrawable().getLevel(); |
| 49 } |
| 50 } |
OLD | NEW |