Changeset 258 for trunk/hiptop


Ignore:
Timestamp:
07/19/06 22:50:24 (18 years ago)
Author:
Nicholas Riley
Message:

Save most recent alarm settings to SettingsDB.

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

Legend:

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

    r257 r258  
    8686        mValidateAlarm = new danger.app.Alarm(1, this);
    8787
     88        editAlarm(Alarms.getDefaultAlarm());
     89
    8890        super.onDecoded();
    8991    }
    9092
    91     protected void editDateOrPeriod(Alarm alarm) {
     93    protected void editAlarm(Alarm alarm) {
     94        mMessageField.setText(alarm.getMessage());
     95
    9296        boolean usesPeriod = alarm.getUsesPeriod();
    9397        if (usesPeriod) {
     
    111115        mInButton.setValue(usesPeriod ? 1 : 0);
    112116        mAtButton.setValue(usesPeriod ? 0 : 1);
     117
     118        mAlertPicker.setRingTone(alarm.getAlert());
    113119    }
    114120
     
    121127            // XXX default to now?
    122128        } else {
    123             mMessageField.setText(alarm.getMessage());
     129            editAlarm(alarm);
    124130            mDiscardAlarmButton.show();
    125             editDateOrPeriod(alarm);
    126             mAlertPicker.setRingTone(mEditingAlarm.getAlert());
    127131        }
    128132        validate();
     
    225229            mEditingAlarm.schedule();
    226230            if (mAlarmIsNew) Alarms.addAlarm(mEditingAlarm);
     231            Alarms.setDefaultAlarm(mEditingAlarm);
    227232            stopEditing();
    228233            return true;
  • trunk/hiptop/pester/net/sabi/pester/Alarms.java

    r255 r258  
    55import danger.app.DataStore;
    66import danger.app.Event;
     7import danger.app.SettingsDB;
     8import danger.app.SettingsDBException;
     9import danger.internal.Date;
    710import danger.util.StdActiveList;
    811
     
    1316    private static Alarms sAlarmList = null;
    1417    private static Listener sListener;
     18    private static SettingsDB sSettingsDB;
    1519
    1620    private DataStore mDataStore;
     
    2428            sAlarmList = new Alarms();
    2529            sListener = new Listener();
     30            sSettingsDB = new SettingsDB("settings", true /* auto sync */);
    2631            Application.registerForEvent(sListener, Event.EVENT_TIME_CHANGED);
    2732        }
     
    3439    public static void removeAlarm(Alarm alarm) {
    3540        sAlarmList.removeItem(alarm);
     41    }
     42
     43    private static String KEY_DEFAULT_ALARM = "default alarm";
     44
     45    public static Alarm getDefaultAlarm() {
     46        Alarm defaultAlarm = new Alarm();
     47        try {
     48            defaultAlarm.fromByteArray(sSettingsDB.getBytes(KEY_DEFAULT_ALARM));
     49        } catch (SettingsDBException e) {
     50            defaultAlarm = new Alarm();
     51            defaultAlarm.setDate(new Date());
     52            defaultAlarm.setPeriod(600, false);
     53        }
     54        return defaultAlarm;
     55    }
     56    public static void setDefaultAlarm(Alarm alarm) {
     57        sSettingsDB.setBytes(KEY_DEFAULT_ALARM, alarm.toByteArray());
    3658    }
    3759
Note: See TracChangeset for help on using the changeset viewer.