private void save() { int interval = ((SeekBar) findViewById(R.id.seekBar)).getProgress(); boolean autoUpdate = ((CheckBox) findViewById(R.id.checkBox)).isChecked(); boolean showPermanent = ((CheckBox) findViewById(R.id.permanent)).isChecked(); boolean notifyOnlyWhenCharging = ((CheckBox) findViewById(R.id.notifyonlycharging)).isChecked(); boolean alwaysShowStartHVAC = ((CheckBox) findViewById(R.id.alwaysshowstarthvac)).isChecked(); final Spinner spinner = (Spinner) findViewById(R.id.spinner_chargelevel); if (showPermanent && !Configuration.showPermanent) { new AlertDialog.Builder(this) .setTitle(getString(R.string.wear_warning)) .setMessage(getString(R.string.undismissible)) .setPositiveButton( getString(R.string.okay), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) {} }) .show(); } Configuration.interval = interval; Configuration.autoUpdate = autoUpdate; Configuration.showPermanent = showPermanent; Configuration.notifyOnlyWhenCharging = notifyOnlyWhenCharging; Configuration.alwaysShowStartHVAC = alwaysShowStartHVAC; Configuration.defaultChargeLevel = spinner.getSelectedItemPosition(); Configuration.save(this); if (autoUpdate) AlarmSetter.setAlarm(this); else AlarmSetter.cancelAlarm(this); // Show the new notification, but don't talk to the server Carwings carwings = new Carwings(this); if (!carwings.lastUpdateTime.equals("")) { LeafNotification.sendNotification(this, carwings); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); final Context context = this; CheckBox metric = (CheckBox) (findViewById(R.id.metric)); metric.setChecked(Configuration.useMetric); metric.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { save(); } }); CheckBox nightupdates = ((CheckBox) (findViewById(R.id.nightupdates))); nightupdates.setChecked(Configuration.noNightUpdates); nightupdates.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { save(); } }); if (Configuration.autoUpdate) AlarmSetter.setAlarm(this); else AlarmSetter.cancelAlarm(this); // Show the new notification, but don't talk to the server Carwings carwings = new Carwings(this); if (!carwings.lastUpdateTime.equals("")) { LeafNotification.sendNotification(this, carwings); } }