Unify general settings

Make Email GeneralPreferences subclass GeneralPrefsFragment.

Only contains a minimum of code to strip out archive-related prefs,
which are not relevant to the current state of Email back-ends.

(These actions could be relevant for Gmail IMAP extensions if support is added for them)

b/9566150

Change-Id: Ie8e26379ed504c7d96c2a2f8e1c843bbe0582cc7
This commit is contained in:
Tony Mantler 2014-06-17 11:33:16 -07:00
parent 2a5dac19e7
commit 6f747eb776
2 changed files with 14 additions and 131 deletions

View File

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- App-wide preferences -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="confirm-delete"
android:persistent="true"
android:defaultValue="false"
android:title="@string/general_preference_confirm_delete_label" />
<CheckBoxPreference
android:key="confirm-send"
android:persistent="true"
android:defaultValue="false"
android:title="@string/general_preference_confirm_send_label" />
<ListPreference
android:key="auto-advance-mode-widget"
android:persistent="false"
android:title="@string/auto_advance_label"
android:summary="@string/auto_advance_summary"
android:entries="@array/prefEntries_autoAdvance"
android:entryValues="@array/prefValues_autoAdvance"
android:dialogTitle="@string/auto_advance_help_title" />
<CheckBoxPreference
android:key="conversation-list-sender-image"
android:persistent="true"
android:defaultValue="true"
android:title="@string/preference_sender_image_title"
android:summary="@string/preference_sender_image_description" />
<CheckBoxPreference
android:key="default-reply-all"
android:persistent="true"
android:defaultValue="false"
android:title="@string/preferences_default_reply_all_title"
android:summary="@string/preferences_default_reply_all_summary" />
<CheckBoxPreference
android:key="conversation-list-swipe"
android:persistent="true"
android:defaultValue="true"
android:title="@string/preference_swipe_title_delete"
android:summary="@string/preference_swipe_description" />
</PreferenceScreen>

View File

@ -16,87 +16,32 @@
package com.android.email.activity.setup;
import android.content.ContentResolver;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.android.email.R;
import com.android.email.provider.EmailProvider;
import com.android.mail.preferences.MailPrefs;
import com.android.mail.ui.settings.ClearPictureApprovalsDialogFragment;
import com.android.mail.preferences.MailPrefs.PreferenceKeys;
import com.android.mail.ui.settings.GeneralPrefsFragment;
public class GeneralPreferences extends PreferenceFragment implements
OnPreferenceChangeListener {
public class GeneralPreferences extends GeneralPrefsFragment {
private static final String AUTO_ADVANCE_MODE_WIDGET = "auto-advance-mode-widget";
private MailPrefs mMailPrefs;
private ListPreference mAutoAdvance;
public GeneralPreferences() {}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
mMailPrefs = MailPrefs.get(getActivity());
getPreferenceManager().setSharedPreferencesName(mMailPrefs.getSharedPreferencesName());
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.general_preferences);
}
@Override
public void onResume() {
loadSettings();
super.onResume();
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
// Indicate we need to send notifications to UI
if (AUTO_ADVANCE_MODE_WIDGET.equals(key)) {
mMailPrefs.setAutoAdvanceMode(mAutoAdvance.findIndexOfValue((String) newValue) + 1);
return true;
final PreferenceScreen ps = getPreferenceScreen();
final Preference removalAction = findPreference(PreferenceKeys.REMOVAL_ACTION);
if (removalAction != null) {
ps.removePreference(removalAction);
}
return false;
}
private void loadSettings() {
mAutoAdvance = (ListPreference) findPreference(AUTO_ADVANCE_MODE_WIDGET);
mAutoAdvance.setValueIndex(mMailPrefs.getAutoAdvanceMode() - 1);
mAutoAdvance.setOnPreferenceChangeListener(this);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.general_prefs_fragment_menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.clear_picture_approvals_menu_item:
clearDisplayImages();
return true;
final Preference confirmArchive = findPreference(PreferenceKeys.CONFIRM_ARCHIVE);
final PreferenceGroup removalGroup =
(PreferenceGroup) findPreference(REMOVAL_ACTIONS_GROUP);
if (confirmArchive != null) {
removalGroup.removePreference(confirmArchive);
}
return super.onOptionsItemSelected(item);
}
private void clearDisplayImages() {
final ClearPictureApprovalsDialogFragment fragment =
ClearPictureApprovalsDialogFragment.newInstance();
fragment.show(getActivity().getFragmentManager(),
ClearPictureApprovalsDialogFragment.FRAGMENT_TAG);
}
}