From e785d02197a6f0b3ca837f6aff781601ebf5fd59 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Thu, 26 Sep 2013 15:21:10 -0700 Subject: [PATCH] Add ProgressBar methods to set tileable Drawables BUG: 8349406 Change-Id: I068ac291c8db19f3c8991675f141ccfc0c7b29b2 --- api/current.txt | 2 + core/java/android/widget/ProgressBar.java | 52 ++++++++++++++++++----- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/api/current.txt b/api/current.txt index 505f7bb3fa4b2..5614baa971e89 100644 --- a/api/current.txt +++ b/api/current.txt @@ -31778,11 +31778,13 @@ package android.widget { method public android.os.Parcelable onSaveInstanceState(); method public synchronized void setIndeterminate(boolean); method public void setIndeterminateDrawable(android.graphics.drawable.Drawable); + method public void setIndeterminateDrawableTiled(android.graphics.drawable.Drawable); method public void setInterpolator(android.content.Context, int); method public void setInterpolator(android.view.animation.Interpolator); method public synchronized void setMax(int); method public synchronized void setProgress(int); method public void setProgressDrawable(android.graphics.drawable.Drawable); + method public void setProgressDrawableTiled(android.graphics.drawable.Drawable); method public synchronized void setSecondaryProgress(int); } diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index b0c2d28a5eb80..217d63080dba3 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -259,10 +259,9 @@ public class ProgressBar extends View { Drawable drawable = a.getDrawable(R.styleable.ProgressBar_progressDrawable); if (drawable != null) { - drawable = tileify(drawable, false); // Calling this method can set mMaxHeight, make sure the corresponding // XML attribute for mMaxHeight is read after calling this method - setProgressDrawable(drawable); + setProgressDrawableTiled(drawable); } @@ -291,8 +290,7 @@ public class ProgressBar extends View { drawable = a.getDrawable(R.styleable.ProgressBar_indeterminateDrawable); if (drawable != null) { - drawable = tileifyIndeterminate(drawable); - setIndeterminateDrawable(drawable); + setIndeterminateDrawableTiled(drawable); } mOnlyIndeterminate = a.getBoolean( @@ -465,11 +463,9 @@ public class ProgressBar extends View { } /** - *

Define the drawable used to draw the progress bar in - * indeterminate mode.

+ * Define the drawable used to draw the progress bar in indeterminate mode. * * @param d the new drawable - * * @see #getIndeterminateDrawable() * @see #setIndeterminate(boolean) */ @@ -486,6 +482,25 @@ public class ProgressBar extends View { postInvalidate(); } } + + /** + * Define the tileable drawable used to draw the progress bar in + * indeterminate mode. + *

+ * If the drawable is a BitmapDrawable or contains BitmapDrawables, a + * tiled copy will be generated for display as a progress bar. + * + * @param d the new drawable + * @see #getIndeterminateDrawable() + * @see #setIndeterminate(boolean) + */ + public void setIndeterminateDrawableTiled(Drawable d) { + if (d != null) { + d = tileifyIndeterminate(d); + } + + setIndeterminateDrawable(d); + } /** *

Get the drawable used to draw the progress bar in @@ -501,11 +516,9 @@ public class ProgressBar extends View { } /** - *

Define the drawable used to draw the progress bar in - * progress mode.

+ * Define the drawable used to draw the progress bar in progress mode. * * @param d the new drawable - * * @see #getProgressDrawable() * @see #setIndeterminate(boolean) */ @@ -544,6 +557,25 @@ public class ProgressBar extends View { doRefreshProgress(R.id.secondaryProgress, mSecondaryProgress, false, false); } } + + /** + * Define the tileable drawable used to draw the progress bar in + * progress mode. + *

+ * If the drawable is a BitmapDrawable or contains BitmapDrawables, a + * tiled copy will be generated for display as a progress bar. + * + * @param d the new drawable + * @see #getProgressDrawable() + * @see #setIndeterminate(boolean) + */ + public void setProgressDrawableTiled(Drawable d) { + if (d != null) { + d = tileify(d, false); + } + + setProgressDrawable(d); + } /** * @return The drawable currently used to draw the progress bar