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);
        btnPrintAll = (Switch) findViewById(R.id.print_all_toggle_button);
        sheets = getIntent().getIntExtra("SHEETS", 10);
        startPage = (TextView) findViewById(R.id.start_page_value);
        start = getIntent().getExtras().getInt("startValue", 1);
        startPage.setText(String.valueOf(this.start));
        endPage = (TextView) findViewById(R.id.end_page_value);
        end = getIntent().getExtras().getInt("endValue", sheets);
        endPage.setText(String.valueOf(this.end));
        startPagePlus = (Button) findViewById(R.id.start_page_plus_button);
        startPageMinus = (Button) findViewById(R.id.start_page_minus_button);
        endPagePlus = (Button) findViewById(R.id.end_page_plus_button);
        endPageMinus = (Button) findViewById(R.id.end_page_minus_button);
        startPagePlus.setOnClickListener(this);
        startPageMinus.setOnClickListener(this);
        endPagePlus.setOnClickListener(this);
        endPageMinus.setOnClickListener(this);
        if (this.start == 1) {
            startPageMinus.setEnabled(false);
            if (this.start < end) {
                startPagePlus.setEnabled(true);
            } else {
                startPagePlus.setEnabled(false);
            }
        }
        if (this.end == sheets) {
            endPagePlus.setEnabled(false);
            if (this.end > start) {
                endPageMinus.setEnabled(true);
            } else {
                endPageMinus.setEnabled(false);
            }
        }
        if (this.start == end) {
            startPagePlus.setEnabled(false);
            endPageMinus.setEnabled(false);
        }
        LongTapRepeatAdapter.bless(this.startPagePlus);
        LongTapRepeatAdapter.bless(this.endPagePlus);
        LongTapRepeatAdapter.bless(this.startPageMinus);
        LongTapRepeatAdapter.bless(this.endPageMinus);
        btnPrintAll.setChecked(getIntent().getExtras().getBoolean("printAll", false));
        if (this.btnPrintAll.isChecked()) {
            startPagePlus.setVisibility(8);
            startPageMinus.setVisibility(8);
            endPagePlus.setVisibility(8);
            endPageMinus.setVisibility(8);
            start = 1;
            end = sheets;
            startPage.setText(String.valueOf(1));
            endPage.setText(String.valueOf(this.sheets));
            if (this.start == 1) {
                startPageMinus.setEnabled(false);
                if (this.start < end) {
                    startPagePlus.setEnabled(true);
                }
            }
            if (this.end == sheets) {
                endPagePlus.setEnabled(false);
                if (this.end > start) {
                    endPageMinus.setEnabled(true);
                }
            }
        }
        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 = end;
                if (i > start) {
                    end = i - 1;
                    endPage.setText(String.valueOf(this.end));
                    if (this.start > 1) {
                        startPageMinus.setEnabled(true);
                    } else {
                        startPageMinus.setEnabled(false);
                    }
                    endPagePlus.setEnabled(true);
                    if (this.end == start) {
                        endPageMinus.setEnabled(false);
                        startPagePlus.setEnabled(false);
                        return;
                    }
                    return;
                }
                return;
            case R.id.end_page_plus_button /*2131231015*/:
                int i2 = end;
                if (i2 < sheets) {
                    end = i2 + 1;
                    endPage.setText(String.valueOf(this.end));
                    endPageMinus.setEnabled(true);
                    startPagePlus.setEnabled(true);
                    if (this.end == sheets) {
                        endPagePlus.setEnabled(false);
                        return;
                    }
                    return;
                }
                return;
            case R.id.start_page_minus_button /*2131231498*/:
                int i3 = start;
                if (i3 > 1) {
                    start = i3 - 1;
                    startPage.setText(String.valueOf(this.start));
                    startPagePlus.setEnabled(true);
                    endPageMinus.setEnabled(true);
                    if (this.start == 1) {
                        startPageMinus.setEnabled(false);
                        return;
                    }
                    return;
                }
                return;
            case R.id.start_page_plus_button /*2131231499*/:
                int i4 = start;
                if (i4 < end) {
                    start = i4 + 1;
                    startPage.setText(String.valueOf(this.start));
                    startPageMinus.setEnabled(true);
                    if (this.start == end) {
                        startPagePlus.setEnabled(false);
                        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", btnPrintAll.isChecked());
        bundle.putInt("startValue", start);
        bundle.putInt("endValue", end);
        intent.putExtras(bundle);
        setResult(-1, intent);
        finish();
        return true;
    }
}
