Changeset 297 for trunk/hiptop
- Timestamp:
- 07/29/06 06:32:09 (18 years ago)
- Location:
- trunk/hiptop/pester/net/sabi/pester
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hiptop/pester/net/sabi/pester/Alarm.java
r296 r297 28 28 private Date mDate; 29 29 private RingToneObject mAlert; 30 private int mCreationID; 30 31 31 32 // transient … … 39 40 mState = STATE_INVALID; 40 41 mAlarm = new danger.app.Alarm(0, Application.getCurrentApp(), this); 42 mCreationID = Hardware.getSystemTime(); 41 43 mUID = 0; 42 44 mAbsoluteFireTime = -1; … … 63 65 public int getUID() { 64 66 return mUID; 67 } 68 public int getCreationID() { 69 return mCreationID; 65 70 } 66 71 … … 100 105 dataStream.writeInt(mType); 101 106 dataStream.writeInt(mAlert == null ? 0 : mAlert.getID()); 107 dataStream.writeInt(mCreationID); 102 108 dataStream.flush(); 103 109 return byteStream.toByteArray(); 104 110 } catch (Exception e) { 105 111 // XXX do something 106 DEBUG.p("failed to write alarm: " + e);112 DEBUG.p("failed to write alarm: " + e); 107 113 } 108 114 return null; … … 124 130 int alertID = dataStream.readInt(); 125 131 mAlert = (alertID == 0 ? null : new RingToneObject(alertID)); 132 mCreationID = dataStream.readInt(); 126 133 mAbsoluteFireTime = -1; // just in case 127 134 } catch (Exception e) { 128 // XXX do something 129 DEBUG.p("failed to read alarm: " + e);135 // XXX do something, prevernt alarm from being activated 136 DEBUG.p("failed to read alarm: " + e); 130 137 } 131 138 } -
trunk/hiptop/pester/net/sabi/pester/Alarms.java
r296 r297 1 1 package net.sabi.pester; 2 2 3 import java.util.Arrays; 3 4 import java.util.Comparator; 4 5 import danger.app.Application; … … 8 9 import danger.app.SettingsDBException; 9 10 import danger.internal.Date; 11 import danger.util.ByteArray; 10 12 import danger.util.StdActiveList; 11 13 import danger.util.DEBUG; … … 18 20 private static Listener sListener; 19 21 private static SettingsDB sSettingsDB; 22 private static DataStore sDeletedAlarms; 20 23 21 24 private DataStore mDataStore; … … 28 31 mDataStore.setAutoSyncNotifyee(sListener); 29 32 refreshFromDataStore(false); 33 } 34 35 private int[] deletedAlarmsCreationIDs() { 36 byte[][] deletedAlarmsData = sDeletedAlarms.getRecords(); 37 int[] ids = new int[deletedAlarmsData.length]; 38 for (int i = 0 ; i < deletedAlarmsData.length ; ++i) 39 ids[i] = ByteArray.readInt(deletedAlarmsData[i], 0); 40 Arrays.sort(ids); 41 return ids; 30 42 } 31 43 … … 51 63 void refreshFromDataStore(boolean datastoreRestored) { 52 64 sAlarmList = null; 65 int[] deleted = null; 53 66 if (datastoreRestored) { 67 deleted = deletedAlarmsCreationIDs(); 54 68 DEBUG.p("+++ BEFORE RESOLUTION +++"); 55 69 dumpAlarms(); … … 69 83 alarm.fromByteArray(alarmsData[i]); 70 84 alarm.setUID(mDataStore.getRecordUID(i)); 85 if (Arrays.binarySearch(deleted, alarm.getCreationID()) >= 0) { 86 mDataStore.removeRecord(i); 87 continue; 88 } 71 89 insertItemSorted(alarm, alarm); 72 90 alarm.resume(); … … 86 104 if (sAlarmList == null) { 87 105 sSettingsDB = new SettingsDB("settings", true /* auto sync */); 106 sDeletedAlarms = DataStore.createDataStore("deleted alarms"); 88 107 sListener = new Listener(); 89 108 new Alarms(); … … 126 145 if (uid < 0) 127 146 mDataStore.removeRecordByUID(-uid); 147 while (sDeletedAlarms.getRecordCount() >= MAX_ALARM_COUNT) 148 sDeletedAlarms.removeRecord(0); 149 byte[] idBytes = new byte[4]; 150 ByteArray.writeInt(idBytes, 0, alarm.getCreationID()); 151 sDeletedAlarms.addRecord(idBytes); 128 152 DEBUG.p("DEL" + alarm.description()); 129 153 }
Note:
See TracChangeset
for help on using the changeset viewer.