Change Email vibrate setting from tri-state to checkbox
Migrate the old value as necessary. Update the unit tests. Cherry-picked from I1c276ffde3496cbc66846ed4a007088d39f20382 with minor changes. Bug: 7624838 Change-Id: I1b3fa331b62f556701bacba5ce9cd64305d9b52a
This commit is contained in:
parent
722b7bc29d
commit
f9997921cb
|
@ -60,7 +60,7 @@ public final class Account extends EmailContent implements AccountColumns, Parce
|
|||
// Whether or not the user has asked for notifications of new mail in this account
|
||||
public final static int FLAGS_NOTIFY_NEW_MAIL = 1<<0;
|
||||
// Whether or not the user has asked for vibration notifications with all new mail
|
||||
public final static int FLAGS_VIBRATE_ALWAYS = 1<<1;
|
||||
public final static int FLAGS_VIBRATE = 1<<1;
|
||||
// Bit mask for the account's deletion policy (see DELETE_POLICY_x below)
|
||||
public static final int FLAGS_DELETE_POLICY_MASK = 1<<2 | 1<<3;
|
||||
public static final int FLAGS_DELETE_POLICY_SHIFT = 2;
|
||||
|
@ -72,8 +72,6 @@ public final class Account extends EmailContent implements AccountColumns, Parce
|
|||
// required by the server; in this state, the user MUST be alerted to the need to update
|
||||
// security settings. Sync adapters SHOULD NOT attempt to sync when this flag is set.
|
||||
public static final int FLAGS_SECURITY_HOLD = 1<<5;
|
||||
// Whether or not the user has asked for vibration notifications when the ringer is silent
|
||||
public static final int FLAGS_VIBRATE_WHEN_SILENT = 1<<6;
|
||||
// Whether the account supports "smart forward" (i.e. the server appends the original
|
||||
// message along with any attachments to the outgoing message)
|
||||
public static final int FLAGS_SUPPORTS_SMART_FORWARD = 1<<7;
|
||||
|
@ -363,8 +361,7 @@ public final class Account extends EmailContent implements AccountColumns, Parce
|
|||
/**
|
||||
* @return the flags for this account
|
||||
* @see #FLAGS_NOTIFY_NEW_MAIL
|
||||
* @see #FLAGS_VIBRATE_ALWAYS
|
||||
* @see #FLAGS_VIBRATE_WHEN_SILENT
|
||||
* @see #FLAGS_VIBRATE
|
||||
*/
|
||||
public int getFlags() {
|
||||
return mFlags;
|
||||
|
@ -373,8 +370,7 @@ public final class Account extends EmailContent implements AccountColumns, Parce
|
|||
/**
|
||||
* Set the flags for this account
|
||||
* @see #FLAGS_NOTIFY_NEW_MAIL
|
||||
* @see #FLAGS_VIBRATE_ALWAYS
|
||||
* @see #FLAGS_VIBRATE_WHEN_SILENT
|
||||
* @see #FLAGS_VIBRATE
|
||||
* @param newFlags the new value for the flags
|
||||
*/
|
||||
public void setFlags(int newFlags) {
|
||||
|
|
|
@ -109,23 +109,6 @@
|
|||
<item>6</item>
|
||||
</string-array>
|
||||
|
||||
<!-- The vibrate notification modes -->
|
||||
<string-array name="account_settings_vibrate_when_entries">
|
||||
<!-- Always -->
|
||||
<item>@string/account_settings_vibrate_when_always</item>
|
||||
<!-- Only when the phone is in Silent mode -->
|
||||
<item>@string/account_settings_vibrate_when_silent</item>
|
||||
<!-- Never -->
|
||||
<item>@string/account_settings_vibrate_when_never</item>
|
||||
</string-array>
|
||||
|
||||
<!-- The vibrate notification values -->
|
||||
<string-array translatable="false" name="account_settings_vibrate_when_values">
|
||||
<item>always</item>
|
||||
<item>silent</item>
|
||||
<item>never</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Auto-advance option values (DO NOT change the order. Code assumes this order)-->
|
||||
<string-array translatable="false" name="general_preference_auto_advance_values">
|
||||
<!-- Move to newer -->
|
||||
|
|
|
@ -1014,17 +1014,6 @@ as <xliff:g id="filename">%s</xliff:g>.</string>
|
|||
|
||||
<!-- On Settings screen, vibrate pop-up menu label -->
|
||||
<string name="account_settings_vibrate_when_label">Vibrate</string>
|
||||
<!-- On Settings screen, vibrate pop-up menu summary text -->
|
||||
<string name="account_settings_vibrate_when_summary">Also vibrate when email arrives</string>
|
||||
<!-- On Settings screen, vibrate pop-up menu option "always" text -->
|
||||
<string name="account_settings_vibrate_when_always">Always</string>
|
||||
<!-- On Settings screen, vibrate pop-up menu option "silent" text -->
|
||||
<string name="account_settings_vibrate_when_silent">Only when silent</string>
|
||||
<!-- On Settings screen, vibrate pop-up menu option "never" text -->
|
||||
<string name="account_settings_vibrate_when_never">Never</string>
|
||||
|
||||
<!-- Dialog title for the Vibrate dialog -->
|
||||
<string name="account_settings_vibrate_when_dlg_title">Vibrate</string>
|
||||
|
||||
<!-- On Settings screen, setting option name -->
|
||||
<string name="account_settings_ringtone">Choose ringtone</string>
|
||||
|
@ -1305,4 +1294,4 @@ as <xliff:g id="filename">%s</xliff:g>.</string>
|
|||
<string name="sent_folder_selection_title">Select server sent items folder for <xliff:g id="account">%s</xliff:g></string>
|
||||
<string name="create_new_folder">Create folder</string>
|
||||
<string name="account_waiting_for_folders_msg">Loading folder list…</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
|
|
@ -107,16 +107,11 @@
|
|||
android:ringtoneType="notification"
|
||||
android:defaultValue="content://settings/system/notification_sound" />
|
||||
|
||||
<ListPreference
|
||||
android:key="account_settings_vibrate_when"
|
||||
android:layout="?android:attr/preferenceLayoutChild"
|
||||
<CheckBoxPreference
|
||||
android:key="account_settings_vibrate"
|
||||
android:dependency="account_notify"
|
||||
android:defaultValue="never"
|
||||
android:title="@string/account_settings_vibrate_when_label"
|
||||
android:summary="@string/account_settings_vibrate_when_summary"
|
||||
android:entries="@array/account_settings_vibrate_when_entries"
|
||||
android:entryValues="@array/account_settings_vibrate_when_values"
|
||||
android:dialogTitle="@string/account_settings_vibrate_when_dlg_title" />
|
||||
android:defaultValue="false"
|
||||
android:title="@string/account_settings_vibrate_when_label" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
|
|
@ -757,12 +757,10 @@ public class NotificationController {
|
|||
void setupSoundAndVibration(Notification.Builder builder, Account account) {
|
||||
final int flags = account.mFlags;
|
||||
final String ringtoneUri = account.mRingtoneUri;
|
||||
final boolean vibrate = (flags & Account.FLAGS_VIBRATE_ALWAYS) != 0;
|
||||
final boolean vibrateWhenSilent = (flags & Account.FLAGS_VIBRATE_WHEN_SILENT) != 0;
|
||||
final boolean isRingerSilent = getRingerMode() != AudioManager.RINGER_MODE_NORMAL;
|
||||
final boolean vibrate = (flags & Account.FLAGS_VIBRATE) != 0;
|
||||
|
||||
int defaults = Notification.DEFAULT_LIGHTS;
|
||||
if (vibrate || (vibrateWhenSilent && isRingerSilent)) {
|
||||
if (vibrate) {
|
||||
defaults |= Notification.DEFAULT_VIBRATE;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,13 +18,11 @@ package com.android.email.activity.setup;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
@ -49,12 +47,10 @@ import com.android.email2.ui.MailActivityEmail;
|
|||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.provider.Account;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.EmailContent.MailboxColumns;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
import com.android.emailcommon.provider.Policy;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
import com.android.mail.providers.UIProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -84,7 +80,8 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
|||
private static final String PREFERENCE_CATEGORY_DATA_USAGE = "data_usage";
|
||||
private static final String PREFERENCE_CATEGORY_NOTIFICATIONS = "account_notifications";
|
||||
private static final String PREFERENCE_NOTIFY = "account_notify";
|
||||
private static final String PREFERENCE_VIBRATE_WHEN = "account_settings_vibrate_when";
|
||||
private static final String PREFERENCE_VIBRATE = "account_settings_vibrate";
|
||||
private static final String PREFERENCE_VIBRATE_OLD = "account_settings_vibrate_when";
|
||||
private static final String PREFERENCE_RINGTONE = "account_ringtone";
|
||||
private static final String PREFERENCE_CATEGORY_SERVER = "account_servers";
|
||||
private static final String PREFERENCE_CATEGORY_POLICIES = "account_policies";
|
||||
|
@ -101,11 +98,6 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
|||
private static final String PREFERENCE_SYSTEM_FOLDERS_TRASH = "system_folders_trash";
|
||||
private static final String PREFERENCE_SYSTEM_FOLDERS_SENT = "system_folders_sent";
|
||||
|
||||
// These strings must match account_settings_vibrate_when_* strings in strings.xml
|
||||
private static final String PREFERENCE_VALUE_VIBRATE_WHEN_ALWAYS = "always";
|
||||
private static final String PREFERENCE_VALUE_VIBRATE_WHEN_SILENT = "silent";
|
||||
private static final String PREFERENCE_VALUE_VIBRATE_WHEN_NEVER = "never";
|
||||
|
||||
private EditTextPreference mAccountDescription;
|
||||
private EditTextPreference mAccountName;
|
||||
private EditTextPreference mAccountSignature;
|
||||
|
@ -114,7 +106,7 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
|||
private CheckBoxPreference mAccountBackgroundAttachments;
|
||||
private CheckBoxPreference mAccountDefault;
|
||||
private CheckBoxPreference mAccountNotify;
|
||||
private ListPreference mAccountVibrateWhen;
|
||||
private CheckBoxPreference mAccountVibrate;
|
||||
private RingtonePreference mAccountRingtone;
|
||||
private CheckBoxPreference mSyncContacts;
|
||||
private CheckBoxPreference mSyncCalendar;
|
||||
|
@ -186,6 +178,8 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
|||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
upgradeVibrateSetting();
|
||||
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.account_settings_preferences);
|
||||
|
||||
|
@ -203,6 +197,20 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
|||
mAccountDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrades the old tri-state vibrate setting to the new boolean value.
|
||||
*/
|
||||
private void upgradeVibrateSetting() {
|
||||
final SharedPreferences sharedPreferences = getPreferenceManager().getSharedPreferences();
|
||||
|
||||
if (!sharedPreferences.contains(PREFERENCE_VIBRATE)) {
|
||||
// Try to migrate the old one
|
||||
final boolean vibrate =
|
||||
"always".equals(sharedPreferences.getString(PREFERENCE_VIBRATE_OLD, ""));
|
||||
sharedPreferences.edit().putBoolean(PREFERENCE_VIBRATE, vibrate);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
if (Logging.DEBUG_LIFECYCLE && MailActivityEmail.DEBUG) {
|
||||
|
@ -330,12 +338,10 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
|||
preferenceChanged(PREFERENCE_NAME, summary);
|
||||
}
|
||||
return false;
|
||||
} else if (key.equals(PREFERENCE_VIBRATE_WHEN)) {
|
||||
final String vibrateSetting = newValue.toString();
|
||||
final int index = mAccountVibrateWhen.findIndexOfValue(vibrateSetting);
|
||||
mAccountVibrateWhen.setSummary(mAccountVibrateWhen.getEntries()[index]);
|
||||
mAccountVibrateWhen.setValue(vibrateSetting);
|
||||
preferenceChanged(PREFERENCE_VIBRATE_WHEN, newValue);
|
||||
} else if (key.equals(PREFERENCE_VIBRATE)) {
|
||||
final boolean vibrateSetting = (Boolean) newValue;
|
||||
mAccountVibrate.setChecked(vibrateSetting);
|
||||
preferenceChanged(PREFERENCE_VIBRATE, newValue);
|
||||
return false;
|
||||
} else {
|
||||
// Default behavior, just indicate that the preferences were written
|
||||
|
@ -589,30 +595,20 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
|||
prefs.edit().putString(PREFERENCE_RINGTONE, mAccount.getRingtone()).apply();
|
||||
|
||||
// Set the vibrator value, or hide it on devices w/o a vibrator
|
||||
mAccountVibrateWhen = (ListPreference) findPreference(PREFERENCE_VIBRATE_WHEN);
|
||||
mAccountVibrate = (CheckBoxPreference) findPreference(PREFERENCE_VIBRATE);
|
||||
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (vibrator.hasVibrator()) {
|
||||
// Calculate the value to set based on the choices, and set the value.
|
||||
final boolean vibrateAlways = 0 != (mAccount.getFlags() & Account.FLAGS_VIBRATE_ALWAYS);
|
||||
final boolean vibrateWhenSilent =
|
||||
0 != (mAccount.getFlags() & Account.FLAGS_VIBRATE_WHEN_SILENT);
|
||||
final String vibrateSetting =
|
||||
vibrateAlways ? PREFERENCE_VALUE_VIBRATE_WHEN_ALWAYS :
|
||||
vibrateWhenSilent ? PREFERENCE_VALUE_VIBRATE_WHEN_SILENT :
|
||||
PREFERENCE_VALUE_VIBRATE_WHEN_NEVER;
|
||||
mAccountVibrateWhen.setValue(vibrateSetting);
|
||||
final boolean vibrateSetting = 0 != (mAccount.getFlags() & Account.FLAGS_VIBRATE);
|
||||
mAccountVibrate.setChecked(vibrateSetting);
|
||||
|
||||
// Update the summary string.
|
||||
final int index = mAccountVibrateWhen.findIndexOfValue(vibrateSetting);
|
||||
mAccountVibrateWhen.setSummary(mAccountVibrateWhen.getEntries()[index]);
|
||||
|
||||
// When the value is changed, update the summary in addition to the setting.
|
||||
mAccountVibrateWhen.setOnPreferenceChangeListener(this);
|
||||
// When the value is changed, update the setting.
|
||||
mAccountVibrate.setOnPreferenceChangeListener(this);
|
||||
} else {
|
||||
// No vibrator present. Remove the preference altogether.
|
||||
PreferenceCategory notificationsCategory = (PreferenceCategory)
|
||||
findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS);
|
||||
notificationsCategory.removePreference(mAccountVibrateWhen);
|
||||
notificationsCategory.removePreference(mAccountVibrate);
|
||||
}
|
||||
|
||||
final Preference retryAccount = findPreference(PREFERENCE_POLICIES_RETRY_ACCOUNT);
|
||||
|
@ -731,7 +727,7 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
|||
// Turn off all controlled flags - will turn them back on while checking UI elements
|
||||
int newFlags = mAccount.getFlags() &
|
||||
~(Account.FLAGS_NOTIFY_NEW_MAIL |
|
||||
Account.FLAGS_VIBRATE_ALWAYS | Account.FLAGS_VIBRATE_WHEN_SILENT |
|
||||
Account.FLAGS_VIBRATE |
|
||||
Account.FLAGS_BACKGROUND_ATTACHMENTS);
|
||||
|
||||
newFlags |= mAccountBackgroundAttachments.isChecked() ?
|
||||
|
@ -747,10 +743,8 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
|||
if (mSyncWindow != null) {
|
||||
mAccount.setSyncLookback(Integer.parseInt(mSyncWindow.getValue()));
|
||||
}
|
||||
if (mAccountVibrateWhen.getValue().equals(PREFERENCE_VALUE_VIBRATE_WHEN_ALWAYS)) {
|
||||
newFlags |= Account.FLAGS_VIBRATE_ALWAYS;
|
||||
} else if (mAccountVibrateWhen.getValue().equals(PREFERENCE_VALUE_VIBRATE_WHEN_SILENT)) {
|
||||
newFlags |= Account.FLAGS_VIBRATE_WHEN_SILENT;
|
||||
if (mAccountVibrate.isChecked()) {
|
||||
newFlags |= Account.FLAGS_VIBRATE;
|
||||
}
|
||||
SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
|
||||
mAccount.setRingtone(prefs.getString(PREFERENCE_RINGTONE, null));
|
||||
|
|
|
@ -70,8 +70,8 @@ public class NotificationControllerTest extends AndroidTestCase {
|
|||
// === Ringer mode change ===
|
||||
mRingerMode = AudioManager.RINGER_MODE_NORMAL;
|
||||
|
||||
// VIBRATE_ALWAYS, with a ringer tone
|
||||
a1.mFlags = Account.FLAGS_VIBRATE_ALWAYS;
|
||||
// VIBRATE, with a ringer tone
|
||||
a1.mFlags = Account.FLAGS_VIBRATE;
|
||||
|
||||
nb.setDefaults(0);
|
||||
nb.setSound(null);
|
||||
|
@ -83,19 +83,6 @@ public class NotificationControllerTest extends AndroidTestCase {
|
|||
assertTrue((n.flags & Notification.FLAG_SHOW_LIGHTS) != 0); // always set
|
||||
assertTrue((n.defaults & Notification.DEFAULT_LIGHTS) != 0); // always set
|
||||
|
||||
// FLAGS_VIBRATE_WHEN_SILENT, with a ringer tone
|
||||
a1.mFlags = Account.FLAGS_VIBRATE_WHEN_SILENT;
|
||||
|
||||
nb.setDefaults(0);
|
||||
nb.setSound(null);
|
||||
mTarget.setupSoundAndVibration(nb, a1);
|
||||
n = nb.getNotification();
|
||||
|
||||
assertEquals(expectedRingtone, n.sound);
|
||||
assertFalse((n.defaults & Notification.DEFAULT_VIBRATE) != 0); // no vibe
|
||||
assertTrue((n.flags & Notification.FLAG_SHOW_LIGHTS) != 0); // always set
|
||||
assertTrue((n.defaults & Notification.DEFAULT_LIGHTS) != 0); // always set
|
||||
|
||||
// No VIBRATE flags, with a ringer tone
|
||||
a1.mFlags = 0;
|
||||
|
||||
|
@ -112,21 +99,8 @@ public class NotificationControllerTest extends AndroidTestCase {
|
|||
// === Ringer mode change ===
|
||||
mRingerMode = AudioManager.RINGER_MODE_VIBRATE;
|
||||
|
||||
// VIBRATE_ALWAYS, with a ringer tone
|
||||
a1.mFlags = Account.FLAGS_VIBRATE_ALWAYS;
|
||||
|
||||
nb.setDefaults(0);
|
||||
nb.setSound(null);
|
||||
mTarget.setupSoundAndVibration(nb, a1);
|
||||
n = nb.getNotification();
|
||||
|
||||
assertEquals(expectedRingtone, n.sound);
|
||||
assertTrue((n.defaults & Notification.DEFAULT_VIBRATE) != 0);
|
||||
assertTrue((n.flags & Notification.FLAG_SHOW_LIGHTS) != 0); // always set
|
||||
assertTrue((n.defaults & Notification.DEFAULT_LIGHTS) != 0); // always set
|
||||
|
||||
// FLAGS_VIBRATE_WHEN_SILENT, with a ringer tone
|
||||
a1.mFlags = Account.FLAGS_VIBRATE_WHEN_SILENT;
|
||||
// VIBRATE, with a ringer tone
|
||||
a1.mFlags = Account.FLAGS_VIBRATE;
|
||||
|
||||
nb.setDefaults(0);
|
||||
nb.setSound(null);
|
||||
|
@ -154,21 +128,8 @@ public class NotificationControllerTest extends AndroidTestCase {
|
|||
// === Ringer mode change ===
|
||||
mRingerMode = AudioManager.RINGER_MODE_SILENT;
|
||||
|
||||
// VIBRATE_ALWAYS, with a ringer tone
|
||||
a1.mFlags = Account.FLAGS_VIBRATE_ALWAYS;
|
||||
|
||||
nb.setDefaults(0);
|
||||
nb.setSound(null);
|
||||
mTarget.setupSoundAndVibration(nb, a1);
|
||||
n = nb.getNotification();
|
||||
|
||||
assertEquals(expectedRingtone, n.sound);
|
||||
assertTrue((n.defaults & Notification.DEFAULT_VIBRATE) != 0);
|
||||
assertTrue((n.flags & Notification.FLAG_SHOW_LIGHTS) != 0); // always set
|
||||
assertTrue((n.defaults & Notification.DEFAULT_LIGHTS) != 0); // always set
|
||||
|
||||
// FLAGS_VIBRATE_WHEN_SILENT, with a ringer tone
|
||||
a1.mFlags = Account.FLAGS_VIBRATE_WHEN_SILENT;
|
||||
// VIBRATE, with a ringer tone
|
||||
a1.mFlags = Account.FLAGS_VIBRATE;
|
||||
|
||||
nb.setDefaults(0);
|
||||
nb.setSound(null);
|
||||
|
|
Loading…
Reference in New Issue