Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7c5186c authored by Cyril Mottier's avatar Cyril Mottier Committed by Steve Kondik
Browse files

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 ...".
parent e8c34053
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -204,12 +204,26 @@ public class RotateDrawable extends Drawable implements Drawable.Callback {
                com.android.internal.R.styleable.RotateDrawable_visible);
        
        TypedValue tv = a.peekValue(com.android.internal.R.styleable.RotateDrawable_pivotX);
        boolean pivotXRel = tv.type == TypedValue.TYPE_FRACTION;
        float pivotX = pivotXRel ? tv.getFraction(1.0f, 1.0f) : tv.getFloat();
        boolean pivotXRel;
        float pivotX;
        if (tv == null) {
            pivotXRel = true;
            pivotX = 0.5f;
        } else {
            pivotXRel = tv.type == TypedValue.TYPE_FRACTION;
            pivotX = pivotXRel ? tv.getFraction(1.0f, 1.0f) : tv.getFloat();
        }
        
        tv = a.peekValue(com.android.internal.R.styleable.RotateDrawable_pivotY);
        boolean pivotYRel = tv.type == TypedValue.TYPE_FRACTION;
        float pivotY = pivotYRel ? tv.getFraction(1.0f, 1.0f) : tv.getFloat();
        boolean pivotYRel;
        float pivotY;
        if (tv == null) {
            pivotYRel = true;
            pivotY = 0.5f;
        } else {
            pivotYRel = tv.type == TypedValue.TYPE_FRACTION;
            pivotY = pivotYRel ? tv.getFraction(1.0f, 1.0f) : tv.getFloat();
        }

        float fromDegrees = a.getFloat(
                com.android.internal.R.styleable.RotateDrawable_fromDegrees, 0.0f);