auto import from //depot/cupcake/@136594
diff --git a/res/layout/alarm_clock.xml b/res/layout/alarm_clock.xml
index a0ca8e3..b56067d 100644
--- a/res/layout/alarm_clock.xml
+++ b/res/layout/alarm_clock.xml
@@ -24,14 +24,14 @@
<LinearLayout
android:id="@+id/clock_layout"
android:layout_width="fill_parent"
- android:layout_height="208dip"
+ android:layout_height="wrap_content"
android:layout_marginBottom="8dip"
android:gravity="center"/>
<ListView
android:id="@+id/alarms_list"
android:layout_width="fill_parent"
- android:layout_height="0dip"
- android:layout_weight="1.0" />
+ android:layout_height="wrap_content"
+ android:layout_weight="1" />
</LinearLayout>
diff --git a/res/layout/alarm_time.xml b/res/layout/alarm_time.xml
index aae6ef2..3a50070 100644
--- a/res/layout/alarm_time.xml
+++ b/res/layout/alarm_time.xml
@@ -16,7 +16,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
+ android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- A layout that displays the time. Shows time, am/pm (if 12-hour),
@@ -27,16 +27,15 @@
android:layout_height="fill_parent"
android:focusable="true"
android:layout_weight="1"
- android:layout_gravity="center_vertical"
+ android:gravity="center_vertical"
android:orientation="vertical"
- android:paddingTop="4dp"
android:paddingLeft="8dp"
+ android:paddingRight="8dp"
android:background="@android:drawable/menuitem_background">
<LinearLayout
android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:gravity="left">
+ android:layout_height="wrap_content">
<TextView android:id="@+id/timeDisplay"
android:layout_width="wrap_content"
@@ -44,7 +43,6 @@
android:paddingTop="-4dp"
android:paddingBottom="-4dp"
android:textSize="28sp"
- android:gravity="left"
android:textColor="@color/white"/>
<LinearLayout android:id="@+id/am_pm"
@@ -66,6 +64,18 @@
android:text="@string/pm"
android:textSize="12sp"/>
</LinearLayout>
+
+ <TextView android:id="@+id/label"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/default_label"
+ android:paddingTop="-4dp"
+ android:paddingBottom="-4dp"
+ android:textSize="28sp"
+ android:textColor="@color/white"
+ android:layout_marginLeft="20dp"
+ android:singleLine="true"/>
+
</LinearLayout>
<TextView android:id="@+id/daysOfWeek"
@@ -74,7 +84,7 @@
android:textSize="10sp"
android:textColor="@color/ltgrey"
android:layout_marginLeft="2dp"
- android:gravity="left"/>
+ android:visibility="gone"/>
</com.android.alarmclock.DigitalClock>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 30b8fe2..d5d6760 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -34,6 +34,12 @@
<!-- Menu item on Alarm Clock screen: Hide clock -->
<string name="hide_clock">Hide clock</string>
+ <!-- Setting label on Set alarm screen: Label -->
+ <string name="label">Label</string>
+
+ <!-- Default label to display for an alarm -->
+ <string name="default_label">Alarm</string>
+
<!-- Preference category on Alarm Settings screen: Set alarm -->
<string name="set_alarm">Set alarm</string>
diff --git a/res/xml/alarm_prefs.xml b/res/xml/alarm_prefs.xml
index bdcf6b7..dfb0401 100644
--- a/res/xml/alarm_prefs.xml
+++ b/res/xml/alarm_prefs.xml
@@ -33,4 +33,7 @@
android:title="@string/alarm_repeat"
android:entries="@array/days_of_week"
android:entryValues="@array/days_of_week"/>
+ <EditTextPreference android:key="label"
+ android:title="@string/label"
+ android:dialogTitle="@string/label" />
</PreferenceScreen>
diff --git a/src/com/android/alarmclock/AlarmAlert.java b/src/com/android/alarmclock/AlarmAlert.java
index eefd5bb..2464c96 100644
--- a/src/com/android/alarmclock/AlarmAlert.java
+++ b/src/com/android/alarmclock/AlarmAlert.java
@@ -54,6 +54,7 @@
private AlarmKlaxon mKlaxon;
private int mAlarmId;
+ private String mLabel;
@Override
protected void onCreate(Bundle icicle) {
@@ -81,7 +82,11 @@
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
- mAlarmId = getIntent().getIntExtra(Alarms.ID, -1);
+ Intent i = getIntent();
+ mAlarmId = i.getIntExtra(Alarms.ID, -1);
+
+ /* Set the title from the passed in label */
+ setTitleFromIntent(i);
/* allow next alarm to trigger while this activity is
active */
@@ -108,6 +113,14 @@
updateLayout();
}
+ private void setTitleFromIntent(Intent i) {
+ mLabel = i.getStringExtra(Alarms.LABEL);
+ if (mLabel == null || mLabel.length() == 0) {
+ mLabel = getString(R.string.default_label);
+ }
+ setTitle(mLabel);
+ }
+
private void updateSilencedText() {
TextView silenced = (TextView) findViewById(R.id.silencedText);
silenced.setText(getString(R.string.alarm_alert_alert_silenced,
@@ -181,7 +194,8 @@
Alarms.formatTime(AlarmAlert.this, c));
mState = DISMISS;
} else {
- Alarms.saveSnoozeAlert(AlarmAlert.this, mAlarmId, snoozeTime);
+ Alarms.saveSnoozeAlert(AlarmAlert.this, mAlarmId, snoozeTime,
+ mLabel);
Alarms.setNextAlert(AlarmAlert.this);
displayTime = getString(R.string.alarm_alert_snooze_set,
SNOOZE_MINUTES);
@@ -218,6 +232,7 @@
disableKeyguard();
mAlarmId = intent.getIntExtra(Alarms.ID, -1);
+ setTitleFromIntent(intent);
/* unset silenced message */
TextView silenced = (TextView)findViewById(R.id.silencedText);
diff --git a/src/com/android/alarmclock/AlarmClock.java b/src/com/android/alarmclock/AlarmClock.java
index 6230d16..ca1c900 100644
--- a/src/com/android/alarmclock/AlarmClock.java
+++ b/src/com/android/alarmclock/AlarmClock.java
@@ -104,6 +104,8 @@
final Alarms.DaysOfWeek daysOfWeek = new Alarms.DaysOfWeek(
cursor.getInt(Alarms.AlarmColumns.ALARM_DAYS_OF_WEEK_INDEX));
final boolean enabled = cursor.getInt(Alarms.AlarmColumns.ALARM_ENABLED_INDEX) == 1;
+ final String label =
+ cursor.getString(Alarms.AlarmColumns.ALARM_MESSAGE_INDEX);
CheckBox onButton = (CheckBox)view.findViewById(R.id.alarmButton);
onButton.setChecked(enabled);
@@ -143,8 +145,26 @@
c.set(Calendar.HOUR_OF_DAY, hour);
c.set(Calendar.MINUTE, minutes);
digitalClock.updateTime(c);
+
+ // Set the repeat text or leave it blank if it does not repeat.
TextView daysOfWeekView = (TextView) digitalClock.findViewById(R.id.daysOfWeek);
- daysOfWeekView.setText(daysOfWeek.toString(AlarmClock.this, false));
+ final String daysOfWeekStr =
+ daysOfWeek.toString(AlarmClock.this, false);
+ if (daysOfWeekStr != null && daysOfWeekStr.length() != 0) {
+ daysOfWeekView.setText(daysOfWeekStr);
+ daysOfWeekView.setVisibility(View.VISIBLE);
+ } else {
+ daysOfWeekView.setVisibility(View.GONE);
+ }
+
+ // Display the label
+ TextView labelView =
+ (TextView) digitalClock.findViewById(R.id.label);
+ if (label != null && label.length() != 0) {
+ labelView.setText(label);
+ } else {
+ labelView.setText(R.string.default_label);
+ }
// Build context menu
digitalClock.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
diff --git a/src/com/android/alarmclock/AlarmReceiver.java b/src/com/android/alarmclock/AlarmReceiver.java
index af18b7b..1137952 100644
--- a/src/com/android/alarmclock/AlarmReceiver.java
+++ b/src/com/android/alarmclock/AlarmReceiver.java
@@ -62,6 +62,7 @@
* so that the current app's notification management is not disturbed */
Intent fireAlarm = new Intent(context, AlarmAlert.class);
fireAlarm.putExtra(Alarms.ID, id);
+ fireAlarm.putExtra(Alarms.LABEL, intent.getStringExtra(Alarms.LABEL));
fireAlarm.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
context.startActivity(fireAlarm);
}
diff --git a/src/com/android/alarmclock/Alarms.java b/src/com/android/alarmclock/Alarms.java
index 56af9b3..8817234 100644
--- a/src/com/android/alarmclock/Alarms.java
+++ b/src/com/android/alarmclock/Alarms.java
@@ -42,9 +42,11 @@
public final static String ALARM_ALERT_ACTION = "com.android.alarmclock.ALARM_ALERT";
public final static String ID = "alarm_id";
public final static String TIME = "alarm_time";
+ public final static String LABEL = "alarm_label";
final static String PREF_SNOOZE_ID = "snooze_id";
final static String PREF_SNOOZE_TIME = "snooze_time";
+ final static String PREF_SNOOZE_LABEL = "snooze_label";
private final static String DM12 = "E h:mm aa";
private final static String DM24 = "E k:mm";
@@ -480,8 +482,9 @@
* Calculates next scheduled alert
*/
static class AlarmCalculator implements AlarmSettings {
- public long mMinAlert = Long.MAX_VALUE;
- public int mMinIdx = -1;
+ private long mMinAlert = Long.MAX_VALUE;
+ private int mMinIdx = -1;
+ private String mLabel;
/**
* returns next scheduled alert, MAX_VALUE if none
@@ -492,6 +495,9 @@
public int getIndex() {
return mMinIdx;
}
+ public String getLabel() {
+ return mLabel;
+ }
public void reportAlarm(
int idx, boolean enabled, int hour, int minutes,
@@ -505,6 +511,7 @@
if (atTime < mMinAlert) {
mMinIdx = idx;
mMinAlert = atTime;
+ mLabel = message;
}
}
}
@@ -564,7 +571,7 @@
long atTime = ac.getAlert();
if (atTime < Long.MAX_VALUE) {
- enableAlert(context, id, atTime);
+ enableAlert(context, id, ac.getLabel(), atTime);
} else {
disableAlert(context, id);
}
@@ -586,13 +593,15 @@
* @param id Alarm ID.
* @param atTimeInMillis milliseconds since epoch
*/
- static void enableAlert(Context context, int id, long atTimeInMillis) {
+ static void enableAlert(Context context, int id, String label,
+ long atTimeInMillis) {
AlarmManager am = (AlarmManager)
context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(ALARM_ALERT_ACTION);
if (Log.LOGV) Log.v("** setAlert id " + id + " atTime " + atTimeInMillis);
intent.putExtra(ID, id);
+ intent.putExtra(LABEL, label);
intent.putExtra(TIME, atTimeInMillis);
PendingIntent sender = PendingIntent.getBroadcast(
context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
@@ -631,12 +640,13 @@
}
static void saveSnoozeAlert(final Context context, int id,
- long atTimeInMillis) {
+ long atTimeInMillis, String label) {
SharedPreferences prefs = context.getSharedPreferences(
AlarmClock.PREFERENCES, 0);
SharedPreferences.Editor ed = prefs.edit();
ed.putInt(PREF_SNOOZE_ID, id);
ed.putLong(PREF_SNOOZE_TIME, atTimeInMillis);
+ ed.putString(PREF_SNOOZE_LABEL, label);
ed.commit();
}
@@ -646,7 +656,7 @@
static int disableSnoozeAlert(final Context context) {
int id = getSnoozeAlarmId(context);
if (id == -1) return -1;
- saveSnoozeAlert(context, -1, 0);
+ saveSnoozeAlert(context, -1, 0, null);
return id;
}
@@ -671,7 +681,13 @@
if (id == -1) return false;
long atTimeInMillis = prefs.getLong(PREF_SNOOZE_TIME, -1);
if (id == -1) return false;
- enableAlert(context, id, atTimeInMillis);
+ // Try to get the label from the snooze preference. If null, use the
+ // default label.
+ String label = prefs.getString(PREF_SNOOZE_LABEL, null);
+ if (label == null) {
+ label = context.getString(R.string.default_label);
+ }
+ enableAlert(context, id, label, atTimeInMillis);
return true;
}
diff --git a/src/com/android/alarmclock/SetAlarm.java b/src/com/android/alarmclock/SetAlarm.java
index d8c9b46..807b469 100644
--- a/src/com/android/alarmclock/SetAlarm.java
+++ b/src/com/android/alarmclock/SetAlarm.java
@@ -27,9 +27,10 @@
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
+import android.preference.CheckBoxPreference;
+import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
-import android.preference.CheckBoxPreference;
import android.preference.PreferenceScreen;
import android.text.format.DateFormat;
import android.view.Menu;
@@ -43,6 +44,7 @@
public class SetAlarm extends PreferenceActivity
implements Alarms.AlarmSettings, TimePickerDialog.OnTimeSetListener {
+ private EditTextPreference mLabel;
private CheckBoxPreference mAlarmOnPref;
private Preference mTimePref;
private AlarmPreference mAlarmPref;
@@ -98,6 +100,16 @@
super.onCreate(icicle);
addPreferencesFromResource(R.xml.alarm_prefs);
+ mLabel = (EditTextPreference) findPreference("label");
+ mLabel.setOnPreferenceChangeListener(
+ new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference p,
+ Object newValue) {
+ p.setSummary((String) newValue);
+ saveAlarm(false, (String) newValue);
+ return true;
+ }
+ });
mAlarmOnPref = (CheckBoxPreference)findPreference("on");
mTimePref = findPreference("time");
mAlarmPref = (AlarmPreference) findPreference("alarm");
@@ -193,9 +205,14 @@
*/
public void reportAlarm(
int idx, boolean enabled, int hour, int minutes,
- Alarms.DaysOfWeek daysOfWeek, boolean vibrate,String message,
+ Alarms.DaysOfWeek daysOfWeek, boolean vibrate, String label,
String alert) {
+ if (label == null || label.length() == 0) {
+ label = getString(R.string.default_label);
+ }
+ mLabel.setText(label);
+ mLabel.setSummary(label);
mHour = hour;
mMinutes = minutes;
mAlarmOnPref.setChecked(enabled);
@@ -251,10 +268,18 @@
}
private void saveAlarm(boolean popToast) {
+ saveAlarm(popToast, mLabel.getText());
+ }
+
+ /**
+ * This version of saveAlarm uses the passed in label since mLabel may
+ * contain the old value (i.e. during the preference value change).
+ */
+ private void saveAlarm(boolean popToast, String label) {
if (mReportAlarmCalled && mAlarmPref.mAlert != null) {
String alertString = mAlarmPref.mAlert.toString();
saveAlarm(this, mId, mAlarmOnPref.isChecked(), mHour, mMinutes,
- mDaysOfWeek, mVibratePref.isChecked(), alertString,
+ mDaysOfWeek, mVibratePref.isChecked(), label, alertString,
popToast);
}
}
@@ -265,14 +290,14 @@
*/
private static void saveAlarm(
Context context, int id, boolean enabled, int hour, int minute,
- Alarms.DaysOfWeek daysOfWeek, boolean vibrate, String alert,
- boolean popToast) {
- if (Log.LOGV) Log.v("** saveAlarm " + id + " " + enabled + " " + hour +
- " " + minute + " vibe " + vibrate);
+ Alarms.DaysOfWeek daysOfWeek, boolean vibrate, String label,
+ String alert, boolean popToast) {
+ if (Log.LOGV) Log.v("** saveAlarm " + id + " " + label + " " + enabled
+ + " " + hour + " " + minute + " vibe " + vibrate);
// Fix alert string first
Alarms.setAlarm(context, id, enabled, hour, minute, daysOfWeek, vibrate,
- "", alert);
+ label, alert);
if (enabled && popToast) {
popAlarmSetToast(context, hour, minute, daysOfWeek);
@@ -392,7 +417,7 @@
int hour = nowHour + (nowMinute == 0? 1 : 0);
saveAlarm(this, mId, true, hour, minutes, mDaysOfWeek, true,
- mAlarmPref.mAlert.toString(), true);
+ mLabel.getText(), mAlarmPref.mAlert.toString(), true);
}
}