package epson.scan.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import epson.common.Constants;
import epson.common.CustomListRow;
import epson.common.CustomListRowAdapter;
import epson.common.CustomListRowImpl;
import epson.print.ActivityIACommon;
import epson.print.C2135R;
import epson.print.Util.EPLog;
import epson.scan.activity.ScanSettingsDetailAdapter;
import epson.scan.lib.ScanSizeHelper;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

public class ScanSettingsDetailActivity extends ActivityIACommon {
    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";
    int adfHeight;
    int adfWidth;
    Context context;
    private List<CustomListRow> items;
    /* access modifiers changed from: private */
    public int lastAdfGuid;
    int lastValue;
    LinkedHashMap<String, Integer> lhmListOptionValue;
    int[] listResolution;
    private ListView listSelect;
    /* access modifiers changed from: private */
    public ListView listSelect2;
    int[] listSize;
    private AdapterView.OnItemClickListener mListOptionClick = new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
            if (view.getTag() instanceof ScanSettingsDetailAdapter.DetailSettingHolder) {
                ScanSettingsDetailAdapter.DetailSettingHolder detailSettingHolder = (ScanSettingsDetailAdapter.DetailSettingHolder) view.getTag();
                if (ScanSettingsDetailActivity.this.screenId == C2135R.string.str_settings_source_title) {
                    ScanSettingsDetailActivity.this.lastValue = detailSettingHolder.value;
                    String unused = ScanSettingsDetailActivity.this.strSelText = detailSettingHolder.text.getText().toString();
                    ScanSettingsDetailActivity.this.ssdAdapter.setSelected(ScanSettingsDetailActivity.this.lastValue);
                    ScanSettingsDetailActivity.this.ssdAdapter.notifyDataSetChanged();
                    if (ScanSettingsDetailActivity.this.lastValue == 1) {
                        ScanSettingsDetailActivity.this.listSelect2.setVisibility(0);
                    } else {
                        ScanSettingsDetailActivity.this.listSelect2.setVisibility(8);
                    }
                } else {
                    Intent intent = ScanSettingsDetailActivity.this.getIntent();
                    int i2 = ScanSettingsDetailActivity.this.screenId;
                    if (i2 != C2135R.string.str_advance_setting) {
                        if (i2 == C2135R.string.str_scanning_size) {
                            intent.putExtra(Constants.SCAN_REFS_SCANNER_CHOSEN_SIZE, detailSettingHolder.value);
                        } else if (i2 != C2135R.string.str_settings_color_title) {
                            if (i2 == C2135R.string.str_settings_resolution_title) {
                                intent.putExtra(Constants.SCAN_REFS_SETTINGS_RESOLUTION, detailSettingHolder.value);
                                intent.putExtra(Constants.SCAN_REFS_SETTINGS_RESOLUTION_NAME, detailSettingHolder.text.getText().toString());
                            }
                        }
                        intent.putExtra(Constants.SCAN_REFS_SETTINGS_COLOR, detailSettingHolder.value);
                        intent.putExtra(Constants.SCAN_REFS_SETTINGS_COLOR_NAME, detailSettingHolder.text.getText().toString());
                    }
                    ScanSettingsDetailActivity.this.setResult(-1, intent);
                    ScanSettingsDetailActivity.this.finish();
                }
            }
        }
    };
    private AdapterView.OnItemClickListener mListOptionClick2 = new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
            EPLog.m313i("mListOptionClick2", "[position]" + i);
            EPLog.m313i("mListOptionClick2", "[id]" + j);
            int unused = ScanSettingsDetailActivity.this.lastAdfGuid = i;
            switch (i) {
                case 0:
                    ScanSettingsDetailActivity.this.mlAdapter.setList(0, CustomListRowImpl.create().addText(ScanSettingsDetailActivity.this.getString(C2135R.string.str_settings_right_aligned)).prefixImage(Integer.valueOf(C2135R.C2136drawable.adf_left_adst)).suffixImage(Integer.valueOf(C2135R.C2136drawable.selected)));
                    ScanSettingsDetailActivity.this.mlAdapter.setList(1, CustomListRowImpl.create().addText(ScanSettingsDetailActivity.this.getString(C2135R.string.str_settings_center_aligned)).prefixImage(Integer.valueOf(C2135R.C2136drawable.adf_center_adst)));
                    break;
                case 1:
                    ScanSettingsDetailActivity.this.mlAdapter.setList(0, CustomListRowImpl.create().addText(ScanSettingsDetailActivity.this.getString(C2135R.string.str_settings_right_aligned)).prefixImage(Integer.valueOf(C2135R.C2136drawable.adf_left_adst)));
                    ScanSettingsDetailActivity.this.mlAdapter.setList(1, CustomListRowImpl.create().addText(ScanSettingsDetailActivity.this.getString(C2135R.string.str_settings_center_aligned)).prefixImage(Integer.valueOf(C2135R.C2136drawable.adf_center_adst)).suffixImage(Integer.valueOf(C2135R.C2136drawable.selected)));
                    break;
            }
            ScanSettingsDetailActivity.this.mlAdapter.notifyDataSetChanged();
        }
    };
    /* access modifiers changed from: private */
    public CustomListRowAdapter mlAdapter;
    int screenId;
    String screenTitle;
    /* access modifiers changed from: private */
    public ScanSettingsDetailAdapter ssdAdapter;
    /* access modifiers changed from: private */
    public String strSelText;

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) C2135R.layout.scan_settings_detail_2);
        Bundle extras = getIntent().getExtras();
        this.screenId = extras.getInt(Constants.SCAN_SETTINGS_DETAIL_TITLE);
        this.lastValue = extras.getInt(SCAN_SETTINGS_LAST_VALUE);
        this.adfWidth = extras.getInt(Constants.SCAN_REFS_OPTIONS_ADF_WIDTH);
        this.adfHeight = extras.getInt(Constants.SCAN_REFS_OPTIONS_ADF_HEIGHT);
        this.listResolution = extras.getIntArray(SCAN_SUPPORTED_RESOLUTION_LIST);
        this.listSize = extras.getIntArray(SCAN_SUPPORTED_SIZE_LIST);
        this.lastAdfGuid = extras.getInt(Constants.SCAN_REFS_SETTINGS_ADF_PAPER_GUIDE);
        this.listSelect = (ListView) findViewById(C2135R.C2137id.lvScannerSettingOptions);
        this.listSelect2 = (ListView) findViewById(C2135R.C2137id.lvScannerSettingOptions2);
        this.context = this;
        makeListCorespondenceOptions(this.screenId);
        setListCorespondenceOptions(this.screenId);
        setActionBar(getTitle().toString(), true);
    }

    private void makeListCorespondenceOptions(int i) {
        this.items = new ArrayList();
        this.lhmListOptionValue = new LinkedHashMap<>();
        switch (i) {
            case C2135R.string.str_advance_setting /*2131625070*/:
                this.screenTitle = getString(C2135R.string.str_advance_setting);
                return;
            case C2135R.string.str_scanning_size /*2131625215*/:
                this.screenTitle = getString(C2135R.string.str_scanning_size);
                for (int i2 : this.listSize) {
                    this.lhmListOptionValue.put(getString(ScanSizeHelper.getScanSizeName(i2)), Integer.valueOf(i2));
                }
                return;
            case C2135R.string.str_settings_color_title /*2131625225*/:
                this.screenTitle = getString(C2135R.string.str_settings_color_title);
                this.lhmListOptionValue.put(getString(C2135R.string.str_settings_color_color), 1);
                this.lhmListOptionValue.put(getString(C2135R.string.str_settings_color_grayscale), 2);
                this.lhmListOptionValue.put(getString(C2135R.string.str_settings_color_monochrome), 3);
                return;
            case C2135R.string.str_settings_resolution_title /*2131625231*/:
                this.screenTitle = getString(C2135R.string.str_settings_resolution_title);
                int i3 = 0;
                while (true) {
                    int[] iArr = this.listResolution;
                    if (i3 < iArr.length) {
                        int i4 = iArr[i3];
                        if (i4 == 75 || i4 == 150 || i4 == 300) {
                            this.lhmListOptionValue.put(String.format(getString(C2135R.string.str_settings_resolution), new Object[]{Integer.valueOf(this.listResolution[i3])}), Integer.valueOf(this.listResolution[i3]));
                        }
                        i3++;
                    } else {
                        return;
                    }
                }
                break;
            case C2135R.string.str_settings_source_title /*2131625235*/:
                this.screenTitle = getString(C2135R.string.str_settings_source_title);
                this.lhmListOptionValue.put(getString(C2135R.string.str_settings_source_doctable), 0);
                if (this.adfWidth > 0 && this.adfHeight > 0) {
                    this.lhmListOptionValue.put(getString(C2135R.string.str_settings_source_adf), 1);
                }
                switch (this.lastAdfGuid) {
                    case 0:
                        this.items.add(CustomListRowImpl.create().addText(getString(C2135R.string.str_settings_right_aligned)).prefixImage(Integer.valueOf(C2135R.C2136drawable.adf_left_adst)).suffixImage(Integer.valueOf(C2135R.C2136drawable.selected)));
                        this.items.add(CustomListRowImpl.create().addText(getString(C2135R.string.str_settings_center_aligned)).prefixImage(Integer.valueOf(C2135R.C2136drawable.adf_center_adst)));
                        return;
                    case 1:
                        this.items.add(CustomListRowImpl.create().addText(getString(C2135R.string.str_settings_right_aligned)).prefixImage(Integer.valueOf(C2135R.C2136drawable.adf_left_adst)));
                        this.items.add(CustomListRowImpl.create().addText(getString(C2135R.string.str_settings_center_aligned)).prefixImage(Integer.valueOf(C2135R.C2136drawable.adf_center_adst)).suffixImage(Integer.valueOf(C2135R.C2136drawable.selected)));
                        return;
                    default:
                        return;
                }
            default:
                return;
        }
    }

    private void setListCorespondenceOptions(int i) {
        setTitle(this.screenTitle);
        switch (i) {
            case C2135R.string.str_scanning_size /*2131625215*/:
            case C2135R.string.str_settings_color_title /*2131625225*/:
            case C2135R.string.str_settings_resolution_title /*2131625231*/:
                break;
            case C2135R.string.str_settings_source_title /*2131625235*/:
                this.mlAdapter = new CustomListRowAdapter(this, C2135R.layout.com_customline_row, this.items);
                this.listSelect2.setAdapter(this.mlAdapter);
                this.listSelect2.setOnItemClickListener(this.mListOptionClick2);
                if (this.lastValue != 1) {
                    this.listSelect2.setVisibility(8);
                    break;
                } else {
                    this.listSelect2.setVisibility(0);
                    break;
                }
            default:
                return;
        }
        this.ssdAdapter = new ScanSettingsDetailAdapter(getBaseContext(), this.lhmListOptionValue, this.lastValue);
        this.listSelect.setAdapter(this.ssdAdapter);
        this.listSelect.setOnItemClickListener(this.mListOptionClick);
    }

    public void onBackPressed() {
        Intent intent = getIntent();
        if (this.screenId != C2135R.string.str_settings_source_title) {
            setResult(0, intent);
        } else {
            if (this.lastValue == 1) {
                this.strSelText = getString(C2135R.string.str_settings_source_adf);
            } else {
                this.strSelText = getString(C2135R.string.str_settings_source_doctable);
            }
            intent.putExtra(Constants.SCAN_REFS_SETTINGS_SOURCE, this.lastValue);
            intent.putExtra(Constants.SCAN_REFS_SETTINGS_SOURCE_NAME, this.strSelText);
            intent.putExtra(Constants.SCAN_REFS_SETTINGS_ADF_PAPER_GUIDE, this.lastAdfGuid);
            setResult(-1, intent);
        }
        finish();
        super.onBackPressed();
    }
}
