use of nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm in project Gadgetbridge by Freeyourgadget.
the class SleepAlarmWidget method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (ACTION.equals(intent.getAction())) {
int userSleepDuration = new ActivityUser().getSleepDuration();
// current timestamp
GregorianCalendar calendar = new GregorianCalendar();
// add preferred sleep duration
calendar.add(Calendar.HOUR_OF_DAY, userSleepDuration);
// overwrite the first alarm and activate it
GBAlarm alarm = GBAlarm.createSingleShot(0, true, calendar);
alarm.store();
if (GBApplication.isRunningLollipopOrLater()) {
setAlarmViaAlarmManager(context, calendar.getTimeInMillis());
}
int hours = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
GB.toast(context, String.format(context.getString(R.string.appwidget_alarms_set), hours, minutes), Toast.LENGTH_SHORT, GB.INFO);
}
}
use of nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm in project Gadgetbridge by Freeyourgadget.
the class GBAlarmListAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup parent) {
final GBAlarm alarm = getItem(position);
if (view == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.alarm_item, parent, false);
}
TextView alarmTime = (TextView) view.findViewById(R.id.alarm_item_time);
Switch isEnabled = (Switch) view.findViewById(R.id.alarm_item_toggle);
TextView isSmartWakeup = (TextView) view.findViewById(R.id.alarm_smart_wakeup);
highlightDay((TextView) view.findViewById(R.id.alarm_item_sunday), alarm.getRepetition(Alarm.ALARM_SUN));
highlightDay((TextView) view.findViewById(R.id.alarm_item_monday), alarm.getRepetition(Alarm.ALARM_MON));
highlightDay((TextView) view.findViewById(R.id.alarm_item_tuesday), alarm.getRepetition(Alarm.ALARM_TUE));
highlightDay((TextView) view.findViewById(R.id.alarm_item_wednesday), alarm.getRepetition(Alarm.ALARM_WED));
highlightDay((TextView) view.findViewById(R.id.alarm_item_thursday), alarm.getRepetition(Alarm.ALARM_THU));
highlightDay((TextView) view.findViewById(R.id.alarm_item_friday), alarm.getRepetition(Alarm.ALARM_FRI));
highlightDay((TextView) view.findViewById(R.id.alarm_item_saturday), alarm.getRepetition(Alarm.ALARM_SAT));
isEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
alarm.setEnabled(isChecked);
update(alarm);
}
});
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ConfigureAlarms) mContext).configureAlarm(alarm);
}
});
alarmTime.setText(alarm.getTime());
isEnabled.setChecked(alarm.isEnabled());
if (alarm.isSmartWakeup()) {
isSmartWakeup.setVisibility(TextView.VISIBLE);
} else {
isSmartWakeup.setVisibility(TextView.GONE);
}
return view;
}
use of nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm in project Gadgetbridge by Freeyourgadget.
the class GBAlarmListAdapter method setAlarmList.
public void setAlarmList(Set<String> preferencesAlarmListSet, int reservedSlots) {
alarmList = new ArrayList<>();
for (String alarmString : preferencesAlarmListSet) {
alarmList.add(new GBAlarm(alarmString));
}
Collections.sort(alarmList);
//cannot do this earlier because the Set is not guaranteed to be in order by ID
alarmList.subList(alarmList.size() - reservedSlots, alarmList.size()).clear();
}
Aggregations