package epson.print.screen;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Switch;
import android.widget.TextView;
import epson.print.ActivityIACommon;
import epson.print.R;
import epson.print.widgets.LongTapRepeatAdapter;

public class PageRangeSetting extends ActivityIACommon implements View.OnClickListener {
    public static final String PREFS_NAME = "PrintSetting";
    Switch btnPrintAll;
    int end;
    TextView endPage;
    Button endPageMinus;
    Button endPagePlus;
    int sheets;
    int start;
    TextView startPage;
    Button startPageMinus;
    Button startPagePlus;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView((int) R.layout.page_range_layout);
        setActionBar((int) R.string.page_range, true);
        this.btnPrintAll = (Switch) findViewById(R.id.print_all_toggle_button);
        this.sheets = getIntent().getIntExtra("SHEETS", 10);
        this.startPage = (TextView) findViewById(R.id.start_page_value);
        this.start = getIntent().getExtras().getInt("startValue", 1);
        this.startPage.setText(String.valueOf(this.start));
        this.endPage = (TextView) findViewById(R.id.end_page_value);
        this.end = getIntent().getExtras().getInt("endValue", this.sheets);
        this.endPage.setText(String.valueOf(this.end));
        this.startPagePlus = (Button) findViewById(R.id.start_page_plus_button);
        this.startPageMinus = (Button) findViewById(R.id.start_page_minus_button);
        this.endPagePlus = (Button) findViewById(R.id.end_page_plus_button);
        this.endPageMinus = (Button) findViewById(R.id.end_page_minus_button);
        this.startPagePlus.setOnClickListener(this);
        this.startPageMinus.setOnClickListener(this);
        this.endPagePlus.setOnClickListener(this);
        this.endPageMinus.setOnClickListener(this);
        if (this.start == 1) {
            this.startPageMinus.setEnabled(false);
            if (this.start < this.end) {
                this.startPagePlus.setEnabled(true);
            } else {
                this.startPagePlus.setEnabled(false);
            }
        }
        if (this.end == this.sheets) {
            this.endPagePlus.setEnabled(false);
            if (this.end > this.start) {
                this.endPageMinus.setEnabled(true);
            } else {
                this.endPageMinus.setEnabled(false);
            }
        }
        if (this.start == this.end) {
            this.startPagePlus.setEnabled(false);
            this.endPageMinus.setEnabled(false);
        }
        LongTapRepeatAdapter.bless(this.startPagePlus);
        LongTapRepeatAdapter.bless(this.endPagePlus);
        LongTapRepeatAdapter.bless(this.startPageMinus);
        LongTapRepeatAdapter.bless(this.endPageMinus);
        this.btnPrintAll.setChecked(getIntent().getExtras().getBoolean("printAll", false));
        if (this.btnPrintAll.isChecked()) {
            this.startPagePlus.setVisibility(8);
            this.startPageMinus.setVisibility(8);
            this.endPagePlus.setVisibility(8);
            this.endPageMinus.setVisibility(8);
            this.start = 1;
            this.end = this.sheets;
            this.startPage.setText(String.valueOf(1));
            this.endPage.setText(String.valueOf(this.sheets));
            if (this.start == 1) {
                this.startPageMinus.setEnabled(false);
                if (this.start < this.end) {
                    this.startPagePlus.setEnabled(true);
                }
            }
            if (this.end == this.sheets) {
                this.endPagePlus.setEnabled(false);
                if (this.end > this.start) {
                    this.endPageMinus.setEnabled(true);
                }
            }
        }
        this.btnPrintAll.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                if (PageRangeSetting.this.btnPrintAll.isChecked()) {
                    PageRangeSetting.this.startPagePlus.setVisibility(8);
                    PageRangeSetting.this.startPageMinus.setVisibility(8);
                    PageRangeSetting.this.endPagePlus.setVisibility(8);
                    PageRangeSetting.this.endPageMinus.setVisibility(8);
                    PageRangeSetting pageRangeSetting = PageRangeSetting.this;
                    pageRangeSetting.start = 1;
                    pageRangeSetting.end = pageRangeSetting.sheets;
                    PageRangeSetting.this.startPage.setText(String.valueOf(1));
                    PageRangeSetting.this.endPage.setText(String.valueOf(PageRangeSetting.this.sheets));
                    return;
                }
                PageRangeSetting.this.startPagePlus.setVisibility(0);
                PageRangeSetting.this.startPageMinus.setVisibility(0);
                if (PageRangeSetting.this.start == 1) {
                    PageRangeSetting.this.startPageMinus.setEnabled(false);
                    if (PageRangeSetting.this.start < PageRangeSetting.this.end) {
                        PageRangeSetting.this.startPagePlus.setEnabled(true);
                    }
                }
                PageRangeSetting.this.endPagePlus.setVisibility(0);
                PageRangeSetting.this.endPageMinus.setVisibility(0);
                PageRangeSetting.this.startPage.setText(String.valueOf(PageRangeSetting.this.start));
                PageRangeSetting.this.endPage.setText(String.valueOf(PageRangeSetting.this.end));
                if (PageRangeSetting.this.end == PageRangeSetting.this.sheets) {
                    PageRangeSetting.this.endPagePlus.setEnabled(false);
                    if (PageRangeSetting.this.end > PageRangeSetting.this.start) {
                        PageRangeSetting.this.endPageMinus.setEnabled(true);
                    }
                }
            }
        });
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.end_page_minus_button /*2131231014*/:
                int i = this.end;
                if (i > this.start) {
                    this.end = i - 1;
                    this.endPage.setText(String.valueOf(this.end));
                    if (this.start > 1) {
                        this.startPageMinus.setEnabled(true);
                    } else {
                        this.startPageMinus.setEnabled(false);
                    }
                    this.endPagePlus.setEnabled(true);
                    if (this.end == this.start) {
                        this.endPageMinus.setEnabled(false);
                        this.startPagePlus.setEnabled(false);
                        return;
                    }
                    return;
                }
                return;
            case R.id.end_page_plus_button /*2131231015*/:
                int i2 = this.end;
                if (i2 < this.sheets) {
                    this.end = i2 + 1;
                    this.endPage.setText(String.valueOf(this.end));
                    this.endPageMinus.setEnabled(true);
                    this.startPagePlus.setEnabled(true);
                    if (this.end == this.sheets) {
                        this.endPagePlus.setEnabled(false);
                        return;
                    }
                    return;
                }
                return;
            case R.id.start_page_minus_button /*2131231498*/:
                int i3 = this.start;
                if (i3 > 1) {
                    this.start = i3 - 1;
                    this.startPage.setText(String.valueOf(this.start));
                    this.startPagePlus.setEnabled(true);
                    this.endPageMinus.setEnabled(true);
                    if (this.start == 1) {
                        this.startPageMinus.setEnabled(false);
                        return;
                    }
                    return;
                }
                return;
            case R.id.start_page_plus_button /*2131231499*/:
                int i4 = this.start;
                if (i4 < this.end) {
                    this.start = i4 + 1;
                    this.startPage.setText(String.valueOf(this.start));
                    this.startPageMinus.setEnabled(true);
                    if (this.start == this.end) {
                        this.startPagePlus.setEnabled(false);
                        this.endPageMinus.setEnabled(false);
                        return;
                    }
                    return;
                }
                return;
            default:
                return;
        }
    }

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

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != R.id.menuSettingsDone) {
            return super.onOptionsItemSelected(menuItem);
        }
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putBoolean("printAll", this.btnPrintAll.isChecked());
        bundle.putInt("startValue", this.start);
        bundle.putInt("endValue", this.end);
        intent.putExtras(bundle);
        setResult(-1, intent);
        finish();
        return true;
    }
}
