package com.epson.cameracopy.ui;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.drawable.BitmapDrawable;
import android.os.Debug;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;

import androidx.core.internal.view.SupportMenu;
import androidx.core.view.InputDeviceCompat;

import java.util.ArrayList;
import java.util.List;

/* renamed from: com.epson.cameracopy.ui.ImageCollectView */
public class ImageCollectView extends View {
    private static final float DRAG_EDGE_STROKE_WIDTH = 1.0f;
    private static final float MESSAGE_TEXT_SIZE = 10.0f;
    private static final float RADIUS_CROP_CIRCLE = 16.0f;
    private static final float SCALE_RANGE_MAX = 4.0f;
    private static final float SCALE_RANGE_MIN = 1.0f;
    private static final float STROKE_WIDTH_DRAG_PATH = 20.0f;
    private static final int TOUCH_STATE_DOWN_MOVE = 0;
    private static final int TOUCH_STATE_IDOLE = -1;
    private static final int TOUCH_STATE_UP = 1;
    private static final float VIEW_MARGINE = 6.0f;
    public static final int VIEW_MODE_COLOR_ADJUSTMENT_ALL = 2;
    public static final int VIEW_MODE_COLOR_ADJUSTMENT_PART = 3;
    public static final int VIEW_MODE_CROP_IMAGE = 0;
    public static final int VIEW_MODE_ENHANCE_TEXT = 1;
    private int[] INVERT = {1, 0};
    private Bitmap mBitmapImage = null;
    private Bitmap mBitmapMask = null;
    private Canvas mCanvasMask = null;
    private Context mContext = null;
    private Data mData = null;
    private GestureDetector mGestureDetector = null;
    private boolean mGetCropPoint = false;
    private Handler mHandlerAvtivity = null;
    private int mOrient = 0;
    private PathEffectData mPathEffectData = null;
    private ScaleGestureDetector mScaleGestureDetector = null;
    private int mViewMode = 0;
    private final GestureDetector.SimpleOnGestureListener onGestureDetectorListener = new GestureDetector.SimpleOnGestureListener() {
        public boolean onDoubleTap(MotionEvent motionEvent) {
            ResetScalePos(true);
            invalidate();
            return super.onDoubleTap(motionEvent);
        }

        public boolean onDoubleTapEvent(MotionEvent motionEvent) {
            return super.onDoubleTapEvent(motionEvent);
        }

        public boolean onDown(MotionEvent motionEvent) {
            return super.onDown(motionEvent);
        }

        public void onLongPress(MotionEvent motionEvent) {
            super.onLongPress(motionEvent);
        }

        public void onShowPress(MotionEvent motionEvent) {
            super.onShowPress(motionEvent);
        }

        public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
            return super.onSingleTapConfirmed(motionEvent);
        }

        public boolean onSingleTapUp(MotionEvent motionEvent) {
            return super.onSingleTapUp(motionEvent);
        }

        public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2) {
            return super.onFling(motionEvent, motionEvent2, f, f2);
        }

        public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2) {
            return super.onScroll(motionEvent, motionEvent2, f, f2);
        }
    };
    private final ScaleGestureDetector.SimpleOnScaleGestureListener onScaleGestureDetector = new ScaleGestureDetector.SimpleOnScaleGestureListener() {
        public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) {
            return super.onScaleBegin(scaleGestureDetector);
        }

        public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
            SetScale(scaleGestureDetector.getScaleFactor());
            invalidate();
            return true;
        }

        public void onScaleEnd(ScaleGestureDetector scaleGestureDetector) {
            SetScale(scaleGestureDetector.getScaleFactor());
            invalidate();
            super.onScaleEnd(scaleGestureDetector);
        }
    };

    private void TouchEventColorAdjustmentAll(MotionEvent motionEvent) {
    }

    /* renamed from: com.epson.cameracopy.ui.ImageCollectView$DataCropImage */
    class DataCropImage {
        public PointF[] mPointPreviewCrop;
        public PointF mPointPreviewTouch;
        public RectF[] mRectCropMovableArea;
        public RectF[] mRectCropTapArea;
        public int mSelectArea;

        DataCropImage() {
            mRectCropTapArea = null;
            mRectCropMovableArea = null;
            mPointPreviewCrop = null;
            mPointPreviewTouch = null;
            mRectCropTapArea = new RectF[5];
            mRectCropTapArea[0] = new RectF();
            mRectCropTapArea[1] = new RectF();
            mRectCropTapArea[2] = new RectF();
            mRectCropTapArea[3] = new RectF();
            mRectCropTapArea[4] = new RectF();
            mRectCropMovableArea = new RectF[4];
            mRectCropMovableArea[0] = new RectF();
            mRectCropMovableArea[1] = new RectF();
            mRectCropMovableArea[2] = new RectF();
            mRectCropMovableArea[3] = new RectF();
            mPointPreviewCrop = new PointF[4];
            mPointPreviewCrop[0] = new PointF();
            mPointPreviewCrop[1] = new PointF();
            mPointPreviewCrop[2] = new PointF();
            mPointPreviewCrop[3] = new PointF();
            mPointPreviewTouch = new PointF();
            mSelectArea = -1;
        }
    }

    /* renamed from: com.epson.cameracopy.ui.ImageCollectView$DataEnhanceText */
    class DataEnhanceText {
        DataEnhanceText() {
        }
    }

    /* renamed from: com.epson.cameracopy.ui.ImageCollectView$DataColorAdjust */
    class DataColorAdjust {
        public List<List<PointF>> mPointArray;
        public List<List<PointF>> mPointEdgeArray;
        public List<PointF> mPointMoveArray;

        DataColorAdjust() {
            mPointArray = null;
            mPointMoveArray = null;
            mPointEdgeArray = null;
            mPointArray = new ArrayList();
            mPointMoveArray = new ArrayList();
            mPointEdgeArray = new ArrayList();
        }
    }

    /* renamed from: com.epson.cameracopy.ui.ImageCollectView$DataDrawPreview */
    class DataDrawPreview {
        public BitmapDrawable mBitmapDrawable;
        public Matrix mMatrixBitmap;
        public PointF mPointInitOffset;
        public PointF[] mPointMoveDeff;
        public PointF mPointMovePoint;
        public RectF mRectBitmap;
        public RectF mRectDrawScale;
        public float[] mScale;

        DataDrawPreview() {
            mBitmapDrawable = null;
            mMatrixBitmap = null;
            mRectBitmap = null;
            mRectDrawScale = null;
            mPointInitOffset = null;
            mPointMovePoint = null;
            mPointMoveDeff = null;
            mMatrixBitmap = new Matrix();
            mRectBitmap = new RectF(0.0f, 0.0f, 0.0f, 0.0f);
            mRectDrawScale = new RectF(0.0f, 0.0f, 0.0f, 0.0f);
            mPointInitOffset = new PointF();
            mPointMovePoint = new PointF(0.0f, 0.0f);
            mPointMoveDeff = new PointF[2];
            mPointMoveDeff[0] = new PointF(0.0f, 0.0f);
            mPointMoveDeff[1] = new PointF(0.0f, 0.0f);
            mScale = new float[2];
            float[] fArr = mScale;
            fArr[0] = 1.0f;
            fArr[1] = 1.0f;
        }
    }

    /* renamed from: com.epson.cameracopy.ui.ImageCollectView$Data */
    class Data {

        /* renamed from: d */
        public C0884D[] f133d;
        private boolean mFlagScale;
        public Paint mPaintCropCircleDeselected;
        public Paint mPaintCropCircleSelect;
        public Paint mPaintCropLine;
        public Paint mPaintCropMovableArea;
        public Paint mPaintCropTapArea;
        public Paint mPaintDragEdge;
        public Paint mPaintDragMask;
        public Paint mPaintDragOff;
        public Paint mPaintDragOn;
        public Paint mPaintImageArea;
        public Paint mPaintMessageArea;
        public Paint mPaintPreviewImage;
        public Paint mPaintTextMessage;
        public Paint mPaintView;
        public PointF[] mPointCrop;
        public PointF[] mPointViewMargine;
        public float mRadiusCropCircle;
        public boolean mShowTextMessage;
        float mStrokeWidth;
        public String mTextMessage;
        public TimerCropImageCropCircle mTimerCropImageCropCircle;
        public int mTouchState;

        /* renamed from: com.epson.cameracopy.ui.ImageCollectView$Data$D */
        class C0884D {
            public DataColorAdjust dca = null;
            public DataCropImage dcm = null;
            public DataDrawPreview[] ddp = null;
            public DataEnhanceText det = null;
            public float[] mBaseScale;
            public PointF mPointPreviewImageOffset = null;
            public RectF mRectImageArea = null;
            public RectF mRectMessageArea = null;
            public RectF mRectPreviewImage = null;
            public RectF mRectView = null;

            public C0884D() {
                dcm = new DataCropImage();
                det = new DataEnhanceText();
                dca = new DataColorAdjust();
                ddp = new DataDrawPreview[4];
                ddp[0] = new DataDrawPreview();
                ddp[1] = new DataDrawPreview();
                ddp[2] = new DataDrawPreview();
                ddp[3] = new DataDrawPreview();
                mRectView = new RectF();
                mRectImageArea = new RectF();
                mRectPreviewImage = new RectF();
                mRectMessageArea = new RectF();
                mPointPreviewImageOffset = new PointF();
                mBaseScale = new float[2];
                float[] fArr = mBaseScale;
                fArr[0] = 1.0f;
                fArr[1] = 1.0f;
            }
        }

        public Data() {
            f133d = null;
            mPointCrop = null;
            mPaintView = null;
            mPaintPreviewImage = null;
            mPaintImageArea = null;
            mPaintCropLine = null;
            mPaintCropCircleSelect = null;
            mPaintCropCircleDeselected = null;
            mPaintDragOn = null;
            mPaintDragOff = null;
            mPaintDragMask = null;
            mPaintDragEdge = null;
            mPaintCropTapArea = null;
            mPaintCropMovableArea = null;
            mPointViewMargine = null;
            mTimerCropImageCropCircle = null;
            mTextMessage = null;
            mPaintTextMessage = null;
            mPaintMessageArea = null;
            mFlagScale = false;
            f133d = new C0884D[2];
            f133d[0] = new C0884D();
            f133d[1] = new C0884D();
            mPointCrop = new PointF[4];
            mPointCrop[0] = new PointF();
            mPointCrop[1] = new PointF();
            mPointCrop[2] = new PointF();
            mPointCrop[3] = new PointF();
            mPaintView = new Paint();
            mPaintPreviewImage = new Paint();
            mPaintImageArea = new Paint();
            mPaintCropLine = new Paint();
            mPaintCropCircleSelect = new Paint();
            mPaintCropCircleDeselected = new Paint();
            mPaintDragOn = new Paint();
            mPaintDragOff = new Paint();
            mPaintDragMask = new Paint();
            mPaintDragEdge = new Paint();
            mPaintCropTapArea = new Paint();
            mPaintCropMovableArea = new Paint();
            mPointViewMargine = new PointF[4];
            mTextMessage = "";
            mPaintTextMessage = new Paint();
            mPaintMessageArea = new Paint();
            mTouchState = -1;
        }
    }

    public ImageCollectView(Context context) {
        super(context);
        if (!isInEditMode()) {
            init(context);
        }
    }

    public ImageCollectView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        if (!isInEditMode()) {
            init(context);
        }
    }

    public ImageCollectView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        if (!isInEditMode()) {
            init(context);
        }
    }

    private void init(Context context) {
        mContext = context;
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        float f = displayMetrics.density;
        float f2 = RADIUS_CROP_CIRCLE * f;
        float f3 = VIEW_MARGINE * f;
        float f4 = 20.0f * f;
        mData = new Data();
        Data data = mData;
        data.mStrokeWidth = f4;
        data.mRadiusCropCircle = f2;
        float f5 = f2 + f3;
        data.mPointViewMargine[0] = new PointF(f5, f5);
        mData.mPointViewMargine[1] = new PointF(f3, f3);
        mData.mPointViewMargine[2] = new PointF(f3, f3);
        mData.mPointViewMargine[3] = new PointF(f3, f3);
        mData.mPaintView.setStyle(Paint.Style.STROKE);
        mData.mPaintView.setColor(-65281);
        mData.mPaintView.setStrokeWidth(2.0f);
        mData.mPaintImageArea.setStyle(Paint.Style.STROKE);
        mData.mPaintImageArea.setColor(InputDeviceCompat.SOURCE_ANY);
        mData.mPaintPreviewImage.setStyle(Paint.Style.STROKE);
        mData.mPaintPreviewImage.setColor(-16776961);
        mData.mPaintCropLine.setStyle(Paint.Style.STROKE);
        mData.mPaintCropLine.setColor(-16711936);
        mData.mPaintCropLine.setStrokeWidth(2.0f);
        mData.mPaintCropCircleSelect.setStyle(Paint.Style.STROKE);
        mData.mPaintCropCircleSelect.setColor(SupportMenu.CATEGORY_MASK);
        mData.mPaintCropCircleDeselected.setStyle(Paint.Style.FILL);
        mData.mPaintCropCircleDeselected.setColor(Color.argb(76, 255, 0, 0));
        mData.mPaintDragOn.setStyle(Paint.Style.STROKE);
        mData.mPaintDragOn.setColor(Color.argb(76, 0, 255, 0));
        mData.mPaintDragOn.setStrokeWidth(f4);
        mData.mPaintDragOn.setStrokeCap(Paint.Cap.ROUND);
        mData.mPaintDragOff.setStyle(Paint.Style.STROKE);
        mData.mPaintDragOff.setColor(Color.argb(76, 0, 0, 255));
        mData.mPaintDragOff.setStrokeWidth(f4);
        mData.mPaintDragOff.setStrokeCap(Paint.Cap.ROUND);
        mData.mPaintDragMask.setStyle(Paint.Style.STROKE);
        mData.mPaintDragMask.setColor(-1);
        mData.mPaintDragMask.setStrokeWidth(f4);
        mData.mPaintDragMask.setStrokeCap(Paint.Cap.ROUND);
        mData.mPaintDragEdge.setStyle(Paint.Style.STROKE);
        mData.mPaintDragEdge.setColor(SupportMenu.CATEGORY_MASK);
        mData.mPaintDragEdge.setStrokeWidth(1.0f * f);
        mData.mPaintCropTapArea.setStyle(Paint.Style.STROKE);
        mData.mPaintCropTapArea.setColor(-1147154);
        mData.mPaintCropTapArea.setStrokeWidth(3.0f);
        mData.mPaintCropMovableArea.setStyle(Paint.Style.STROKE);
        mData.mPaintCropMovableArea.setColor(-16711681);
        mData.mPaintTextMessage.setTextAlign(Paint.Align.CENTER);
        mData.mPaintTextMessage.setTextSize(f * MESSAGE_TEXT_SIZE);
        mData.mPaintTextMessage.setColor(SupportMenu.CATEGORY_MASK);
        mData.mPaintTextMessage.setAntiAlias(true);
        mData.mPaintMessageArea.setStyle(Paint.Style.FILL_AND_STROKE);
        mData.mPaintMessageArea.setColor(-855638017);
        mData.mTimerCropImageCropCircle = new TimerCropImageCropCircle();
        mGestureDetector = new GestureDetector(context, onGestureDetectorListener);
        mScaleGestureDetector = new ScaleGestureDetector(context, onScaleGestureDetector);
        mPathEffectData = new PathEffectData(this);
    }

    public void SetViewMode(int i) {
        mViewMode = i;
        if (mViewMode == 3) {
            if (mData.f133d[mOrient].dca.mPointArray != null) {
                for (List<PointF> clear : mData.f133d[mOrient].dca.mPointArray) {
                    clear.clear();
                }
                mData.f133d[mOrient].dca.mPointArray.clear();
            }
            if (mBitmapImage != null) {
                Bitmap bitmap = mBitmapMask;
                if (bitmap != null) {
                    bitmap.recycle();
                }
                mBitmapMask = Bitmap.createBitmap(mBitmapImage.getWidth(), mBitmapImage.getHeight(), Bitmap.Config.ARGB_8888);
                mCanvasMask = new Canvas(mBitmapMask);
            }
        }
    }

    public void SetMessage(String str) {
        mData.mTextMessage = new String(str);
    }

    public void SetHandler(Handler handler) {
        mHandlerAvtivity = handler;
    }

    public void SetPreviewBitmapAndCropData(Bitmap bitmap, PointF[] pointFArr) {
        mGetCropPoint = true;
        if (pointFArr == null || pointFArr.length != 4) {
            for (int i = 0; i < 4; i++) {
                mData.mPointCrop[i].set(0.0f, 0.0f);
            }
        } else {
            mData.mPointCrop[0].set(pointFArr[0]);
            mData.mPointCrop[1].set(pointFArr[3]);
            mData.mPointCrop[2].set(pointFArr[2]);
            mData.mPointCrop[3].set(pointFArr[1]);
        }
        SetPreviewBitmap(bitmap);
    }

    public void SetPreviewBitmapAndCropData(Bitmap bitmap) {
        for (int i = 0; i < 4; i++) {
            mData.mPointCrop[i].set(0.0f, 0.0f);
        }
        SetPreviewBitmap(bitmap);
    }

    private void SetPreviewBitmap(Bitmap bitmap) {
        if (mBitmapImage != null) {
            ReleaseBitmap();
        }
        mBitmapImage = bitmap;
        ResetScalePos(false);
        invalidate();
    }

    public List<List<PointF>> GetBcscPointArray() {
        return ClontPointArray(mData.f133d[mOrient].dca.mPointArray);
    }

    public float GetBcscScale() {
        return mData.f133d[mOrient].mBaseScale[1];
    }

    public float GetBcscStrokeWidth() {
        return mData.mStrokeWidth;
    }

    public Bitmap GetMaskImage() {
        return mBitmapMask;
    }

    public void SetMaskEdge(List<List<PointF>> list) {
        mData.f133d[mOrient].dca.mPointEdgeArray.clear();
        for (List<PointF> next : list) {
            if (next.size() > 0) {
                ArrayList arrayList = new ArrayList();
                for (PointF pointF : next) {
                    arrayList.add(new PointF(pointF.x * mData.f133d[mOrient].mBaseScale[1], pointF.y * mData.f133d[mOrient].mBaseScale[1]));
                }
                mData.f133d[mOrient].dca.mPointEdgeArray.add(arrayList);
            }
        }
        invalidate();
    }

    public void MessageOff() {
        mData.mTimerOff();
    }

    public void ReleaseResource() {
        ReleaseBitmap();
        ReleaseMask();
        PathEffectData pathEffectData = mPathEffectData;
        if (pathEffectData != null) {
            Cleanup();
        }
    }

    public void ReleaseBitmap() {
        for (int i = 0; i < 2; i++) {
            for (int i2 = 0; i2 < mData.f133d[i].ddp.length; i2++) {
                if (mData.f133d[i].ddp[i2].mBitmapDrawable != null) {
                    mData.f133d[i].ddp[i2].mBitmapDrawable = null;
                }
            }
        }
        mBitmapImage = null;
    }

    public void ReleaseMask() {
        Bitmap bitmap = mBitmapMask;
        if (bitmap != null) {
            bitmap.recycle();
            mBitmapMask = null;
            mCanvasMask = null;
        }
    }

    public PointF[] GetCropPoint() {
        PointF[] pointFArr = new PointF[4];
        PointF[] pointFArr2 = new PointF[4];
        for (int i = 0; i < 4; i++) {
            pointFArr2[i] = new PointF();
            pointFArr2[i].x = (mData.f133d[mOrient].dcm.mPointPreviewCrop[i].x - mData.f133d[mOrient].mPointPreviewImageOffset.x) / mData.f133d[mOrient].mBaseScale[1];
            pointFArr2[i].y = (mData.f133d[mOrient].dcm.mPointPreviewCrop[i].y - mData.f133d[mOrient].mPointPreviewImageOffset.y) / mData.f133d[mOrient].mBaseScale[1];
        }
        float width = (float) mBitmapImage.getWidth();
        float height = (float) mBitmapImage.getHeight();
        if (pointFArr2[0].x < 0.0f) {
            pointFArr2[0].x = 0.0f;
        }
        if (pointFArr2[0].y < 0.0f) {
            pointFArr2[0].y = 0.0f;
        }
        if (pointFArr2[1].x > width) {
            pointFArr2[1].x = width;
        }
        if (pointFArr2[1].y < 0.0f) {
            pointFArr2[1].y = 0.0f;
        }
        if (pointFArr2[2].x > width) {
            pointFArr2[2].x = width;
        }
        if (pointFArr2[2].y > height) {
            pointFArr2[2].y = height;
        }
        if (pointFArr2[3].x < 0.0f) {
            pointFArr2[3].x = 0.0f;
        }
        if (pointFArr2[3].y > height) {
            pointFArr2[3].y = height;
        }
        pointFArr[0] = pointFArr2[0];
        pointFArr[1] = pointFArr2[3];
        pointFArr[2] = pointFArr2[2];
        pointFArr[3] = pointFArr2[1];
        return pointFArr;
    }

    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        int i5;
        Context context = mContext;
        if (context != null) {
            int rotation = ((Activity) context).getWindowManager().getDefaultDisplay().getRotation();
            i5 = (rotation == 1 || rotation == 3) ? 1 : 0;
        } else {
            i5 = 0;
        }
        boolean z = (i3 == 0 || mOrient == i5) ? false : true;
        mOrient = i5;
        Data data = mData;
        if (data != null && data.f133d != null && mData.f133d[mOrient].mRectView != null) {
            boolean z2 = (!z && mData.f133d[mOrient].mRectView.right == ((float) i) && mData.f133d[mOrient].mRectView.bottom == ((float) i2)) ? false : true;
            mData.f133d[mOrient].mRectView.set(0.0f, 0.0f, (float) i, (float) i2);
            float f = mData.mPointViewMargine[mViewMode].x;
            float f2 = mData.mPointViewMargine[mViewMode].y;
            mData.f133d[mOrient].mRectImageArea.set(mData.f133d[mOrient].mRectView.left + f, mData.f133d[mOrient].mRectView.top + f2, mData.f133d[mOrient].mRectView.right - f, mData.f133d[mOrient].mRectView.bottom - f2);
            float f3 = mData.f133d[z ? INVERT[mOrient] : mOrient].mBaseScale[1];
            GetPreviewImage();
            float f4 = mData.f133d[mOrient].mBaseScale[1] / f3;
            if (z) {
                int i6 = mViewMode;
                if (i6 == 0) {
                    if (mGetCropPoint && mData.f133d[INVERT[mOrient]].dcm.mPointPreviewCrop[3].y != 0.0f) {
                        for (int i7 = 0; i7 < 4; i7++) {
                            mData.f133d[mOrient].dcm.mPointPreviewCrop[i7].x = ((mData.f133d[INVERT[mOrient]].dcm.mPointPreviewCrop[i7].x - mData.f133d[INVERT[mOrient]].mPointPreviewImageOffset.x) * f4) + mData.f133d[mOrient].mPointPreviewImageOffset.x;
                            mData.f133d[mOrient].dcm.mPointPreviewCrop[i7].y = ((mData.f133d[INVERT[mOrient]].dcm.mPointPreviewCrop[i7].y - mData.f133d[INVERT[mOrient]].mPointPreviewImageOffset.y) * f4) + mData.f133d[mOrient].mPointPreviewImageOffset.y;
                        }
                        DataCropImage dataCropImage = mData.f133d[mOrient].dcm;
                        mData.f133d[INVERT[mOrient]].dcm.mSelectArea = -1;
                        dataCropImage.mSelectArea = -1;
                    }
                } else if (i6 == 1) {
                    mData.f133d[mOrient].ddp[mViewMode].mScale[1] = mData.f133d[INVERT[mOrient]].ddp[mViewMode].mScale[1];
                    mData.f133d[mOrient].ddp[mViewMode].mScale[0] = mData.f133d[INVERT[mOrient]].ddp[mViewMode].mScale[0];
                    mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].x = mData.f133d[INVERT[mOrient]].ddp[mViewMode].mPointMoveDeff[1].x * f4;
                    mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].y = mData.f133d[INVERT[mOrient]].ddp[mViewMode].mPointMoveDeff[1].y * f4;
                    mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[0].x = mData.f133d[INVERT[mOrient]].ddp[mViewMode].mPointMoveDeff[0].x * f4;
                    mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[0].y = mData.f133d[INVERT[mOrient]].ddp[mViewMode].mPointMoveDeff[0].y * f4;
                    DrawPreviewImageCalcMatrix(new Matrix());
                    DrawPreviewImagePointCheck(true);
                }
            }
            if (z2 && f4 != 0.0f && mViewMode == 3) {
                if (z) {
                    mData.f133d[mOrient].dca.mPointArray = ClontPointArray(mData.f133d[INVERT[mOrient]].dca.mPointArray);
                    mData.f133d[mOrient].dca.mPointEdgeArray = ClontPointArray(mData.f133d[INVERT[mOrient]].dca.mPointEdgeArray);
                }
                if (mData.f133d[mOrient].dca.mPointArray != null) {
                    for (List<PointF> it : mData.f133d[mOrient].dca.mPointArray) {
                        for (PointF pointF : it) {
                            pointF.x *= f4;
                            pointF.y *= f4;
                        }
                    }
                }
                if (mData.f133d[mOrient].dca.mPointEdgeArray != null) {
                    for (List<PointF> it2 : mData.f133d[mOrient].dca.mPointEdgeArray) {
                        for (PointF pointF2 : it2) {
                            pointF2.x *= f4;
                            pointF2.y *= f4;
                        }
                    }
                }
            }
        }
    }

    private List<List<PointF>> ClontPointArray(List<List<PointF>> list) {
        ArrayList arrayList = new ArrayList();
        if (list != null) {
            for (List<PointF> it : list) {
                ArrayList arrayList2 = new ArrayList();
                for (PointF add : it) {
                    arrayList2.add(add);
                }
                arrayList.add(arrayList2);
            }
        }
        return arrayList;
    }

    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Data data = mData;
        if (data != null && data.f133d != null) {
            GetPreviewImage();
            int i = mViewMode;
            if (i == 0) {
                DrawCropImage(canvas);
            } else if (i == 1) {
                DrawEnhanceText(canvas);
            } else if (i == 2) {
                DrawColorAdjustmentAll(canvas);
            } else if (i == 3) {
                DrawColorAdjustmentPart(canvas);
            }
        }
    }

    private void DrawCropImage(Canvas canvas) {
        DrawPreviewImage(canvas);
        GetPreviewCropPoint();
        if (mData.f133d[mOrient].dcm.mPointPreviewCrop[3].y != 0.0f) {
            canvas.drawLine(mData.f133d[mOrient].dcm.mPointPreviewCrop[0].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[0].y, mData.f133d[mOrient].dcm.mPointPreviewCrop[1].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[1].y, mData.mPaintCropLine);
            canvas.drawLine(mData.f133d[mOrient].dcm.mPointPreviewCrop[1].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[1].y, mData.f133d[mOrient].dcm.mPointPreviewCrop[2].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[2].y, mData.mPaintCropLine);
            canvas.drawLine(mData.f133d[mOrient].dcm.mPointPreviewCrop[2].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[2].y, mData.f133d[mOrient].dcm.mPointPreviewCrop[3].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[3].y, mData.mPaintCropLine);
            canvas.drawLine(mData.f133d[mOrient].dcm.mPointPreviewCrop[3].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[3].y, mData.f133d[mOrient].dcm.mPointPreviewCrop[0].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[0].y, mData.mPaintCropLine);
            for (int i = 0; i < 4; i++) {
                if (i == mData.f133d[mOrient].dcm.mSelectArea) {
                    canvas.drawCircle(mData.f133d[mOrient].dcm.mPointPreviewCrop[i].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[i].y, mData.mRadiusCropCircle, mData.mPaintCropCircleSelect);
                } else {
                    canvas.drawCircle(mData.f133d[mOrient].dcm.mPointPreviewCrop[i].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[i].y, mData.mRadiusCropCircle, mData.mPaintCropCircleDeselected);
                }
            }
        }
    }

    private void DrawEnhanceText(Canvas canvas) {
        DrawPreviewImage(canvas);
    }

    private void DrawColorAdjustmentAll(Canvas canvas) {
        DrawPreviewImage(canvas);
        mData.mPaintDragEdge.setPathEffect(mBlinkingIndex((RectF) null));
        canvas.drawRect(mData.f133d[mOrient].mRectPreviewImage, mData.mPaintDragEdge);
    }

    private void DrawColorAdjustmentPart(Canvas canvas) {
        DrawPreviewImage(canvas);
        float f = mData.f133d[mOrient].mRectPreviewImage.left;
        float f2 = mData.f133d[mOrient].mRectPreviewImage.top;
        float f3 = mData.f133d[mOrient].mBaseScale[1];
        Path path = new Path();
        Path path2 = new Path();
        mData.mPaintDragOn.setStrokeWidth(mData.mStrokeWidth * f3);
        for (List next : mData.f133d[mOrient].dca.mPointArray) {
            if (next.size() > 0) {
                PointF pointF = (PointF) next.get(0);
                if (next.size() > 1) {
                    path.moveTo(pointF.x + f, pointF.y + f2);
                    path2.moveTo(pointF.x / f3, pointF.y / f3);
                    for (int i = 1; i < next.size(); i++) {
                        PointF pointF2 = (PointF) next.get(i);
                        path.lineTo(pointF2.x + f, pointF2.y + f2);
                        path2.lineTo(pointF2.x / f3, pointF2.y / f3);
                    }
                }
            }
        }
        if (mData.mTouchState == 0) {
            int size = mData.f133d[mOrient].dca.mPointMoveArray.size();
            if (size > 0) {
                PointF pointF3 = mData.f133d[mOrient].dca.mPointMoveArray.get(0);
                if (size > 1) {
                    path.moveTo(pointF3.x + f, pointF3.y + f2);
                    for (int i2 = 1; i2 < size; i2++) {
                        PointF pointF4 = mData.f133d[mOrient].dca.mPointMoveArray.get(i2);
                        path.lineTo(pointF4.x + f, pointF4.y + f2);
                    }
                }
            }
            if (!path.isEmpty()) {
                canvas.drawPath(path, mData.mPaintDragOn);
            }
        } else if (path.isEmpty()) {
        } else {
            if (mData.mTouchState == 1) {
                mData.mTouchState = -1;
                if (mCanvasMask != null) {
                    if (!path2.isEmpty()) {
                        mCanvasMask.drawPath(path2, mData.mPaintDragMask);
                    }
                    mHandlerAvtivity.sendEmptyMessage(301);
                }
            } else if (mData.f133d[mOrient].dca.mPointEdgeArray != null && !mData.f133d[mOrient].dca.mPointEdgeArray.isEmpty()) {
                Path path3 = new Path();
                mData.mPaintDragEdge.setPathEffect(mBlinkingIndex((RectF) null));
                for (List next2 : mData.f133d[mOrient].dca.mPointEdgeArray) {
                    if (next2.size() > 0) {
                        PointF pointF5 = (PointF) next2.get(0);
                        float f4 = pointF5.x + f;
                        float f5 = pointF5.y + f2;
                        path3.moveTo(f4, f5);
                        for (int i3 = 1; i3 < next2.size(); i3++) {
                            PointF pointF6 = (PointF) next2.get(i3);
                            path3.lineTo(pointF6.x + f, pointF6.y + f2);
                        }
                        path3.lineTo(f4, f5);
                    }
                    canvas.drawPath(path3, mData.mPaintDragEdge);
                    path3.reset();
                }
            }
        }
    }

    private void DrawPreviewImage(Canvas canvas) {
        if (mBitmapImage != null) {
            BitmapDrawable bitmapDrawable = mData.f133d[mOrient].ddp[mViewMode].mBitmapDrawable;
            if (bitmapDrawable == null) {
                bitmapDrawable = DrawPreviewImageGetDrawable(mBitmapImage, mData.f133d[mOrient].ddp[mViewMode].mRectBitmap);
                mData.f133d[mOrient].ddp[mViewMode].mBitmapDrawable = bitmapDrawable;
            }
            if (bitmapDrawable != null && DrawPreviewImageGetMatrix(mData.f133d[mOrient].ddp[mViewMode].mMatrixBitmap)) {
                canvas.save();
                canvas.concat(mData.f133d[mOrient].ddp[mViewMode].mMatrixBitmap);
                bitmapDrawable.draw(canvas);
                canvas.restore();
            }
        }
    }

    private BitmapDrawable DrawPreviewImageGetDrawable(Bitmap bitmap, RectF rectF) {
        if (bitmap == null) {
            return null;
        }
        BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);
        rectF.set(0.0f, 0.0f, (float) bitmap.getWidth(), (float) bitmap.getHeight());
        bitmapDrawable.setBounds(new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()));
        return bitmapDrawable;
    }

    private boolean DrawPreviewImageGetMatrix(Matrix matrix) {
        DrawPreviewImageCalcMatrix(matrix);
        if (mViewMode == 1 && DrawPreviewImagePointCheck(mData.mFlagScale)) {
            DrawPreviewImageCalcMatrix(matrix);
        }
        return true;
    }

    private boolean DrawPreviewImagePointCheck(boolean z) {
        boolean z2;
        boolean z3;
        boolean z4;
        float f;
        float f2;
        if (z) {
            if (mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.width() < mData.f133d[mOrient].mRectView.width()) {
                f = (mData.f133d[mOrient].mRectView.left + ((mData.f133d[mOrient].mRectView.width() - mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.width()) / 2.0f)) - mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.left;
            } else {
                f = mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.left > mData.f133d[mOrient].mRectView.left ? mData.f133d[mOrient].mRectView.left - mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.left : 0.0f;
                if (mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.right < mData.f133d[mOrient].mRectView.right) {
                    f = mData.f133d[mOrient].mRectView.right - mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.right;
                }
            }
            if (mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.height() < mData.f133d[mOrient].mRectView.height()) {
                f2 = (mData.f133d[mOrient].mRectView.top + ((mData.f133d[mOrient].mRectView.height() - mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.height()) / 2.0f)) - mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.top;
            } else {
                f2 = mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.top > mData.f133d[mOrient].mRectView.top ? mData.f133d[mOrient].mRectView.top - mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.top : 0.0f;
                if (mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.bottom < mData.f133d[mOrient].mRectView.bottom) {
                    f2 = mData.f133d[mOrient].mRectView.bottom - mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.bottom;
                }
            }
            if (f == 0.0f && f2 == 0.0f) {
                return false;
            }
            PointF pointF = mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[0];
            PointF pointF2 = mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1];
            float f3 = mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].x + f;
            pointF2.x = f3;
            pointF.x = f3;
            PointF pointF3 = mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[0];
            PointF pointF4 = mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1];
            float f4 = mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].y + f2;
            pointF4.y = f4;
            pointF3.y = f4;
            return true;
        }
        if (mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.width() < mData.f133d[mOrient].mRectView.width()) {
            mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[0].x = 0.0f;
            z2 = true;
        } else {
            z2 = mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.left > mData.f133d[mOrient].mRectView.left;
            if (mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.right < mData.f133d[mOrient].mRectView.right) {
                z2 = true;
            }
        }
        if (mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.height() < mData.f133d[mOrient].mRectView.height()) {
            mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[0].y = 0.0f;
            z3 = true;
        } else {
            z3 = mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.top > mData.f133d[mOrient].mRectView.top;
            if (mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.bottom < mData.f133d[mOrient].mRectView.bottom) {
                z3 = true;
            }
        }
        if (z2) {
            mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].x = mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[0].x;
            z4 = true;
        } else {
            mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[0].x = mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].x;
            z4 = false;
        }
        if (z3) {
            mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].y = mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[0].y;
            return true;
        }
        mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[0].y = mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].y;
        return z4;
    }

    private void DrawPreviewImageCalcMatrix(Matrix matrix) {
        matrix.reset();
        float f = mData.f133d[mOrient].ddp[mViewMode].mScale[1] * mData.f133d[mOrient].mBaseScale[1];
        matrix.postScale(f, f);
        matrix.postTranslate(mData.f133d[mOrient].ddp[mViewMode].mPointInitOffset.x, mData.f133d[mOrient].ddp[mViewMode].mPointInitOffset.y);
        mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.set(0.0f, 0.0f, mData.f133d[mOrient].ddp[mViewMode].mRectBitmap.width(), mData.f133d[mOrient].ddp[mViewMode].mRectBitmap.height());
        matrix.mapRect(mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale);
        float f2 = -(((mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.height() - mData.f133d[mOrient].mRectImageArea.height()) / 2.0f) - (mData.f133d[mOrient].mRectImageArea.top - mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.top));
        matrix.postTranslate(mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].x + (-(((mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.width() - mData.f133d[mOrient].mRectImageArea.width()) / 2.0f) - (mData.f133d[mOrient].mRectImageArea.left - mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.left))), mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].y + f2);
        mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale.set(0.0f, 0.0f, mData.f133d[mOrient].ddp[mViewMode].mRectBitmap.width(), mData.f133d[mOrient].ddp[mViewMode].mRectBitmap.height());
        matrix.mapRect(mData.f133d[mOrient].ddp[mViewMode].mRectDrawScale);
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        int i = mViewMode;
        if (i == 0) {
            TouchEventCropImage(motionEvent);
        } else if (i == 1) {
            TouchEventEnhanceText(motionEvent);
        } else if (i == 2) {
            TouchEventColorAdjustmentAll(motionEvent);
        } else if (i == 3) {
            TouchEventColorAdjustmentPart(motionEvent);
        }
        return true;
    }

    private void TouchEventCropImage(MotionEvent motionEvent) {
        int TouchEventCropImageHitCheck;
        switch (motionEvent.getAction() & 255) {
            case 0:
                float x = motionEvent.getX();
                float y = motionEvent.getY();
                mData.mTimerOff();
                int TouchEventCropImageHitCheck2 = TouchEventCropImageHitCheck(x, y, true);
                if (TouchEventCropImageHitCheck2 > -1) {
                    mData.f133d[mOrient].dcm.mPointPreviewTouch.set(x, y);
                    mData.f133d[mOrient].dcm.mSelectArea = TouchEventCropImageHitCheck2;
                    return;
                } else if (mData.f133d[mOrient].dcm.mSelectArea > -1 && (TouchEventCropImageHitCheck = TouchEventCropImageHitCheck(x, y, false)) > -1) {
                    mData.mTimerOn(this);
                    mData.f133d[mOrient].dcm.mPointPreviewTouch.set(x, y);
                    mData.f133d[mOrient].dcm.mSelectArea = TouchEventCropImageHitCheck;
                    return;
                } else {
                    return;
                }
            case 1:
            case 3:
                if (mData.f133d[mOrient].dcm.mSelectArea > -1) {
                    mData.mTimerOn(this);
                    return;
                }
                return;
            case 2:
                int i = mData.f133d[mOrient].dcm.mSelectArea;
                if (i > -1) {
                    float x2 = motionEvent.getX();
                    float y2 = motionEvent.getY();
                    float f = mData.f133d[mOrient].dcm.mPointPreviewCrop[i].x + (x2 - mData.f133d[mOrient].dcm.mPointPreviewTouch.x);
                    float f2 = mData.f133d[mOrient].dcm.mPointPreviewCrop[i].y + (y2 - mData.f133d[mOrient].dcm.mPointPreviewTouch.y);
                    if (!mData.f133d[mOrient].dcm.mRectCropMovableArea[i].contains(f, f2)) {
                        if (f < mData.f133d[mOrient].dcm.mRectCropMovableArea[i].left) {
                            f = mData.f133d[mOrient].dcm.mRectCropMovableArea[i].left;
                        }
                        if (f2 < mData.f133d[mOrient].dcm.mRectCropMovableArea[i].top) {
                            f2 = mData.f133d[mOrient].dcm.mRectCropMovableArea[i].top;
                        }
                        if (f > mData.f133d[mOrient].dcm.mRectCropMovableArea[i].right) {
                            f = mData.f133d[mOrient].dcm.mRectCropMovableArea[i].right;
                        }
                        if (f2 > mData.f133d[mOrient].dcm.mRectCropMovableArea[i].bottom) {
                            f2 = mData.f133d[mOrient].dcm.mRectCropMovableArea[i].bottom;
                        }
                    }
                    mData.f133d[mOrient].dcm.mPointPreviewCrop[i].x = f;
                    mData.f133d[mOrient].dcm.mPointPreviewCrop[i].y = f2;
                    mData.f133d[mOrient].dcm.mPointPreviewTouch.x = x2;
                    mData.f133d[mOrient].dcm.mPointPreviewTouch.y = y2;
                    invalidate();
                    return;
                }
                return;
            default:
                return;
        }
    }

    private int TouchEventCropImageHitCheck(float f, float f2, boolean z) {
        int i = 3;
        while (i > -1) {
            RectF rectF = new RectF();
            Path path = new Path();
            path.addCircle(mData.f133d[mOrient].dcm.mPointPreviewCrop[i].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[i].y, mData.mRadiusCropCircle, Path.Direction.CW);
            path.computeBounds(rectF, true);
            Region region = new Region();
            region.setPath(path, new Region(rectF.left, rectF.top, rectF.right, rectF.bottom));
            boolean contains = region.contains(Math.round(f), Math.round(f2));
            if (!contains) {
                if (z) {
                    contains = mData.f133d[mOrient].dcm.mRectCropMovableArea[i].contains(f, f2);
                } else {
                    contains = mData.f133d[mOrient].dcm.mRectCropTapArea[i].contains(f, f2);
                }
            }
            if (contains) {
                break;
            }
            i--;
        }
        return i;
    }

    private void TouchEventEnhanceText(MotionEvent motionEvent) {
        int action = motionEvent.getAction() & 255;
        int pointerCount = motionEvent.getPointerCount();
        if (action != 5) {
            switch (action) {
                case 0:
                    if (!mData.mFlagScale) {
                        mData.f133d[mOrient].ddp[mViewMode].mPointMovePoint.set(motionEvent.getX(), motionEvent.getY());
                        break;
                    }
                    break;
                case 1:
                case 3:
                    boolean unused = mData.mFlagScale = false;
                    break;
                case 2:
                    if (!mData.mFlagScale) {
                        float x = motionEvent.getX();
                        float y = motionEvent.getY();
                        mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].x += x - mData.f133d[mOrient].ddp[mViewMode].mPointMovePoint.x;
                        mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].y += y - mData.f133d[mOrient].ddp[mViewMode].mPointMovePoint.y;
                        mData.f133d[mOrient].ddp[mViewMode].mPointMovePoint.x = x;
                        mData.f133d[mOrient].ddp[mViewMode].mPointMovePoint.y = y;
                        invalidate();
                        break;
                    }
                    break;
            }
        } else {
            boolean unused2 = mData.mFlagScale = true;
        }
        if (pointerCount == 1) {
            mGestureDetector.onTouchEvent(motionEvent);
        }
        if (pointerCount >= 2) {
            try {
                mScaleGestureDetector.onTouchEvent(motionEvent);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
        }
    }

    private void TouchEventColorAdjustmentPart(MotionEvent motionEvent) {
        int action = motionEvent.getAction() & 255;
        float x = motionEvent.getX();
        float y = motionEvent.getY();
        float f = mData.f133d[mOrient].mRectPreviewImage.left;
        float f2 = mData.f133d[mOrient].mRectPreviewImage.top;
        float f3 = x - f;
        float f4 = y - f2;
        switch (action) {
            case 0:
                Data data = mData;
                data.mTouchState = 0;
                data.f133d[mOrient].dca.mPointMoveArray.clear();
                mData.f133d[mOrient].dca.mPointMoveArray.add(new PointF(f3, f4));
                return;
            case 1:
            case 3:
                if (mData.f133d[mOrient].dca.mPointMoveArray.size() > 0) {
                    ArrayList arrayList = new ArrayList();
                    for (PointF next : mData.f133d[mOrient].dca.mPointMoveArray) {
                        if (mData.f133d[mOrient].mRectPreviewImage.contains(next.x + f, next.y + f2)) {
                            arrayList.add(next);
                        }
                    }
                    if (arrayList.size() > 0) {
                        if (arrayList.size() == 1) {
                            float f5 = ((PointF) arrayList.get(0)).x;
                            float f6 = ((PointF) arrayList.get(0)).y;
                            arrayList.clear();
                            float f7 = f5 - 1.0f;
                            float f8 = f6 - 1.0f;
                            arrayList.add(new PointF(f7, f8));
                            arrayList.add(new PointF(f5, f8));
                            float f9 = f5 + 1.0f;
                            arrayList.add(new PointF(f9, f8));
                            arrayList.add(new PointF(f9, f6));
                            float f10 = 1.0f + f6;
                            arrayList.add(new PointF(f9, f10));
                            arrayList.add(new PointF(f5, f10));
                            arrayList.add(new PointF(f7, f10));
                            arrayList.add(new PointF(f7, f6));
                        }
                        mData.f133d[mOrient].dca.mPointArray.add(arrayList);
                    }
                    mData.f133d[mOrient].dca.mPointMoveArray.clear();
                }
                mData.mTouchState = 1;
                invalidate();
                return;
            case 2:
                mData.f133d[mOrient].dca.mPointMoveArray.add(new PointF(f3, f4));
                invalidate();
                return;
            default:
                return;
        }
    }

    private void SetScale(float f) {
        mData.f133d[mOrient].ddp[mViewMode].mScale[0] = mData.f133d[mOrient].ddp[mViewMode].mScale[1];
        float f2 = mData.f133d[mOrient].ddp[mViewMode].mScale[1] * f;
        if (f2 < 1.0f) {
            mData.f133d[mOrient].ddp[mViewMode].mScale[1] = 1.0f;
        } else if (f2 > SCALE_RANGE_MAX) {
            mData.f133d[mOrient].ddp[mViewMode].mScale[1] = 4.0f;
        } else {
            mData.f133d[mOrient].ddp[mViewMode].mScale[1] = f2;
        }
    }

    private void ResetScalePos(boolean z) {
        if (z || mViewMode != 1) {
            mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[0].set(0.0f, 0.0f);
            mData.f133d[mOrient].ddp[mViewMode].mPointMoveDeff[1].set(0.0f, 0.0f);
            float[] fArr = mData.f133d[mOrient].ddp[mViewMode].mScale;
            mData.f133d[mOrient].ddp[mViewMode].mScale[1] = 1.0f;
            fArr[0] = 1.0f;
        }
        if (mViewMode == 0) {
            mData.f133d[mOrient].ddp[1].mPointMoveDeff[0].set(0.0f, 0.0f);
            mData.f133d[mOrient].ddp[1].mPointMoveDeff[1].set(0.0f, 0.0f);
            float[] fArr2 = mData.f133d[mOrient].ddp[1].mScale;
            mData.f133d[mOrient].ddp[1].mScale[1] = 1.0f;
            fArr2[0] = 1.0f;
        }
    }

    private void GetPreviewImage() {
        Bitmap bitmap;
        Data data = mData;
        if (data != null && data.f133d != null && (bitmap = mBitmapImage) != null) {
            float width = (float) bitmap.getWidth();
            float height = (float) mBitmapImage.getHeight();
            float width2 = mData.f133d[mOrient].mRectImageArea.width() / width;
            float height2 = mData.f133d[mOrient].mRectImageArea.height() / height;
            if (width2 >= height2) {
                width2 = height2;
            }
            mData.f133d[mOrient].mBaseScale[1] = width2;
            mData.f133d[mOrient].mRectPreviewImage.set(0.0f, 0.0f, width * width2, height * width2);
            mData.f133d[mOrient].mPointPreviewImageOffset.set(mData.f133d[mOrient].mRectImageArea.left + ((mData.f133d[mOrient].mRectImageArea.width() - mData.f133d[mOrient].mRectPreviewImage.width()) / 2.0f), mData.f133d[mOrient].mRectImageArea.top + ((mData.f133d[mOrient].mRectImageArea.height() - mData.f133d[mOrient].mRectPreviewImage.height()) / 2.0f));
            mData.f133d[mOrient].mRectPreviewImage.offset(mData.f133d[mOrient].mPointPreviewImageOffset.x, mData.f133d[mOrient].mPointPreviewImageOffset.y);
            float width3 = mData.f133d[mOrient].mRectPreviewImage.width() / 2.0f;
            float height3 = mData.f133d[mOrient].mRectPreviewImage.height() / 2.0f;
            float width4 = mData.f133d[mOrient].mRectPreviewImage.width() * 0.05f;
            float f = mData.f133d[mOrient].mRectPreviewImage.left + width3;
            float f2 = mData.f133d[mOrient].mRectPreviewImage.top + height3;
            mData.f133d[mOrient].dcm.mRectCropMovableArea[0].set(mData.f133d[mOrient].mRectPreviewImage.left, mData.f133d[mOrient].mRectPreviewImage.top, (mData.f133d[mOrient].mRectPreviewImage.left + width3) - width4, (mData.f133d[mOrient].mRectPreviewImage.top + height3) - width4);
            mData.f133d[mOrient].dcm.mRectCropMovableArea[1].set((mData.f133d[mOrient].mRectPreviewImage.right - width3) + width4, mData.f133d[mOrient].mRectPreviewImage.top, mData.f133d[mOrient].mRectPreviewImage.right, (mData.f133d[mOrient].mRectPreviewImage.top + height3) - width4);
            mData.f133d[mOrient].dcm.mRectCropMovableArea[2].set((mData.f133d[mOrient].mRectPreviewImage.right - width3) + width4, (mData.f133d[mOrient].mRectPreviewImage.bottom - height3) + width4, mData.f133d[mOrient].mRectPreviewImage.right, mData.f133d[mOrient].mRectPreviewImage.bottom);
            mData.f133d[mOrient].dcm.mRectCropMovableArea[3].set(mData.f133d[mOrient].mRectPreviewImage.left, (mData.f133d[mOrient].mRectPreviewImage.bottom - height3) + width4, (mData.f133d[mOrient].mRectPreviewImage.left + width3) - width4, mData.f133d[mOrient].mRectPreviewImage.bottom);
            mData.f133d[mOrient].dcm.mRectCropTapArea[0].set(mData.f133d[mOrient].mRectView.left, mData.f133d[mOrient].mRectView.top, (mData.f133d[mOrient].mRectPreviewImage.left + width3) - width4, (mData.f133d[mOrient].mRectPreviewImage.top + height3) - width4);
            mData.f133d[mOrient].dcm.mRectCropTapArea[1].set((mData.f133d[mOrient].mRectPreviewImage.right - width3) + width4, mData.f133d[mOrient].mRectView.top, mData.f133d[mOrient].mRectView.right, (mData.f133d[mOrient].mRectPreviewImage.top + height3) - width4);
            mData.f133d[mOrient].dcm.mRectCropTapArea[2].set((mData.f133d[mOrient].mRectPreviewImage.right - width3) + width4, (mData.f133d[mOrient].mRectPreviewImage.bottom - height3) + width4, mData.f133d[mOrient].mRectView.right, mData.f133d[mOrient].mRectView.bottom);
            mData.f133d[mOrient].dcm.mRectCropTapArea[3].set(mData.f133d[mOrient].mRectView.left, (mData.f133d[mOrient].mRectPreviewImage.bottom - height3) + width4, (mData.f133d[mOrient].mRectPreviewImage.left + width3) - width4, mData.f133d[mOrient].mRectView.bottom);
            mData.f133d[mOrient].dcm.mRectCropTapArea[4].set(f - width4, f2 - width4, f + width4, f2 + width4);
            mData.f133d[mOrient].ddp[mViewMode].mPointInitOffset.x = mData.f133d[mOrient].mPointPreviewImageOffset.x;
            mData.f133d[mOrient].ddp[mViewMode].mPointInitOffset.y = mData.f133d[mOrient].mPointPreviewImageOffset.y;
        }
    }

    private void GetPreviewCropPoint() {
        boolean z;
        Data data = mData;
        if (data != null && data.f133d != null && mData.f133d[mOrient].dcm != null && mBitmapImage != null && mData.f133d[mOrient].dcm.mPointPreviewCrop[3].y == 0.0f) {
            if (mData.mPointCrop[3].y != 0.0f) {
                for (int i = 0; i < 4; i++) {
                    mData.f133d[mOrient].dcm.mPointPreviewCrop[i].x = (mData.mPointCrop[i].x * mData.f133d[mOrient].mBaseScale[1]) + mData.f133d[mOrient].mPointPreviewImageOffset.x;
                    mData.f133d[mOrient].dcm.mPointPreviewCrop[i].y = (mData.mPointCrop[i].y * mData.f133d[mOrient].mBaseScale[1]) + mData.f133d[mOrient].mPointPreviewImageOffset.y;
                }
                int i2 = 0;
                while (true) {
                    if (i2 >= 4) {
                        z = false;
                        break;
                    } else if (!mData.f133d[mOrient].dcm.mRectCropMovableArea[i2].contains(mData.f133d[mOrient].dcm.mPointPreviewCrop[i2].x, mData.f133d[mOrient].dcm.mPointPreviewCrop[i2].y)) {
                        z = true;
                        break;
                    } else {
                        i2++;
                    }
                }
            } else {
                z = true;
            }
            if (mGetCropPoint && z) {
                mData.f133d[mOrient].dcm.mPointPreviewCrop[0].x = mData.f133d[mOrient].mRectPreviewImage.left;
                mData.f133d[mOrient].dcm.mPointPreviewCrop[0].y = mData.f133d[mOrient].mRectPreviewImage.top;
                mData.f133d[mOrient].dcm.mPointPreviewCrop[1].x = mData.f133d[mOrient].mRectPreviewImage.right;
                mData.f133d[mOrient].dcm.mPointPreviewCrop[1].y = mData.f133d[mOrient].mRectPreviewImage.top;
                mData.f133d[mOrient].dcm.mPointPreviewCrop[2].x = mData.f133d[mOrient].mRectPreviewImage.right;
                mData.f133d[mOrient].dcm.mPointPreviewCrop[2].y = mData.f133d[mOrient].mRectPreviewImage.bottom;
                mData.f133d[mOrient].dcm.mPointPreviewCrop[3].x = mData.f133d[mOrient].mRectPreviewImage.left;
                mData.f133d[mOrient].dcm.mPointPreviewCrop[3].y = mData.f133d[mOrient].mRectPreviewImage.bottom;
            }
        }
    }

    /* renamed from: com.epson.cameracopy.ui.ImageCollectView$TimerCropImageTextMessage */
    class TimerCropImageTextMessage {
        private static final int CROP_IMAGE_TIMER_LIMIT = 5000;
        private static final int CROP_IMAGE_TIMER_TIME = 200;
        private static final int MSG_TIMER_CROP_IMAGE_TEXT_MESSAGE_TIMEOUT = 501;
        private boolean mBreak = false;
        private Handler mHandlerTimerCropImageTextMessage = new Handler() {
            public void handleMessage(Message message) {
                if (message.what == 501) {
                    mData.mShowTextMessage = false;
                    if (mView != null) {
                        mView.invalidate();
                    }
                }
            }
        };
        private Thread mThreadTimer = null;
        private View mView = null;

        TimerCropImageTextMessage() {
        }

        public void TimerOff() {
            Thread thread = mThreadTimer;
            if (thread != null && thread.isAlive()) {
                mBreak = true;
                do {
                } while (mThreadTimer.isAlive());
            }
        }

        public void Timer(View view) {
            mView = view;
            if (mThreadTimer == null) {
                mThreadTimer = new Thread(new Runnable() {
                    public void run() {
                        int i = 0;
                        while (true) {
                            if (i >= 25) {
                                break;
                            }
                            try {
                                if (mBreak) {
                                    break;
                                }
                                Thread.sleep(200);
                                i++;
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        if (mHandlerTimerCropImageTextMessage != null) {
                            mHandlersendEmptyMessage(501);
                        }
                    }
                });
                mThreadTimer.start();
            }
        }
    }

    /* renamed from: com.epson.cameracopy.ui.ImageCollectView$TimerCropImageCropCircle */
    class TimerCropImageCropCircle {
        private static final int MSG_TIMER_CROP_IMAGE_CROP_CIRCLE_TIMEOUT = 500;
        private boolean mBreak = false;
        private Handler mHandlerTimerCropImageCropCircle = new Handler() {
            public void handleMessage(Message message) {
                if (message.what == 500) {
                    mData.f133d[mOrient].dcm.mSelectArea = -1;
                    if (mView != null) {
                        mView.invalidate();
                    }
                }
            }
        };
        private long mNewTime;
        private long mStartTime;
        private Thread mTimer = null;
        private View mView = null;

        TimerCropImageCropCircle() {
        }

        public void TimerOn(View view) {
            Thread thread;
            mView = view;
            Thread thread2 = mTimer;
            if ((thread2 != null && !thread2.isAlive()) || (thread = mTimer) == null) {
                mStartTime = System.currentTimeMillis();
                Timer(2000);
            } else if (thread != null && thread.isAlive()) {
                mStartTime = System.currentTimeMillis();
            }
        }

        public void TimerOff() {
            Thread thread = mTimer;
            if (thread != null && thread.isAlive()) {
                mBreak = true;
                do {
                } while (mTimer.isAlive());
            }
        }

        private void Timer(final int i) {
            mBreak = false;
            mTimer = new Thread(new Runnable() {
                public void run() {
                    while (!mBreak) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        long unused = mNewTime = System.currentTimeMillis();
                        if (mStartTime + ((long) i) <= mNewTime) {
                            break;
                        }
                    }
                    if (!mBreak && mHandlerTimerCropImageCropCircle != null) {
                        mHandlersendEmptyMessage(500);
                    }
                }
            });
            mTimer.start();
        }
    }

    /* renamed from: com.epson.cameracopy.ui.ImageCollectView$PathEffectData */
    private class PathEffectData {
        private static final int BLINKING_TIME = 500;
        private static final int DEFAULT_BLINKING_DELAYTIMES = 200;
        private static final int MSG_INVALIDATE_VIEW = 901;
        private long mBlinkingDelayTimes = 200;
        private boolean mBreak = false;
        private Handler mHandlerPathEffectData = new Handler() {
            public void handleMessage(Message message) {
                if (message.what != MSG_INVALIDATE_VIEW || mView == null) {
                    return;
                }
                if (mRectDirty.isEmpty()) {
                    mView.invalidate();
                } else {
                    mView.invalidate(mRectDirty);
                }
            }
        };
        private long mNewTime;
        private int mPathEffectBlinkingIndex = 0;
        private long mPathEffectBlinkingTime = 0;
        private PathEffect[] mPathEffectList = new PathEffect[5];
        private Rect mRectDirty = new Rect(0, 0, 0, 0);
        private long mStartTime;
        private Thread mTimer = null;
        private View mView = null;

        public PathEffectData(View view) {
            mPathEffectList[0] = new DashPathEffect(new float[]{5.0f, 5.0f}, 8.0f);
            mPathEffectList[1] = new DashPathEffect(new float[]{5.0f, 5.0f}, VIEW_MARGINE);
            mPathEffectList[2] = new DashPathEffect(new float[]{5.0f, 5.0f}, SCALE_RANGE_MAX);
            mPathEffectList[3] = new DashPathEffect(new float[]{5.0f, 5.0f}, 2.0f);
            mPathEffectList[4] = new DashPathEffect(new float[]{5.0f, 5.0f}, 0.0f);
            mView = view;
        }

        public PathEffect BlinkingIndex(RectF rectF) {
            long currentTimeMillis = System.currentTimeMillis();
            if (mPathEffectBlinkingTime == 0) {
                mPathEffectBlinkingTime = currentTimeMillis;
                if (rectF != null) {
                    mRectDirty.left = rectF.left;
                    mRectDirty.top = rectF.top;
                    mRectDirty.right = (rectF.right + 1.0f);
                    mRectDirty.bottom = (rectF.bottom + 1.0f);
                } else {
                    mRectDirty.setEmpty();
                }
            }
            BlinkOn(0);
            if (mPathEffectBlinkingTime + mBlinkingDelayTimes < currentTimeMillis) {
                int i = mPathEffectBlinkingIndex;
                if (i < mPathEffectList.length - 1) {
                    mPathEffectBlinkingIndex = i + 1;
                } else {
                    mPathEffectBlinkingIndex = 0;
                }
                mPathEffectBlinkingTime = currentTimeMillis;
            }
            return mPathEffectList[mPathEffectBlinkingIndex];
        }

        public void Cleanup() {
            Thread thread = mTimer;
            if (thread == null || !thread.isAlive()) {
                mTimer = null;
                mView = null;
                mPathEffectList = null;
            }
            mBreak = true;
            do {
            } while (mTimer.isAlive());
            mTimer = null;
            mView = null;
            mPathEffectList = null;
        }

        private void BlinkOn(int i) {
            Thread thread;
            Thread thread2 = mTimer;
            if ((thread2 != null && !thread2.isAlive()) || (thread = mTimer) == null) {
                mStartTime = System.currentTimeMillis();
                Timer(500);
            } else if (thread != null && thread.isAlive()) {
                mStartTime = System.currentTimeMillis();
            }
        }

        private void Timer(final int i) {
            mBreak = false;
            mTimer = new Thread(new Runnable() {
                public void run() {
                    while (!mBreak) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        long unused = mNewTime = System.currentTimeMillis();
                        mHandlersendEmptyMessage(MSG_INVALIDATE_VIEW);
                        if (mStartTime + ((long) i) <= mNewTime) {
                            return;
                        }
                    }
                }
            });
            mTimer.start();
        }
    }
}
