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

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

Fix bug with alarm update interval; update tooltip when time changes.

File size: 3.6 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;
[273]7import danger.ui.Rect;
8import danger.ui.ToolTipWindow;
[237]9import danger.util.ActiveList;
[259]10import danger.util.DEBUG;
[237]11
12public class AlarmListView extends ActiveListView
13 implements Resources, Commands {
[250]14
15 // XXX some of these shouldn't conceptually be static
[237]16 private static AlarmListWindow sAlarmListWindow;
[250]17 private static AlarmSetDialog sAlarmSetDialog;
[237]18
[273]19 private danger.app.Alarm mToolTipAlarm;
20 private ToolTipWindow mToolTipWindow;
21
[237]22 public void onDecoded() {
23 sAlarmListWindow = (AlarmListWindow)getWindow();
[274]24 setAutoResize(true);
25 setHasBorder(false); // this doesn't work in the rsrc file
[250]26 setList(Alarms.getList());
[274]27 if (alarmsSet() > 0)
28 setHasBorder(true);
[273]29 mToolTipAlarm = new danger.app.Alarm(0, this);
[275]30 Application.registerForEvent(this, Event.EVENT_TIME_CHANGED);
[237]31 super.onDecoded();
32 }
33
[250]34 protected AlarmSetDialog alarmSetDialog() {
35 if (sAlarmSetDialog == null)
36 sAlarmSetDialog = AlarmSetDialog.getDialog();
37 return sAlarmSetDialog;
38 }
39
[237]40 public boolean eventWidgetUp(int widget, Event e) {
41 switch (widget) {
42 case Event.DEVICE_BUTTON_BACK:
43 case Event.DEVICE_BUTTON_CANCEL:
[250]44 Application.getCurrentApp().returnToLauncher();
[237]45 return true;
46 }
47 return super.eventWidgetUp(widget, e);
48 }
49
50 public boolean receiveEvent(Event e) {
51 switch (e.type) {
52 case EVENT_NEW_ALARM:
[250]53 alarmSetDialog().editAlarm(new Alarm(), true);
[237]54 return true;
[260]55 case EVENT_CONFIRM_DISCARD_ALARM:
56 AlertWindow alert =
57 Application.getCurrentApp().getAlert(ID_DISCARD_ALERT, this);
58 // XXX localize
59 alert.setMessage("Permanently discard \u201c" +
60 ((Alarm)getFocusedItem()).getMessage() +
61 "\u201d?");
62 alert.show();
63 return true;
[237]64 case EVENT_DISCARD_ALARM:
[250]65 Alarms.removeAlarm((Alarm)getFocusedItem());
[237]66 return true;
[275]67 case Event.EVENT_TIME_CHANGED:
68 if (mToolTipWindow == null || !mToolTipWindow.isVisible())
69 return true;
[273]70 case Event.EVENT_ALARM: // tooltip invalid
71 showToolTip();
72 return true;
[237]73 }
74 return super.receiveEvent(e);
75 }
76
77 protected void itemActivated(Object item) {
[250]78 if (item == null)
79 return;
80 alarmSetDialog().editAlarm((Alarm)item, false);
[237]81 }
82
[273]83 protected void itemFocused(Object item) {
84 mToolTipAlarm.deactivate();
85 }
86
87 public void loseFocus() {
88 mToolTipAlarm.deactivate();
89 super.loseFocus();
90 }
91
92 public void showToolTip() {
93 Alarm alarm = (Alarm)getFocusedItem();
94 if (alarm == null)
95 return;
96 Rect rect = new Rect();
97 rect = localToGlobal(getInterestingRect(rect));
98 if (mToolTipWindow != null)
99 mToolTipWindow.hide();
100 mToolTipWindow =
101 ToolTipWindow.showToolTip(alarm.getDateTimeString() + " - " +
102 alarm.getIntervalString(),
103 10, rect.bottom, 1, sAlarmListWindow);
104 int secondsUntilUpdate = alarm.getSecondsUntilNextIntervalStringUpdate();
105 if (secondsUntilUpdate == 0)
106 return;
107 mToolTipAlarm.resetWake(secondsUntilUpdate);
108 }
109
[237]110 public int alarmsSet() {
111 return getListSize();
112 }
113 public void onItemAdded(ActiveList list, Object item, int index) {
114 sAlarmListWindow.updateAlarmCount();
[259]115 super.onItemAdded(list, item, index);
116 // super's default behavior is to preserve the existing selection,
117 // which is admirable in general, but not what we want
[250]118 setFocus(index);
[274]119 setHasBorder(true);
[237]120 }
121 public void onItemRemoved(ActiveList list, Object item, int index) {
[242]122 ((Alarm)item).cancel();
[237]123 sAlarmListWindow.updateAlarmCount();
124 super.onItemRemoved(list, item, index);
[274]125 if (alarmsSet() == 0)
126 setHasBorder(false);
[237]127 }
128}
Note: See TracBrowser for help on using the repository browser.