package com.epson.cameracopy.p006ui;

import android.app.AlertDialog;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.ComponentName;
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.PointF;
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.support.annotation.Nullable;
import android.support.p000v4.app.DialogFragment;
import android.support.p000v4.app.FragmentActivity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.epson.cameracopy.printlayout.ImageAndLayout;
import com.epson.cameracopy.printlayout.ManuscriptSize;
import com.epson.cameracopy.printlayout.PreviewView;
import com.epson.mobilephone.common.ReviewInvitationDialog;
import com.epson.mobilephone.common.ReviewInvitationViewModel;
import com.epson.mobilephone.common.escpr.MediaInfo;
import com.epson.mobilephone.common.wifidirect.NfcTagUtils;
import epson.common.Constants;
import epson.common.DialogProgress;
import epson.common.DialogProgressViewModel;
import epson.common.ExternalFileUtils;
import epson.print.ActivityIACommon;
import epson.print.ActivityNfcPrinter;

import epson.print.CommonDefine;
import epson.print.EPImage;
import epson.print.EPImageList;
import epson.print.MyPrinter;
import epson.print.Util.AsyncTaskExecutor;
import epson.print.Util.EPLog;
import epson.print.screen.PaperSourceInfo;
import epson.print.screen.PaperSourceSetting;
import epson.print.screen.PaperSourceSettingScr;
import epson.print.screen.PrintSetting;
import epson.print.service.EpsonService;
import epson.print.service.IEpsonService;
import epson.print.service.IEpsonServiceCallback;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Locale;

/* renamed from: com.epson.cameracopy.ui.PrintPreviewActivity */
public class PrintPreviewActivity extends ActivityIACommon implements CommonDefine, View.OnClickListener, PreviewView.PrttargetScaleChangeListener, ReviewInvitationDialog.OnClickListener {
    static final /* synthetic */ boolean $assertionsDisabled = false;
    private static final String DIALOG_KEY_STORE_DIALOG = "store-dialog";
    private static final String DIALOG_PROGRESS = "dialog_progress";
    private static final String KEY_PREVIEW_VIEW = "preview-view";
    private static final int MESSAGE_MANUSCRIPT_SCALE_TEXT_UPDATE = 8;
    public static final String PARAM_DISPLAY_SIZE_SET_MESSAGE = "display-sizeset-message";
    public static final String PARAM_IMAGE_LIST = "imageList";
    private static final int REQUEST_CODE_NFC_PRINTER_CHANGE = 4;
    private static final int REQUEST_CODE_ORG_PAPER_SIZE_SELECT = 3;
    private static final int REQUEST_CODE_PRINT = 1;
    private static final int REQUEST_CODE_SETTING = 2;
    private final int LOAD_ALL_IMAGE = 3;
    private final int OUT_OF_MEMORY_ERROR = 7;
    private final int PREVIEW_LOAD_DIALOG_DISMISS = 1;
    private final int PREVIEW_LOAD_DIALOG_SHOW = 0;
    private final PrintSetting.Kind PRINT_MODE_CAMERACOPY = PrintSetting.Kind.cameracopy;
    private final int START_PRINT = 5;
    private final int ZOOM_CONTROL = 2;
    private ArrayList<PaperSourceSetting> aPaperSourceSetting;
    boolean bAutoStartPrint = false;
    private Button backButton = null;
    private int currentColor = 0;
    private int currentLayout = 2;
    private int currentPaperSize = 0;
    private String currentPrinterName = "";
    private boolean enableShowWarning = true;
    /* access modifiers changed from: private */
    public final 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 final ServiceConnection mEpsonConnection = new ServiceConnection() {
        public void onServiceDisconnected(ComponentName componentName) {
            try {
                PrintPreviewActivity.this.mEpsonService.unregisterCallback(PrintPreviewActivity.this.mCallback);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
            IEpsonService unused = PrintPreviewActivity.this.mEpsonService = null;
        }

        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            IEpsonService unused = PrintPreviewActivity.this.mEpsonService = IEpsonService.Stub.asInterface(iBinder);
            if (PrintPreviewActivity.this.mEpsonService != null) {
                try {
                    PrintPreviewActivity.this.mEpsonService.registerCallback(PrintPreviewActivity.this.mCallback);
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    /* access modifiers changed from: private */
    public IEpsonService mEpsonService = null;
    Handler mHandler = new Handler(new Handler.Callback() {
        static final /* synthetic */ boolean $assertionsDisabled = false;

        static {
            Class<PrintPreviewActivity> cls = PrintPreviewActivity.class;
        }

        public boolean handleMessage(Message message) {
            int i = message.what;
            if (i == 3) {
                PrintPreviewActivity.this.startLoadtask();
            } else if (i == 5) {
                PrintPreviewActivity.this.disablePrintButton();
                PrintPreviewActivity.this.startPrint();
            } else if (i != 100) {
                switch (i) {
                    case 0:
                        PrintPreviewActivity.this.showProgressDialog();
                        break;
                    case 1:
                        PrintPreviewActivity.this.dismissProgressDialog();
                        break;
                    default:
                        switch (i) {
                            case 7:
                                if (PrintPreviewActivity.this.mImageList.size() <= 0) {
                                    PrintPreviewActivity.this.disablePrintButton();
                                }
                                PrintPreviewActivity printPreviewActivity = PrintPreviewActivity.this;
                                Toast.makeText(printPreviewActivity, printPreviewActivity.getString(R.string.file_size_notsupport), 1).show();
                                break;
                            case 8:
                                PrintPreviewActivity.this.updateManuscriptScaleText(((Double) message.obj).doubleValue());
                                return true;
                        }
                }
            } else {
                PrintPreviewActivity.this.updatePaperDisplay(message);
            }
            return true;
        }
    });
    /* access modifiers changed from: private */
    public final EPImageList mImageList = new EPImageList();
    private boolean mIsRemotePrinter = false;
    ManuscriptSize mManuscriptSize;
    private DialogProgressViewModel mModelDialog;
    private Button mOriginalImageSizeButton;
    private PreviewView mPreviewView = null;
    int mPrintTargetPaperSizeId = -2;
    private TextView mPrintTargetSizeText;
    private ReviewInvitationViewModel mReviewInvitationViewModel;
    private TextView mScaleText;
    private ImageView paperMissmath = null;
    PaperSourceInfo paperSourceInfo = null;
    private TextView papersizeTextView = null;
    /* access modifiers changed from: private */
    public Button printButton = null;
    private String printerId = "";
    private ImageButton printsettingButton = null;
    private AllReloadTask reloadTask = null;
    private Button rotateButton = null;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_camera_print_preview);
        this.mModelDialog = (DialogProgressViewModel) ViewModelProviders.m2of((FragmentActivity) this).get(DialogProgressViewModel.class);
        this.mModelDialog.getDialogJob().observe(this, new Observer() {
            public final void onChanged(Object obj) {
                PrintPreviewActivity.lambda$onCreate$0(PrintPreviewActivity.this, (Deque) obj);
            }
        });
        this.mReviewInvitationViewModel = (ReviewInvitationViewModel) ViewModelProviders.m2of((FragmentActivity) this).get(ReviewInvitationViewModel.class);
        this.mReviewInvitationViewModel.getShowInvitationLiveData().observe(this, new Observer<Boolean>() {
            public void onChanged(@Nullable Boolean bool) {
                if (bool.booleanValue()) {
                    PrintPreviewActivity.this.showStoreDialog();
                }
            }
        });
        setActionBar((int) R.string.print_title, true);
        ExternalFileUtils.getInstance(this).initPrintDir();
        getImageListFromIntent();
        EPImageList ePImageList = this.mImageList;
        if (ePImageList == null || ePImageList.size() != 1) {
            finish();
            return;
        }
        this.mPreviewView = (PreviewView) findViewById(R.id.previewImageView);
        this.papersizeTextView = (TextView) findViewById(R.id.paper_size_text);
        this.papersizeTextView.setOnClickListener(this);
        this.mPrintTargetSizeText = (TextView) findViewById(R.id.printtarget_size_text);
        this.mPrintTargetSizeText.setOnClickListener(this);
        this.mScaleText = (TextView) findViewById(R.id.scale_text);
        this.mScaleText.setOnClickListener(this);
        this.paperMissmath = (ImageView) findViewById(R.id.icon_papermissmatch);
        this.paperMissmath.setOnClickListener(this);
        this.mOriginalImageSizeButton = (Button) findViewById(R.id.paper_size_button);
        this.mOriginalImageSizeButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                PrintPreviewActivity.this.startOrgImageSizeActivity();
            }
        });
        this.rotateButton = (Button) findViewById(R.id.rotate_button);
        this.rotateButton.setOnClickListener(this);
        this.printButton = (Button) findViewById(R.id.print_button);
        this.printButton.setOnClickListener(this);
        this.mPreviewView.setImage(this.mImageList.get(0).loadImageFileName);
        loadPrinterSettingAndChangeView(true);
        updateManuscriptScaleText(1.0d);
        this.mPreviewView.setPrttargetScaleChangeListener(this);
        this.enableShowWarning = getSharedPreferences(Constants.PREFS_EPSON_CONNECT, 0).getBoolean(Constants.ENABLE_SHOW_WARNING, true);
        this.paperSourceInfo = PaperSourceInfo.getInstance(this);
        if (this.mEpsonService == null) {
            bindService(new Intent(this, EpsonService.class), this.mEpsonConnection, 1);
        }
        if (bundle == null) {
            this.mHandler.sendEmptyMessageDelayed(3, 300);
            checkSizeSetMessage();
        }
    }

    public static /* synthetic */ void lambda$onCreate$0(PrintPreviewActivity printPreviewActivity, Deque deque) {
        String[] checkQueue = printPreviewActivity.mModelDialog.checkQueue();
        if (checkQueue != null) {
            String str = checkQueue[0];
            String str2 = checkQueue[1];
            if (str2.equals("do_show")) {
                printPreviewActivity.showDialog(str);
            }
            if (str2.equals("do_dismiss")) {
                printPreviewActivity.dismissDialog(str);
            }
        }
    }

    /* access modifiers changed from: private */
    public void showStoreDialog() {
        ReviewInvitationDialog.newInstance().show(getSupportFragmentManager(), DIALOG_KEY_STORE_DIALOG);
    }

    private void checkSizeSetMessage() {
        Intent intent = getIntent();
        if (intent != null && intent.getBooleanExtra(PARAM_DISPLAY_SIZE_SET_MESSAGE, false)) {
            Toast makeText = Toast.makeText(this, getString(R.string.manuscript_size_set_message), 1);
            makeText.setGravity(8, 0, 0);
            makeText.show();
        }
    }

    protected void startOrgImageSizeActivity() {
        startActivityForResult(new Intent(this, DocumentSizeSettingActivity.class), 3);
    }

    private void getImageListFromIntent() {
        this.mImageList.clear();
        Intent intent = getIntent();
        if (intent == null) {
            finish();
            return;
        }
        ArrayList<String> stringArrayListExtra = intent.getStringArrayListExtra("imageList");
        if (stringArrayListExtra == null) {
            finish();
            return;
        }
        for (int i = 0; i < stringArrayListExtra.size(); i++) {
            this.mImageList.add(stringArrayListExtra.get(i));
        }
        for (int i2 = 0; i2 < this.mImageList.size(); i2++) {
            if (!checkEPImage(this.mImageList.get(i2))) {
                this.mImageList.clear();
                finish();
                return;
            }
        }
    }

    private boolean checkEPImage(EPImage ePImage) {
        return ePImage != null && ePImage.srcWidth > 0 && ePImage.srcHeight > 0;
    }

    private void updateParaSizeText() {
        String string = getString(new MediaInfo.PaperSize().getStringId(this.currentPaperSize));
        TextView textView = this.papersizeTextView;
        textView.setText(getString(R.string.paper_size) + ": " + string);
    }

    private boolean updateManuscriptSize() {
        ManuscriptSize manuscriptSize = this.mManuscriptSize;
        this.mManuscriptSize = ManuscriptSize.load(this, this.mImageList.get(0).loadImageFileName);
        boolean z = manuscriptSize == null || !manuscriptSize.equals(this.mManuscriptSize);
        if (this.mManuscriptSize.displayLength()) {
            PointF documentSize = this.mManuscriptSize.getDocumentSize(this);
            this.mPrintTargetSizeText.setText(String.format(Locale.US, this.mManuscriptSize.getUnitType(this) == 2 ? "%s: %s (%.1f x %.1f %s)" : "%s: %s (%.0f x %.0f %s)", new Object[]{getString(R.string.document_size), this.mManuscriptSize.getSizeName(this), Float.valueOf(documentSize.x), Float.valueOf(documentSize.y), this.mManuscriptSize.getUnitStr(this)}));
        } else {
            this.mPrintTargetSizeText.setText(String.format(Locale.US, "%s: %s", new Object[]{getString(R.string.document_size), this.mManuscriptSize.getSizeName(this)}));
        }
        return z;
    }

    /* access modifiers changed from: private */
    public void updateManuscriptScaleText(double d) {
        PointF physicalSize = this.mManuscriptSize.getPhysicalSize(this);
        this.mScaleText.setText(String.format(Locale.US, this.mManuscriptSize.getUnitType(this) == 2 ? "%s: %.0f%% (%.1f x %.1f %s)" : "%s: %.0f%% (%.0f x %.0f %s)", new Object[]{getString(R.string.magnification), Double.valueOf(100.0d * d), Double.valueOf(((double) physicalSize.x) * d), Double.valueOf(((double) physicalSize.y) * d), this.mManuscriptSize.getUnitStr(this)}));
    }

    /* access modifiers changed from: private */
    public void loadPrinterSettingAndChangeView(boolean z) {
        boolean z2;
        boolean z3;
        PreviewView previewView;
        boolean isRemotePrinter = isRemotePrinter();
        boolean z4 = false;
        SharedPreferences sharedPreferences = getSharedPreferences("PrintSetting", 0);
        if (sharedPreferences != null) {
            String string = sharedPreferences.getString(Constants.PRINTER_NAME, getString(R.string.str_lbl_title_scan));
            PrintSetting printSetting = new PrintSetting(this, PrintSetting.Kind.cameracopy);
            printSetting.loadSettings();
            this.printerId = sharedPreferences.getString(Constants.PRINTER_ID, (String) null);
            boolean z5 = true;
            if (z || this.mIsRemotePrinter != isRemotePrinter) {
                this.mIsRemotePrinter = isRemotePrinter;
                z3 = true;
                z2 = true;
            } else {
                z3 = false;
                z2 = false;
            }
            if (z || !this.currentPrinterName.equalsIgnoreCase(string)) {
                this.currentPrinterName = string;
                z3 = true;
                z2 = true;
            }
            if (z || this.currentPaperSize != printSetting.paperSizeValue) {
                this.currentPaperSize = printSetting.paperSizeValue;
                PreviewView previewView2 = this.mPreviewView;
                if (previewView2 != null) {
                    previewView2.setPaperSize(this.currentPaperSize);
                }
                z3 = true;
                z2 = true;
            }
            if (z || this.currentLayout != printSetting.layoutValue) {
                this.currentLayout = printSetting.layoutValue;
                if (this.mPreviewView != null) {
                    if (this.currentLayout == 1) {
                        z4 = true;
                    }
                    this.mPreviewView.setBorderless(z4);
                }
                z3 = true;
                z2 = true;
            }
            if (z || this.currentColor != printSetting.colorValue) {
                this.currentColor = printSetting.colorValue;
                PreviewView previewView3 = this.mPreviewView;
                if (previewView3 != null) {
                    previewView3.setColor(this.currentColor);
                }
            } else {
                z5 = z2;
            }
            if (z3) {
                updateManuscriptSize();
                PreviewView previewView4 = this.mPreviewView;
                if (previewView4 != null) {
                    previewView4.printPostionResetRequest();
                    this.mPreviewView.setPrintTargetSize(this.mManuscriptSize.getPixelWidth(), this.mManuscriptSize.getPixelHeight());
                    this.mPreviewView.update();
                }
                updateParaSizeText();
            } else if (z5 && (previewView = this.mPreviewView) != null) {
                previewView.update();
            }
        } else if (this.mIsRemotePrinter != isRemotePrinter) {
            this.mIsRemotePrinter = isRemotePrinter;
        }
    }

    private void enablePrintButton() {
        this.printButton.setEnabled(true);
    }

    /* access modifiers changed from: private */
    public void disablePrintButton() {
        this.printButton.setEnabled(false);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:6:0x0014, code lost:
        r0 = (r0 = getSharedPreferences("PrintSetting", 0)).getString(epson.common.Constants.PRINTER_NAME, getString(epson.print.R.string.str_lbl_title_scan));
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private boolean isPrinterChanged() {
        /*
            r5 = this;
            boolean r0 = r5.isRemotePrinter()
            boolean r1 = r5.mIsRemotePrinter
            r2 = 1
            if (r1 == r0) goto L_0x000a
            return r2
        L_0x000a:
            java.lang.String r0 = "PrintSetting"
            r1 = 0
            android.content.SharedPreferences r0 = r5.getSharedPreferences(r0, r1)
            if (r0 != 0) goto L_0x0014
            return r2
        L_0x0014:
            java.lang.String r3 = "PRINTER_NAME"
            r4 = 2131625174(0x7f0e04d6, float:1.8877549E38)
            java.lang.String r4 = r5.getString(r4)
            java.lang.String r0 = r0.getString(r3, r4)
            if (r0 != 0) goto L_0x0024
            return r2
        L_0x0024:
            java.lang.String r3 = r5.currentPrinterName
            boolean r0 = r3.equalsIgnoreCase(r0)
            if (r0 != 0) goto L_0x002d
            return r2
        L_0x002d:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.epson.cameracopy.p006ui.PrintPreviewActivity.isPrinterChanged():boolean");
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        switch (i) {
            case 1:
                enablePrintButton();
                ExternalFileUtils.getInstance(this).initPrintDir();
                this.mReviewInvitationViewModel.onPrintEnd(CameraPrintProgress.isPrintSuccess(i2));
                return;
            case 2:
                if (i2 == 3) {
                    enablePrintButton();
                    if (isPrinterChanged()) {
                        this.aPaperSourceSetting = null;
                        setPaperSizeDisplayForNoPapaerInfoPrinter();
                        startLoadtask();
                        return;
                    }
                    loadPrinterSettingAndChangeView(false);
                    return;
                }
                return;
            case 3:
                if (updateManuscriptSize()) {
                    this.mPreviewView.setPrintTargetSize(this.mManuscriptSize.getPixelWidth(), this.mManuscriptSize.getPixelHeight());
                    this.mPreviewView.update();
                    return;
                }
                return;
            case 4:
                if (i2 == -1) {
                    this.aPaperSourceSetting = null;
                    setPaperSizeDisplayForNoPapaerInfoPrinter();
                    this.bAutoStartPrint = true;
                    startLoadtask();
                    return;
                }
                return;
            default:
                return;
        }
    }

    protected void onRestart() {
        super.onRestart();
        PreviewView previewView = this.mPreviewView;
        if (previewView != null) {
            previewView.restoreBitmap();
        }
    }

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

    protected void onNewIntent(Intent intent) {
        NfcTagUtils.EpsonNfcConnectInfo parseNECTag;
        super.onNewIntent(intent);
        String action = intent.getAction();
        AllReloadTask allReloadTask = this.reloadTask;
        if (allReloadTask != null && allReloadTask.getStatus() == AsyncTask.Status.FINISHED && "android.nfc.action.NDEF_DISCOVERED".equals(action) && (parseNECTag = NfcTagUtils.parseNECTag(this, intent)) != null) {
            Intent intent2 = new Intent();
            intent2.setClass(this, ActivityNfcPrinter.class);
            intent2.putExtra(ActivityNfcPrinter.CONNECTINFO, parseNECTag);
            intent2.putExtra(ActivityNfcPrinter.CHANGEMODE, 1);
            startActivityForResult(intent2, 4);
        }
    }

    protected void onDestroy() {
        EPLog.m316v("ActivityImageViewSelect", "onDestroy");
        super.onDestroy();
        IEpsonService iEpsonService = this.mEpsonService;
        if (iEpsonService != null) {
            try {
                iEpsonService.cancelSearchPrinter();
                this.mEpsonService.unregisterCallback(this.mCallback);
                unbindService(this.mEpsonConnection);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    }

    protected void onPause() {
        EPLog.m305d("ActivityImageViewSelect", "onPause");
        super.onPause();
        if (isFinishing()) {
            AllReloadTask allReloadTask = this.reloadTask;
            if (allReloadTask != null) {
                allReloadTask.cancel(false);
            }
            dismissProgressDialog();
            this.mHandler.removeMessages(3);
            this.mHandler.removeMessages(5);
            this.mHandler.removeMessages(0);
            this.mHandler.removeMessages(1);
            this.mHandler.removeMessages(100);
            this.mHandler.removeMessages(8);
            this.mPreviewView.setPrttargetScaleChangeListener((PreviewView.PrttargetScaleChangeListener) null);
            this.mPreviewView = null;
        }
        NfcTagUtils.disableForegroundDispatch(this);
        this.paperSourceInfo.stop();
    }

    protected void onStop() {
        if (isFinishing()) {
            new PrintSetting(this, PrintSetting.Kind.cameracopy).resetPrintSettings();
        }
        super.onStop();
    }

    private void check3GAndStartPrint() {
        this.mHandler.sendEmptyMessage(5);
    }

    /* access modifiers changed from: private */
    public void startLoadtask() {
        this.reloadTask = new AllReloadTask();
        this.reloadTask.executeOnExecutor(new Void[0]);
    }

    /* access modifiers changed from: private */
    public void showProgressDialog() {
        this.mModelDialog.doShow(DIALOG_PROGRESS);
    }

    /* access modifiers changed from: private */
    public void dismissProgressDialog() {
        this.mModelDialog.doDismiss(DIALOG_PROGRESS);
    }

    /* access modifiers changed from: private */
    public void startPrint() {
        ExternalFileUtils.getInstance(this).initPrintDir();
        ImageAndLayout imageAndLayout = this.mPreviewView.getImageAndLayout();
        imageAndLayout.setOrgFileName(this.mImageList.get(0).loadImageFileName);
        ArrayList arrayList = new ArrayList();
        arrayList.add(imageAndLayout);
        Intent intent = new Intent(this, CameraPrintProgress.class);
        intent.putExtra(CameraPrintProgress.KEY_IMAGE_AND_LAYOUT, arrayList);
        startActivityForResult(intent, 1);
    }

    /* access modifiers changed from: private */
    public void updatePaperDisplay(Message message) {
        this.aPaperSourceSetting = message.getData().getParcelableArrayList(PaperSourceInfo.KEY_PAPERSOURCEINFO);
        if (this.aPaperSourceSetting != null) {
            this.papersizeTextView.setTextColor(getResources().getColor(R.color.epson_blue));
            this.mPrintTargetSizeText.setTextColor(getResources().getColor(R.color.epson_blue));
            this.mScaleText.setTextColor(getResources().getColor(R.color.epson_blue));
            PrintSetting printSetting = new PrintSetting(this, PrintSetting.Kind.cameracopy);
            printSetting.loadSettings();
            if (this.paperSourceInfo.checkPaperMissmatch(printSetting, this.aPaperSourceSetting)) {
                this.paperMissmath.setVisibility(0);
            } else {
                this.paperMissmath.setVisibility(4);
            }
        } else {
            setPaperSizeDisplayForNoPapaerInfoPrinter();
        }
    }

    private void setPaperSizeDisplayForNoPapaerInfoPrinter() {
        this.papersizeTextView.setTextColor(getResources().getColor(R.color.all_black));
        this.mPrintTargetSizeText.setTextColor(getResources().getColor(R.color.all_black));
        this.mScaleText.setTextColor(getResources().getColor(R.color.all_black));
        this.paperMissmath.setVisibility(4);
    }

    /* access modifiers changed from: private */
    public boolean isRemotePrinter() {
        return MyPrinter.isRemotePrinter(this);
    }

    private void showDialog(String str) {
        DialogProgress newInstance = DialogProgress.newInstance(str, 0, getString(R.string.str_load));
        newInstance.setCancelable(false);
        newInstance.show(getSupportFragmentManager(), str);
    }

    private void dismissDialog(String str) {
        DialogFragment dialogFragment = (DialogFragment) getSupportFragmentManager().findFragmentByTag(str);
        if (dialogFragment != null) {
            dialogFragment.dismiss();
        }
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.icon_papermissmatch /*2131231117*/:
            case R.id.paper_size_text /*2131231310*/:
            case R.id.printtarget_size_text /*2131231374*/:
                if (this.aPaperSourceSetting != null) {
                    Intent intent = new Intent();
                    intent.setClass(this, PaperSourceSettingScr.class);
                    intent.putParcelableArrayListExtra(PaperSourceInfo.KEY_PAPERSOURCEINFO, this.aPaperSourceSetting);
                    intent.putExtra(PaperSourceSettingScr.PRINT_SETTING_TYPE, PrintSetting.Kind.cameracopy.name());
                    startActivityForResult(intent, 2);
                    return;
                }
                callPrintSetting();
                return;
            case R.id.print_button /*2131231336*/:
                this.mIsRemotePrinter = isRemotePrinter();
                if (this.mIsRemotePrinter && this.enableShowWarning) {
                    AlertDialog.Builder cancelable = new AlertDialog.Builder(this).setCancelable(false);
                    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) {
                            PrintPreviewActivity.this.check3GAndStartPrint();
                        }
                    }).setNegativeButton(getString(R.string.str_no), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                        }
                    }).show();
                    return;
                } else if (this.currentPrinterName.equalsIgnoreCase(getString(R.string.str_lbl_title_scan))) {
                    new AlertDialog.Builder(this).setCancelable(false).setTitle(R.string.printer_notselect_title).setMessage(getString(R.string.printer_notselect_warning)).setPositiveButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialogInterface, int i) {
                        }
                    }).show();
                    return;
                } else {
                    check3GAndStartPrint();
                    return;
                }
            case R.id.rotate_button /*2131231420*/:
                this.mPreviewView.rotateImageR90();
                this.mPreviewView.update();
                return;
            default:
                return;
        }
    }

    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.C2138menu.print_menu, menu);
        return true;
    }

    private void setPreferencesDocumentMode() {
        SharedPreferences.Editor edit = getSharedPreferences("PrintSetting", 0).edit();
        edit.putInt(Constants.SOURCE_TYPE, 1);
        edit.commit();
    }

    public void callPrintSetting() {
        System.gc();
        Intent intent = new Intent(this, CameraPrintSettingActivity.class);
        intent.setAction("android.intent.action.VIEW");
        startActivityForResult(intent, 2);
    }

    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (keyEvent.getAction() == 0 && i == 84) {
            EPLog.m307e("key search", "diable");
            return true;
        } else if (keyEvent.getAction() != 0 || i != 4) {
            return false;
        } else {
            onBackPressed();
            return true;
        }
    }

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

    protected void onRestoreInstanceState(Bundle bundle) {
        super.onRestoreInstanceState(bundle);
        this.mPreviewView.restoreInstanceState(bundle, KEY_PREVIEW_VIEW);
    }

    protected void onSaveInstanceState(Bundle bundle) {
        this.mPreviewView.saveInstanceState(bundle, KEY_PREVIEW_VIEW);
        super.onSaveInstanceState(bundle);
    }

    public void onPrttargetScaleChange(double d) {
        this.mHandler.sendMessage(this.mHandler.obtainMessage(8, Double.valueOf(d)));
    }

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

    /* renamed from: com.epson.cameracopy.ui.PrintPreviewActivity$AllReloadTask */
    public class AllReloadTask extends AsyncTaskExecutor<Void, Integer, Boolean> {
        public AllReloadTask() {
        }

        protected void onPreExecute() {
            PrintPreviewActivity.this.showProgressDialog();
        }

        protected Boolean doInBackground(Void... voidArr) {
            System.gc();
            int i = 0;
            do {
                try {
                    if (PrintPreviewActivity.this.mEpsonService != null) {
                        break;
                    } else if (isCancelled()) {
                        return false;
                    } else {
                        Thread.sleep(100);
                        i++;
                    }
                } catch (RemoteException e) {
                    e.printStackTrace();
                } catch (InterruptedException e2) {
                    e2.printStackTrace();
                }
            } while (i < 100);
            if (isCancelled()) {
                return false;
            }
            if (PrintPreviewActivity.this.mEpsonService != null) {
                if (PrintPreviewActivity.this.isRemotePrinter()) {
                    PrintPreviewActivity.this.mEpsonService.EpsonConnectUpdatePrinterSettings(PrintSetting.Kind.cameracopy.name());
                } else {
                    PrintPreviewActivity.this.mEpsonService.updatePrinterSettings(PrintSetting.Kind.cameracopy.name());
                }
            }
            return true;
        }

        protected void onPostExecute(Boolean bool) {
            PrintPreviewActivity.this.loadPrinterSettingAndChangeView(false);
            PrintPreviewActivity.this.dismissProgressDialog();
            if (PrintPreviewActivity.this.bAutoStartPrint) {
                PrintPreviewActivity printPreviewActivity = PrintPreviewActivity.this;
                printPreviewActivity.onClick(printPreviewActivity.printButton);
                PrintPreviewActivity.this.bAutoStartPrint = false;
            }
        }
    }
}
