Changeset 250 for trunk/hiptop
- Timestamp:
- 07/13/06 16:43:36 (18 years ago)
- Location:
- trunk/hiptop/pester
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hiptop/pester/locale/en_US/Pester.rsrc
r248 r250 18 18 19 19 string ID_VERSION "V@APP_VERSION_MAJOR@.@APP_VERSION_MINOR@" 20 21 int EVENT_CANCEL_ALARM 1 22 int EVENT_TIME_EDITOR_LOST_FOCUS 2 20 23 21 24 splashScreen ID_SPLASH_SCREEN_RESOURCE … … 84 87 title = "Set Alarm" 85 88 showCancel 86 #className = "net.sabi.pester.AlarmSetDialog"89 className = "net.sabi.pester.AlarmSetDialog" 87 90 widthPct = 100 88 91 centerUnderTitleBar … … 158 161 alignBaseline = ID_AT_BUTTON 159 162 positionToRight = ID_AT_BUTTON : 1 163 className = "net.sabi.pester.AlarmTimeEditor" 160 164 161 165 dateEditor -
trunk/hiptop/pester/net/sabi/pester/Alarm.java
r249 r250 21 21 private String mMessage; 22 22 private int mType; 23 private int m Interval; // XXX rename to 'interval'23 private int mPeriod; 24 24 private Date mDate; 25 25 private RingToneObject mAlert; … … 38 38 } 39 39 public int getPeriod() { 40 return m Interval;40 return mPeriod; 41 41 } 42 42 public boolean getUsesPeriod() { … … 58 58 public void setPeriod(int period, boolean repeating) { 59 59 mType = repeating ? TYPE_PERIODIC_REPEATING : TYPE_PERIODIC; 60 m Interval= period;60 mPeriod = period; 61 61 } 62 62 public void setDate(Date date) { … … 75 75 dataStream.writeByte(VERSION_1); 76 76 dataStream.writeUTF(mMessage); 77 dataStream.writeInt(m Interval);77 dataStream.writeInt(mPeriod); 78 78 dataStream.writeInt(mDate.getUnixTimeGMT()); 79 79 dataStream.writeInt(mType); … … 96 96 } 97 97 mMessage = dataStream.readUTF(); 98 m Interval= dataStream.readInt();98 mPeriod = dataStream.readInt(); 99 99 mType = dataStream.readInt(); 100 100 } catch (Exception e) { … … 128 128 if (getUsesPeriod()) { 129 129 mDate = new Date(); 130 mDate.addSeconds(m Interval);130 mDate.addSeconds(mPeriod); 131 131 } 132 132 resume(); … … 154 154 switch (mType) { 155 155 case TYPE_PERIODIC: 156 sb.append("periodic (").append(m Interval).append("s) "); break;156 sb.append("periodic (").append(mPeriod).append("s) "); break; 157 157 case TYPE_PERIODIC_REPEATING: 158 sb.append("repeating periodic (").append(m Interval).append("s) ");158 sb.append("repeating periodic (").append(mPeriod).append("s) "); 159 159 break; 160 160 case TYPE_DATE: … … 170 170 return null; 171 171 String layout = LocaleUtils.getDateTimePattern(); 172 String timeFormat = LocaleUtils.getMediumTimeFormat();173 172 String dateFormat = LocaleUtils.getMediumDateFormat(); 174 String timeString = DateFormat.withFormat(timeFormat, date);175 String dateString = DateFormat.withFormat(dateFormat, date);173 String dateString; 174 String timeFormat; 176 175 if (relative) { 176 timeFormat = LocaleUtils.getShortTimeFormat(); 177 177 int daysFromToday = date.getDaysBetween(new Date()); 178 178 if (daysFromToday == 0) … … 182 182 else if (daysFromToday < 7) 183 183 dateString = date.getDayString(); 184 } 184 else 185 dateString = DateFormat.withFormat(dateFormat, date); 186 } else { 187 dateString = DateFormat.withFormat(dateFormat, date); 188 timeFormat = LocaleUtils.getMediumTimeFormat(); 189 } 190 String timeString = DateFormat.withFormat(timeFormat, date); 185 191 return StringFormat.withFormat(layout, timeString, dateString); 186 192 } -
trunk/hiptop/pester/net/sabi/pester/AlarmListView.java
r249 r250 3 3 import danger.app.Application; 4 4 import danger.app.Event; 5 import danger.audio.ToneClass;6 import danger.audio.ToneRights;7 8 import danger.internal.Date;9 5 import danger.ui.ActiveListView; 10 import danger.ui.Button;11 import danger.ui.CheckBox;12 import danger.ui.DateTimeEditor;13 import danger.ui.DatePicker;14 import danger.ui.DialogWindow;15 import danger.ui.MenuItem;16 import danger.ui.NumberEditor;17 import danger.ui.PopupMenu;18 import danger.ui.RadioButton;19 import danger.ui.Rect;20 import danger.ui.RingTonePicker;21 import danger.ui.TypeAheadTextField;22 6 import danger.util.ActiveList; 23 import danger.util.StdActiveList;24 import danger.util.DEBUG;25 7 26 8 public class AlarmListView extends ActiveListView 27 9 implements Resources, Commands { 28 private static Pester sPester; 10 11 // XXX some of these shouldn't conceptually be static 29 12 private static AlarmListWindow sAlarmListWindow; 30 // XXX some of these shouldn't conceptually be static, but who cares 31 private static StdActiveList sAlarmList; 32 private static Alarms sAlarms; 13 private static AlarmSetDialog sAlarmSetDialog; 33 14 34 private static DialogWindow sEditWindow; 35 private TypeAheadTextField sMessageField; 36 private RadioButton sInButton, sAtButton; 37 private NumberEditor sPeriodField; 38 private PopupMenu sPeriodUnitsPopup; 39 // XXX don't allow <5 second repeating alarms 40 private CheckBox sRepeatCheckBox; 41 private DateTimeEditor sTimeEditor, sDateEditor; 42 private DatePicker sDatePicker; 43 private RingTonePicker sAlertPicker; 44 private Button sDiscardAlarmButton, sSetAlarmButton; 15 public void onDecoded() { 16 sAlarmListWindow = (AlarmListWindow)getWindow(); 17 setList(Alarms.getList()); 18 super.onDecoded(); 19 } 45 20 46 private static Alarm sFocusedAlarm, sEditingAlarm; 47 48 private static final int EVENT_CANCEL_ALARM = -1; // XXX move this? 49 50 public void onDecoded() { 51 sPester = (Pester)Application.getCurrentApp(); 52 sAlarmListWindow = (AlarmListWindow)getWindow(); 53 sAlarmList = new StdActiveList(); 54 setList(sAlarmList); 55 56 sEditWindow = sPester.getDialog(ID_ALARM_SET_DIALOG, this); 57 sEditWindow.setCancelButtonEvent(new Event(this, EVENT_CANCEL_ALARM)); 58 sMessageField = (TypeAheadTextField)sEditWindow.getDescendantWithID(ID_MESSAGE_FIELD); 59 sEditWindow.disableBottomRightButtonOnEmptyField(sMessageField); 60 sInButton = (RadioButton)sEditWindow.getDescendantWithID(ID_IN_BUTTON); 61 sAtButton = (RadioButton)sEditWindow.getDescendantWithID(ID_AT_BUTTON); 62 sPeriodField = (NumberEditor)sEditWindow.getDescendantWithID(ID_PERIOD_FIELD); 63 sPeriodUnitsPopup = (PopupMenu)sEditWindow.getDescendantWithID(ID_PERIOD_UNITS_POPUP); 64 sRepeatCheckBox = (CheckBox)sEditWindow.getDescendantWithID(ID_PERIOD_REPEAT_CHECKBOX); 65 sTimeEditor = (DateTimeEditor)sEditWindow.getDescendantWithID(ID_TIME_EDITOR); 66 sDateEditor = (DateTimeEditor)sEditWindow.getDescendantWithID(ID_DATE_EDITOR); 67 sDatePicker = (DatePicker)sEditWindow.getDescendantWithID(ID_DATE_PICKER); 68 sAlertPicker = (RingTonePicker)sEditWindow.getDescendantWithID(ID_ALERT_PICKER); 69 sSetAlarmButton = (Button)sEditWindow.getDescendantWithID(ID_SET_ALARM_BUTTON); 70 sDiscardAlarmButton = (Button)sEditWindow.getDescendantWithID(ID_DISCARD_ALARM_BUTTON); 71 sInButton.setValue(1); 72 sDateEditor.limitToDangerEpoch(); 73 sAlertPicker.setGroupFilter(ToneClass.FOREGROUND | ToneClass.CUSTOM); 74 sAlertPicker.setRights(ToneRights.FULL); 75 // this doesn't work properly yet 76 // sAlertPicker.setCanRecord(true); 77 78 super.onDecoded(); 21 protected AlarmSetDialog alarmSetDialog() { 22 if (sAlarmSetDialog == null) 23 sAlarmSetDialog = AlarmSetDialog.getDialog(); 24 return sAlarmSetDialog; 79 25 } 80 26 … … 83 29 case Event.DEVICE_BUTTON_BACK: 84 30 case Event.DEVICE_BUTTON_CANCEL: 85 sPester.returnToLauncher();31 Application.getCurrentApp().returnToLauncher(); 86 32 return true; 87 33 } … … 89 35 } 90 36 91 protected void editDateOrPeriod(Alarm alarm) {92 boolean usesPeriod = alarm.getUsesPeriod();93 if (usesPeriod) {94 int period = alarm.getPeriod();95 for (int i = sPeriodUnitsPopup.itemCount() - 1 ; i >= 0 ; --i) {96 int unitsPerSec = sPeriodUnitsPopup.getItem(i).getEvent().data;97 if (period % unitsPerSec == 0) {98 sPeriodUnitsPopup.setValue(i);99 sPeriodField.setValue(period / unitsPerSec);100 break;101 }102 }103 sRepeatCheckBox.setValue(alarm.getRepeating() ? 1 : 0);104 }105 106 Date date = alarm.getDate();107 sTimeEditor.setDate(date);108 sDateEditor.setDate(date);109 sDatePicker.setDate(date);110 111 sInButton.setValue(usesPeriod ? 1 : 0);112 sAtButton.setValue(usesPeriod ? 0 : 1);113 }114 115 protected void editAlarm(Alarm alarm, boolean asNew) {116 sEditingAlarm = alarm;117 alarm.beginEditing();118 if (asNew) {119 sDiscardAlarmButton.hide();120 } else {121 sMessageField.setText(alarm.getMessage());122 sDiscardAlarmButton.show();123 editDateOrPeriod(alarm);124 sAlertPicker.setRingTone(sEditingAlarm.getAlert());125 }126 constrainDate();127 sEditWindow.show();128 }129 130 protected Date editingDate() {131 Date date = sDateEditor.getDate();132 date.setTime(sTimeEditor.getDate().getTime());133 date.setSeconds(0);134 return date;135 }136 137 // XXX make this into a more general validation method;138 // XXX check before dismissing dialog that alarm is valid139 // XXX and display alarm date140 // XXX default to now somehow? Would be useful.141 protected void constrainDate() {142 // XXX schedule every minute (second?) if in AT mode143 // XXX could use onPeriodicPulse() perhaps144 Date now = new Date();145 sDateEditor.min(now);146 sDatePicker.min(now);147 sSetAlarmButton.setEnabled(sInButton.getValue() == 1 ||148 editingDate().compareTo(now) > 0);149 }150 151 37 public boolean receiveEvent(Event e) { 152 38 switch (e.type) { 153 39 case EVENT_NEW_ALARM: 154 editAlarm(new Alarm(), true); 155 return true; 156 case EVENT_SET_ALARM: 157 sEditingAlarm.setMessage(sMessageField.toString()); 158 if (sInButton.getValue() == 1) { 159 int itemIndex = sPeriodUnitsPopup.getValue(); 160 MenuItem itemAtIndex = sPeriodUnitsPopup.getItem(itemIndex); 161 Event event = itemAtIndex.getEvent(); 162 sEditingAlarm.setPeriod(sPeriodField.getValue() * event.data, 163 sRepeatCheckBox.getValue() == 1); 164 } else { 165 sEditingAlarm.setDate(editingDate()); 166 } 167 sEditingAlarm.setAlert(sAlertPicker.getRingTone()); 168 // schedule before adding so the tooltip is correct 169 sEditingAlarm.schedule(); 170 if (sEditingAlarm != sFocusedAlarm) { // new alarm 171 sAlarmList.addItem(sEditingAlarm); 172 setFocusedItem(sEditingAlarm); 173 sFocusedAlarm = sEditingAlarm; 174 } 175 return true; 176 case EVENT_CANCEL_ALARM: 177 if (sEditingAlarm == sFocusedAlarm) // existing alarm 178 sEditingAlarm.resume(); 179 sEditingAlarm = null; 40 alarmSetDialog().editAlarm(new Alarm(), true); 180 41 return true; 181 42 case EVENT_DISCARD_ALARM: 182 43 // XXX confirmation 183 sAlarmList.removeItem(sFocusedAlarm); 184 return true; 185 case EVENT_IN: 186 sAtButton.setValue(0); 187 constrainDate(); 188 return true; 189 case EVENT_AT: 190 sInButton.setValue(0); 191 constrainDate(); 192 return true; 193 case EVENT_TIME_EDITOR: 194 Date date = editingDate(); 195 // XXX do this on exit from the field, not on change 196 if (date.compareTo(new Date()) <= 0) { 197 date.addDays(1); 198 sDatePicker.setDate(date); 199 sDateEditor.setDate(date); 200 } 201 constrainDate(); 202 return true; 203 case EVENT_DATE_EDITOR: 204 sDatePicker.setDate(sDateEditor.getDate()); 205 constrainDate(); 206 return true; 207 case EVENT_DATE_PICKER: 208 sDateEditor.setDate((Date)e.argument); 209 constrainDate(); 44 Alarms.removeAlarm((Alarm)getFocusedItem()); 210 45 return true; 211 46 } … … 214 49 215 50 protected void itemActivated(Object item) { 216 editAlarm(sFocusedAlarm, false); 217 } 218 protected void itemFocused(Object item) { 219 sFocusedAlarm = (Alarm)item; 51 if (item == null) 52 return; 53 alarmSetDialog().editAlarm((Alarm)item, false); 220 54 } 221 55 … … 225 59 public void onItemAdded(ActiveList list, Object item, int index) { 226 60 sAlarmListWindow.updateAlarmCount(); 61 setFocus(index); 227 62 super.onItemAdded(list, item, index); 228 63 } -
trunk/hiptop/pester/net/sabi/pester/Alarms.java
r237 r250 3 3 import java.util.Comparator; 4 4 import danger.app.DataStore; 5 import danger.util.StdActiveList; 5 6 6 public class Alarms {7 public class Alarms extends StdActiveList { 7 8 // max # records in a datastore 8 9 private static final int MAX_ALARM_COUNT = 50; 9 10 10 private static Alarms sAlarm s= null;11 private static Alarms sAlarmList = null; 11 12 private static DataStore sDataStore; 12 13 … … 14 15 sDataStore = DataStore.createDataStore("alarms", true /* auto sync */); 15 16 } 16 17 public static Alarms getInstance() {18 if (sAlarms == null)19 sAlarms = new Alarms();20 17 21 return sAlarms; 18 public static Alarms getList() { 19 if (sAlarmList == null) 20 sAlarmList = new Alarms(); 21 return sAlarmList; 22 } 23 24 public static void addAlarm(Alarm alarm) { 25 sAlarmList.addItem(alarm); 26 } 27 public static void removeAlarm(Alarm alarm) { 28 sAlarmList.removeItem(alarm); 22 29 } 23 30
Note:
See TracChangeset
for help on using the changeset viewer.