diff options
| author | Joe Onorato <joeo@google.com> | 2010-12-08 15:31:28 -0800 |
|---|---|---|
| committer | Joe Onorato <joeo@google.com> | 2010-12-08 15:48:06 -0800 |
| commit | aa072634630c9515e44890dc302307fa969bbb85 (patch) | |
| tree | 345097888367bc302e363693061c3911839c6f94 /core/java/android/widget/ProgressBar.java | |
| parent | 8a78d759c4eed346d58ceef2dc71d832ec2ce6e6 (diff) | |
Make setDrawable work after initialization has occurred.
Change-Id: Id040f69f2fc3402013229114fc3c1b0730eef579
Diffstat (limited to 'core/java/android/widget/ProgressBar.java')
| -rw-r--r-- | core/java/android/widget/ProgressBar.java | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index 85ca5f3aa3a5..5b143fe2dd91 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -436,6 +436,14 @@ public class ProgressBar extends View { * @see #setIndeterminate(boolean) */ public void setProgressDrawable(Drawable d) { + boolean needUpdate; + if (mProgressDrawable != null && d != mProgressDrawable) { + mProgressDrawable.setCallback(null); + needUpdate = true; + } else { + needUpdate = false; + } + if (d != null) { d.setCallback(this); @@ -451,6 +459,13 @@ public class ProgressBar extends View { mCurrentDrawable = d; postInvalidate(); } + + if (needUpdate) { + updateDrawableBounds(getWidth(), getHeight()); + updateDrawableState(); + doRefreshProgress(R.id.progress, mProgress, false, false); + doRefreshProgress(R.id.secondaryProgress, mSecondaryProgress, false, false); + } } /** @@ -493,7 +508,7 @@ public class ProgressBar extends View { } public void run() { - doRefreshProgress(mId, mProgress, mFromUser); + doRefreshProgress(mId, mProgress, mFromUser, true); // Put ourselves back in the cache when we are done mRefreshProgressRunnable = this; } @@ -506,7 +521,8 @@ public class ProgressBar extends View { } - private synchronized void doRefreshProgress(int id, int progress, boolean fromUser) { + private synchronized void doRefreshProgress(int id, int progress, boolean fromUser, + boolean callBackToApp) { float scale = mMax > 0 ? (float) progress / (float) mMax : 0; final Drawable d = mCurrentDrawable; if (d != null) { @@ -522,7 +538,7 @@ public class ProgressBar extends View { invalidate(); } - if (id == R.id.progress) { + if (callBackToApp && id == R.id.progress) { onProgressRefresh(scale, fromUser); } } @@ -532,7 +548,7 @@ public class ProgressBar extends View { private synchronized void refreshProgress(int id, int progress, boolean fromUser) { if (mUiThreadId == Thread.currentThread().getId()) { - doRefreshProgress(id, progress, fromUser); + doRefreshProgress(id, progress, fromUser, true); } else { RefreshProgressRunnable r; if (mRefreshProgressRunnable != null) { @@ -831,6 +847,10 @@ public class ProgressBar extends View { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { + updateDrawableBounds(w, h); + } + + private void updateDrawableBounds(int w, int h) { // onDraw will translate the canvas so we draw starting at 0,0 int right = w - mPaddingRight - mPaddingLeft; int bottom = h - mPaddingBottom - mPaddingTop; @@ -888,6 +908,7 @@ public class ProgressBar extends View { dw = Math.max(mMinWidth, Math.min(mMaxWidth, d.getIntrinsicWidth())); dh = Math.max(mMinHeight, Math.min(mMaxHeight, d.getIntrinsicHeight())); } + updateDrawableState(); dw += mPaddingLeft + mPaddingRight; dh += mPaddingTop + mPaddingBottom; @@ -898,7 +919,10 @@ public class ProgressBar extends View { @Override protected void drawableStateChanged() { super.drawableStateChanged(); + updateDrawableState(); + } + private void updateDrawableState() { int[] state = getDrawableState(); if (mProgressDrawable != null && mProgressDrawable.isStateful()) { |
