package com.epson.mobilephone.common.guide;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;

import android.support.p000v4.app.Fragment;
import android.support.p000v4.app.FragmentManager;
import android.support.p000v4.app.FragmentStatePagerAdapter;
import android.support.p000v4.view.ViewPager;

import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.epson.guidelib.C0907R;
import com.epson.mobilephone.common.guide.GuideWebviewFragment;
import java.util.ArrayList;
import java.util.Locale;

public class NoticeGuideActivity extends AppCompatActivity implements GuideWebviewFragment.MyClickListener {
    public static int DIALOG_MODE_OFF = 20001;
    public static int DIALOG_MODE_ON = 20000;
    public static int DIALOG_MODE_ONLY_BUTTON = 20002;
    public static String KEY_BOOT_GROUP = "BOOT_GROUP";
    public static String KEY_BOOT_MODE = "BOOT_MODE";
    public static String KEY_DIALOG_BUTTON_NO = "DIALOG_NO";
    public static String KEY_DIALOG_BUTTON_YES = "DIALOG_YES";
    public static String KEY_DIALOG_MODE = "DIALOG_MODE";
    public static String KEY_DIALOG_TITLE = "DIALOG_TITLE";
    public static String KEY_GUIDE_VER = "GUIDE_VER";
    public static String KEY_HTML_PATH = "HTML_PATH";
    public static int MODE_AUTO = 10001;
    public static int MODE_MANUAL = 10000;
    public String SP_KEY_GUIDE_VER = "GuideVersion";
    private String boot_group;
    private int boot_mode;
    private int dialog_mode;
    private ArrayList<String> htmlpath = new ArrayList<>();
    private MyFragmentStatePagerAdapter mAdapter;
    private Button mCancel;
    private String mDialogButtonNo = "";
    private String mDialogButtonYes = "";
    private TextView mDialogText;
    private String mDialogTextMessage = "";
    private View mGrayLine_Hor;
    private LinearLayout mGuideDialogView;
    private Button mOK;
    private LinearLayout mPageDisplayView;
    private MyViewPager mViewPager;
    private int version;

    protected void onCreate(Bundle bundle) {
        String str;
        super.onCreate(bundle);
        setContentView(C0907R.layout.activity_notice_guide);
        Intent intent = getIntent();
        if (intent != null) {
            this.htmlpath = intent.getStringArrayListExtra(KEY_HTML_PATH);
            if (this.htmlpath.size() == 0) {
                finish();
            }
            this.boot_mode = intent.getIntExtra(KEY_BOOT_MODE, 0);
            this.boot_group = intent.getStringExtra(KEY_BOOT_GROUP);
            this.dialog_mode = intent.getIntExtra(KEY_DIALOG_MODE, 0);
            this.version = intent.getIntExtra(KEY_GUIDE_VER, 0);
            this.mDialogTextMessage = intent.getStringExtra(KEY_DIALOG_TITLE);
            this.mDialogButtonYes = intent.getStringExtra(KEY_DIALOG_BUTTON_YES);
            this.mDialogButtonNo = intent.getStringExtra(KEY_DIALOG_BUTTON_NO);
            if (this.boot_group != null) {
                this.SP_KEY_GUIDE_VER += "-" + this.boot_group;
            }
        }
        if (this.boot_mode == MODE_AUTO) {
            if (this.version <= PreferenceManager.getDefaultSharedPreferences(this).getInt(this.SP_KEY_GUIDE_VER, 0)) {
                finish();
            }
        }
        final MyPageAdapter myPageAdapter = new MyPageAdapter();
        this.mAdapter = new MyFragmentStatePagerAdapter(getSupportFragmentManager(), this.htmlpath);
        this.mViewPager = (MyViewPager) findViewById(C0907R.C0909id.guideViewPager);
        this.mViewPager.setAdapter(this.mAdapter);
        this.mViewPager.setOffscreenPageLimit(2);
        this.mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            public void onPageScrollStateChanged(int i) {
            }

            public void onPageScrolled(int i, float f, int i2) {
            }

            public void onPageSelected(int i) {
                myPageAdapter.changePage(i);
            }
        });
        this.mPageDisplayView = (LinearLayout) findViewById(C0907R.C0909id.pageDisplayViewGroup);
        myPageAdapter.setPageSize(this.mPageDisplayView, this.mAdapter.getCount());
        myPageAdapter.changePage(this.mViewPager.getCurrentItem());
        this.mGuideDialogView = (LinearLayout) findViewById(C0907R.C0909id.guide_dialog_layout);
        this.mGrayLine_Hor = findViewById(C0907R.C0909id.guide_dialog_horizon_gray_line);
        this.mDialogText = (TextView) findViewById(C0907R.C0909id.guide_dialog_message);
        int i = this.dialog_mode;
        if (i == DIALOG_MODE_ON || i == DIALOG_MODE_ONLY_BUTTON) {
            this.mGuideDialogView.setVisibility(0);
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.mGuideDialogView.getLayoutParams();
            marginLayoutParams.width = (int) Utils.dptopx(Utils.getWebViewDP(this, getApplicationContext()) + Utils.LAYOUT_MEARGIN, getApplicationContext());
            this.mGuideDialogView.setLayoutParams(marginLayoutParams);
            this.mOK = (Button) findViewById(C0907R.C0909id.ok_button);
            this.mCancel = (Button) findViewById(C0907R.C0909id.cancel_btn);
            String str2 = this.mDialogButtonYes;
            if (str2 != null) {
                this.mOK.setText(str2);
            }
            String str3 = this.mDialogButtonNo;
            if (str3 != null) {
                this.mCancel.setText(str3);
            }
            this.mOK.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    NoticeGuideActivity.this.setResult(-1);
                    NoticeGuideActivity.this.onClickClose();
                }
            });
            this.mCancel.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    NoticeGuideActivity.this.setResult(0);
                    NoticeGuideActivity.this.onClickClose();
                }
            });
            if (this.dialog_mode == DIALOG_MODE_ON && (str = this.mDialogTextMessage) != null) {
                this.mDialogText.setText(str);
            }
            if (this.dialog_mode == DIALOG_MODE_ONLY_BUTTON) {
                this.mGrayLine_Hor.setVisibility(8);
                this.mDialogText.setVisibility(8);
                this.mOK.setBackground(getResources().getDrawable(C0907R.C0908drawable.rectangle_left_button));
                this.mCancel.setBackground(getResources().getDrawable(C0907R.C0908drawable.rectangle_right_button));
            }
        }
    }

    public void onBackPressed() {
        onClickClose();
    }

    public void onClickClose() {
        if (this.boot_mode == MODE_AUTO) {
            PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(this.SP_KEY_GUIDE_VER, this.version).apply();
        }
        finish();
    }

    public void onConfigurationChanged(Configuration configuration) {
        switch (configuration.orientation) {
            case 1:
                if (this.dialog_mode == DIALOG_MODE_ON) {
                    this.mGuideDialogView.setVisibility(0);
                    break;
                }
                break;
            case 2:
                if (this.dialog_mode == DIALOG_MODE_ON) {
                    this.mGuideDialogView.setVisibility(8);
                    break;
                }
                break;
        }
        super.onConfigurationChanged(configuration);
    }

    public static class MyFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
        private ArrayList<String> HTML_PAGE;
        private int PAGE_LENGTH;

        private MyFragmentStatePagerAdapter(FragmentManager fragmentManager, ArrayList<String> arrayList) {
            super(fragmentManager);
            this.HTML_PAGE = new ArrayList<>();
            this.PAGE_LENGTH = 0;
            this.HTML_PAGE = arrayList;
            this.PAGE_LENGTH = arrayList.size();
        }

        public Fragment getItem(int i) {
            return GuideWebviewFragment.newInstance(String.format(Locale.US, this.HTML_PAGE.get(i), new Object[]{Integer.valueOf(i + 1)}));
        }

        public int getCount() {
            return this.PAGE_LENGTH;
        }
    }

    class MyPageAdapter {
        private ImageView[] mPagePosition;

        private MyPageAdapter() {
        }

        /* access modifiers changed from: private */
        public void setPageSize(@NonNull ViewGroup viewGroup, int i) {
            this.mPagePosition = new ImageView[i];
            int i2 = 0;
            while (i2 < i) {
                ImageView imageView = new ImageView(NoticeGuideActivity.this.getApplicationContext());
                imageView.setImageResource(C0907R.C0908drawable.cycle02);
                int i3 = i2 + 1;
                viewGroup.addView(imageView, i3);
                this.mPagePosition[i2] = imageView;
                i2 = i3;
            }
        }

        private void changePage(int i) {
            int i2 = 0;
            while (true) {
                ImageView[] imageViewArr = this.mPagePosition;
                if (i2 < imageViewArr.length) {
                    if (imageViewArr[i2] != null) {
                        if (i == i2) {
                            imageViewArr[i2].setImageResource(C0907R.C0908drawable.cycle03);
                        } else {
                            imageViewArr[i2].setImageResource(C0907R.C0908drawable.cycle02);
                        }
                    }
                    i2++;
                } else {
                    return;
                }
            }
        }
    }
}
