OSDN Git Service

Enable changing ProgressBar min/max width/height
authorMihai Popa <popam@google.com>
Tue, 5 Feb 2019 18:35:29 +0000 (18:35 +0000)
committerMihai Popa <popam@google.com>
Wed, 6 Feb 2019 15:13:01 +0000 (15:13 +0000)
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
core/java/android/widget/ProgressBar.java

index 16b7b74..600356d 100644 (file)
@@ -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);
index b600268..6b48c65 100644 (file)
@@ -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;
@@ -393,6 +406,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.
      *
      * @param dr the drawable to check