[237] | 1 | package net.sabi.pester;
|
---|
| 2 |
|
---|
| 3 | import danger.app.Application;
|
---|
| 4 | import danger.app.Event;
|
---|
| 5 | import danger.ui.ActiveListView;
|
---|
| 6 | import danger.util.ActiveList;
|
---|
[259] | 7 | import danger.util.DEBUG;
|
---|
[237] | 8 |
|
---|
| 9 | public class AlarmListView extends ActiveListView
|
---|
| 10 | implements Resources, Commands {
|
---|
[250] | 11 |
|
---|
| 12 | // XXX some of these shouldn't conceptually be static
|
---|
[237] | 13 | private static AlarmListWindow sAlarmListWindow;
|
---|
[250] | 14 | private static AlarmSetDialog sAlarmSetDialog;
|
---|
[237] | 15 |
|
---|
| 16 | public void onDecoded() {
|
---|
| 17 | sAlarmListWindow = (AlarmListWindow)getWindow();
|
---|
[250] | 18 | setList(Alarms.getList());
|
---|
[237] | 19 | super.onDecoded();
|
---|
| 20 | }
|
---|
| 21 |
|
---|
[250] | 22 | protected AlarmSetDialog alarmSetDialog() {
|
---|
| 23 | if (sAlarmSetDialog == null)
|
---|
| 24 | sAlarmSetDialog = AlarmSetDialog.getDialog();
|
---|
| 25 | return sAlarmSetDialog;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
[237] | 28 | public boolean eventWidgetUp(int widget, Event e) {
|
---|
| 29 | switch (widget) {
|
---|
| 30 | case Event.DEVICE_BUTTON_BACK:
|
---|
| 31 | case Event.DEVICE_BUTTON_CANCEL:
|
---|
[250] | 32 | Application.getCurrentApp().returnToLauncher();
|
---|
[237] | 33 | return true;
|
---|
| 34 | }
|
---|
| 35 | return super.eventWidgetUp(widget, e);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public boolean receiveEvent(Event e) {
|
---|
| 39 | switch (e.type) {
|
---|
| 40 | case EVENT_NEW_ALARM:
|
---|
[250] | 41 | alarmSetDialog().editAlarm(new Alarm(), true);
|
---|
[237] | 42 | return true;
|
---|
| 43 | case EVENT_DISCARD_ALARM:
|
---|
[257] | 44 | // XXX prompt for confirmation
|
---|
[250] | 45 | Alarms.removeAlarm((Alarm)getFocusedItem());
|
---|
[237] | 46 | return true;
|
---|
| 47 | }
|
---|
| 48 | return super.receiveEvent(e);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | protected void itemActivated(Object item) {
|
---|
[250] | 52 | if (item == null)
|
---|
| 53 | return;
|
---|
| 54 | alarmSetDialog().editAlarm((Alarm)item, false);
|
---|
[237] | 55 | }
|
---|
| 56 |
|
---|
| 57 | public int alarmsSet() {
|
---|
| 58 | return getListSize();
|
---|
| 59 | }
|
---|
| 60 | public void onItemAdded(ActiveList list, Object item, int index) {
|
---|
| 61 | sAlarmListWindow.updateAlarmCount();
|
---|
[259] | 62 | super.onItemAdded(list, item, index);
|
---|
| 63 | // super's default behavior is to preserve the existing selection,
|
---|
| 64 | // which is admirable in general, but not what we want
|
---|
[250] | 65 | setFocus(index);
|
---|
[237] | 66 | }
|
---|
| 67 | public void onItemRemoved(ActiveList list, Object item, int index) {
|
---|
[242] | 68 | ((Alarm)item).cancel();
|
---|
[237] | 69 | sAlarmListWindow.updateAlarmCount();
|
---|
| 70 | super.onItemRemoved(list, item, index);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | protected CharSequence getToolTipForItem(Object item) {
|
---|
| 74 | if (item == null) // this is dumb, why do we get asked for a tooltip?
|
---|
| 75 | return null;
|
---|
[249] | 76 | // XXX need to refresh, localize
|
---|
| 77 | Alarm alarm = (Alarm)item;
|
---|
| 78 | return alarm.getDateTimeString() + " - " + alarm.getIntervalString();
|
---|
[237] | 79 | }
|
---|
| 80 | }
|
---|