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

Commit 50436e81 authored by d34d's avatar d34d Committed by Clark Scheff
Browse files

Themes: Add randomization to composed icon rotation

This patch adds an addition attribute named "plusMinus" which allows
a theme designer to specifiy a +/- variation to the angle of rotation.
The final icon will be rotated by the angle specified +/- a random angle
within the range specified by the value defined with "plusMinus"

ex:
<rotate angle="30" plusMinus="5" />

Change-Id: I51a65c90209547417fe99b215164f8418f9f7f6b
parent f89dbff4
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ public class ComposedIconInfo implements Parcelable {
    public int[] iconBacks;
    public float iconScale;
    public float iconRotation;
    // value used to provide some randomization to the angle of rotation
    public float iconRotationVariance;
    public float iconTranslationX;
    public float iconTranslationY;
    public int iconDensity;
@@ -47,6 +49,7 @@ public class ComposedIconInfo implements Parcelable {
    private ComposedIconInfo(Parcel source) {
        iconScale = source.readFloat();
        iconRotation = source.readFloat();
        iconRotationVariance = source.readFloat();
        iconTranslationX = source.readFloat();
        iconTranslationY = source.readFloat();
        iconDensity = source.readInt();
@@ -87,6 +90,7 @@ public class ComposedIconInfo implements Parcelable {
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeFloat(iconScale);
        dest.writeFloat(iconRotation);
        dest.writeFloat(iconRotationVariance);
        dest.writeFloat(iconTranslationX);
        dest.writeFloat(iconTranslationY);
        dest.writeInt(iconDensity);
+16 −2
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ public class IconPackHelper {

    // Rotation and translation constants
    private static final String ANGLE_ATTR = "angle";
    private static final String ANGLE_VARIANCE = "plusMinus";
    private static final String TRANSLATE_X_ATTR = "xOffset";
    private static final String TRANSLATE_Y_ATTR = "yOffset";

@@ -295,11 +296,19 @@ public class IconPackHelper {
    private boolean parseRotationComponent(XmlPullParser parser, ComposedIconInfo iconInfo) {
        if (!parser.getName().equalsIgnoreCase(ICON_ROTATE_TAG)) return false;
        String angle = parser.getAttributeValue(null, ANGLE_ATTR);
        String variance = parser.getAttributeValue(null, ANGLE_VARIANCE);
        if (angle != null) {
            try {
                iconInfo.iconRotation = Float.valueOf(angle);
            } catch (NumberFormatException e) {
                Log.w(TAG, "Error parsing angle", e);
                Log.w(TAG, "Error parsing " + ANGLE_ATTR, e);
            }
        }
        if (variance != null) {
            try {
                iconInfo.iconRotationVariance = Float.valueOf(variance);
            } catch (NumberFormatException e) {
                Log.w(TAG, "Error parsing " + ANGLE_VARIANCE, e);
            }
        }
        return true;
@@ -720,7 +729,12 @@ public class IconPackHelper {
            canvas.save();
            final float halfWidth = width / 2f;
            final float halfHeight = height / 2f;
            canvas.rotate(iconInfo.iconRotation, halfWidth, halfHeight);
            float angle = iconInfo.iconRotation;
            if (iconInfo.iconRotationVariance != 0) {
                angle += (sRandom.nextFloat() * (iconInfo.iconRotationVariance * 2))
                        - iconInfo.iconRotationVariance;
            }
            canvas.rotate(angle, halfWidth, halfHeight);
            canvas.scale(iconInfo.iconScale, iconInfo.iconScale, halfWidth, halfHeight);
            canvas.translate(iconInfo.iconTranslationX, iconInfo.iconTranslationY);
            if (iconInfo.colorFilter != null) {