From 0f52e546ef662e126b7360ad69c8c8f838789ef3 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Thu, 9 Sep 2010 15:34:19 -0700 Subject: [PATCH] Implement General Preferences - Removed the place holder setting - Added "auto-advance" setting, which has "newer", "older" (original behavior, default) and "message list" - Strings were copied from Gmail This CL has preference change only (i.e. the setting isn't used yet). The actual implementation will come later. Change-Id: I9f90a723c67e066fdc536a73490101817a127933 --- res/values/arrays.xml | 38 ++++++++--- res/values/strings.xml | 30 +++++++-- res/xml/general_preferences.xml | 12 ++-- src/com/android/email/Preferences.java | 15 +++++ .../android/email/activity/MessageListXL.java | 3 +- .../android/email/activity/MessageView.java | 2 +- .../activity/setup/AccountSettingsXL.java | 22 +------ .../activity/setup/GeneralPreferences.java | 63 +++++++++++++++++++ 8 files changed, 144 insertions(+), 41 deletions(-) create mode 100644 src/com/android/email/activity/setup/GeneralPreferences.java diff --git a/res/values/arrays.xml b/res/values/arrays.xml index b896f65d6..7cbac40df 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -4,9 +4,9 @@ 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. @@ -18,9 +18,9 @@ - + - + @string/account_setup_options_mail_check_frequency_never @string/account_setup_options_mail_check_frequency_5min @@ -36,10 +36,10 @@ 10 15 30 - 60 + 60 - - + + @string/account_setup_options_mail_check_frequency_push @@ -58,9 +58,9 @@ 10 15 30 - 60 + 60 - + @@ -98,6 +98,26 @@ never + + + + @string/general_preference_auto_advance_newer + + @string/general_preference_auto_advance_older + + @string/general_preference_auto_advance_message_list + + + + + + newer + + older + + list + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 2d370b6a6..ae63c58b3 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -775,10 +775,32 @@ Email Preferences Application Preferences - - Fix All Bugs - - Cheaper than beer + + + Auto-advance + + + Select which screen to show after you delete a message + + Advance to + + Newer message + + Older message + + Message list - + diff --git a/src/com/android/email/Preferences.java b/src/com/android/email/Preferences.java index 387afef19..eb6af8231 100644 --- a/src/com/android/email/Preferences.java +++ b/src/com/android/email/Preferences.java @@ -36,6 +36,13 @@ public class Preferences { private static final String ENABLE_EXCHANGE_FILE_LOGGING = "enableExchangeFileLogging"; private static final String DEVICE_UID = "deviceUID"; private static final String ONE_TIME_INITIALIZATION_PROGRESS = "oneTimeInitializationProgress"; + private static final String AUTO_ADVANCE_DIRECTION = "autoAdvance"; + + public static final int AUTO_ADVANCE_NEWER = 0; + public static final int AUTO_ADVANCE_OLDER = 1; + public static final int AUTO_ADVANCE_MESSAGE_LIST = 2; + // "move to older" was the behavior on older versions. + public static final int AUTO_ADVANCE_DEFAULT = AUTO_ADVANCE_OLDER; private static Preferences sPreferences; @@ -178,6 +185,14 @@ public class Preferences { mSharedPreferences.edit().putInt(ONE_TIME_INITIALIZATION_PROGRESS, progress).commit(); } + public int getAutoAdvanceDirection() { + return mSharedPreferences.getInt(AUTO_ADVANCE_DIRECTION, AUTO_ADVANCE_DEFAULT); + } + + public void setAutoAdvanceDirection(int direction) { + mSharedPreferences.edit().putInt(AUTO_ADVANCE_DIRECTION, direction).commit(); + } + public void save() { } diff --git a/src/com/android/email/activity/MessageListXL.java b/src/com/android/email/activity/MessageListXL.java index 9b52f288e..c0819043f 100644 --- a/src/com/android/email/activity/MessageListXL.java +++ b/src/com/android/email/activity/MessageListXL.java @@ -302,7 +302,8 @@ public class MessageListXL extends Activity implements View.OnClickListener, // the delete triggers mCursorObserver in MessageOrderManager. // first move to older/newer before the actual delete long messageIdToDelete = mFragmentManager.getMessageId(); - if (!moveToOlder()) moveToNewer(); + + if (!moveToOlder()) moveToNewer(); // TODO use "auto-advance" preference ActivityHelper.deleteMessage(this, messageIdToDelete); // If this was the last message, moveToOlder/Newer didn't move the current position. // MessageOrderManager detects the current message is gone, and we go back to the message diff --git a/src/com/android/email/activity/MessageView.java b/src/com/android/email/activity/MessageView.java index cabb978bc..1fe464ede 100644 --- a/src/com/android/email/activity/MessageView.java +++ b/src/com/android/email/activity/MessageView.java @@ -180,7 +180,7 @@ public class MessageView extends MessageViewBase implements View.OnClickListener // the delete triggers mCursorObserver in MessageOrderManager. // first move to older/newer before the actual delete long messageIdToDelete = mMessageId; - boolean moved = moveToOlder() || moveToNewer(); + boolean moved = moveToOlder() || moveToNewer(); // TODO use "auto-advance" preference ActivityHelper.deleteMessage(this, messageIdToDelete); if (!moved) { // this generates a benign warning "Duplicate finish request" because diff --git a/src/com/android/email/activity/setup/AccountSettingsXL.java b/src/com/android/email/activity/setup/AccountSettingsXL.java index e8bffd0a8..dd6320e32 100644 --- a/src/com/android/email/activity/setup/AccountSettingsXL.java +++ b/src/com/android/email/activity/setup/AccountSettingsXL.java @@ -320,7 +320,7 @@ public class AccountSettingsXL extends PreferenceActivity implements OnClickList mAppPreferencesHeader.summary = null; mAppPreferencesHeader.iconRes = 0; mAppPreferencesHeader.icon = null; - mAppPreferencesHeader.fragment = GeneralPreferences.getCanonicalName(); + mAppPreferencesHeader.fragment = GeneralPreferences.class.getCanonicalName(); mAppPreferencesHeader.fragmentArguments = null; } return mAppPreferencesHeader; @@ -609,26 +609,6 @@ public class AccountSettingsXL extends PreferenceActivity implements OnClickList } } - /** - * Placeholder for app-wide preferences - * STOPSHIP - make this real - */ - public static class GeneralPreferences extends PreferenceFragment { - - /** STOPSHIP - this is hardcoded for now because getCanonicalName() doesn't return $ */ - public static String getCanonicalName() { - return "com.android.email.activity.setup.AccountSettingsXL$GeneralPreferences"; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Load the preferences from an XML resource - addPreferencesFromResource(R.xml.general_preferences); - } - } - /** * Dialog fragment to show "exit with unsaved changes?" dialog */ diff --git a/src/com/android/email/activity/setup/GeneralPreferences.java b/src/com/android/email/activity/setup/GeneralPreferences.java new file mode 100644 index 000000000..3f00d42e6 --- /dev/null +++ b/src/com/android/email/activity/setup/GeneralPreferences.java @@ -0,0 +1,63 @@ +/* + * 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. + */ + +package com.android.email.activity.setup; + +import com.android.email.Preferences; +import com.android.email.R; + +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.PreferenceFragment; + +public class GeneralPreferences extends PreferenceFragment { + + private static final String PREFERENCE_AUTO_ADVANCE= "auto_advance"; + + private Preferences mPreferences; + private ListPreference mAutoAdvance; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.general_preferences); + } + + @Override + public void onResume() { + loadSettings(); + super.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + saveSettings(); + } + + private void loadSettings() { + mPreferences = Preferences.getPreferences(getActivity()); + mAutoAdvance = (ListPreference) findPreference(PREFERENCE_AUTO_ADVANCE); + mAutoAdvance.setValueIndex(mPreferences.getAutoAdvanceDirection()); + } + + private void saveSettings() { + mPreferences.setAutoAdvanceDirection( + mAutoAdvance.findIndexOfValue(mAutoAdvance.getValue())); + } +}