package com.handset.serialportsensor.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;

import com.handset.serialportsensor.R;
import com.handset.serialportsensor.account.AccountManager;
import com.handset.serialportsensor.utils.SPUtils;

/**
 * Created by zy on 2019/2/23.
 */

public class ThirdSensorSettingsActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third_sensor_settings);
        Switch sw_sensor = (Switch) findViewById(R.id.sw_sensor);
        boolean sensor_third_enable = SPUtils.getInstance(this).get("sensor_third_enable", false);
        sw_sensor.setChecked(sensor_third_enable);
        sw_sensor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SPUtils.getInstance(ThirdSensorSettingsActivity.this).put("sensor_third_enable", isChecked);
                AccountManager.get().putUserData("sensor_third_enable", isChecked + "");
            }
        });
        TextView tvTitle = findViewById(R.id.title_text);
        ImageView ivBack = findViewById(R.id.title_back);
        tvTitle.setText("第三方传感器弹筒信息开关");
        ivBack.setVisibility(View.VISIBLE);
        ivBack.setOnClickListener((View v) -> ThirdSensorSettingsActivity.this.finish());
    }
}
