package epson.scan.activity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.epson.iprint.shared.SharedParamScan;
import com.epson.mobilephone.common.PrintingLib.define.Constants;
import com.epson.mobilephone.common.wifidirect.WiFiDirectManager;
import epson.common.Constants;
import epson.common.Utils;
import epson.print.ActivityIACommon;
import epson.print.C2135R;
import epson.print.EPPrinterManager;
import epson.print.Util.EPLog;
import epson.scan.lib.ScanCommonParams;
import epson.scan.lib.ScanInfoStorage;
import epson.scan.lib.ScanSettingHelper;
import epson.scan.lib.ScanSizeHelper;
import epson.scan.lib.ScannerInfo;

public class ScanSettingsActivity extends ActivityIACommon {
    public static final String HIDE_COLOR_MODE = "hide-color-mode";
    public static final String HIDE_RESOLUTION = "hide-resolution";
    public static final String IS_NEW_SAVE = "IS_NEW_SAVE";
    public static final String NO_CLEAR_RESULT = "NO_CLEAR_RESULT";
    public static final String PARAM_KEY_EXTERNAL_DATA = "external-scan-params";
    private static final int REQUEST_CODE_BRIGHTNESS = 8;
    private static final int REQUEST_CODE_CHANGE_ESC_I_VERSION = 100;
    private static final int REQUEST_CODE_SELECT_SCANNER = 1;
    private static final String SCAN_SETTINGS_LAST_DENSITY = "SCAN_SETTINGS_LAST_DENSITY";
    private static final String SCAN_SETTINGS_LAST_DENSITY_STATUS = "SCAN_SETTINGS_LAST_DENSITY_STATUS";
    private static final String SCAN_SETTINGS_LAST_VALUE = "SCAN_SETTINGS_LAST_VALUE";
    private static final String SCAN_SUPPORTED_RESOLUTION_LIST = "SCAN_SUPPORTED_RESOLUTION_LIST";
    private static final String SCAN_SUPPORTED_SIZE_LIST = "SCAN_SUPPORTED_SIZE_LIST";
    /* access modifiers changed from: private */
    public String autoConnectSsid = null;
    private Context context;
    private AlertDialog errorDialog;
    private boolean isNeedSaveSupportedOptions = false;
    /* access modifiers changed from: private */
    public LinearLayout llScanName;
    private LinearLayout llScanSettingsAdvance2Sided;
    private LinearLayout llScanSettingsColor;
    private LinearLayout llScanSettingsDensity;
    private LinearLayout llScanSettingsGamma;
    private LinearLayout llScanSettingsResolution;
    private LinearLayout llScanSettingsSize;
    private LinearLayout llScanSettingsSource;
    private View mBrightnessSeparator;
    private SharedParamScan mExternalIntentData;
    private boolean mHideColorMode;
    private boolean mHideResolution;
    private View.OnClickListener mLLScanNameClick = new View.OnClickListener() {
        public void onClick(View view) {
            ScanSettingsActivity.this.llScanName.setClickable(false);
            new AsyncTask<Void, Void, Void>() {
                /* access modifiers changed from: protected */
                public void onPreExecute() {
                }

                /* access modifiers changed from: protected */
                public Void doInBackground(Void... voidArr) {
                    WiFiDirectManager.disconnect(ScanSettingsActivity.this.getApplicationContext(), WiFiDirectManager.DEVICE_TYPE_SCANNER, ScanSettingsActivity.this.scanInfo.getIp());
                    WiFiDirectManager.disconnectSimpleAP(ScanSettingsActivity.this.getApplicationContext(), ScanSettingsActivity.this.autoConnectSsid, ScanSettingsActivity.this.scanInfo.getIp());
                    return null;
                }

                /* access modifiers changed from: protected */
                public void onPostExecute(Void voidR) {
                    ScanSettingsActivity.this.startActivityForResult(ScanSearchActivity.getStartIntent(ScanSettingsActivity.this.getApplicationContext(), ScanSettingsActivity.this.scanInfo.getScannerId(), ScanSettingsActivity.this.scanInfo.getLocation(), ScanSettingsActivity.this.autoConnectSsid), 1);
                    ScanSettingsActivity.this.llScanName.setClickable(true);
                }
            }.execute(new Void[0]);
        }
    };
    private View.OnClickListener mLLScanSettings2Sided = new View.OnClickListener() {
        public void onClick(View view) {
            ScanSettingsActivity scanSettingsActivity = ScanSettingsActivity.this;
            scanSettingsActivity.goToSettingAdvanceDetailsScreen(Constants.SCAN_SETTINGS_DETAIL_TITLE, C2135R.string.str_settings_2sided_title, scanSettingsActivity.scanInfo.getTwoSidedScanningValue(), 7);
        }
    };
    private View.OnClickListener mLLScanSettingsColor = new View.OnClickListener() {
        public void onClick(View view) {
            if (ScanSettingsActivity.this.scanInfo.getIp().equals("")) {
                return;
            }
            if (ScanSettingsActivity.this.progressGetOption == null || !ScanSettingsActivity.this.progressGetOption.isShown()) {
                ScanSettingsActivity scanSettingsActivity = ScanSettingsActivity.this;
                scanSettingsActivity.startDetailSettingScreenForResult(Constants.SCAN_SETTINGS_DETAIL_TITLE, C2135R.string.str_settings_color_title, scanSettingsActivity.scanInfo.getColorValue(), 5);
            }
        }
    };
    private View.OnClickListener mLLScanSettingsDensity = new View.OnClickListener() {
        public void onClick(View view) {
            ScanSettingsActivity.this.goToSettingAdvanceDensityScreen();
        }
    };
    private View.OnClickListener mLLScanSettingsGamma = new View.OnClickListener() {
        public void onClick(View view) {
            ScanSettingsActivity scanSettingsActivity = ScanSettingsActivity.this;
            scanSettingsActivity.goToSettingAdvanceDetailsScreen(Constants.SCAN_SETTINGS_DETAIL_TITLE, C2135R.string.str_settings_gamma_title, scanSettingsActivity.scanInfo.getGammaValue(), 9);
        }
    };
    private View.OnClickListener mLLScanSettingsResolution = new View.OnClickListener() {
        public void onClick(View view) {
            if (ScanSettingsActivity.this.scanInfo.getIp().equals("")) {
                return;
            }
            if (ScanSettingsActivity.this.progressGetOption == null || !ScanSettingsActivity.this.progressGetOption.isShown()) {
                ScanSettingsActivity scanSettingsActivity = ScanSettingsActivity.this;
                scanSettingsActivity.startDetailSettingScreenForResult(Constants.SCAN_SETTINGS_DETAIL_TITLE, C2135R.string.str_settings_resolution_title, scanSettingsActivity.scanInfo.getResolutionValue(), 6);
            }
        }
    };
    private View.OnClickListener mLLScanSettingsSize = new View.OnClickListener() {
        public void onClick(View view) {
            ScanSettingsActivity scanSettingsActivity = ScanSettingsActivity.this;
            scanSettingsActivity.startDetailSettingScreenForResult(Constants.SCAN_SETTINGS_DETAIL_TITLE, C2135R.string.str_scanning_size, scanSettingsActivity.scanInfo.getSizeValue(), 11);
        }
    };
    private View.OnClickListener mLLScanSettingsSource = new View.OnClickListener() {
        public void onClick(View view) {
            if (ScanSettingsActivity.this.scanInfo.getIp().equals("")) {
                return;
            }
            if (ScanSettingsActivity.this.progressGetOption == null || !ScanSettingsActivity.this.progressGetOption.isShown()) {
                ScanSettingsActivity.this.startInputUnitSettingActivity();
            }
        }
    };
    private ScanInfoStorage mScanInfoStorage;
    /* access modifiers changed from: private */
    public View progressGetOption;
    /* access modifiers changed from: private */
    public ScannerInfo scanInfo;
    private ScannerInfo siOrigin;
    private TextView tvScanner2Sided;
    private TextView tvScannerColor;
    private TextView tvScannerDensity;
    private TextView tvScannerGamma;
    private TextView tvScannerName;
    private TextView tvScannerResolution;
    private TextView tvScannerSize;
    private TextView tvScannerSource;
    private View viewScanSettingsAdvance2Sided;
    private View viewScanSettingsSource;

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.mScanInfoStorage = ScanInfoStorage.getInstance();
        setContentView((int) C2135R.layout.scan_settings_main);
        setActionBar((int) C2135R.string.str_lbl_title_scan_settings, true);
        this.context = this;
        this.llScanName = (LinearLayout) findViewById(C2135R.C2137id.llScannerName);
        this.llScanName.setOnClickListener(this.mLLScanNameClick);
        this.llScanSettingsSource = (LinearLayout) findViewById(C2135R.C2137id.llScanSettingsSource);
        this.llScanSettingsSource.setOnClickListener(this.mLLScanSettingsSource);
        this.llScanSettingsSize = (LinearLayout) findViewById(C2135R.C2137id.llScanSettingsSize);
        this.llScanSettingsSize.setOnClickListener(this.mLLScanSettingsSize);
        this.viewScanSettingsSource = findViewById(C2135R.C2137id.viewScanSettingsSource);
        this.llScanSettingsColor = (LinearLayout) findViewById(C2135R.C2137id.llScanSettingsColor);
        this.llScanSettingsColor.setOnClickListener(this.mLLScanSettingsColor);
        this.llScanSettingsResolution = (LinearLayout) findViewById(C2135R.C2137id.llScanSettingsResolution);
        this.llScanSettingsResolution.setOnClickListener(this.mLLScanSettingsResolution);
        this.tvScannerName = (TextView) findViewById(C2135R.C2137id.tvScannerName);
        this.tvScannerSource = (TextView) findViewById(C2135R.C2137id.tvScannerSource);
        this.tvScannerSize = (TextView) findViewById(C2135R.C2137id.tvScannerSize);
        this.tvScannerColor = (TextView) findViewById(C2135R.C2137id.tvScannerColor);
        this.tvScannerResolution = (TextView) findViewById(C2135R.C2137id.tvScannerResolution);
        this.progressGetOption = findViewById(C2135R.C2137id.progressGetOption);
        this.llScanSettingsAdvance2Sided = (LinearLayout) findViewById(C2135R.C2137id.llScanSettingsAdvance2Sided);
        this.llScanSettingsAdvance2Sided.setOnClickListener(this.mLLScanSettings2Sided);
        this.viewScanSettingsAdvance2Sided = findViewById(C2135R.C2137id.viewScanSettingsAdvance2Sided);
        this.llScanSettingsDensity = (LinearLayout) findViewById(C2135R.C2137id.llScanSettingsDensity);
        this.llScanSettingsDensity.setOnClickListener(this.mLLScanSettingsDensity);
        this.mBrightnessSeparator = findViewById(C2135R.C2137id.brightnessSeparator);
        this.llScanSettingsGamma = (LinearLayout) findViewById(C2135R.C2137id.llScanSettingsGamma);
        this.llScanSettingsGamma.setOnClickListener(this.mLLScanSettingsGamma);
        this.tvScanner2Sided = (TextView) findViewById(C2135R.C2137id.tvScanner2Sided);
        this.tvScannerDensity = (TextView) findViewById(C2135R.C2137id.tvScannerDensity);
        this.tvScannerGamma = (TextView) findViewById(C2135R.C2137id.tvScannerGamma);
        Intent intent = getIntent();
        this.mHideResolution = intent.getBooleanExtra(HIDE_RESOLUTION, false);
        if (this.mHideResolution) {
            this.llScanSettingsResolution.setVisibility(8);
        }
        this.mHideColorMode = intent.getBooleanExtra(HIDE_COLOR_MODE, false);
        if (this.mHideColorMode) {
            this.llScanSettingsColor.setVisibility(8);
        }
        this.mExternalIntentData = (SharedParamScan) intent.getSerializableExtra(PARAM_KEY_EXTERNAL_DATA);
        this.scanInfo = new ScannerInfo();
        getScannerSavedSettings();
        if (this.scanInfo.getIp().equals("")) {
            setBlankSettings();
            showNewSelectedScannerInfo();
        } else {
            setResolutionClickable();
            setColorModeClickable();
        }
        this.siOrigin = new ScannerInfo(this.scanInfo);
        updateScannerInfoIfEscIVersionChanged(getIntent());
    }

    private void updateScannerInfoIfEscIVersionChanged(Intent intent) {
        ScannerPropertyWrapper scannerPropertyWrapper = SettingActivityParams.getScannerPropertyWrapper(intent);
        if (scannerPropertyWrapper != null) {
            if (!scannerPropertyWrapper.isPrinterSet()) {
                resetSettings();
                return;
            }
            ScannerInfo i1ScannerInfo = scannerPropertyWrapper.getI1ScannerInfo();
            if (i1ScannerInfo != null) {
                this.isNeedSaveSupportedOptions = true;
                updateSelectedScannerInfo(i1ScannerInfo, scannerPropertyWrapper.getSimpleApSsid());
            }
        }
    }

    private void updatePrinterIcon() {
        if (this.scanInfo.isModelNameEmpty()) {
            ((ImageView) findViewById(C2135R.C2137id.imageViewPrinterLocation)).setVisibility(8);
            return;
        }
        ((ImageView) findViewById(C2135R.C2137id.imageViewPrinterLocation)).setVisibility(0);
        switch (this.scanInfo.getLocation()) {
            case 1:
                ((ImageView) findViewById(C2135R.C2137id.imageViewPrinterLocation)).setImageResource(C2135R.C2136drawable.print_local);
                return;
            case 2:
                ((ImageView) findViewById(C2135R.C2137id.imageViewPrinterLocation)).setImageResource(C2135R.C2136drawable.print_remote);
                return;
            case 3:
                ((ImageView) findViewById(C2135R.C2137id.imageViewPrinterLocation)).setImageResource(C2135R.C2136drawable.print_ip);
                return;
            default:
                return;
        }
    }

    private void getScannerSavedSettings() {
        EPLog.m313i("epson.scan.activity.ScanSettingsActivity", "Start get saved option");
        loadRefScannerName();
        loadRefScannerSourceSetting();
        loadRefScannerColorSetting();
        loadRefScannerResolutionSetting();
        loadRefScannerBasicOptions();
        this.scanInfo.setSizeValue(Constants.PaperName.EPS_MSID_UNKNOWN.getCode());
        this.mScanInfoStorage.loadScanSetting(this, this.scanInfo);
        int[] iArr = new int[64];
        for (int i = 0; i < 64; i++) {
            Context context2 = this.context;
            iArr[i] = Utils.getPrefInt(context2, epson.common.Constants.SCAN_REFS_SUPPORTED_OPTIONS, epson.common.Constants.SCAN_REFS_OPTIONS_RESOLUTION_ + i);
        }
        this.scanInfo.setSupportedResolutionList(iArr);
        this.autoConnectSsid = WiFiDirectManager.getConnectInfo(this, WiFiDirectManager.DEVICE_TYPE_SCANNER);
        updateScanner2SidedSetting(this.scanInfo.getTwoSidedScanningName(), this.scanInfo.getSupportedAdfDuplex());
        this.tvScannerDensity.setText(String.valueOf(255 - this.scanInfo.getDensityValue()));
        this.tvScannerGamma.setText(this.scanInfo.getGammaName());
    }

    @Deprecated
    private void loadRefScannerName() {
        this.mScanInfoStorage.loadScannerConnectivityInfo(this, this.scanInfo);
        displayScannerName();
        updatePrinterIcon();
    }

    private void displayScannerName() {
        String ipPrinterUserName;
        if (this.scanInfo.getLocation() != 3 || (ipPrinterUserName = new EPPrinterManager(this).getIpPrinterUserName(this.scanInfo.getScannerId())) == null) {
            String modelName = this.scanInfo.getModelName();
            if (modelName == null || modelName.isEmpty()) {
                this.tvScannerName.setText(C2135R.string.str_lbl_title_scan);
            } else {
                this.tvScannerName.setText(modelName);
            }
        } else {
            this.tvScannerName.setText(ipPrinterUserName);
        }
    }

    @Deprecated
    private void loadRefScannerSourceSetting() {
        this.mScanInfoStorage.loadSupportedAdfSize(this, this.scanInfo);
        this.mScanInfoStorage.loadReadUnitValue(this, this.scanInfo);
        this.tvScannerSource.setText(getString(this.scanInfo.getSourceName()));
        if (this.scanInfo.getSupportedAdfHeight() == 0 && this.scanInfo.getSupportedAdfWidth() == 0) {
            this.llScanSettingsSource.setVisibility(8);
            this.viewScanSettingsSource.setVisibility(8);
            return;
        }
        this.llScanSettingsSource.setVisibility(0);
        this.viewScanSettingsSource.setVisibility(0);
    }

    @Deprecated
    private void loadRefScannerColorSetting() {
        this.mScanInfoStorage.loadColorValue(this, this.scanInfo);
        this.tvScannerColor.setText(getString(this.scanInfo.getColorName()));
    }

    @Deprecated
    private void loadRefScannerResolutionSetting() {
        this.mScanInfoStorage.loadResolution(this, this.scanInfo);
        this.tvScannerResolution.setText(this.scanInfo.getResolutionName(this));
    }

    private void loadRefScannerBasicOptions() {
        this.mScanInfoStorage.loadSupportedValue(this, this.scanInfo);
    }

    /* access modifiers changed from: private */
    public void startInputUnitSettingActivity() {
        if (this.scanInfo.getSupportedAdfWidth() > 0 && this.scanInfo.getSupportedAdfHeight() > 0) {
            startActivityForResult(InputUnitSettingActivity.getStartIntent(this, this.scanInfo.getSourceValue(), this.scanInfo.getAdfPaperGuide()), 4);
        }
    }

    /* access modifiers changed from: private */
    public void startDetailSettingScreenForResult(String str, int i, int i2, int i3) {
        Intent intent = new Intent(this, ScanSettingsDetailActivity.class);
        intent.putExtra(str, i);
        intent.putExtra(SCAN_SETTINGS_LAST_VALUE, i2);
        intent.putExtra(epson.common.Constants.SCAN_REFS_OPTIONS_ADF_WIDTH, this.scanInfo.getSupportedAdfWidth());
        intent.putExtra(epson.common.Constants.SCAN_REFS_OPTIONS_ADF_HEIGHT, this.scanInfo.getSupportedAdfHeight());
        intent.putExtra(SCAN_SUPPORTED_RESOLUTION_LIST, this.scanInfo.getSupportedResolutionList());
        intent.putExtra(epson.common.Constants.SCAN_REFS_SETTINGS_ADF_PAPER_GUIDE, this.scanInfo.getAdfPaperGuide());
        int[] iArr = new int[0];
        switch (this.scanInfo.getSourceValue()) {
            case 0:
                iArr = ScanSizeHelper.getSupportedScanSizeList(this.scanInfo.getSourceValue(), 0, this.scanInfo.getSupportedBasicWidth(), this.scanInfo.getSupportedBasicHeight(), this.scanInfo.getSupportedBasicResolution());
                break;
            case 1:
                iArr = ScanSizeHelper.getSupportedScanSizeList(this.scanInfo.getSourceValue(), this.scanInfo.getTwoSidedScanningValue(), this.scanInfo.getSupportedAdfWidth(), this.scanInfo.getSupportedAdfHeight(), this.scanInfo.getSupportedBasicResolution());
                break;
        }
        intent.putExtra(SCAN_SUPPORTED_SIZE_LIST, iArr);
        intent.setAction("android.intent.action.VIEW");
        startActivityForResult(intent, i3);
    }

    /* access modifiers changed from: private */
    public void goToSettingAdvanceDensityScreen() {
        startActivityForResult(ScanSettingsAdvanceDensityActivity.getStartIntent(this, this.scanInfo.getDensityValue(), this.scanInfo.isDensityStatus()), 8);
    }

    /* access modifiers changed from: private */
    public void goToSettingAdvanceDetailsScreen(String str, int i, int i2, int i3) {
        Intent intent = new Intent(this, ScanSettingsAdvanceDetailActivity.class);
        intent.putExtra(str, i);
        intent.putExtra(SCAN_SETTINGS_LAST_VALUE, i2);
        intent.putExtra(epson.common.Constants.SCAN_REFS_OPTIONS_SUPPORTED_ADF_DUPLEX, this.scanInfo.getSupportedAdfDuplex());
        int i4 = 1;
        if (!this.scanInfo.isAdfDuplexRotaitonYes()) {
            i4 = 0;
        }
        intent.putExtra(epson.common.Constants.SCAN_REFS_SETTINGS_ROTATE, i4);
        intent.setAction("android.intent.action.VIEW");
        startActivityForResult(intent, i3);
    }

    /* access modifiers changed from: protected */
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i == 1) {
            onScannerSelectResult(i2, intent);
        } else if (i != 100) {
            if (i2 == -1) {
                Bundle extras = intent.getExtras();
                boolean z = false;
                switch (i) {
                    case 4:
                        this.scanInfo.setSourceValue(InputUnitSettingActivity.getInputUnit(intent));
                        int adfAlignment = InputUnitSettingActivity.getAdfAlignment(intent);
                        if (adfAlignment >= 0) {
                            this.scanInfo.setAdfPaperGuide(adfAlignment);
                        }
                        this.tvScannerSource.setText(this.scanInfo.getSourceName());
                        if (this.scanInfo.getSourceValue() == 0) {
                            this.scanInfo.setTwoSidedScanningValue(0);
                        }
                        updateScanner2SidedSetting(this.scanInfo.getTwoSidedScanningName(), this.scanInfo.getSupportedAdfDuplex());
                        this.scanInfo.setSizeValue(Constants.PaperName.EPS_MSID_UNKNOWN.getCode());
                        this.tvScannerSize.setText(getString(ScanSizeHelper.getScanSizeName(this.scanInfo.getSizeValue())));
                        break;
                    case 5:
                        this.scanInfo.setColorValue(extras.getInt(epson.common.Constants.SCAN_REFS_SETTINGS_COLOR));
                        this.tvScannerColor.setText(getString(this.scanInfo.getColorName()));
                        break;
                    case 6:
                        this.scanInfo.setResolutionValue(extras.getInt(epson.common.Constants.SCAN_REFS_SETTINGS_RESOLUTION));
                        this.tvScannerResolution.setText(this.scanInfo.getResolutionName(this));
                        break;
                    case 7:
                        this.scanInfo.setTwoSidedScanningValue(extras.getInt(epson.common.Constants.SCAN_REFS_SETTINGS_2SIDED));
                        String string = extras.getString(epson.common.Constants.SCAN_REFS_SETTINGS_2SIDED_NAME);
                        int i3 = C2135R.string.str_yes;
                        if (!string.equals(getString(C2135R.string.str_yes))) {
                            i3 = C2135R.string.str_no;
                        }
                        this.tvScanner2Sided.setText(i3);
                        ScannerInfo scannerInfo = this.scanInfo;
                        if (extras.getInt(epson.common.Constants.SCAN_REFS_SETTINGS_ROTATE) == 1) {
                            z = true;
                        }
                        scannerInfo.setAdfDuplexRotaitonYes(z);
                        if (this.scanInfo.getTwoSidedScanningValue() == 1) {
                            this.scanInfo.setSourceValue(1);
                            this.tvScannerSource.setText(getString(this.scanInfo.getSourceName()));
                        }
                        this.scanInfo.setSizeValue(Constants.PaperName.EPS_MSID_UNKNOWN.getCode());
                        this.tvScannerSize.setText(getString(ScanSizeHelper.getScanSizeName(this.scanInfo.getSizeValue())));
                        break;
                    case 8:
                        this.scanInfo.setDensityValue(ScanSettingsAdvanceDensityActivity.getDensityFromReturnIntent(intent));
                        this.scanInfo.setDensityStatus(ScanSettingsAdvanceDensityActivity.getChangeAble(intent));
                        this.tvScannerDensity.setText(String.valueOf(255 - this.scanInfo.getDensityValue()));
                        break;
                    case 9:
                        this.scanInfo.setGammaValue(extras.getInt(epson.common.Constants.SCAN_REFS_SETTINGS_GAMMA));
                        String string2 = extras.getString(epson.common.Constants.SCAN_REFS_SETTINGS_GAMMA_NAME);
                        int i4 = C2135R.string.str_settings_gamma_10;
                        if (!string2.equals(getString(C2135R.string.str_settings_gamma_10))) {
                            i4 = C2135R.string.str_settings_gamma_18;
                        }
                        this.tvScannerGamma.setText(i4);
                        break;
                    case 11:
                        this.scanInfo.setSizeValue(extras.getInt(epson.common.Constants.SCAN_REFS_SCANNER_CHOSEN_SIZE));
                        this.tvScannerSize.setText(getString(ScanSizeHelper.getScanSizeName(this.scanInfo.getSizeValue())));
                        break;
                }
            }
            EPLog.m313i(getLocalClassName(), "back to settings");
        } else if (i2 == 1) {
            onScannerSelectResult(-1, intent);
        } else {
            setResult(i2, intent);
            finish();
        }
    }

    private void onScannerSelectResult(int i, Intent intent) {
        if (i == -1) {
            ScannerPropertyWrapper scannerPropertyWrapper = SettingActivityParams.getScannerPropertyWrapper(intent);
            if (scannerPropertyWrapper != null) {
                if (scannerPropertyWrapper.getEscIVersion() != 2) {
                    ScannerInfo i1ScannerInfo = scannerPropertyWrapper.getI1ScannerInfo();
                    if (i1ScannerInfo != null) {
                        updateSelectedScannerInfo(i1ScannerInfo, scannerPropertyWrapper.getSimpleApSsid());
                    }
                } else if (SettingActivityParams.returnIfEscIVersionChanged(getIntent())) {
                    setResult(1, SettingActivityParams.getSettingReturnIntent(scannerPropertyWrapper));
                    finish();
                } else {
                    startActivityForResult(SettingActivityParams.getChangeSettingActivityStartIntent(this, scannerPropertyWrapper, true, this.mHideColorMode, this.mHideResolution, this.mExternalIntentData), 100);
                }
            }
        } else {
            updateIpAddressPrinter();
        }
    }

    private void updateIpAddressPrinter() {
        if (this.scanInfo.getLocation() == 3 && !new EPPrinterManager(this).doseContainScannerIdInIpPrinterList(this.scanInfo.getScannerId())) {
            resetSettings();
        }
    }

    private void updateSelectedScannerInfo(ScannerInfo scannerInfo, String str) {
        this.isNeedSaveSupportedOptions = true;
        this.scanInfo.setScannerId(scannerInfo.getScannerId());
        this.scanInfo.setIp(scannerInfo.getIp());
        this.scanInfo.setLocation(scannerInfo.getLocation());
        this.scanInfo.setModelName(scannerInfo.getModelName());
        this.autoConnectSsid = str;
        displayScannerName();
        updatePrinterIcon();
        this.scanInfo.setSupportedOptions(new int[7]);
        this.scanInfo.setSupportedResolutionList(new int[64]);
        ScanSettingHelper.updateNewSelectedScannerSupportedOptions(this.scanInfo);
        setBlankSettings();
        this.scanInfo.setSupportedOptions(scannerInfo.getSupportedOptions());
        this.scanInfo.setSupportedResolutionList(scannerInfo.getSupportedResolutionList());
        ScanSettingHelper.updateNewSelectedScannerSupportedOptions(this.scanInfo);
        ScanSettingHelper.setDefaultSettings3(ScanCommonParams.load(this), this.scanInfo);
        showNewSelectedScannerInfo();
        if (!this.scanInfo.getIp().equals("")) {
            setResolutionClickable();
            setColorModeClickable();
            this.llScanSettingsDensity.setClickable(true);
            this.llScanSettingsGamma.setClickable(true);
        }
    }

    private void setBlankSettings() {
        this.scanInfo.setSourceValue(0);
        this.scanInfo.setSupportedAdfHeight(0);
        this.scanInfo.setSupportedAdfWidth(0);
        this.scanInfo.setSupportedAdfDuplex(0);
        this.scanInfo.setTwoSidedScanningValue(0);
        this.scanInfo.setResolutionValue(150);
        this.scanInfo.setSizeValue(Constants.PaperName.EPS_MSID_UNKNOWN.getCode());
        this.scanInfo.setColorValue(1);
        this.scanInfo.setDensityStatus(false);
        this.scanInfo.setDensityValue(128);
        this.scanInfo.setGammaValue(1);
        this.llScanSettingsResolution.setClickable(false);
        this.llScanSettingsColor.setClickable(false);
        this.llScanSettingsDensity.setClickable(false);
        this.llScanSettingsGamma.setClickable(false);
    }

    private void showNewSelectedScannerInfo() {
        displayNewDocumentSourceSetting();
        this.tvScannerSize.setText(getString(ScanSizeHelper.getScanSizeName(this.scanInfo.getSizeValue())));
        this.tvScannerColor.setText(getString(this.scanInfo.getColorName()));
        this.tvScannerResolution.setText(this.scanInfo.getResolutionName(this));
        this.tvScannerDensity.setText(String.valueOf(255 - this.scanInfo.getDensityValue()));
        this.tvScannerGamma.setText(this.scanInfo.getGammaName());
    }

    private void displayNewDocumentSourceSetting() {
        if (this.scanInfo.getSupportedAdfHeight() == 0 && this.scanInfo.getSupportedAdfWidth() == 0) {
            this.llScanSettingsSource.setVisibility(8);
            this.viewScanSettingsSource.setVisibility(8);
        } else {
            this.llScanSettingsSource.setVisibility(0);
            this.viewScanSettingsSource.setVisibility(0);
            this.tvScannerSource.setText(getString(this.scanInfo.getSourceName()));
        }
        updateScanner2SidedSetting(this.scanInfo.getTwoSidedScanningName(), this.scanInfo.getSupportedAdfDuplex());
    }

    private void updateScanner2SidedSetting(int i, int i2) {
        this.tvScanner2Sided.setText(i);
        if (i2 != 1) {
            this.llScanSettingsAdvance2Sided.setVisibility(8);
            this.viewScanSettingsAdvance2Sided.setVisibility(8);
            return;
        }
        this.llScanSettingsAdvance2Sided.setVisibility(0);
        this.viewScanSettingsAdvance2Sided.setVisibility(0);
    }

    private void setResolutionClickable() {
        if (!this.mHideResolution) {
            this.llScanSettingsResolution.setClickable(true);
        }
    }

    private void setColorModeClickable() {
        if (!this.mHideColorMode) {
            this.llScanSettingsColor.setClickable(true);
        }
    }

    public void onBackPressed() {
        new EPPrinterManager(this).rollbackIPPrinterInfo();
        setResult(0);
        finish();
    }

    private void onSettingDone() {
        if (this.progressGetOption.getVisibility() == 8) {
            if (!this.scanInfo.isReSearch() && !this.scanInfo.getIp().equals("")) {
                this.scanInfo.setReSearch(true);
            }
            if (this.isNeedSaveSupportedOptions) {
                ScanSettingHelper.saveSupportedOptionToRef(this.context, this.scanInfo);
                String str = this.autoConnectSsid;
                if (str == null || str.length() <= 0) {
                    WiFiDirectManager.resetConnectInfo(this, WiFiDirectManager.DEVICE_TYPE_SCANNER);
                } else {
                    WiFiDirectManager.setConnectInfo(this, this.autoConnectSsid, WiFiDirectManager.DEVICE_TYPE_SCANNER, this.scanInfo.getModelName());
                }
            }
            boolean z = false;
            this.isNeedSaveSupportedOptions = false;
            if (this.scanInfo.getModelName().equals(this.siOrigin.getModelName()) && this.scanInfo.getSourceValue() == this.siOrigin.getSourceValue() && this.scanInfo.getColorValue() == this.siOrigin.getColorValue() && this.scanInfo.getResolutionValue() == this.siOrigin.getResolutionValue() && this.scanInfo.getTwoSidedScanningValue() == this.siOrigin.getTwoSidedScanningValue() && this.scanInfo.isAdfDuplexRotaitonYes() == this.siOrigin.isAdfDuplexRotaitonYes() && this.scanInfo.getAdfPaperGuide() == this.siOrigin.getAdfPaperGuide() && this.scanInfo.getDensityValue() == this.siOrigin.getDensityValue() && this.scanInfo.getGammaValue() == this.siOrigin.getGammaValue()) {
                z = true;
            }
            ScanInfoStorage.saveEscIVersion(this, 1);
            ScanSettingHelper.saveAllUserSettingsToRef(this.context, this.scanInfo);
            backToScanScreen(z);
        }
    }

    private void backToScanScreen(boolean z) {
        new EPPrinterManager(this).commitIPPrinterInfo();
        Intent intent = getIntent();
        intent.putExtra(epson.common.Constants.ACT_RESULT, epson.common.Constants.ACT_RESULT_SAVE);
        intent.putExtra(IS_NEW_SAVE, true);
        intent.putExtra(NO_CLEAR_RESULT, z);
        setResult(-1, intent);
        finish();
    }

    /* access modifiers changed from: protected */
    public void onStop() {
        super.onStop();
        EPLog.m313i(getLocalClassName(), "scannsetting screen, onStop");
        this.progressGetOption.setVisibility(8);
        AlertDialog alertDialog = this.errorDialog;
        if (alertDialog != null && alertDialog.isShowing()) {
            this.errorDialog.dismiss();
        }
    }

    private void resetSettings() {
        this.scanInfo.setScannerId("");
        this.scanInfo.setIp("");
        this.scanInfo.setModelName("");
        this.scanInfo.setLocation(1);
        this.autoConnectSsid = "";
        setBlankSettings();
        showNewSelectedScannerInfo();
        displayScannerName();
        updatePrinterIcon();
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(C2135R.C2138menu.menu_done, menu);
        return super.onCreateOptionsMenu(menu);
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != C2135R.C2137id.menuSettingsDone) {
            return super.onOptionsItemSelected(menuItem);
        }
        onSettingDone();
        return true;
    }
}
