2015-06-24 20:14:08 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.os.Bundle;
|
2015-06-25 14:34:21 +02:00
|
|
|
import android.os.Parcelable;
|
2015-06-24 20:14:08 +02:00
|
|
|
import android.text.format.DateFormat;
|
2015-06-26 17:22:42 +02:00
|
|
|
import android.view.MenuItem;
|
2015-06-27 18:32:13 +02:00
|
|
|
import android.widget.CheckBox;
|
2015-06-24 20:14:08 +02:00
|
|
|
import android.widget.TimePicker;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2015-09-24 14:45:21 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm;
|
2015-06-24 20:14:08 +02:00
|
|
|
|
|
|
|
public class AlarmDetails extends Activity {
|
|
|
|
|
|
|
|
private GBAlarm alarm;
|
|
|
|
private TimePicker timePicker;
|
2015-06-27 18:32:13 +02:00
|
|
|
private CheckBox cbSmartWakeup;
|
|
|
|
private CheckBox cbMonday;
|
|
|
|
private CheckBox cbTuesday;
|
|
|
|
private CheckBox cbWednesday;
|
|
|
|
private CheckBox cbThursday;
|
|
|
|
private CheckBox cbFriday;
|
|
|
|
private CheckBox cbSaturday;
|
|
|
|
private CheckBox cbSunday;
|
2015-06-24 20:14:08 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_alarm_details);
|
|
|
|
|
2015-06-25 14:34:21 +02:00
|
|
|
Parcelable p = getIntent().getExtras().getParcelable("alarm");
|
|
|
|
alarm = (GBAlarm) p;
|
|
|
|
|
|
|
|
timePicker = (TimePicker) findViewById(R.id.alarm_time_picker);
|
2015-06-27 18:32:13 +02:00
|
|
|
cbSmartWakeup = (CheckBox) findViewById(R.id.alarm_cb_smart_wakeup);
|
|
|
|
cbMonday = (CheckBox) findViewById(R.id.alarm_cb_mon);
|
|
|
|
cbTuesday = (CheckBox) findViewById(R.id.alarm_cb_tue);
|
|
|
|
cbWednesday = (CheckBox) findViewById(R.id.alarm_cb_wed);
|
|
|
|
cbThursday = (CheckBox) findViewById(R.id.alarm_cb_thu);
|
|
|
|
cbFriday = (CheckBox) findViewById(R.id.alarm_cb_fri);
|
|
|
|
cbSaturday = (CheckBox) findViewById(R.id.alarm_cb_sat);
|
|
|
|
cbSunday = (CheckBox) findViewById(R.id.alarm_cb_sun);
|
2015-06-25 14:34:21 +02:00
|
|
|
|
|
|
|
timePicker.setIs24HourView(DateFormat.is24HourFormat(GBApplication.getContext()));
|
|
|
|
timePicker.setCurrentHour(alarm.getHour());
|
|
|
|
timePicker.setCurrentMinute(alarm.getMinute());
|
|
|
|
|
2015-06-27 18:32:13 +02:00
|
|
|
cbSmartWakeup.setChecked(alarm.isSmartWakeup());
|
2015-06-25 14:34:21 +02:00
|
|
|
|
2015-06-27 18:32:13 +02:00
|
|
|
cbMonday.setChecked(alarm.getRepetition(GBAlarm.ALARM_MON));
|
|
|
|
cbTuesday.setChecked(alarm.getRepetition(GBAlarm.ALARM_TUE));
|
|
|
|
cbWednesday.setChecked(alarm.getRepetition(GBAlarm.ALARM_WED));
|
|
|
|
cbThursday.setChecked(alarm.getRepetition(GBAlarm.ALARM_THU));
|
|
|
|
cbFriday.setChecked(alarm.getRepetition(GBAlarm.ALARM_FRI));
|
|
|
|
cbSaturday.setChecked(alarm.getRepetition(GBAlarm.ALARM_SAT));
|
|
|
|
cbSunday.setChecked(alarm.getRepetition(GBAlarm.ALARM_SUN));
|
2015-06-24 20:14:08 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-26 17:22:42 +02:00
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
// back button
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateAlarm() {
|
2015-06-27 18:32:13 +02:00
|
|
|
alarm.setSmartWakeup(cbSmartWakeup.isChecked());
|
|
|
|
alarm.setRepetition(cbMonday.isChecked(), cbTuesday.isChecked(), cbWednesday.isChecked(), cbThursday.isChecked(), cbFriday.isChecked(), cbSaturday.isChecked(), cbSunday.isChecked());
|
2015-06-24 20:14:08 +02:00
|
|
|
alarm.setHour(timePicker.getCurrentHour());
|
|
|
|
alarm.setMinute(timePicker.getCurrentMinute());
|
2015-06-26 17:22:42 +02:00
|
|
|
alarm.store();
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|
2015-10-18 23:52:59 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
updateAlarm();
|
|
|
|
super.onPause();
|
|
|
|
}
|
2015-06-24 20:14:08 +02:00
|
|
|
}
|