package com.epson.cameracopy.ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
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.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
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 androidx.fragment.app.FragmentActivity;

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 org.opencv.core.Size;

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 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 epson.print.R;

/* 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;
    private static CropImageActivity mCropImageActivity;
    private 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;
    private List<CorrectionParamSet> mCorrectionHistory = null;
    private 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;
    private int mDebugMode = 0;
    private int mDebugResolutionThreshold = 2;
    private int mDebugSmallPreviewRate = 2;
    Size mDeviceSize = null;
    DocumentSizeInfo mDocumentSizeInfo = null;
    private GestureDetector mGestureDetector = null;
    private 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;
    private ImageCollectView mImageCollectView = null;
    private int mImageType = 2;
    Info_paper mInfoPaper = null;
    private int mMaskType;
    private AlertDialog mMessageDialog = null;
    private DisplayMetrics mMetrics = null;
    private DialogProgressViewModel mModelDialog;
    private double mPaperHeight = 0.0d;
    private int mPaperId = -999;
    Size mPaperSize = null;
    private double mPaperWidth = 0.0d;
    private 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.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(R.layout.activity_crop_image);
        mModelDialog = (DialogProgressViewModel) ViewModelProviders.m2of((FragmentActivity) this).get(DialogProgressViewModel.class);
        mModelDialog.getDialogJob().observe(this, new Observer() {
            public final void onChanged(Object obj) {
                CropImageActivity.lambda$onCreate$0(CropImageActivity.this, (Deque) obj);
            }
        });
        setActionBar(R.string.crop_image_title, true);
        mActivity = new WeakReference<>(this);
        mCropImageActivity = (CropImageActivity) mActivity.get();
        mModelDialog.doShow(DIALOG_PROGRESS);
        mPaperSize = new Size(0.0d, 0.0d);
        GetPaperInfo();
        mDaemonView = new DaemonView(this);
        mCropImageFrameLayout = (FrameLayout) findViewById(R.id.crop_image_frame_layout);
        mCropImageFrameLayout.addView(mDaemonView);
        mImageCollectLayout = (RelativeLayout) findViewById(R.id.ImageCollectLayout);
        mImageCollectPreviewLayout = (LinearLayout) findViewById(R.id.ImageCollectPreviewLayout);
        mImageCollectView = (ImageCollectView) mImageCollectPreviewLayout.findViewById(R.id.ImageCollectView);
        mImageCollectView.SetHandler(mHandler);
        mImageCollectPaperSizeInfo = (TextView) mImageCollectPreviewLayout.findViewById(R.id.ImageCollectPaperSizeInfo);
        mImageCollectPaperSizeInfo.setSingleLine(true);
        mImageCollectPaperSizeInfo.setEllipsize(TextUtils.TruncateAt.END);
        mImageCollectPaperSizeInfo.setText(getDocumentSizeText());
        mImageCollectPalletButton = (Button) mImageCollectPreviewLayout.findViewById(R.id.ImageCollectPalletButton);
        mImageCollectPalletButton.setOnClickListener(this);
        mImageCollectPalletButton.setVisibility(4);
        mImageCollectSwitchLayout = (LinearLayout) findViewById(R.id.ImageCollectSwitchLayout);
        mImageCollectSwitch = (RadioGroup) findViewById(R.id.ImageCollectSwitch);
        mImageCollectSwitchLeft = (RadioButton) findViewById(R.id.ImageCollectSwitchLeft);
        mImageCollectSwitchLeft.setOnClickListener(this);
        mImageCollectSwitchMiddle = (RadioButton) findViewById(R.id.ImageCollectSwitchMiddle);
        mImageCollectSwitchMiddle.setOnClickListener(this);
        mImageCollectSwitchRight = (RadioButton) findViewById(R.id.ImageCollectSwitchRight);
        mImageCollectSwitchRight.setOnClickListener(this);
        mImageCollectPalletLayout = (LinearLayout) findViewById(R.id.ImageCollectPalletLayout);
        mImageCollectAdjustmentBrightness = (LinearLayout) findViewById(R.id.ImageCollectAdjustmentBrightness);
        mImageCollectAdjustmentBrightnessTitle = (TextView) mImageCollectAdjustmentBrightness.findViewById(R.id.AdjustmentBarTitle);
        mImageCollectAdjustmentBrightnessTitle.setText(R.string.brightness);
        mImageCollectAdjustmentBrightnessSeekBar = (SeekBar) mImageCollectAdjustmentBrightness.findViewById(R.id.AdjustmentBarSeekBar);
        mImageCollectAdjustmentBrightnessSeekBar.setOnSeekBarChangeListener(this);
        mImageCollectAdjustmentContrast = (LinearLayout) findViewById(R.id.ImageCollectAdjustmentContrast);
        mImageCollectAdjustmentContrastTitle = (TextView) mImageCollectAdjustmentContrast.findViewById(R.id.AdjustmentBarTitle);
        mImageCollectAdjustmentContrastTitle.setText(R.string.contrast);
        mImageCollectAdjustmentContrastSeekBar = (SeekBar) mImageCollectAdjustmentContrast.findViewById(R.id.AdjustmentBarSeekBar);
        mImageCollectAdjustmentContrastSeekBar.setOnSeekBarChangeListener(this);
        mImageCollectAdjustmentSaturation = (LinearLayout) findViewById(R.id.ImageCollectAdjustmentSaturation);
        mImageCollectAdjustmentSaturationTitle = (TextView) mImageCollectAdjustmentSaturation.findViewById(R.id.AdjustmentBarTitle);
        mImageCollectAdjustmentSaturationTitle.setText(R.string.saturation);
        mImageCollectAdjustmentSaturationSeekBar = (SeekBar) mImageCollectAdjustmentSaturation.findViewById(R.id.AdjustmentBarSeekBar);
        mImageCollectAdjustmentSaturationSeekBar.setOnSeekBarChangeListener(this);
        mImageCollectAdjustmentSwitch = (RadioGroup) findViewById(R.id.AdjustmentModeSwitch);
        mImageCollectAdjustmentSwitchLeft = (RadioButton) findViewById(R.id.AdjustmentModeSwitchLeft);
        mImageCollectAdjustmentSwitchLeft.setOnClickListener(this);
        mImageCollectAdjustmentSwitchRight = (RadioButton) findViewById(R.id.AdjustmentModeSwitchRight);
        mImageCollectAdjustmentSwitchRight.setOnClickListener(this);
        mCropImageHeader = findViewById(R.id.navigation_bar);
        mToolBartLayout = (LinearLayout) findViewById(R.id.tool_bar);
        mToolbarCropImage = (LinearLayout) mToolBartLayout.findViewById(R.id.ImageCollectToolbarCropImage);
        mToolbarEnhanceText = (LinearLayout) mToolBartLayout.findViewById(R.id.ImageCollectToolbarEnhanceText);
        mToolbarColorAdjustment = (LinearLayout) mToolBartLayout.findViewById(R.id.ImageCollectToolbarColorAdjustment);
        mCropImageHeader.setOnTouchListener(this);
        mCropImageHeader.setOnClickListener(this);
        mToolbarCropImage.setOnTouchListener(this);
        mToolbarCropImage.setOnClickListener(this);
        mToolbarEnhanceText.setOnTouchListener(this);
        mToolbarEnhanceText.setOnClickListener(this);
        mBcscSeekBarBDefault = 5;
        mBcscSeekBarCDefault = 0;
        mBcscSeekBarSDefault = 5;
        mBcscBDefault = 0.0f;
        mBcscCDefault = 0.0f;
        mBcscSDefault = 0.0f;
        InitBCSCParams();
        mSaveApprovalTable = new boolean[5];
        activityModeChange(0);
        String stringExtra = getIntent().getStringExtra(IMAGE_FILE_NAME);
        mMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(mMetrics);
        mDeviceSize = new Size(mMetrics.widthPixels, mMetrics.heightPixels);
        mCorrectionParamSet = new CorrectionParamSet();
        mCorrectionHistory = new ArrayList();
        mUserFolder = GetCacheFolder(false);
        mCacheFolder = GetCacheFolder(true);
        CameraPreviewControl instance = CameraPreviewControl.getInstance(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())) {
            mCurrentPaperId = 1;
        }
        mCurrentPaperSize = new Size(3048.0d, 4321.0d);
        Info_paper infoPaper = Info_paper.getInfoPaper(this, mCurrentPaperId);
        if (infoPaper != null) {
            mCurrentPaperSize.width = infoPaper.getPaper_width();
            mCurrentPaperSize.height = infoPaper.getPaper_height();
        }
        mImageCollect = new ImageCollect(stringExtra, mMetrics.density, mCurrentPaperSize);
        mImageCollect.SetPath(mCacheFolder, mUserFolder, instance.getSaveDirecotry());
        mPreviewType = -1;
        mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_PHOTO);
        mGestureDetector = new GestureDetector(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.d("dismissDialog");
                if (cropImageActivity.mCropImageMessageShow) {
                    EPLog.d("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 (mCustomToast != null) {
            EPLog.d(" Toast Cancel");
            mCustomToast.cancel();
            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 = mActivityMode;
        if (i == 0) {
            mActivityMode = -1;
            mImageCollectView.MessageOff();
            CancelToast();
            releaseResource();
            finish();
        } else if (i == 1) {
            activityModeChange(0);
            PointF[] GetCornerPoints = mImageCollect.GetCornerPoints();
            GetPreviewImage(0);
            mImageCollectView.SetPreviewBitmapAndCropData(mBitmapPreview, GetCornerPoints);
        } else if (i == 2) {
            activityModeChange(1);
            GetPreviewImage(mImageType);
            mImageCollectView.SetPreviewBitmapAndCropData(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();
            mImageCollectPaperSizeInfo.setText(getDocumentSizeText());
        }
        if (i == 4 && i2 == -1) {
            savePreviewExecute();
        }
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.AdjustmentModeSwitchLeft /*2131230725*/:
                if (mImageCollectAdjustmentSwitchId != R.id.AdjustmentModeSwitchLeft) {
                    mImageCollectAdjustmentSwitchId = R.id.AdjustmentModeSwitchLeft;
                    AdjustmentModeSwitchALL();
                    return;
                }
                return;
            case R.id.AdjustmentModeSwitchRight /*2131230726*/:
                if (mImageCollectAdjustmentSwitchId != R.id.AdjustmentModeSwitchRight) {
                    mImageCollectAdjustmentSwitchId = R.id.AdjustmentModeSwitchRight;
                    AdjustmentModeSwitchPART();
                    return;
                }
                return;
            case R.id.ImageCollectPalletButton /*2131230737*/:
                palletShow();
                return;
            case R.id.ImageCollectSwitchLeft /*2131230744*/:
                if (mImageCollectSwitchId != R.id.ImageCollectSwitchLeft) {
                    mImageCollectSwitchId = R.id.ImageCollectSwitchLeft;
                    ImageCollectSwitchPWC(1);
                    return;
                }
                return;
            case R.id.ImageCollectSwitchMiddle /*2131230745*/:
                if (mImageCollectSwitchId != R.id.ImageCollectSwitchMiddle) {
                    mImageCollectSwitchId = R.id.ImageCollectSwitchMiddle;
                    ImageCollectSwitchPWC(2);
                    return;
                }
                return;
            case R.id.ImageCollectSwitchRight /*2131230746*/:
                if (mImageCollectSwitchId != R.id.ImageCollectSwitchRight) {
                    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*/:
                mImageCollectView.MessageOff();
                setDocumentSize();
                return;
            case R.id.execute_button /*2131231032*/:
                int i = mActivityMode;
                if (i == 0) {
                    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 (!(mBcscBValue == mBcscBDefault && mBcscCValue == mBcscCDefault && mBcscSValue == mBcscSDefault)) {
                        z = true;
                    }
                    if (mCorrectionParamSet.Size() > 0) {
                        z = true;
                    }
                    if (z) {
                        MessageBox(101, -1, R.string.finish_color_adjustment_message, MSG_SDIC_BCSC_FIX_PROC, MSG_SDIC_BCSC_FIX_CANCEL);
                        return;
                    }
                    activityModeChange(1);
                    GetPreviewImage(mImageType);
                    mImageCollectView.SetPreviewBitmapAndCropData(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) {
        mDebugID = view.getId();
        mGestureDetector.onTouchEvent(motionEvent);
        return false;
    }

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

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

    private void executeMessage(Message message) {
        String str;
        switch (message.what) {
            case 301:
                ImageCollectView imageCollectView = mImageCollectView;
                imageCollectView.SetMaskEdge(mImageCollect.DetectEdge(imageCollectView.GetMaskImage()));
                float progress = (float) mImageCollectAdjustmentContrastSeekBar.getProgress();
                float progress2 = (float) mImageCollectAdjustmentSaturationSeekBar.getProgress();
                UiCommon.setButtonEnabled(mButtonReset, true);
                if (((float) mImageCollectAdjustmentBrightnessSeekBar.getProgress()) != ((float) mBcscSeekBarBDefault) || progress != ((float) mBcscSeekBarCDefault) || progress2 != ((float) 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"}, mDebugResolutionThreshold, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch (i) {
                            case 0:
                                CropImageActivity.mImageCollect.SetResolutionThreshold(360.0d);
                                break;
                            case 1:
                                CropImageActivity.mImageCollect.SetResolutionThreshold(300.0d);
                                break;
                            case 2:
                                CropImageActivity.mImageCollect.SetResolutionThreshold(240.0d);
                                break;
                            case 3:
                                CropImageActivity.mImageCollect.SetResolutionThreshold(180.0d);
                                break;
                            case 4:
                                CropImageActivity.mImageCollect.SetResolutionThreshold(120.0d);
                                break;
                        }
                        int unused = CropImageActivity.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"}, mDebugSmallPreviewRate, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch (i) {
                            case 0:
                                CropImageActivity.mImageCollect.SetSmallPreviewRate(1.0f);
                                break;
                            case 1:
                                CropImageActivity.mImageCollect.SetSmallPreviewRate(1.5f);
                                break;
                            case 2:
                                CropImageActivity.mImageCollect.SetSmallPreviewRate(2.0f);
                                break;
                            case 3:
                                CropImageActivity.mImageCollect.SetSmallPreviewRate(2.5f);
                                break;
                            case 4:
                                CropImageActivity.mImageCollect.SetSmallPreviewRate(3.0f);
                                break;
                            case 5:
                                CropImageActivity.mImageCollect.SetSmallPreviewRate(3.5f);
                                break;
                            case 6:
                                CropImageActivity.mImageCollect.SetSmallPreviewRate(4.0f);
                                break;
                        }
                        int unused = CropImageActivity.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.mDocumentSizeInfo.getPaperId();
                        double width = CropImageActivity.mDocumentSizeInfo.getWidth();
                        double height = CropImageActivity.mDocumentSizeInfo.getHeight();
                        PointF[] GetCropPoint = CropImageActivity.mImageCollectView.GetCropPoint();
                        boolean z = false;
                        boolean z2 = true;
                        if (!(CropImageActivity.mPointPreviewCropPoint == null || GetCropPoint == null || (CropImageActivity.mPointPreviewCropPoint[0].x == GetCropPoint[0].x && CropImageActivity.mPointPreviewCropPoint[0].y == GetCropPoint[0].y && CropImageActivity.mPointPreviewCropPoint[1].x == GetCropPoint[1].x && CropImageActivity.mPointPreviewCropPoint[1].y == GetCropPoint[1].y && CropImageActivity.mPointPreviewCropPoint[2].x == GetCropPoint[2].x && CropImageActivity.mPointPreviewCropPoint[2].y == GetCropPoint[2].y && CropImageActivity.mPointPreviewCropPoint[3].x == GetCropPoint[3].x && CropImageActivity.mPointPreviewCropPoint[3].y == GetCropPoint[3].y))) {
                            z = true;
                        }
                        if (z || (CropImageActivity.mPaperId == -1 || paperId == -1 ? CropImageActivity.mPaperId == paperId : CropImageActivity.mPaperWidth == width && CropImageActivity.mPaperHeight == height)) {
                            z2 = z;
                        }
                        int unused = CropImageActivity.mPaperId = paperId;
                        double unused2 = CropImageActivity.mPaperWidth = width;
                        double unused3 = CropImageActivity.mPaperHeight = height;
                        if (z2) {
                            PointF[] unused4 = CropImageActivity.mPointPreviewCropPoint = GetCropPoint;
                            CropImageActivity.mImageCollect.MakePreviewImageCROP(CropImageActivity.mPointPreviewCropPoint, CropImageActivity.mPaperSize, CropImageActivity.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.mImageCollect.MakePreviewImagePWC(-1);
                        CropImageActivity.mHandler.sendEmptyMessage(CropImageActivity.MSG_SDIC_PWC_FINISH);
                    }
                }).start();
                return;
            case MSG_SDIC_PWC_FINISH /*812*/:
                mImageCollectSwitchId = R.id.ImageCollectSwitchLeft;
                mImageCollectSwitch.check(mImageCollectSwitchId);
                mImageType = 2;
                activityModeChange(1);
                ImageCollectSwitchPWC(1);
                mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_DISMISS);
                return;
            case MSG_SDIC_BCSC_RESET /*823*/:
                InitBCSC();
                UiCommon.setButtonEnabled(mButtonReset, false);
                return;
            case MSG_SDIC_BCSC_FIX_PROC /*824*/:
                AdjustmentModeSwitchEXECUTE();
                mSaveApprovalTable[4] = true;
                mHandler.sendEmptyMessage(MSG_PREVIEW_LOAD_DIALOG_SHOW);
                mCorrectionParamSet.SetImageType(mImageType);
                mCorrectionHistory.add(mCorrectionParamSet.Clone());
                new Thread(new Runnable() {
                    public void run() {
                        CropImageActivity.mImageCollect.MakePreviewBCSC(CropImageActivity.mCorrectionParamSet);
                        CropImageActivity.mHandler.sendEmptyMessage(CropImageActivity.MSG_SDIC_BCSC_FIX_QUIT);
                    }
                }).start();
                return;
            case MSG_SDIC_BCSC_FIX_QUIT /*826*/:
                activityModeChange(1);
                GetPreviewImage(4);
                mImageCollectView.SetPreviewBitmapAndCropData(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 = 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(mImageCollect.GetSavePath(true));
                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.mImageCollect.MakePreviewImageRAW(CropImageActivity.mDeviceSize.width, CropImageActivity.mDeviceSize.height);
                        CropImageActivity.this.GetPreviewImage(0);
                        CropImageActivity.mHandler.sendEmptyMessage(CropImageActivity.MSG_PREVIEW_LOAD_FINISH);
                    }
                }).start();
                return;
            case MSG_PREVIEW_LOAD_FINISH /*912*/:
                EPLog.d("MSG_PREVIEW_LOAD_FINISH");
                if (mBitmapPreview != null) {
                    mImageCollectView.SetPreviewBitmapAndCropData(mBitmapPreview, 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);
        mImageCollectView.SetPreviewBitmapAndCropData(mBitmapPreview);
        mCorrectionHistory.clear();
    }

    private void ImageCollectSwitchCROP() {
        mImageType = 1;
        GetPreviewImage(1);
        mImageCollectView.SetPreviewBitmapAndCropData(mBitmapPreview);
        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 (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);
        mBcscType = mImageType;
        mImageCollect.SiwtchPreviewImageBCSC(mBcscType);
        if (i > 0) {
            ToastMessage(getString(i));
        }
        mImageCollectView.SetViewMode(i2);
        mImageCollectView.invalidate();
    }

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

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

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

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

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

    private void GetPreviewImage(int i) {
        Bitmap GetPreviewImage;
        if (i == 1 || i == 2 || i == 3 || i == 4) {
            mImageType = i;
            SaveButtonState();
        }
        if ((i == 6 || i == 4 || i != mPreviewType) && (GetPreviewImage = mImageCollect.GetPreviewImage(i)) != null) {
            Bitmap bitmap = mBitmapPreview;
            if (bitmap != null) {
                bitmap.recycle();
            }
            mBitmapPreview = GetPreviewImage;
            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.mImageCollect.MakeCropPrintSizeImage(CropImageActivity.mPointPreviewCropPoint, CropImageActivity.mPaperSize, CropImageActivity.mImageType, CropImageActivity.mCorrectionHistory);
                if (CropImageActivity.mImageCollect.SaveExecute(z, CropImageActivity.mImageType, CropImageActivity.mPaperSize) && !z) {
                    Uri fromFile = Uri.fromFile(new File(CropImageActivity.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 = mPaperSize;
        size.width = 0.0d;
        size.height = 0.0d;
        mDocumentSizeInfo = RegistedDocumentSizeList.getInstance(this).getCurrentDocumentSize();
        int paperId = mDocumentSizeInfo.getPaperId();
        int scaleId = mDocumentSizeInfo.getScaleId();
        if (paperId > -1) {
            mInfoPaper = Info_paper.getInfoPaper(this, mDocumentSizeInfo.getPaperId());
            Info_paper info_paper = mInfoPaper;
            if (info_paper != null) {
                mPaperSize.width = info_paper.getPaper_width();
                mPaperSize.height = mInfoPaper.getPaper_height();
            }
        } else if (paperId < -1) {
            double width = mDocumentSizeInfo.getWidth();
            double height = mDocumentSizeInfo.getHeight();
            if (scaleId == 1) {
                Size size2 = mPaperSize;
                size2.width = (width / 25.4d) * 360.0d;
                size2.height = (height / 25.4d) * 360.0d;
                return;
            }
            Size size3 = mPaperSize;
            size3.width = width * 360.0d;
            size3.height = height * 360.0d;
        }
    }

    private String getDocumentSizeText() {
        new String();
        if (mDocumentSizeInfo.getPaperId() != -2) {
            return mDocumentSizeInfo.getDocSizeName(this);
        }
        return String.format(Locale.US, mDocumentSizeInfo.getScaleId() == 2 ? "%s (%.1f x %.1f in)" : "%s (%.0f x %.0f mm)", new Object[]{mDocumentSizeInfo.getDocSizeName(this), Float.valueOf((float) mDocumentSizeInfo.getWidth()), Float.valueOf((float) 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 (!mImageCollectSwitchMiddle.isChecked()) {
            mImageCollectSwitchRight.isChecked();
        }
    }

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

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

    private void LoadProgressHide() {
        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);
        }
        mMessageDialog = builder.create();
        mMessageDialog.show();
    }

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

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

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

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

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

    private void showDialog(String str) {
        mProgressDialog = DialogProgress.newInstance(str, 0, getString(R.string.processing_image_message));
        mProgressDialog.setCancelable(false);
        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() {
            mToast = null;
            mBreak = false;
        }

        public void makeText(Context context, CharSequence charSequence, int i, int i2) {
            mBreak = false;
            mToast = Toast.makeText(context, charSequence, 1);
            mToast.setGravity(17, i, i2);
            View view = 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.d("show :");
            if (!mBreak) {
                EPLog.d("run:show");
                mToast.show();
                return;
            }
            EPLog.d("run:break");
        }

        public void cancel() {
            EPLog.d("cancel");
            mBreak = true;
            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) {
            mHandlerAvtivity = handler;
            setVisibility(View.VISIBLE);
        }

        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 = mHandlerAvtivity) == null) {
                return false;
            }
            handler.sendEmptyMessage(CropImageActivity.MSG_PREVIEW_TOUCH_EVENT_ACTION_DOWN);
            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) {
            mImageType = i;
        }

        public int GetImageType() {
            return mImageType;
        }

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

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

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

        public int GetAfterPWC() {
            return mAfterPWCtype;
        }

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

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

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

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

        public CorrectionParam() {
        }

        public boolean GetMaskType() {
            return mMaskType;
        }

        public float GetBcscBValue() {
            return mBcscBValue;
        }

        public float GetBcscCValue() {
            return mBcscCValue;
        }

        public float GetBcscSValue() {
            return mBcscSValue;
        }

        public Point GetPreviewImageSize() {
            return mPreviewImageSize;
        }

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

        public float GetScale() {
            return mScale;
        }

        public float GetStrokeWidth() {
            return mStrokeWidth;
        }

        public CorrectionParam Clone() {
            CorrectionParam correctionParam = new CorrectionParam();
            correctionParam.mMaskType = mMaskType;
            correctionParam.mBcscBValue = mBcscBValue;
            correctionParam.mBcscCValue = mBcscCValue;
            correctionParam.mBcscSValue = mBcscSValue;
            correctionParam.mPreviewImageSize = new Point(mPreviewImageSize.x, mPreviewImageSize.y);
            correctionParam.mPointArray = new ArrayList();
            List<List<PointF>> list = 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 = mScale;
            correctionParam.mStrokeWidth = mStrokeWidth;
            return correctionParam;
        }
    }
}
