Commit 5ad9026a authored by Patrick Scott's avatar Patrick Scott
Browse files

Pop a toast when handling the set alarm intent.

If the intent does not contain extras, start the AlarmClock activity to show the
list of alarms.

When checking for an alarm that already exists, make sure the repeat setting is
0.

Change-Id: If257b0d3bd591cddf7ff92b56bb240af8cb621a3
parent 60661f1e
......@@ -38,6 +38,10 @@ public class HandleSetAlarm extends Activity {
if (intent == null || !ACTION_SET_ALARM.equals(intent.getAction())) {
finish();
return;
} else if (!intent.hasExtra(EXTRA_HOUR)) {
startActivity(new Intent(this, AlarmClock.class));
finish();
return;
}
final Calendar calendar = Calendar.getInstance();
......@@ -52,18 +56,21 @@ public class HandleSetAlarm extends Activity {
}
Cursor c = null;
long timeInMillis = Alarms.calculateAlarm(hour, minutes,
new Alarm.DaysOfWeek(0)).getTimeInMillis();
try {
c = getContentResolver().query(
Alarm.Columns.CONTENT_URI,
new String[] { Alarm.Columns._ID },
Alarm.Columns.HOUR + "=" + hour + " AND " +
Alarm.Columns.MINUTES + "=" + minutes + " AND " +
Alarm.Columns.DAYS_OF_WEEK + "=0 AND " +
Alarm.Columns.MESSAGE + "=?",
new String[] { message }, null);
if (c != null && c.moveToFirst()) {
do {
Alarms.enableAlarm(this, c.getInt(0), true);
} while (c.moveToNext());
// Enable the first alarm we find.
Alarms.enableAlarm(this, c.getInt(0), true);
SetAlarm.popAlarmSetToast(this, timeInMillis);
finish();
return;
}
......@@ -77,12 +84,12 @@ public class HandleSetAlarm extends Activity {
values.put(Alarm.Columns.MESSAGE, message);
values.put(Alarm.Columns.ENABLED, 1);
values.put(Alarm.Columns.VIBRATE, 1);
values.put(Alarm.Columns.ALARM_TIME,
Alarms.calculateAlarm(hour, minutes,
new Alarm.DaysOfWeek(0)).getTimeInMillis());
values.put(Alarm.Columns.DAYS_OF_WEEK, 0);
values.put(Alarm.Columns.ALARM_TIME, timeInMillis);
if (getContentResolver().insert(
Alarm.Columns.CONTENT_URI, values) != null) {
SetAlarm.popAlarmSetToast(this, timeInMillis);
Alarms.setNextAlert(this);
}
......
......@@ -316,7 +316,7 @@ public class SetAlarm extends PreferenceActivity
.getTimeInMillis());
}
private static void popAlarmSetToast(Context context, long timeInMillis) {
static void popAlarmSetToast(Context context, long timeInMillis) {
String toastText = formatToast(context, timeInMillis);
Toast toast = Toast.makeText(context, toastText, Toast.LENGTH_LONG);
ToastMaster.setToast(toast);
......
......@@ -37,18 +37,13 @@ public class TestAddAlarm extends Activity {
// Should not see a duplicate
startActivity(i);
// No message, alarm set for now.
startActivity(new Intent(AlarmClock.ACTION_SET_ALARM));
i.removeExtra(AlarmClock.EXTRA_MESSAGE);
startActivity(i);
// No dup of null message.
startActivity(i);
// Enable default 8:30 alarm.
i.putExtra(AlarmClock.EXTRA_HOUR, 8);
i.putExtra(AlarmClock.EXTRA_MINUTES, 30);
startActivity(i);
// No extras, launches the alarm list.
startActivity(new Intent(AlarmClock.ACTION_SET_ALARM));
finish();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment