Changeset 255 for trunk/hiptop


Ignore:
Timestamp:
07/19/06 04:38:21 (13 years ago)
Author:
Nicholas Riley
Message:

Handle time changes by rescheduling (if it's time-based) or just updating the fire time (if it's interval-based, since those use real time when active).

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

Legend:

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

    r253 r255  
    88import danger.audio.RingToneObject;
    99import danger.internal.Date;
     10import danger.system.Hardware;
    1011import danger.util.LocaleUtils;
    1112import danger.util.StdActiveList;
     
    2728    // transient
    2829    private int mState;
     30    private int mAbsoluteFireTime; // only valid if periodic
    2931    private danger.app.Alarm mAlarm;
    3032
     
    122124    }
    123125
    124     // XXX trigger on EVENT_TIME_CHANGED
    125126    void resume() {
    126127        mState = STATE_SCHEDULED;
     
    132133    }
    133134
     135    void timeChanged() {
     136        if (mState != STATE_SCHEDULED)
     137            return;
     138        if (getUsesPeriod()) {
     139            int realSecondsLeft = mAbsoluteFireTime - Hardware.getAbsoluteTime();
     140            mDate = new Date();
     141            mDate.addSeconds(realSecondsLeft < 0 ? 0 : realSecondsLeft);
     142            // no need to call resume(): alarm uses absolute time
     143        } else {
     144            resume();
     145        }
     146    }
     147
    134148    void schedule() {
    135149        if (getUsesPeriod()) {
    136150            mDate = new Date();
    137151            mDate.addSeconds(mPeriod);
     152            mAbsoluteFireTime = Hardware.getAbsoluteTime() + mPeriod;
    138153        }
    139154        resume();
  • trunk/hiptop/pester/net/sabi/pester/AlarmSetDialog.java

    r254 r255  
    127127        }
    128128        validate();
    129         Application.registerForEvent(this, Event.EVENT_TIME_CHANGED));
     129        Application.registerForEvent(this, Event.EVENT_TIME_CHANGED);
    130130        show();
    131131        if (!mHaveShownWindow) {
  • trunk/hiptop/pester/net/sabi/pester/Alarms.java

    r250 r255  
    22
    33import java.util.Comparator;
     4import danger.app.Application;
    45import danger.app.DataStore;
     6import danger.app.Event;
    57import danger.util.StdActiveList;
    68
     
    1012
    1113    private static Alarms sAlarmList = null;
    12     private static DataStore sDataStore;
     14    private static Listener sListener;
     15
     16    private DataStore mDataStore;
    1317
    1418    private Alarms() {
    15         sDataStore = DataStore.createDataStore("alarms", true /* auto sync */);
     19        mDataStore = DataStore.createDataStore("alarms", true /* auto sync */);
    1620    }
    1721
    1822    public static Alarms getList() {
    19         if (sAlarmList == null)
     23        if (sAlarmList == null) {
    2024            sAlarmList = new Alarms();
     25            sListener = new Listener();
     26            Application.registerForEvent(sListener, Event.EVENT_TIME_CHANGED);
     27        }
    2128        return sAlarmList;
    2229    }
     
    3744    }
    3845    */
     46
     47    static class Listener extends danger.app.Listener
     48        implements danger.util.ActiveList.ForEach {
     49       
     50        public void receive(Object item) {
     51            ((Alarm)item).timeChanged();
     52        }
     53
     54        public boolean receiveEvent(Event e) {
     55            if (e.type == Event.EVENT_TIME_CHANGED) {
     56                // XXX do we get this when the time zone changes?
     57                Alarms.getList().forEach(this);
     58                return true;
     59            }
     60            return super.receiveEvent(e);
     61        }
     62    }
    3963}
     64
Note: See TracChangeset for help on using the changeset viewer.