Hide vibrate notification option on no-vibrate devices

* Check for existence of vibrator, hide option if appropriate
* Notifications with vibration are still OK, they are just ignored
* Minor cleanups & renaming

Bug: 2988758
Change-Id: Ia1fd259f57d33a75a54cf1016f66a1c072aba579
This commit is contained in:
Andy Stadler 2010-11-04 21:13:45 -07:00
parent bad09c18d9
commit 9ce244b2e3
2 changed files with 37 additions and 25 deletions

View File

@ -20,45 +20,47 @@
android:key="account_settings">
<EditTextPreference
android:order="1"
android:key="account_description"
android:order="1"
android:title="@string/account_settings_description_label"
android:summary=""
android:dialogTitle="@string/account_settings_description_label" />
<EditTextPreference
android:order="2"
android:key="account_name"
android:order="2"
android:title="@string/account_settings_name_label"
android:summary=""
android:dialogTitle="@string/account_settings_name_label" />
<EditTextPreference
android:order="3"
android:key="account_signature"
android:order="3"
android:title="@string/account_settings_signature_label"
android:summary=""
android:dialogTitle="@string/account_settings_signature_label" />
<ListPreference
android:order="4"
android:key="account_check_frequency"
android:order="4"
android:title="@string/account_settings_mail_check_frequency_label"
android:entries="@array/account_settings_check_frequency_entries"
android:entryValues="@array/account_settings_check_frequency_values"
android:dialogTitle="@string/account_settings_mail_check_frequency_label" />
<!-- Reserve order#5 here for window size (if inserted) -->
<!-- Reserve order#5 here for window size (if inserted) -->
<CheckBoxPreference
android:order="6"
android:key="account_default"
android:order="6"
android:title="@string/account_settings_default_label"
android:summary="@string/account_settings_default_summary" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/account_settings_notifications">
<PreferenceCategory
android:key="account_notifications"
android:title="@string/account_settings_notifications">
<CheckBoxPreference
android:key="account_notify"
@ -67,17 +69,17 @@
android:summary="@string/account_settings_notify_summary" />
<RingtonePreference
android:key="account_ringtone"
android:layout="?android:attr/preferenceLayoutChild"
android:dependency="account_notify"
android:key="account_ringtone"
android:title="@string/account_settings_ringtone"
android:ringtoneType="notification"
android:defaultValue="content://settings/system/notification_sound" />
<ListPreference
android:key="account_settings_vibrate_when"
android:layout="?android:attr/preferenceLayoutChild"
android:dependency="account_notify"
android:key="account_settings_vibrate_when"
android:defaultValue="never"
android:title="@string/account_settings_vibrate_when_label"
android:summary="@string/account_settings_vibrate_when_summary"
@ -100,20 +102,20 @@
android:title="@string/account_settings_outgoing_label" />
<CheckBoxPreference
android:layout="?android:attr/preferenceLayoutChild"
android:key="account_sync_email"
android:layout="?android:attr/preferenceLayoutChild"
android:defaultValue="true"
android:title="@string/account_settings_sync_email_enable"
android:summary="@string/account_settings_sync_email_summary" />
<CheckBoxPreference
android:layout="?android:attr/preferenceLayoutChild"
android:key="account_sync_contacts"
android:layout="?android:attr/preferenceLayoutChild"
android:defaultValue="true"
android:title="@string/account_settings_sync_contacts_enable"
android:summary="@string/account_settings_sync_contacts_summary" />
<CheckBoxPreference
android:layout="?android:attr/preferenceLayoutChild"
android:key="account_sync_calendar"
android:layout="?android:attr/preferenceLayoutChild"
android:defaultValue="true"
android:title="@string/account_settings_sync_calendar_enable"
android:summary="@string/account_settings_sync_calendar_summary" />

View File

@ -38,6 +38,7 @@ import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Vibrator;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
@ -66,22 +67,22 @@ public class AccountSettingsFragment extends PreferenceFragment {
// Keys used for arguments bundle
private static final String BUNDLE_KEY_ACCOUNT_ID = "AccountSettingsFragment.AccountId";
private static final String PREFERENCE_TOP_CATEGORY = "account_settings";
private static final String PREFERENCE_CATEGORY_TOP = "account_settings";
private static final String PREFERENCE_DESCRIPTION = "account_description";
private static final String PREFERENCE_NAME = "account_name";
private static final String PREFERENCE_SIGNATURE = "account_signature";
private static final String PREFERENCE_FREQUENCY = "account_check_frequency";
private static final String PREFERENCE_DEFAULT = "account_default";
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_RINGTONE = "account_ringtone";
private static final String PREFERENCE_SERVER_CATEGORY = "account_servers";
private static final String PREFERENCE_CATEGORY_SERVER = "account_servers";
private static final String PREFERENCE_INCOMING = "incoming";
private static final String PREFERENCE_OUTGOING = "outgoing";
private static final String PREFERENCE_SYNC_CONTACTS = "account_sync_contacts";
private static final String PREFERENCE_SYNC_CALENDAR = "account_sync_calendar";
private static final String PREFERENCE_SYNC_EMAIL = "account_sync_email";
private static final String PREFERENCE_DELETE_ACCOUNT_CATEGORY = "category_delete_account";
private static final String PREFERENCE_DELETE_ACCOUNT = "delete_account";
// These strings must match account_settings_vibrate_when_* strings in strings.xml
@ -350,7 +351,7 @@ public class AccountSettingsFragment extends PreferenceFragment {
mSaveOnExit = true;
PreferenceCategory topCategory =
(PreferenceCategory) findPreference(PREFERENCE_TOP_CATEGORY);
(PreferenceCategory) findPreference(PREFERENCE_CATEGORY_TOP);
topCategory.setTitle(mContext.getString(R.string.account_settings_title_fmt));
mAccountDescription = (EditTextPreference) findPreference(PREFERENCE_DESCRIPTION);
@ -453,13 +454,22 @@ public class AccountSettingsFragment extends PreferenceFragment {
SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
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);
boolean flagsVibrate = 0 != (mAccount.getFlags() & Account.FLAGS_VIBRATE_ALWAYS);
boolean flagsVibrateSilent = 0 != (mAccount.getFlags() & Account.FLAGS_VIBRATE_WHEN_SILENT);
mAccountVibrateWhen.setValue(
flagsVibrate ? PREFERENCE_VALUE_VIBRATE_WHEN_ALWAYS :
flagsVibrateSilent ? PREFERENCE_VALUE_VIBRATE_WHEN_SILENT :
PREFERENCE_VALUE_VIBRATE_WHEN_NEVER);
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator.hasVibrator()) {
boolean flagsVibrate = 0 != (mAccount.getFlags() & Account.FLAGS_VIBRATE_ALWAYS);
boolean flagsVibrateSilent =
0 != (mAccount.getFlags() & Account.FLAGS_VIBRATE_WHEN_SILENT);
mAccountVibrateWhen.setValue(
flagsVibrate ? PREFERENCE_VALUE_VIBRATE_WHEN_ALWAYS :
flagsVibrateSilent ? PREFERENCE_VALUE_VIBRATE_WHEN_SILENT :
PREFERENCE_VALUE_VIBRATE_WHEN_NEVER);
} else {
PreferenceCategory notificationsCategory = (PreferenceCategory)
findPreference(PREFERENCE_CATEGORY_NOTIFICATIONS);
notificationsCategory.removePreference(mAccountVibrateWhen);
}
findPreference(PREFERENCE_INCOMING).setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
@ -493,7 +503,7 @@ public class AccountSettingsFragment extends PreferenceFragment {
});
} else {
PreferenceCategory serverCategory = (PreferenceCategory) findPreference(
PREFERENCE_SERVER_CATEGORY);
PREFERENCE_CATEGORY_SERVER);
serverCategory.removePreference(prefOutgoing);
}
@ -511,7 +521,7 @@ public class AccountSettingsFragment extends PreferenceFragment {
.getSyncAutomatically(acct, EmailContent.AUTHORITY));
} else {
PreferenceCategory serverCategory = (PreferenceCategory) findPreference(
PREFERENCE_SERVER_CATEGORY);
PREFERENCE_CATEGORY_SERVER);
serverCategory.removePreference(mSyncContacts);
serverCategory.removePreference(mSyncCalendar);
serverCategory.removePreference(mSyncEmail);