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

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

Discard alarm confirmation.

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