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