Changeset 276 for trunk/hiptop/pester/net/sabi
- Timestamp:
- 07/22/06 08:45:34 (18 years ago)
- Location:
- trunk/hiptop/pester/net/sabi/pester
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hiptop/pester/net/sabi/pester/Alarm.java
r275 r276 32 32 private int mAbsoluteFireTime; // only valid if periodic 33 33 private danger.app.Alarm mAlarm; 34 private int mUID; 34 35 35 36 public Alarm() { 36 37 mState = STATE_INVALID; 37 38 mAlarm = new danger.app.Alarm(0, Application.getCurrentApp(), this); 39 mUID = 0; 38 40 } 39 41 … … 55 57 public RingToneObject getAlert() { 56 58 return mAlert; 59 } 60 public int getUID() { 61 return mUID; 57 62 } 58 63 … … 70 75 public void setAlert(RingToneObject alert) { 71 76 mAlert = alert.isValid() ? alert : null; 77 } 78 public void setUID(int uid) { 79 mUID = uid; 72 80 } 73 81 -
trunk/hiptop/pester/net/sabi/pester/AlarmListView.java
r275 r276 22 22 public void onDecoded() { 23 23 sAlarmListWindow = (AlarmListWindow)getWindow(); 24 mToolTipAlarm = new danger.app.Alarm(0, this); 24 25 setAutoResize(true); 25 setHasBorder(false); // this doesn't work in the rsrc file26 26 setList(Alarms.getList()); 27 if (alarmsSet() > 0) 28 setHasBorder(true); 29 mToolTipAlarm = new danger.app.Alarm(0, this); 27 if (alarmsSet() == 0) 28 setHasBorder(false); // this doesn't work in the rsrc file 30 29 Application.registerForEvent(this, Event.EVENT_TIME_CHANGED); 31 30 super.onDecoded(); … … 65 64 Alarms.removeAlarm((Alarm)getFocusedItem()); 66 65 return true; 67 case Event.EVENT_TIME_CHANGED: 66 case Event.EVENT_TIME_CHANGED: // XXX EVENT_TIME_FORMAT_CHANGED too 68 67 if (mToolTipWindow == null || !mToolTipWindow.isVisible()) 69 68 return true; -
trunk/hiptop/pester/net/sabi/pester/Alarms.java
r259 r276 9 9 import danger.internal.Date; 10 10 import danger.util.StdActiveList; 11 import danger.util.DEBUG; 11 12 12 13 public class Alarms extends StdActiveList { … … 22 23 private Alarms() { 23 24 mDataStore = DataStore.createDataStore("alarms", true /* auto sync */); 25 byte[][] alarmsData = mDataStore.getRecords(); 26 int i; 27 for (i = 0 ; i < alarmsData.length ; ++i) { 28 Alarm alarm = new Alarm(); 29 alarm.fromByteArray(alarmsData[i]); 30 alarm.setUID(mDataStore.getRecordUID(i)); 31 insertItemSorted(alarm, alarm); 32 alarm.resume(); 33 } 24 34 } 25 35 26 36 public static Alarms getList() { 27 37 if (sAlarmList == null) { 38 Application.registerForEvent(sListener, Event.EVENT_TIME_CHANGED); 39 sSettingsDB = new SettingsDB("settings", true /* auto sync */); 40 sListener = new Listener(); 28 41 sAlarmList = new Alarms(); 29 sListener = new Listener();30 sSettingsDB = new SettingsDB("settings", true /* auto sync */);31 Application.registerForEvent(sListener, Event.EVENT_TIME_CHANGED);32 42 } 33 43 return sAlarmList; … … 39 49 public static void removeAlarm(Alarm alarm) { 40 50 sAlarmList.removeItem(alarm); 51 } 52 53 // XXX handle EVENT_DATASTORE_RESTORED: note that in the event of 54 // a hard reset, items may come back out of order, so we need to 55 // implement an in-place sort, then insert the current alarm list. 56 // Aiee. Also, what on earth happens when UIDs aren't synchronized? 57 58 protected void onItemAdded(Object item, int index) { 59 if (sAlarmList == null) // restoring from service 60 return; 61 Alarm alarm = (Alarm)item; 62 DEBUG.p("adding: " + alarm + 63 " next UID: " + mDataStore.getAutoSyncNextUID()); 64 index = mDataStore.addRecord(alarm.toByteArray(), index); 65 alarm.setUID(mDataStore.getRecordUID(index)); 66 DEBUG.p("added UID " + alarm.getUID() + " @ " + index); 67 } 68 69 protected void onItemRemoved(Object item, int index) { 70 Alarm alarm = (Alarm)item; 71 // XXX make sure +/- UIDs are OK 72 int uid = alarm.getUID(); 73 if (uid == 0) 74 return; 75 DEBUG.p("removing; " + alarm + " UID " + uid); 76 mDataStore.removeRecordByUID(uid); 77 } 78 79 public void onItemUpdated(Object item, int index) { 80 if (sAlarmList == null) // restoring from service 81 return; 82 Alarm alarm = (Alarm)item; 83 // XXX check that updating a + UID by a - one is OK 84 mDataStore.setRecordDataByUID(alarm.getUID(), alarm.toByteArray(), true); 85 DEBUG.p("updated: " + alarm + " UID " + alarm.getUID()); 41 86 } 42 87 … … 67 112 public boolean receiveEvent(Event e) { 68 113 if (e.type == Event.EVENT_TIME_CHANGED) { 69 // XXX do we get this when the time zone changes?70 114 Alarms.getList().forEach(this); 71 115 return true; … … 75 119 } 76 120 } 77
Note:
See TracChangeset
for help on using the changeset viewer.