From cbc059d7134c3fa2a2c23fa967fb4fe3a1d0b89b Mon Sep 17 00:00:00 2001 From: Mihai Popa Date: Tue, 5 Feb 2019 18:35:29 +0000 Subject: [PATCH] Enable changing ProgressBar min/max width/height The CL adds getters and setters for the min/max width/height attributes of ProgressBar. This could be already specified in xml, but not post inflation. Bug: 123769470 Test: atest android.widget.cts.ProgressBarTest Change-Id: I3bb4992da0c34cd88078588253ef6789fa8f1856 --- api/current.txt | 8 +++ core/java/android/widget/ProgressBar.java | 87 ++++++++++++++++++++++- 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/api/current.txt b/api/current.txt index 16b7b74b08c60..600356dd55eaa 100644 --- a/api/current.txt +++ b/api/current.txt @@ -56368,7 +56368,11 @@ package android.widget { method @Nullable public android.graphics.PorterDuff.Mode getIndeterminateTintMode(); method public android.view.animation.Interpolator getInterpolator(); method @android.view.ViewDebug.ExportedProperty(category="progress") public int getMax(); + method @Px public int getMaxHeight(); + method @Px public int getMaxWidth(); method @android.view.ViewDebug.ExportedProperty(category="progress") public int getMin(); + method @Px public int getMinHeight(); + method @Px public int getMinWidth(); method @android.view.ViewDebug.ExportedProperty(category="progress") public int getProgress(); method @Nullable public android.content.res.ColorStateList getProgressBackgroundTintList(); method @Nullable public android.graphics.PorterDuff.Mode getProgressBackgroundTintMode(); @@ -56392,7 +56396,11 @@ package android.widget { method public void setInterpolator(android.content.Context, @InterpolatorRes int); method public void setInterpolator(android.view.animation.Interpolator); method public void setMax(int); + method public void setMaxHeight(@Px int); + method public void setMaxWidth(@Px int); method public void setMin(int); + method public void setMinHeight(@Px int); + method public void setMinWidth(@Px int); method public void setProgress(int); method public void setProgress(int, boolean); method public void setProgressBackgroundTintList(@Nullable android.content.res.ColorStateList); diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index b60026810efba..6b48c6584ad29 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -20,6 +20,7 @@ import android.animation.ObjectAnimator; import android.annotation.InterpolatorRes; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.Px; import android.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.res.ColorStateList; @@ -170,12 +171,24 @@ public class ProgressBar extends View { /** Duration of smooth progress animations. */ private static final int PROGRESS_ANIM_DURATION = 80; - @UnsupportedAppUsage + /** + * Outside the framework, please use {@link ProgressBar#getMinWidth()} and + * {@link ProgressBar#setMinWidth(int)} instead of accessing these directly. + */ + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) int mMinWidth; int mMaxWidth; - @UnsupportedAppUsage + /** + * Outside the framework, please use {@link ProgressBar#getMinHeight()} and + * {@link ProgressBar#setMinHeight(int)} instead of accessing these directly. + */ + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) int mMinHeight; - @UnsupportedAppUsage + /** + * Outside the framework, please use {@link ProgressBar#getMaxHeight()} ()} and + * {@link ProgressBar#setMaxHeight(int)} (int)} instead of accessing these directly. + */ + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) int mMaxHeight; private int mProgress; @@ -392,6 +405,74 @@ public class ProgressBar extends View { } } + /** + * Sets the minimum width the progress bar can have. + * @param minWidth the minimum width to be set, in pixels + * @attr ref android.R.styleable#ProgressBar_minWidth + */ + public void setMinWidth(@Px int minWidth) { + mMinWidth = minWidth; + requestLayout(); + } + + /** + * @return the minimum width the progress bar can have, in pixels + */ + @Px public int getMinWidth() { + return mMinWidth; + } + + /** + * Sets the maximum width the progress bar can have. + * @param maxWidth the maximum width to be set, in pixels + * @attr ref android.R.styleable#ProgressBar_maxWidth + */ + public void setMaxWidth(@Px int maxWidth) { + mMaxWidth = maxWidth; + requestLayout(); + } + + /** + * @return the maximum width the progress bar can have, in pixels + */ + @Px public int getMaxWidth() { + return mMaxWidth; + } + + /** + * Sets the minimum height the progress bar can have. + * @param minHeight the minimum height to be set, in pixels + * @attr ref android.R.styleable#ProgressBar_minHeight + */ + public void setMinHeight(@Px int minHeight) { + mMinHeight = minHeight; + requestLayout(); + } + + /** + * @return the minimum height the progress bar can have, in pixels + */ + @Px public int getMinHeight() { + return mMinHeight; + } + + /** + * Sets the maximum height the progress bar can have. + * @param maxHeight the maximum height to be set, in pixels + * @attr ref android.R.styleable#ProgressBar_maxHeight + */ + public void setMaxHeight(@Px int maxHeight) { + mMaxHeight = maxHeight; + requestLayout(); + } + + /** + * @return the maximum height the progress bar can have, in pixels + */ + @Px public int getMaxHeight() { + return mMaxHeight; + } + /** * Returns {@code true} if the target drawable needs to be tileified. *