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.CustomListRowAdapter;
import epson.common.CustomListRowImpl;
import epson.print.ActivityIACommon;
import epson.print.R;
import epson.scan.activity.ScanSettingsDetailAdapter;
import java.util.ArrayList;
import java.util.LinkedHashMap;

public class InputUnitSettingActivity extends ActivityIACommon {
    public static final int IGNORE_ADF_ALIGNMENT = -1;
    private static final String SCAN_SETTINGS_ADF_ALIGNMENT = "adf-alignment";
    private static final String SCAN_SETTINGS_LAST_VALUE = "SCAN_SETTINGS_LAST_VALUE";
    private boolean displayAdfAlignment;
    private int lastAdfGuide;
    private int lastValue;
    private ListView listSelect;
    private ListView listSelect2;
    private final AdapterView.OnItemClickListener mListOptionClick = new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
            int unused = InputUnitSettingActivity.this.lastValue = ((ScanSettingsDetailAdapter.DetailSettingHolder) view.getTag()).value;
            InputUnitSettingActivity.this.ssdAdapter.setSelected(InputUnitSettingActivity.this.lastValue);
            InputUnitSettingActivity.this.ssdAdapter.notifyDataSetChanged();
            if (InputUnitSettingActivity.this.lastValue == 1) {
                InputUnitSettingActivity.this.listSelect2.setVisibility(0);
            } else {
                InputUnitSettingActivity.this.listSelect2.setVisibility(8);
            }
        }
    };
    private final AdapterView.OnItemClickListener mListOptionClick2 = new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
            int unused = InputUnitSettingActivity.this.lastAdfGuide = i;
            switch (i) {
                case 0:
                    InputUnitSettingActivity.mlAdapter.setList(0, CustomListRowImpl.create().addText(InputUnitSettingActivity.this.getString(R.string.str_settings_right_aligned)).prefixImage(Integer.valueOf(R.C2136drawable.adf_left_adst)).suffixImage(Integer.valueOf(R.C2136drawable.selected)));
                    InputUnitSettingActivity.mlAdapter.setList(1, CustomListRowImpl.create().addText(InputUnitSettingActivity.this.getString(R.string.str_settings_center_aligned)).prefixImage(Integer.valueOf(R.C2136drawable.adf_center_adst)));
                    break;
                case 1:
                    InputUnitSettingActivity.mlAdapter.setList(0, CustomListRowImpl.create().addText(InputUnitSettingActivity.this.getString(R.string.str_settings_right_aligned)).prefixImage(Integer.valueOf(R.C2136drawable.adf_left_adst)));
                    InputUnitSettingActivity.mlAdapter.setList(1, CustomListRowImpl.create().addText(InputUnitSettingActivity.this.getString(R.string.str_settings_center_aligned)).prefixImage(Integer.valueOf(R.C2136drawable.adf_center_adst)).suffixImage(Integer.valueOf(R.C2136drawable.selected)));
                    break;
            }
            InputUnitSettingActivity.mlAdapter.notifyDataSetChanged();
        }
    };
    private CustomListRowAdapter mlAdapter;
    private ScanSettingsDetailAdapter ssdAdapter;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.scan_settings_detail_2);
        Bundle extras = getIntent().getExtras();
        lastValue = extras.getInt(SCAN_SETTINGS_LAST_VALUE);
        lastAdfGuide = extras.getInt(SCAN_SETTINGS_ADF_ALIGNMENT);
        if (this.lastAdfGuide >= 0) {
            displayAdfAlignment = true;
        } else {
            displayAdfAlignment = false;
        }
        listSelect = (ListView) findViewById(R.id.lvScannerSettingOptions);
        listSelect2 = (ListView) findViewById(R.id.lvScannerSettingOptions2);
        makeListCorrespondenceOptions();
        setActionBar(getTitle().toString(), true);
    }

    private void makeListCorrespondenceOptions() {
        setTitle(getString(R.string.str_settings_source_title));
        ArrayList arrayList = new ArrayList();
        switch (this.lastAdfGuide) {
            case 0:
                arrayList.add(CustomListRowImpl.create().addText(getString(R.string.str_settings_right_aligned)).prefixImage(Integer.valueOf(R.C2136drawable.adf_left_adst)).suffixImage(Integer.valueOf(R.C2136drawable.selected)));
                arrayList.add(CustomListRowImpl.create().addText(getString(R.string.str_settings_center_aligned)).prefixImage(Integer.valueOf(R.C2136drawable.adf_center_adst)));
                break;
            case 1:
                arrayList.add(CustomListRowImpl.create().addText(getString(R.string.str_settings_right_aligned)).prefixImage(Integer.valueOf(R.C2136drawable.adf_left_adst)));
                arrayList.add(CustomListRowImpl.create().addText(getString(R.string.str_settings_center_aligned)).prefixImage(Integer.valueOf(R.C2136drawable.adf_center_adst)).suffixImage(Integer.valueOf(R.C2136drawable.selected)));
                break;
        }
        mlAdapter = new CustomListRowAdapter(this, R.layout.com_customline_row, arrayList);
        listSelect2.setAdapter(mlAdapter);
        listSelect2.setOnItemClickListener(mListOptionClick2);
        if (this.lastValue == 1) {
            listSelect2.setVisibility(0);
        } else {
            listSelect2.setVisibility(8);
        }
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put(getString(R.string.str_settings_source_doctable), 0);
        linkedHashMap.put(getString(R.string.str_settings_source_adf), 1);
        ssdAdapter = new ScanSettingsDetailAdapter(getBaseContext(), linkedHashMap, lastValue);
        listSelect.setAdapter(this.ssdAdapter);
        listSelect.setOnItemClickListener(mListOptionClick);
    }

    public void onBackPressed() {
        Intent intent = new Intent();
        intent.putExtra(Constants.SCAN_REFS_SETTINGS_SOURCE, lastValue);
        intent.putExtra(SCAN_SETTINGS_ADF_ALIGNMENT, displayAdfAlignment ? lastAdfGuide : -1);
        setResult(-1, intent);
        finish();
    }

    public static Intent getStartIntent(Context context, int i, int i2) {
        Intent intent = new Intent(context, InputUnitSettingActivity.class);
        intent.putExtra(SCAN_SETTINGS_LAST_VALUE, i);
        intent.putExtra(SCAN_SETTINGS_ADF_ALIGNMENT, i2);
        return intent;
    }

    public static int getInputUnit(Intent intent) {
        if (intent == null) {
            return 0;
        }
        return intent.getIntExtra(Constants.SCAN_REFS_SETTINGS_SOURCE, 0);
    }

    public static int getAdfAlignment(Intent intent) {
        if (intent == null) {
            return -1;
        }
        return intent.getIntExtra(SCAN_SETTINGS_ADF_ALIGNMENT, -1);
    }
}
