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

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

Make discard button on set dialog do something again.

File size: 2.1 KB
RevLine 
[237]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 {
[250]10
11 // XXX some of these shouldn't conceptually be static
[237]12 private static AlarmListWindow sAlarmListWindow;
[250]13 private static AlarmSetDialog sAlarmSetDialog;
[237]14
15 public void onDecoded() {
16 sAlarmListWindow = (AlarmListWindow)getWindow();
[250]17 setList(Alarms.getList());
[237]18 super.onDecoded();
19 }
20
[250]21 protected AlarmSetDialog alarmSetDialog() {
22 if (sAlarmSetDialog == null)
23 sAlarmSetDialog = AlarmSetDialog.getDialog();
24 return sAlarmSetDialog;
25 }
26
[237]27 public boolean eventWidgetUp(int widget, Event e) {
28 switch (widget) {
29 case Event.DEVICE_BUTTON_BACK:
30 case Event.DEVICE_BUTTON_CANCEL:
[250]31 Application.getCurrentApp().returnToLauncher();
[237]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:
[250]40 alarmSetDialog().editAlarm(new Alarm(), true);
[237]41 return true;
42 case EVENT_DISCARD_ALARM:
[257]43 // XXX prompt for confirmation
[250]44 Alarms.removeAlarm((Alarm)getFocusedItem());
[237]45 return true;
46 }
47 return super.receiveEvent(e);
48 }
49
50 protected void itemActivated(Object item) {
[250]51 if (item == null)
52 return;
53 alarmSetDialog().editAlarm((Alarm)item, false);
[237]54 }
55
56 public int alarmsSet() {
57 return getListSize();
58 }
59 public void onItemAdded(ActiveList list, Object item, int index) {
60 sAlarmListWindow.updateAlarmCount();
[250]61 setFocus(index);
[237]62 super.onItemAdded(list, item, index);
63 }
64 public void onItemRemoved(ActiveList list, Object item, int index) {
[242]65 ((Alarm)item).cancel();
[237]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;
[249]73 // XXX need to refresh, localize
74 Alarm alarm = (Alarm)item;
75 return alarm.getDateTimeString() + " - " + alarm.getIntervalString();
[237]76 }
77}
Note: See TracBrowser for help on using the repository browser.