Skip to content

Commit b81b144

Browse files
author
Cyril Mottier
committed
Default RotateDrawable's pivot set to (50%, 50%)
In order to define the pivot in an XML-instanciated RotateDrawable, android:pivotX and android:pivotY had to be set in your XML. Forgetting to set those attributes ended up in a NullPointerException (tv = null) that were caught by the Resources.getDrawable() method (caught as an Exception). As a result a not-very-accurate message was logged: "Resource not found ...". Defining a default pivot value seems like a great fix. Some other fixes would be to modify the documentation or notify the user with a better explanation than "Resource not found ...".
1 parent b09ef7b commit b81b144

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

graphics/java/android/graphics/drawable/RotateDrawable.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,27 @@ public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
204204
com.android.internal.R.styleable.RotateDrawable_visible);
205205

206206
TypedValue tv = a.peekValue(com.android.internal.R.styleable.RotateDrawable_pivotX);
207-
boolean pivotXRel = tv.type == TypedValue.TYPE_FRACTION;
208-
float pivotX = pivotXRel ? tv.getFraction(1.0f, 1.0f) : tv.getFloat();
207+
boolean pivotXRel;
208+
float pivotX;
209+
if (tv == null) {
210+
pivotXRel = true;
211+
pivotX = 0.5f;
212+
} else {
213+
pivotXRel = tv.type == TypedValue.TYPE_FRACTION;
214+
pivotX = pivotXRel ? tv.getFraction(1.0f, 1.0f) : tv.getFloat();
215+
}
209216

210217
tv = a.peekValue(com.android.internal.R.styleable.RotateDrawable_pivotY);
211-
boolean pivotYRel = tv.type == TypedValue.TYPE_FRACTION;
212-
float pivotY = pivotYRel ? tv.getFraction(1.0f, 1.0f) : tv.getFloat();
213-
218+
boolean pivotYRel;
219+
float pivotY;
220+
if (tv == null) {
221+
pivotYRel = true;
222+
pivotY = 0.5f;
223+
} else {
224+
pivotYRel = tv.type == TypedValue.TYPE_FRACTION;
225+
pivotY = pivotYRel ? tv.getFraction(1.0f, 1.0f) : tv.getFloat();
226+
}
227+
214228
float fromDegrees = a.getFloat(
215229
com.android.internal.R.styleable.RotateDrawable_fromDegrees, 0.0f);
216230
float toDegrees = a.getFloat(

0 commit comments

Comments
 (0)