source: trunk/hiptop/pester/net/sabi/pester/AlarmListView.java@ 255

Last change on this file since 255 was 250, checked in by Nicholas Riley, 18 years ago

Refactor editing, coalese Alarms and alarm list. Try (and fail) to recognize exit from alarm time editor.

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