Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa072634 authored by Joe Onorato's avatar Joe Onorato
Browse files

Make setDrawable work after initialization has occurred.

Change-Id: Id040f69f2fc3402013229114fc3c1b0730eef579
parent 8a78d759
Loading
Loading
Loading
Loading
+28 −4
Original line number Diff line number Diff line
@@ -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()) {