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;
|
---|
7 | import danger.util.DEBUG;
|
---|
8 |
|
---|
9 | public class AlarmListView extends ActiveListView
|
---|
10 | implements Resources, Commands {
|
---|
11 |
|
---|
12 | // XXX some of these shouldn't conceptually be static
|
---|
13 | private static AlarmListWindow sAlarmListWindow;
|
---|
14 | private static AlarmSetDialog sAlarmSetDialog;
|
---|
15 |
|
---|
16 | public void onDecoded() {
|
---|
17 | sAlarmListWindow = (AlarmListWindow)getWindow();
|
---|
18 | setList(Alarms.getList());
|
---|
19 | super.onDecoded();
|
---|
20 | }
|
---|
21 |
|
---|
22 | protected AlarmSetDialog alarmSetDialog() {
|
---|
23 | if (sAlarmSetDialog == null)
|
---|
24 | sAlarmSetDialog = AlarmSetDialog.getDialog();
|
---|
25 | return sAlarmSetDialog;
|
---|
26 | }
|
---|
27 |
|
---|
28 | public boolean eventWidgetUp(int widget, Event e) {
|
---|
29 | switch (widget) {
|
---|
30 | case Event.DEVICE_BUTTON_BACK:
|
---|
31 | case Event.DEVICE_BUTTON_CANCEL:
|
---|
32 | Application.getCurrentApp().returnToLauncher();
|
---|
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:
|
---|
41 | alarmSetDialog().editAlarm(new Alarm(), true);
|
---|
42 | return true;
|
---|
43 | case EVENT_DISCARD_ALARM:
|
---|
44 | // XXX prompt for confirmation
|
---|
45 | Alarms.removeAlarm((Alarm)getFocusedItem());
|
---|
46 | return true;
|
---|
47 | }
|
---|
48 | return super.receiveEvent(e);
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected void itemActivated(Object item) {
|
---|
52 | if (item == null)
|
---|
53 | return;
|
---|
54 | alarmSetDialog().editAlarm((Alarm)item, false);
|
---|
55 | }
|
---|
56 |
|
---|
57 | public int alarmsSet() {
|
---|
58 | return getListSize();
|
---|
59 | }
|
---|
60 | public void onItemAdded(ActiveList list, Object item, int index) {
|
---|
61 | sAlarmListWindow.updateAlarmCount();
|
---|
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
|
---|
65 | setFocus(index);
|
---|
66 | }
|
---|
67 | public void onItemRemoved(ActiveList list, Object item, int index) {
|
---|
68 | ((Alarm)item).cancel();
|
---|
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;
|
---|
76 | // XXX need to refresh, localize
|
---|
77 | Alarm alarm = (Alarm)item;
|
---|
78 | return alarm.getDateTimeString() + " - " + alarm.getIntervalString();
|
---|
79 | }
|
---|
80 | }
|
---|