<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>
<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),
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"
android:paddingTop="-4dp"
android:paddingBottom="-4dp"
android:textSize="28sp"
- android:gravity="left"
android:textColor="@color/white"/>
<LinearLayout android:id="@+id/am_pm"
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"
android:textSize="10sp"
android:textColor="@color/ltgrey"
android:layout_marginLeft="2dp"
- android:gravity="left"/>
+ android:visibility="gone"/>
</com.android.alarmclock.DigitalClock>
<!-- 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>
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>
private AlarmKlaxon mKlaxon;
private int mAlarmId;
+ private String mLabel;
@Override
protected void onCreate(Bundle icicle) {
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 */
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,
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);
disableKeyguard();
mAlarmId = intent.getIntExtra(Alarms.ID, -1);
+ setTitleFromIntent(intent);
/* unset silenced message */
TextView silenced = (TextView)findViewById(R.id.silencedText);
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);
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() {
* 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);
}
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";
* 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
public int getIndex() {
return mMinIdx;
}
+ public String getLabel() {
+ return mLabel;
+ }
public void reportAlarm(
int idx, boolean enabled, int hour, int minutes,
if (atTime < mMinAlert) {
mMinIdx = idx;
mMinAlert = atTime;
+ mLabel = message;
}
}
}
long atTime = ac.getAlert();
if (atTime < Long.MAX_VALUE) {
- enableAlert(context, id, atTime);
+ enableAlert(context, id, ac.getLabel(), atTime);
} else {
disableAlert(context, id);
}
* @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);
}
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();
}
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;
}
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;
}
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;
public class SetAlarm extends PreferenceActivity
implements Alarms.AlarmSettings, TimePickerDialog.OnTimeSetListener {
+ private EditTextPreference mLabel;
private CheckBoxPreference mAlarmOnPref;
private Preference mTimePref;
private AlarmPreference mAlarmPref;
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");
*/
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);
}
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);
}
}
*/
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);
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);
}
}