Ignore:
Timestamp:
07/29/06 00:53:01 (18 years ago)
Author:
Nicholas Riley
Message:

Better alarm debug description, datastore debugging; use absolute fire time for snoozed alarms too; replace the buggy alarm stack and misaligned sleep message with a painfully constructed alert.

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

Legend:

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

    r295 r296  
    3131    // transient
    3232    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
    3435    private danger.app.Alarm mAlarm;
    3536    private int mUID;
     
    155156        if (mState != STATE_SCHEDULED)
    156157            return;
    157         if (getUsesPeriod() && mAbsoluteFireTime != -1) {
     158        if (mAbsoluteFireTime != -1) {
    158159            int realSecondsLeft = mAbsoluteFireTime - Hardware.getAbsoluteTime();
    159160            mDate = new Date();
     
    200201    public String description() {
    201202        StringBuffer sb = new StringBuffer();
     203        if (mUID != 0) sb.append('(').append(mUID).append(") ");
    202204        switch (mState) {
    203         case STATE_INVALID: sb.append("invalid "); break;
    204         case STATE_EDITING: sb.append("editing "); break;
    205         case STATE_SCHEDULED: sb.append("scheduled "); 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;
    206208        }
    207209        switch (mType) {
     210        case TYPE_PERIODIC_REPEATING:
     211            sb.append("r-");
    208212        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;
    213216        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(": ");
    217220        sb.append('"').append(mMessage).append('"');
    218221        return sb.toString();
  • trunk/hiptop/pester/net/sabi/pester/Alarms.java

    r295 r296  
    3030    }
    3131
     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    }
    3251    void refreshFromDataStore(boolean datastoreRestored) {
    3352        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?
    3559        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        }
    3765        byte[][] alarmsData = mDataStore.getRecords();
    3866        int i;
     
    4977            MessageFinder.setDefaultMessageList();
    5078        }
     79        DEBUG.p("+++ AFTER RESTORATION +++");
     80        dumpAlarms();
     81        dumpDatastore();
    5182        sAlarmList = this;
    5283    }
     
    80111            return;
    81112        Alarm alarm = (Alarm)item;
    82         DEBUG.p("adding: " + alarm +
    83                 " next UID: " + mDataStore.getAutoSyncNextUID());
    84113        index = mDataStore.addRecord(alarm.toByteArray());
    85114        alarm.setUID(mDataStore.getRecordUID(index));
    86         DEBUG.p("added UID " + alarm.getUID() + " @ " + index);
     115        DEBUG.p("ADD" + alarm.description());
    87116    }
    88117
     
    95124            return;
    96125        mDataStore.removeRecordByUID(uid);
    97         DEBUG.p("removed UID " + alarm.getUID());
     126        if (uid < 0)
     127            mDataStore.removeRecordByUID(-uid);
     128        DEBUG.p("DEL" + alarm.description());
    98129    }
    99130
     
    103134        Alarm alarm = (Alarm)item;
    104135        mDataStore.setRecordDataByUID(alarm.getUID(), alarm.toByteArray(), true);
    105         DEBUG.p("updated: " + alarm + " UID " + alarm.getUID());
     136        DEBUG.p("MOD" + alarm.description());
    106137    }
    107138
     
    137168            } else if (e.type == Event.EVENT_DATASTORE_RESTORED) {
    138169                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")) {
    141172                    // because we only get/set the default alarm on demand
    142173                    // there's no need to handle conflicts with the settings...
  • trunk/hiptop/pester/net/sabi/pester/Pester.java

    r288 r296  
    33import danger.app.Application;
    44import danger.app.Event;
    5 import danger.app.IPCMessage;
     5import danger.ui.AlertWindow;
     6import danger.ui.Container;
     7import danger.ui.Control;
     8import danger.ui.Font;
    69import danger.ui.Layout;
    7 import danger.ui.TextField;
    8 import danger.ui.TextInputAlertWindow;
     10import danger.ui.RecordingPen;
    911import danger.ui.ScreenWindow;
    1012import danger.ui.StaticText;
     13import danger.ui.TextField;
    1114import danger.util.DEBUG;
    12 import java.util.Stack;
     15import danger.util.TextInputFilter;
    1316
    1417public class Pester extends Application implements Resources, Commands {
    1518    private static ScreenWindow sAlarmListWindow;
    16     private static Stack sAlarmStack;
    1719
    1820    public Pester() {
    1921        sAlarmListWindow = (ScreenWindow)getResources().getScreen(ID_ALARM_LIST_SCREEN);
    2022        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);
    2263    }
    2364
     
    2566        switch (e.type) {
    2667        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);
    3669            return true;
    3770        case EVENT_SET_ALARM:
    38             AlarmSetDialog.getDialog().rescheduleAlarm((Alarm)sAlarmStack.pop());
     71            AlarmSetDialog.getDialog().rescheduleAlarm((Alarm)e.argument);
    3972            return true;
    4073        case EVENT_SNOOZE_ALARM:
     74            AlertWindow alert = (AlertWindow)e.argument;
    4175            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);
    4680            return true;
    4781        case EVENT_DISMISS_ALARM:
    48             ((Alarm)sAlarmStack.pop()).dismiss();
     82            ((Alarm)e.argument).dismiss();
    4983            return true;
    5084        }
Note: See TracChangeset for help on using the changeset viewer.