summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Chan <mchan@android.com>2012-11-20 07:16:14 -0800
committerMichael Chan <mchan@android.com>2012-12-05 14:39:22 -0800
commit72d1d73a9b5b6f776d7294f4f83bcc1cfdfac4d9 (patch)
treecd5ace628a8660f87d23167725c096b86756512a
parent65a98ff630a601e4dc26855a51736ae0734b99e0 (diff)
downloadandroid_packages_apps_Calendar-72d1d73a9b5b6f776d7294f4f83bcc1cfdfac4d9.tar.gz
android_packages_apps_Calendar-72d1d73a9b5b6f776d7294f4f83bcc1cfdfac4d9.tar.bz2
android_packages_apps_Calendar-72d1d73a9b5b6f776d7294f4f83bcc1cfdfac4d9.zip
Remove vibrate-on-silent-mode per UX
Also show current ringtone (6265196) Cherry-picked from https://googleplex-android-review.googlesource.com/#/c/253780/ https://googleplex-android-review.googlesource.com/#/c/253801/ Bug: 7631982 Bug: 6265196 Change-Id: I7a9212d8672a225ab95c0fa2973ae616b393f005
-rw-r--r--res/values/strings.xml33
-rw-r--r--res/xml/general_preferences.xml9
-rw-r--r--src/com/android/calendar/GeneralPreferences.java68
-rw-r--r--src/com/android/calendar/Utils.java22
-rw-r--r--src/com/android/calendar/alerts/AlertService.java50
-rw-r--r--tests/src/com/android/calendar/alerts/AlertServiceTest.java30
6 files changed, 86 insertions, 126 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5a6472f4..8fad8dcc 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -466,7 +466,7 @@
<string name="preferences_general_title">Calendar view setting</string>
<!-- This is the title of a section in the Settings screen for settings
related to reminders for calendar events -->
- <string name="preferences_reminder_title">Reminder settings</string>
+ <string name="preferences_reminder_title">Notifications \u0026 reminders</string>
<!-- Settings check box label to hide events that the user has declined to attend -->
<string name="preferences_hide_declined_title">Hide declined events</string>
<!-- Settings week start label to start week on specific day-->
@@ -485,8 +485,10 @@
<string name="preferences_alerts_title">Notifications</string>
<!-- Settings dialog label that specifies when the phone should vibrate -->
<string name="preferences_alerts_vibrateWhen_title">Vibrate</string>
+ <!-- The old value for enabling vibration. used only for migrating -->
+ <string translatable="false" name="prefDefault_alerts_vibrate_true">always</string>
<!-- Title of ringtone selector dialog -->
- <string name="preferences_alerts_ringtone_title">Choose ringtone</string>
+ <string name="preferences_alerts_ringtone_title">Sound</string>
<!-- Title of check box label to enable or disable pop-up notifications -->
<string name="preferences_alerts_popup_title">Pop-up notification</string>
<!-- List item label for setting the default number of reminder minutes -->
@@ -513,33 +515,6 @@
<!-- Build version of the application -->
<string name="preferences_build_version">Build version</string>
- <!-- The vibrate notification modes -->
- <string-array name="prefEntries_alerts_vibrateWhen">
- <!-- Always -->
- <item>Always</item>
- <!-- Only when the phone is in Silent mode -->
- <item>Only when silent</item>
- <!-- Never -->
- <item>Never</item>
- </string-array>
-
- <!-- The default vibrateWhen value, when none is set -->
- <string translatable="false" name="prefDefault_alerts_vibrateWhen">never</string>
- <!-- The value to use then migrating from old versions for a true vibrate setting -->
- <string translatable="false" name="prefDefault_alerts_vibrate_true">always</string>
- <!-- The value to use then migrating from old versions for a false vibrate setting -->
- <string translatable="false" name="prefDefault_alerts_vibrate_false">never</string>
-
- <!-- The vibrateWhen values -->
- <string-array translatable="false" name="prefValues_alerts_vibrateWhen">
- <item>always</item>
- <item>silent</item>
- <item>never</item>
- </string-array>
-
- <!-- Dialog title for the Vibrate dialog -->
- <string name="prefDialogTitle_vibrateWhen">Vibrate</string>
-
<!-- Widget -->
<skip/>
<!-- Title for calendar gadget when displayed in list of all other gadgets -->
diff --git a/res/xml/general_preferences.xml b/res/xml/general_preferences.xml
index 0a2c14ce..674d0445 100644
--- a/res/xml/general_preferences.xml
+++ b/res/xml/general_preferences.xml
@@ -64,14 +64,11 @@
android:ringtoneType="notification"
android:defaultValue="content://settings/system/notification_sound" />
- <ListPreference
+ <CheckBoxPreference
android:layout="?android:attr/preferenceLayoutChild"
- android:key="preferences_alerts_vibrateWhen"
+ android:key="preferences_alerts_vibrate"
android:title="@string/preferences_alerts_vibrateWhen_title"
- android:entries="@array/prefEntries_alerts_vibrateWhen"
- android:entryValues="@array/prefValues_alerts_vibrateWhen"
- android:defaultValue="@string/prefDefault_alerts_vibrateWhen"
- android:dialogTitle="@string/prefDialogTitle_vibrateWhen" />
+ android:defaultValue="false" />
<CheckBoxPreference
android:layout="?android:attr/preferenceLayoutChild"
diff --git a/src/com/android/calendar/GeneralPreferences.java b/src/com/android/calendar/GeneralPreferences.java
index abaa2b66..d98d3e65 100644
--- a/src/com/android/calendar/GeneralPreferences.java
+++ b/src/com/android/calendar/GeneralPreferences.java
@@ -22,6 +22,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.media.Ringtone;
+import android.media.RingtoneManager;
+import android.net.Uri;
import android.os.Bundle;
import android.os.Vibrator;
import android.preference.CheckBoxPreference;
@@ -59,7 +62,6 @@ public class GeneralPreferences extends PreferenceFragment implements
public static final String KEY_ALERTS_CATEGORY = "preferences_alerts_category";
public static final String KEY_ALERTS = "preferences_alerts";
public static final String KEY_ALERTS_VIBRATE = "preferences_alerts_vibrate";
- public static final String KEY_ALERTS_VIBRATE_WHEN = "preferences_alerts_vibrateWhen";
public static final String KEY_ALERTS_RINGTONE = "preferences_alerts_ringtone";
public static final String KEY_ALERTS_POPUP = "preferences_alerts_popup";
@@ -102,7 +104,7 @@ public class GeneralPreferences extends PreferenceFragment implements
public static final boolean DEFAULT_SHOW_WEEK_NUM = false;
CheckBoxPreference mAlert;
- ListPreference mVibrateWhen;
+ CheckBoxPreference mVibrate;
RingtonePreference mRingtone;
CheckBoxPreference mPopup;
CheckBoxPreference mUseHomeTZ;
@@ -141,17 +143,21 @@ public class GeneralPreferences extends PreferenceFragment implements
final PreferenceScreen preferenceScreen = getPreferenceScreen();
mAlert = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS);
- mVibrateWhen = (ListPreference) preferenceScreen.findPreference(KEY_ALERTS_VIBRATE_WHEN);
+ mVibrate = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_VIBRATE);
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator == null || !vibrator.hasVibrator()) {
PreferenceCategory mAlertGroup = (PreferenceCategory) preferenceScreen
.findPreference(KEY_ALERTS_CATEGORY);
- mAlertGroup.removePreference(mVibrateWhen);
- } else {
- mVibrateWhen.setSummary(mVibrateWhen.getEntry());
+ mAlertGroup.removePreference(mVibrate);
}
mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_ALERTS_RINGTONE);
+ String ringToneUri = Utils.getSharedPreference(activity, KEY_ALERTS_RINGTONE, "");
+ if (!TextUtils.isEmpty(ringToneUri)) {
+ String ringtone = getRingtoneTitleFromUri(getActivity(), ringToneUri);
+ mRingtone.setSummary(ringtone == null ? "" : ringtone);
+ }
+
mPopup = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_POPUP);
mUseHomeTZ = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HOME_TZ_ENABLED);
mHideDeclined = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HIDE_DECLINED);
@@ -181,8 +187,8 @@ public class GeneralPreferences extends PreferenceFragment implements
}
@Override
- public void onResume() {
- super.onResume();
+ public void onStart() {
+ super.onStart();
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
setPreferenceListeners(this);
@@ -199,16 +205,15 @@ public class GeneralPreferences extends PreferenceFragment implements
mDefaultReminder.setOnPreferenceChangeListener(listener);
mRingtone.setOnPreferenceChangeListener(listener);
mHideDeclined.setOnPreferenceChangeListener(listener);
- mVibrateWhen.setOnPreferenceChangeListener(listener);
-
+ mVibrate.setOnPreferenceChangeListener(listener);
}
@Override
- public void onPause() {
- super.onPause();
+ public void onStop() {
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
setPreferenceListeners(null);
+ super.onStop();
}
@Override
@@ -266,17 +271,32 @@ public class GeneralPreferences extends PreferenceFragment implements
mDefaultReminder.setValue((String) newValue);
mDefaultReminder.setSummary(mDefaultReminder.getEntry());
} else if (preference == mRingtone) {
- // TODO update this after b/3417832 is fixed
+ if (newValue instanceof String) {
+ String ringtone = getRingtoneTitleFromUri(getActivity(), (String) newValue);
+ mRingtone.setSummary(ringtone == null ? "" : ringtone);
+ }
+ return true;
+ } else if (preference == mVibrate) {
+ mVibrate.setChecked((Boolean) newValue);
return true;
- } else if (preference == mVibrateWhen) {
- mVibrateWhen.setValue((String)newValue);
- mVibrateWhen.setSummary(mVibrateWhen.getEntry());
} else {
return true;
}
return false;
}
+ public String getRingtoneTitleFromUri(Context context, String uri) {
+ if (TextUtils.isEmpty(uri)) {
+ return null;
+ }
+
+ Ringtone ring = RingtoneManager.getRingtone(getActivity(), Uri.parse(uri));
+ if (ring != null) {
+ return ring.getTitle(context);
+ }
+ return null;
+ }
+
/**
* If necessary, upgrades previous versions of preferences to the current
* set of keys and values.
@@ -284,13 +304,9 @@ public class GeneralPreferences extends PreferenceFragment implements
*/
private void migrateOldPreferences(SharedPreferences prefs) {
// If needed, migrate vibration setting from a previous version
- if (!prefs.contains(KEY_ALERTS_VIBRATE_WHEN) &&
- prefs.contains(KEY_ALERTS_VIBRATE)) {
- int stringId = prefs.getBoolean(KEY_ALERTS_VIBRATE, false) ?
- R.string.prefDefault_alerts_vibrate_true :
- R.string.prefDefault_alerts_vibrate_false;
- mVibrateWhen.setValue(getActivity().getString(stringId));
- }
+
+ mVibrate.setChecked(Utils.getDefaultVibrate(getActivity(), prefs));
+
// If needed, migrate the old alerts type settin
if (!prefs.contains(KEY_ALERTS) && prefs.contains(KEY_ALERTS_TYPE)) {
String type = prefs.getString(KEY_ALERTS_TYPE, ALERT_TYPE_STATUS_BAR);
@@ -319,13 +335,11 @@ public class GeneralPreferences extends PreferenceFragment implements
*/
private void updateChildPreferences() {
if (mAlert.isChecked()) {
- mVibrateWhen.setEnabled(true);
+ mVibrate.setEnabled(true);
mRingtone.setEnabled(true);
mPopup.setEnabled(true);
} else {
- mVibrateWhen.setValue(
- getActivity().getString(R.string.prefDefault_alerts_vibrate_false));
- mVibrateWhen.setEnabled(false);
+ mVibrate.setEnabled(false);
mRingtone.setEnabled(false);
mPopup.setEnabled(false);
}
diff --git a/src/com/android/calendar/Utils.java b/src/com/android/calendar/Utils.java
index 3afcfd44..e21a8f32 100644
--- a/src/com/android/calendar/Utils.java
+++ b/src/com/android/calendar/Utils.java
@@ -116,6 +116,8 @@ public class Utils {
public static final String KEY_QUICK_RESPONSES = "preferences_quick_responses";
+ public static final String KEY_ALERTS_VIBRATE_WHEN = "preferences_alerts_vibrateWhen";
+
public static final String APPWIDGET_DATA_TYPE = "vnd.android.data/update";
static final String MACHINE_GENERATED_ADDRESS = "calendar.google.com";
@@ -224,6 +226,26 @@ public class Utils {
return mTZUtils.formatDateRange(context, startMillis, endMillis, flags);
}
+ public static boolean getDefaultVibrate(Context context, SharedPreferences prefs) {
+ boolean vibrate;
+ if (prefs.contains(KEY_ALERTS_VIBRATE_WHEN)) {
+ // Migrate setting to new 4.2 behavior
+ //
+ // silent and never -> off
+ // always -> on
+ String vibrateWhen = prefs.getString(KEY_ALERTS_VIBRATE_WHEN, null);
+ vibrate = vibrateWhen != null && vibrateWhen.equals(context
+ .getString(R.string.prefDefault_alerts_vibrate_true));
+ prefs.edit().remove(KEY_ALERTS_VIBRATE_WHEN).commit();
+ Log.d(TAG, "Migrating KEY_ALERTS_VIBRATE_WHEN(" + vibrateWhen
+ + ") to KEY_ALERTS_VIBRATE = " + vibrate);
+ } else {
+ vibrate = prefs.getBoolean(GeneralPreferences.KEY_ALERTS_VIBRATE,
+ false);
+ }
+ return vibrate;
+ }
+
public static String[] getSharedPreference(Context context, String key, String[] defaultValue) {
SharedPreferences prefs = GeneralPreferences.getSharedPreferences(context);
Set<String> ss = prefs.getStringSet(key, null);
diff --git a/src/com/android/calendar/alerts/AlertService.java b/src/com/android/calendar/alerts/AlertService.java
index 9811dabf..94ffd9a6 100644
--- a/src/com/android/calendar/alerts/AlertService.java
+++ b/src/com/android/calendar/alerts/AlertService.java
@@ -26,7 +26,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
-import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -44,7 +43,6 @@ import android.text.format.Time;
import android.util.Log;
import com.android.calendar.GeneralPreferences;
-import com.android.calendar.R;
import com.android.calendar.Utils;
import java.util.ArrayList;
@@ -506,7 +504,6 @@ public class AlertService extends Service {
// Use app local storage to keep track of fired alerts to fix problem of multiple
// installed calendar apps potentially causing missed alarms.
boolean newAlertOverride = false;
- String alertIdStr = Long.toString(alertId);
if (AlertUtils.BYPASS_DB && ((currentTime - alarmTime) / MINUTE_MS < 1)) {
// To avoid re-firing alerts, only fire if alarmTime is very recent. Otherwise
// we can get refires for non-dismissed alerts after app installation, or if the
@@ -588,18 +585,6 @@ public class AlertService extends Service {
}
// TODO: Prefer accepted events in case of ties.
- int newStatus;
- switch (status) {
- case Attendees.ATTENDEE_STATUS_ACCEPTED:
- newStatus = 2;
- break;
- case Attendees.ATTENDEE_STATUS_TENTATIVE:
- newStatus = 1;
- break;
- default:
- newStatus = 0;
- }
-
NotificationInfo newInfo = new NotificationInfo(eventName, location,
description, beginTime, endTime, eventId, allDay, newAlert);
@@ -831,40 +816,7 @@ public class AlertService extends Service {
private boolean getDefaultVibrate() {
if (defaultVibrate < 0) {
- // Find out the circumstances under which to vibrate.
- // Migrate from pre-Froyo boolean setting if necessary.
- String vibrateWhen; // "always" or "silent" or "never"
- if(prefs.contains(GeneralPreferences.KEY_ALERTS_VIBRATE_WHEN))
- {
- // Look up Froyo setting
- vibrateWhen =
- prefs.getString(GeneralPreferences.KEY_ALERTS_VIBRATE_WHEN, null);
- } else if(prefs.contains(GeneralPreferences.KEY_ALERTS_VIBRATE)) {
- // No Froyo setting. Migrate pre-Froyo setting to new Froyo-defined value.
- boolean vibrate =
- prefs.getBoolean(GeneralPreferences.KEY_ALERTS_VIBRATE, false);
- vibrateWhen = vibrate ?
- context.getString(R.string.prefDefault_alerts_vibrate_true) :
- context.getString(R.string.prefDefault_alerts_vibrate_false);
- } else {
- // No setting. Use Froyo-defined default.
- vibrateWhen = context.getString(R.string.prefDefault_alerts_vibrateWhen);
- }
-
- if (vibrateWhen.equals("always")) {
- defaultVibrate = 1;
- } else if (!vibrateWhen.equals("silent")) {
- defaultVibrate = 0;
- } else {
- // Settings are to vibrate when silent. Return true if it is now silent.
- AudioManager audioManager =
- (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
- if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
- defaultVibrate = 1;
- } else {
- defaultVibrate = 0;
- }
- }
+ defaultVibrate = Utils.getDefaultVibrate(context, prefs) ? 1 : 0;
}
return defaultVibrate == 1;
}
diff --git a/tests/src/com/android/calendar/alerts/AlertServiceTest.java b/tests/src/com/android/calendar/alerts/AlertServiceTest.java
index ef472866..75a14b7b 100644
--- a/tests/src/com/android/calendar/alerts/AlertServiceTest.java
+++ b/tests/src/com/android/calendar/alerts/AlertServiceTest.java
@@ -47,8 +47,7 @@ public class AlertServiceTest extends AndroidTestCase {
class MockSharedPreferences implements SharedPreferences {
- /* "always", "silent", depends on ringer mode */
- private String mVibrateWhen;
+ private Boolean mVibrate;
private String mRingtone;
private Boolean mPopup;
@@ -66,14 +65,14 @@ public class AlertServiceTest extends AndroidTestCase {
}
void init() {
- mVibrateWhen = "always";
+ mVibrate = true;
mRingtone = "/some/cool/ringtone";
mPopup = true;
}
@Override
public boolean contains(String key) {
- if (GeneralPreferences.KEY_ALERTS_VIBRATE_WHEN.equals(key)) {
+ if (GeneralPreferences.KEY_ALERTS_VIBRATE.equals(key)) {
return true;
}
return false;
@@ -81,6 +80,17 @@ public class AlertServiceTest extends AndroidTestCase {
@Override
public boolean getBoolean(String key, boolean defValue) {
+ if (GeneralPreferences.KEY_ALERTS_VIBRATE.equals(key)) {
+ if (mVibrate == null) {
+ Assert.fail(GeneralPreferences.KEY_ALERTS_VIBRATE
+ + " fetched more than once.");
+ }
+ boolean val = mVibrate;
+ if (mStrict) {
+ mVibrate = null;
+ }
+ return val;
+ }
if (GeneralPreferences.KEY_ALERTS_POPUP.equals(key)) {
if (mPopup == null) {
Assert.fail(GeneralPreferences.KEY_ALERTS_POPUP + " fetched more than once.");
@@ -96,17 +106,6 @@ public class AlertServiceTest extends AndroidTestCase {
@Override
public String getString(String key, String defValue) {
- if (GeneralPreferences.KEY_ALERTS_VIBRATE_WHEN.equals(key)) {
- if (mVibrateWhen == null) {
- Assert.fail(GeneralPreferences.KEY_ALERTS_VIBRATE_WHEN
- + " fetched more than once.");
- }
- String val = mVibrateWhen;
- if (mStrict) {
- mVibrateWhen = null;
- }
- return val;
- }
if (GeneralPreferences.KEY_ALERTS_RINGTONE.equals(key)) {
if (mRingtone == null) {
Assert.fail(GeneralPreferences.KEY_ALERTS_RINGTONE
@@ -377,6 +376,7 @@ public class AlertServiceTest extends AndroidTestCase {
assertNull("Unexpected cancel for id " + id, mExpectedNotifications[id]);
}
+ @Override
public void notify(int id, NotificationWrapper nw) {
assertTrue("id out of bound: " + id, 0 <= id);
assertTrue("id out of bound: " + id, id < mExpectedNotifications.length);