From e1c6ff4b91072a4071589938c74dd65d66f88fb5 Mon Sep 17 00:00:00 2001
From: Romain Guy
Date: Tue, 26 Apr 2011 11:50:17 -0700
Subject: [PATCH] Make setGradientCenter/Radius work.
The previous implementation would not rebuild the gradient shader
when programmatically changing the shader's properties. Also fixes
the documentation since the gradient center does affect linear
gradients.
Change-Id: I5387188484b862f6835b0da9042b25032e55e792
---
docs/html/guide/topics/resources/drawable-resource.jd | 6 ++----
.../java/android/graphics/drawable/GradientDrawable.java | 3 +++
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/docs/html/guide/topics/resources/drawable-resource.jd b/docs/html/guide/topics/resources/drawable-resource.jd
index cee8fc3fcc42d..89c85e22973ae 100644
--- a/docs/html/guide/topics/resources/drawable-resource.jd
+++ b/docs/html/guide/topics/resources/drawable-resource.jd
@@ -1561,11 +1561,9 @@ want, providing zero ("0dp") where you don't want rounded corners.
Integer. The angle for the gradient, in degrees. 0 is left to right, 90 is
bottom to top. It must be a multiple of 45. Default is 0.
android:centerX
- Float. The relative X-position for the center of the gradient (0 - 1.0).
-Does not apply when {@code android:type="linear"}.
+ Float. The relative X-position for the center of the gradient (0 - 1.0).
android:centerY
- Float. The relative Y-position for the center of the gradient (0 - 1.0).
-Does not apply when {@code android:type="linear"}.
+ Float. The relative Y-position for the center of the gradient (0 - 1.0).
android:centerColor
Color. Optional color that comes between the start and end colors, as a
hexadecimal value or color resource.
diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java
index 7adea061f3ad3..de0fabc7bd8f7 100644
--- a/graphics/java/android/graphics/drawable/GradientDrawable.java
+++ b/graphics/java/android/graphics/drawable/GradientDrawable.java
@@ -240,16 +240,19 @@ public class GradientDrawable extends Drawable {
public void setGradientCenter(float x, float y) {
mGradientState.setGradientCenter(x, y);
+ mRectIsDirty = true;
invalidateSelf();
}
public void setGradientRadius(float gradientRadius) {
mGradientState.setGradientRadius(gradientRadius);
+ mRectIsDirty = true;
invalidateSelf();
}
public void setUseLevel(boolean useLevel) {
mGradientState.mUseLevel = useLevel;
+ mRectIsDirty = true;
invalidateSelf();
}