package epson.scan.activity;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.os.Handler;
import android.support.p000v4.view.ViewCompat;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import epson.common.Constants;
import epson.common.Utils;
import epson.print.ActivityIACommon;
import epson.print.C2135R;
import epson.print.Util.EPLog;
import epson.scan.lib.escanLib;
import java.util.ArrayList;
import java.util.Locale;

public class ScanBaseView extends ActivityIACommon {
    public static int SCAN_AREA_HOTSPOT_SIZE = 40;
    private static final int SCAN_REDRAWBITMAP = -100;
    private static final String TAG = "ScanBaseView";
    public final int LINE_AREA_BORDER = 2;
    public final int LINE_CORNER_BIG = 18;
    public final int LINE_CORNER_BIG_WIDTH = 150;
    public final int LINE_CORNER_SMALL = 6;
    public final int LINE_CORNER_SMALL_WIDTH = 60;
    public final int MARGIN_LEFT_RIGHT = 10;
    public int MARGIN_TOP_BOT = 60;
    final int MAX_DASHEFFECT_PHASE;
    public final int SCREEN_STATUS_BOTLEFT_TOPRIGHT = 2;
    public final int SCREEN_STATUS_BOTRIGHT_TOPLEFT = 3;
    public final int SCREEN_STATUS_TOPLEFT_BOTRIGHT = 1;
    public final int SCREEN_STATUS_TOPRIGHT_BOTLEFT = 4;
    /* access modifiers changed from: private */
    public BitmapFactory.Options _bmOption;
    public boolean bLongTouch = false;
    public Bitmap bmCenter;
    private RectF bmRectF;
    Context context;
    int curentViewingFile;
    escanLib escan;
    private PointInfo first;
    /* access modifiers changed from: private */
    public int inSampleSize;
    /* access modifiers changed from: private */
    public boolean isDisplayResult;
    public boolean isDoctable = false;
    /* access modifiers changed from: private */
    public boolean isSetSize = false;
    private boolean isValidArea;
    private ArrayList<String> listSavedJPGFilePath;
    private Point mBaseBot;
    private Point mBaseTop;
    private Bitmap mBitmap;
    Point mBot;
    Point mCenter;
    Point mFirstTouch;
    private Paint mPaint;
    Point mTop;
    Point mTouch;
    int mWhere;
    private double maxScanHeightOnScreen = 0.0d;
    private double maxScanWidthOnScreen = 0.0d;
    private int maxheight = 0;
    private int maxwidth = 0;
    int phase;
    private PointInfo piBaseBot;
    private PointInfo piBaseTop;
    private RectF rectScanArea;
    private double scale;
    /* access modifiers changed from: private */
    public int screenStatus = 1;
    private PointInfo second;
    int totalScanned;

    class PointInfo {
        /* access modifiers changed from: private */

        /* renamed from: x */
        public double f411x = 0.0d;
        /* access modifiers changed from: private */

        /* renamed from: y */
        public double f412y = 0.0d;

        public PointInfo(double d, double d2) {
            this.f411x = d;
            this.f412y = d2;
        }

        public double getX() {
            return this.f411x;
        }

        public void setX(double d) {
            this.f411x = d;
        }

        public double getY() {
            return this.f412y;
        }

        public void setY(double d) {
            this.f412y = d;
        }

        public String toString() {
            return String.format(Locale.US, "(%.2f,%.2f)", new Object[]{Double.valueOf(this.f411x), Double.valueOf(this.f412y)});
        }
    }

    public PointInfo getPiBaseTop() {
        return this.piBaseTop;
    }

    public void setPiBaseTop(PointInfo pointInfo) {
        this.piBaseTop = pointInfo;
    }

    public PointInfo getPiBaseBot() {
        return this.piBaseBot;
    }

    public void setPiBaseBot(PointInfo pointInfo) {
        this.piBaseBot = pointInfo;
    }

    public Context getContext() {
        return this.context;
    }

    public void setContext(Context context2) {
        this.context = context2;
    }

    public Point getmBaseTop() {
        return this.mBaseTop;
    }

    public void setmBaseTop(Point point) {
        this.mBaseTop = point;
    }

    public Point getmBaseBot() {
        return this.mBaseBot;
    }

    public void setmBaseBot(Point point) {
        this.mBaseBot = point;
    }

    public RectF getRectScanArea() {
        return this.rectScanArea;
    }

    public void setRectScanArea(RectF rectF) {
        this.rectScanArea = rectF;
    }

    public escanLib getEscan() {
        return this.escan;
    }

    public void setEscan(escanLib escanlib) {
        this.escan = escanlib;
    }

    public double getScale() {
        return this.scale;
    }

    public void setScale(double d) {
        this.scale = d;
    }

    public int getMaxwidth() {
        return this.maxwidth;
    }

    public void setMaxwidth(int i) {
        this.maxwidth = i;
    }

    public int getMaxheight() {
        return this.maxheight;
    }

    public void setMaxheight(int i) {
        this.maxheight = i;
    }

    public Point getmTop() {
        return this.mTop;
    }

    public void setmTop(Point point) {
        this.mTop = point;
    }

    public Point getmBot() {
        return this.mBot;
    }

    public void setmBot(Point point) {
        this.mBot = point;
    }

    public Point getmCenter() {
        return this.mCenter;
    }

    public void setmCenter(Point point) {
        this.mCenter = point;
    }

    public Point getmTouch() {
        return this.mTouch;
    }

    public void setmTouch(Point point) {
        this.mTouch = point;
    }

    public Point getmFirstTouch() {
        return this.mFirstTouch;
    }

    public void setmFirstTouch(Point point) {
        this.mFirstTouch = point;
    }

    public Bitmap getBmCenter() {
        return this.bmCenter;
    }

    public void setBmCenter(Bitmap bitmap) {
        this.bmCenter = bitmap;
    }

    public int getScreenStatus() {
        return this.screenStatus;
    }

    public void setScreenStatus(int i) {
        this.screenStatus = i;
    }

    public BitmapFactory.Options get_bmOption() {
        return this._bmOption;
    }

    public void set_bmOption(BitmapFactory.Options options) {
        this._bmOption = options;
    }

    public int getInSampleSize() {
        return this.inSampleSize;
    }

    public void setInSampleSize(int i) {
        this.inSampleSize = i;
    }

    public boolean isSetSize() {
        return this.isSetSize;
    }

    public void setSetSize(boolean z) {
        this.isSetSize = z;
    }

    public RectF getBmRectF() {
        return this.bmRectF;
    }

    public void setBmRectF(RectF rectF) {
        this.bmRectF = rectF;
    }

    public Bitmap getBm() {
        return this.mBitmap;
    }

    public void setBm(Bitmap bitmap) {
        this.mBitmap = bitmap;
    }

    public int getmWhere() {
        return this.mWhere;
    }

    public void setmWhere(int i) {
        this.mWhere = i;
    }

    public Paint getmPaint() {
        return this.mPaint;
    }

    public void setmPaint(Paint paint) {
        this.mPaint = paint;
    }

    public void setListSavedJPGFilePath(ArrayList<String> arrayList) {
        this.listSavedJPGFilePath = arrayList;
    }

    public ArrayList<String> getListSavedJPGFilePath() {
        return this.listSavedJPGFilePath;
    }

    public double getMaxScanHeightOnScreen() {
        return this.maxScanHeightOnScreen;
    }

    public void setMaxScanHeightOnScreen(double d) {
        this.maxScanHeightOnScreen = d;
    }

    public double getMaxScanWidthOnScreen() {
        return this.maxScanWidthOnScreen;
    }

    public void setMaxScanWidthOnScreen(double d) {
        this.maxScanWidthOnScreen = d;
    }

    public ScanBaseView() {
        this.piBaseTop = new PointInfo(0.0d, 0.0d);
        this.piBaseBot = new PointInfo(0.0d, 0.0d);
        this.mBaseTop = new Point();
        this.mBaseBot = new Point();
        this.mTop = new Point();
        this.mBot = new Point();
        this.mCenter = new Point();
        this.mTouch = new Point();
        this.mFirstTouch = new Point();
        this.curentViewingFile = 1;
        this.totalScanned = 0;
        this.mWhere = 2;
        this.first = new PointInfo(0.0d, 0.0d);
        this.second = new PointInfo(0.0d, 0.0d);
        this.isValidArea = false;
        this.isDisplayResult = false;
        this.phase = 0;
        this.MAX_DASHEFFECT_PHASE = 1000;
        this.escan = new escanLib();
        this.escan.setJobDone(false);
        this._bmOption = new BitmapFactory.Options();
        if (this.mPaint == null) {
            this.mPaint = new Paint();
            this.mPaint.setStrokeWidth(2.0f);
            this.mPaint.setColor(ViewCompat.MEASURED_STATE_MASK);
        }
        this.listSavedJPGFilePath = new ArrayList<>();
    }

    public void setupScanArea() {
        double unused = this.first.f411x = Math.min(this.piBaseTop.f411x, this.piBaseBot.f411x);
        double unused2 = this.first.f412y = Math.min(this.piBaseTop.f412y, this.piBaseBot.f412y);
        double unused3 = this.second.f411x = Math.max(this.piBaseTop.f411x, this.piBaseBot.f411x);
        double unused4 = this.second.f412y = Math.max(this.piBaseTop.f412y, this.piBaseBot.f412y);
        if (this.first.f411x < ((double) getmBaseTop().x)) {
            double unused5 = this.first.f411x = (double) getmBaseTop().x;
        }
        if (this.first.f412y < ((double) getmBaseTop().y)) {
            double unused6 = this.first.f412y = (double) getmBaseTop().y;
        }
        if (this.second.f411x > ((double) getmBaseBot().x)) {
            double unused7 = this.second.f411x = (double) getmBaseBot().x;
        }
        if (this.second.f412y > ((double) getmBaseBot().y)) {
            double unused8 = this.second.f412y = (double) getmBaseBot().y;
        }
        if (this.second.f411x <= ((double) getmBaseTop().x) || this.first.f411x >= ((double) getmBaseBot().x) || this.second.f412y <= ((double) getmBaseTop().y) || this.first.f412y >= ((double) getmBaseBot().y)) {
            this.isValidArea = false;
        } else {
            this.isValidArea = true;
        }
        this.escan.setOffsetX((int) Math.max((Math.abs(this.first.f411x - ((double) getmBaseTop().x)) * ((double) getMaxwidth())) / getMaxScanWidthOnScreen(), 0.0d));
        this.escan.setOffsetY((int) Math.max((Math.abs(this.first.f412y - ((double) getmBaseTop().y)) * ((double) getMaxheight())) / getMaxScanHeightOnScreen(), 0.0d));
        int min = (int) Math.min((Math.abs(this.first.f411x - this.second.f411x) * ((double) getMaxwidth())) / getMaxScanWidthOnScreen(), (double) (getMaxwidth() - this.escan.getOffsetX()));
        int min2 = (int) Math.min((Math.abs(this.first.f412y - this.second.f412y) * ((double) getMaxheight())) / getMaxScanHeightOnScreen(), (double) (getMaxheight() - this.escan.getOffsetY()));
        if (min == 0) {
            escanLib escanlib = this.escan;
            escanlib.setOffsetX(escanlib.getOffsetX() - 1);
            min = 1;
        }
        if (min2 == 0) {
            escanLib escanlib2 = this.escan;
            escanlib2.setOffsetY(escanlib2.getOffsetY() - 1);
            min2 = 1;
        }
        this.escan.setScanAreaWidth(min);
        this.escan.setScanAreaHeight(min2);
        if (Utils.getPrefInt(this.context, Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_2SIDED) == 1 || !this.isDoctable) {
            this.escan.setOffsetX(Utils.getPrefInt(getContext(), Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_MAX_WIDTH) - min);
        }
        this.rectScanArea = new RectF((float) ((int) Math.max(this.first.f411x, (double) getmBaseTop().x)), (float) ((int) Math.max(this.first.f412y, (double) getmBaseTop().y)), (float) ((int) Math.min(this.second.f411x, (double) getmBaseBot().x)), (float) ((int) Math.min(this.second.f412y, (double) getmBaseBot().y)));
    }

    public Point calculateTheCenterPoint(Point point, Point point2) {
        Point point3 = new Point();
        point3.x = Math.min(point.x, point2.x) + Math.round((float) (Math.abs(point.x - point2.x) / 2));
        point3.y = Math.min(point.y, point2.y) + Math.round((float) (Math.abs(point.y - point2.y) / 2));
        return point3;
    }

    public boolean isValidArea() {
        return this.isValidArea;
    }

    public void setValidArea(boolean z) {
        this.isValidArea = z;
    }

    class ScanAreaSet extends View {
        private Point _pBaseBottomRight;
        private Point _pBaseCenter;
        private Point _pBaseTopLeft;
        int _touchtime = 0;
        public Handler redrawCBHandler = null;

        public ScanAreaSet(Context context) {
            super(context);
            ScanBaseView.SCAN_AREA_HOTSPOT_SIZE = (int) ((((float) ScanBaseView.SCAN_AREA_HOTSPOT_SIZE) * getResources().getDisplayMetrics().density) + 0.5f);
        }

        /* access modifiers changed from: protected */
        public void onSizeChanged(int i, int i2, int i3, int i4) {
            super.onSizeChanged(i, i2, i3, i4);
        }

        /* access modifiers changed from: protected */
        public void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (ScanBaseView.this.bLongTouch && ScanBaseView.this.mWhere != 2) {
                invalidate();
                ScanBaseView.this.phase += 2;
                if (ScanBaseView.this.phase > 1000) {
                    ScanBaseView.this.phase = 0;
                }
            }
            drawScanArea(canvas);
            Handler handler = this.redrawCBHandler;
            if (handler != null) {
                handler.sendEmptyMessage(-100);
            }
        }

        private synchronized void drawScanArea(Canvas canvas) {
            this._pBaseTopLeft = ScanBaseView.this.getmTop();
            this._pBaseBottomRight = ScanBaseView.this.getmBot();
            if (!ScanBaseView.this.isDisplayResult && ScanBaseView.this.getBm() != null) {
                if (Build.VERSION.SDK_INT >= 14) {
                    EPLog.m313i("drawScanArea", "14");
                    Bitmap bm = ScanBaseView.this.getBm();
                    RectF bmRectF = ScanBaseView.this.getBmRectF();
                    Bitmap createScaledBitmap = Bitmap.createScaledBitmap(bm, (int) bmRectF.width(), (int) bmRectF.height(), true);
                    ScanBaseView.this.setBm(createScaledBitmap);
                    canvas.drawBitmap(createScaledBitmap, ScanBaseView.this.getBmRectF().left, ScanBaseView.this.getBmRectF().top, (Paint) null);
                } else {
                    canvas.drawBitmap(ScanBaseView.this.getBm(), (Rect) null, ScanBaseView.this.getBmRectF(), ScanBaseView.this.getmPaint());
                }
            }
            if (ScanBaseView.this.isDoctable) {
                if (ScanBaseView.this.isSetSize) {
                    drawNormalCorner(canvas);
                    this._pBaseCenter = ScanBaseView.this.getmCenter();
                }
                Paint paint = new Paint();
                if (!ScanBaseView.this.bLongTouch || ScanBaseView.this.mWhere == 2) {
                    Paint paint2 = ScanBaseView.this.getmPaint();
                    canvas.drawLine((float) this._pBaseTopLeft.x, (float) this._pBaseTopLeft.y, (float) this._pBaseBottomRight.x, (float) this._pBaseTopLeft.y, paint2);
                    canvas.drawLine((float) this._pBaseBottomRight.x, (float) this._pBaseTopLeft.y, (float) this._pBaseBottomRight.x, (float) this._pBaseBottomRight.y, paint2);
                    canvas.drawLine((float) this._pBaseBottomRight.x, (float) this._pBaseBottomRight.y, (float) this._pBaseTopLeft.x, (float) this._pBaseBottomRight.y, paint2);
                    canvas.drawLine((float) this._pBaseTopLeft.x, (float) this._pBaseBottomRight.y, (float) this._pBaseTopLeft.x, (float) this._pBaseTopLeft.y, paint2);
                } else {
                    Path path = new Path();
                    path.addRect((float) this._pBaseTopLeft.x, (float) this._pBaseTopLeft.y, (float) this._pBaseBottomRight.x, (float) this._pBaseBottomRight.y, Path.Direction.CW);
                    paint.setPathEffect(new DashPathEffect(new float[]{10.0f, 2.0f}, (float) ScanBaseView.this.phase));
                    paint.setStrokeWidth(1.5f);
                    paint.setStyle(Paint.Style.STROKE);
                    canvas.drawPath(path, paint);
                }
                if (ScanBaseView.this.bLongTouch) {
                    drawTheCornerImage(canvas, ScanBaseView.this.getmPaint());
                } else {
                    drawNormalCorner(canvas);
                }
            }
            if (ScanBaseView.this.isSetSize) {
                ScanBaseView.this.setupScanArea();
                ScanBaseView.this.setSetSize(false);
            }
        }

        private void drawTheCornerImage(Canvas canvas, Paint paint) {
            switch (ScanBaseView.this.screenStatus) {
                case 1:
                    int i = ScanBaseView.this.mWhere;
                    if (i != -1) {
                        if (i == 1) {
                            drawCornerTopLeft(canvas, this._pBaseTopLeft);
                            drawCornerBotRightMoving(canvas, this._pBaseBottomRight);
                            break;
                        } else {
                            drawCornerTopLeft(canvas, this._pBaseTopLeft);
                            drawCornerBotRight(canvas, this._pBaseBottomRight);
                            break;
                        }
                    } else {
                        drawCornerTopLeftMoving(canvas, this._pBaseTopLeft);
                        drawCornerBotRight(canvas, this._pBaseBottomRight);
                        break;
                    }
                case 2:
                    int i2 = ScanBaseView.this.mWhere;
                    if (i2 != -1) {
                        if (i2 == 1) {
                            drawCornerBotLeft(canvas, this._pBaseTopLeft);
                            drawCornerTopRightMoving(canvas, this._pBaseBottomRight);
                            break;
                        } else {
                            drawCornerBotLeft(canvas, this._pBaseTopLeft);
                            drawCornerTopRight(canvas, this._pBaseBottomRight);
                            break;
                        }
                    } else {
                        drawCornerBotLeftMoving(canvas, this._pBaseTopLeft);
                        drawCornerTopRight(canvas, this._pBaseBottomRight);
                        break;
                    }
                case 3:
                    int i3 = ScanBaseView.this.mWhere;
                    if (i3 != -1) {
                        if (i3 == 1) {
                            drawCornerBotRight(canvas, this._pBaseTopLeft);
                            drawCornerTopLeftMoving(canvas, this._pBaseBottomRight);
                            break;
                        } else {
                            drawCornerBotRight(canvas, this._pBaseTopLeft);
                            drawCornerTopLeft(canvas, this._pBaseBottomRight);
                            break;
                        }
                    } else {
                        drawCornerBotRightMoving(canvas, this._pBaseTopLeft);
                        drawCornerTopLeft(canvas, this._pBaseBottomRight);
                        break;
                    }
                case 4:
                    int i4 = ScanBaseView.this.mWhere;
                    if (i4 != -1) {
                        if (i4 == 1) {
                            drawCornerTopRight(canvas, this._pBaseTopLeft);
                            drawCornerBotLeftMoving(canvas, this._pBaseBottomRight);
                            break;
                        } else {
                            drawCornerTopRight(canvas, this._pBaseTopLeft);
                            drawCornerBotLeft(canvas, this._pBaseBottomRight);
                            break;
                        }
                    } else {
                        drawCornerTopRightMoving(canvas, this._pBaseTopLeft);
                        drawCornerBotLeft(canvas, this._pBaseBottomRight);
                        break;
                    }
            }
            if (ScanBaseView.this.bLongTouch) {
                String localClassName = ScanBaseView.this.getLocalClassName();
                EPLog.m313i(localClassName, "mWhere = " + ScanBaseView.this.mWhere);
                if (ScanBaseView.this.mWhere == 0 && ScanBaseView.this.bmCenter == null) {
                    ScanBaseView.this.bmCenter = BitmapFactory.decodeResource(getResources(), C2135R.C2136drawable.area_center, ScanBaseView.this._bmOption);
                }
                if (ScanBaseView.this.bmCenter != null) {
                    if (this._pBaseCenter == null) {
                        this._pBaseCenter = ScanBaseView.this.getmCenter();
                    }
                    if (ScanBaseView.this.inSampleSize != 0) {
                        canvas.drawBitmap(ScanBaseView.this.bmCenter, (float) (this._pBaseCenter.x - ((ScanBaseView.this.bmCenter.getWidth() / 2) * ScanBaseView.this.getInSampleSize())), (float) (this._pBaseCenter.y - ((ScanBaseView.this.bmCenter.getHeight() / 2) * ScanBaseView.this.getInSampleSize())), (Paint) null);
                    } else {
                        canvas.drawBitmap(ScanBaseView.this.bmCenter, (float) (this._pBaseCenter.x - (ScanBaseView.this.bmCenter.getWidth() / 2)), (float) (this._pBaseCenter.y - (ScanBaseView.this.bmCenter.getHeight() / 2)), (Paint) null);
                    }
                }
            }
        }

        public boolean onTouchEvent(MotionEvent motionEvent) {
            if (!ScanBaseView.this.isDoctable) {
                return true;
            }
            Point point = new Point((int) motionEvent.getX(), (int) motionEvent.getY());
            ScanBaseView.this.setmTouch(point);
            ScanBaseView.this.detectTheScreenStatus();
            switch (motionEvent.getAction()) {
                case 0:
                    ScanBaseView.this.setmWhere(2);
                    ScanBaseView.this.detectTheTouchPoint();
                    ScanBaseView.this.setmFirstTouch(point);
                    break;
                case 1:
                    ScanBaseView.this.setmWhere(2);
                    ScanBaseView.this.setBmCenter((Bitmap) null);
                    ScanBaseView scanBaseView = ScanBaseView.this;
                    scanBaseView.phase = 0;
                    this._touchtime = 0;
                    scanBaseView.setupScanArea();
                    ScanBaseView.this.bLongTouch = false;
                    break;
                case 2:
                    if (ScanBaseView.this.bLongTouch) {
                        moveTheTouchPoint();
                        break;
                    }
                    break;
                default:
                    return false;
            }
            postInvalidate();
            return true;
        }

        public void moveTheTouchPoint() {
            switch (ScanBaseView.this.getmWhere()) {
                case -1:
                    this._pBaseTopLeft = ScanBaseView.this.getmTouch();
                    this._pBaseCenter = ScanBaseView.this.calculateTheCenterPoint(this._pBaseTopLeft, this._pBaseBottomRight);
                    break;
                case 0:
                    moveCenter();
                    ScanBaseView.this.setmCenter(this._pBaseCenter);
                    break;
                case 1:
                    this._pBaseBottomRight = ScanBaseView.this.getmTouch();
                    this._pBaseCenter = ScanBaseView.this.calculateTheCenterPoint(this._pBaseTopLeft, this._pBaseBottomRight);
                    break;
            }
            ScanBaseView.this.setmTop(this._pBaseTopLeft);
            ScanBaseView.this.setmBot(this._pBaseBottomRight);
            ScanBaseView scanBaseView = ScanBaseView.this;
            scanBaseView.setPiBaseTop(new PointInfo((double) this._pBaseTopLeft.x, (double) this._pBaseTopLeft.y));
            ScanBaseView scanBaseView2 = ScanBaseView.this;
            scanBaseView2.setPiBaseBot(new PointInfo((double) this._pBaseBottomRight.x, (double) this._pBaseBottomRight.y));
            ScanBaseView.this.setmCenter(this._pBaseCenter);
        }

        private void moveCenter() {
            Point point = ScanBaseView.this.getmFirstTouch();
            Point point2 = ScanBaseView.this.getmTouch();
            int i = point2.x - point.x;
            int i2 = point2.y - point.y;
            this._pBaseTopLeft.x += i;
            this._pBaseTopLeft.y += i2;
            this._pBaseBottomRight.x += i;
            this._pBaseBottomRight.y += i2;
            this._pBaseCenter.x += i;
            this._pBaseCenter.y += i2;
            ScanBaseView.this.setmFirstTouch(point2);
        }

        private void drawNormalCorner(Canvas canvas) {
            switch (ScanBaseView.this.screenStatus) {
                case 2:
                    drawCornerBotLeft(canvas, ScanBaseView.this.mTop);
                    drawCornerTopRight(canvas, ScanBaseView.this.mBot);
                    return;
                case 3:
                    drawCornerBotRight(canvas, ScanBaseView.this.mTop);
                    drawCornerTopLeft(canvas, ScanBaseView.this.mBot);
                    return;
                case 4:
                    drawCornerTopRight(canvas, ScanBaseView.this.mTop);
                    drawCornerBotLeft(canvas, ScanBaseView.this.mBot);
                    return;
                default:
                    drawCornerTopLeft(canvas, ScanBaseView.this.mTop);
                    drawCornerBotRight(canvas, ScanBaseView.this.mBot);
                    return;
            }
        }

        private void drawCornerTopLeft(Canvas canvas, Point point) {
            Canvas canvas2 = canvas;
            canvas2.drawRect((float) (point.x - 6), (float) (point.y - 6), (float) ((point.x - 6) + 60), (float) point.y, ScanBaseView.this.getmPaint());
            canvas2.drawRect((float) (point.x - 6), (float) (point.y - 6), (float) point.x, (float) ((point.y - 6) + 60), ScanBaseView.this.getmPaint());
        }

        private void drawCornerBotRight(Canvas canvas, Point point) {
            Canvas canvas2 = canvas;
            canvas2.drawRect((float) ((point.x + 6) - 60), (float) point.y, (float) (point.x + 6), (float) (point.y + 6), ScanBaseView.this.getmPaint());
            canvas2.drawRect((float) point.x, (float) ((point.y + 6) - 60), (float) (point.x + 6), (float) (point.y + 6), ScanBaseView.this.getmPaint());
        }

        private void drawCornerBotLeft(Canvas canvas, Point point) {
            Canvas canvas2 = canvas;
            canvas2.drawRect((float) (point.x - 6), (float) point.y, (float) ((point.x - 6) + 60), (float) (point.y + 6), ScanBaseView.this.getmPaint());
            canvas2.drawRect((float) (point.x - 6), (float) ((point.y + 6) - 60), (float) point.x, (float) (point.y + 6), ScanBaseView.this.getmPaint());
        }

        private void drawCornerTopRight(Canvas canvas, Point point) {
            Canvas canvas2 = canvas;
            canvas2.drawRect((float) ((point.x + 6) - 60), (float) (point.y - 6), (float) (point.x + 6), (float) point.y, ScanBaseView.this.getmPaint());
            canvas2.drawRect((float) point.x, (float) (point.y - 6), (float) (point.x + 6), (float) ((point.y - 6) + 60), ScanBaseView.this.getmPaint());
        }

        private void drawCornerTopLeftMoving(Canvas canvas, Point point) {
            Canvas canvas2 = canvas;
            canvas2.drawRect((float) (point.x - 18), (float) (point.y - 18), (float) ((point.x - 18) + 150), (float) point.y, ScanBaseView.this.getmPaint());
            canvas2.drawRect((float) (point.x - 18), (float) (point.y - 18), (float) point.x, (float) ((point.y - 18) + 150), ScanBaseView.this.getmPaint());
        }

        private void drawCornerBotRightMoving(Canvas canvas, Point point) {
            Canvas canvas2 = canvas;
            canvas2.drawRect((float) ((point.x + 18) - 150), (float) point.y, (float) (point.x + 18), (float) (point.y + 18), ScanBaseView.this.getmPaint());
            canvas2.drawRect((float) point.x, (float) ((point.y + 18) - 150), (float) (point.x + 18), (float) (point.y + 18), ScanBaseView.this.getmPaint());
        }

        private void drawCornerBotLeftMoving(Canvas canvas, Point point) {
            Canvas canvas2 = canvas;
            canvas2.drawRect((float) (point.x - 18), (float) point.y, (float) ((point.x - 18) + 150), (float) (point.y + 18), ScanBaseView.this.getmPaint());
            canvas2.drawRect((float) (point.x - 18), (float) ((point.y + 18) - 150), (float) point.x, (float) (point.y + 18), ScanBaseView.this.getmPaint());
        }

        private void drawCornerTopRightMoving(Canvas canvas, Point point) {
            Canvas canvas2 = canvas;
            canvas2.drawRect((float) ((point.x + 18) - 150), (float) (point.y - 18), (float) (point.x + 18), (float) point.y, ScanBaseView.this.getmPaint());
            canvas2.drawRect((float) point.x, (float) (point.y - 18), (float) (point.x + 18), (float) ((point.y - 18) + 150), ScanBaseView.this.getmPaint());
        }
    }

    public void detectTheTouchPoint() {
        if (this.mTouch.x > Math.max(this.mTop.x, this.mBot.x) || this.mTouch.x < Math.min(this.mTop.x, this.mBot.x) || this.mTouch.y > Math.max(this.mTop.y, this.mBot.y) || this.mTouch.y < Math.min(this.mTop.y, this.mBot.y)) {
            EPLog.m313i(getLocalClassName(), "touche out");
            if ((Math.abs(Math.min(this.mTop.x, this.mBot.x) - this.mTouch.x) >= SCAN_AREA_HOTSPOT_SIZE && Math.abs(this.mTouch.x - Math.max(this.mTop.x, this.mBot.x)) >= SCAN_AREA_HOTSPOT_SIZE) || (Math.abs(Math.min(this.mTop.y, this.mBot.y) - this.mTouch.y) >= SCAN_AREA_HOTSPOT_SIZE && Math.abs(this.mTouch.y - Math.max(this.mTop.y, this.mBot.y)) >= SCAN_AREA_HOTSPOT_SIZE)) {
                this.mWhere = 2;
            } else if (this.mTop.x >= this.mBot.x || this.mTop.y >= this.mBot.y) {
                if (this.mTop.x >= this.mBot.x || this.mTop.y <= this.mBot.y) {
                    if (this.mTop.x <= this.mBot.x || this.mTop.y <= this.mBot.y) {
                        if ((this.mTouch.x > this.mTop.x && Math.abs(this.mTouch.y - this.mTop.y) < SCAN_AREA_HOTSPOT_SIZE) || Math.abs(this.mTop.x - this.mTouch.x) < SCAN_AREA_HOTSPOT_SIZE) {
                            this.mWhere = -1;
                        } else if ((this.mTouch.x >= this.mBot.x || Math.abs(this.mTouch.y - this.mBot.y) >= SCAN_AREA_HOTSPOT_SIZE) && Math.abs(this.mTouch.x - this.mBot.x) >= SCAN_AREA_HOTSPOT_SIZE) {
                            this.mWhere = 0;
                        } else {
                            this.mWhere = 1;
                        }
                    } else if ((this.mTouch.x > this.mTop.x && Math.abs(this.mTouch.y - this.mTop.y) < SCAN_AREA_HOTSPOT_SIZE) || Math.abs(this.mTop.x - this.mTouch.x) < SCAN_AREA_HOTSPOT_SIZE) {
                        this.mWhere = -1;
                    } else if ((this.mTouch.x >= this.mBot.x || Math.abs(this.mTouch.y - this.mBot.y) >= SCAN_AREA_HOTSPOT_SIZE) && Math.abs(this.mTouch.x - this.mBot.x) >= SCAN_AREA_HOTSPOT_SIZE) {
                        this.mWhere = 0;
                    } else {
                        this.mWhere = 1;
                    }
                } else if ((this.mTouch.x < this.mTop.x && Math.abs(this.mTouch.y - this.mTop.y) < SCAN_AREA_HOTSPOT_SIZE) || Math.abs(this.mTouch.x - this.mTop.x) < SCAN_AREA_HOTSPOT_SIZE) {
                    this.mWhere = -1;
                } else if ((this.mTouch.x <= this.mBot.x || Math.abs(this.mTouch.y - this.mBot.y) >= SCAN_AREA_HOTSPOT_SIZE) && Math.abs(this.mBot.x - this.mTouch.x) >= SCAN_AREA_HOTSPOT_SIZE) {
                    this.mWhere = 0;
                } else {
                    this.mWhere = 1;
                }
            } else if ((this.mTouch.x < this.mTop.x && Math.abs(this.mTouch.y - this.mTop.y) < SCAN_AREA_HOTSPOT_SIZE) || Math.abs(this.mTouch.x - this.mTop.x) < SCAN_AREA_HOTSPOT_SIZE) {
                this.mWhere = -1;
            } else if ((this.mTouch.x <= this.mBot.x || Math.abs(this.mTouch.y - this.mBot.y) >= SCAN_AREA_HOTSPOT_SIZE) && Math.abs(this.mBot.x - this.mTouch.x) >= SCAN_AREA_HOTSPOT_SIZE) {
                this.mWhere = 0;
            } else {
                this.mWhere = 1;
            }
        } else {
            EPLog.m313i(getLocalClassName(), "touche in");
            if (this.mTop.x >= this.mBot.x || this.mTop.y >= this.mBot.y) {
                if (this.mTop.x >= this.mBot.x || this.mTop.y <= this.mBot.y) {
                    if (this.mTop.x <= this.mBot.x || this.mTop.y <= this.mBot.y) {
                        if (Math.abs(this.mTop.x - this.mTouch.x) < SCAN_AREA_HOTSPOT_SIZE && this.mTouch.y - this.mTop.y < SCAN_AREA_HOTSPOT_SIZE) {
                            this.mWhere = -1;
                        } else if (Math.abs(this.mTouch.x - this.mBot.x) >= SCAN_AREA_HOTSPOT_SIZE || this.mBot.y - this.mTouch.y >= SCAN_AREA_HOTSPOT_SIZE) {
                            this.mWhere = 0;
                        } else {
                            this.mWhere = 1;
                        }
                    } else if (Math.abs(this.mTop.x - this.mTouch.x) < SCAN_AREA_HOTSPOT_SIZE && this.mTop.y - this.mTouch.y < SCAN_AREA_HOTSPOT_SIZE) {
                        this.mWhere = -1;
                    } else if (Math.abs(this.mTouch.x - this.mBot.x) >= SCAN_AREA_HOTSPOT_SIZE || this.mTouch.y - this.mBot.y >= SCAN_AREA_HOTSPOT_SIZE) {
                        this.mWhere = 0;
                    } else {
                        this.mWhere = 1;
                    }
                } else if (Math.abs(this.mTouch.x - this.mTop.x) < SCAN_AREA_HOTSPOT_SIZE && this.mTop.y - this.mTouch.y < SCAN_AREA_HOTSPOT_SIZE) {
                    this.mWhere = -1;
                } else if (Math.abs(this.mBot.x - this.mTouch.x) >= SCAN_AREA_HOTSPOT_SIZE || this.mTouch.y - this.mBot.y >= SCAN_AREA_HOTSPOT_SIZE) {
                    this.mWhere = 0;
                } else {
                    this.mWhere = 1;
                }
            } else if (Math.abs(this.mTouch.x - this.mTop.x) < SCAN_AREA_HOTSPOT_SIZE && this.mTouch.y - this.mTop.y < SCAN_AREA_HOTSPOT_SIZE) {
                this.mWhere = -1;
            } else if (Math.abs(this.mBot.x - this.mTouch.x) >= SCAN_AREA_HOTSPOT_SIZE || this.mBot.y - this.mTouch.y >= SCAN_AREA_HOTSPOT_SIZE) {
                this.mWhere = 0;
            } else {
                this.mWhere = 1;
            }
        }
    }

    public void detectTheScreenStatus() {
        if (this.mTop.x < this.mBot.x && this.mTop.y < this.mBot.y) {
            this.screenStatus = 1;
        } else if (this.mTop.x < this.mBot.x && this.mTop.y > this.mBot.y) {
            this.screenStatus = 2;
        } else if (this.mTop.x <= this.mBot.x || this.mTop.y <= this.mBot.y) {
            this.screenStatus = 4;
        } else {
            this.screenStatus = 3;
        }
    }

    class ScanAreaBackground extends View {
        Paint _paint = new Paint();
        Paint _textPaint;
        boolean hideText;
        ScanActivity mScanActivity;
        String text;

        /* access modifiers changed from: protected */
        public void onSizeChanged(int i, int i2, int i3, int i4) {
            super.onSizeChanged(i, i2, i3, i4);
            this.mScanActivity.onScanAreaSizeChange();
        }

        /* access modifiers changed from: package-private */
        public void drawTextInCanvas(Canvas canvas) {
            String str = new String();
            float f = ((float) (ScanBaseView.this.getmBaseBot().x - ScanBaseView.this.getmBaseTop().x)) * 0.9f;
            float f2 = (float) (ScanBaseView.this.getmBaseBot().y - ScanBaseView.this.getmBaseTop().y);
            Rect rect = new Rect();
            int length = this.text.length();
            String str2 = str;
            int i = 0;
            int i2 = 0;
            while (i < length) {
                int breakText = this._textPaint.breakText(this.text.substring(i, length), true, f, (float[]) null) + i;
                String substring = this.text.substring(i, breakText);
                this._textPaint.getTextBounds(substring, 0, substring.length(), rect);
                i2 += rect.height();
                str2 = (str2 + substring) + Constants.BREAK_LINE;
                i = breakText;
            }
            int i3 = (int) (((float) ScanBaseView.this.getmBaseTop().x) + (((float) (ScanBaseView.this.getmBaseBot().x - ScanBaseView.this.getmBaseTop().x)) * 0.05f));
            int i4 = (int) ((((float) ScanBaseView.this.getmBaseTop().y) + (f2 / 2.0f)) - ((float) (i2 / 2)));
            String[] split = str2.split(Constants.BREAK_LINE);
            int i5 = 0;
            for (int i6 = 0; i6 < split.length; i6++) {
                canvas.drawText(split[i6], (float) i3, (float) (i4 + i5), this._textPaint);
                this._textPaint.getTextBounds(split[i6], 0, split[i6].length(), rect);
                i5 += rect.height();
            }
        }

        public void hideText(boolean z) {
            this.hideText = z;
        }

        public ScanAreaBackground(Context context) {
            super(context);
            this.mScanActivity = (ScanActivity) context;
            this._paint.setColor(-1);
            this._paint.setShadowLayer(5.5f, 6.0f, 6.0f, C2135R.color.light_gray);
            this._textPaint = new Paint();
            this._textPaint.setColor(getResources().getColor(C2135R.color.light_gray));
            this._textPaint.setAntiAlias(true);
            this._textPaint.setTextAlign(Paint.Align.LEFT);
            this._textPaint.setTextSize(new EditText(getContext()).getTextSize());
            this.text = ScanBaseView.this.getString(C2135R.string.str_msg_scan_viewbase);
        }

        /* access modifiers changed from: protected */
        public void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            drawTheDefaultBackground(canvas);
        }

        private void drawTheDefaultBackground(Canvas canvas) {
            canvas.drawRect((float) ScanBaseView.this.getmBaseTop().x, (float) ScanBaseView.this.getmBaseTop().y, (float) ScanBaseView.this.getmBaseBot().x, (float) ScanBaseView.this.getmBaseBot().y, this._paint);
            if (!this.hideText) {
                drawTextInCanvas(canvas);
            }
        }
    }
}
