package com.epson.cameracopy.p006ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.PointF;
import android.net.Uri;
import android.os.Bundle;
import android.os.Debug;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.support.p000v4.app.DialogFragment;
import android.support.p000v4.app.FragmentActivity;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import com.epson.cameracopy.alt.UiCommon;
import com.epson.cameracopy.device.CameraPreviewControl;
import com.epson.cameracopy.printlayout.DocumentSizeInfo;
import com.epson.cameracopy.printlayout.RegistedDocumentSizeList;
import com.epson.mobilephone.common.EpLog;
import epson.colorcorrection.ImageCollect;
import epson.common.DialogProgress;
import epson.common.DialogProgressViewModel;
import epson.common.ExternalFileUtils;
import epson.common.Info_paper;
import epson.print.ActivityIACommon;
import epson.print.ActivityRequestPermissions;

import epson.print.CommonDefine;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Locale;
import org.opencv.core.Size;

/* renamed from: com.epson.cameracopy.ui.CropImageActivity */
public class CropImageActivity extends ActivityIACommon implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, View.OnTouchListener, GestureDetector.OnDoubleTapListener {
    private static final int ACTIVITY_MODE_COLOR_ADJUSTMENT = 2;
    private static final int ACTIVITY_MODE_CROP_IMAGE = 0;
    private static final int ACTIVITY_MODE_ENHANCE_TEXT = 1;
    private static final String DIALOG_PROGRESS = "dialog_progress";
    private static final String ICPD_FOLDER_PRINT_DATA = "ic";
    public static final String IMAGE_FILE_NAME = "image_file_name";
    private static final int MESSAGE_BOX_TYPE_CANCEL = 103;
    private static final int MESSAGE_BOX_TYPE_OK = 102;
    private static final int MESSAGE_BOX_TYPE_YES_NO = 101;
    private static final int MSG_DEBUG_MODE = 390;
    private static final int MSG_DEBUG_RESOLUTION_THRESHOLD = 391;
    private static final int MSG_DEBUG_SMALL_PREVIEW_RATE = 392;
    private static final int MSG_PREVIEW_CROP = 801;
    public static final int MSG_PREVIEW_EDGE_DETECTION = 301;
    private static final int MSG_PREVIEW_LOAD_DIALOG_DISMISS = 902;
    private static final int MSG_PREVIEW_LOAD_DIALOG_SHOW = 901;
    private static final int MSG_PREVIEW_LOAD_FINISH = 912;
    private static final int MSG_PREVIEW_LOAD_PHOTO = 911;
    private static final int MSG_PREVIEW_PRINT_PREVIEW_EXECUTE = 841;
    private static final int MSG_PREVIEW_PRINT_PREVIEW_FINISH = 842;
    private static final int MSG_PREVIEW_SAVE_EXECUTE = 831;
    private static final int MSG_PREVIEW_SAVE_FINISH = 832;
    public static final int MSG_PREVIEW_TOUCH_EVENT_ACTION_DOWN = 311;
    private static final int MSG_SDIC_BCSC_FIX_CANCEL = 825;
    private static final int MSG_SDIC_BCSC_FIX_PROC = 824;
    private static final int MSG_SDIC_BCSC_FIX_QUIT = 826;
    private static final int MSG_SDIC_BCSC_RESET = 823;
    private static final int MSG_SDIC_PWC_EXECUTE = 811;
    private static final int MSG_SDIC_PWC_FINISH = 812;
    private static final int REQUEST_CODE_ORG_PAPER_SIZE_SELECT = 3;
    private static final int REQUEST_RUNTIMEPERMMISSION = 4;
    public static final String RESULT_COLLECTED_FILE_NAME = "corrected_file_name";
    private static final int SEEK_BAR_STEP = 10;
    private static WeakReference<Activity> mActivity;
    /* access modifiers changed from: private */
    public static CropImageActivity mCropImageActivity;
    /* access modifiers changed from: private */
    public static Handler mHandler = new Handler() {
        public void handleMessage(Message message) {
            if (CropImageActivity.mCropImageActivity != null) {
                CropImageActivity.mCropImageActivity.executeMessage(message);
            }
        }
    };
    private int mActivityMode;
    private float mBcscBDefault;
    private float mBcscBValue;
    private float mBcscCDefault;
    private float mBcscCValue;
    private float mBcscSDefault;
    private float mBcscSValue;
    private int mBcscSeekBarBDefault;
    private int mBcscSeekBarCDefault;
    private int mBcscSeekBarSDefault;
    private int mBcscType;
    private Bitmap mBitmapPreview = null;
    private Button mButtonColorAdjustment;
    private Button mButtonDocSize;
    private Button mButtonExecute;
    private Button mButtonReset;
    private Button mButtonSave;
    private File mCacheFolder = null;
    /* access modifiers changed from: private */
    public List<CorrectionParamSet> mCorrectionHistory = null;
    /* access modifiers changed from: private */
    public CorrectionParamSet mCorrectionParamSet = null;
    private FrameLayout mCropImageFrameLayout = null;
    private View mCropImageHeader = null;
    boolean mCropImageMessageShow = true;
    private int mCurrentPaperId = 0;
    Size mCurrentPaperSize = null;
    private CustomToast mCustomToast = null;
    private DaemonView mDaemonView = null;
    private int mDebugID = 0;
    /* access modifiers changed from: private */
    public int mDebugMode = 0;
    /* access modifiers changed from: private */
    public int mDebugResolutionThreshold = 2;
    /* access modifiers changed from: private */
    public int mDebugSmallPreviewRate = 2;
    Size mDeviceSize = null;
    DocumentSizeInfo mDocumentSizeInfo = null;
    private GestureDetector mGestureDetector = null;
    /* access modifiers changed from: private */
    public ImageCollect mImageCollect = null;
    private LinearLayout mImageCollectAdjustmentBrightness = null;
    private SeekBar mImageCollectAdjustmentBrightnessSeekBar = null;
    private TextView mImageCollectAdjustmentBrightnessTitle = null;
    private LinearLayout mImageCollectAdjustmentContrast = null;
    private SeekBar mImageCollectAdjustmentContrastSeekBar = null;
    private TextView mImageCollectAdjustmentContrastTitle = null;
    private LinearLayout mImageCollectAdjustmentSaturation = null;
    private SeekBar mImageCollectAdjustmentSaturationSeekBar = null;
    private TextView mImageCollectAdjustmentSaturationTitle = null;
    private RadioGroup mImageCollectAdjustmentSwitch = null;
    private int mImageCollectAdjustmentSwitchId;
    private RadioButton mImageCollectAdjustmentSwitchLeft = null;
    private RadioButton mImageCollectAdjustmentSwitchRight = null;
    private RelativeLayout mImageCollectLayout = null;
    private Button mImageCollectPalletButton = null;
    private LinearLayout mImageCollectPalletLayout = null;
    private TextView mImageCollectPaperSizeInfo = null;
    private LinearLayout mImageCollectPreviewLayout = null;
    private RadioGroup mImageCollectSwitch = null;
    private int mImageCollectSwitchId;
    private LinearLayout mImageCollectSwitchLayout = null;
    private RadioButton mImageCollectSwitchLeft = null;
    private RadioButton mImageCollectSwitchMiddle = null;
    private RadioButton mImageCollectSwitchRight = null;
    /* access modifiers changed from: private */
    public ImageCollectView mImageCollectView = null;
    /* access modifiers changed from: private */
    public int mImageType = 2;
    Info_paper mInfoPaper = null;
    private int mMaskType;
    private AlertDialog mMessageDialog = null;
    private DisplayMetrics mMetrics = null;
    private DialogProgressViewModel mModelDialog;
    /* access modifiers changed from: private */
    public double mPaperHeight = 0.0d;
    /* access modifiers changed from: private */
    public int mPaperId = -999;
    Size mPaperSize = null;
    /* access modifiers changed from: private */
    public double mPaperWidth = 0.0d;
    /* access modifiers changed from: private */
    public PointF[] mPointPreviewCropPoint = null;
    private int mPreviewType;
    private DialogProgress mProgressDialog = null;
    private boolean[] mSaveApprovalTable = null;
    private LinearLayout mToolBartLayout = null;
    private LinearLayout mToolbarColorAdjustment = null;
    private LinearLayout mToolbarCropImage = null;
    private LinearLayout mToolbarEnhanceText = null;
    private File mUserFolder = null;
    private final GestureDetector.SimpleOnGestureListener onGestureDetectorListener = new GestureDetector.SimpleOnGestureListener() {
        public void onLongPress(MotionEvent motionEvent) {
            if (CropImageActivity.this.mDebugMode == 4) {
                CropImageActivity.mHandler.sendEmptyMessage(CropImageActivity.MSG_DEBUG_MODE);
            }
            super.onLongPress(motionEvent);
        }
    };

    public boolean onDoubleTapEvent(MotionEvent motionEvent) {
        return false;
    }

    public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
        return false;
    }

    public void onStartTrackingTouch(SeekBar seekBar) {
    }

    public void onStopTrackingTouch(SeekBar seekBar) {
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_crop_image);
        this.mModelDialog = (DialogProgressViewModel) ViewModelProviders.m2of((FragmentActivity) this).get(DialogProgressViewModel.class);
        this.mModelDialog.getDialogJob().observe(this, new Observer() {
            public final void onChanged(Object obj) {
                CropImageActivity.lambda$onCreate$0(CropImageActivity.this, (Deque) obj);
            }
        });
        setActionBar((int) R.string.crop_image_title, true);
        mActivity = new WeakReference<>(this);
        mCropImageActivity = (CropImageActivity) mActivity.get();
        this.mModelDialog.doShow(DIALOG_PROGRESS);
        this.mPaperSize = new Size(0.0d, 0.0d);
        GetPaperInfo();
        this.mDaemonView = new DaemonView(this);
        this.mCropImageFrameLayout = (FrameLayout) findViewById(R.id.crop_image_frame_layout);
        this.mCropImageFrameLayout.addView(this.mDaemonView);
        this.mImageCollectLayout = (RelativeLayout) findViewById(R.id.ImageCollectLayout);
        this.mImageCollectPreviewLayout = (LinearLayout) findViewById(R.id.ImageCollectPreviewLayout);
        this.mImageCollectView = (ImageCollectView) this.mImageCollectPreviewLayout.findViewById(R.id.ImageCollectView);
        this.mImageCollectView.SetHandler(mHandler);
        this.mImageCollectPaperSizeInfo = (TextView) this.mImageCollectPreviewLayout.findViewById(R.id.ImageCollectPaperSizeInfo);
        this.mImageCollectPaperSizeInfo.setSingleLine(true);
        this.mImageCollectPaperSizeInfo.setEllipsize(TextUtils.TruncateAt.END);
        this.mImageCollectPaperSizeInfo.setText(getDocumentSizeText());
        this.mImageCollectPalletButton = (Button) this.mImageCollectPreviewLayout.findViewById(R.id.ImageCollectPalletButton);
        this.mImageCollectPalletButton.setOnClickListener(this);
        this.mImageCollectPalletButton.setVisibility(4);
        this.mImageCollectSwitchLayout = (LinearLayout) findViewById(R.id.ImageCollectSwitchLayout);
        this.mImageCollectSwitch = (RadioGroup) findViewById(R.id.ImageCollectSwitch);
        this.mImageCollectSwitchLeft = (RadioButton) findViewById(R.id.ImageCollectSwitchLeft);
        this.mImageCollectSwitchLeft.setOnClickListener(this);
        this.mImageCollectSwitchMiddle = (RadioButton) findViewById(R.id.ImageCollectSwitchMiddle);
        this.mImageCollectSwitchMiddle.setOnClickListener(this);
        this.mImageCollectSwitchRight = (RadioButton) findViewById(R.id.ImageCollectSwitchRight);
        this.mImageCollectSwitchRight.setOnClickListener(this);
        this.mImageCollectPalletLayout = (LinearLayout) findViewById(R.id.ImageCollectPalletLayout);
        this.mImageCollectAdjustmentBrightness = (LinearLayout) findViewById(R.id.ImageCollectAdjustmentBrightness);
        this.mImageCollectAdjustmentBrightnessTitle = (TextView) this.mImageCollectAdjustmentBrightness.findViewById(R.id.AdjustmentBarTitle);
        this.mImageCollectAdjustmentBrightnessTitle.setText(R.string.brightness);
        this.mImageCollectAdjustmentBrightnessSeekBar = (SeekBar) this.mImageCollectAdjustmentBrightness.findViewById(R.id.AdjustmentBarSeekBar);
        this.mImageCollectAdjustmentBrightnessSeekBar.setOnSeekBarChangeListener(this);
        this.mImageCollectAdjustmentContrast = (LinearLayout) findViewById(R.id.ImageCollectAdjustmentContrast);
        this.mImageCollectAdjustmentContrastTitle = (TextView) this.mImageCollectAdjustmentContrast.findViewById(R.id.AdjustmentBarTitle);
        this.mImageCollectAdjustmentContrastTitle.setText(R.string.contrast);
        this.mImageCollectAdjustmentContrastSeekBar = (SeekBar) this.mImageCollectAdjustmentContrast.findViewById(R.id.AdjustmentBarSeekBar);
        this.mImageCollectAdjustmentContrastSeekBar.setOnSeekBarChangeListener(this);
        this.mImageCollectAdjustmentSaturation = (LinearLayout) findViewById(R.id.ImageCollectAdjustmentSaturation);
        this.mImageCollectAdjustmentSaturationTitle = (TextView) this.mImageCollectAdjustmentSaturation.findViewById(R.id.AdjustmentBarTitle);
        this.mImageCollectAdjustmentSaturationTitle.setText(R.string.saturation);
        this.mImageCollectAdjustmentSaturationSeekBar = (SeekBar) this.mImageCollectAdjustmentSaturation.findViewById(R.id.AdjustmentBarSeekBar);
        this.mImageCollectAdjustmentSaturationSeekBar.setOnSeekBarChangeListener(this);
        this.mImageCollectAdjustmentSwitch = (RadioGroup) findViewById(R.id.AdjustmentModeSwitch);
        this.mImageCollectAdjustmentSwitchLeft = (RadioButton) findViewById(R.id.AdjustmentModeSwitchLeft);
        this.mImageCollectAdjustmentSwitchLeft.setOnClickListener(this);
        this.mImageCollectAdjustmentSwitchRight = (RadioButton) findViewById(R.id.AdjustmentModeSwitchRight);
        this.mImageCollectAdjustmentSwitchRight.setOnClickListener(this);
        this.mCropImageHeader = findViewById(R.id.navigation_bar);
        this.mToolBartLayout = (LinearLayout) findViewById(R.id.tool_bar);
        this.mToolbarCropImage = (LinearLayout) this.mToolBartLayout.findViewById(R.id.ImageCollectToolbarCropImage);
        this.mToolbarEnhanceText = (LinearLayout) this.mToolBartLayout.findViewById(R.id.ImageCollectToolbarEnhanceText);
        this.mToolbarColorAdjustment = (LinearLayout) this.mToolBartLayout.findViewById(R.id.ImageCollectToolbarColorAdjustment);
        this.mCropImageHeader.setOnTouchListener(this);
        this.mCropImageHeader.setOnClickListener(this);
        this.mToolbarCropImage.setOnTouchListener(this);
        this.mToolbarCropImage.setOnClickListener(this);
        this.mToolbarEnhanceText.setOnTouchListener(this);
        this.mToolbarEnhanceText.setOnClickListener(this);
        this.mBcscSeekBarBDefault = 5;
        this.mBcscSeekBarCDefault = 0;
        this.mBcscSeekBarSDefault = 5;
        this.mBcscBDefault = 0.0f;
        this.mBcscCDefault = 0.0f;
        this.mBcscSDefault = 0.0f;
        InitBCSCParams();
        this.mSaveApprovalTable = new boolean[5];
        activityModeChange(0);
        String stringExtra = getIntent().getStringExtra(IMAGE_FILE_NAME);
        this.mMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(this.mMetrics);
        this.mDeviceSize = new Size((double) this.mMetrics.widthPixels, (double) this.mMetrics.heightPixels);
        this.mCorrectionParamSet = new CorrectionParamSet();
        this.mCorrectionHistory = new ArrayList();
        this.mUserFolder = GetCacheFolder(false);
        this.mCacheFolder = GetCacheFolder(true);
        CameraPreviewControl instance = CameraPreviewControl.getInstance(this);
        this.mCurrentPaperId = 0;
        String country = Locale.getDefault().getCountry();
        String language = Locale.getDefault().getLanguage();
        if ((country.equals(Locale.US.getCountry()) || country.equals(Locale.CANADA.getCountry())) && !language.equals(Locale.FRENCH.getLanguage())) {
            this.mCurrentPaperId = 1;
        }
        this.mCurrentPaperSize = new Size(3048.0d, 4321.0d);
        Info_paper infoPaper = Info_paper.getInfoPaper(this, this.mCurrentPaperId);
        if (infoPaper != null) {
            this.mCurrentPaperSize.width = (double) infoPaper.getPaper_width();
            this.mCurrentPaperSize.height = (double) infoPaper.getPaper_height();
        }
        this.mImageCollect = new ImageCollect(stringExtra, this.mMetrics.density, this.mCurrentPaperSize);
        this.mImageCollect.SetPath(this.mCacheFolder, this.mUserFolder, instance.getSaveDirecotry());
        this.mPreviewType = -1;
        mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_PHOTO);
        this.mGestureDetector = new GestureDetector(this, this.onGestureDetectorListener);
    }

    public static /* synthetic */ void lambda$onCreate$0(CropImageActivity cropImageActivity, Deque deque) {
        String[] checkQueue = cropImageActivity.mModelDialog.checkQueue();
        if (checkQueue != null) {
            String str = checkQueue[0];
            String str2 = checkQueue[1];
            if (str2.equals("do_show")) {
                cropImageActivity.showDialog(str);
            }
            if (str2.equals("do_dismiss")) {
                cropImageActivity.dismissDialog(str);
                EpLog.m69d("dismissDialog");
                if (cropImageActivity.mCropImageMessageShow) {
                    EpLog.m69d("TOAST");
                    cropImageActivity.mCropImageMessageShow = false;
                    cropImageActivity.ToastMessage(cropImageActivity.getString(R.string.crop_image_message));
                }
            }
        }
    }

    public void onRestart() {
        super.onRestart();
    }

    public void onStart() {
        super.onStart();
    }

    public void onResume() {
        super.onResume();
    }

    public void onPause() {
        super.onPause();
        EpLog.m68d();
        CancelToast();
    }

    public void onStop() {
        super.onStop();
        EpLog.m68d();
        CancelToast();
    }

    private void CancelToast() {
        if (this.mCustomToast != null) {
            EpLog.m69d(" Toast Cancel");
            this.mCustomToast.cancel();
            this.mCustomToast = null;
        }
    }

    protected void onDestroy() {
        releaseResource();
        super.onDestroy();
    }

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

    public void onWindowFocusChanged(boolean z) {
        super.onWindowFocusChanged(z);
    }

    public void onBackPressed() {
        int i = this.mActivityMode;
        if (i == 0) {
            this.mActivityMode = -1;
            this.mImageCollectView.MessageOff();
            CancelToast();
            releaseResource();
            finish();
        } else if (i == 1) {
            activityModeChange(0);
            PointF[] GetCornerPoints = this.mImageCollect.GetCornerPoints();
            GetPreviewImage(0);
            this.mImageCollectView.SetPreviewBitmapAndCropData(this.mBitmapPreview, GetCornerPoints);
        } else if (i == 2) {
            activityModeChange(1);
            GetPreviewImage(this.mImageType);
            this.mImageCollectView.SetPreviewBitmapAndCropData(this.mBitmapPreview);
        }
    }

    protected void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
    }

    protected void onRestoreInstanceState(Bundle bundle) {
        super.onRestoreInstanceState(bundle);
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        if (i == 3) {
            GetPaperInfo();
            this.mImageCollectPaperSizeInfo.setText(getDocumentSizeText());
        }
        if (i == 4 && i2 == -1) {
            savePreviewExecute();
        }
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.AdjustmentModeSwitchLeft /*2131230725*/:
                if (this.mImageCollectAdjustmentSwitchId != R.id.AdjustmentModeSwitchLeft) {
                    this.mImageCollectAdjustmentSwitchId = R.id.AdjustmentModeSwitchLeft;
                    AdjustmentModeSwitchALL();
                    return;
                }
                return;
            case R.id.AdjustmentModeSwitchRight /*2131230726*/:
                if (this.mImageCollectAdjustmentSwitchId != R.id.AdjustmentModeSwitchRight) {
                    this.mImageCollectAdjustmentSwitchId = R.id.AdjustmentModeSwitchRight;
                    AdjustmentModeSwitchPART();
                    return;
                }
                return;
            case R.id.ImageCollectPalletButton /*2131230737*/:
                palletShow();
                return;
            case R.id.ImageCollectSwitchLeft /*2131230744*/:
                if (this.mImageCollectSwitchId != R.id.ImageCollectSwitchLeft) {
                    this.mImageCollectSwitchId = R.id.ImageCollectSwitchLeft;
                    ImageCollectSwitchPWC(1);
                    return;
                }
                return;
            case R.id.ImageCollectSwitchMiddle /*2131230745*/:
                if (this.mImageCollectSwitchId != R.id.ImageCollectSwitchMiddle) {
                    this.mImageCollectSwitchId = R.id.ImageCollectSwitchMiddle;
                    ImageCollectSwitchPWC(2);
                    return;
                }
                return;
            case R.id.ImageCollectSwitchRight /*2131230746*/:
                if (this.mImageCollectSwitchId != R.id.ImageCollectSwitchRight) {
                    this.mImageCollectSwitchId = R.id.ImageCollectSwitchRight;
                    ImageCollectSwitchCROP();
                    return;
                }
                return;
            case R.id.color_adjustment_button /*2131230932*/:
                activityModeChange(2);
                InitBCSC();
                return;
            case R.id.document_size_button /*2131230996*/:
                this.mImageCollectView.MessageOff();
                setDocumentSize();
                return;
            case R.id.execute_button /*2131231032*/:
                int i = this.mActivityMode;
                if (i == 0) {
                    this.mImageCollectView.MessageOff();
                    mHandler.sendEmptyMessage(MSG_PREVIEW_CROP);
                    return;
                } else if (i == 1) {
                    MessageBox(101, -1, R.string.finish_adjustment_message, MSG_PREVIEW_PRINT_PREVIEW_EXECUTE);
                    return;
                } else if (i == 2) {
                    boolean z = false;
                    if (!(this.mBcscBValue == this.mBcscBDefault && this.mBcscCValue == this.mBcscCDefault && this.mBcscSValue == this.mBcscSDefault)) {
                        z = true;
                    }
                    if (this.mCorrectionParamSet.Size() > 0) {
                        z = true;
                    }
                    if (z) {
                        MessageBox(101, -1, (int) R.string.finish_color_adjustment_message, (int) MSG_SDIC_BCSC_FIX_PROC, (int) MSG_SDIC_BCSC_FIX_CANCEL);
                        return;
                    }
                    activityModeChange(1);
                    GetPreviewImage(this.mImageType);
                    this.mImageCollectView.SetPreviewBitmapAndCropData(this.mBitmapPreview);
                    return;
                } else {
                    return;
                }
            case R.id.reset_button /*2131231403*/:
                MessageBox(101, -1, R.string.reset_color_adjustment_message, MSG_SDIC_BCSC_RESET);
                return;
            case R.id.save_button /*2131231436*/:
                mHandler.sendEmptyMessage(MSG_PREVIEW_SAVE_EXECUTE);
                return;
            default:
                return;
        }
    }

    public boolean onTouch(View view, MotionEvent motionEvent) {
        this.mDebugID = view.getId();
        this.mGestureDetector.onTouchEvent(motionEvent);
        return false;
    }

    public boolean onDoubleTap(MotionEvent motionEvent) {
        if (this.mDebugID == this.mCropImageHeader.getId()) {
            int i = this.mDebugMode;
            if (i == 1) {
                this.mDebugMode = i + 1;
            }
            int i2 = this.mDebugMode;
            if (i2 == 3) {
                this.mDebugMode = i2 + 1;
                this.mToolbarCropImage.setBackgroundColor(Color.rgb(8, 35, 130));
                this.mToolbarEnhanceText.setBackgroundColor(Color.rgb(8, 35, 130));
                this.mToolbarColorAdjustment.setBackgroundColor(Color.rgb(8, 35, 130));
            }
        } else if (this.mDebugID == this.mToolbarCropImage.getId() || this.mDebugID == this.mToolbarEnhanceText.getId()) {
            int i3 = this.mDebugMode;
            if (i3 == 0) {
                this.mDebugMode = i3 + 1;
            }
            int i4 = this.mDebugMode;
            if (i4 == 2) {
                this.mDebugMode = i4 + 1;
            }
        }
        this.mDebugID = 0;
        return false;
    }

    public void onProgressChanged(SeekBar seekBar, int i, boolean z) {
        if (z) {
            SeekBarTracking();
        }
    }

    /* access modifiers changed from: private */
    public void executeMessage(Message message) {
        String str;
        switch (message.what) {
            case 301:
                ImageCollectView imageCollectView = this.mImageCollectView;
                imageCollectView.SetMaskEdge(this.mImageCollect.DetectEdge(imageCollectView.GetMaskImage()));
                float progress = (float) this.mImageCollectAdjustmentContrastSeekBar.getProgress();
                float progress2 = (float) this.mImageCollectAdjustmentSaturationSeekBar.getProgress();
                UiCommon.setButtonEnabled(this.mButtonReset, true);
                if (((float) this.mImageCollectAdjustmentBrightnessSeekBar.getProgress()) != ((float) this.mBcscSeekBarBDefault) || progress != ((float) this.mBcscSeekBarCDefault) || progress2 != ((float) this.mBcscSeekBarSDefault)) {
                    PreviewImageBCSC();
                    return;
                }
                return;
            case MSG_PREVIEW_TOUCH_EVENT_ACTION_DOWN /*311*/:
                CancelToast();
                return;
            case MSG_DEBUG_MODE /*390*/:
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("Menu");
                builder.setCancelable(false);
                builder.setItems(new String[]{"Resolution Threshold", "Small Preview Rate"}, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch (i) {
                            case 0:
                                CropImageActivity.mHandler.sendEmptyMessage(CropImageActivity.MSG_DEBUG_RESOLUTION_THRESHOLD);
                                return;
                            case 1:
                                CropImageActivity.mHandler.sendEmptyMessage(CropImageActivity.MSG_DEBUG_SMALL_PREVIEW_RATE);
                                return;
                            default:
                                return;
                        }
                    }
                });
                builder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                    }
                });
                builder.show();
                return;
            case MSG_DEBUG_RESOLUTION_THRESHOLD /*391*/:
                AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
                builder2.setTitle("Resolution Threshold");
                builder2.setCancelable(false);
                builder2.setSingleChoiceItems(new String[]{"360dpi", "300dpi", "240dpi", "180dpi", "120dpi"}, this.mDebugResolutionThreshold, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch (i) {
                            case 0:
                                CropImageActivity.this.mImageCollect.SetResolutionThreshold(360.0d);
                                break;
                            case 1:
                                CropImageActivity.this.mImageCollect.SetResolutionThreshold(300.0d);
                                break;
                            case 2:
                                CropImageActivity.this.mImageCollect.SetResolutionThreshold(240.0d);
                                break;
                            case 3:
                                CropImageActivity.this.mImageCollect.SetResolutionThreshold(180.0d);
                                break;
                            case 4:
                                CropImageActivity.this.mImageCollect.SetResolutionThreshold(120.0d);
                                break;
                        }
                        int unused = CropImageActivity.this.mDebugResolutionThreshold = i;
                    }
                });
                builder2.setPositiveButton(CommonDefine.f335OK, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                    }
                });
                builder2.show();
                return;
            case MSG_DEBUG_SMALL_PREVIEW_RATE /*392*/:
                AlertDialog.Builder builder3 = new AlertDialog.Builder(this);
                builder3.setTitle("Small Preview Rate");
                builder3.setCancelable(false);
                builder3.setSingleChoiceItems(new String[]{"1/1.0", "1/1.5", "1/2.0", "1/2.5", "1/3.0", "1/3.5", "1/4.0"}, this.mDebugSmallPreviewRate, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch (i) {
                            case 0:
                                CropImageActivity.this.mImageCollect.SetSmallPreviewRate(1.0f);
                                break;
                            case 1:
                                CropImageActivity.this.mImageCollect.SetSmallPreviewRate(1.5f);
                                break;
                            case 2:
                                CropImageActivity.this.mImageCollect.SetSmallPreviewRate(2.0f);
                                break;
                            case 3:
                                CropImageActivity.this.mImageCollect.SetSmallPreviewRate(2.5f);
                                break;
                            case 4:
                                CropImageActivity.this.mImageCollect.SetSmallPreviewRate(3.0f);
                                break;
                            case 5:
                                CropImageActivity.this.mImageCollect.SetSmallPreviewRate(3.5f);
                                break;
                            case 6:
                                CropImageActivity.this.mImageCollect.SetSmallPreviewRate(4.0f);
                                break;
                        }
                        int unused = CropImageActivity.this.mDebugSmallPreviewRate = i;
                    }
                });
                builder3.setPositiveButton(CommonDefine.f335OK, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                    }
                });
                builder3.show();
                return;
            case MSG_PREVIEW_CROP /*801*/:
                mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_SHOW);
                new Thread(new Runnable() {
                    public void run() {
                        int paperId = CropImageActivity.this.mDocumentSizeInfo.getPaperId();
                        double width = CropImageActivity.this.mDocumentSizeInfo.getWidth();
                        double height = CropImageActivity.this.mDocumentSizeInfo.getHeight();
                        PointF[] GetCropPoint = CropImageActivity.this.mImageCollectView.GetCropPoint();
                        boolean z = false;
                        boolean z2 = true;
                        if (!(CropImageActivity.this.mPointPreviewCropPoint == null || GetCropPoint == null || (CropImageActivity.this.mPointPreviewCropPoint[0].x == GetCropPoint[0].x && CropImageActivity.this.mPointPreviewCropPoint[0].y == GetCropPoint[0].y && CropImageActivity.this.mPointPreviewCropPoint[1].x == GetCropPoint[1].x && CropImageActivity.this.mPointPreviewCropPoint[1].y == GetCropPoint[1].y && CropImageActivity.this.mPointPreviewCropPoint[2].x == GetCropPoint[2].x && CropImageActivity.this.mPointPreviewCropPoint[2].y == GetCropPoint[2].y && CropImageActivity.this.mPointPreviewCropPoint[3].x == GetCropPoint[3].x && CropImageActivity.this.mPointPreviewCropPoint[3].y == GetCropPoint[3].y))) {
                            z = true;
                        }
                        if (z || (CropImageActivity.this.mPaperId == -1 || paperId == -1 ? CropImageActivity.this.mPaperId == paperId : CropImageActivity.this.mPaperWidth == width && CropImageActivity.this.mPaperHeight == height)) {
                            z2 = z;
                        }
                        int unused = CropImageActivity.this.mPaperId = paperId;
                        double unused2 = CropImageActivity.this.mPaperWidth = width;
                        double unused3 = CropImageActivity.this.mPaperHeight = height;
                        if (z2) {
                            PointF[] unused4 = CropImageActivity.this.mPointPreviewCropPoint = GetCropPoint;
                            CropImageActivity.this.mImageCollect.MakePreviewImageCROP(CropImageActivity.this.mPointPreviewCropPoint, CropImageActivity.this.mPaperSize, CropImageActivity.this.mDeviceSize);
                            CropImageActivity.mHandler.sendEmptyMessage(CropImageActivity.MSG_SDIC_PWC_EXECUTE);
                            return;
                        }
                        CropImageActivity.mHandler.sendEmptyMessage(CropImageActivity.MSG_SDIC_PWC_FINISH);
                    }
                }).start();
                return;
            case MSG_SDIC_PWC_EXECUTE /*811*/:
                new Thread(new Runnable() {
                    public void run() {
                        CropImageActivity.this.mImageCollect.MakePreviewImagePWC(-1);
                        CropImageActivity.mHandler.sendEmptyMessage(CropImageActivity.MSG_SDIC_PWC_FINISH);
                    }
                }).start();
                return;
            case MSG_SDIC_PWC_FINISH /*812*/:
                this.mImageCollectSwitchId = R.id.ImageCollectSwitchLeft;
                this.mImageCollectSwitch.check(this.mImageCollectSwitchId);
                this.mImageType = 2;
                activityModeChange(1);
                ImageCollectSwitchPWC(1);
                mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_DISMISS);
                return;
            case MSG_SDIC_BCSC_RESET /*823*/:
                InitBCSC();
                UiCommon.setButtonEnabled(this.mButtonReset, false);
                return;
            case MSG_SDIC_BCSC_FIX_PROC /*824*/:
                AdjustmentModeSwitchEXECUTE();
                this.mSaveApprovalTable[4] = true;
                mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_SHOW);
                this.mCorrectionParamSet.SetImageType(this.mImageType);
                this.mCorrectionHistory.add(this.mCorrectionParamSet.Clone());
                new Thread(new Runnable() {
                    public void run() {
                        CropImageActivity.this.mImageCollect.MakePreviewBCSC(CropImageActivity.this.mCorrectionParamSet);
                        CropImageActivity.mHandler.sendEmptyMessage(CropImageActivity.MSG_SDIC_BCSC_FIX_QUIT);
                    }
                }).start();
                return;
            case MSG_SDIC_BCSC_FIX_QUIT /*826*/:
                activityModeChange(1);
                GetPreviewImage(4);
                this.mImageCollectView.SetPreviewBitmapAndCropData(this.mBitmapPreview);
                mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_DISMISS);
                return;
            case MSG_PREVIEW_SAVE_EXECUTE /*831*/:
                if (ActivityRequestPermissions.isRuntimePermissionSupported()) {
                    String[] strArr = {"android.permission.WRITE_EXTERNAL_STORAGE"};
                    ActivityRequestPermissions.Permission permission = new ActivityRequestPermissions.Permission(strArr[0], new String[]{getString(R.string.permission_dialog_title), getString(R.string.permission_dialog_title)}, new String[]{ActivityRequestPermissions.DialogParameter.setMessage2((Context) this, getString(R.string.permission_dialog_message_storage)), ActivityRequestPermissions.DialogParameter.setMessage3A((Context) this, getString(R.string.permission_dialog_message_storage), getString(R.string.permission_function_storage))});
                    if (!ActivityRequestPermissions.checkPermission(this, strArr)) {
                        ActivityRequestPermissions.requestPermission((Activity) this, permission, 4);
                        return;
                    }
                }
                savePreviewExecute();
                return;
            case MSG_PREVIEW_SAVE_FINISH /*832*/:
                mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_DISMISS);
                String GetSavePath = this.mImageCollect.GetSavePath(false);
                if (GetSavePath != null) {
                    str = String.format(getString(R.string.image_save_message), new Object[]{GetSavePath});
                } else {
                    str = getString(R.string.file_save_error_message);
                }
                MessageBox(102, -1, str, -1, -1);
                return;
            case MSG_PREVIEW_PRINT_PREVIEW_EXECUTE /*841*/:
                mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_SHOW);
                MakePrintData(true, MSG_PREVIEW_PRINT_PREVIEW_FINISH);
                return;
            case MSG_PREVIEW_PRINT_PREVIEW_FINISH /*842*/:
                startPrintPreviewActivity(this.mImageCollect.GetSavePath(true));
                this.mActivityMode = -1;
                mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_DISMISS);
                return;
            case MSG_PREVIEW_LOAD_DIALOG_SHOW /*901*/:
                LoadProgressShow();
                return;
            case MSG_PREVIEW_LOAD_DIALOG_DISMISS /*902*/:
                LoadProgressHide();
                return;
            case MSG_PREVIEW_LOAD_PHOTO /*911*/:
                mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_SHOW);
                new Thread(new Runnable() {
                    public void run() {
                        CropImageActivity.this.mImageCollect.MakePreviewImageRAW(CropImageActivity.this.mDeviceSize.width, CropImageActivity.this.mDeviceSize.height);
                        CropImageActivity.this.GetPreviewImage(0);
                        CropImageActivity.mHandler.sendEmptyMessage(CropImageActivity.MSG_PREVIEW_LOAD_FINISH);
                    }
                }).start();
                return;
            case MSG_PREVIEW_LOAD_FINISH /*912*/:
                EpLog.m69d("MSG_PREVIEW_LOAD_FINISH");
                if (this.mBitmapPreview != null) {
                    this.mImageCollectView.SetPreviewBitmapAndCropData(this.mBitmapPreview, this.mImageCollect.GetCornerPoints());
                }
                mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_DISMISS);
                return;
            default:
                return;
        }
    }

    private void savePreviewExecute() {
        SaveButtonDisable();
        mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_SHOW);
        MakePrintData(false, MSG_PREVIEW_SAVE_FINISH);
    }

    private void ImageCollectSwitchPWC(int i) {
        GetPreviewImage(i == 1 ? 2 : 3);
        this.mImageCollectView.SetPreviewBitmapAndCropData(this.mBitmapPreview);
        this.mCorrectionHistory.clear();
    }

    private void ImageCollectSwitchCROP() {
        this.mImageType = 1;
        GetPreviewImage(1);
        this.mImageCollectView.SetPreviewBitmapAndCropData(this.mBitmapPreview);
        this.mCorrectionHistory.clear();
    }

    private void AdjustmentModeSwitchALL() {
        AdjustmentModeProc(false, true, 0, 2);
    }

    private void AdjustmentModeSwitchPART() {
        AdjustmentModeProc(true, true, R.string.start_adjustment_partly_message, 3);
    }

    private void AdjustmentModeSwitchEXECUTE() {
        if (this.mImageCollectAdjustmentSwitch.getCheckedRadioButtonId() == R.id.AdjustmentModeSwitchRight) {
            AdjustmentModeProc(false, true, 0, 3);
        } else {
            AdjustmentModeProc(true, true, 0, 2);
        }
    }

    private void AdjustmentModeProc(boolean z, boolean z2, int i, int i2) {
        StackBCSCParams(z, z2);
        this.mBcscType = this.mImageType;
        this.mImageCollect.SiwtchPreviewImageBCSC(this.mBcscType);
        if (i > 0) {
            ToastMessage(getString(i));
        }
        this.mImageCollectView.SetViewMode(i2);
        this.mImageCollectView.invalidate();
    }

    private void InitBCSC() {
        InitBCSCParams();
        this.mCorrectionParamSet.Reset();
        this.mImageCollect.ResetPreviewImageBCSC();
        this.mBcscType = this.mImageType;
        this.mImageCollect.MakePreviewImageBCSC_Init(this.mBcscType, true);
        if (this.mImageCollectAdjustmentSwitch.getCheckedRadioButtonId() == R.id.AdjustmentModeSwitchRight) {
            this.mImageCollectView.SetViewMode(3);
        } else {
            this.mImageCollectView.SetViewMode(2);
        }
        GetPreviewImage(this.mImageType);
        this.mImageCollectView.SetPreviewBitmapAndCropData(this.mBitmapPreview);
    }

    private void InitBCSCParams() {
        this.mImageCollectAdjustmentBrightnessSeekBar.setMax(10);
        this.mImageCollectAdjustmentBrightnessSeekBar.setProgress(this.mBcscSeekBarBDefault);
        this.mImageCollectAdjustmentContrastSeekBar.setMax(10);
        this.mImageCollectAdjustmentContrastSeekBar.setProgress(this.mBcscSeekBarCDefault);
        this.mImageCollectAdjustmentSaturationSeekBar.setMax(10);
        this.mImageCollectAdjustmentSaturationSeekBar.setProgress(this.mBcscSeekBarSDefault);
        this.mBcscBValue = this.mBcscBDefault;
        this.mBcscCValue = this.mBcscCDefault;
        this.mBcscSValue = this.mBcscSDefault;
    }

    private void StackBCSCParams(boolean z, boolean z2) {
        if (this.mBcscBValue != this.mBcscBDefault || this.mBcscCValue != this.mBcscCDefault || this.mBcscSValue != this.mBcscSDefault) {
            CorrectionParam correctionParam = new CorrectionParam();
            boolean unused = correctionParam.mMaskType = z;
            float unused2 = correctionParam.mBcscBValue = this.mBcscBValue;
            float unused3 = correctionParam.mBcscCValue = this.mBcscCValue;
            float unused4 = correctionParam.mBcscSValue = this.mBcscSValue;
            if (!z) {
                List unused5 = correctionParam.mPointArray = this.mImageCollectView.GetBcscPointArray();
                float unused6 = correctionParam.mScale = this.mImageCollectView.GetBcscScale();
                float unused7 = correctionParam.mStrokeWidth = this.mImageCollectView.GetBcscStrokeWidth();
                Point unused8 = correctionParam.mPreviewImageSize = this.mImageCollect.GetMakedPreviewImageSize();
            }
            this.mCorrectionParamSet.AddParam(correctionParam);
            if (z2) {
                InitBCSCParams();
            }
        }
    }

    private void SeekBarTracking() {
        float progress = (((float) this.mImageCollectAdjustmentBrightnessSeekBar.getProgress()) * 0.2f) - 1.0f;
        float progress2 = ((float) this.mImageCollectAdjustmentContrastSeekBar.getProgress()) * 0.1f;
        float progress3 = (((float) this.mImageCollectAdjustmentSaturationSeekBar.getProgress()) * 0.2f) - 1.0f;
        if (progress != this.mBcscBValue || progress2 != this.mBcscCValue || progress3 != this.mBcscSValue) {
            this.mBcscBValue = progress;
            this.mBcscCValue = progress2;
            this.mBcscSValue = progress3;
            PreviewImageBCSC();
            UiCommon.setButtonEnabled(this.mButtonReset, true);
        }
    }

    private void PreviewImageBCSC() {
        if (this.mImageCollectAdjustmentSwitch.getCheckedRadioButtonId() == R.id.AdjustmentModeSwitchLeft) {
            this.mMaskType = 7;
        } else {
            this.mMaskType = 8;
        }
        this.mImageCollect.MakePreviewImageBCSC_Exec(this.mMaskType, true, this.mBcscBValue, this.mBcscCValue, this.mBcscSValue, this.mImageCollectView.GetBcscScale());
        GetPreviewImage(6);
        this.mImageCollectView.SetPreviewBitmapAndCropData(this.mBitmapPreview);
    }

    /* access modifiers changed from: private */
    public void GetPreviewImage(int i) {
        Bitmap GetPreviewImage;
        if (i == 1 || i == 2 || i == 3 || i == 4) {
            this.mImageType = i;
            SaveButtonState();
        }
        if ((i == 6 || i == 4 || i != this.mPreviewType) && (GetPreviewImage = this.mImageCollect.GetPreviewImage(i)) != null) {
            Bitmap bitmap = this.mBitmapPreview;
            if (bitmap != null) {
                bitmap.recycle();
            }
            this.mBitmapPreview = GetPreviewImage;
            this.mPreviewType = i;
        }
    }

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

    private File GetCacheFolder(boolean z) {
        if (!z) {
            return Environment.getExternalStorageDirectory();
        }
        File file = new File(getExternalCacheDir(), ICPD_FOLDER_PRINT_DATA);
        ExternalFileUtils.getInstance(this).createTempFolder(file.getPath());
        return file;
    }

    private void MakePrintData(final boolean z, final int i) {
        new Thread(new Runnable() {
            public void run() {
                CropImageActivity.this.mImageCollect.MakeCropPrintSizeImage(CropImageActivity.this.mPointPreviewCropPoint, CropImageActivity.this.mPaperSize, CropImageActivity.this.mImageType, CropImageActivity.this.mCorrectionHistory);
                if (CropImageActivity.this.mImageCollect.SaveExecute(z, CropImageActivity.this.mImageType, CropImageActivity.this.mPaperSize) && !z) {
                    Uri fromFile = Uri.fromFile(new File(CropImageActivity.this.mImageCollect.GetSavePath(true)));
                    ContentValues contentValues = new ContentValues();
                    contentValues.put("title", fromFile.getLastPathSegment());
                    contentValues.put("_display_name", fromFile.getLastPathSegment());
                    contentValues.put("mime_type", "image/jpeg");
                    contentValues.put("_data", fromFile.getPath());
                    contentValues.put("datetaken", Long.valueOf(System.currentTimeMillis()));
                    CropImageActivity.this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
                }
                CropImageActivity.mHandler.sendEmptyMessage(i);
            }
        }).start();
    }

    private void GetPaperInfo() {
        Size size = this.mPaperSize;
        size.width = 0.0d;
        size.height = 0.0d;
        this.mDocumentSizeInfo = RegistedDocumentSizeList.getInstance(this).getCurrentDocumentSize();
        int paperId = this.mDocumentSizeInfo.getPaperId();
        int scaleId = this.mDocumentSizeInfo.getScaleId();
        if (paperId > -1) {
            this.mInfoPaper = Info_paper.getInfoPaper(this, this.mDocumentSizeInfo.getPaperId());
            Info_paper info_paper = this.mInfoPaper;
            if (info_paper != null) {
                this.mPaperSize.width = (double) info_paper.getPaper_width();
                this.mPaperSize.height = (double) this.mInfoPaper.getPaper_height();
            }
        } else if (paperId < -1) {
            double width = this.mDocumentSizeInfo.getWidth();
            double height = this.mDocumentSizeInfo.getHeight();
            if (scaleId == 1) {
                Size size2 = this.mPaperSize;
                size2.width = (width / 25.4d) * 360.0d;
                size2.height = (height / 25.4d) * 360.0d;
                return;
            }
            Size size3 = this.mPaperSize;
            size3.width = width * 360.0d;
            size3.height = height * 360.0d;
        }
    }

    private String getDocumentSizeText() {
        new String();
        if (this.mDocumentSizeInfo.getPaperId() != -2) {
            return this.mDocumentSizeInfo.getDocSizeName(this);
        }
        return String.format(Locale.US, this.mDocumentSizeInfo.getScaleId() == 2 ? "%s (%.1f x %.1f in)" : "%s (%.0f x %.0f mm)", new Object[]{this.mDocumentSizeInfo.getDocSizeName(this), Float.valueOf((float) this.mDocumentSizeInfo.getWidth()), Float.valueOf((float) this.mDocumentSizeInfo.getHeight())});
    }

    private void startPrintPreviewActivity(String str) {
        releaseResource();
        if (str != null) {
            Intent intent = new Intent();
            intent.putExtra(RESULT_COLLECTED_FILE_NAME, str);
            setResult(-1, intent);
        } else {
            setResult(0);
        }
        logRecordImageImageProcessingType();
        finish();
    }

    private void logRecordImageImageProcessingType() {
        if (!this.mImageCollectSwitchMiddle.isChecked()) {
            this.mImageCollectSwitchRight.isChecked();
        }
    }

    private void palletShow() {
        if (this.mImageCollectPalletLayout.getVisibility() == 0) {
            this.mImageCollectPalletLayout.setVisibility(8);
            this.mImageCollectPalletButton.setText("▲");
            return;
        }
        this.mImageCollectPalletLayout.setVisibility(0);
        this.mImageCollectPalletButton.setText("▼");
    }

    private void LoadProgressShow() {
        this.mModelDialog.doShow(DIALOG_PROGRESS);
    }

    private void LoadProgressHide() {
        this.mModelDialog.doDismiss(DIALOG_PROGRESS);
    }

    private void MessageBox(int i, int i2, int i3, int i4) {
        MessageBox(i, i2, getString(i3), i4, -1);
    }

    private void MessageBox(int i, int i2, int i3, int i4, int i5) {
        MessageBox(i, i2, getString(i3), i4, i5);
    }

    private void MessageBox(int i, int i2, String str, final int i3, final int i4) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setCancelable(false);
        if (i2 != -1) {
            builder.setTitle(i2);
        }
        if (str != null) {
            builder.setMessage(str);
        }
        C086515 r4 = null;
        C086414 r5 = i3 != -1 ? new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                CropImageActivity.mHandler.sendEmptyMessage(i3);
            }
        } : null;
        if (i4 != -1) {
            r4 = new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    CropImageActivity.mHandler.sendEmptyMessage(i4);
                }
            };
        }
        if (i == 101) {
            builder.setPositiveButton(R.string.str_yes, r5);
            builder.setNegativeButton(R.string.str_no, r4);
        } else if (i == 102) {
            builder.setPositiveButton(R.string.str_ok, r5);
        } else if (i == 103) {
            builder.setNegativeButton(R.string.str_cancel, r4);
        }
        this.mMessageDialog = builder.create();
        this.mMessageDialog.show();
    }

    private void releaseResource() {
        ImageCollectView imageCollectView = this.mImageCollectView;
        if (imageCollectView != null) {
            imageCollectView.ReleaseResource();
            this.mImageCollectView = null;
        }
        ImageCollect imageCollect = this.mImageCollect;
        if (imageCollect != null) {
            imageCollect.ReleaseImageCollect();
            this.mImageCollect = null;
        }
        Bitmap bitmap = this.mBitmapPreview;
        if (bitmap != null) {
            bitmap.recycle();
            this.mBitmapPreview = null;
        }
        System.gc();
    }

    private void SaveButtonState() {
        UiCommon.setButtonEnabled(this.mButtonSave, this.mSaveApprovalTable[this.mImageType]);
    }

    private void SaveButtonDisable() {
        boolean[] zArr = this.mSaveApprovalTable;
        int i = this.mImageType;
        zArr[i] = false;
        UiCommon.setButtonEnabled(this.mButtonSave, zArr[i]);
    }

    private void activityModeChange(int i) {
        if (i == 0) {
            this.mImageCollectPreviewLayout.setVisibility(0);
            this.mImageCollectPaperSizeInfo.setVisibility(0);
            this.mImageCollectPalletButton.setVisibility(4);
            this.mImageCollectSwitchLayout.setVisibility(8);
            this.mImageCollectPalletLayout.setVisibility(8);
            setTitle(R.string.crop_image_title);
            this.mToolbarCropImage.setVisibility(0);
            this.mToolbarEnhanceText.setVisibility(8);
            this.mToolbarColorAdjustment.setVisibility(8);
            this.mButtonDocSize = (Button) this.mToolbarCropImage.findViewById(R.id.document_size_button);
            this.mButtonDocSize.setOnClickListener(this);
            this.mButtonExecute = (Button) this.mToolbarCropImage.findViewById(R.id.execute_button);
            this.mButtonExecute.setText(R.string.execute_button);
            this.mButtonExecute.setOnClickListener(this);
            this.mImageCollectView.SetViewMode(0);
            boolean[] zArr = this.mSaveApprovalTable;
            zArr[0] = false;
            zArr[1] = true;
            zArr[2] = true;
            zArr[3] = true;
            zArr[4] = true;
        } else if (i == 1) {
            this.mImageCollectPreviewLayout.setVisibility(0);
            this.mImageCollectPaperSizeInfo.setVisibility(4);
            this.mImageCollectPalletButton.setVisibility(4);
            this.mImageCollectSwitchLayout.setVisibility(0);
            this.mImageCollectPalletLayout.setVisibility(8);
            setTitle(R.string.enhance_text_title);
            this.mToolbarCropImage.setVisibility(8);
            this.mToolbarEnhanceText.setVisibility(0);
            this.mToolbarColorAdjustment.setVisibility(8);
            this.mButtonSave = (Button) this.mToolbarEnhanceText.findViewById(R.id.save_button);
            this.mButtonSave.setOnClickListener(this);
            this.mButtonColorAdjustment = (Button) this.mToolbarEnhanceText.findViewById(R.id.color_adjustment_button);
            this.mButtonColorAdjustment.setOnClickListener(this);
            this.mButtonExecute = (Button) this.mToolbarEnhanceText.findViewById(R.id.execute_button);
            this.mButtonExecute.setText(R.string.print_preview_button);
            this.mButtonExecute.setOnClickListener(this);
            this.mImageCollectView.SetViewMode(1);
        } else if (i == 2) {
            this.mImageCollectPreviewLayout.setVisibility(0);
            this.mImageCollectPaperSizeInfo.setVisibility(4);
            this.mImageCollectPalletButton.setVisibility(0);
            this.mImageCollectPalletButton.setText("▼");
            this.mImageCollectSwitchLayout.setVisibility(8);
            this.mImageCollectPalletLayout.setVisibility(0);
            setTitle(R.string.color_adjustment_title);
            this.mToolbarCropImage.setVisibility(8);
            this.mToolbarEnhanceText.setVisibility(8);
            this.mToolbarColorAdjustment.setVisibility(0);
            this.mButtonReset = (Button) this.mToolbarColorAdjustment.findViewById(R.id.reset_button);
            this.mButtonReset.setOnClickListener(this);
            UiCommon.setButtonEnabled(this.mButtonReset, false);
            this.mButtonExecute = (Button) this.mToolbarColorAdjustment.findViewById(R.id.execute_button);
            this.mButtonExecute.setText(R.string.execute_button);
            this.mButtonExecute.setOnClickListener(this);
            this.mImageCollectAdjustmentSwitchId = R.id.AdjustmentModeSwitchLeft;
            this.mImageCollectAdjustmentSwitch.check(this.mImageCollectAdjustmentSwitchId);
            AdjustmentModeSwitchALL();
            this.mImageCollectView.SetViewMode(2);
        }
        this.mActivityMode = i;
    }

    private void ToastMessage(CharSequence charSequence) {
        CancelToast();
        this.mDaemonView.SetHandler(mHandler);
        this.mCustomToast = new CustomToast();
        this.mCustomToast.makeText(this, charSequence, 0, (this.mImageCollectPreviewLayout.getHeight() - this.mImageCollectLayout.getHeight()) / 2);
        this.mCustomToast.show();
    }

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

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

    @SuppressLint({"ShowToast"})
    /* renamed from: com.epson.cameracopy.ui.CropImageActivity$CustomToast */
    private class CustomToast {
        private boolean mBreak;
        private Toast mToast;

        private CustomToast() {
            this.mToast = null;
            this.mBreak = false;
        }

        public void makeText(Context context, CharSequence charSequence, int i, int i2) {
            this.mBreak = false;
            this.mToast = Toast.makeText(context, charSequence, 1);
            this.mToast.setGravity(17, i, i2);
            View view = this.mToast.getView();
            view.setBackgroundColor(-12303292);
            if (view instanceof ViewGroup) {
                ViewGroup viewGroup = (ViewGroup) view;
                for (int i3 = 0; i3 < viewGroup.getChildCount(); i3++) {
                    View childAt = viewGroup.getChildAt(i3);
                    if (childAt instanceof TextView) {
                        ((TextView) childAt).setTextColor(-1);
                    }
                }
            }
            view.setOnTouchListener(new View.OnTouchListener() {
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    if (motionEvent.getAction() != 0) {
                        return false;
                    }
                    CustomToast.this.cancel();
                    return false;
                }
            });
        }

        public void show() {
            EpLog.m69d("show :");
            if (!this.mBreak) {
                EpLog.m69d("run:show");
                this.mToast.show();
                return;
            }
            EpLog.m69d("run:break");
        }

        public void cancel() {
            EpLog.m69d("cancel");
            this.mBreak = true;
            this.mToast.cancel();
        }
    }

    /* renamed from: com.epson.cameracopy.ui.CropImageActivity$DaemonView */
    private class DaemonView extends View {
        private Handler mHandlerAvtivity = null;

        public DaemonView(Context context) {
            super(context);
            Init();
        }

        public DaemonView(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            Init();
        }

        public DaemonView(Context context, AttributeSet attributeSet, int i) {
            super(context, attributeSet, i);
            Init();
        }

        public void SetHandler(Handler handler) {
            this.mHandlerAvtivity = handler;
            setVisibility(0);
        }

        private void Init() {
            setVisibility(4);
            setBackgroundColor(Color.argb(0, 0, 0, 0));
            setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
        }

        public boolean onTouchEvent(MotionEvent motionEvent) {
            Handler handler;
            if ((motionEvent.getAction() & 255) != 0 || (handler = this.mHandlerAvtivity) == null) {
                return false;
            }
            handler.sendEmptyMessage(CropImageActivity.MSG_PREVIEW_TOUCH_EVENT_ACTION_DOWN);
            this.mHandlerAvtivity = null;
            setVisibility(4);
            return false;
        }
    }

    /* renamed from: com.epson.cameracopy.ui.CropImageActivity$CorrectionParamSet */
    public class CorrectionParamSet {
        private int mAfterPWCtype = 0;
        private int mImageType = 0;
        private List<CorrectionParam> mParamArray = new ArrayList();

        public CorrectionParamSet() {
        }

        public void SetImageType(int i) {
            this.mImageType = i;
        }

        public int GetImageType() {
            return this.mImageType;
        }

        public void AddParam(CorrectionParam correctionParam) {
            this.mParamArray.add(correctionParam);
        }

        public CorrectionParam GetParam(int i) {
            return this.mParamArray.get(i);
        }

        public void SetAfterPWC(int i) {
            this.mAfterPWCtype = i;
        }

        public int GetAfterPWC() {
            return this.mAfterPWCtype;
        }

        public void Reset() {
            this.mParamArray.clear();
        }

        public int Size() {
            return this.mParamArray.size();
        }

        public CorrectionParamSet Clone() {
            CorrectionParamSet correctionParamSet = new CorrectionParamSet();
            ArrayList arrayList = new ArrayList();
            for (CorrectionParam Clone : this.mParamArray) {
                arrayList.add(Clone.Clone());
            }
            correctionParamSet.mParamArray = arrayList;
            correctionParamSet.mImageType = this.mImageType;
            correctionParamSet.mAfterPWCtype = this.mAfterPWCtype;
            return correctionParamSet;
        }
    }

    /* renamed from: com.epson.cameracopy.ui.CropImageActivity$CorrectionParam */
    public class CorrectionParam {
        /* access modifiers changed from: private */
        public float mBcscBValue;
        /* access modifiers changed from: private */
        public float mBcscCValue;
        /* access modifiers changed from: private */
        public float mBcscSValue;
        /* access modifiers changed from: private */
        public boolean mMaskType;
        /* access modifiers changed from: private */
        public List<List<PointF>> mPointArray;
        /* access modifiers changed from: private */
        public Point mPreviewImageSize = new Point(0, 0);
        /* access modifiers changed from: private */
        public float mScale;
        /* access modifiers changed from: private */
        public float mStrokeWidth;

        public CorrectionParam() {
        }

        public boolean GetMaskType() {
            return this.mMaskType;
        }

        public float GetBcscBValue() {
            return this.mBcscBValue;
        }

        public float GetBcscCValue() {
            return this.mBcscCValue;
        }

        public float GetBcscSValue() {
            return this.mBcscSValue;
        }

        public Point GetPreviewImageSize() {
            return this.mPreviewImageSize;
        }

        public List<List<PointF>> GetPointArray() {
            return this.mPointArray;
        }

        public float GetScale() {
            return this.mScale;
        }

        public float GetStrokeWidth() {
            return this.mStrokeWidth;
        }

        public CorrectionParam Clone() {
            CorrectionParam correctionParam = new CorrectionParam();
            correctionParam.mMaskType = this.mMaskType;
            correctionParam.mBcscBValue = this.mBcscBValue;
            correctionParam.mBcscCValue = this.mBcscCValue;
            correctionParam.mBcscSValue = this.mBcscSValue;
            correctionParam.mPreviewImageSize = new Point(this.mPreviewImageSize.x, this.mPreviewImageSize.y);
            correctionParam.mPointArray = new ArrayList();
            List<List<PointF>> list = this.mPointArray;
            if (list != null) {
                for (List<PointF> it : list) {
                    ArrayList arrayList = new ArrayList();
                    for (PointF add : it) {
                        arrayList.add(add);
                    }
                    correctionParam.mPointArray.add(arrayList);
                }
            }
            correctionParam.mScale = this.mScale;
            correctionParam.mStrokeWidth = this.mStrokeWidth;
            return correctionParam;
        }
    }

    /* renamed from: com.epson.cameracopy.ui.CropImageActivity$EPxLog */
    static class EPxLog {
        EPxLog() {
        }

        /* renamed from: d */
        public static final void m58d(String str, String str2) {
            Log.d(str, str2);
        }

        /* renamed from: e */
        public static final void m59e(String str, String str2) {
            if (Debug.isDebuggerConnected()) {
                Log.e(str, str2);
            }
        }

        /* renamed from: i */
        public static final void m60i(String str, String str2) {
            if (Debug.isDebuggerConnected()) {
                Log.i(str, str2);
            }
        }

        /* renamed from: v */
        public static final void m61v(String str, String str2) {
            if (Debug.isDebuggerConnected()) {
                Log.v(str, str2);
            }
        }

        /* renamed from: w */
        public static final void m62w(String str, String str2) {
            if (Debug.isDebuggerConnected()) {
                Log.w(str, str2);
            }
        }
    }
}
