- Timestamp:
- 07/29/06 00:53:01 (18 years ago)
- Location:
- trunk/hiptop/pester
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hiptop/pester/locale/en_US/Pester.rsrc
r295 r296 230 230 endDialog 231 231 232 textInputAlert ID_ALARM_ALERT 232 string ID_SNOOZE_LABEL_LEFT "Snooze for" 233 string ID_SNOOZE_LABEL_RIGHT "minute(s)" 234 235 alert ID_ALARM_ALERT 233 236 systemDialog 234 237 title = "Alarm" … … 243 246 shortcut = cancelButton 244 247 button 248 id = ID_RESCHEDULE_BUTTON 245 249 event = EVENT_SET_ALARM 246 250 title = "Reschedule..." 247 251 position = buttonBottom3 248 252 button 253 id = ID_DISMISS_BUTTON 249 254 event = EVENT_DISMISS_ALARM 250 255 title = okButton 251 256 position = buttonBottom1 252 257 shortcut = doneButton 253 textField 254 id = ID_SNOOZE_MINUTES 255 title = "Snooze for minutes:" 256 dontAcceptKeyRepeats 257 initiallySelectAll 258 numericOnly 259 justifyRight 260 maxLength = 2 261 position = top 262 endTextInputAlert 258 endAlert 263 259 264 260 alert ID_LIMIT_ALERT -
trunk/hiptop/pester/net/sabi/pester/Alarm.java
r295 r296 31 31 // transient 32 32 private int mState; 33 private int mAbsoluteFireTime; // valid if periodic and modified since reboot 33 private int mAbsoluteFireTime; // valid if periodic or snoozed, 34 // and modified since reboot 34 35 private danger.app.Alarm mAlarm; 35 36 private int mUID; … … 155 156 if (mState != STATE_SCHEDULED) 156 157 return; 157 if ( getUsesPeriod() &&mAbsoluteFireTime != -1) {158 if (mAbsoluteFireTime != -1) { 158 159 int realSecondsLeft = mAbsoluteFireTime - Hardware.getAbsoluteTime(); 159 160 mDate = new Date(); … … 200 201 public String description() { 201 202 StringBuffer sb = new StringBuffer(); 203 if (mUID != 0) sb.append('(').append(mUID).append(") "); 202 204 switch (mState) { 203 case STATE_INVALID: sb.append("inv alid"); break;204 case STATE_EDITING: sb.append("edi ting"); break;205 case STATE_SCHEDULED: sb.append("sch eduled"); break;205 case STATE_INVALID: sb.append("inv "); break; 206 case STATE_EDITING: sb.append("edi "); break; 207 case STATE_SCHEDULED: sb.append("sch "); break; 206 208 } 207 209 switch (mType) { 210 case TYPE_PERIODIC_REPEATING: 211 sb.append("r-"); 208 212 case TYPE_PERIODIC: 209 sb.append("periodic (").append(mPeriod).append("s) "); break; 210 case TYPE_PERIODIC_REPEATING: 211 sb.append("repeating periodic (").append(mPeriod).append("s) "); 212 break; 213 sb.append("per(").append(mPeriod).append("s)"); 214 if (mState != STATE_SCHEDULED) 215 break; 213 216 case TYPE_DATE: 214 sb.append(" date (").append(getDateTimeString()).append(")"); break;215 } 216 sb.append(" alarm: ");217 sb.append("(").append(getDateTimeString()).append(")"); break; 218 } 219 sb.append(": "); 217 220 sb.append('"').append(mMessage).append('"'); 218 221 return sb.toString(); -
trunk/hiptop/pester/net/sabi/pester/Alarms.java
r295 r296 30 30 } 31 31 32 private void dumpAlarms() { // XXX enable via IPC, make validity checking 33 int i; 34 DEBUG.p("== ALARMS =="); 35 for (i = 0 ; i < size() ; ++i) { 36 DEBUG.p(((Alarm)getItem(i)).description()); 37 } 38 39 } 40 private void dumpDatastore() { 41 int i; 42 DEBUG.p("== DATASTORE CONTENTS =="); 43 byte[][] alarmsData = mDataStore.getRecords(); 44 for (i = 0 ; i < alarmsData.length ; ++i) { 45 Alarm alarm = new Alarm(); 46 alarm.fromByteArray(alarmsData[i]); 47 alarm.setUID(mDataStore.getRecordUID(i)); 48 DEBUG.p(alarm.description()); 49 } 50 } 32 51 void refreshFromDataStore(boolean datastoreRestored) { 33 52 sAlarmList = null; 34 removeAllItems(); 53 if (datastoreRestored) { 54 DEBUG.p("+++ BEFORE RESOLUTION +++"); 55 dumpAlarms(); 56 dumpDatastore(); 57 } 58 removeAllItems(); // XXX no, we can't do this because some alarms may be (a) in the process of being edited, (b) sitting at expiry, or (c) are periodic or snoozed and need their absolute time preserved. Instead, we should just add all the new records - but what about conflicts? 35 59 if (datastoreRestored) 36 mDataStore.doneResolvingConflict(); // resolves UID conflicts 60 mDataStore.doneResolvingConflict(); // renumbers on-device records 61 if (datastoreRestored) { 62 DEBUG.p("+++ AFTER RESOLUTION +++"); 63 dumpDatastore(); 64 } 37 65 byte[][] alarmsData = mDataStore.getRecords(); 38 66 int i; … … 49 77 MessageFinder.setDefaultMessageList(); 50 78 } 79 DEBUG.p("+++ AFTER RESTORATION +++"); 80 dumpAlarms(); 81 dumpDatastore(); 51 82 sAlarmList = this; 52 83 } … … 80 111 return; 81 112 Alarm alarm = (Alarm)item; 82 DEBUG.p("adding: " + alarm +83 " next UID: " + mDataStore.getAutoSyncNextUID());84 113 index = mDataStore.addRecord(alarm.toByteArray()); 85 114 alarm.setUID(mDataStore.getRecordUID(index)); 86 DEBUG.p(" added UID " + alarm.getUID() + " @ " + index);115 DEBUG.p("ADD" + alarm.description()); 87 116 } 88 117 … … 95 124 return; 96 125 mDataStore.removeRecordByUID(uid); 97 DEBUG.p("removed UID " + alarm.getUID()); 126 if (uid < 0) 127 mDataStore.removeRecordByUID(-uid); 128 DEBUG.p("DEL" + alarm.description()); 98 129 } 99 130 … … 103 134 Alarm alarm = (Alarm)item; 104 135 mDataStore.setRecordDataByUID(alarm.getUID(), alarm.toByteArray(), true); 105 DEBUG.p(" updated: " + alarm + " UID " + alarm.getUID());136 DEBUG.p("MOD" + alarm.description()); 106 137 } 107 138 … … 137 168 } else if (e.type == Event.EVENT_DATASTORE_RESTORED) { 138 169 String dbName = (String)e.argument; 139 DEBUG.p(" DATASTORE_RESTORED:" + dbName);140 if ( !dbName.endsWith("alarms")) {170 DEBUG.p("Pester: DATASTORE_RESTORED " + dbName); 171 if (dbName.endsWith("alarms")) { 141 172 // because we only get/set the default alarm on demand 142 173 // there's no need to handle conflicts with the settings... -
trunk/hiptop/pester/net/sabi/pester/Pester.java
r288 r296 3 3 import danger.app.Application; 4 4 import danger.app.Event; 5 import danger.app.IPCMessage; 5 import danger.ui.AlertWindow; 6 import danger.ui.Container; 7 import danger.ui.Control; 8 import danger.ui.Font; 6 9 import danger.ui.Layout; 7 import danger.ui.TextField; 8 import danger.ui.TextInputAlertWindow; 10 import danger.ui.RecordingPen; 9 11 import danger.ui.ScreenWindow; 10 12 import danger.ui.StaticText; 13 import danger.ui.TextField; 11 14 import danger.util.DEBUG; 12 import java.util.Stack;15 import danger.util.TextInputFilter; 13 16 14 17 public class Pester extends Application implements Resources, Commands { 15 18 private static ScreenWindow sAlarmListWindow; 16 private static Stack sAlarmStack;17 19 18 20 public Pester() { 19 21 sAlarmListWindow = (ScreenWindow)getResources().getScreen(ID_ALARM_LIST_SCREEN); 20 22 sAlarmListWindow.show(); 21 sAlarmStack = new Stack(); 23 } 24 25 private void showAlertForAlarm(Alarm alarm) { 26 AlertWindow alert = (AlertWindow)getAlert(ID_ALARM_ALERT, this); 27 alert.setTitle(alarm.getDateTimeString()); 28 alert.setMessage(alarm.getMessage()); 29 alert.setShowTone(alarm.getAlert()); 30 31 Font font = Font.findBoldSystemFont(); 32 StaticText label = new StaticText(getString(ID_SNOOZE_LABEL_LEFT), font); 33 TextField field = new TextField(); 34 field.setAlignment(TextField.JUSTIFY_RIGHT); 35 field.attachInputFilter(TextInputFilter.newLengthFilter(2)); 36 field.attachInputFilter(TextInputFilter.newNumericFilter()); 37 label.setLeft(35); // XXX alert.getMessageView().getLeft() 38 Layout.positionToRight(field, label, 3); 39 Layout.alignBaseline(label, field); 40 alert.addChildBelowMessageArea(label, label.getLeft(), label.getTop()); 41 alert.addChildBelowMessageArea(field, field.getLeft(), field.getTop()); 42 label = new StaticText(getString(ID_SNOOZE_LABEL_RIGHT), font); 43 Layout.positionToRight(label, field, 3); 44 Layout.alignBaseline(label, field); 45 alert.addChildBelowMessageArea(label, label.getLeft(), label.getTop()); 46 47 alert.setEventArgForControlWithID(ID_RESCHEDULE_BUTTON, alarm); 48 alert.setEventArgForControlWithID(ID_DISMISS_BUTTON, alarm); 49 alert.setDefaultFocus(field); 50 51 alert.paint(new RecordingPen()); // force layout 52 int fieldID = alert.incrementMaxChildID(); 53 alert.removeChild(field); 54 alert.addChild(field, fieldID); 55 Control snoozeButton = alert.getControlWithID(ID_SNOOZE_BUTTON); 56 Event event = snoozeButton.getEvent(); 57 event.argument = alert; 58 event.data = fieldID; 59 snoozeButton.setEvent(event); 60 alert.disableButtonOnEmptyField(ID_SNOOZE_BUTTON, fieldID); 61 62 alert.show(AlertWindow.SYSTEM_ALERT_TYPE_ALARM); 22 63 } 23 64 … … 25 66 switch (e.type) { 26 67 case Event.EVENT_ALARM: 27 Alarm alarm = (Alarm)e.argument; 28 TextInputAlertWindow alert = getTextInputAlert(ID_ALARM_ALERT, this); 29 alert.setTitle(alarm.getDateTimeString()); 30 alert.setMessage(alarm.getMessage()); 31 alert.setShowTone(alarm.getAlert()); 32 alert.disableButtonOnEmptyField(ID_SNOOZE_BUTTON, ID_SNOOZE_MINUTES); 33 alert.setShowCancel(false); 34 alert.show(TextInputAlertWindow.SYSTEM_ALERT_TYPE_ALARM); 35 sAlarmStack.push(alarm); 68 showAlertForAlarm((Alarm)e.argument); 36 69 return true; 37 70 case EVENT_SET_ALARM: 38 AlarmSetDialog.getDialog().rescheduleAlarm((Alarm) sAlarmStack.pop());71 AlarmSetDialog.getDialog().rescheduleAlarm((Alarm)e.argument); 39 72 return true; 40 73 case EVENT_SNOOZE_ALARM: 74 AlertWindow alert = (AlertWindow)e.argument; 41 75 int snoozeMinutes = 42 Integer.parseInt( TextInputAlertWindow.43 getTextFieldValue((IPCMessage)e.argument,44 ID_SNOOZE_MINUTES));45 ((Alarm)sAlarmStack.pop()).snoozeForMinutes(snoozeMinutes);76 Integer.parseInt(alert.getControlWithID(e.data).toString()); 77 Control dismissButton = alert.getControlWithID(ID_DISMISS_BUTTON); 78 Alarm alarm = (Alarm)dismissButton.getEvent().argument; 79 alarm.snoozeForMinutes(snoozeMinutes); 46 80 return true; 47 81 case EVENT_DISMISS_ALARM: 48 ((Alarm) sAlarmStack.pop()).dismiss();82 ((Alarm)e.argument).dismiss(); 49 83 return true; 50 84 }
Note:
See TracChangeset
for help on using the changeset viewer.