summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adam Powell <adamp@google.com> 2011-09-02 15:05:15 -0700
committer Adam Powell <adamp@google.com> 2011-09-02 16:37:41 -0700
commita1b92c5e8b750d8f5b2dc5ca7e8b4edc97de5575 (patch)
tree8ea0a06dd6255ae74738a8378b563b67e7da12c0
parentf7315dd1922868efc04fcd83caff4202f215bae1 (diff)
Fix bug 5231904 - Fix wobbly progress spinners
Make ProgressBar maintain aspect ratio on indeterminate progress drawables. Make RotateDrawable tolerate left/top bounds != 0. Change-Id: Iee03030caa98f72a8745f1ae3fb0de108ff663d4
-rw-r--r--core/java/android/widget/ProgressBar.java25
-rw-r--r--graphics/java/android/graphics/drawable/RotateDrawable.java2
2 files changed, 25 insertions, 2 deletions
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java
index b2c3051c20a1..e033d2d0558f 100644
--- a/core/java/android/widget/ProgressBar.java
+++ b/core/java/android/widget/ProgressBar.java
@@ -933,9 +933,32 @@ public class ProgressBar extends View {
// onDraw will translate the canvas so we draw starting at 0,0
int right = w - mPaddingRight - mPaddingLeft;
int bottom = h - mPaddingBottom - mPaddingTop;
+ int top = 0;
+ int left = 0;
if (mIndeterminateDrawable != null) {
- mIndeterminateDrawable.setBounds(0, 0, right, bottom);
+ if (mOnlyIndeterminate) {
+ // Maintain aspect ratio. Certain kinds of animated drawables
+ // get very confused otherwise.
+ final int intrinsicWidth = mIndeterminateDrawable.getIntrinsicWidth();
+ final int intrinsicHeight = mIndeterminateDrawable.getIntrinsicHeight();
+ final float intrinsicAspect = (float) intrinsicWidth / intrinsicHeight;
+ final float boundAspect = (float) w / h;
+ if (intrinsicAspect != boundAspect) {
+ if (boundAspect > intrinsicAspect) {
+ // New width is larger. Make it smaller to match height.
+ final int width = (int) (h * intrinsicAspect);
+ left = (w - width) / 2;
+ right = left + width;
+ } else {
+ // New height is larger. Make it smaller to match width.
+ final int height = (int) (w * (1 / intrinsicAspect));
+ top = (h - height) / 2;
+ bottom = top + height;
+ }
+ }
+ }
+ mIndeterminateDrawable.setBounds(left, top, right, bottom);
}
if (mProgressDrawable != null) {
diff --git a/graphics/java/android/graphics/drawable/RotateDrawable.java b/graphics/java/android/graphics/drawable/RotateDrawable.java
index 4f74b374cbdb..e987679dd49f 100644
--- a/graphics/java/android/graphics/drawable/RotateDrawable.java
+++ b/graphics/java/android/graphics/drawable/RotateDrawable.java
@@ -83,7 +83,7 @@ public class RotateDrawable extends Drawable implements Drawable.Callback {
float px = st.mPivotXRel ? (w * st.mPivotX) : st.mPivotX;
float py = st.mPivotYRel ? (h * st.mPivotY) : st.mPivotY;
- canvas.rotate(st.mCurrentDegrees, px, py);
+ canvas.rotate(st.mCurrentDegrees, px + bounds.left, py + bounds.top);
st.mDrawable.draw(canvas);