package epson.print;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;


import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.preference.PreferenceManager;

import android.view.Display;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.box.androidsdk.content.models.BoxFile;
import com.epson.iprint.prtlogger.NewLoggerController;
import com.epson.iprint.prtlogger.PrintLog;
import com.epson.mobilephone.common.escpr.MediaInfo;
import com.epson.mobilephone.common.license.LicenseTopActivity;
import com.epson.mobilephone.common.wifidirect.NfcTagUtils;
import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import epson.common.Constants;
import epson.common.ExternalFileUtils;
import epson.common.Info_paper;
import epson.common.IprintLicenseInfo;
import epson.common.IprintUserSurveyInfo;
import epson.common.Utils;
import epson.print.Util.AsyncTaskExecutor;
import epson.print.Util.EPLog;
import epson.print.Util.Photo;
import epson.print.ecclient.EccErrorInfo;
import epson.print.gdconv.ConvertProgressActivity;
import epson.print.pdf.pdfRender;
import epson.print.screen.LocalDocumentParams;
import epson.print.screen.PaperSourceInfo;
import epson.print.screen.PaperSourceSetting;
import epson.print.screen.PaperSourceSettingScr;
import epson.print.screen.PrintProgress;
import epson.print.screen.PrintSetting;
import epson.print.screen.SettingScr;
import epson.print.service.EpsonService;
import epson.print.service.IEpsonService;
import epson.print.service.IEpsonServiceCallback;
import epson.print.widgets.CustomTitleAlertDialogBuilder;
import epson.server.utils.MyUtility;

public class ActivityDocsPrintPreview extends ActivityIACommon implements CommonDefine, View.OnClickListener, ReviewInvitationDialog.OnClickListener {
    private static final int COMFIRM_REMOTEPRINT = 13;
    private static final int COMFIRM_REMOTEPRINT_PREVIEW = 12;
    private static final int CONFIRM_GDOC_COV = 5;
    private static final int CONVERT_AUTHENTICATE = 1;
    private static final String DIALOG_KEY_STORE_DIALOG = "store-dialog";
    private static final int DIALOG_PASS = 2;
    private static final int EPS_ERR_NONE = 0;
    private static final int ERR_FILENAME_OVER_256_CHARACTERS = -1;
    private static final int GDOC_CONVERT_FAIL = 7;
    private static final int GDOC_CONVERT_INTERNET_PROBLEM = 11;
    private static final int GDOC_CONVERT_SIZEOVER_DOC = 8;
    private static final int GDOC_CONVERT_SIZEOVER_PPT = 10;
    private static final int GDOC_CONVERT_SIZEOVER_XLS = 9;
    private static final int NOAVAILABLE_NETWORK = 6;
    private static final int NOT_PRINTER_SELECTED = 4;
    public static final String PARAMS_KEY_DOC_PRINT_LOG = "print_log";
    private static final String PREFS_NAME = "PrintSetting";
    private static final int PRINT_GDOC_COV = 8;
    private static final int PRINT_LOCAL = 0;
    private static final int PRINT_REMOTE = 1;
    private static final int PRINT_RENDER_SERVER = 4;
    private static final int PRINT_SHOWPREVIEW = 2;
    private static final int REQUEST_CODE_LICENSE_CHECK = 3;
    private static final int RESULT_RUNTIMEPERMMISSION = 2;
    private static final String TAG = "ActivityDocsPrintPreview";
    private static final String confirmDlgShowPref = "ConfirmDlgShow";
    private static final Object mConnect = new Object();
    private RelativeLayout.LayoutParams Relative_para;
    private ArrayList<PaperSourceSetting> aPaperSourceSetting;
    boolean bAutoStartPrint = false;
    private boolean confirmDlgShow = true;
    private boolean disablePrintArea = false;
    private String docFileName;
    private String docFileName_org;
    private boolean isBackKeyOK = true;
    boolean isCreateJobDone = false;
    boolean isEnableNFCTouch = false;
    private boolean isRemotePrinterOld = false;
    LoadRemotePreviewTask loadRemotePreviewTask = null;
    private Bitmap mBitmap = null;
    private IEpsonServiceCallback mCallback = new IEpsonServiceCallback.Stub() {
        public void onFindPrinterResult(String str, String str2, String str3, String str4, String str5) throws RemoteException {
        }

        public void onGetInkState() throws RemoteException {
        }

        public void onGetStatusState() throws RemoteException {
        }

        public void onNotifyContinueable(int i) throws RemoteException {
        }

        public void onNotifyEndJob(int i) throws RemoteException {
        }

        public void onNotifyError(int i, int i2, boolean z) throws RemoteException {
        }

        public void onNotifyProgress(int i, int i2) throws RemoteException {
        }
    };
    private int mColorMode;
    private PrintSetting mCurPrintSetting = null;
    private String mCurPrinterEmailAdress;
    private String mCurPrinterName;
    private int mCurrentPageView;
    private TextView mDisablePreviewMsg;
    private int mEndPage;
    private int mEndPageView;
    private ServiceConnection mEpsonConnection = new ServiceConnection() {
        public void onServiceDisconnected(ComponentName componentName) {
            try {
                ActivityDocsPrintPreview.mEpsonService.unregisterCallback(ActivityDocsPrintPreview.mCallback);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
            IEpsonService unused = ActivityDocsPrintPreview.mEpsonService = null;
        }

        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            IEpsonService unused = ActivityDocsPrintPreview.mEpsonService = IEpsonService.Stub.asInterface(iBinder);
            if (ActivityDocsPrintPreview.mEpsonService != null) {
                try {
                    ActivityDocsPrintPreview.mEpsonService.registerCallback(ActivityDocsPrintPreview.mCallback);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    private IEpsonService mEpsonService = null;
    private ImageView mImageView;
    private boolean mIsPortrait = true;
    private int mLayout;
    private int mLayoutMulti;
    private LinearLayout mLn_zoomview;
    private PrintProgress.ProgressParams mLocalPrintProgressParams;
    private float mMoveX;
    private Button mNext;
    private TextView mPageNum;
    private Info_paper mPaperSize;
    private pdfRender mPdfRender = null;
    private Button mPre;
    private volatile boolean mPreviewPaperAreaLandscape;
    private Button mPrint;
    private EPImageList mPrintImageList;
    private PrintLog mPrintLog;
    private String mPrinterName;
    private View mProgress;
    private EPImageList mRemotePreviewImageList = new EPImageList();
    private ReviewInvitationViewModel mReviewInvitationViewModel;
    private RelativeLayout mRl_zoomview;
    private TextView mSizeInfo;
    private int mStartPage;
    private int mStartPageView;
    private float mStartX;
    final Handler mUiHandler = new Handler(new Handler.Callback() {
        public boolean handleMessage(Message message) {
            if (ActivityDocsPrintPreview.this.isFinishing()) {
                int i = message.what;
                if (!(i == 4 || i == 6 || i == 13 || i == 22 || i == 39 || i == 50 || i == 100)) {
                    switch (i) {
                        case 0:
                        case 1:
                            break;
                        default:
                            switch (i) {
                                case 10:
                                case 11:
                                    break;
                                default:
                                    switch (i) {
                                        case 30:
                                        case 31:
                                        case 32:
                                        case 33:
                                            break;
                                    }
                            }
                    }
                }
                return true;
            }
            switch (message.what) {
                case 0:
                    EPLog.d(ActivityDocsPrintPreview.TAG, "handleMessage : CONVERTED_OK");
                    ActivityDocsPrintPreview.this.enableProgressBar(false);
                    int unused = ActivityDocsPrintPreview.mCurrentPageView = message.getData().getInt(CommonDefine.CONVERTED_PAGE);
                    ActivityDocsPrintPreview.this.updatePageTextView();
                    ActivityDocsPrintPreview.this.updatePrevNextButtonView();
                    ActivityDocsPrintPreview activityDocsPrintPreview = ActivityDocsPrintPreview.this;
                    activityDocsPrintPreview.setNewImageView(activityDocsPrintPreview.mPdfRender.getConvertedPagePreview());
                    if (ActivityDocsPrintPreview.mCurrentPageView == 1) {
                        ActivityDocsPrintPreview activityDocsPrintPreview2 = ActivityDocsPrintPreview.this;
                        boolean unused2 = activityDocsPrintPreview2.mIsPortrait = !activityDocsPrintPreview2.mPdfRender.rotate();
                        ActivityDocsPrintPreview activityDocsPrintPreview3 = ActivityDocsPrintPreview.this;
                        activityDocsPrintPreview3.setOrentationView(activityDocsPrintPreview3.mIsPortrait);
                    }
                    ActivityDocsPrintPreview activityDocsPrintPreview4 = ActivityDocsPrintPreview.this;
                    activityDocsPrintPreview4.isEnableNFCTouch = true;
                    if (activityDocsPrintPreview4.bAutoStartPrint) {
                        ActivityDocsPrintPreview activityDocsPrintPreview5 = ActivityDocsPrintPreview.this;
                        activityDocsPrintPreview5.onClick(activityDocsPrintPreview5.mPrint);
                        EPLog.d(ActivityDocsPrintPreview.TAG, "onClick(mPrint)");
                        ActivityDocsPrintPreview.this.bAutoStartPrint = false;
                        break;
                    }
                    break;
                case 1:
                    ActivityDocsPrintPreview.this.showDialog(2);
                    break;
                case 4:
                    EPLog.d(ActivityDocsPrintPreview.TAG, "handleMessage : STAR_CONVERT");
                    ActivityDocsPrintPreview.this.enableProgressBar(true);
                    break;
                case 6:
                    ActivityDocsPrintPreview.this.enableProgressBar(false);
                    ActivityDocsPrintPreview activityDocsPrintPreview6 = ActivityDocsPrintPreview.this;
                    activityDocsPrintPreview6.showErrorDialog(activityDocsPrintPreview6.getString(R.string.str_error_tile), ActivityDocsPrintPreview.this.getString(R.string.str_error_ms));
                    break;
                case 7:
                    if (ActivityDocsPrintPreview.mPdfRender != null) {
                        ActivityDocsPrintPreview.mPdfRender.setMIsPreviewCon(false);
                        ActivityDocsPrintPreview.mPdfRender.setPrintingStt(false);
                    }
                    ActivityDocsPrintPreview.this.cancelLoadRemotePreviewTask();
                    if (ActivityDocsPrintPreview.this.isCreateJobDone) {
                        try {
                            ActivityDocsPrintPreview.mEpsonService.EpsonConnectEndJob();
                            ActivityDocsPrintPreview.this.isCreateJobDone = false;
                        } catch (RemoteException e) {
                            e.printStackTrace();
                        }
                    }
                    ExternalFileUtils.getInstance(ActivityDocsPrintPreview.this).initTempViewDir();
                    ExternalFileUtils.getInstance(ActivityDocsPrintPreview.this).initTempCRDir();
                    ExternalFileUtils.getInstance(ActivityDocsPrintPreview.this).getPrintDir();
                    ExternalFileUtils.getInstance(ActivityDocsPrintPreview.this.getApplicationContext()).initTempCacheDirectory(ExternalFileUtils.TempCacheDirectory.GOOGLE_DRIVE_CONVERT);
                    ActivityDocsPrintPreview.this.finish();
                    break;
                case 10:
                    ActivityDocsPrintPreview.this.enableProgressBar(true);
                    if (ActivityDocsPrintPreview.mEpsonService != null) {
                        ActivityDocsPrintPreview.this.enableProgressBar(false);
                        int unused3 = ActivityDocsPrintPreview.mStartPageView = 1;
                        int unused4 = ActivityDocsPrintPreview.mCurrentPageView = 1;
                        int unused5 = ActivityDocsPrintPreview.mEndPageView = 1;
                        ActivityDocsPrintPreview.this.resetPageRange();
                        ActivityDocsPrintPreview activityDocsPrintPreview7 = ActivityDocsPrintPreview.this;
                        String unused6 = activityDocsPrintPreview7.docFileName = activityDocsPrintPreview7.docFileName_org;
                        ActivityDocsPrintPreview activityDocsPrintPreview8 = ActivityDocsPrintPreview.this;
                        activityDocsPrintPreview8.isEnableNFCTouch = false;
                        if (MyPrinter.isRemotePrinter(activityDocsPrintPreview8)) {
                            ActivityDocsPrintPreview activityDocsPrintPreview9 = ActivityDocsPrintPreview.this;
                            int unused7 = activityDocsPrintPreview9.printMode = (activityDocsPrintPreview9.remoteEnableShowPreview ? 2 : 0) | 1;
                            if (Utils.isECConvertFile(ActivityDocsPrintPreview.this.docFileName)) {
                                ActivityDocsPrintPreview activityDocsPrintPreview10 = ActivityDocsPrintPreview.this;
                                int unused8 = activityDocsPrintPreview10.printMode = activityDocsPrintPreview10.printMode | 4;
                            } else if (Utils.checkMimeType(ActivityDocsPrintPreview.this.docFileName, "application/pdf")) {
                                if (!ActivityDocsPrintPreview.mPdfRender.openPdfFile(ActivityDocsPrintPreview.this.docFileName, "", ActivityDocsPrintPreview.this)) {
                                    ActivityDocsPrintPreview activityDocsPrintPreview11 = ActivityDocsPrintPreview.this;
                                    int unused9 = activityDocsPrintPreview11.printMode = activityDocsPrintPreview11.printMode | 4;
                                }
                            } else if (Utils.isGConvertFile(ActivityDocsPrintPreview.this.docFileName)) {
                                ActivityDocsPrintPreview activityDocsPrintPreview12 = ActivityDocsPrintPreview.this;
                                int unused10 = activityDocsPrintPreview12.printMode = activityDocsPrintPreview12.printMode | 8;
                                ActivityDocsPrintPreview activityDocsPrintPreview13 = ActivityDocsPrintPreview.this;
                                int unused11 = activityDocsPrintPreview13.printMode = activityDocsPrintPreview13.printMode | 4;
                            } else {
                                ActivityDocsPrintPreview activityDocsPrintPreview14 = ActivityDocsPrintPreview.this;
                                Toast.makeText(activityDocsPrintPreview14, activityDocsPrintPreview14.getString(R.string.file_size_notsupport), 1).show();
                                ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                                return false;
                            }
                        } else {
                            int unused12 = ActivityDocsPrintPreview.this.printMode = 2;
                            if (Utils.isGConvertFile(ActivityDocsPrintPreview.this.docFileName)) {
                                ActivityDocsPrintPreview activityDocsPrintPreview15 = ActivityDocsPrintPreview.this;
                                int unused13 = activityDocsPrintPreview15.printMode = activityDocsPrintPreview15.printMode | 8;
                            } else if (!Utils.checkMimeType(ActivityDocsPrintPreview.this.docFileName, "application/pdf")) {
                                ActivityDocsPrintPreview activityDocsPrintPreview16 = ActivityDocsPrintPreview.this;
                                Toast.makeText(activityDocsPrintPreview16, activityDocsPrintPreview16.getString(R.string.file_size_notsupport), 1).show();
                                ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                                return false;
                            }
                        }
                        if ((ActivityDocsPrintPreview.this.printMode & 2) != 0) {
                            ActivityDocsPrintPreview.mDisablePreviewMsg.setVisibility(View.GONE);
                        } else {
                            ActivityDocsPrintPreview.mPageNum.setVisibility(4);
                            ActivityDocsPrintPreview.mPre.setVisibility(4);
                            ActivityDocsPrintPreview.mNext.setVisibility(4);
                            ActivityDocsPrintPreview.mImageView.setImageBitmap((Bitmap) null);
                            ActivityDocsPrintPreview.mDisablePreviewMsg.setVisibility(View.VISIBLE);
                        }
                        ActivityDocsPrintPreview.mImageView.setImageBitmap((Bitmap) null);
                        ActivityDocsPrintPreview activityDocsPrintPreview17 = ActivityDocsPrintPreview.this;
                        activityDocsPrintPreview17.setOrentationView(activityDocsPrintPreview17.mIsPortrait);
                        if ((ActivityDocsPrintPreview.this.printMode & 8) == 0) {
                            new AsyncTaskExecutor<Void, Void, Void>() {
                                protected void onPreExecute() {
                                    super.onPreExecute();
                                    ActivityDocsPrintPreview.this.enableProgressBar(true);
                                }

                                protected Void doInBackground(Void... voidArr) {
                                    ActivityDocsPrintPreview.this.adjustPrintSettings();
                                    return null;
                                }

                                protected void onPostExecute(Void voidR) {
                                    super.onPostExecute(voidR);
                                    ActivityDocsPrintPreview.this.enableProgressBar(false);
                                    ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(11);
                                }
                            }.executeOnExecutor(new Void[0]);
                            break;
                        } else {
                            new AsyncTaskExecutor<Void, Void, Boolean>() {
                                protected Boolean doInBackground(Void... voidArr) {
                                    MyUtility myUtility = new MyUtility();
                                    if (!epson.print.Util.Utils.getInstance().isNetworkAvailable(ActivityDocsPrintPreview.this) || myUtility.doNet(ActivityDocsPrintPreview.this) == "") {
                                        return false;
                                    }
                                    return true;
                                }

                                protected void onPostExecute(Boolean bool) {
                                    if (!ActivityDocsPrintPreview.this.isFinishing()) {
                                        super.onPostExecute(bool);
                                        if (!bool.booleanValue()) {
                                            ActivityDocsPrintPreview.this.showDialog(6);
                                        } else if (ActivityDocsPrintPreview.this.confirmDlgShow) {
                                            ActivityDocsPrintPreview.this.showDialog(5);
                                        } else {
                                            ActivityDocsPrintPreview.this.startConvertActivity();
                                        }
                                    }
                                }
                            }.executeOnExecutor(new Void[0]);
                            break;
                        }
                    } else {
                        ActivityDocsPrintPreview.mUiHandler.sendEmptyMessageDelayed(10, 100);
                        break;
                    }
                case 11:
                    if ((ActivityDocsPrintPreview.this.printMode & 4) == 0) {
                        ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(13);
                        break;
                    } else {
                        boolean unused14 = ActivityDocsPrintPreview.this.disablePrintArea = true;
                        if ((ActivityDocsPrintPreview.this.printMode & 2) != 0) {
                            if (!ActivityDocsPrintPreview.this.remoteEnableShowWarning) {
                                ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(30);
                                break;
                            } else {
                                ActivityDocsPrintPreview.this.showDialog(12);
                                break;
                            }
                        } else {
                            ActivityDocsPrintPreview.this.isEnableNFCTouch = true;
                            break;
                        }
                    }
                case 13:
                    if (!ActivityDocsPrintPreview.mPdfRender.openPdfFile(ActivityDocsPrintPreview.this.docFileName, ActivityDocsPrintPreview.this.pdfpass, ActivityDocsPrintPreview.this)) {
                        if (ActivityDocsPrintPreview.mPdfRender.canPrintableDoc()) {
                            ActivityDocsPrintPreview activityDocsPrintPreview18 = ActivityDocsPrintPreview.this;
                            int unused15 = activityDocsPrintPreview18.mEndPageView = activityDocsPrintPreview18.mPdfRender.totalPages();
                            ActivityDocsPrintPreview.this.resetPageRange();
                            if ((ActivityDocsPrintPreview.this.printMode & 2) != 2) {
                                ActivityDocsPrintPreview.this.isEnableNFCTouch = true;
                                break;
                            } else {
                                ActivityDocsPrintPreview.mPdfRender.startConvertPage(ActivityDocsPrintPreview.mCurrentPageView, 1, 0);
                                break;
                            }
                        } else {
                            Toast.makeText(ActivityDocsPrintPreview.this, R.string.str_error_ms_print, 1).show();
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                            return false;
                        }
                    } else {
                        ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(1);
                        break;
                    }
                case 22:
                    ActivityDocsPrintPreview.mUiHandler.removeMessages(22);
                    if ((ActivityDocsPrintPreview.this.printMode & 4) != 0 && !ActivityDocsPrintPreview.this.isCreateJobDone) {
                        new PrintUploadTask().execute(new String[]{ActivityDocsPrintPreview.this.docFileName});
                        break;
                    } else {
                        new PreparePrintTask().executeOnExecutor(new Void[0]);
                        break;
                    }
                    break;
                case 30:
                    ActivityDocsPrintPreview.this.enableProgressBar(false);
                    ActivityDocsPrintPreview activityDocsPrintPreview19 = ActivityDocsPrintPreview.this;
                    activityDocsPrintPreview19.loadRemotePreviewTask = new LoadRemotePreviewTask();
                    ActivityDocsPrintPreview.this.loadRemotePreviewTask.execute(new String[]{ActivityDocsPrintPreview.this.docFileName});
                    break;
                case 31:
                    EPLog.d(ActivityDocsPrintPreview.TAG, "handleMessage : CONVERTED_OK_EC");
                    ActivityDocsPrintPreview.this.enableProgressBar(false);
                    int unused16 = ActivityDocsPrintPreview.mCurrentPageView = message.getData().getInt(CommonDefine.CONVERTED_PAGE);
                    ActivityDocsPrintPreview.this.updatePageTextView();
                    ActivityDocsPrintPreview.this.updatePrevNextButtonView();
                    ActivityDocsPrintPreview.this.setNewImageView((String) message.obj);
                    if (ActivityDocsPrintPreview.mBitmap != null) {
                        if (ActivityDocsPrintPreview.mBitmap.getWidth() > ActivityDocsPrintPreview.mBitmap.getHeight()) {
                            boolean unused17 = ActivityDocsPrintPreview.mIsPortrait = false;
                        } else {
                            boolean unused18 = ActivityDocsPrintPreview.mIsPortrait = true;
                        }
                        ActivityDocsPrintPreview activityDocsPrintPreview20 = ActivityDocsPrintPreview.this;
                        activityDocsPrintPreview20.setOrentationView(activityDocsPrintPreview20.mIsPortrait);
                    }
                    ActivityDocsPrintPreview activityDocsPrintPreview21 = ActivityDocsPrintPreview.this;
                    activityDocsPrintPreview21.isEnableNFCTouch = true;
                    if (activityDocsPrintPreview21.bAutoStartPrint) {
                        ActivityDocsPrintPreview activityDocsPrintPreview22 = ActivityDocsPrintPreview.this;
                        activityDocsPrintPreview22.onClick(activityDocsPrintPreview22.mPrint);
                        EPLog.d(ActivityDocsPrintPreview.TAG, "onClick(mPrint)");
                        ActivityDocsPrintPreview.this.bAutoStartPrint = false;
                        break;
                    }
                    break;
                case 32:
                    boolean unused19 = ActivityDocsPrintPreview.this.disablePrintArea = false;
                    ActivityDocsPrintPreview.this.resetPageRange();
                    ActivityDocsPrintPreview.this.updatePrevNextButtonView();
                    ActivityDocsPrintPreview.this.updatePageTextView();
                    break;
                case 33:
                    ActivityDocsPrintPreview.this.resetPageRangeBySettings();
                    if ((ActivityDocsPrintPreview.this.printMode & 4) == 0) {
                        if ((ActivityDocsPrintPreview.this.printMode & 2) == 0) {
                            ActivityDocsPrintPreview activityDocsPrintPreview23 = ActivityDocsPrintPreview.this;
                            activityDocsPrintPreview23.setOrentationView(activityDocsPrintPreview23.mIsPortrait);
                            break;
                        } else {
                            ActivityDocsPrintPreview.this.loadConfig();
                            ActivityDocsPrintPreview.mPdfRender.startConvertPage(1, 1, 0);
                            break;
                        }
                    } else if (ActivityDocsPrintPreview.this.isRemotePrintSettingsChanged()) {
                        if ((ActivityDocsPrintPreview.this.printMode & 2) == 0) {
                            ActivityDocsPrintPreview activityDocsPrintPreview24 = ActivityDocsPrintPreview.this;
                            activityDocsPrintPreview24.isCreateJobDone = false;
                            activityDocsPrintPreview24.setOrentationView(activityDocsPrintPreview24.mIsPortrait);
                            break;
                        } else {
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(30);
                            break;
                        }
                    }
                    break;
                case 39:
                    String string = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_GENERAL_TITLE);
                    String string2 = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_GENERAL);
                    boolean unused20 = ActivityDocsPrintPreview.this.isBackKeyOK = true;
                    int i2 = message.arg1;
                    if (i2 != -1100) {
                        if (i2 != -1056) {
                            if (i2 != -1) {
                                switch (i2) {
                                    case EccErrorInfo.ECC_ERR_SVR_HTTP_NOT_FOUND /*-1209*/:
                                    case EccErrorInfo.ECC_ERR_SVR_BUSY /*-1208*/:
                                        string = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_BUSY_TITLE);
                                        string2 = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_BUSY) + "0X" + Integer.toHexString(message.arg1).toUpperCase() + ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_BUSY2);
                                        break;
                                    case EccErrorInfo.ECC_ERR_SVR_PAGE_NOT_PREPARED /*-1207*/:
                                        new AlertDialog.Builder(ActivityDocsPrintPreview.this).setCancelable(false).setTitle(string).setMessage(ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_PAGE_NOT_PREPARED)).setNegativeButton(ActivityDocsPrintPreview.this.getString(R.string.ok), new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                ActivityDocsPrintPreview.this.enableProgressBar(false);
                                                dialogInterface.cancel();
                                            }
                                        }).create().show();
                                        return false;
                                    case -1206:
                                        string = ActivityDocsPrintPreview.this.getString(R.string.epsonconnect_str_print_job_too_many_title);
                                        string2 = ActivityDocsPrintPreview.this.getString(R.string.epsonconnect_str_print_job_too_many);
                                        break;
                                    case -1205:
                                        string = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_FILE_TOO_LONG_TITLE);
                                        try {
                                            string2 = String.format(ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_FILE_TOO_LONG_FORMAT), new Object[]{Integer.valueOf(ActivityDocsPrintPreview.mEpsonService.EpsonConnectGetRemotePrintMaxFileSize() / 1048576)});
                                            break;
                                        } catch (Exception e2) {
                                            e2.printStackTrace();
                                            break;
                                        }
                                    case -1204:
                                    case -1200:
                                        break;
                                    case -1203:
                                        string = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_INVALID_ACCESSKEY_TITLE);
                                        string2 = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_INVALID_ACCESSKEY);
                                        break;
                                    case -1202:
                                        string = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_REMOTE_INVALID_TITLE);
                                        string2 = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_REMOTE_INVALID);
                                        break;
                                    case -1201:
                                        string = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_NOT_REGISTERED_TITLE);
                                        string2 = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_NOT_REGISTERED);
                                        break;
                                }
                            } else {
                                string = ActivityDocsPrintPreview.this.getString(R.string.epsonconnect_str_error_filename_too_long_title);
                                string2 = ActivityDocsPrintPreview.this.getString(R.string.epsonconnect_str_error_filename_too_long);
                            }
                        }
                        string = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_GENERAL_TITLE);
                        string2 = ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_GENERAL) + ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_GENERAL2) + "0X" + Integer.toHexString(message.arg1).toUpperCase() + ActivityDocsPrintPreview.this.getString(R.string.ECC_ERR_SVR_GENERAL3);
                    } else {
                        string = ActivityDocsPrintPreview.this.getString(R.string.EC_ERR_COMM_ERROR_TITLE);
                        string2 = ActivityDocsPrintPreview.this.getString(R.string.EC_ERR_COMM_ERROR);
                    }
                    ActivityDocsPrintPreview.this.showErrorDialog(string, string2);
                    break;
                case 50:
                    ActivityDocsPrintPreview.mLn_zoomview.invalidate();
                    ActivityDocsPrintPreview.mRl_zoomview.invalidate();
                    break;
                case 100:
                    ArrayList unused21 = ActivityDocsPrintPreview.this.aPaperSourceSetting = message.getData().getParcelableArrayList(PaperSourceInfo.KEY_PAPERSOURCEINFO);
                    if (ActivityDocsPrintPreview.this.aPaperSourceSetting == null) {
                        ActivityDocsPrintPreview.mSizeInfo.setBackground(ActivityDocsPrintPreview.this.getResources().getDrawable(R.drawable.text_view_boder));
                        ActivityDocsPrintPreview.mSizeInfo.setTextColor(ActivityDocsPrintPreview.this.getResources().getColor(R.color.epson_blue));
                        ActivityDocsPrintPreview.this.paperMissmath.setVisibility(View.GONE);
                        break;
                    } else {
                        ActivityDocsPrintPreview.mSizeInfo.setBackgroundColor(ActivityDocsPrintPreview.this.getResources().getColor(R.color.epson_blue));
                        ActivityDocsPrintPreview.mSizeInfo.setTextColor(ActivityDocsPrintPreview.this.getResources().getColor(R.color.all_white));
                        PrintSetting printSetting = new PrintSetting(ActivityDocsPrintPreview.this, PrintSetting.Kind.document);
                        printSetting.loadSettings();
                        if (!ActivityDocsPrintPreview.this.paperSourceInfo.checkPaperMissmatch(printSetting, ActivityDocsPrintPreview.this.aPaperSourceSetting)) {
                            ActivityDocsPrintPreview.this.paperMissmath.setVisibility(View.GONE);
                            break;
                        } else {
                            ActivityDocsPrintPreview.this.paperMissmath.setVisibility(View.VISIBLE);
                            break;
                        }
                    }
            }
            return false;
        }
    });
    private ImageView paperMissmath = null;
    private int paperSize;
    PaperSourceInfo paperSourceInfo = null;
    private String pdfpass = "";
    private int printMode = 2;
    private String printerId;
    private boolean remoteEnableShowPreview = true;
    private boolean remoteEnableShowWarning = true;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        NewLoggerController.stopLoggerIfNotAgreed(this);
        mReviewInvitationViewModel = (ReviewInvitationViewModel) ViewModelProviders.m2of((FragmentActivity) this).get(ReviewInvitationViewModel.class);
        mReviewInvitationViewModel = (ReviewInvitationViewModel) ViewModelProviders.m2of((FragmentActivity) this).get(ReviewInvitationViewModel.class);
        mReviewInvitationViewModel.getShowInvitationLiveData().observe(this, new Observer<Boolean>() {
            public void onChanged(@Nullable Boolean bool) {
                if (bool.booleanValue()) {
                    ActivityDocsPrintPreview.this.showStoreDialog();
                }
            }
        });
        Intent intent = getIntent();
        try {
            mPrintLog = (PrintLog) intent.getSerializableExtra("print_log");
        } catch (ClassCastException unused) {
        }
        epson.print.Util.Utils.getInstance();
        ExternalFileUtils.getInstance(this).initTempViewDir();
        ExternalFileUtils.getInstance(this).initTempCRDir();
        ExternalFileUtils.getInstance(this).initPrintDir();
        ExternalFileUtils.getInstance(getApplicationContext()).initTempCacheDirectory(ExternalFileUtils.TempCacheDirectory.GOOGLE_DRIVE_CONVERT);
        setContentView(R.layout.doc_print_preview);
        setActionBar(R.string.document_btn_label, true);
        mProgress = findViewById(R.id.progress);
        mPageNum = (TextView) findViewById(R.id.tv_page_num);
        mSizeInfo = (TextView) findViewById(R.id.tv_page_size);
        mPre = (Button) findViewById(R.id.btn_pre);
        mNext = (Button) findViewById(R.id.btn_next);
        mPrint = (Button) findViewById(R.id.btn_print);
        mLn_zoomview = (LinearLayout) findViewById(R.id.ln_zoomview);
        mRl_zoomview = (RelativeLayout) findViewById(R.id.rl_zoomview);
        mImageView = (ImageView) findViewById(R.id.zoomview);
        mDisablePreviewMsg = (TextView) findViewById(R.id.textViewNoPreviewMsg);
        paperMissmath = (ImageView) findViewById(R.id.icon_papermissmatch);
        mSizeInfo.setOnClickListener(this);
        mPrint.setOnClickListener(this);
        mPre.setOnClickListener(this);
        mPre.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case 0:
                        ActivityDocsPrintPreview.mPre.setBackgroundResource(R.drawable.bt_left_hover);
                        return false;
                    case 1:
                        ActivityDocsPrintPreview.mPre.setBackgroundResource(R.drawable.bt_left);
                        return false;
                    default:
                        return false;
                }
            }
        });
        mNext.setOnClickListener(this);
        mNext.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case 0:
                        ActivityDocsPrintPreview.mNext.setBackgroundResource(R.drawable.bt_right_hover);
                        return false;
                    case 1:
                        ActivityDocsPrintPreview.mNext.setBackgroundResource(R.drawable.bt_right_1);
                        return false;
                    default:
                        return false;
                }
            }
        });
        mImageView.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View view, MotionEvent motionEvent) {
                Display defaultDisplay = ActivityDocsPrintPreview.this.getWindowManager().getDefaultDisplay();
                Point point = new Point();
                defaultDisplay.getSize(point);
                float f = (float) point.y;
                float f2 = (float) point.x;
                if ((ActivityDocsPrintPreview.this.printMode & 2) == 0) {
                    return true;
                }
                if (f > f2) {
                    f = f2;
                }
                switch (motionEvent.getAction()) {
                    case 0:
                        float unused = ActivityDocsPrintPreview.mStartX = motionEvent.getX();
                        float unused2 = ActivityDocsPrintPreview.mMoveX = 0.0f;
                        break;
                    case 1:
                        ActivityDocsPrintPreview activityDocsPrintPreview = ActivityDocsPrintPreview.this;
                        float unused3 = activityDocsPrintPreview.mMoveX = activityDocsPrintPreview.mStartX - motionEvent.getX();
                        break;
                }
                float f3 = f / 10.0f;
                if (ActivityDocsPrintPreview.mMoveX > f3) {
                    if (ActivityDocsPrintPreview.mCurrentPageView == ActivityDocsPrintPreview.mEndPageView) {
                        return true;
                    }
                    ActivityDocsPrintPreview activityDocsPrintPreview2 = ActivityDocsPrintPreview.this;
                    activityDocsPrintPreview2.onClick(activityDocsPrintPreview2.mNext);
                } else if (ActivityDocsPrintPreview.mMoveX >= f3 * -1.0f || ActivityDocsPrintPreview.mCurrentPageView == 1) {
                    return true;
                } else {
                    ActivityDocsPrintPreview activityDocsPrintPreview3 = ActivityDocsPrintPreview.this;
                    activityDocsPrintPreview3.onClick(activityDocsPrintPreview3.mPre);
                }
                return true;
            }
        });
        mPdfRender = new pdfRender(this, mUiHandler);
        if ("android.intent.action.VIEW".equals(intent.getAction()) || "android.intent.action.SEND".equals(intent.getAction())) {
            docFileName = getDocFileNameFromIntent(intent);
            String str = docFileName;
            if (str == null || str.length() == 0) {
                EPLog.e(TAG, "onCreate : Error ACTION_VIEW or ACTION_SEND");
                Toast.makeText(this, getString(R.string.file_size_notsupport), 1).show();
                finish();
                return;
            }
            setPrintLogForExternalApp(this.docFileName);
        } else {
            docFileName = intent.getStringExtra(CommonDefine.SEND_DOCUMENT_VIEW);
        }
        docFileName_org = docFileName;
        if (intent.getIntExtra("from", 3) == 4) {
            setTitle(getString(R.string.network_storage_title));
        } else {
            setTitle(getString(R.string.document_btn_label));
        }
        confirmDlgShow = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(confirmDlgShowPref, true);
        SharedPreferences sharedPreferences = getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0);
        remoteEnableShowPreview = sharedPreferences.getBoolean(Constants.ENABLE_SHOW_PREVIEW, true);
        remoteEnableShowWarning = sharedPreferences.getBoolean(Constants.ENABLE_SHOW_WARNING, true);
        paperSourceInfo = PaperSourceInfo.getInstance(this);
        if (bundle == null) {
            startLicenseCheckActivity();
        } else if (!IprintLicenseInfo.isAgreedCurrentVersion(getApplicationContext())) {
            finish();
        } else {
            onInitEnd();
        }
    }

    private void showStoreDialog() {
        ReviewInvitationDialog.newInstance().show(getSupportFragmentManager(), DIALOG_KEY_STORE_DIALOG);
    }

    private void startLicenseCheckActivity() {
        IprintLicenseInfo.beforeLicenseCheck(getApplicationContext());
        startActivityForResult(LicenseTopActivity.getStartIntent(getApplicationContext(), new IprintLicenseInfo(), new IprintUserSurveyInfo()), 3);
    }

    private void onInitEnd() {
        if (mEpsonService == null) {
            bindService(new Intent(this, EpsonService.class), mEpsonConnection, 1);
        }
        if (ActivityRequestPermissions.isRuntimePermissionSupported() && !this.docFileName.toLowerCase().startsWith(ExternalFileUtils.getInstance(this).getWorkingDir().toLowerCase())) {
            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, 2);
                return;
            }
        }
        mUiHandler.sendEmptyMessage(10);
    }

    private void setPrintLogForExternalApp(String str) {
        if (mPrintLog == null) {
            mPrintLog = new PrintLog();
        }
        if (mPrintLog == null) {
            mPrintLog = new PrintLog();
        }
        if (mPrintLog.callerPackage == null) {
            mPrintLog.callerPackage = getCallingPackage();
        }
        if (mPrintLog.uiRoute <= 0) {
            mPrintLog.uiRoute = 4098;
        }
        if (mPrintLog.originalFileExtension == null) {
            mPrintLog.originalFileExtension = PrintLog.getFileExtension(str);
        }
    }

    private String getDocFileNameFromIntent(Intent intent) {
        Uri uri;
        if ("android.intent.action.VIEW".equals(intent.getAction())) {
            EPLog.i(TAG, "getDocFileNameFromIntent : Intent.ACTION_VIEW.equals(intent.getAction())");
            uri = intent.getData();
        } else if ("android.intent.action.SEND".equals(intent.getAction())) {
            EPLog.i(TAG, "getDocFileNameFromIntent : Intent.ACTION_SEND.equals(intent.getAction())");
            uri = (Uri) intent.getParcelableExtra("android.intent.extra.STREAM");
        } else {
            uri = null;
        }
        if (uri == null) {
            return null;
        }
        EPLog.i(TAG, "getDocFileNameFromIntent : Call by Intent url =" + uri);
        if (uri.getScheme().equals("content")) {
            EPLog.i(TAG, "getDocFileNameFromIntent : content");
            ContentResolver contentResolver = getContentResolver();
            try {
                String type = intent.getType();
                if (type == null) {
                    EPLog.w(TAG, "getDocFileNameFromIntent : Not set Type");
                    String extention = Utils.getExtention(uri.getPath());
                    if (extention != null) {
                        type = Utils.getExtType(extention);
                        EPLog.i(TAG, "getDocFileNameFromIntent : fType = " + type);
                    }
                }
                String makeTempFileName = Utils.makeTempFileName(type);
                InputStream openInputStream = contentResolver.openInputStream(uri);
                File file = new File(ExternalFileUtils.getInstance(this).getTempCRDir(), makeTempFileName);
                FileOutputStream fileOutputStream = new FileOutputStream(file);
                byte[] bArr = new byte[1024];
                while (true) {
                    int read = openInputStream.read(bArr);
                    if (read > 0) {
                        fileOutputStream.write(bArr, 0, read);
                    } else {
                        fileOutputStream.close();
                        return file.getPath();
                    }
                }
            } catch (IOException | SecurityException e) {
                EPLog.e(TAG, "getDocFileNameFromIntent : " + e.toString());
                Toast.makeText(getApplicationContext(), getString(R.string.file_size_notsupport), 1).show();
                finish();
                return null;
            }
        } else if (!uri.getScheme().equals(BoxFile.TYPE)) {
            return null;
        } else {
            String path = uri.getPath();
            return path.startsWith("/file:") ? path.substring(6) : path;
        }
    }

    protected void onDestroy() {
        super.onDestroy();
        Bitmap bitmap = mBitmap;
        if (bitmap != null) {
            bitmap.recycle();
            mBitmap = null;
        }
        if (mImageView != null) {
            mImageView = null;
        }
        IEpsonService iEpsonService = mEpsonService;
        if (iEpsonService != null) {
            try {
                iEpsonService.unregisterCallback(mCallback);
                unbindService(mEpsonConnection);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    }

    public void onBackPressed() {
        if (this.isBackKeyOK) {
            mUiHandler.sendEmptyMessage(7);
        }
    }

    protected void onResume() {
        super.onResume();
        NfcTagUtils.enableForegroundDispatch(this, (IntentFilter[]) null, (String[][]) null);
        paperMissmath.setVisibility(View.GONE);
        paperSourceInfo.start(this, mUiHandler);
    }

    protected void onPause() {
        super.onPause();
        NfcTagUtils.disableForegroundDispatch(this);
        paperSourceInfo.stop();
    }

    protected void onNewIntent(Intent intent) {
        NfcTagUtils.EpsonNfcConnectInfo parseNECTag;
        super.onNewIntent(intent);
        String action = intent.getAction();
        if (this.isEnableNFCTouch && "android.nfc.action.NDEF_DISCOVERED".equals(action) && (parseNECTag = NfcTagUtils.parseNECTag(this, intent)) != null) {
            cancelLoadRemotePreviewTask();
            saveCurSettings();
            Intent intent2 = new Intent();
            intent2.setClass(this, ActivityNfcPrinter.class);
            intent2.putExtra(ActivityNfcPrinter.CONNECTINFO, parseNECTag);
            intent2.putExtra(ActivityNfcPrinter.CHANGEMODE, 1);
            startActivityForResult(intent2, 5);
        }
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i != 255) {
            switch (i) {
                case 1:
                    switch (i2) {
                        case 100:
                            EPLog.i(TAG, "onActivityResult : CONVERT_OK");
                            docFileName = intent.getStringExtra(CommonDefine.DOWNLOAD_PATH);
                            new AsyncTaskExecutor<Void, Void, Void>() {
                                protected void onPreExecute() {
                                    super.onPreExecute();
                                    ActivityDocsPrintPreview.this.enableProgressBar(true);
                                }

                                protected Void doInBackground(Void... voidArr) {
                                    ActivityDocsPrintPreview.this.adjustPrintSettings();
                                    return null;
                                }

                                protected void onPostExecute(Void voidR) {
                                    super.onPostExecute(voidR);
                                    ActivityDocsPrintPreview.this.enableProgressBar(false);
                                    ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(11);
                                }
                            }.executeOnExecutor(new Void[0]);
                            break;
                        case 101:
                            EPLog.i(TAG, "onActivityResult : CONVERT_FAIL");
                            showDialog(7);
                            break;
                        case 102:
                            EPLog.i(TAG, "onActivityResult : SIZE_ERROR");
                            showDialog(11);
                            break;
                        case 104:
                            EPLog.i(TAG, "onActivityResult : SIZE_ERROR");
                            showDialog(8);
                            break;
                        case 105:
                            EPLog.i(TAG, "onActivityResult : SIZE_ERROR");
                            showDialog(9);
                            break;
                        case 106:
                            EPLog.i(TAG, "onActivityResult : SIZE_ERROR");
                            showDialog(10);
                            break;
                        default:
                            EPLog.i(TAG, "onActivityResult : ELSE");
                            mUiHandler.sendEmptyMessage(7);
                            break;
                    }
                case 2:
                    if (i2 != -1) {
                        onBackPressed();
                        return;
                    } else {
                        mUiHandler.sendEmptyMessage(10);
                        return;
                    }
                case 3:
                    if (i2 != -1) {
                        finish();
                        return;
                    } else {
                        onInitEnd();
                        return;
                    }
                default:
                    switch (i) {
                        case 5:
                            if (i2 != -1) {
                                return;
                            }
                            if (this.isRemotePrinterOld != MyPrinter.isRemotePrinter(this)) {
                                Toast.makeText(this, R.string.nfc_connect_printpreview, 1).show();
                                WiFiDirectManager.disconnect(this, WiFiDirectManager.DEVICE_TYPE_PRINTER, MyPrinter.getCurPrinter(this).getIp());
                                mUiHandler.sendEmptyMessage(10);
                                return;
                            }
                            new AsyncTaskExecutor<Void, Void, Void>() {
                                protected void onPreExecute() {
                                    super.onPreExecute();
                                    ActivityDocsPrintPreview.this.enableProgressBar(true);
                                }

                                protected Void doInBackground(Void... voidArr) {
                                    ActivityDocsPrintPreview.this.adjustPrintSettings();
                                    return null;
                                }

                                protected void onPostExecute(Void voidR) {
                                    super.onPostExecute(voidR);
                                    ActivityDocsPrintPreview.this.enableProgressBar(false);
                                    ActivityDocsPrintPreview activityDocsPrintPreview = ActivityDocsPrintPreview.this;
                                    activityDocsPrintPreview.bAutoStartPrint = true;
                                    activityDocsPrintPreview.mUiHandler.sendEmptyMessage(33);
                                }
                            }.executeOnExecutor(new Void[0]);
                            return;
                        case 6:
                            break;
                        default:
                            return;
                    }
            }
            if (i2 != 3) {
                return;
            }
            if (this.isRemotePrinterOld != MyPrinter.isRemotePrinter(this)) {
                mUiHandler.sendEmptyMessage(10);
            } else {
                mUiHandler.sendEmptyMessage(33);
            }
        } else {
            pdfRender pdfrender = mPdfRender;
            if (pdfrender != null) {
                pdfrender.setPrintingStt(false);
            }
            mPrint.setEnabled(true);
            mReviewInvitationViewModel.onPrintEnd(PrintProgress.isPrintSuccess(i2));
        }
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_next /*2131230873*/:
                nextPage();
                return;
            case R.id.btn_pre /*2131230876*/:
                prevPage();
                return;
            case R.id.btn_print /*2131230877*/:
                if (mPrinterName.equalsIgnoreCase(getString(R.string.str_lbl_title_scan))) {
                    showDialog(4);
                    return;
                } else if ((this.printMode & 1) == 0 || !this.remoteEnableShowWarning) {
                    mUiHandler.sendEmptyMessage(22);
                    return;
                } else {
                    showDialog(13);
                    return;
                }
            case R.id.tv_page_size /*2131231601*/:
                if (this.aPaperSourceSetting != null) {
                    Intent intent = new Intent();
                    intent.setClass(this, PaperSourceSettingScr.class);
                    intent.putExtra(PaperSourceSettingScr.PRINT_SETTING_TYPE, PrintSetting.Kind.document.name());
                    intent.putParcelableArrayListExtra(PaperSourceInfo.KEY_PAPERSOURCEINFO, aPaperSourceSetting);
                    startActivityForResult(intent, 6);
                    return;
                }
                callPrintSetting();
                return;
            default:
                return;
        }
    }

    private void prevPage() {
        if ((this.printMode & 4) != 0) {
            int i = mCurrentPageView;
            if (i > 1 && i > mStartPageView) {
                EPImage ePImage = mRemotePreviewImageList.get(i - 2);
                Message message = new Message();
                message.what = 31;
                message.obj = ePImage.loadImageFileName;
                message.getData().putInt(CommonDefine.CONVERTED_PAGE, mCurrentPageView - 1);
                mUiHandler.sendMessage(message);
                return;
            }
            return;
        }
        int i2 = mCurrentPageView;
        if (i2 > 1 && i2 > mStartPageView) {
            mPdfRender.startConvertPage(i2 - 1, 1, 0);
        }
    }

    private void nextPage() {
        if ((this.printMode & 4) == 0) {
            int i = mCurrentPageView;
            int i2 = mEndPageView;
            if (i < i2 && i < i2) {
                mPdfRender.startConvertPage(i + 1, 1, 0);
            }
        } else if (mCurrentPageView < mRemotePreviewImageList.size()) {
            EPImage ePImage = mRemotePreviewImageList.get(mCurrentPageView);
            Message message = new Message();
            message.what = 31;
            message.obj = ePImage.loadImageFileName;
            message.getData().putInt(CommonDefine.CONVERTED_PAGE, mCurrentPageView + 1);
            mUiHandler.sendMessage(message);
        } else {
            new LoadRemotePreviewNext().executeOnExecutor(new Void[0]);
        }
    }

    protected Dialog onCreateDialog(int i) {
        Dialog onCreateDialog = super.onCreateDialog(i);
        if (i != 2) {
            switch (i) {
                case 4:
                    return new AlertDialog.Builder(this).setCancelable(false).setTitle(R.string.printer_not_select).setMessage(getString(R.string.printer_notselect_warning)).setPositiveButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                        }
                    }).create();
                case 5:
                    final AlertDialog create = new AlertDialog.Builder(this).create();
                    View inflate = LayoutInflater.from(this).inflate(R.layout.dlg_mes_checkbox, (ViewGroup) findViewById(R.id.layout_root));
                    create.setView(inflate);
                    create.setCancelable(false);
                    create.setTitle(getString(R.string.google_drive));
                    create.setMessage(getString(R.string.agreement_google_docs_convert));
                    CheckBox checkBox = (CheckBox) inflate.findViewById(R.id.checkBox1);
                    checkBox.setText(getString(R.string.not_display_next_time));
                    checkBox.setChecked(false);
                    checkBox.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View view) {
                            boolean unused = ActivityDocsPrintPreview.this.confirmDlgShow = !((CheckBox) view).isChecked();
                        }
                    });
                    create.setButton(-1, getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                            if (!ActivityDocsPrintPreview.this.confirmDlgShow) {
                                SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(ActivityDocsPrintPreview.this).edit();
                                edit.putBoolean(ActivityDocsPrintPreview.confirmDlgShowPref, ActivityDocsPrintPreview.this.confirmDlgShow);
                                edit.commit();
                            }
                            create.dismiss();
                            ActivityDocsPrintPreview.this.startConvertActivity();
                        }
                    });
                    create.setButton(-2, getString(R.string.str_no), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                            create.dismiss();
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                        }
                    });
                    return create;
                case 6:
                    final AlertDialog create2 = new AlertDialog.Builder(this).create();
                    create2.setTitle(R.string.str_warnig);
                    create2.setMessage(getString(R.string.str_no_internet));
                    create2.setButton(-1, getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                            create2.dismiss();
                            ActivityDocsPrintPreview.this.startActivity(new Intent("android.settings.WIRELESS_SETTINGS"));
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                        }
                    });
                    return create2;
                case 7:
                    final AlertDialog create3 = new AlertDialog.Builder(this).create();
                    create3.setTitle(getString(R.string.error));
                    create3.setMessage(getString(R.string.err_convert_gdocs));
                    create3.setButton(-1, getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                            create3.dismiss();
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                        }
                    });
                    return create3;
                case 8:
                    final AlertDialog create4 = new AlertDialog.Builder(this).create();
                    create4.setTitle(getString(R.string.err_title_file_size_gdocs));
                    create4.setMessage(String.format(getString(R.string.err_file_size_gdocs), new Object[]{2}));
                    create4.setButton(-1, getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                            create4.dismiss();
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                        }
                    });
                    return create4;
                case 9:
                    final AlertDialog create5 = new AlertDialog.Builder(this).create();
                    create5.setTitle(getString(R.string.err_title_file_size_gdocs));
                    create5.setMessage(String.format(getString(R.string.err_file_size_gdocs), new Object[]{20}));
                    create5.setButton(-1, getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                            create5.dismiss();
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                        }
                    });
                    return create5;
                case 10:
                    final AlertDialog create6 = new AlertDialog.Builder(this).create();
                    create6.setTitle(getString(R.string.err_title_file_size_gdocs));
                    create6.setMessage(String.format(getString(R.string.err_file_size_gdocs), new Object[]{10}));
                    create6.setButton(-1, getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                            create6.dismiss();
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                        }
                    });
                    return create6;
                case 11:
                    final AlertDialog create7 = new AlertDialog.Builder(this).create();
                    create7.setTitle(getString(R.string.error));
                    create7.setMessage(getString(R.string.network_error_mes));
                    create7.setButton(-1, getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                            create7.dismiss();
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                        }
                    });
                    return create7;
                case 12:
                    AlertDialog.Builder cancelable = new AlertDialog.Builder(this).setCancelable(false);
                    return cancelable.setMessage(getString(R.string.epsonconnect_str_remote_print_warning) + "\n\n" + getString(R.string.epsonconnect_str_remote_print_warning2)).setPositiveButton(getString(R.string.str_yes), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(30);
                        }
                    }).setNegativeButton(getString(R.string.str_no), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                        }
                    }).create();
                case 13:
                    AlertDialog.Builder cancelable2 = new AlertDialog.Builder(this).setCancelable(false);
                    return cancelable2.setMessage(getString(R.string.epsonconnect_str_remote_print_warning) + "\n\n" + getString(R.string.epsonconnect_str_remote_print_warning2)).setPositiveButton(getString(R.string.str_yes), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                            ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(22);
                        }
                    }).setNegativeButton(getString(R.string.str_no), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                        }
                    }).create();
                default:
                    return onCreateDialog;
            }
        } else {
            View inflate2 = LayoutInflater.from(this).inflate(R.layout.pdf_file_password, (ViewGroup) null);
            final EditText editText = (EditText) inflate2.findViewById(R.id.etPassword);
            return new AlertDialog.Builder(this).setIcon(R.drawable.file).setTitle(getString(R.string.str_enter_pass)).setView(inflate2).setCancelable(false).setPositiveButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    String unused = ActivityDocsPrintPreview.this.pdfpass = editText.getText().toString();
                    if (!ActivityDocsPrintPreview.mPdfRender.openPdfFile(ActivityDocsPrintPreview.this.docFileName, ActivityDocsPrintPreview.this.pdfpass, ActivityDocsPrintPreview.this)) {
                        ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(13);
                    } else {
                        ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(1);
                    }
                }
            }).setNegativeButton(getString(R.string.str_cancel), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
                }
            }).create();
        }
    }

    private void startConvertActivity() {
        startActivityForResult(ConvertProgressActivity.getStartIntent(this, docFileName), 1);
    }

    public void callPrintSetting() {
        cancelLoadRemotePreviewTask();
        saveCurSettings();
        SharedPreferences.Editor edit = getSharedPreferences("PrintSetting", 0).edit();
        edit.putInt(Constants.SOURCE_TYPE, 1);
        edit.commit();
        Intent intent = new Intent(this, SettingScr.class);
        intent.putExtra(PrintProgress.PARAM_DOCUMENT_MODE, true);
        if ((this.printMode & 4) != 0) {
            intent.putExtra("SHEETS", mEndPageView);
            intent.putExtra("PRINTAREA", disablePrintArea);
        } else {
            intent.putExtra("SHEETS", mPdfRender.totalPages());
        }
        intent.setAction("android.intent.action.VIEW");
        startActivityForResult(intent, 6);
    }

    private class PreparePrintTask extends AsyncTaskExecutor<Void, Void, Void> {
        private boolean mIsLandscape;
        EPImageList tmpList = new EPImageList();

        public PreparePrintTask() {
        }

        protected void onPreExecute() {
            ActivityDocsPrintPreview.this.enableProgressBar(true);
            ActivityDocsPrintPreview.mPrint.setEnabled(false);
            mIsLandscape = calcLandscape();
        }

        private boolean calcLandscape() {
            return (ActivityDocsPrintPreview.mLn_zoomview.getRight() - ActivityDocsPrintPreview.mLn_zoomview.getPaddingRight()) - (ActivityDocsPrintPreview.mLn_zoomview.getLeft() + ActivityDocsPrintPreview.mLn_zoomview.getPaddingLeft()) > (ActivityDocsPrintPreview.mLn_zoomview.getBottom() - ActivityDocsPrintPreview.mLn_zoomview.getPaddingBottom()) - (ActivityDocsPrintPreview.mLn_zoomview.getTop() + ActivityDocsPrintPreview.mLn_zoomview.getPaddingTop());
        }

        protected Void doInBackground(Void... voidArr) {
            if ((ActivityDocsPrintPreview.this.printMode & 4) != 0) {
                ActivityDocsPrintPreview.this.cancelLoadRemotePreviewTask();
            } else if ((ActivityDocsPrintPreview.this.printMode & 1) != 0) {
                OLD_setImageListForLocalPrinter();
            } else {
                setImageListForLocalPrinter2();
            }
            if ((ActivityDocsPrintPreview.this.printMode & 1) == 0) {
                return null;
            }
            SharedPreferences.Editor edit = ActivityDocsPrintPreview.this.getSharedPreferences("PrintSetting", 0).edit();
            if ((ActivityDocsPrintPreview.this.printMode & 4) != 0) {
                edit.putInt(Constants.SOURCE_TYPE, 1);
                tmpList.clear();
                EPImage ePImage = new EPImage();
                ePImage.loadImageFileName = ActivityDocsPrintPreview.this.docFileName_org;
                ePImage.setOrgName(ActivityDocsPrintPreview.this.docFileName_org);
                tmpList.add(ePImage);
            } else {
                edit.putInt(Constants.SOURCE_TYPE, 3);
                EPImage ePImage2 = tmpList.get(0);
                if (ActivityDocsPrintPreview.this.docFileName_org.lastIndexOf(47) > 0) {
                    ePImage2.webUrl = ActivityDocsPrintPreview.this.docFileName_org.substring(ActivityDocsPrintPreview.this.docFileName_org.lastIndexOf(47) + 1);
                } else {
                    ePImage2.webUrl = ActivityDocsPrintPreview.this.docFileName_org;
                }
            }
            edit.commit();
            return null;
        }

        private void setImageListForLocalPrinter2() {
            ExternalFileUtils.getInstance(ActivityDocsPrintPreview.this).initPrintDir();
            if (ActivityDocsPrintPreview.mPrintLog == null) {
                PrintLog unused = ActivityDocsPrintPreview.mPrintLog = new PrintLog();
            }
            ActivityDocsPrintPreview.mPrintLog.previewType = 2;
            ActivityDocsPrintPreview activityDocsPrintPreview = ActivityDocsPrintPreview.this;
            PrintProgress.ProgressParams unused2 = activityDocsPrintPreview.mLocalPrintProgressParams = new LocalDocumentParams(activityDocsPrintPreview.docFileName, ActivityDocsPrintPreview.this.docFileName_org, ActivityDocsPrintPreview.this.pdfpass, ActivityDocsPrintPreview.mPreviewPaperAreaLandscape, ActivityDocsPrintPreview.mStartPage, ActivityDocsPrintPreview.mEndPage, ActivityDocsPrintPreview.mPrintLog);
        }

        private void OLD_setImageListForLocalPrinter() {
            int i;
            int i2;
            ExternalFileUtils.getInstance(ActivityDocsPrintPreview.this).initPrintDir();
            for (int access$4000 = ActivityDocsPrintPreview.mStartPage; access$4000 <= ActivityDocsPrintPreview.mEndPage; access$4000++) {
                tmpList.add(ActivityDocsPrintPreview.mPdfRender.getDecodeJpegFilename(access$4000));
            }
            ActivityDocsPrintPreview.mPdfRender.startConvertPage(ActivityDocsPrintPreview.mStartPage, ActivityDocsPrintPreview.mEndPage, 1);
            while (!ActivityDocsPrintPreview.mPdfRender.RendererStart()) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if (this.tmpList.imageList.size() > 0) {
                EPImage ePImage = new EPImage(this.tmpList.imageList.get(0).getLoadImageFileName(), 0);
                i = ePImage.srcHeight;
                i2 = ePImage.srcWidth;
                EPLog.i(ActivityDocsPrintPreview.TAG, "Finish Renderer Page No.1 : srcWidth = " + i2 + " srcHeight = " + i);
            } else {
                i2 = 0;
                i = 0;
            }
            for (int i3 = 0; i3 < tmpList.imageList.size(); i3++) {
                EPImage ePImage2 = tmpList.get(i3);
                ePImage2.previewPaperRectLeft = ActivityDocsPrintPreview.mLn_zoomview.getLeft() + ActivityDocsPrintPreview.mLn_zoomview.getPaddingLeft();
                ePImage2.previewPaperRectTop = ActivityDocsPrintPreview.mLn_zoomview.getTop() + ActivityDocsPrintPreview.mLn_zoomview.getPaddingTop();
                ePImage2.previewPaperRectRight = ActivityDocsPrintPreview.mLn_zoomview.getRight() - ActivityDocsPrintPreview.mLn_zoomview.getPaddingRight();
                ePImage2.previewPaperRectBottom = ActivityDocsPrintPreview.mLn_zoomview.getBottom() - ActivityDocsPrintPreview.mLn_zoomview.getPaddingBottom();
                ePImage2.previewImageRectLeft = (float) (ActivityDocsPrintPreview.mLn_zoomview.getLeft() + ActivityDocsPrintPreview.mImageView.getLeft());
                ePImage2.previewImageRectTop = (float) (ActivityDocsPrintPreview.mLn_zoomview.getTop() + ActivityDocsPrintPreview.mImageView.getTop());
                ePImage2.previewImageRectRight = (float) (ActivityDocsPrintPreview.mLn_zoomview.getLeft() + ActivityDocsPrintPreview.mImageView.getRight());
                ePImage2.previewImageRectBottom = (float) (ActivityDocsPrintPreview.mLn_zoomview.getTop() + ActivityDocsPrintPreview.mImageView.getBottom());
                ePImage2.previewWidth = (ePImage2.previewImageRectRight - ePImage2.previewImageRectLeft);
                ePImage2.previewHeight = (ePImage2.previewImageRectBottom - ePImage2.previewImageRectTop);
                if (ePImage2.previewPaperRectRight - ePImage2.previewPaperRectLeft > ePImage2.previewPaperRectBottom - ePImage2.previewPaperRectTop) {
                    ePImage2.isPaperLandScape = true;
                } else {
                    ePImage2.isPaperLandScape = false;
                }
                ePImage2.srcWidth = i2;
                ePImage2.srcHeight = i;
                ePImage2.setOrgName(ActivityDocsPrintPreview.this.docFileName_org);
            }
        }

        protected void onPostExecute(Void voidR) {
            super.onPostExecute(voidR);
            EPImageList unused = ActivityDocsPrintPreview.mPrintImageList = tmpList;
            ActivityDocsPrintPreview.this.enableProgressBar(false);
            ActivityDocsPrintPreview.this.check3GAndStartPrint();
        }
    }

    private void check3GAndStartPrint() {
        startPrintActivity();
    }

    private void startPrintActivity() {
        if ((this.printMode & 1) == 0) {
            PrintProgress.ProgressParams progressParams = mLocalPrintProgressParams;
            if (progressParams != null) {
                startActivityForResult(PrintProgress.getPdfPrintIntent(this, progressParams), 255);
                return;
            }
            return;
        }
        if (mPrintLog == null) {
            mPrintLog = new PrintLog();
        }
        PrintLog printLog = mPrintLog;
        printLog.previewType = 2;
        startActivityForResult(PrintProgress.getPrintIntent(this, mPrintImageList, true, false, printLog), 255);
    }

    public void invitationDialogClicked(boolean z) {
        mReviewInvitationViewModel.setStartStoreEnd();
    }

    private class LoadRemotePreviewTask extends AsyncTask<String, Void, Void> {
        CustomProDialog serverConnectDialog;

        private LoadRemotePreviewTask() {
        }

        protected void onPreExecute() {
            ActivityDocsPrintPreview.mRemotePreviewImageList.clear();
            ActivityDocsPrintPreview.this.updatePageTextView();
            ActivityDocsPrintPreview.this.loadConfig();
            ActivityDocsPrintPreview activityDocsPrintPreview = ActivityDocsPrintPreview.this;
            serverConnectDialog = new CustomProDialog(activityDocsPrintPreview, R.style.AppTheme_Translucent_Gray, R.layout.work_dialog_transparent, true);
            CustomProDialog customProDialog = serverConnectDialog;
            if (customProDialog != null) {
                customProDialog.setCancelable(false);
                serverConnectDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
                    public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                        if (i != 4 || ActivityDocsPrintPreview.this.loadRemotePreviewTask == null) {
                            return false;
                        }
                        ActivityDocsPrintPreview.this.loadRemotePreviewTask.cancel(true);
                        return false;
                    }
                });
                serverConnectDialog.show();
            }
        }

        public Void doInBackground(String... r22) {

            throw new UnsupportedOperationException("Method not decompiled: epson.print.ActivityDocsPrintPreview.LoadRemotePreviewTask.doInBackground(java.lang.String[]):java.lang.Void");
        }

        protected void onProgressUpdate(Void... voidArr) {
            ActivityDocsPrintPreview.this.updatePrevNextButtonView();
            ActivityDocsPrintPreview.this.updatePageTextView();
        }
    }

    private void cancelLoadRemotePreviewTask() {
        LoadRemotePreviewTask loadRemotePreviewTask2 = loadRemotePreviewTask;
        if (loadRemotePreviewTask2 != null && !loadRemotePreviewTask2.isCancelled()) {
            synchronized (mConnect) {
                loadRemotePreviewTask.cancel(true);
            }
            loadRemotePreviewTask = null;
        }
    }

    private boolean checkJobNameLength(String str) {
        return new File(str).getName().length() <= 256;
    }

    private class LoadRemotePreviewNext extends AsyncTaskExecutor<Void, Void, Void> {
        private LoadRemotePreviewNext() {
        }


        public Void doInBackground(Void... r10) {
            throw new UnsupportedOperationException("Method not decompiled: epson.print.ActivityDocsPrintPreview.LoadRemotePreviewNext.doInBackground(java.lang.Void[]):java.lang.Void");
        }
    }

    private class PrintUploadTask extends AsyncTask<String, Void, Void> {
        CustomProDialog serverConnectDialog;

        private PrintUploadTask() {
        }

        protected void onPreExecute() {
            ActivityDocsPrintPreview activityDocsPrintPreview = ActivityDocsPrintPreview.this;
            serverConnectDialog = new CustomProDialog(activityDocsPrintPreview, R.style.AppTheme_Translucent, R.layout.work_dialog_transparent, false);
            serverConnectDialog.setCancelable(false);
            serverConnectDialog.show();
        }

        /* access modifiers changed from: protected */
        /* JADX WARNING: Code restructure failed: missing block: B:15:0x007a, code lost:
            r0 = r2;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:26:0x009c, code lost:
            r0 = move-exception;
         */
        /* JADX WARNING: Code restructure failed: missing block: B:27:0x009d, code lost:
            r0.printStackTrace();
         */
        /* JADX WARNING: Code restructure failed: missing block: B:28:?, code lost:
            return null;
         */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Removed duplicated region for block: B:26:0x009c A[ExcHandler: RemoteException (r0v4 'e' android.os.RemoteException A[CUSTOM_DECLARE]), Splitter:B:3:0x0009] */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        public Void doInBackground(String... r22) {
            /*
                r21 = this;
                r1 = r21
                epson.print.ActivityDocsPrintPreview r0 = epson.print.ActivityDocsPrintPreview.this
                boolean r0 = r0.isCreateJobDone
                if (r0 != 0) goto L_0x00a0
                r0 = 0
                epson.print.screen.PrintSetting r2 = new epson.print.screen.PrintSetting     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                epson.print.ActivityDocsPrintPreview r3 = epson.print.ActivityDocsPrintPreview.this     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                epson.print.screen.PrintSetting$Kind r4 = epson.print.screen.PrintSetting.Kind.document     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                r2.<init>(r3, r4)     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                r2.loadSettings()     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                int r8 = r2.paperSizeValue     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                int r9 = r2.paperTypeValue     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                int r10 = r2.layoutValue     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                int r11 = r2.qualityValue     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                int r12 = r2.paperSourceValue     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                int r13 = r2.colorValue     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                int r14 = r2.brightnessValue     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                int r15 = r2.contrastValue     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                int r3 = r2.saturationValue     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                int r4 = r2.duplexValue     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                int r2 = r2.feedDirectionValue     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                r6 = 1
                r19 = 1403(0x57b, float:1.966E-42)
                r20 = 1403(0x57b, float:1.966E-42)
                epson.print.ActivityDocsPrintPreview r5 = epson.print.ActivityDocsPrintPreview.this     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                epson.print.service.IEpsonService r5 = r5.mEpsonService     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                r5.EpsonConnectEndJob()     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                epson.print.ActivityDocsPrintPreview r5 = epson.print.ActivityDocsPrintPreview.this     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                r7 = r22[r0]     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                boolean r5 = r5.checkJobNameLength(r7)     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                if (r5 == 0) goto L_0x0082
                epson.print.ActivityDocsPrintPreview r5 = epson.print.ActivityDocsPrintPreview.this     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                epson.print.service.IEpsonService r5 = r5.mEpsonService     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                r7 = r22[r0]     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                r16 = r3
                r17 = r2
                r18 = r4
                int r2 = r5.EpsonConnectCreateJob(r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, r16, r17, r18, r19, r20)     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                if (r2 != 0) goto L_0x007c
                epson.print.ActivityDocsPrintPreview r3 = epson.print.ActivityDocsPrintPreview.this     // Catch:{ RemoteException -> 0x009c, Exception -> 0x007a }
                r4 = 1
                r3.isCreateJobDone = r4     // Catch:{ RemoteException -> 0x009c, Exception -> 0x007a }
                epson.print.ActivityDocsPrintPreview r3 = epson.print.ActivityDocsPrintPreview.this     // Catch:{ RemoteException -> 0x009c, Exception -> 0x007a }
                epson.print.service.IEpsonService r3 = r3.mEpsonService     // Catch:{ RemoteException -> 0x009c, Exception -> 0x007a }
                r0 = r22[r0]     // Catch:{ RemoteException -> 0x009c, Exception -> 0x007a }
                int r0 = r3.EpsonConnectUploadFile(r0, r4)     // Catch:{ RemoteException -> 0x009c, Exception -> 0x007a }
                if (r0 != 0) goto L_0x0074
                epson.print.ActivityDocsPrintPreview r2 = epson.print.ActivityDocsPrintPreview.this     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                android.os.Handler r2 = r2.mUiHandler     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                r3 = 22
                r2.sendEmptyMessage(r3)     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                goto L_0x00a0
            L_0x0074:
                java.lang.Exception r2 = new java.lang.Exception     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                r2.<init>()     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                throw r2     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
            L_0x007a:
                r0 = r2
                goto L_0x0089
            L_0x007c:
                java.lang.Exception r0 = new java.lang.Exception     // Catch:{ RemoteException -> 0x009c, Exception -> 0x007a }
                r0.<init>()     // Catch:{ RemoteException -> 0x009c, Exception -> 0x007a }
                throw r0     // Catch:{ RemoteException -> 0x009c, Exception -> 0x007a }
            L_0x0082:
                r0 = -1
                java.lang.Exception r2 = new java.lang.Exception     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                r2.<init>()     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
                throw r2     // Catch:{ RemoteException -> 0x009c, Exception -> 0x0089 }
            L_0x0089:
                android.os.Message r2 = new android.os.Message
                r2.<init>()
                r3 = 39
                r2.what = r3
                r2.arg1 = r0
                epson.print.ActivityDocsPrintPreview r0 = epson.print.ActivityDocsPrintPreview.this
                android.os.Handler r0 = r0.mUiHandler
                r0.sendMessage(r2)
                goto L_0x00a0
            L_0x009c:
                r0 = move-exception
                r0.printStackTrace()
            L_0x00a0:
                r0 = 0
                return r0
            */
            throw new UnsupportedOperationException("Method not decompiled: epson.print.ActivityDocsPrintPreview.PrintUploadTask.doInBackground(java.lang.String[]):java.lang.Void");
        }

        protected void onPostExecute(Void voidR) {
            CustomProDialog customProDialog = serverConnectDialog;
            if (customProDialog != null && customProDialog.isShowing()) {
                serverConnectDialog.dismiss();
            }
        }
    }

    private void adjustPrintSettings() {
        try {
            if ((this.printMode & 1) != 0) {
                mEpsonService.EpsonConnectUpdatePrinterSettings(PrintSetting.Kind.document.name());
            } else {
                mEpsonService.updatePrinterSettings(PrintSetting.Kind.document.name());
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    private void saveCurSettings() {
        mCurPrinterName = MyPrinter.getCurPrinter(this).getName();
        mCurPrinterEmailAdress = MyPrinter.getCurPrinter(this).getEmailAddress();
        isRemotePrinterOld = MyPrinter.isRemotePrinter(this);
        mCurPrintSetting = new PrintSetting(this, PrintSetting.Kind.document);
        mCurPrintSetting.loadSettings();
    }

    private boolean isRemotePrintSettingsChanged() {
        String emailAddress = MyPrinter.getCurPrinter(this).getEmailAddress();
        PrintSetting printSetting = new PrintSetting(this, PrintSetting.Kind.document);
        printSetting.loadSettings();
        int i = printSetting.paperSizeValue;
        int i2 = printSetting.paperTypeValue;
        int i3 = printSetting.layoutValue;
        int i4 = printSetting.qualityValue;
        int i5 = printSetting.paperSourceValue;
        int i6 = printSetting.colorValue;
        int i7 = printSetting.duplexValue;
        int i8 = printSetting.brightnessValue;
        int i9 = printSetting.contrastValue;
        int i10 = printSetting.saturationValue;
        if (mCurPrinterEmailAdress.equals(emailAddress) && mCurPrintSetting.paperSizeValue == i && mCurPrintSetting.paperTypeValue == i2 && mCurPrintSetting.layoutValue == i3 && mCurPrintSetting.qualityValue == i4 && mCurPrintSetting.paperSourceValue == i5 && mCurPrintSetting.colorValue == i6 && mCurPrintSetting.duplexValue == i7 && mCurPrintSetting.brightnessValue == i8 && mCurPrintSetting.contrastValue == i9 && mCurPrintSetting.saturationValue == i10) {
            return false;
        }
        return true;
    }

    public boolean resetPageRangeBySettings() {
        String string = getSharedPreferences("PrintSetting", 0).getString(Constants.PRINTER_NAME, "");
        PrintSetting printSetting = new PrintSetting(this, PrintSetting.Kind.document);
        printSetting.loadSettings();
        int i = printSetting.paperSizeValue;
        int i2 = printSetting.layoutValue;
        if (string.equals(mCurPrinterName) && mCurPrintSetting.paperSizeValue == i && mCurPrintSetting.layoutValue == i2) {
            return false;
        }
        printSetting.resetPageRange(1, mEndPageView);
        return true;
    }

    public void resetPageRange() {
        new PrintSetting(this, PrintSetting.Kind.document).resetPageRange(1, mEndPageView);
        mStartPage = 1;
        mEndPage = mEndPageView;
    }

    private void loadConfig() {
        SharedPreferences sharedPreferences = getSharedPreferences("PrintSetting", 0);
        PrintSetting printSetting = new PrintSetting(this, PrintSetting.Kind.document);
        printSetting.loadSettings();
        paperSize = printSetting.paperSizeValue;
        mColorMode = printSetting.colorValue;
        mLayout = printSetting.layoutValue;
        mLayoutMulti = printSetting.layoutMultiPageValue;
        mPaperSize = Info_paper.getInfoPaper(this, paperSize);
        MediaInfo.PaperSize paperSize2 = new MediaInfo.PaperSize();
        mSizeInfo.setText(getString(paperSize2.getStringId(this.paperSize)));
        paperSize2.destructor();
        mPrinterName = sharedPreferences.getString(Constants.PRINTER_NAME, getString(R.string.str_lbl_title_scan));
        printerId = sharedPreferences.getString(Constants.PRINTER_ID, (String) null);
        mStartPage = printSetting.startValue;
        mEndPage = printSetting.endValue;
    }

    public void setNewImageView(String str) {
        if ((this.printMode & 2) != 0) {
            Bitmap bitmap = mBitmap;
            if (bitmap != null) {
                bitmap.recycle();
            }
            if (mColorMode == 1) {
                try {
                    mBitmap = Photo.createBitmapWithUri(str, 992, 1403, true);
                } catch (Exception e) {
                    e.printStackTrace();
                    mUiHandler.sendEmptyMessage(6);
                }
            } else {
                try {
                    mBitmap = Photo.createBitmapWithUri(str, 992, 1403, false);
                } catch (Exception e2) {
                    e2.printStackTrace();
                    mUiHandler.sendEmptyMessage(6);
                }
            }
            mImageView.setImageBitmap(mBitmap);
        }
    }

    public void setOrentationView(boolean z) {
        int i;
        loadConfig();
        Display defaultDisplay = getWindowManager().getDefaultDisplay();
        int paper_width = mPaperSize.getPaper_width();
        int paper_height = mPaperSize.getPaper_height();
        int i2 = mLayoutMulti;
        int i3 = 0;
        if (i2 != 0) {
            if (i2 == 65536) {
                Rect paperSize_2in1 = mPaperSize.getPaperSize_2in1();
                paper_height = paperSize_2in1.width();
                paper_width = paperSize_2in1.height();
                Rect printingArea_2in1 = mPaperSize.getPrintingArea_2in1();
                i3 = printingArea_2in1.width();
                i = printingArea_2in1.height();
            } else if (i2 == 131072 || i2 == 262144) {
                Rect paperSize_4in1 = mPaperSize.getPaperSize_4in1();
                paper_height = paperSize_4in1.width();
                paper_width = paperSize_4in1.height();
                Rect printingArea_4in1 = mPaperSize.getPrintingArea_4in1();
                i3 = printingArea_4in1.width();
                i = printingArea_4in1.height();
            } else {
                i = 0;
                int i4 = paper_height;
                paper_height = paper_width;
                paper_width = i4;
            }
            if (paper_height > paper_width) {
                int i5 = paper_height;
                paper_height = paper_width;
                paper_width = i5;
            } else {
                int i6 = i3;
                i3 = i;
                i = i6;
            }
        } else if (paper_width > paper_height) {
            i = 0;
        } else {
            i = 0;
            int i7 = paper_height;
            paper_height = paper_width;
            paper_width = i7;
        }
        mPreviewPaperAreaLandscape = !z;
        Point point = new Point();
        defaultDisplay.getSize(point);
        if (z) {
            int height = point.y - (mPrint.getHeight() * 4);
            double d = paper_width;
            double d2 = paper_height;
            int i8 = (((height) / d) * d2);
            if (i8 > (point.x * 4) / 5) {
                i8 = (point.x * 4) / 5;
                height = (((i8) / d2) * d);
            }
            Relative_para = new RelativeLayout.LayoutParams(i8, height);
        } else {
            int i9 = (point.x * 4) / 5;
            double d3 = paper_width;
            double d4 = paper_height;
            int i10 = (((i9) / d3) * d4);
            if (i10 > point.y - (mPrint.getHeight() * 4)) {
                i10 = point.y - (mPrint.getHeight() * 4);
                i9 = (((i10) / d4) * d3);
            }
            Relative_para = new RelativeLayout.LayoutParams(i9, i10);
        }
        Relative_para.addRule(13);
        mLn_zoomview.setLayoutParams(this.Relative_para);
        if (mLayout == 2) {
            if (mLayoutMulti == 0) {
                if (z) {
                    float f = ((float) Relative_para.width) / ((float) paper_height);
                    mLn_zoomview.setPadding((((float) mPaperSize.getLeftMargin_border()) * f), (((float) mPaperSize.getTopMargin_border()) * f), (((float) mPaperSize.getRightMargin_border()) * f), (((float) mPaperSize.getBottomMargin_border()) * f));
                } else {
                    float f2 = ((float) Relative_para.width) / ((float) paper_width);
                    mLn_zoomview.setPadding((((float) mPaperSize.getTopMargin_border()) * f2), (((float) mPaperSize.getRightMargin_border()) * f2), (((float) mPaperSize.getBottomMargin_border()) * f2), (((float) mPaperSize.getLeftMargin_border()) * f2));
                }
            } else if (z) {
                float f3 = ((float) Relative_para.width) / ((float) paper_height);
                int i11 = (((float) ((paper_height - i) / 2)) * f3);
                int i12 = (((float) ((paper_width - i3) / 2)) * f3);
                mLn_zoomview.setPadding(i11, i12, i11, i12);
            } else {
                float f4 = ((float) Relative_para.width) / ((float) paper_width);
                int i13 = (((float) ((paper_width - i3) / 2)) * f4);
                int i14 = (((float) ((paper_height - i) / 2)) * f4);
                mLn_zoomview.setPadding(i13, i14, i13, i14);
            }
        }
        mUiHandler.sendEmptyMessageDelayed(50, 200);
        if ((this.printMode & 2) == 0) {
            mDisablePreviewMsg.setLayoutParams(this.Relative_para);
        }
    }

    public void enableProgressBar(boolean z) {
        if (z) {
            mProgress.setVisibility(View.VISIBLE);
            mPre.setEnabled(false);
            mNext.setEnabled(false);
            findViewById(R.id.toolbar).invalidate();
            isBackKeyOK = false;
            return;
        }
        mProgress.setVisibility(View.GONE);
        mPre.setEnabled(true);
        mNext.setEnabled(true);
        findViewById(R.id.toolbar).invalidate();
        isBackKeyOK = true;
    }

    public void updatePageTextView() {
        mPageNum.setText(mCurrentPageView + CommonDefine.SLASH + mEndPageView);
    }

    public void updatePrevNextButtonView() {
        if ((this.printMode & 2) != 0) {
            if (mCurrentPageView != mStartPageView) {
                mPre.setVisibility(View.VISIBLE);
            } else {
                mPre.setVisibility(4);
            }
            if (this.disablePrintArea) {
                mNext.setVisibility(View.VISIBLE);
            } else if (mCurrentPageView != mEndPageView) {
                mNext.setVisibility(View.VISIBLE);
            } else {
                mNext.setVisibility(4);
            }
        }
    }

    public void showErrorDialog(String str, String str2) {
        new CustomTitleAlertDialogBuilder(this).setCancelable(false).setTitle(str).setMessage(str2).setNegativeButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.cancel();
                ActivityDocsPrintPreview.mUiHandler.sendEmptyMessage(7);
            }
        }).create().show();
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        setOrentationView(mIsPortrait);
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == R.id.Menu_Show_PrintSettings) {
            callPrintSetting();
        }
        return super.onOptionsItemSelected(menuItem);
    }

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

    private class CustomProDialog extends Dialog {
        private boolean hasCancelButton;
        private int mLayoutId;

        public CustomProDialog(Context context, int i, int i2, boolean z) {
            super(context, i);
            mLayoutId = i2;
            hasCancelButton = z;
            setCancelable(false);
        }

        protected void onCreate(Bundle bundle) {
            super.onCreate(bundle);
            requestWindowFeature(1);
            View inflate = getLayoutInflater().inflate(mLayoutId, (ViewGroup) null);
            ((Button) inflate.findViewById(R.id.close_btn)).setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    ((Button) CustomProDialog.this.findViewById(R.id.close_btn)).setEnabled(false);
                    if (ActivityDocsPrintPreview.this.loadRemotePreviewTask != null) {
                        ActivityDocsPrintPreview.this.loadRemotePreviewTask.cancel(true);
                    }
                }
            });
            ((TextView) inflate.findViewById(R.id.caution_tv)).setVisibility(4);
            setContentView(inflate);
            if (this.hasCancelButton) {
                ((Button) findViewById(R.id.close_btn)).setVisibility(View.VISIBLE);
            } else {
                ((Button) findViewById(R.id.close_btn)).setVisibility(4);
            }
            ((TextView) findViewById(R.id.loading_tv)).setText(ActivityDocsPrintPreview.this.getString(R.string.epsonconnect_str_get_server_preview));
        }
    }
}
