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
RevLine 
[237]1package net.sabi.pester;
2
3import danger.app.Application;
4import danger.app.Event;
[260]5import danger.ui.AlertWindow;
[237]6import danger.ui.ActiveListView;
7import danger.util.ActiveList;
[259]8import danger.util.DEBUG;
[237]9
10public class AlarmListView extends ActiveListView
11 implements Resources, Commands {
[250]12
13 // XXX some of these shouldn't conceptually be static
[237]14 private static AlarmListWindow sAlarmListWindow;
[250]15 private static AlarmSetDialog sAlarmSetDialog;
[237]16
17 public void onDecoded() {
18 sAlarmListWindow = (AlarmListWindow)getWindow();
[250]19 setList(Alarms.getList());
[237]20 super.onDecoded();
21 }
22
[250]23 protected AlarmSetDialog alarmSetDialog() {
24 if (sAlarmSetDialog == null)
25 sAlarmSetDialog = AlarmSetDialog.getDialog();
26 return sAlarmSetDialog;
27 }
28
[237]29 public boolean eventWidgetUp(int widget, Event e) {
30 switch (widget) {
31 case Event.DEVICE_BUTTON_BACK:
32 case Event.DEVICE_BUTTON_CANCEL:
[250]33 Application.getCurrentApp().returnToLauncher();
[237]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:
[250]42 alarmSetDialog().editAlarm(new Alarm(), true);
[237]43 return true;
[260]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;
[237]53 case EVENT_DISCARD_ALARM:
[250]54 Alarms.removeAlarm((Alarm)getFocusedItem());
[237]55 return true;
56 }
57 return super.receiveEvent(e);
58 }
59
60 protected void itemActivated(Object item) {
[250]61 if (item == null)
62 return;
63 alarmSetDialog().editAlarm((Alarm)item, false);
[237]64 }
65
66 public int alarmsSet() {
67 return getListSize();
68 }
69 public void onItemAdded(ActiveList list, Object item, int index) {
70 sAlarmListWindow.updateAlarmCount();
[259]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
[250]74 setFocus(index);
[237]75 }
76 public void onItemRemoved(ActiveList list, Object item, int index) {
[242]77 ((Alarm)item).cancel();
[237]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;
[249]85 // XXX need to refresh, localize
86 Alarm alarm = (Alarm)item;
87 return alarm.getDateTimeString() + " - " + alarm.getIntervalString();
[237]88 }
89}
Note: See TracBrowser for help on using the repository browser.