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 java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import epson.common.Constants;
import epson.common.CustomListRow;
import epson.common.CustomListRowAdapter;
import epson.common.CustomListRowImpl;
import epson.print.ActivityIACommon;
import epson.print.R;
import epson.print.Util.EPLog;
import epson.scan.lib.ScanSizeHelper;

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;
    private int lastAdfGuid;
    int lastValue;
    LinkedHashMap<String, Integer> lhmListOptionValue;
    int[] listResolution;
    private ListView listSelect;
    private 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 == R.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(View.VISIBLE);
                    } else {
                        ScanSettingsDetailActivity.this.listSelect2.setVisibility(View.GONE);
                    }
                } else {
                    Intent intent = ScanSettingsDetailActivity.this.getIntent();
                    int i2 = ScanSettingsDetailActivity.this.screenId;
                    if (i2 != R.string.str_advance_setting) {
                        if (i2 == R.string.str_scanning_size) {
                            intent.putExtra(Constants.SCAN_REFS_SCANNER_CHOSEN_SIZE, detailSettingHolder.value);
                        } else if (i2 != R.string.str_settings_color_title) {
                            if (i2 == R.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.i("mListOptionClick2", "[position]" + i);
            EPLog.i("mListOptionClick2", "[id]" + j);
            int unused = ScanSettingsDetailActivity.this.lastAdfGuid = i;
            switch (i) {
                case 0:
                    ScanSettingsDetailActivity.mlAdapter.setList(0, CustomListRowImpl.create().addText(ScanSettingsDetailActivity.this.getString(R.string.str_settings_right_aligned)).prefixImage(Integer.valueOf(R.drawable.adf_left_adst)).suffixImage(Integer.valueOf(R.drawable.selected)));
                    ScanSettingsDetailActivity.mlAdapter.setList(1, CustomListRowImpl.create().addText(ScanSettingsDetailActivity.this.getString(R.string.str_settings_center_aligned)).prefixImage(Integer.valueOf(R.drawable.adf_center_adst)));
                    break;
                case 1:
                    ScanSettingsDetailActivity.mlAdapter.setList(0, CustomListRowImpl.create().addText(ScanSettingsDetailActivity.this.getString(R.string.str_settings_right_aligned)).prefixImage(Integer.valueOf(R.drawable.adf_left_adst)));
                    ScanSettingsDetailActivity.mlAdapter.setList(1, CustomListRowImpl.create().addText(ScanSettingsDetailActivity.this.getString(R.string.str_settings_center_aligned)).prefixImage(Integer.valueOf(R.drawable.adf_center_adst)).suffixImage(Integer.valueOf(R.drawable.selected)));
                    break;
            }
            ScanSettingsDetailActivity.mlAdapter.notifyDataSetChanged();
        }
    };
    private CustomListRowAdapter mlAdapter;
    int screenId;
    String screenTitle;
    private ScanSettingsDetailAdapter ssdAdapter;
    private String strSelText;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.scan_settings_detail_2);
        Bundle extras = getIntent().getExtras();
        screenId = extras.getInt(Constants.SCAN_SETTINGS_DETAIL_TITLE);
        lastValue = extras.getInt(SCAN_SETTINGS_LAST_VALUE);
        adfWidth = extras.getInt(Constants.SCAN_REFS_OPTIONS_ADF_WIDTH);
        adfHeight = extras.getInt(Constants.SCAN_REFS_OPTIONS_ADF_HEIGHT);
        listResolution = extras.getIntArray(SCAN_SUPPORTED_RESOLUTION_LIST);
        listSize = extras.getIntArray(SCAN_SUPPORTED_SIZE_LIST);
        lastAdfGuid = extras.getInt(Constants.SCAN_REFS_SETTINGS_ADF_PAPER_GUIDE);
        listSelect = (ListView) findViewById(R.id.lvScannerSettingOptions);
        listSelect2 = (ListView) findViewById(R.id.lvScannerSettingOptions2);
        context = this;
        makeListCorespondenceOptions(this.screenId);
        setListCorespondenceOptions(this.screenId);
        setActionBar(getTitle().toString(), true);
    }

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

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

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