- Timestamp:
- 07/12/06 22:11:04 (18 years ago)
- Location:
- trunk/hiptop/pester/net/sabi/pester
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/hiptop/pester/net/sabi/pester/Alarm.java
r247 r249 21 21 private String mMessage; 22 22 private int mType; 23 private int m Period; // XXX rename to 'interval'23 private int mInterval; // XXX rename to 'interval' 24 24 private Date mDate; 25 25 private RingToneObject mAlert; … … 38 38 } 39 39 public int getPeriod() { 40 return m Period;40 return mInterval; 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 Period= period;60 mInterval = 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 Period);77 dataStream.writeInt(mInterval); 78 78 dataStream.writeInt(mDate.getUnixTimeGMT()); 79 79 dataStream.writeInt(mType); … … 96 96 } 97 97 mMessage = dataStream.readUTF(); 98 m Period= dataStream.readInt();98 mInterval = dataStream.readInt(); 99 99 mType = dataStream.readInt(); 100 100 } catch (Exception e) { … … 108 108 } 109 109 110 public static int secondsFromNow(Date date) { 111 return date.getDangerTimeGMT() - new Date().getDangerTimeGMT(); 112 } 113 114 protected int remainingInterval() { 115 return secondsFromNow(mDate); 116 } 117 110 118 void resume() { 111 119 mState = STATE_SCHEDULED; 112 int period = mDate.getDangerTimeGMT() - new Date().getDangerTimeGMT();113 if ( period < 0) period= 0;114 mAlarm.resetWake( period);115 DEBUG.p("resetWake: " + description() + " - " + period+ "s left");120 int interval = remainingInterval(); 121 if (interval < 0) interval = 0; 122 mAlarm.resetWake(interval); 123 DEBUG.p("resetWake: " + description() + " - " + interval + "s left"); 116 124 update(); 117 125 } … … 120 128 if (getUsesPeriod()) { 121 129 mDate = new Date(); 122 mDate.addSeconds(m Period);130 mDate.addSeconds(mInterval); 123 131 } 124 132 resume(); … … 146 154 switch (mType) { 147 155 case TYPE_PERIODIC: 148 sb.append("periodic (").append(m Period).append("s) "); break;156 sb.append("periodic (").append(mInterval).append("s) "); break; 149 157 case TYPE_PERIODIC_REPEATING: 150 sb.append("repeating periodic (").append(m Period).append("s) ");158 sb.append("repeating periodic (").append(mInterval).append("s) "); 151 159 break; 152 160 case TYPE_DATE: … … 158 166 } 159 167 160 p rotected static String dateTimeString(Date date) {168 public static String dateTimeString(Date date, boolean relative) { 161 169 if (date == null) 162 170 return null; … … 164 172 String timeFormat = LocaleUtils.getMediumTimeFormat(); 165 173 String dateFormat = LocaleUtils.getMediumDateFormat(); 166 return StringFormat.withFormat(layout, 167 DateFormat.withFormat(timeFormat, date), 168 DateFormat.withFormat(dateFormat, date)); 174 String timeString = DateFormat.withFormat(timeFormat, date); 175 String dateString = DateFormat.withFormat(dateFormat, date); 176 if (relative) { 177 int daysFromToday = date.getDaysBetween(new Date()); 178 if (daysFromToday == 0) 179 dateString = "Today"; // XXX localize 180 else if (daysFromToday == 1) 181 dateString = "Tomorrow"; // XXX localize 182 else if (daysFromToday < 7) 183 dateString = date.getDayString(); 184 } 185 return StringFormat.withFormat(layout, timeString, dateString); 186 } 187 188 protected static void addUnit(StringBuffer sb, int n, String unit) { 189 if (n == 0) return; 190 if (sb.length() > 0) sb.append(", "); 191 if (n == 1) sb.append("one ").append(unit); 192 else sb.append(n).append(' ').append(unit).append("s"); 193 } 194 195 public static String intervalString(int i) { // XXX localize 196 if (i < 0) 197 return "expired"; 198 StringBuffer sb = new StringBuffer(); 199 if (i < 60) { 200 addUnit(sb, i, "second"); 201 } else { 202 i /= 60; // minutes 203 if (i < 24 * 60) { 204 addUnit(sb, i / 60, "hour"); 205 addUnit(sb, i % 60, "minute"); 206 } else { 207 i /= 60; // hours 208 if (i < 365) { 209 addUnit(sb, i / 24, "day"); 210 addUnit(sb, i % 24, "hour"); 211 } else { 212 i /= 24; // days 213 addUnit(sb, i / 365, "year"); // XXX actually 365.242199 214 addUnit(sb, i % 365, "day"); 215 } 216 } 217 } 218 return sb.toString(); 219 } 220 221 public String getDateTimeString(boolean relative) { 222 return dateTimeString(mDate, relative); 169 223 } 170 224 171 225 public String getDateTimeString() { 172 return dateTimeString(mDate); 226 return getDateTimeString(false); 227 } 228 229 public String getIntervalString() { 230 return intervalString(remainingInterval()); 173 231 } 174 232 175 233 public String toString() { 176 return mMessage;234 return getDateTimeString(true) + " - " + mMessage; 177 235 } 178 236 -
trunk/hiptop/pester/net/sabi/pester/AlarmListView.java
r248 r249 138 138 // XXX check before dismissing dialog that alarm is valid 139 139 // XXX and display alarm date 140 // XXX default to now somehow? Would be useful. 140 141 protected void constrainDate() { 141 142 // XXX schedule every minute (second?) if in AT mode … … 235 236 if (item == null) // this is dumb, why do we get asked for a tooltip? 236 237 return null; 237 // XXX need "in XXX minutes" too 238 return ((Alarm)item).getDateTimeString(); 238 // XXX need to refresh, localize 239 Alarm alarm = (Alarm)item; 240 return alarm.getDateTimeString() + " - " + alarm.getIntervalString(); 239 241 } 240 242 }
Note:
See TracChangeset
for help on using the changeset viewer.