package com.mjsheng.myappstore.activity;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.base.BaseActivity;
import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.utils.MySQLData;
import com.mjsheng.myappstore.view.ToggleButton;
import com.mjsheng.myappstore.widget.Sound;


/**
 * Created by chris on 2015/12/4.
 */
public class SettingActivity extends BaseActivity implements View.OnClickListener {
    private boolean selector = false;
    private boolean mIsPasswordLock;
    private ImageView toBackImg;
    private TextView statementTv;
    private ToggleButton toggleBtn;

    private Sound sound;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        sound = new Sound(this);
        initView();
    }

    private void initView() {
        toBackImg = (ImageView) findViewById(R.id.iv_selecter_back);
        statementTv = (TextView) findViewById(R.id.tv_statement);
        statementTv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        statementTv.getPaint().setAntiAlias(true);//抗锯齿
        mIsPasswordLock = MySQLData.GetBooleanData(SettingActivity.this,  CommonDatas.SP_PASSWORD_LOCK);

        toggleBtn = (ToggleButton) findViewById(R.id.iv_setting);
        toggleBtn.setOnToggleChanged(new ToggleButton.OnToggleChanged() {
            @Override
            public void onToggle(boolean on) {
                if (selector == false) {
                    selector = true;
                } else {
                    selector = false;
                }
            }
        });

        if (mIsPasswordLock) {
            selector = true;
            toggleBtn.setToggleOn();
        } else {
            selector = false;
            toggleBtn.setToggleOff();
        }

        toBackImg.setOnClickListener(this);
        statementTv.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        sound.playSoundEffect();
        switch (v.getId()) {
            case R.id.tv_statement:
                Intent intent = new Intent();
                intent.setClass(this, StatementActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(intent);
                overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
                break;
            case R.id.iv_selecter_back:
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MySQLData.SetBooleanData(SettingActivity.this, CommonDatas.SP_PASSWORD_LOCK, selector);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
    }

}
