package com.electric.chargingpile.activity; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.ToggleButton; import com.electric.chargingpile.R; import com.electric.chargingpile.manager.ProfileManager; import com.electric.chargingpile.util.BarColorUtil; import com.umeng.analytics.MobclickAgent; import java.util.HashMap; import java.util.Map; public class RoutePreferenceActivity extends Activity implements View.OnClickListener { private static final String TAG = "RoutePreferenceActivity"; private ToggleButton tb_dbyd , tb_bmsf , tb_bzgs , tb_gsyx; private ImageView iv_back; private boolean tag = false; public static final int REQUSET = 11; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_route_preference); BarColorUtil.initStatusBarColor(RoutePreferenceActivity.this); initViews(); } private void initViews(){ iv_back = (ImageView) findViewById(R.id.iv_back); iv_back.setOnClickListener(this); tb_dbyd = (ToggleButton) findViewById(R.id.tb_dbyd); tb_dbyd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ //选中 // Toast.makeText(getApplicationContext(),"yes",Toast.LENGTH_SHORT).show(); }else{ //未选中 // Toast.makeText(getApplicationContext(),"no",Toast.LENGTH_SHORT).show(); } } });// 添加监听事件 tb_bmsf = (ToggleButton) findViewById(R.id.tb_bmsf); tb_bmsf.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ //选中 // Toast.makeText(getApplicationContext(),"yes",Toast.LENGTH_SHORT).show(); if (tb_gsyx.isChecked()){ tb_gsyx.setChecked(false); ProfileManager.getInstance().setGsyx(getApplicationContext(),false); } }else{ //未选中 // Toast.makeText(getApplicationContext(),"no",Toast.LENGTH_SHORT).show(); } } });// 添加监听事件 tb_bzgs = (ToggleButton) findViewById(R.id.tb_bzgs); tb_bzgs.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ //选中 // Toast.makeText(getApplicationContext(),"yes",Toast.LENGTH_SHORT).show(); if (tb_gsyx.isChecked()){ tb_gsyx.setChecked(false); ProfileManager.getInstance().setGsyx(getApplicationContext(),false); } }else{ //未选中 // Toast.makeText(getApplicationContext(),"no",Toast.LENGTH_SHORT).show(); } } });// 添加监听事件 tb_gsyx = (ToggleButton) findViewById(R.id.tb_gsyx); tb_gsyx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ //选中 // Toast.makeText(getApplicationContext(),"yes",Toast.LENGTH_SHORT).show(); if (tb_bmsf.isChecked()){ tb_bmsf.setChecked(false); ProfileManager.getInstance().setBmsf(getApplicationContext(),false); } if (tb_bzgs.isChecked()){ tb_bzgs.setChecked(false); ProfileManager.getInstance().setBzgs(getApplicationContext(),false); } }else{ //未选中 // Toast.makeText(getApplicationContext(),"no",Toast.LENGTH_SHORT).show(); } } });// 添加监听事件 tb_bmsf.setOnClickListener(this); tb_bzgs.setOnClickListener(this); tb_gsyx.setOnClickListener(this); tb_dbyd.setOnClickListener(this); if (ProfileManager.getInstance().getBzgs(getApplicationContext()) == false){ tb_bzgs.setChecked(false); }else { tb_bzgs.setChecked(true); } if (ProfileManager.getInstance().getGsyx(getApplicationContext()) == false){ tb_gsyx.setChecked(false); }else { tb_gsyx.setChecked(true); } if (ProfileManager.getInstance().getBmsf(getApplicationContext()) == false){ tb_bmsf.setChecked(false); }else { tb_bmsf.setChecked(true); } if (ProfileManager.getInstance().getDbyd(getApplicationContext()) == false){ tb_dbyd.setChecked(false); }else { tb_dbyd.setChecked(true); } } @Override public void onClick(View v) { switch (v.getId()){ case R.id.iv_back: if (tag == false){ finish(); }else { ProfileManager.getInstance().setDbyd(getApplicationContext(), tb_dbyd.isChecked()); ProfileManager.getInstance().setBmsf(getApplicationContext(), tb_bmsf.isChecked()); ProfileManager.getInstance().setGsyx(getApplicationContext(), tb_gsyx.isChecked()); ProfileManager.getInstance().setBzgs(getApplicationContext(), tb_bzgs.isChecked()); setResult(RESULT_OK); Map map = new HashMap<>(); map.put("躲避拥堵",tb_dbyd.isChecked()+""); map.put("避免收费",tb_bmsf.isChecked()+""); map.put("高速优先",tb_gsyx.isChecked()+""); map.put("不走高速",tb_bzgs.isChecked()+""); MobclickAgent.onEvent(getApplicationContext(),"0302",map); map.clear(); finish(); } break; case R.id.tb_bmsf: tag = true; // Log.e(TAG, "onClick: tag"+tag ); break; case R.id.tb_gsyx: tag = true; // Log.e(TAG, "onClick: tag"+tag ); break; case R.id.tb_bzgs: tag = true; // Log.e(TAG, "onClick: tag"+tag ); break; case R.id.tb_dbyd: tag = true; // Log.e(TAG, "onClick: tag"+tag ); break; default: break; } } }