1d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy/* 2d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * Copyright (C) 2012 The Android Open Source Project 3d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * 4d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * Licensed under the Apache License, Version 2.0 (the "License"); 5d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * you may not use this file except in compliance with the License. 6d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * You may obtain a copy of the License at 7d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * 8d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * http://www.apache.org/licenses/LICENSE-2.0 9d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * 10d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * Unless required by applicable law or agreed to in writing, software 11d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * distributed under the License is distributed on an "AS IS" BASIS, 12d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * See the License for the specific language governing permissions and 14d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * limitations under the License. 15d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy */ 16d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedypackage com.android.mail.preferences; 17d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 18d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport android.content.ContentUris; 19d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport android.content.Context; 20d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport android.database.Cursor; 21d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport android.media.RingtoneManager; 22d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport android.net.Uri; 23d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport android.provider.Settings; 24d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 25cde6eb0eb380f6212b7091d9381b3fec5006f6a8Scott Kennedyimport com.android.mail.providers.Account; 26d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport com.android.mail.providers.Folder; 27cde6eb0eb380f6212b7091d9381b3fec5006f6a8Scott Kennedyimport com.android.mail.providers.UIProvider.AccountCapabilities; 28d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport com.android.mail.providers.UIProvider.FolderCapabilities; 29d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport com.android.mail.utils.NotificationActionUtils.NotificationActionType; 303047a9f03d9febaf2aba1e5ea0827e0b740d1ab2Andrew Sappersteinimport com.google.android.mail.common.base.Strings; 313047a9f03d9febaf2aba1e5ea0827e0b740d1ab2Andrew Sappersteinimport com.google.common.collect.ImmutableSet; 32d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 33d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport java.util.LinkedHashSet; 34d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedyimport java.util.Set; 35d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 36d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy/** 37d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * Preferences relevant to one specific folder. In Email, this would only be used for an account's 38d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * inbox. In Gmail, this is used for every account/label pair. 39d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy */ 40d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedypublic class FolderPreferences extends VersionedPrefs { 41d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 42d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy private static final String PREFS_NAME_PREFIX = "Folder"; 43d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 44d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public static final class PreferenceKeys { 45d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy /** Boolean value indicating whether notifications are enabled */ 46d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public static final String NOTIFICATIONS_ENABLED = "notifications-enabled"; 47d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy /** String value of the notification ringtone URI */ 48d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public static final String NOTIFICATION_RINGTONE = "notification-ringtone"; 49d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy /** Boolean value indicating whether we should explicitly vibrate */ 50d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public static final String NOTIFICATION_VIBRATE = "notification-vibrate"; 51d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy /** 52d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * Boolean value indicating whether we notify for every message (<code>true</code>), or just 53d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * once for the folder (<code>false</code>) 54d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy */ 55d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public static final String NOTIFICATION_NOTIFY_EVERY_MESSAGE = 56d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy "notification-notify-every-message"; 57d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 58d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public static final ImmutableSet<String> BACKUP_KEYS = 59d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy new ImmutableSet.Builder<String>() 60d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy .add(NOTIFICATIONS_ENABLED) 61d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy .add(NOTIFICATION_RINGTONE) 62d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy .add(NOTIFICATION_VIBRATE) 63d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy .add(NOTIFICATION_NOTIFY_EVERY_MESSAGE) 64d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy .build(); 65d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 66d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 67d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy private final Folder mFolder; 68d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy /** An id that is constant across app installations. */ 69d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy private final String mPersistentId; 70d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy private final boolean mUseInboxDefaultNotificationSettings; 71d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 72d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy /** 73afb10d038c70c0a8646f0315836c49c704765ff9Tony Mantler * @param accountEmail The account email. This must never change for the account. 7461bd0e84a3b0545a722bbfe931233b47afdf52e2Scott Kennedy * @param folder The folder 75d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy */ 76afb10d038c70c0a8646f0315836c49c704765ff9Tony Mantler public FolderPreferences(final Context context, final String accountEmail, final Folder folder, 77d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final boolean useInboxDefaultNotificationSettings) { 78afb10d038c70c0a8646f0315836c49c704765ff9Tony Mantler this(context, accountEmail, folder, folder.persistentId, 79afb10d038c70c0a8646f0315836c49c704765ff9Tony Mantler useInboxDefaultNotificationSettings); 80d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 81d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 82d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy /** 83d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * A constructor that can be used when no {@link Folder} object is available (like during a 84f3219a170b4518b4f0ee96ab4c8c0d6855e56d6fScott Kennedy * restore). This will function as expected except when calling 85f3219a170b4518b4f0ee96ab4c8c0d6855e56d6fScott Kennedy * {@link #getDefaultNotificationActions(Context)}, so 86d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * {@link #FolderPreferences(Context, String, Folder, boolean)} should be used if at all 87d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * possible. 88d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * 89afb10d038c70c0a8646f0315836c49c704765ff9Tony Mantler * @param accountEmail The account email. This must never change for the account. 90d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * @param persistentId An identifier for the folder that does not change across app 91d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * installations. 92d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy */ 93afb10d038c70c0a8646f0315836c49c704765ff9Tony Mantler public FolderPreferences(final Context context, final String accountEmail, final String persistentId, 94d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final boolean useInboxDefaultNotificationSettings) { 95afb10d038c70c0a8646f0315836c49c704765ff9Tony Mantler this(context, accountEmail, null, persistentId, useInboxDefaultNotificationSettings); 96d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 97d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 98afb10d038c70c0a8646f0315836c49c704765ff9Tony Mantler private FolderPreferences(final Context context, final String accountEmail, final Folder folder, 99d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final String persistentId, final boolean useInboxDefaultNotificationSettings) { 100afb10d038c70c0a8646f0315836c49c704765ff9Tony Mantler super(context, buildSharedPrefsName(accountEmail, persistentId)); 101d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy mFolder = folder; 102d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy mPersistentId = persistentId; 103d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy mUseInboxDefaultNotificationSettings = useInboxDefaultNotificationSettings; 104d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 105d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 106d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy private static String buildSharedPrefsName(final String account, final String persistentId) { 107d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return PREFS_NAME_PREFIX + '-' + account + '-' + persistentId; 108d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 109d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 110d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy @Override 111d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy protected void performUpgrade(final int oldVersion, final int newVersion) { 112d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (oldVersion > newVersion) { 113d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy throw new IllegalStateException( 114d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy "You appear to have downgraded your app. Please clear app data."); 115d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 116d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 117d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 118d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy @Override 119d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy protected boolean canBackup(final String key) { 120d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (mPersistentId == null) { 121d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return false; 122d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 123d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 124d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return PreferenceKeys.BACKUP_KEYS.contains(key); 125d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 126d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 127d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy @Override 128d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy protected Object getBackupValue(final String key, final Object value) { 129d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (PreferenceKeys.NOTIFICATION_RINGTONE.equals(key)) { 130d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return getRingtoneTitle((String) value); 131d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 132d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 133d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return super.getBackupValue(key, value); 134d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 135d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 136d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy @Override 137d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy protected Object getRestoreValue(final String key, final Object value) { 138d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (PreferenceKeys.NOTIFICATION_RINGTONE.equals(key)) { 139d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return getRingtoneUri((String) value); 140d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 141d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 142d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return super.getBackupValue(key, value); 143d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 144d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 145d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy private String getRingtoneTitle(final String ringtoneUriString) { 146d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (ringtoneUriString.length() == 0) { 147d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return ringtoneUriString; 148d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 149d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final Uri uri = Uri.parse(ringtoneUriString); 150d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (RingtoneManager.isDefault(uri)) { 151d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return ringtoneUriString; 152d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 153d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final RingtoneManager ringtoneManager = new RingtoneManager(getContext()); 154d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy ringtoneManager.setType(RingtoneManager.TYPE_NOTIFICATION); 155d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final Cursor cursor = ringtoneManager.getCursor(); 156d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy try { 157d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy while (cursor.moveToNext()) { 158d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final Uri cursorUri = ContentUris.withAppendedId( 159d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy Uri.parse(cursor.getString(RingtoneManager.URI_COLUMN_INDEX)), 160d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy cursor.getLong(RingtoneManager.ID_COLUMN_INDEX)); 161d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (cursorUri.toString().equals(ringtoneUriString)) { 162d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final String title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX); 163d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (!Strings.isNullOrEmpty(title)) { 164d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return title; 165d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 166d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 167d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 168d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } finally { 169d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy cursor.close(); 170d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 171d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return null; 172d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 173d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 174d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy private String getRingtoneUri(final String name) { 175d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (name.length() == 0 || RingtoneManager.isDefault(Uri.parse(name))) { 176d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return name; 177d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 178d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 179d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final RingtoneManager ringtoneManager = new RingtoneManager(getContext()); 180d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy ringtoneManager.setType(RingtoneManager.TYPE_NOTIFICATION); 181d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final Cursor cursor = ringtoneManager.getCursor(); 182d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy try { 183d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy while (cursor.moveToNext()) { 184d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy String title = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX); 185d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy if (name.equals(title)) { 186d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy Uri uri = ContentUris.withAppendedId( 187d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy Uri.parse(cursor.getString(RingtoneManager.URI_COLUMN_INDEX)), 188d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy cursor.getLong(RingtoneManager.ID_COLUMN_INDEX)); 189d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return uri.toString(); 190d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 191d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 192d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } finally { 193d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy cursor.close(); 194d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 195d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return null; 196d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 197d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 198d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy /** 199d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * If <code>true</code>, we use inbox-defaults for notification settings. If <code>false</code>, 200d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy * we use standard defaults. 201d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy */ 202d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy private boolean getUseInboxDefaultNotificationSettings() { 203d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return mUseInboxDefaultNotificationSettings; 204d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 205d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 206d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public boolean isNotificationsEnabledSet() { 207d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return getSharedPreferences().contains(PreferenceKeys.NOTIFICATIONS_ENABLED); 208d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 209d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 210d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public boolean areNotificationsEnabled() { 211d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return getSharedPreferences().getBoolean( 212d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy PreferenceKeys.NOTIFICATIONS_ENABLED, getUseInboxDefaultNotificationSettings()); 213d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 214d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 215d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public void setNotificationsEnabled(final boolean enabled) { 216d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy getEditor().putBoolean(PreferenceKeys.NOTIFICATIONS_ENABLED, enabled).apply(); 217f9024cc52785c8740654dc89296a10a18da83077Scott Kennedy notifyBackupPreferenceChanged(); 218d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 219d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 220d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public String getNotificationRingtoneUri() { 221d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return getSharedPreferences().getString(PreferenceKeys.NOTIFICATION_RINGTONE, 222d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy Settings.System.DEFAULT_NOTIFICATION_URI.toString()); 223d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 224d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 225d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public void setNotificationRingtoneUri(final String uri) { 226d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy getEditor().putString(PreferenceKeys.NOTIFICATION_RINGTONE, uri).apply(); 227f9024cc52785c8740654dc89296a10a18da83077Scott Kennedy notifyBackupPreferenceChanged(); 228d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 229d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 230d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public boolean isNotificationVibrateEnabled() { 231d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return getSharedPreferences().getBoolean(PreferenceKeys.NOTIFICATION_VIBRATE, false); 232d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 233d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 234d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public void setNotificationVibrateEnabled(final boolean enabled) { 235d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy getEditor().putBoolean(PreferenceKeys.NOTIFICATION_VIBRATE, enabled).apply(); 236f9024cc52785c8740654dc89296a10a18da83077Scott Kennedy notifyBackupPreferenceChanged(); 237d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 238d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 239d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public boolean isEveryMessageNotificationEnabled() { 240d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return getSharedPreferences() 241d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy .getBoolean(PreferenceKeys.NOTIFICATION_NOTIFY_EVERY_MESSAGE, false); 242d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 243d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 244d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy public void setEveryMessageNotificationEnabled(final boolean enabled) { 245d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy getEditor().putBoolean(PreferenceKeys.NOTIFICATION_NOTIFY_EVERY_MESSAGE, enabled).apply(); 246f9024cc52785c8740654dc89296a10a18da83077Scott Kennedy notifyBackupPreferenceChanged(); 247d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 248d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 24926f2b30a88a35bc0ae6992c3f4297ebf20bbca53Scott Kennedy public Set<String> getNotificationActions(final Account account) { 250cde6eb0eb380f6212b7091d9381b3fec5006f6a8Scott Kennedy final boolean supportsArchiveRemoveLabel = 251d4796d78b3d6994d77edaf91b176fc3c79bb7362Scott Kennedy mFolder.supportsCapability(FolderCapabilities.ARCHIVE) 252d4796d78b3d6994d77edaf91b176fc3c79bb7362Scott Kennedy || mFolder.supportsCapability(FolderCapabilities.ALLOWS_REMOVE_CONVERSATION); 25343a1cc1adc835f9a5df30ca2558a2aee35019706Andrew Sapperstein final boolean preferDelete = MailPrefs.RemovalActions.DELETE.equals( 254d4796d78b3d6994d77edaf91b176fc3c79bb7362Scott Kennedy MailPrefs.get(getContext()).getRemovalAction( 255d4796d78b3d6994d77edaf91b176fc3c79bb7362Scott Kennedy account.supportsCapability(AccountCapabilities.ARCHIVE))); 256d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final NotificationActionType destructiveActionType = 257cde6eb0eb380f6212b7091d9381b3fec5006f6a8Scott Kennedy supportsArchiveRemoveLabel && !preferDelete ? 25885db140774e0691b703a3aa94a4640631ef814d0Scott Kennedy NotificationActionType.ARCHIVE_REMOVE_LABEL : NotificationActionType.DELETE; 259d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final String destructiveAction = destructiveActionType.getPersistedValue(); 260d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 261d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final String replyAction = 26222cf7e5a491382bacbfb97ccc2dcba86f03f9837Scott Kennedy MailPrefs.get(getContext()).getDefaultReplyAll() 26322cf7e5a491382bacbfb97ccc2dcba86f03f9837Scott Kennedy ? NotificationActionType.REPLY_ALL.getPersistedValue() 264d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy : NotificationActionType.REPLY.getPersistedValue(); 265d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 266d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy final Set<String> notificationActions = new LinkedHashSet<String>(2); 267d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy notificationActions.add(destructiveAction); 268d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy notificationActions.add(replyAction); 269d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy 270d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy return notificationActions; 271d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy } 272d5edd2d02649dffb40065fdb6a16acf91552b800Scott Kennedy} 273