Changeset 276 for trunk/hiptop/pester


Ignore:
Timestamp:
07/22/06 08:45:34 (18 years ago)
Author:
Nicholas Riley
Message:

First pass at alarm persistence.

Location:
trunk/hiptop/pester/net/sabi/pester
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/hiptop/pester/net/sabi/pester/Alarm.java

    r275 r276  
    3232    private int mAbsoluteFireTime; // only valid if periodic
    3333    private danger.app.Alarm mAlarm;
     34    private int mUID;
    3435
    3536    public Alarm() {
    3637        mState = STATE_INVALID;
    3738        mAlarm = new danger.app.Alarm(0, Application.getCurrentApp(), this);
     39        mUID = 0;
    3840    }
    3941
     
    5557    public RingToneObject getAlert() {
    5658        return mAlert;
     59    }
     60    public int getUID() {
     61        return mUID;
    5762    }
    5863
     
    7075    public void setAlert(RingToneObject alert) {
    7176        mAlert = alert.isValid() ? alert : null;
     77    }
     78    public void setUID(int uid) {
     79        mUID = uid;
    7280    }
    7381
  • trunk/hiptop/pester/net/sabi/pester/AlarmListView.java

    r275 r276  
    2222    public void onDecoded() {
    2323        sAlarmListWindow = (AlarmListWindow)getWindow();
     24        mToolTipAlarm = new danger.app.Alarm(0, this);
    2425        setAutoResize(true);
    25         setHasBorder(false); // this doesn't work in the rsrc file
    2626        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
    3029        Application.registerForEvent(this, Event.EVENT_TIME_CHANGED);
    3130        super.onDecoded();
     
    6564            Alarms.removeAlarm((Alarm)getFocusedItem());
    6665            return true;
    67         case Event.EVENT_TIME_CHANGED:
     66        case Event.EVENT_TIME_CHANGED: // XXX EVENT_TIME_FORMAT_CHANGED too
    6867            if (mToolTipWindow == null || !mToolTipWindow.isVisible())
    6968                return true;
  • trunk/hiptop/pester/net/sabi/pester/Alarms.java

    r259 r276  
    99import danger.internal.Date;
    1010import danger.util.StdActiveList;
     11import danger.util.DEBUG;
    1112
    1213public class Alarms extends StdActiveList {
     
    2223    private Alarms() {
    2324        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        }
    2434    }
    2535
    2636    public static Alarms getList() {
    2737        if (sAlarmList == null) {
     38            Application.registerForEvent(sListener, Event.EVENT_TIME_CHANGED);
     39            sSettingsDB = new SettingsDB("settings", true /* auto sync */);
     40            sListener = new Listener();
    2841            sAlarmList = new Alarms();
    29             sListener = new Listener();
    30             sSettingsDB = new SettingsDB("settings", true /* auto sync */);
    31             Application.registerForEvent(sListener, Event.EVENT_TIME_CHANGED);
    3242        }
    3343        return sAlarmList;
     
    3949    public static void removeAlarm(Alarm alarm) {
    4050        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());
    4186    }
    4287
     
    67112        public boolean receiveEvent(Event e) {
    68113            if (e.type == Event.EVENT_TIME_CHANGED) {
    69                 // XXX do we get this when the time zone changes?
    70114                Alarms.getList().forEach(this);
    71115                return true;
     
    75119    }
    76120}
    77 
Note: See TracChangeset for help on using the changeset viewer.