Listen for relevant shared preferences changes
b/9566150 Change-Id: If6005de568330d12e2838220b815467d58276d71
This commit is contained in:
parent
988ad6e002
commit
c8d8a8445e
@ -40,8 +40,6 @@ public class GeneralPreferences extends PreferenceFragment implements
|
||||
private MailPrefs mMailPrefs;
|
||||
private ListPreference mAutoAdvance;
|
||||
|
||||
private boolean mSettingsChanged = false;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -57,25 +55,13 @@ public class GeneralPreferences extends PreferenceFragment implements
|
||||
@Override
|
||||
public void onResume() {
|
||||
loadSettings();
|
||||
mSettingsChanged = false;
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (mSettingsChanged) {
|
||||
// Notify the account list that we have changes
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
resolver.notifyChange(EmailProvider.UIPROVIDER_ALL_ACCOUNTS_NOTIFIER, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String key = preference.getKey();
|
||||
// Indicate we need to send notifications to UI
|
||||
mSettingsChanged = true;
|
||||
if (AUTO_ADVANCE_MODE_WIDGET.equals(key)) {
|
||||
mMailPrefs.setAutoAdvanceMode(mAutoAdvance.findIndexOfValue((String) newValue) + 1);
|
||||
return true;
|
||||
@ -83,17 +69,6 @@ public class GeneralPreferences extends PreferenceFragment implements
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||
if (getActivity() == null) {
|
||||
// Guard against monkeys.
|
||||
return false;
|
||||
}
|
||||
// Indicate we need to send notifications to UI
|
||||
mSettingsChanged = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void loadSettings() {
|
||||
mAutoAdvance = (ListPreference) findPreference(AUTO_ADVANCE_MODE_WIDGET);
|
||||
mAutoAdvance.setValueIndex(mMailPrefs.getAutoAdvanceMode() - 1);
|
||||
|
@ -30,6 +30,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.OperationApplicationException;
|
||||
import android.content.PeriodicSync;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.UriMatcher;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
@ -105,6 +106,7 @@ import com.android.emailcommon.utility.IntentUtilities;
|
||||
import com.android.emailcommon.utility.Utility;
|
||||
import com.android.ex.photo.provider.PhotoContract;
|
||||
import com.android.mail.preferences.MailPrefs;
|
||||
import com.android.mail.preferences.MailPrefs.PreferenceKeys;
|
||||
import com.android.mail.providers.Folder;
|
||||
import com.android.mail.providers.FolderList;
|
||||
import com.android.mail.providers.Settings;
|
||||
@ -146,7 +148,8 @@ import java.util.regex.Pattern;
|
||||
* @author mblank
|
||||
*
|
||||
*/
|
||||
public class EmailProvider extends ContentProvider {
|
||||
public class EmailProvider extends ContentProvider
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private static final String TAG = LogTag.getLogTag();
|
||||
|
||||
@ -1037,6 +1040,8 @@ public class EmailProvider extends ContentProvider {
|
||||
public void onLowMemory() {}
|
||||
});
|
||||
|
||||
MailPrefs.get(context).registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -6080,4 +6085,20 @@ public class EmailProvider extends ContentProvider {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (PreferenceKeys.REMOVAL_ACTION.equals(key) ||
|
||||
PreferenceKeys.CONVERSATION_LIST_SWIPE.equals(key) ||
|
||||
PreferenceKeys.SHOW_SENDER_IMAGES.equals(key) ||
|
||||
PreferenceKeys.DEFAULT_REPLY_ALL.equals(key) ||
|
||||
PreferenceKeys.CONVERSATION_OVERVIEW_MODE.equals(key) ||
|
||||
PreferenceKeys.AUTO_ADVANCE_MODE.equals(key) ||
|
||||
PreferenceKeys.SNAP_HEADER_MODE.equals(key) ||
|
||||
PreferenceKeys.CONFIRM_DELETE.equals(key) ||
|
||||
PreferenceKeys.CONFIRM_ARCHIVE.equals(key) ||
|
||||
PreferenceKeys.CONFIRM_SEND.equals(key)) {
|
||||
notifyUI(UIPROVIDER_ALL_ACCOUNTS_NOTIFIER, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user