package com.xiaopo.flying.sticker;

import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.graphics.RectF;

/**
 * Created by snowbean on 16-8-6.
 */
public abstract class Sticker {
    protected static final String TAG = "Sticker";

    protected Matrix mMatrix;
    protected boolean mIsFlipped;

    public boolean isFlipped() {
        return mIsFlipped;
    }

    public void setFlipped(boolean flipped) {
        mIsFlipped = flipped;
    }

    public Matrix getMatrix() {
        return mMatrix;
    }

    public void setMatrix(Matrix matrix) {
        mMatrix.set(matrix);
    }

    public abstract void draw(Canvas canvas);

    public abstract int getWidth();

    public abstract int getHeight();

    public float[] getBoundPoints() {
        if (!mIsFlipped) {
            return new float[]{
                    0f, 0f,
                    getWidth(), 0f,
                    0f, getHeight(),
                    getWidth(), getHeight()
            };
        } else {
            return new float[]{
                    getWidth(), 0f,
                    0f, 0f,
                    getWidth(), getHeight(),
                    0f, getHeight()
            };
        }
    }

    public float[] getMappedBoundPoints() {
        float[] dst = new float[8];
        mMatrix.mapPoints(dst, getBoundPoints());
        return dst;
    }

    public float[] getMappedPoints(float[] src) {
        float[] dst = new float[src.length];
        mMatrix.mapPoints(dst, src);
        return dst;
    }


    public RectF getBound() {
        return new RectF(0, 0, getWidth(), getHeight());
    }

    public RectF getMappedBound() {
        RectF dst = new RectF();
        mMatrix.mapRect(dst, getBound());
        return dst;
    }

    public PointF getCenterPoint() {
        return new PointF(getWidth() / 2, getHeight() / 2);
    }

    public PointF getMappedCenterPoint() {
        PointF pointF = getCenterPoint();
        float[] dst = getMappedPoints(new float[]{
                pointF.x,
                pointF.y
        });
        return new PointF(dst[0], dst[1]);
    }

    public void release() {
    }

}

@@ -155,16 +155,103 @@
 s.RectF;
+%0Aimport android.support.annotation.IntRange;%0Aimport android.support.annotation.NonNull;
 %0A%0A/**%0A *
@@ -433,16 +433,66 @@
 Flipped;
+%0A    private float%5B%5D mMatrixValues = new float%5B9%5D;
 %0A%0A    pu
@@ -2276,32 +2276,1264 @@
 dst%5B1%5D);%0A    %7D%0A%0A
+    public float getCurrentScale() %7B%0A        return getMatrixScale(mMatrix);%0A    %7D%0A%0A    public float getCurrentHeight() %7B%0A        return getMatrixScale(mMatrix) * getHeight();%0A    %7D%0A%0A    public float getCurrentWidth() %7B%0A        return getMatrixScale(mMatrix) * getWidth();%0A    %7D%0A%0A    /**%0A     * This method calculates scale value for given Matrix object.%0A     */%0A    private float getMatrixScale(@NonNull Matrix matrix) %7B%0A        return (float) Math.sqrt(Math.pow(getMatrixValue(matrix, Matrix.MSCALE_X), 2)%0A                + Math.pow(getMatrixValue(matrix, Matrix.MSKEW_Y), 2));%0A    %7D%0A%0A    /**%0A     * @return - current image rotation angle.%0A     */%0A    public float getCurrentAngle() %7B%0A        return getMatrixAngle(mMatrix);%0A    %7D%0A%0A    /**%0A     * This method calculates rotation angle for given Matrix object.%0A     */%0A    private float getMatrixAngle(@NonNull Matrix matrix) %7B%0A        return (float) -(Math.atan2(getMatrixValue(matrix, Matrix.MSKEW_X),%0A                getMatrixValue(matrix, Matrix.MSCALE_X)) * (180 / Math.PI));%0A    %7D%0A%0A    private float getMatrixValue(@NonNull Matrix matrix, @IntRange(from = 0, to = 9) int valueIndex) %7B%0A        matrix.getValues(mMatrixValues);%0A        return mMatrixValues%5BvalueIndex%5D;%0A    %7D%0A%0A
     public void 

add sticker method which to support get current info