| 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.content.Context; | 7 import android.content.Context; |
| 8 import android.graphics.Color; | 8 import android.graphics.Color; |
| 9 import android.graphics.Rect; | 9 import android.graphics.Rect; |
| 10 import android.graphics.drawable.ClipDrawable; | 10 import android.graphics.drawable.ClipDrawable; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 public int progressBarBackgroundColor; | 32 public int progressBarBackgroundColor; |
| 33 } | 33 } |
| 34 | 34 |
| 35 // ClipDrawable's max is a fixed constant 10000. | 35 // ClipDrawable's max is a fixed constant 10000. |
| 36 // http://developer.android.com/reference/android/graphics/drawable/ClipDraw
able.html | 36 // http://developer.android.com/reference/android/graphics/drawable/ClipDraw
able.html |
| 37 private static final int CLIP_DRAWABLE_MAX = 10000; | 37 private static final int CLIP_DRAWABLE_MAX = 10000; |
| 38 | 38 |
| 39 private final ColorDrawable mForegroundDrawable; | 39 private final ColorDrawable mForegroundDrawable; |
| 40 private int mBackgroundColor = Color.TRANSPARENT; | 40 private int mBackgroundColor = Color.TRANSPARENT; |
| 41 private float mProgress; | 41 private float mProgress; |
| 42 private int mProgressUpdateCount; | |
| 43 private int mDesiredVisibility; | 42 private int mDesiredVisibility; |
| 44 | 43 |
| 45 /** | 44 /** |
| 46 * Create the progress bar with a custom height. | 45 * Create the progress bar with a custom height. |
| 47 * @param context An Android context. | 46 * @param context An Android context. |
| 48 * @param height The height in px of the progress bar. | 47 * @param height The height in px of the progress bar. |
| 49 */ | 48 */ |
| 50 public ClipDrawableProgressBar(Context context, int height) { | 49 public ClipDrawableProgressBar(Context context, int height) { |
| 51 super(context); | 50 super(context); |
| 52 | 51 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 77 /** | 76 /** |
| 78 * Set the current progress to the specified value. | 77 * Set the current progress to the specified value. |
| 79 * | 78 * |
| 80 * @param progress The new progress, between 0.0 and 1.0. | 79 * @param progress The new progress, between 0.0 and 1.0. |
| 81 */ | 80 */ |
| 82 public void setProgress(float progress) { | 81 public void setProgress(float progress) { |
| 83 assert 0.0f <= progress && progress <= 1.0f; | 82 assert 0.0f <= progress && progress <= 1.0f; |
| 84 if (mProgress == progress) return; | 83 if (mProgress == progress) return; |
| 85 | 84 |
| 86 mProgress = progress; | 85 mProgress = progress; |
| 87 mProgressUpdateCount += 1; | |
| 88 getDrawable().setLevel(Math.round(progress * CLIP_DRAWABLE_MAX)); | 86 getDrawable().setLevel(Math.round(progress * CLIP_DRAWABLE_MAX)); |
| 89 } | 87 } |
| 90 | 88 |
| 91 /** | 89 /** |
| 92 * @return Foreground color of the progress bar. | 90 * @return Foreground color of the progress bar. |
| 93 */ | 91 */ |
| 94 public int getForegroundColor() { | 92 public int getForegroundColor() { |
| 95 return mForegroundDrawable.getColor(); | 93 return mForegroundDrawable.getColor(); |
| 96 } | 94 } |
| 97 | 95 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 123 getRight(), | 121 getRight(), |
| 124 getBottom()); | 122 getBottom()); |
| 125 drawingInfoOut.progressBarBackgroundRect.set( | 123 drawingInfoOut.progressBarBackgroundRect.set( |
| 126 getLeft(), | 124 getLeft(), |
| 127 getTop(), | 125 getTop(), |
| 128 drawingInfoOut.progressBarRect.left, | 126 drawingInfoOut.progressBarRect.left, |
| 129 getBottom()); | 127 getBottom()); |
| 130 } | 128 } |
| 131 } | 129 } |
| 132 | 130 |
| 133 /** | |
| 134 * Resets progress update count to 0. | |
| 135 */ | |
| 136 public void resetProgressUpdateCount() { | |
| 137 mProgressUpdateCount = 0; | |
| 138 } | |
| 139 | |
| 140 /** | |
| 141 * @return Progress update count since reset. | |
| 142 */ | |
| 143 public int getProgressUpdateCount() { | |
| 144 return mProgressUpdateCount; | |
| 145 } | |
| 146 | |
| 147 private void updateInternalVisibility() { | 131 private void updateInternalVisibility() { |
| 148 int oldVisibility = getVisibility(); | 132 int oldVisibility = getVisibility(); |
| 149 int newVisibility = mDesiredVisibility; | 133 int newVisibility = mDesiredVisibility; |
| 150 if (getAlpha() == 0 && mDesiredVisibility == VISIBLE) newVisibility = IN
VISIBLE; | 134 if (getAlpha() == 0 && mDesiredVisibility == VISIBLE) newVisibility = IN
VISIBLE; |
| 151 if (oldVisibility != newVisibility) super.setVisibility(newVisibility); | 135 if (oldVisibility != newVisibility) super.setVisibility(newVisibility); |
| 152 } | 136 } |
| 153 | 137 |
| 154 private int applyAlpha(int color, float alpha) { | 138 private int applyAlpha(int color, float alpha) { |
| 155 return (Math.round(alpha * (color >>> 24)) << 24) | (0x00ffffff & color)
; | 139 return (Math.round(alpha * (color >>> 24)) << 24) | (0x00ffffff & color)
; |
| 156 } | 140 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 185 public void setForegroundColor(int color) { | 169 public void setForegroundColor(int color) { |
| 186 mForegroundDrawable.setColor(color); | 170 mForegroundDrawable.setColor(color); |
| 187 } | 171 } |
| 188 | 172 |
| 189 @Override | 173 @Override |
| 190 protected boolean onSetAlpha(int alpha) { | 174 protected boolean onSetAlpha(int alpha) { |
| 191 updateInternalVisibility(); | 175 updateInternalVisibility(); |
| 192 return super.onSetAlpha(alpha); | 176 return super.onSetAlpha(alpha); |
| 193 } | 177 } |
| 194 } | 178 } |
| OLD | NEW |