[237] | 1 | package net.sabi.pester;
|
---|
| 2 |
|
---|
| 3 | import danger.app.Application;
|
---|
[242] | 4 | import danger.app.Event;
|
---|
[296] | 5 | import danger.ui.AlertWindow;
|
---|
| 6 | import danger.ui.Container;
|
---|
| 7 | import danger.ui.Control;
|
---|
| 8 | import danger.ui.Font;
|
---|
[287] | 9 | import danger.ui.Layout;
|
---|
[296] | 10 | import danger.ui.RecordingPen;
|
---|
[237] | 11 | import danger.ui.ScreenWindow;
|
---|
[287] | 12 | import danger.ui.StaticText;
|
---|
[296] | 13 | import danger.ui.TextField;
|
---|
[242] | 14 | import danger.util.DEBUG;
|
---|
[296] | 15 | import danger.util.TextInputFilter;
|
---|
[237] | 16 |
|
---|
| 17 | public class Pester extends Application implements Resources, Commands {
|
---|
[242] | 18 | private static ScreenWindow sAlarmListWindow;
|
---|
| 19 |
|
---|
[237] | 20 | public Pester() {
|
---|
[242] | 21 | sAlarmListWindow = (ScreenWindow)getResources().getScreen(ID_ALARM_LIST_SCREEN);
|
---|
| 22 | sAlarmListWindow.show();
|
---|
[237] | 23 | }
|
---|
| 24 |
|
---|
[296] | 25 | private void showAlertForAlarm(Alarm alarm) {
|
---|
| 26 | AlertWindow alert = (AlertWindow)getAlert(ID_ALARM_ALERT, this);
|
---|
| 27 | alert.setTitle(alarm.getDateTimeString());
|
---|
| 28 | alert.setMessage(alarm.getMessage());
|
---|
| 29 | alert.setShowTone(alarm.getAlert());
|
---|
| 30 |
|
---|
| 31 | Font font = Font.findBoldSystemFont();
|
---|
| 32 | StaticText label = new StaticText(getString(ID_SNOOZE_LABEL_LEFT), font);
|
---|
| 33 | TextField field = new TextField();
|
---|
| 34 | field.setAlignment(TextField.JUSTIFY_RIGHT);
|
---|
| 35 | field.attachInputFilter(TextInputFilter.newLengthFilter(2));
|
---|
| 36 | field.attachInputFilter(TextInputFilter.newNumericFilter());
|
---|
| 37 | label.setLeft(35); // XXX alert.getMessageView().getLeft()
|
---|
| 38 | Layout.positionToRight(field, label, 3);
|
---|
| 39 | Layout.alignBaseline(label, field);
|
---|
| 40 | alert.addChildBelowMessageArea(label, label.getLeft(), label.getTop());
|
---|
| 41 | alert.addChildBelowMessageArea(field, field.getLeft(), field.getTop());
|
---|
| 42 | label = new StaticText(getString(ID_SNOOZE_LABEL_RIGHT), font);
|
---|
| 43 | Layout.positionToRight(label, field, 3);
|
---|
| 44 | Layout.alignBaseline(label, field);
|
---|
| 45 | alert.addChildBelowMessageArea(label, label.getLeft(), label.getTop());
|
---|
| 46 |
|
---|
| 47 | alert.setEventArgForControlWithID(ID_RESCHEDULE_BUTTON, alarm);
|
---|
| 48 | alert.setEventArgForControlWithID(ID_DISMISS_BUTTON, alarm);
|
---|
| 49 | alert.setDefaultFocus(field);
|
---|
| 50 |
|
---|
| 51 | alert.paint(new RecordingPen()); // force layout
|
---|
| 52 | int fieldID = alert.incrementMaxChildID();
|
---|
| 53 | alert.removeChild(field);
|
---|
| 54 | alert.addChild(field, fieldID);
|
---|
| 55 | Control snoozeButton = alert.getControlWithID(ID_SNOOZE_BUTTON);
|
---|
| 56 | Event event = snoozeButton.getEvent();
|
---|
| 57 | event.argument = alert;
|
---|
| 58 | event.data = fieldID;
|
---|
| 59 | snoozeButton.setEvent(event);
|
---|
| 60 | alert.disableButtonOnEmptyField(ID_SNOOZE_BUTTON, fieldID);
|
---|
| 61 |
|
---|
| 62 | alert.show(AlertWindow.SYSTEM_ALERT_TYPE_ALARM);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[242] | 65 | public boolean receiveEvent(Event e) {
|
---|
| 66 | switch (e.type) {
|
---|
| 67 | case Event.EVENT_ALARM:
|
---|
[296] | 68 | showAlertForAlarm((Alarm)e.argument);
|
---|
[242] | 69 | return true;
|
---|
[287] | 70 | case EVENT_SET_ALARM:
|
---|
[296] | 71 | AlarmSetDialog.getDialog().rescheduleAlarm((Alarm)e.argument);
|
---|
[287] | 72 | return true;
|
---|
| 73 | case EVENT_SNOOZE_ALARM:
|
---|
[296] | 74 | AlertWindow alert = (AlertWindow)e.argument;
|
---|
[288] | 75 | int snoozeMinutes =
|
---|
[296] | 76 | Integer.parseInt(alert.getControlWithID(e.data).toString());
|
---|
| 77 | Control dismissButton = alert.getControlWithID(ID_DISMISS_BUTTON);
|
---|
| 78 | Alarm alarm = (Alarm)dismissButton.getEvent().argument;
|
---|
| 79 | alarm.snoozeForMinutes(snoozeMinutes);
|
---|
[287] | 80 | return true;
|
---|
[242] | 81 | case EVENT_DISMISS_ALARM:
|
---|
[296] | 82 | ((Alarm)e.argument).dismiss();
|
---|
[242] | 83 | return true;
|
---|
| 84 | }
|
---|
| 85 | return super.receiveEvent(e);
|
---|
| 86 | }
|
---|
| 87 | }
|
---|