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

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

Get rid of phantom full-size scrollbar; remove border if list is empty.

File size: 3.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;
[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);
[237]30 super.onDecoded();
31 }
32
[250]33 protected AlarmSetDialog alarmSetDialog() {
34 if (sAlarmSetDialog == null)
35 sAlarmSetDialog = AlarmSetDialog.getDialog();
36 return sAlarmSetDialog;
37 }
38
[237]39 public boolean eventWidgetUp(int widget, Event e) {
40 switch (widget) {
41 case Event.DEVICE_BUTTON_BACK:
42 case Event.DEVICE_BUTTON_CANCEL:
[250]43 Application.getCurrentApp().returnToLauncher();
[237]44 return true;
45 }
46 return super.eventWidgetUp(widget, e);
47 }
48
49 public boolean receiveEvent(Event e) {
50 switch (e.type) {
51 case EVENT_NEW_ALARM:
[250]52 alarmSetDialog().editAlarm(new Alarm(), true);
[237]53 return true;
[260]54 case EVENT_CONFIRM_DISCARD_ALARM:
55 AlertWindow alert =
56 Application.getCurrentApp().getAlert(ID_DISCARD_ALERT, this);
57 // XXX localize
58 alert.setMessage("Permanently discard \u201c" +
59 ((Alarm)getFocusedItem()).getMessage() +
60 "\u201d?");
61 alert.show();
62 return true;
[237]63 case EVENT_DISCARD_ALARM:
[250]64 Alarms.removeAlarm((Alarm)getFocusedItem());
[237]65 return true;
[273]66 case Event.EVENT_ALARM: // tooltip invalid
67 // XXX should do this too if the time changes
68 showToolTip();
69 return true;
[237]70 }
71 return super.receiveEvent(e);
72 }
73
74 protected void itemActivated(Object item) {
[250]75 if (item == null)
76 return;
77 alarmSetDialog().editAlarm((Alarm)item, false);
[237]78 }
79
[273]80 protected void itemFocused(Object item) {
81 mToolTipAlarm.deactivate();
82 }
83
84 public void loseFocus() {
85 mToolTipAlarm.deactivate();
86 super.loseFocus();
87 }
88
89 public void showToolTip() {
90 Alarm alarm = (Alarm)getFocusedItem();
91 if (alarm == null)
92 return;
93 Rect rect = new Rect();
94 rect = localToGlobal(getInterestingRect(rect));
95 if (mToolTipWindow != null)
96 mToolTipWindow.hide();
97 mToolTipWindow =
98 ToolTipWindow.showToolTip(alarm.getDateTimeString() + " - " +
99 alarm.getIntervalString(),
100 10, rect.bottom, 1, sAlarmListWindow);
101 int secondsUntilUpdate = alarm.getSecondsUntilNextIntervalStringUpdate();
102 if (secondsUntilUpdate == 0)
103 return;
104 mToolTipAlarm.resetWake(secondsUntilUpdate);
105 }
106
[237]107 public int alarmsSet() {
108 return getListSize();
109 }
110 public void onItemAdded(ActiveList list, Object item, int index) {
111 sAlarmListWindow.updateAlarmCount();
[259]112 super.onItemAdded(list, item, index);
113 // super's default behavior is to preserve the existing selection,
114 // which is admirable in general, but not what we want
[250]115 setFocus(index);
[274]116 setHasBorder(true);
[237]117 }
118 public void onItemRemoved(ActiveList list, Object item, int index) {
[242]119 ((Alarm)item).cancel();
[237]120 sAlarmListWindow.updateAlarmCount();
121 super.onItemRemoved(list, item, index);
[274]122 if (alarmsSet() == 0)
123 setHasBorder(false);
[237]124 }
125}
Note: See TracBrowser for help on using the repository browser.