package epson.scan.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.RectF;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.StatFs;
import android.view.Display;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.epson.iprint.prtlogger.Analytics;
import com.epson.iprint.prtlogger.CommonLog;
import com.epson.iprint.prtlogger.PrintLog;
import com.epson.iprint.shared.EpsoniPrintSharedActivity;
import com.epson.iprint.shared.SharedParamScan;
import com.epson.mobilephone.common.PrintingLib.define.Constants;
import com.epson.mobilephone.common.wifidirect.NfcTagUtils;
import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;

import org.opencv.videoio.Videoio;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;

import epson.common.ExternalFileUtils;
import epson.common.Utils;
import epson.print.ActivityNfcPrinter;
import epson.print.ActivityPrintWeb;
import epson.print.ActivityRequestPermissions;
import epson.print.CommonDefine;
import epson.print.R;
import epson.print.Util.EPLog;
import epson.print.Util.Photo;
import epson.scan.lib.I1ScanParams;
import epson.scan.lib.ScanInfoStorage;
import epson.scan.lib.ScanSizeHelper;
import epson.scan.lib.ScannerInfo;
import epson.scan.lib.escanLib;
import epson.server.screens.StorageServer;
import epson.server.utils.Define;

public class ScanActivity extends ScanBaseView implements ScanContinueParam.ScanContinueDialogButtonClick {
    private static final int MESSAGE_CHECK_STATUS_AND_START_SCAN = 20;
    public static final String PARAM_KEY_SCAN_LOG = "scan-log";
    private static final int REQEST_RUNTIMEPERMMISSION = 4;
    private static final int REQUEST_CODE_ESC_I_VERSION_CHANGE = 20;
    static final String RETURN_KEY_SCAN_FILE = "scan-file";
    private static final int SCAN_CANCELED = -2;
    private static final int SCAN_DISMISS = -3;
    public static final int SCAN_ENDPAGE_CB = 11;
    private static final int SCAN_ERROR = -1;
    private static final int SCAN_FINISHED = 2;
    public static final int SCAN_RECV_IMGBLOCK_CB = 10;
    private static final int SCAN_REDRAWBITMAP = -100;
    private static final int START_SCAN = 0;
    private static final String TAG = "ScanActivity";
    private RectF area;
    private int areaHeightOnScreen = 0;
    private int areaWidthOnScreen = 0;
    private boolean bAutoStartScan = false;
    private Button btnCancelScan;
    private Button btnMail;
    private Button btnNext;
    private Button btnPrev;
    private Button btnPrint;
    private Button btnSave;
    private Button btnScan;
    private AlertDialog confirmAlertDialog;
    private int convertCount = 0;
    private Thread doscan;
    private int error = 0;
    private AlertDialog errorDialog;
    private escanLib escan;
    private SharedParamScan extParam;
    private FrameLayout flScanResult;
    private GestureDetector gestureDetector;
    private View.OnTouchListener gestureListener;
    private boolean isConfirmCancel = false;
    private boolean isCustomAction = false;
    private boolean isDecoding = false;
    private boolean isNeedClearBm = false;
    private boolean isNeedDeleteTempFile = true;
    private boolean isNeedGetScanSize = true;
    private boolean isNeedRedrawBitmap = false;
    private boolean isNeedScale = false;
    private boolean isNeedUpdateScanningArea = false;
    private boolean isStopScan = false;
    private LinearLayout llScanArea;
    private LinearLayout llScanAreaBackground;
    private LinearLayout llScanningProgress;
    private boolean mActivityPaused;
    private View.OnClickListener mButtonCancelScanListener = new View.OnClickListener() {
        public void onClick(View view) {
            String localClassName = ScanActivity.this.getLocalClassName();
            EPLog.i(localClassName, "isStopScan = " + ScanActivity.this.isStopScan);
            if (!ScanActivity.this.escan.isJobDone() && !ScanActivity.this.isStopScan) {
                ScanActivity.this.hideScanningPop();
                ScanActivity scanActivity = ScanActivity.this;
                scanActivity.confirmationDialog(scanActivity.getString(R.string.str_msg_scan_cancel));
            }
        }
    };
    private View.OnClickListener mButtonMailListener = new View.OnClickListener() {
        public void onClick(View view) {
            if (ScanActivity.this.totalScanned > 0 && ScanActivity.this.isCompletedScanProcess()) {
                Intent intent = new Intent(ScanActivity.this, MailActivity.class);
                intent.putStringArrayListExtra(Define.SAVING_FILE_PATH, ScanActivity.this.getListSavedJPGFilePath());
                ScanActivity.this.startActivityForResult(intent, 1);
            }
        }
    };
    private View.OnClickListener mButtonNextListener = new View.OnClickListener() {
        public void onClick(View view) {
            if (ScanActivity.this.isCompletedScanProcess()) {
                ScanActivity.this.curentViewingFile++;
                if (ScanActivity.this.curentViewingFile > 300 || ScanActivity.this.curentViewingFile > ScanActivity.this.totalScanned) {
                    ScanActivity scanActivity = ScanActivity.this;
                    scanActivity.curentViewingFile--;
                    return;
                }
                ScanActivity scanActivity2 = ScanActivity.this;
                scanActivity2.updateThumbResult(scanActivity2.curentViewingFile);
                ScanActivity.this.showDisplayingResult();
                ScanActivity.this.scanArea.postInvalidate();
            }
        }
    };
    private View.OnClickListener mButtonPrevListener = new View.OnClickListener() {
        public void onClick(View view) {
            if (ScanActivity.this.isCompletedScanProcess()) {
                ScanActivity.this.curentViewingFile--;
                if (ScanActivity.this.curentViewingFile < 1) {
                    ScanActivity.this.curentViewingFile++;
                    return;
                }
                ScanActivity scanActivity = ScanActivity.this;
                scanActivity.updateThumbResult(scanActivity.curentViewingFile);
                ScanActivity.this.showDisplayingResult();
                ScanActivity.this.scanArea.postInvalidate();
            }
        }
    };
    private View.OnClickListener mButtonPrintListener = new View.OnClickListener() {
        public void onClick(View view) {
            if (ScanActivity.this.totalScanned > 0) {
                Intent intent = new Intent(ScanActivity.this, ActivityPrintWeb.class);
                intent.putExtra("from", 1);
                intent.putStringArrayListExtra("print_web", ScanActivity.this.getListSavedJPGFilePath());
                intent.putExtra("print_log", ScanActivity.getPrintLog());
                ScanActivity.this.startActivityForResult(intent, 3);
            }
        }
    };
    private View.OnClickListener mButtonSaveListener = new View.OnClickListener() {
        public void onClick(View view) {
            if (ScanActivity.this.totalScanned > 0 && ScanActivity.this.isCompletedScanProcess()) {
                if (ScanActivity.this.isCustomAction) {
                    Intent intent = new Intent();
                    if (ScanActivity.this.extParam != null) {
                        intent.putExtra(ScanActivity.RETURN_KEY_SCAN_FILE, ScanActivity.this.extParam.getArrayOutFilePath());
                        ScanActivity.this.setResult(-1, intent);
                        ScanActivity.this.finish();
                        return;
                    }
                    return;
                }
                Intent intent2 = new Intent(ScanActivity.this, StorageServer.class);
                intent2.putExtra(Define.PICK_SERVER_FOR, 2);
                intent2.putStringArrayListExtra(Define.SAVING_FILE_PATH, ScanActivity.this.getListSavedJPGFilePath());
                intent2.putExtra(StorageServer.FOR_PRINT_LOGGER_CALL_FROM, 1);
                ScanActivity.this.startActivityForResult(intent2, 1);
            }
        }
    };
    private View.OnClickListener mButtonScanListener = new View.OnClickListener() {
        public void onClick(View view) {
            ScanActivity.this.check3GAndStartPrint();
        }
    };
    private I1ScanParams mI1ScanParams;
    private ViewTreeObserver.OnPreDrawListener mOnPreDrawListener = new ViewTreeObserver.OnPreDrawListener() {
        public boolean onPreDraw() {
            int i;
            RectF bmRectF;
            if (!ScanActivity.mActivityPaused && ScanActivity.mScanAreaBackgroundViewSizeChanged) {
                boolean unused = ScanActivity.mScanAreaBackgroundViewSizeChanged = false;
                boolean unused2 = ScanActivity.this.isNeedGetScanSize = true;
                boolean unused3 = ScanActivity.this.isNeedScale = true;
                ScanActivity.this.llScanArea.invalidate();
                ScanActivity.this.llScanAreaBackground.invalidate();
                ScanActivity.this.scanArea.invalidate();
                ScanActivity.this.scanAreaBackground.invalidate();
                ScanActivity.this.flScanResult.invalidate();
            }
            if (ScanActivity.this.isNeedGetScanSize) {
                if (ScanActivity.this.isDoctable) {
                    ScanActivity scanActivity = ScanActivity.this;
                    scanActivity.setMaxwidth(Utils.getPrefInt(scanActivity.getContext(), Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_MAX_WIDTH));
                    ScanActivity scanActivity2 = ScanActivity.this;
                    scanActivity2.setMaxheight(Utils.getPrefInt(scanActivity2.getContext(), Constants.SCAN_REFS_SUPPORTED_OPTIONS, Constants.SCAN_REFS_MAX_HEIGHT));
                }
                if (ScanActivity.this.getMaxwidth() == 0) {
                    ScanActivity.this.setMaxwidth(Constants.SCAN_MAX_WIDTH);
                }
                if (ScanActivity.this.getMaxheight() == 0) {
                    ScanActivity.this.setMaxheight(Constants.SCAN_MAX_HEIGHT);
                }
                int prefInt = !"".equals(Utils.getPrefString(ScanActivity.this.getContext(), Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SCANNER_MODEL)) ? Utils.getPrefInt(ScanActivity.this.getContext(), Constants.SCAN_REFS_USED_SCANNER_PATH, Constants.SCAN_REFS_SETTINGS_RESOLUTION) : 150;
                if (prefInt == ScanActivity.this.resolution && !ScanActivity.this.isDoctable) {
                    boolean unused4 = ScanActivity.this.isNeedUpdateScanningArea = true;
                }
                int unused5 = ScanActivity.this.resolution = prefInt;
                ScanActivity scanActivity3 = ScanActivity.this;
                int unused6 = scanActivity3.areaHeightOnScreen = scanActivity3.llScanAreaBackground.getHeight();
                ScanActivity scanActivity4 = ScanActivity.this;
                int unused7 = scanActivity4.areaWidthOnScreen = scanActivity4.llScanAreaBackground.getWidth();
            }
            ScanActivity.this.initFrameWithScreensize();
            Point point = ScanActivity.this.getmBaseTop();
            Point point2 = ScanActivity.this.getmBaseBot();
            int i2 = point2.x - point.x;
            int i3 = point2.y - point.y;
            ScanActivity scanActivity5 = ScanActivity.this;
            scanActivity5.setmBaseTop(new Point((((scanActivity5.areaWidthOnScreen) - ScanActivity.this.getMaxScanWidthOnScreen())) / 2, ScanActivity.mARGIN_TOP_BOT));
            ScanActivity scanActivity6 = ScanActivity.this;
            scanActivity6.setmBaseBot(new Point(scanActivity6.areaWidthOnScreen - ScanActivity.this.getmBaseTop().x, ScanActivity.this.areaHeightOnScreen - ScanActivity.mARGIN_TOP_BOT));
            if (!ScanActivity.this.isDoctable && !ScanActivity.this.isNeedGetScanSize) {
                ScanActivity scanActivity7 = ScanActivity.this;
                scanActivity7.setPiBaseTop(new ScanBaseView.PointInfo(scanActivity7.getmBaseTop().x, ScanActivity.this.getmBaseTop().y));
                ScanActivity scanActivity8 = ScanActivity.this;
                scanActivity8.setPiBaseBot(new ScanBaseView.PointInfo(scanActivity8.getmBaseBot().x, ScanActivity.this.getmBaseBot().y));
                ScanActivity scanActivity9 = ScanActivity.this;
                scanActivity9.setmTop(scanActivity9.getmBaseTop());
                ScanActivity scanActivity10 = ScanActivity.this;
                scanActivity10.setmBot(scanActivity10.getmBaseBot());
            }
            if (ScanActivity.this.isNeedGetScanSize) {
                if (ScanActivity.this.isNeedUpdateScanningArea) {
                    ScanActivity scanActivity11 = ScanActivity.this;
                    scanActivity11.setPiBaseTop(new ScanBaseView.PointInfo(scanActivity11.getmBaseTop().x, ScanActivity.this.getmBaseTop().y));
                    ScanActivity scanActivity12 = ScanActivity.this;
                    scanActivity12.setPiBaseBot(new ScanBaseView.PointInfo(scanActivity12.getmBaseBot().x, ScanActivity.this.getmBaseBot().y));
                    ScanActivity scanActivity13 = ScanActivity.this;
                    scanActivity13.setmTop(scanActivity13.getmBaseTop());
                    ScanActivity scanActivity14 = ScanActivity.this;
                    scanActivity14.setmBot(scanActivity14.getmBaseBot());
                    ScanActivity.this.setScreenStatus(1);
                }
                if (ScanActivity.this.isNeedScale) {
                    boolean unused8 = ScanActivity.this.isNeedScale = false;
                    Point point3 = new Point();
                    float f = (float) i2;
                    point2.x = (((float) ScanActivity.this.getmBaseTop().x) + (((float) ((ScanActivity.this.getmBaseBot().x - ScanActivity.this.getmBaseTop().x) * (ScanActivity.this.getmTop().x - point.x))) / f));
                    float f2 = (float) i3;
                    point2.y = (((float) ScanActivity.this.getmBaseTop().y) + (((float) ((ScanActivity.this.getmBaseBot().y - ScanActivity.this.getmBaseTop().y) * (ScanActivity.this.getmTop().y - point.y))) / f2));
                    point3.x = (((float) ScanActivity.this.getmBaseTop().x) + (((float) ((ScanActivity.this.getmBaseBot().x - ScanActivity.this.getmBaseTop().x) * (ScanActivity.this.getmBot().x - point.x))) / f));
                    point3.y = (((float) ScanActivity.this.getmBaseTop().y) + (((float) ((ScanActivity.this.getmBaseBot().y - ScanActivity.this.getmBaseTop().y) * (ScanActivity.this.getmBot().y - point.y))) / f2));
                    ScanActivity scanActivity15 = ScanActivity.this;
                    scanActivity15.setPiBaseTop(new ScanBaseView.PointInfo(point2.x, point2.y));
                    ScanActivity scanActivity16 = ScanActivity.this;
                    scanActivity16.setPiBaseBot(new ScanBaseView.PointInfo(point3.x, point3.y));
                    ScanActivity.this.setmTop(point2);
                    ScanActivity.this.setmBot(point3);
                    if (!ScanActivity.this.isNeedRedrawBitmap && (bmRectF = ScanActivity.this.getBmRectF()) != null) {
                        bmRectF.left = ((float) ScanActivity.this.getmBaseTop().x) + ((((float) (ScanActivity.this.getmBaseBot().x - ScanActivity.this.getmBaseTop().x)) * (bmRectF.left - ((float) point.x))) / f);
                        bmRectF.top = ((float) ScanActivity.this.getmBaseTop().y) + ((((float) (ScanActivity.this.getmBaseBot().y - ScanActivity.this.getmBaseTop().y)) * (bmRectF.top - ((float) point.y))) / f2);
                        bmRectF.right = ((float) ScanActivity.this.getmBaseTop().x) + ((((float) (ScanActivity.this.getmBaseBot().x - ScanActivity.this.getmBaseTop().x)) * (bmRectF.right - ((float) point.x))) / f);
                        bmRectF.bottom = ((float) ScanActivity.this.getmBaseTop().y) + ((((float) (ScanActivity.this.getmBaseBot().y - ScanActivity.this.getmBaseTop().y)) * (bmRectF.bottom - ((float) point.y))) / f2);
                        ScanActivity.this.setBmRectF(bmRectF);
                    }
                }
                ScanActivity scanActivity17 = ScanActivity.this;
                scanActivity17.setmCenter(scanActivity17.calculateTheCenterPoint(scanActivity17.getmTop(), ScanActivity.this.getmBot()));
                ScanActivity scanActivity18 = ScanActivity.this;
                scanActivity18.setInSampleSize(Math.round((float) (100 / ((scanActivity18.areaHeightOnScreen * 100) / 650))));
                ScanActivity.this.get_bmOption().inSampleSize = ScanActivity.this.getInSampleSize();
                ScanActivity.this.setupScanArea();
                boolean unused9 = ScanActivity.this.isNeedGetScanSize = false;
                ScanActivity.this.setSetSize(true);
                SharedPreferences sharedPreferences = ScanActivity.this.context.getSharedPreferences(Constants.SCAN_REFS_USED_SCANNER_PATH, 0);
                if (ScanActivity.this.isDoctable) {
                    i = sharedPreferences.getInt(Constants.SCAN_REFS_SCANNER_CHOSEN_SIZE_DOC, Constants.PaperName.EPS_MSID_UNKNOWN.getCode());
                } else {
                    i = sharedPreferences.getInt(epson.common.Constants.SCAN_REFS_SCANNER_CHOSEN_SIZE_ADF, Constants.PaperName.EPS_MSID_UNKNOWN.getCode());
                }
                if (ScanActivity.this.isNeedUpdateScanningArea) {
                    if (i == Constants.PaperName.EPS_MSID_UNKNOWN.getCode()) {
                        ScanActivity.this.chooseScanSize(ScanSizeHelper.getDefaultScanSize());
                    } else {
                        ScanActivity.this.chooseScanSize(i);
                    }
                }
                ScanActivity.this.scanArea.redrawCBHandler = ScanActivity.this.scanningProgressHandler;
                boolean unused10 = ScanActivity.this.isNeedUpdateScanningArea = false;
            }
            return true;
        }
    };
    private boolean mScanAreaBackgroundViewSizeChanged;
    private CommonLog mScanLog;
    private String oldScannerId;
    private int previousTotalScanned = 0;
    private int resolution = 0;
    private ScanBaseView.ScanAreaSet scanArea;
    private ScanBaseView.ScanAreaBackground scanAreaBackground;
    private int scanOrigin = 2;
    private Handler scanningProgressHandler = new Handler(new Handler.Callback() {
        /* JADX WARNING: Can't fix incorrect switch cases order */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        public boolean handleMessage(android.os.Message r9) {
            /*
                r8 = this;
                epson.scan.activity.ScanActivity r0 = epson.scan.activity.ScanActivity.this
                boolean r0 = r0.isFinishing()
                r1 = -3
                r2 = -100
                r3 = 20
                r4 = 2
                r5 = 1
                if (r0 == 0) goto L_0x0021
                int r0 = r9.what
                if (r0 == r2) goto L_0x0020
                if (r0 == r1) goto L_0x0020
                if (r0 == r4) goto L_0x0020
                if (r0 == r3) goto L_0x0020
                switch(r0) {
                    case -1: goto L_0x0020;
                    case 0: goto L_0x0020;
                    default: goto L_0x001c;
                }
            L_0x001c:
                switch(r0) {
                    case 10: goto L_0x0020;
                    case 11: goto L_0x0020;
                    default: goto L_0x001f;
                }
            L_0x001f:
                goto L_0x0021
            L_0x0020:
                return r5
            L_0x0021:
                int r9 = r9.what
                r0 = 0
                if (r9 == r2) goto L_0x044e
                r2 = -1
                if (r9 == r4) goto L_0x03b2
                if (r9 == r3) goto L_0x0382
                r6 = 1000(0x3e8, double:4.94E-321)
                switch(r9) {
                    case -3: goto L_0x037b;
                    case -2: goto L_0x02a0;
                    case -1: goto L_0x01a1;
                    case 0: goto L_0x00ea;
                    default: goto L_0x0030;
                }
            L_0x0030:
                switch(r9) {
                    case 10: goto L_0x0093;
                    case 11: goto L_0x0035;
                    default: goto L_0x0033;
                }
            L_0x0033:
                goto L_0x047f
            L_0x0035:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r1 = r9.escan
                java.util.List r1 = r1.getListScannedFile()
                int r1 = r1.size()
                r9.totalScanned = r1
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                int r9 = r9.totalScanned
                if (r9 >= r5) goto L_0x004c
                return r0
            L_0x004c:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.String r9 = r9.getLocalClassName()
                java.lang.String r1 = "end page, waiting..."
                epson.print.Util.EPLog.i(r9, r1)
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                int r9 = r9.convertCount
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r1 = r1.escan
                java.util.List r1 = r1.getListScannedFile()
                int r1 = r1.size()
                if (r9 >= r1) goto L_0x0086
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r1 = r9.escan
                java.util.List r1 = r1.getListScannedFile()
                epson.scan.activity.ScanActivity r2 = epson.scan.activity.ScanActivity.this
                int r2 = r2.convertCount
                java.lang.Object r1 = r1.get(r2)
                java.lang.String r1 = (java.lang.String) r1
                r9.convert(r1)
            L_0x0086:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.String r9 = r9.getLocalClassName()
                java.lang.String r1 = "done add to list"
                epson.print.Util.EPLog.i(r9, r1)
                goto L_0x047f
            L_0x0093:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r1 = r9.escan
                java.util.List r1 = r1.getListScannedFile()
                int r1 = r1.size()
                r9.totalScanned = r1
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                int r9 = r9.totalScanned
                if (r9 >= r5) goto L_0x00aa
                return r0
            L_0x00aa:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r9 = r9.escan
                boolean r9 = r9.isJobDone()
                if (r9 == 0) goto L_0x00b7
                return r5
            L_0x00b7:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this     // Catch:{ RejectedExecutionException -> 0x00e4 }
                boolean r9 = r9.isDecoding     // Catch:{ RejectedExecutionException -> 0x00e4 }
                if (r9 != 0) goto L_0x047f
                epson.scan.activity.ScanActivity$BitmapTask r9 = new epson.scan.activity.ScanActivity$BitmapTask     // Catch:{ RejectedExecutionException -> 0x00e4 }
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this     // Catch:{ RejectedExecutionException -> 0x00e4 }
                r9.<init>()     // Catch:{ RejectedExecutionException -> 0x00e4 }
                java.lang.String[] r1 = new java.lang.String[r5]     // Catch:{ RejectedExecutionException -> 0x00e4 }
                epson.scan.activity.ScanActivity r2 = epson.scan.activity.ScanActivity.this     // Catch:{ RejectedExecutionException -> 0x00e4 }
                epson.scan.lib.escanLib r2 = r2.escan     // Catch:{ RejectedExecutionException -> 0x00e4 }
                java.util.List r2 = r2.getListScannedFile()     // Catch:{ RejectedExecutionException -> 0x00e4 }
                epson.scan.activity.ScanActivity r3 = epson.scan.activity.ScanActivity.this     // Catch:{ RejectedExecutionException -> 0x00e4 }
                int r3 = r3.totalScanned     // Catch:{ RejectedExecutionException -> 0x00e4 }
                int r3 = r3 - r5
                java.lang.Object r2 = r2.get(r3)     // Catch:{ RejectedExecutionException -> 0x00e4 }
                java.lang.String r2 = (java.lang.String) r2     // Catch:{ RejectedExecutionException -> 0x00e4 }
                r1[r0] = r2     // Catch:{ RejectedExecutionException -> 0x00e4 }
                r9.execute(r1)     // Catch:{ RejectedExecutionException -> 0x00e4 }
                goto L_0x047f
            L_0x00e4:
                r9 = move-exception
                r9.printStackTrace()
                goto L_0x047f
            L_0x00ea:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.String r9 = r9.getCallingPackage()
                java.lang.String r1 = "[EPSON SCAN] START SCAN"
                epson.print.Util.EPLog.i(r9, r1)
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean unused = r9.isStopScan = r0
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean unused = r9.isConfirmCancel = r0
                boolean r9 = epson.scan.activity.ScanContinueParam.isContinueScanning()
                if (r9 != 0) goto L_0x010a
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                int unused = r9.convertCount = r0
            L_0x010a:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean unused = r9.isDecoding = r0
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.view.WindowManager r9 = r9.getWindowManager()
                android.view.Display r9 = r9.getDefaultDisplay()
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                android.content.res.Resources r1 = r1.getResources()
                android.content.res.Configuration r1 = r1.getConfiguration()
                java.lang.String r2 = "display;"
                int r3 = r1.orientation
                java.lang.String r3 = java.lang.String.valueOf(r3)
                epson.print.Util.EPLog.i(r2, r3)
                java.lang.String r2 = "display;"
                int r3 = r9.getRotation()
                java.lang.String r3 = java.lang.String.valueOf(r3)
                epson.print.Util.EPLog.i(r2, r3)
                int r9 = r9.getRotation()
                r2 = 9
                r3 = 8
                switch(r9) {
                    case 0: goto L_0x018b;
                    case 1: goto L_0x017b;
                    case 2: goto L_0x0161;
                    case 3: goto L_0x0147;
                    default: goto L_0x0146;
                }
            L_0x0146:
                goto L_0x019a
            L_0x0147:
                int r9 = android.os.Build.VERSION.SDK_INT
                if (r9 <= r3) goto L_0x015b
                int r9 = r1.orientation
                if (r9 != r5) goto L_0x0155
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.setRequestedOrientation(r5)
                goto L_0x019a
            L_0x0155:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.setRequestedOrientation(r3)
                goto L_0x019a
            L_0x015b:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.setRequestedOrientation(r5)
                goto L_0x019a
            L_0x0161:
                int r9 = android.os.Build.VERSION.SDK_INT
                if (r9 <= r3) goto L_0x0175
                int r9 = r1.orientation
                if (r9 != r4) goto L_0x016f
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.setRequestedOrientation(r3)
                goto L_0x019a
            L_0x016f:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.setRequestedOrientation(r2)
                goto L_0x019a
            L_0x0175:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.setRequestedOrientation(r5)
                goto L_0x019a
            L_0x017b:
                int r9 = r1.orientation
                if (r9 != r5) goto L_0x0185
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.setRequestedOrientation(r2)
                goto L_0x019a
            L_0x0185:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.setRequestedOrientation(r0)
                goto L_0x019a
            L_0x018b:
                int r9 = r1.orientation
                if (r9 != r4) goto L_0x0195
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.setRequestedOrientation(r0)
                goto L_0x019a
            L_0x0195:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.setRequestedOrientation(r5)
            L_0x019a:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.showScanningPop()
                goto L_0x047f
            L_0x01a1:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.app.AlertDialog r9 = r9.confirmAlertDialog
                if (r9 == 0) goto L_0x01be
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.app.AlertDialog r9 = r9.confirmAlertDialog
                boolean r9 = r9.isShowing()
                if (r9 == 0) goto L_0x01be
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.app.AlertDialog r9 = r9.confirmAlertDialog
                r9.dismiss()
            L_0x01be:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean unused = r9.isStopScan = r5
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.os.Handler r9 = r9.scanningProgressHandler
                r9.sendEmptyMessage(r1)
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean r9 = r9.isCompletedScanProcess()
                if (r9 != 0) goto L_0x01df
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.os.Handler r9 = r9.scanningProgressHandler
                r9.sendEmptyMessageDelayed(r2, r6)
                goto L_0x047f
            L_0x01df:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.updateScreenPreviewToLastData()
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean r9 = r9.isConfirmCancel
                if (r9 == 0) goto L_0x01ee
                goto L_0x047f
            L_0x01ee:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.app.AlertDialog r9 = r9.errorDialog
                if (r9 == 0) goto L_0x037b
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.app.AlertDialog r9 = r9.errorDialog
                boolean r9 = r9.isShowing()
                if (r9 != 0) goto L_0x037b
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r9 = r9.escan
                int[] r9 = r9.getStatus()
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                int r1 = r1.error
                r2 = -1100(0xfffffffffffffbb4, float:NaN)
                if (r1 != r2) goto L_0x0227
                r1 = r9[r5]
                r2 = 5
                if (r1 != r2) goto L_0x025d
                r1 = r9[r4]
                if (r1 == 0) goto L_0x025d
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                r9 = r9[r4]
                int unused = r1.error = r9
                goto L_0x025d
            L_0x0227:
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                int r1 = r1.error
                r3 = 2131625174(0x7f0e04d6, float:1.8877549E38)
                if (r1 == r3) goto L_0x025d
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                int r1 = r1.error
                r3 = -1300(0xfffffffffffffaec, float:NaN)
                if (r1 == r3) goto L_0x025d
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                int r1 = r1.error
                if (r1 == r2) goto L_0x025d
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                int r1 = r1.error
                if (r1 == r5) goto L_0x025d
                r1 = r9[r4]
                r2 = 100
                if (r1 == r2) goto L_0x025d
                r1 = r9[r4]
                if (r1 == 0) goto L_0x025d
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                r9 = r9[r4]
                int unused = r1.error = r9
            L_0x025d:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.String r9 = r9.getCallingPackage()
                java.lang.StringBuilder r1 = new java.lang.StringBuilder
                r1.<init>()
                java.lang.String r2 = "error = "
                r1.append(r2)
                epson.scan.activity.ScanActivity r2 = epson.scan.activity.ScanActivity.this
                int r2 = r2.error
                r1.append(r2)
                java.lang.String r1 = r1.toString()
                epson.print.Util.EPLog.i(r9, r1)
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                int r1 = r9.error
                r9.setupErrorMessage(r1)
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.app.AlertDialog r9 = r9.errorDialog
                r9.show()
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.content.Context r9 = r9.context
                java.lang.String r1 = "scanner"
                epson.scan.activity.ScanActivity r2 = epson.scan.activity.ScanActivity.this
                java.lang.String r2 = r2.usingScannerIp
                com.epson.mobilephone.common.wifidirect.WiFiDirectManager.disconnect(r9, r1, r2)
                goto L_0x037b
            L_0x02a0:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean unused = r9.isStopScan = r5
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.Thread r9 = r9.doscan
                if (r9 == 0) goto L_0x02c2
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.Thread r9 = r9.doscan
                boolean r9 = r9.isAlive()
                if (r9 == 0) goto L_0x02c2
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.Thread r9 = r9.doscan
                r9.interrupt()
            L_0x02c2:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r9 = r9.escan
                boolean r9 = r9.isScanning()
                if (r9 != 0) goto L_0x02e7
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.String r9 = r9.getLocalClassName()
                java.lang.String r1 = "scan, cancel find"
                epson.print.Util.EPLog.i(r9, r1)
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r9 = r9.escan
                r9.escanWrapperCancelFindScanner()
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.hideScanningPop()
            L_0x02e7:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r9 = r9.escan
                boolean r9 = r9.isScanning()
                r1 = -2
                if (r9 == 0) goto L_0x034f
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r9 = r9.escan
                boolean r9 = r9.isJobDone()
                if (r9 != 0) goto L_0x034f
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r9 = r9.escan
                boolean r9 = r9.isCanselOK()
                if (r9 != r5) goto L_0x032c
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.String r9 = r9.getLocalClassName()
                java.lang.String r2 = "isCanselOK OK"
                epson.print.Util.EPLog.i(r9, r2)
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.String r9 = r9.getLocalClassName()
                java.lang.String r2 = "scan, cancel scan job"
                epson.print.Util.EPLog.i(r9, r2)
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r9 = r9.escan
                r9.cancelScanJob()
                goto L_0x034f
            L_0x032c:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.String r9 = r9.getLocalClassName()
                java.lang.String r2 = "isCanselOK NO"
                epson.print.Util.EPLog.i(r9, r2)
                java.lang.Thread.sleep(r6)     // Catch:{ InterruptedException -> 0x033b }
                goto L_0x033f
            L_0x033b:
                r9 = move-exception
                r9.printStackTrace()
            L_0x033f:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.os.Handler r9 = r9.scanningProgressHandler
                r9.sendEmptyMessage(r1)
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean unused = r9.isConfirmCancel = r0
                goto L_0x047f
            L_0x034f:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean unused = r9.isConfirmCancel = r0
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean r9 = r9.isCompletedScanProcess()
                if (r9 != 0) goto L_0x0367
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.os.Handler r9 = r9.scanningProgressHandler
                r9.sendEmptyMessageDelayed(r1, r6)
                goto L_0x047f
            L_0x0367:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.updateScreenPreviewToLastData()
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.content.Context r9 = r9.context
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                java.lang.String r1 = r1.usingScannerIp
                epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r9, r1)
                goto L_0x047f
            L_0x037b:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.hideScanningPop()
                goto L_0x047f
            L_0x0382:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.Thread r9 = r9.doscan
                if (r9 == 0) goto L_0x0396
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.Thread r9 = r9.doscan
                boolean r9 = r9.isAlive()
                if (r9 != 0) goto L_0x039e
            L_0x0396:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean r9 = r9.isValidArea()
                if (r9 != 0) goto L_0x03ab
            L_0x039e:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.os.Handler r9 = r9.scanningProgressHandler
                r1 = 300(0x12c, double:1.48E-321)
                r9.sendEmptyMessageDelayed(r3, r1)
                goto L_0x047f
            L_0x03ab:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                r9.scanStart()
                goto L_0x047f
            L_0x03b2:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                java.lang.String r9 = r9.getLocalClassName()
                java.lang.String r1 = "MESSAGE SCAN FINISHED!!!"
                epson.print.Util.EPLog.i(r9, r1)
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r1 = r9.escan
                java.util.List r1 = r1.getListScannedFile()
                int r1 = r1.size()
                r9.totalScanned = r1
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                int r9 = r9.totalScanned
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                epson.scan.activity.ScanCount.saveScanCount(r1, r9)
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                epson.scan.lib.escanLib r1 = r1.escan
                r1.setJobDone(r5)
                epson.scan.activity.ScanActivity r1 = epson.scan.activity.ScanActivity.this
                android.content.Context r1 = r1.getApplicationContext()
                int r1 = com.epson.iprint.prtlogger.Analytics.getConnectionType(r1)
                epson.scan.activity.ScanActivity r3 = epson.scan.activity.ScanActivity.this
                android.app.AlertDialog r3 = r3.confirmAlertDialog
                if (r3 == 0) goto L_0x0406
                epson.scan.activity.ScanActivity r3 = epson.scan.activity.ScanActivity.this
                android.app.AlertDialog r3 = r3.confirmAlertDialog
                boolean r3 = r3.isShowing()
                if (r3 == 0) goto L_0x0406
                epson.scan.activity.ScanActivity r3 = epson.scan.activity.ScanActivity.this
                android.app.AlertDialog r3 = r3.confirmAlertDialog
                r3.dismiss()
            L_0x0406:
                epson.scan.activity.ScanActivity r3 = epson.scan.activity.ScanActivity.this
                r3.updateDoneScanJob()
                epson.scan.activity.ScanActivity r3 = epson.scan.activity.ScanActivity.this
                java.util.ArrayList r3 = r3.getListSavedJPGFilePath()
                int r3 = r3.size()
                epson.scan.activity.ScanContinueParam.setScannedFileCount(r3)
                boolean r3 = epson.scan.activity.ScanContinueParam.isReachMaximumScan()
                if (r3 == 0) goto L_0x0431
                epson.scan.activity.ScanActivity r3 = epson.scan.activity.ScanActivity.this
                android.content.Context r3 = r3.context
                java.lang.String r4 = "epson.scanner.SelectedScanner"
                java.lang.String r6 = "SCAN_REFS_SETTINGS_SOURCE"
                int r3 = epson.common.Utils.getPrefInt(r3, r4, r6)
                if (r3 != r5) goto L_0x0431
                epson.scan.activity.ScanActivity r3 = epson.scan.activity.ScanActivity.this
                epson.scan.activity.ScanContinueParam.showScanErrorLimit(r3)
            L_0x0431:
                epson.scan.activity.ScanActivity r3 = epson.scan.activity.ScanActivity.this
                r3.setRequestedOrientation(r2)
                epson.scan.activity.ScanActivity r2 = epson.scan.activity.ScanActivity.this
                android.content.Context r2 = r2.context
                epson.scan.activity.ScanActivity r3 = epson.scan.activity.ScanActivity.this
                java.lang.String r3 = r3.usingScannerIp
                epson.scan.lib.ScannerConnection.disconnectIfSimpleAp(r2, r3)
                epson.scan.activity.ScanActivity r2 = epson.scan.activity.ScanActivity.this
                r2.loggerScanCountUp()
                epson.scan.activity.ScanActivity r2 = epson.scan.activity.ScanActivity.this
                r2.checkLoggerServer(r9, r1)
                goto L_0x047f
            L_0x044e:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.activity.ScanBaseView$ScanAreaSet r9 = r9.scanArea
                r1 = 0
                r9.redrawCBHandler = r1
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean r9 = r9.isNeedRedrawBitmap
                if (r9 != r5) goto L_0x0476
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                boolean unused = r9.isNeedRedrawBitmap = r0
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.graphics.RectF r1 = r9.getRectScanArea()
                android.graphics.RectF unused = r9.area = r1
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                android.graphics.RectF r1 = r9.area
                r9.setBmRectF(r1)
            L_0x0476:
                epson.scan.activity.ScanActivity r9 = epson.scan.activity.ScanActivity.this
                epson.scan.activity.ScanBaseView$ScanAreaSet r9 = r9.scanArea
                r9.postInvalidate()
            L_0x047f:
                return r0
            */
            throw new UnsupportedOperationException("Method not decompiled: epson.scan.activity.ScanActivity.C240214.handleMessage(android.os.Message):boolean");
        }
    });
    private TextView tvScanResult;
    private String usingScannerId;
    private String usingScannerIp;
    private int usingScannerLocation;
    private String usingScannerModel;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.scan);
        setActionBar(R.string.str_scan_btn, true);
        setContext(this);
        mActivityPaused = true;
        mScanAreaBackgroundViewSizeChanged = false;
        ExternalFileUtils.getInstance(this).initTempViewDir();
        ExternalFileUtils.getInstance(this).initPrintDir();
        Intent intent = getIntent();
        if (intent.getAction() == null || !intent.getAction().equals(EpsoniPrintSharedActivity.ACTION_SCAN)) {
            extParam = new SharedParamScan();
        } else {
            isCustomAction = true;
            extParam = (SharedParamScan) intent.getSerializableExtra("extParam");
        }
        try {
            mScanLog = (CommonLog) intent.getSerializableExtra(PARAM_KEY_SCAN_LOG);
        } catch (ClassCastException unused) {
        }
        if (mScanLog == null) {
            mScanLog = new CommonLog();
        }
        btnScan = (Button) findViewById(R.id.btnScan);
        btnScan.setOnClickListener(mButtonScanListener);
        btnSave = (Button) findViewById(R.id.btnSave);
        btnSave.setOnClickListener(mButtonSaveListener);
        btnMail = (Button) findViewById(R.id.btnMail);
        btnMail.setOnClickListener(mButtonMailListener);
        btnPrint = (Button) findViewById(R.id.btnPrint);
        btnPrint.setOnClickListener(mButtonPrintListener);
        getSelectedScannerInfo();
        disableFunctionButtons();
        if (this.isCustomAction) {
            btnMail.setVisibility(View.GONE);
            btnPrint.setVisibility(View.GONE);
        }
        llScanAreaBackground = (LinearLayout) findViewById(R.id.llScanAreaBackground);
        scanAreaBackground = new ScanBaseView.ScanAreaBackground(getContext());
        llScanAreaBackground.addView(this.scanAreaBackground);
        tvScanResult = (TextView) findViewById(R.id.tvScanResult);
        scanArea = new ScanBaseView.ScanAreaSet(getContext());
        flScanResult = (FrameLayout) findViewById(R.id.flScanResult);
        gestureDetector = new GestureDetector(this, new ScanAreaGestureDetector());
        gestureListener = new View.OnTouchListener() {
            public boolean onTouch(View view, MotionEvent motionEvent) {
                ScanActivity.this.gestureDetector.onTouchEvent(motionEvent);
                ScanActivity.this.scanArea.onTouchEvent(motionEvent);
                return true;
            }
        };
        flScanResult.setOnTouchListener(this.gestureListener);
        btnNext = (Button) findViewById(R.id.btnNext);
        btnNext.setOnClickListener(mButtonNextListener);
        btnNext.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case 0:
                        ScanActivity.this.btnNext.setBackgroundResource(R.drawable.bt_right_hover);
                        return false;
                    case 1:
                        ScanActivity.this.btnNext.setBackgroundResource(R.drawable.bt_right_1);
                        return false;
                    default:
                        return false;
                }
            }
        });
        btnPrev = (Button) findViewById(R.id.btnPrev);
        btnPrev.setOnClickListener(mButtonPrevListener);
        btnPrev.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case 0:
                        ScanActivity.this.btnPrev.setBackgroundResource(R.drawable.bt_left_hover);
                        return false;
                    case 1:
                        ScanActivity.this.btnPrev.setBackgroundResource(R.drawable.bt_left);
                        return false;
                    default:
                        return false;
                }
            }
        });
        btnNext.setVisibility(View.GONE);
        btnPrev.setVisibility(View.GONE);
        errorDialog = new AlertDialog.Builder(this).create();
        escan = getEscan();
        escan.escanWrapperInitDriver(this);
        escan.setScanHandler(this.scanningProgressHandler);
        llScanArea = (LinearLayout) findViewById(R.id.llScanArea);
        llScanArea.addView(this.scanArea);
        llScanningProgress = (LinearLayout) findViewById(R.id.llScanningProgress);
        btnCancelScan = (Button) findViewById(R.id.btnCancelScan);
        btnCancelScan.setOnClickListener(mButtonCancelScanListener);
        llScanArea.getViewTreeObserver().addOnPreDrawListener(mOnPreDrawListener);
        if (ActivityRequestPermissions.isRuntimePermissionSupported()) {
            String[] strArr = {"android.permission.WRITE_EXTERNAL_STORAGE"};
            ActivityRequestPermissions.Permission permission = new ActivityRequestPermissions.Permission(strArr[0], new String[]{getString(R.string.permission_dialog_title), getString(R.string.permission_dialog_title)}, new String[]{ActivityRequestPermissions.DialogParameter.setMessage2((Context) this, getString(R.string.permission_dialog_message_storage)), ActivityRequestPermissions.DialogParameter.setMessage3A((Context) this, getString(R.string.permission_dialog_message_storage), getString(R.string.permission_function_storage))});
            if (!ActivityRequestPermissions.checkPermission(this, strArr)) {
                ActivityRequestPermissions.requestPermission((Activity) this, permission, 4);
                return;
            }
        }
        if (bundle == null && !startI2ActivityIfEscIVersionMismatch()) {
        }
    }

    private boolean startI2ActivityIfEscIVersionMismatch() {
        if (ScanInfoStorage.loadEscIVersion(this) != 2) {
            return false;
        }
        SharedParamScan sharedParamScan = null;
        setBm((Bitmap) null);
        boolean z = bAutoStartScan;
        if (this.isCustomAction) {
            sharedParamScan = extParam;
        }
        startActivityForResult(ScanActivityCommonParams.getEscIVersionChangeIntent(this, 2, z, sharedParamScan, mScanLog), 20);
        return true;
    }

    public void onScanAreaSizeChange() {
        mScanAreaBackgroundViewSizeChanged = true;
    }

    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        LinearLayout linearLayout = llScanningProgress;
        if (linearLayout == null || linearLayout.getVisibility() != 0) {
            return super.onKeyDown(i, keyEvent);
        }
        return true;
    }

    protected void onRestart() {
        isNeedDeleteTempFile = false;
        super.onRestart();
    }

    protected void onStart() {
        if (this.isNeedDeleteTempFile) {
            removeTempContents(this);
        }
        super.onStart();
    }

    public void onBackPressed() {
        super.onBackPressed();
        escan.escanWrapperReleaseDriver();
        removeTempContents(this);
        finish();
    }

    protected void onDestroy() {
        removeTempContents(this);
        if (this.isCustomAction) {
            ArrayList<String> listSavedJPGFilePath = getListSavedJPGFilePath();
            for (int i = 0; i < listSavedJPGFilePath.size(); i++) {
                Utils.deleteTempFile(listSavedJPGFilePath.get(i));
            }
        }
        System.gc();
        super.onDestroy();
    }

    protected void onResume() {
        super.onResume();
        NfcTagUtils.enableForegroundDispatch(this, (IntentFilter[]) null, (String[][]) null);
        mActivityPaused = false;
    }

    protected void onPause() {
        super.onPause();
        NfcTagUtils.disableForegroundDispatch(this);
        mActivityPaused = true;
        if (isFinishing()) {
            escan.escanWrapperReleaseDriver();
        }
    }

    protected void onNewIntent(Intent intent) {
        NfcTagUtils.EpsonNfcConnectInfo parseNECTag;
        super.onNewIntent(intent);
        String action = intent.getAction();
        Thread thread = doscan;
        if ((thread == null || !thread.isAlive()) && "android.nfc.action.NDEF_DISCOVERED".equals(action) && (parseNECTag = NfcTagUtils.parseNECTag(this, intent)) != null) {
            Intent intent2 = new Intent();
            intent2.setClass(this, ActivityNfcPrinter.class);
            intent2.putExtra(ActivityNfcPrinter.CONNECTINFO, parseNECTag);
            intent2.putExtra(ActivityNfcPrinter.CHANGEMODE, 2);
            startActivityForResult(intent2, 2);
            bAutoStartScan = true;
        }
    }

    public static void removeTempContents(Context context) {
        File file = new File(ExternalFileUtils.getInstance(context).getScannedImageDir());
        if (file.exists()) {
            if (file.isDirectory()) {
                for (File file2 : file.listFiles()) {
                    if (file2.isFile()) {
                        file2.delete();
                    }
                }
            }
            if (file.isFile()) {
                file.delete();
            }
        }
    }

    protected void onStop() {
        isStopScan = true;
        escan.setJobDone(false);
        Thread thread = doscan;
        if (thread != null && thread.isAlive()) {
            scanningProgressHandler.sendEmptyMessage(-2);
        }
        AlertDialog alertDialog = errorDialog;
        if (alertDialog != null && alertDialog.isShowing()) {
            errorDialog.dismiss();
        }
        LinearLayout linearLayout = llScanningProgress;
        if (linearLayout != null && linearLayout.getVisibility() == 0) {
            llScanningProgress.setVisibility(View.GONE);
        }
        super.onStop();
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        isNeedGetScanSize = true;
        isNeedScale = true;
        RectF rectF = area;
        if (rectF != null) {
            area = getRectScanArea();
            if ((rectF.left) == (area.left) && (rectF.top) == (area.top) && (rectF.right) == (area.right) && (rectF.bottom) == (area.bottom)) {
                isNeedRedrawBitmap = true;
            } else {
                isNeedRedrawBitmap = false;
            }
        }
        if (mActivityPaused) {
            mScanAreaBackgroundViewSizeChanged = true;
        }
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.scan_menu, menu);
        super.onCreateOptionsMenu(menu);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != R.id.btn_scan_settings) {
            return super.onOptionsItemSelected(menuItem);
        }
        callScanSetting();
        return true;
    }

    private void initFrameWithScreensize() {
        int i = 20;
        while (true) {
            int i2 = areaHeightOnScreen;
            if (i < i2) {
                mARGIN_TOP_BOT = i;
                setMaxScanHeightOnScreen((i2 - (mARGIN_TOP_BOT * 2)));
                setScale((getMaxheight()) / getMaxScanHeightOnScreen());
                setMaxScanWidthOnScreen((getMaxwidth()) / getScale());
                if (getMaxScanWidthOnScreen() > ((this.areaWidthOnScreen - 20))) {
                    i += 10;
                } else {
                    return;
                }
            } else {
                return;
            }
        }
    }

    private void chooseScanSize(int i) {
        int i2;
        int i3;
        int i4 = i;
        if (i4 == Constants.PaperName.EPS_MSID_USER.getCode()) {
            int i5 = resolution;
            double d = i5 != 75 ? i5 != 300 ? 1.0d : 2.0d : 0.5d;
            i3 = Utils.getPrefInt(this.context, epson.common.Constants.SCAN_REFS_SUPPORTED_OPTIONS, epson.common.Constants.SCAN_REFS_MAX_WIDTH);
            i2 = Utils.getPrefInt(this.context, epson.common.Constants.SCAN_REFS_SUPPORTED_OPTIONS, epson.common.Constants.SCAN_REFS_MAX_HEIGHT);
            if (i3 == 0) {
                i3 = (1275.0d * d);
            }
            if (i2 == 0) {
                i2 = (d * 1755.0d);
            }
        } else {
            Point paperSize = ScanSizeHelper.getPaperSize(i4, resolution);
            int i6 = paperSize.x;
            i2 = paperSize.y;
            i3 = i6;
        }
        if (this.isDoctable) {
            if (this.scanOrigin == 2) {
                setmTop(getmBaseTop());
                double d2 = i3;
                double d3 = i2;
                setmBot(new Point(Math.ceil((getmBaseTop().x) + ((getMaxScanWidthOnScreen() * d2) / (getMaxwidth()))), Math.round((getmBaseTop().y) + ((getMaxScanHeightOnScreen() * d3) / (getMaxheight())))));
                setPiBaseTop(new ScanBaseView.PointInfo(getmBaseTop().x, getmBaseTop().y));
                setPiBaseBot(new ScanBaseView.PointInfo((getmBaseTop().x) + ((d2 * getMaxScanWidthOnScreen()) / (getMaxwidth())), (getmBaseTop().y) + ((d3 * getMaxScanHeightOnScreen()) / (getMaxheight()))));
                setScreenStatus(1);
            }
            hideTotalScanned();
        } else {
            setMaxwidth(i3);
            setMaxheight(i2);
            setScale((getMaxheight()) / getMaxScanHeightOnScreen());
            setMaxScanWidthOnScreen((((getMaxwidth()) / getScale())));
            setmBaseTop(new Point((((areaWidthOnScreen) - getMaxScanWidthOnScreen())) / 2, mARGIN_TOP_BOT));
            setmBaseBot(new Point(this.areaWidthOnScreen - getmBaseTop().x, areaHeightOnScreen - mARGIN_TOP_BOT));
            setmTop(getmBaseTop());
            setmBot(getmBaseBot());
            setPiBaseTop(new ScanBaseView.PointInfo(((areaWidthOnScreen) - getMaxScanWidthOnScreen()) / 2.0d, mARGIN_TOP_BOT));
            setPiBaseBot(new ScanBaseView.PointInfo((this.areaWidthOnScreen - getmBaseTop().x), (this.areaHeightOnScreen - mARGIN_TOP_BOT)));
            if (this.isNeedClearBm) {
                hideTotalScanned();
                setBm((Bitmap) null);
            }
        }
        setmCenter(calculateTheCenterPoint(getmTop(), getmBot()));
        setSetSize(true);
        scanArea.postInvalidate();
        scanAreaBackground.postInvalidate();
        if (this.isDoctable) {
            Utils.savePref(getApplicationContext(), epson.common.Constants.SCAN_REFS_USED_SCANNER_PATH, epson.common.Constants.SCAN_REFS_SCANNER_CHOSEN_SIZE_DOC, i4);
        } else {
            Utils.savePref(getApplicationContext(), epson.common.Constants.SCAN_REFS_USED_SCANNER_PATH, epson.common.Constants.SCAN_REFS_SCANNER_CHOSEN_SIZE_ADF, i4);
        }
    }

    private void nextPage() {
        curentViewingFile++;
        if (this.curentViewingFile > 300 || curentViewingFile > totalScanned) {
            curentViewingFile--;
            return;
        }
        updateThumbResult(this.curentViewingFile);
        showDisplayingResult();
        scanArea.postInvalidate();
    }

    private void prevPage() {
        curentViewingFile--;
        if (this.curentViewingFile < 1) {
            curentViewingFile++;
            return;
        }
        updateThumbResult(this.curentViewingFile);
        showDisplayingResult();
        scanArea.postInvalidate();
    }

    private void scanStart() {
        if (this.usingScannerModel.equals(getString(R.string.str_lbl_title_scan)) || usingScannerModel.equals("")) {
            new AlertDialog.Builder(this.context).setCancelable(false).setTitle(R.string.scanner_not_select).setMessage(getString(R.string.scanner_notselect_warning)).setPositiveButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                }
            }).show();
            return;
        }
        if (this.isCustomAction) {
            extParam.clearArrayOutFilePath();
        }
        Thread thread = doscan;
        if ((thread == null || !thread.isAlive()) && isValidArea()) {
            error = 0;
            setBm((Bitmap) null);
            isNeedClearBm = false;
            scanAreaBackground.hideText(true);
            scanAreaBackground.invalidate();
            preparingForScan();
            scanningProgressHandler.sendEmptyMessage(0);
            doscan = new Thread() {
                public void run() {
                    if (!WiFiDirectManager.isNeedConnect(ScanActivity.this, WiFiDirectManager.DEVICE_TYPE_SCANNER) || !WiFiDirectManager.reconnect(ScanActivity.this, WiFiDirectManager.DEVICE_TYPE_SCANNER, 10)) {
                        if (!ScanContinueParam.isContinueScanning()) {
                            ScanCount.countUpScanPage(ScanActivity.this.getApplicationContext());
                        }
                        if (!Utils.isMediaMounted()) {
                            int unused = ScanActivity.this.error = 101;
                            ScanActivity.this.scanningProgressHandler.sendEmptyMessage(-1);
                        } else if (!ScanActivity.this.canStartScan()) {
                            int unused2 = ScanActivity.this.error = -1001;
                            ScanActivity.this.scanningProgressHandler.sendEmptyMessage(-1);
                        } else if (ScanActivity.this.usingScannerId == null || ScanActivity.this.usingScannerId.trim().length() < 1) {
                            int unused3 = ScanActivity.this.error = -1300;
                            ScanActivity.this.scanningProgressHandler.sendEmptyMessage(-1);
                        } else {
                            if (ScanActivity.this.usingScannerLocation != 3) {
                                ScanActivity scanActivity = ScanActivity.this;
                                int unused4 = scanActivity.error = scanActivity.escan.probeScannerById(ScanActivity.this.usingScannerId, ScanActivity.this.usingScannerIp);
                                if (ScanActivity.this.error == -1051) {
                                    EPLog.e(ScanActivity.this.getLocalClassName(), "scan, ESCAN_ERR_LIB_NOT_INITIALIZED");
                                    ScanActivity.this.escan.escanWrapperInitDriver(ScanActivity.this);
                                    ScanActivity scanActivity2 = ScanActivity.this;
                                    int unused5 = scanActivity2.error = scanActivity2.escan.probeScannerById(ScanActivity.this.usingScannerId, ScanActivity.this.usingScannerIp);
                                }
                            } else {
                                ScanActivity scanActivity3 = ScanActivity.this;
                                int unused6 = scanActivity3.error = scanActivity3.escan.probeScannerByIp(ScanActivity.this.usingScannerId, ScanActivity.this.usingScannerIp);
                                if (ScanActivity.this.error == -1051) {
                                    EPLog.e(ScanActivity.this.getLocalClassName(), "scan, ESCAN_ERR_LIB_NOT_INITIALIZED");
                                    ScanActivity.this.escan.escanWrapperInitDriver(ScanActivity.this);
                                    ScanActivity scanActivity4 = ScanActivity.this;
                                    int unused7 = scanActivity4.error = scanActivity4.escan.probeScannerByIp(ScanActivity.this.usingScannerId, ScanActivity.this.usingScannerIp);
                                }
                            }
                            if (ScanActivity.this.error == 0) {
                                EPLog.i(ScanActivity.this.getLocalClassName(), "scan, done probe");
                                if (ScanActivity.this.escan.getListFoundScanner() == null || ScanActivity.this.escan.getListFoundScanner().size() < 1) {
                                    EPLog.e(ScanActivity.this.getLocalClassName(), "scan, ESCAN_ERR_SCANNER_NOT_FOUND");
                                    int unused8 = ScanActivity.this.error = -1300;
                                    if (!ScanActivity.this.isStopScan) {
                                        ScanActivity.this.scanningProgressHandler.sendEmptyMessage(-1);
                                        return;
                                    }
                                    return;
                                }
                                ScanActivity scanActivity5 = ScanActivity.this;
                                int unused9 = scanActivity5.error = scanActivity5.escan.escanWrapperSetScanner(0);
                                if (ScanActivity.this.error != 0) {
                                    int unused10 = ScanActivity.this.error = -1300;
                                    ScanActivity.this.scanningProgressHandler.sendEmptyMessage(-1);
                                    return;
                                }
                                ScanActivity scanActivity6 = ScanActivity.this;
                                String unused11 = scanActivity6.usingScannerIp = scanActivity6.escan.getListFoundScanner().get(0).getIp();
                                ScanActivity.this.escan.resetEscanLib();
                                if (ScanActivity.this.escan.getListScannedFile() == null) {
                                    EPLog.i(ScanActivity.this.getLocalClassName(), "scan, getListScannedFile == NULL");
                                    ScanActivity.this.escan.setListScannedFile(new ArrayList());
                                } else if (!ScanContinueParam.isContinueScanning()) {
                                    EPLog.i(ScanActivity.this.getLocalClassName(), "scan, getListScannedFile != NULL");
                                    ScanActivity.this.escan.getListScannedFile().clear();
                                    int unused12 = ScanActivity.this.previousTotalScanned = 0;
                                }
                                ScanActivity scanActivity7 = ScanActivity.this;
                                int unused13 = scanActivity7.error = scanActivity7.escan.GetSupportedOption();
                                ScanActivity.this.escan.makeJobAttribute(ScanActivity.this.getContext(), ScanActivity.this.extParam);
                                synchronized (ScanActivity.this) {
                                    I1ScanParams unused14 = ScanActivity.mI1ScanParams = ScanActivity.this.escan.getScanParams();
                                }
                                if (ScanActivity.this.isStopScan || ScanActivity.this.escan.isScanning()) {
                                    EPLog.e(ScanActivity.this.getLocalClassName(), "scan, after makeJobAttribute");
                                    return;
                                }
                                ScanActivity scanActivity8 = ScanActivity.this;
                                String access$3300 = scanActivity8.makeImageName(scanActivity8.extParam);
                                String localClassName = ScanActivity.this.getLocalClassName();
                                EPLog.i(localClassName, "scan, fname = " + access$3300);
                                ScanActivity scanActivity9 = ScanActivity.this;
                                int unused15 = scanActivity9.error = scanActivity9.escan.startScanJob(access$3300);
                                String localClassName2 = ScanActivity.this.getLocalClassName();
                                EPLog.i(localClassName2, "[ESCAN][DONE] escanLib().startScanJob - return - " + ScanActivity.this.error);
                                if (ScanActivity.this.error == 40) {
                                    boolean unused16 = ScanActivity.this.isStopScan = true;
                                    int unused17 = ScanActivity.this.error = 0;
                                }
                                if (!ScanActivity.this.isStopScan) {
                                    EPLog.e(ScanActivity.this.getLocalClassName(), "IN-> isStopScan.");
                                    if (!(ScanActivity.this.escan.getStatus()[2] == 4 || (ScanActivity.this.error == 0 && ScanActivity.this.escan.getStatus()[2] == 0))) {
                                        ScanActivity.this.scanningProgressHandler.sendEmptyMessage(-1);
                                        if (ScanActivity.this.escan.getListScannedFile().size() > 0) {
                                            EPLog.e(ScanActivity.this.getLocalClassName(), "END SCAN because error.");
                                            ScanActivity.this.scanningProgressHandler.sendEmptyMessageDelayed(2, 500);
                                        }
                                        EPLog.e(ScanActivity.this.getLocalClassName(), "SCAN error.");
                                        return;
                                    }
                                }
                                EPLog.i(ScanActivity.this.getLocalClassName(), "END SCAN NORMALY.");
                                ScanActivity.this.scanningProgressHandler.sendEmptyMessage(2);
                            } else if (!ScanActivity.this.isStopScan) {
                                ScanActivity.this.scanningProgressHandler.sendEmptyMessage(-1);
                            }
                        }
                    }
                }
            };
            doscan.start();
        }
    }

    private void check3GAndStartPrint() {
        ScanContinueParam.judgeScanContinue(this, getListSavedJPGFilePath());
    }

    private boolean canStartScan() {
        StatFs statFs = new StatFs(CommonDefine.DEFAULT_DIR);
        double availableBlocksLong = (statFs.getAvailableBlocksLong()) * (statFs.getBlockSizeLong());
        double maxwidth = (getMaxwidth() * getMaxheight() * 3);
        if (availableBlocksLong > (!this.isDoctable ? maxwidth * ((ScanContinueParam.getAvailableScanPageCount() + 1)) : maxwidth * 2.0d)) {
            return true;
        }
        return false;
    }

    private String makeImageName(SharedParamScan sharedParamScan) {
        StringBuilder sb;
        if (sharedParamScan.isAvailable()) {
            File file = new File(sharedParamScan.getFolder_name());
            file.mkdirs();
            sb = new StringBuilder(file.getPath());
            sb.append(CommonDefine.SLASH);
            sb.append(sharedParamScan.getFile_name());
        } else {
            File file2 = new File(ExternalFileUtils.getInstance(this).getScannedImageDir());
            file2.mkdirs();
            if (!ScanContinueParam.isContinueScanning()) {
                removeTempScannedImage(file2);
                ScanContinueParam.resetParameter();
            }
            Calendar instance = Calendar.getInstance();
            sb = new StringBuilder(file2.getPath());
            sb.append(CommonDefine.SLASH);
            sb.append(instance.get(1));
            sb.append(instance.get(2) + 1);
            sb.append(instance.get(5));
            sb.append(instance.get(11));
            sb.append(instance.get(12));
            sb.append(instance.get(13));
        }
        return sb.toString();
    }

    private static void removeTempScannedImage(File file) {
        if (!file.exists()) {
            return;
        }
        if (file.isDirectory()) {
            for (File file2 : file.listFiles()) {
                if (file2.isFile()) {
                    file2.delete();
                }
            }
        } else if (file.isFile()) {
            file.delete();
        }
    }

    private void setupErrorMessage(int i) {
        if (i != -500001) {
            if (i != -1501) {
                if (i != -1300) {
                    if (i != -1100) {
                        if (i == -1001) {
                            errorDialog = Utils.makeMessageBox(getContext(), getString(R.string.str_blank), getString(R.string.str_err_msg_out_of_memory_title), getString(R.string.str_ok));
                            return;
                        } else if (i != R.string.str_lbl_title_scan) {
                            switch (i) {
                                case 2:
                                    errorDialog = Utils.makeMessageBox(getContext(), getString(R.string.str_err_msg_scan_coveropen_title), getString(R.string.str_err_msg_scan_coveropen), getString(R.string.str_ok));
                                    return;
                                case 3:
                                    errorDialog = Utils.makeMessageBox(getContext(), getString(R.string.str_err_msg_scan_paperjam_title), getString(R.string.str_err_msg_scan_paperjam), getString(R.string.str_ok));
                                    return;
                                case 4:
                                    errorDialog = Utils.makeMessageBox(getContext(), getString(R.string.str_err_msg_scan_paperout_title), getString(R.string.str_err_msg_scan_paperout), getString(R.string.str_ok));
                                    return;
                                case 5:
                                    break;
                                case 6:
                                    break;
                                default:
                                    switch (i) {
                                        case 100:
                                            errorDialog = Utils.makeMessageBox(getContext(), getString(R.string.str_err_msg_scan_adf_paperout_title), getString(R.string.str_err_msg_scan_adf_paperout), getString(R.string.str_ok));
                                            return;
                                        case 101:
                                            errorDialog = Utils.makeMessageBox(getContext(), getString(R.string.unknow_error_title), getString(R.string.str_no_sdcard), getString(R.string.str_ok));
                                            return;
                                        default:
                                            errorDialog = Utils.makeMessageBox(getContext(), getString(R.string.str_err_msg_scan_generic_internal_title), getString(R.string.str_err_msg_scan_generic_internal), getString(R.string.str_ok));
                                            return;
                                    }
                            }
                        } else {
                            errorDialog = Utils.makeMessageBox(getContext(), getString(R.string.str_lbl_title_scan), getString(R.string.str_ok));
                            return;
                        }
                    }
                    errorDialog = Utils.makeMessageBox(getContext(), getString(R.string.str_err_msg_scan_comm_title), getString(R.string.str_err_msg_scan_comm), getString(R.string.str_ok));
                    return;
                }
                errorDialog = Utils.makeMessageBox(getContext(), getString(R.string.str_err_msg_scan_not_found_title), getString(R.string.str_err_msg_scan_not_found_research), getString(R.string.str_ok));
                return;
            }
            errorDialog = Utils.makeMessageBox(getContext(), getString(R.string.str_err_msg_scan_busy_title), getString(R.string.str_err_msg_scan_busy), getString(R.string.str_ok));
            return;
        }
        errorDialog = Utils.makeMessageBox(this.context, getString(R.string.EPS_PRNERR_COMM_TITLE2), getString(R.string.str_ipprinter_comerror), getString(R.string.str_ok));
    }

    private void showScanningPop() {
        LinearLayout linearLayout = llScanningProgress;
        if (linearLayout != null) {
            linearLayout.setVisibility(View.VISIBLE);
            findViewById(R.id.llScanFunctionBar).invalidate();
        }
        EPLog.i(TAG, "addFlags : FLAG_KEEP_SCREEN_ON ");
        getWindow().addFlags(128);
    }

    private void hideScanningPop() {
        LinearLayout linearLayout = llScanningProgress;
        if (linearLayout != null) {
            linearLayout.setVisibility(View.GONE);
            findViewById(R.id.llScanFunctionBar).invalidate();
        }
        EPLog.i(TAG, "clearFlags : FLAG_KEEP_SCREEN_ON ");
        getWindow().clearFlags(128);
    }

    static PrintLog getPrintLog() {
        PrintLog printLog = new PrintLog();
        printLog.uiRoute = 4;
        return printLog;
    }

    private void getSelectedScannerInfo() {
        if (this.isNeedGetScanSize) {
            String prefString = Utils.getPrefString(getApplicationContext(), epson.common.Constants.SCAN_REFS_USED_SCANNER_PATH, epson.common.Constants.SCAN_REFS_SCANNER_ID);
            if (!this.isNeedUpdateScanningArea) {
                if (prefString.equals(this.usingScannerId)) {
                    isNeedUpdateScanningArea = false;
                } else {
                    isNeedUpdateScanningArea = true;
                    setBm((Bitmap) null);
                }
            }
            usingScannerId = prefString;
            usingScannerModel = Utils.getPrefString(getApplicationContext(), epson.common.Constants.SCAN_REFS_USED_SCANNER_PATH, epson.common.Constants.SCAN_REFS_SCANNER_MODEL);
            usingScannerIp = Utils.getPrefString(getApplicationContext(), epson.common.Constants.SCAN_REFS_USED_SCANNER_PATH, epson.common.Constants.SCAN_REFS_SCANNER_IP);
            usingScannerLocation = Utils.getPrefInt(getApplicationContext(), epson.common.Constants.SCAN_REFS_USED_SCANNER_PATH, epson.common.Constants.SCAN_REFS_SCANNER_LOCATION);
            boolean z = Utils.getPrefInt(this.context, epson.common.Constants.SCAN_REFS_USED_SCANNER_PATH, epson.common.Constants.SCAN_REFS_SETTINGS_SOURCE) == 0;
            if (z != isDoctable) {
                isNeedClearBm = true;
                setBm((Bitmap) null);
            } else {
                isNeedClearBm = false;
            }
            if (!z && z == isDoctable && !this.isNeedUpdateScanningArea) {
                isNeedUpdateScanningArea = false;
            }
            if (z && z == isDoctable && !this.isNeedUpdateScanningArea) {
                isNeedUpdateScanningArea = false;
            } else {
                isNeedUpdateScanningArea = true;
            }
            isDoctable = z;
        }
    }

    private void loggerScanCountUp() {
        if (this.totalScanned > 0) {
        }
    }

    private boolean isCompletedScanProcess() {
        return getListSavedJPGFilePath().size() == totalScanned;
    }

    private void preparingForScan() {
        escan.setJobDone(false);
        escan.setScanning(false);
        isConfirmCancel = false;
        previousTotalScanned = escan.getListScannedFile().size();
        area = getRectScanArea();
        if (!ScanContinueParam.isContinueScanning()) {
            totalScanned = 0;
            curentViewingFile = 0;
            hideTotalScanned();
            disableFunctionButtons();
            getListSavedJPGFilePath().clear();
        }
    }

    private void showTotalScanned() {
        tvScanResult.setVisibility(View.VISIBLE);
        TextView textView = tvScanResult;
        textView.setText(this.curentViewingFile + epson.common.Constants.CROSS + totalScanned);
    }

    private void hideTotalScanned() {
        tvScanResult.setVisibility(View.GONE);
        btnNext.setVisibility(View.GONE);
        btnPrev.setVisibility(View.GONE);
    }

    private void showDisplayingResult() {
        TextView textView = tvScanResult;
        textView.setText(this.curentViewingFile + epson.common.Constants.CROSS + totalScanned);
    }

    private void updateDoneScanJob() {
        totalScanned = escan.getListScannedFile().size();
        if (this.totalScanned == previousTotalScanned) {
            if (Utils.getPrefInt(this.context, epson.common.Constants.SCAN_REFS_USED_SCANNER_PATH, epson.common.Constants.SCAN_REFS_SETTINGS_SOURCE) == 1) {
                error = 100;
                scanningProgressHandler.sendEmptyMessage(-1);
                return;
            }
            totalScanned = escan.getListScannedFile().size();
            if (this.totalScanned == previousTotalScanned) {
                error = -1100;
                scanningProgressHandler.sendEmptyMessage(-1);
                return;
            }
        }
        if (this.totalScanned > 0) {
            enableFunctionButtons();
        }
        if (this.totalScanned > 1) {
            curentViewingFile = totalScanned;
            btnNext.setVisibility(View.VISIBLE);
            btnPrev.setVisibility(View.GONE);
            showTotalScanned();
        }
        if (!isCompletedScanProcess()) {
            scanningProgressHandler.sendEmptyMessageDelayed(2, 1000);
            return;
        }
        scanningProgressHandler.sendEmptyMessage(-3);
        updateThumbResult(this.curentViewingFile);
    }

    private void updateScreenPreviewToLastData() {
        if (this.totalScanned > 1) {
            curentViewingFile = totalScanned;
            showTotalScanned();
            updateThumbResult(this.curentViewingFile);
        }
    }

    private void updateThumbResult(int i) {
        if (this.totalScanned >= 1) {
            if (this.totalScanned > 1) {
                if (this.curentViewingFile == totalScanned) {
                    btnNext.setVisibility(View.GONE);
                } else {
                    btnNext.setVisibility(View.VISIBLE);
                }
                if (this.curentViewingFile == 1) {
                    btnPrev.setVisibility(View.GONE);
                } else {
                    btnPrev.setVisibility(View.VISIBLE);
                }
            }
            if (i < 1) {
                i = 1;
            }
            if (i > totalScanned) {
                i = totalScanned;
            }
            String str = getListSavedJPGFilePath().get(i - 1);
            try {
                int width = area.width();
                int height = area.height();
                if (width * height < 819200) {
                    width = 1024;
                    height = Videoio.CAP_PVAPI;
                }
                Bitmap createBitmapWithUri = Photo.createBitmapWithUri(str, width, height, false);
                setBmRectF(this.area);
                setBm(createBitmapWithUri);
                scanArea.postInvalidate();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (OutOfMemoryError e2) {
                e2.printStackTrace();
            }
        }
    }

    private void disableFunctionButtons() {
        CustomButtonWrapper.setScanButtonState(this.btnSave, R.drawable.scan_save, R.string.str_save, false);
        CustomButtonWrapper.setScanButtonState(this.btnMail, R.drawable.scan_mail, R.string.str_btn_mail, false);
        CustomButtonWrapper.setScanButtonState(this.btnPrint, R.drawable.scan_print, R.string.str_print, false);
    }

    private void enableFunctionButtons() {
        CustomButtonWrapper.setScanButtonState(this.btnSave, R.drawable.scan_save, R.string.str_save, true);
        CustomButtonWrapper.setScanButtonState(this.btnMail, R.drawable.scan_mail, R.string.str_btn_mail, true);
        CustomButtonWrapper.setScanButtonState(this.btnPrint, R.drawable.scan_print, R.string.str_print, true);
    }

    private void confirmationDialog(String str) {
        if (!this.isConfirmCancel) {
            confirmAlertDialog = new AlertDialog.Builder(this.context).create();
            confirmAlertDialog.setIcon(R.drawable.ic_action_warning);
            confirmAlertDialog.setCancelable(false);
            confirmAlertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
                public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                    return keyEvent.getKeyCode() == 84;
                }
            });
            confirmAlertDialog.setMessage(str);
            confirmAlertDialog.setButton(-2, getText(R.string.str_no), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (!ScanActivity.this.escan.isJobDone()) {
                        ScanActivity.this.showScanningPop();
                    }
                    boolean unused = ScanActivity.this.isConfirmCancel = false;
                }
            });
            confirmAlertDialog.setButton(-1, getText(R.string.str_yes), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    boolean unused = ScanActivity.this.isConfirmCancel = true;
                    String localClassName = ScanActivity.this.getLocalClassName();
                    EPLog.i(localClassName, "yes pressed, isConfirmCancel = " + ScanActivity.this.isConfirmCancel);
                    if (!ScanActivity.this.escan.isJobDone()) {
                        ScanActivity.this.showScanningPop();
                    }
                    ScanActivity.this.scanningProgressHandler.sendEmptyMessage(-2);
                }
            });
            confirmAlertDialog.show();
        }
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i != 10) {
            if (i != 20) {
                switch (i) {
                    case 2:
                        escan.resetEscanLib();
                        escan.escanWrapperInitDriver(this);
                        escan.setScanHandler(this.scanningProgressHandler);
                        onScanSettingEnd(i2, intent);
                        bAutoStartScan = false;
                        return;
                    case 4:
                        if (i2 != -1) {
                            onBackPressed();
                            return;
                        } else if (!startI2ActivityIfEscIVersionMismatch()) {
                            return;
                        } else {
                            return;
                        }
                    default:
                        return;
                }
            } else if (i2 == 1) {
                bAutoStartScan = I2ScanActivity.getAutoStartRequestedFromReturnIntent(intent);
                Intent intent2 = new Intent();
                intent2.putExtra(ScanSettingsActivity.IS_NEW_SAVE, true);
                intent2.putExtra(ScanSettingsActivity.NO_CLEAR_RESULT, false);
                onScanSettingEnd(-1, intent2);
                bAutoStartScan = false;
            } else if (this.isCustomAction) {
                setResult(i2, intent);
                finish();
            } else {
                finish();
            }
        } else if (i2 != -1) {
            hideScanningPop();
        } else {
            mButtonScanListener.onClick(this.btnScan);
            EPLog.d(TAG, "Send CHECK_PRINTER Message.");
        }
    }

    private void onScanSettingEnd(int i, Intent intent) {
        if (i == -1) {
            if (!startI2ActivityIfEscIVersionMismatch() && intent != null) {
                Bundle extras = intent.getExtras();
                String string = extras.getString(epson.common.Constants.ACT_RESULT);
                if (string == null || !string.equals(epson.common.Constants.ACT_RESULT_BACK)) {
                    isNeedGetScanSize = extras.getBoolean(ScanSettingsActivity.IS_NEW_SAVE);
                    boolean z = extras.getBoolean(ScanSettingsActivity.NO_CLEAR_RESULT);
                    if (!z) {
                        setBm((Bitmap) null);
                        hideTotalScanned();
                        disableFunctionButtons();
                        removeTempContents(getApplicationContext());
                        if (this.escan.getListScannedFile() != null) {
                            escan.getListScannedFile().clear();
                            totalScanned = 0;
                            curentViewingFile = 0;
                        }
                        if (getListSavedJPGFilePath() != null) {
                            getListSavedJPGFilePath().clear();
                        }
                        ScanContinueParam.resetParameter();
                    }
                    getSelectedScannerInfo();
                    int prefInt = Utils.getPrefInt(getContext(), epson.common.Constants.SCAN_REFS_USED_SCANNER_PATH, epson.common.Constants.SCAN_REFS_SCANNER_CHOSEN_SIZE);
                    if (prefInt != Constants.PaperName.EPS_MSID_UNKNOWN.getCode()) {
                        chooseScanSize(prefInt);
                    } else {
                        String str = oldScannerId;
                        if (str == null || str.length() == 0 || usingScannerId.length() == 0 || oldScannerId.equals(this.usingScannerId)) {
                            int prefInt2 = Utils.getPrefInt(getContext(), epson.common.Constants.SCAN_REFS_SUPPORTED_OPTIONS, epson.common.Constants.SCAN_REFS_MAX_WIDTH);
                            int prefInt3 = Utils.getPrefInt(getContext(), epson.common.Constants.SCAN_REFS_SUPPORTED_OPTIONS, epson.common.Constants.SCAN_REFS_MAX_HEIGHT);
                            if (prefInt2 < getMaxwidth() || prefInt3 < getMaxheight()) {
                                chooseScanSize(ScanSizeHelper.getDefaultScanSize());
                            }
                        } else {
                            chooseScanSize(ScanSizeHelper.getDefaultScanSize());
                        }
                    }
                    if (!z) {
                        isNeedGetScanSize = true;
                        isNeedUpdateScanningArea = true;
                    }
                    if (this.bAutoStartScan) {
                        mButtonScanListener.onClick(this.btnScan);
                        EPLog.d(TAG, "Send CHECK_PRINTER Message.");
                    }
                }
            }
        } else if (i == 0 && !startI2ActivityIfEscIVersionMismatch()) {
            isNeedGetScanSize = false;
        }
    }

    public void onRequestScanAction() {
        scanStart();
    }

    class ScanAreaGestureDetector extends GestureDetector.SimpleOnGestureListener {
        ScanAreaGestureDetector() {
        }

        public void onLongPress(MotionEvent motionEvent) {
            ScanActivity scanActivity = ScanActivity.this;
            scanActivity.bLongTouch = true;
            scanActivity.scanArea.postInvalidate();
            super.onLongPress(motionEvent);
        }

        public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2) {
            Display defaultDisplay = ScanActivity.this.getWindowManager().getDefaultDisplay();
            Point point = new Point();
            defaultDisplay.getSize(point);
            float f3 = (float) point.y;
            float f4 = (float) point.x;
            if (f3 > f4) {
                f3 = f4;
            }
            double rawX = ((motionEvent.getRawX() - motionEvent2.getRawX()));
            if (rawX < ((-f3)) * 0.1d) {
                ScanActivity.this.prevPage();
                return false;
            } else if (rawX <= (f3) * 0.1d) {
                return false;
            } else {
                ScanActivity.this.nextPage();
                return false;
            }
        }
    }

    private void callScanSetting() {
        escan.escanWrapperReleaseDriver();
        oldScannerId = usingScannerId;
        Intent intent = new Intent(this, ScanSettingsActivity.class);
        if (this.isCustomAction) {
            if (this.extParam.getRes_main() > 0 && extParam.getRes_sub() > 0) {
                intent.putExtra(ScanSettingsActivity.HIDE_RESOLUTION, true);
            }
            intent.putExtra(ScanSettingsActivity.HIDE_COLOR_MODE, true);
            intent.putExtra(ScanSettingsActivity.PARAM_KEY_EXTERNAL_DATA, extParam);
        }
        intent.setAction("android.intent.action.VIEW");
        startActivityForResult(intent, 2);
    }

    class BitmapTask extends AsyncTask<String, Void, Bitmap> {
        public BitmapTask() {
        }

        protected Bitmap doInBackground(String... strArr) {
            if (ScanActivity.this.escan.isJobDone()) {
                return null;
            }
            return ScanActivity.this.showBitmap(strArr[0]);
        }

        protected void onPostExecute(Bitmap bitmap) {
            ScanActivity.this.displayPreview(bitmap);
        }
    }

    private Bitmap showBitmap(String str) {
        Bitmap bitmap;
        isDecoding = true;
        EPLog.i(getCallingPackage(), "start decode for preview ");
        File file = new File(str);
        if (file.exists() && file.isFile()) {
            try {
                bitmap = Utils.decodeFile(file, areaHeightOnScreen - (mARGIN_TOP_BOT * 2));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (OutOfMemoryError e2) {
                e2.printStackTrace();
            }
            EPLog.i(getCallingPackage(), "end decode for preview ");
            return bitmap;
        }
        bitmap = null;
        EPLog.i(getCallingPackage(), "end decode for preview ");
        return bitmap;
    }

    private void displayPreview(Bitmap bitmap) {
        if (!this.escan.isJobDone()) {
            EPLog.i(EpsoniPrintSharedActivity.ACTIVITY_SCAN, "update UI");
            setBm(bitmap);
            setBmRectF(this.area);
            scanArea.postInvalidate();
        }
        isDecoding = false;
    }

    private void convert(String str) {
        getListSavedJPGFilePath().add(str.substring(0, str.length() - 4).concat(".jpg"));
        if (this.isCustomAction) {
            extParam.setArrayOutFilePath(str);
        } else {
            Utils.deleteTempFile(str);
        }
        convertCount++;
        updateThumbResult(this.convertCount);
    }

    @SuppressLint({"NewApi"})
    static void localSetAllCaps(TextView textView, boolean z) {
        if (Build.VERSION.SDK_INT >= 21) {
            textView.setAllCaps(z);
        }
    }

    private void checkLoggerServer(int i, int i2) {
        I1ScanParams i1ScanParams;
        if (mScanLog.action == 0) {
            mScanLog.action = PrintLog.ACTION_SCAN;
        }
        CommonLog commonLog = mScanLog;
        commonLog.numberOfSheet = i - previousTotalScanned;
        commonLog.connectionType = i2;
        ScannerInfo scannerInfo = new ScannerInfo();
        ScanInfoStorage.getInstance().loadScannerConnectivityInfo(this, scannerInfo);
        mScanLog.printerName = scannerInfo.getModelName();
        synchronized (this) {
            i1ScanParams = mI1ScanParams;
        }
        if (mScanLog.numberOfSheet > 0 && i1ScanParams != null) {
            Analytics.sendScanI1Log(this, i1ScanParams, mScanLog, ScanContinueParam.isContinueScanning());
        }
    }

    public static ArrayList<String> getScanFileListFromReturnIntent(@Nullable Intent intent) {
        if (intent == null) {
            return null;
        }
        return intent.getStringArrayListExtra(RETURN_KEY_SCAN_FILE);
    }
}
