From f579eb8ac3c0deacf248468b1648ef971fb65c16 Mon Sep 17 00:00:00 2001 From: Mindy Pereira Date: Fri, 18 Nov 2011 13:54:57 -0800 Subject: [PATCH] Add account should be shown on all Email prefs screens and subscreens on tablet. For phone, should match Gmail and just show it at the top level. Fixes b/5621803 "Add account" button disappeared - IKXEVERESTLTE-3051 Change-Id: I143043485cbb912023fe015a768c6f37c8cad3f5 --- .../setup/AccountServerBaseFragment.java | 11 ++++++ .../email/activity/setup/AccountSettings.java | 34 ---------------- .../setup/AccountSettingsFragment.java | 2 +- .../setup/EmailPreferenceFragment.java | 39 +++++++++++++++++++ .../activity/setup/GeneralPreferences.java | 4 +- 5 files changed, 53 insertions(+), 37 deletions(-) create mode 100644 src/com/android/email/activity/setup/EmailPreferenceFragment.java diff --git a/src/com/android/email/activity/setup/AccountServerBaseFragment.java b/src/com/android/email/activity/setup/AccountServerBaseFragment.java index abc31a135..b1df7474e 100644 --- a/src/com/android/email/activity/setup/AccountServerBaseFragment.java +++ b/src/com/android/email/activity/setup/AccountServerBaseFragment.java @@ -22,6 +22,9 @@ import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; @@ -142,6 +145,14 @@ public abstract class AccountServerBaseFragment extends Fragment if (getArguments() != null) { mSettingsMode = getArguments().getBoolean(BUNDLE_KEY_SETTINGS); } + setHasOptionsMenu(true); + } + + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + MenuItem item = menu.findItem(R.id.add_new_account); + if (item != null && !UiUtilities.useTwoPane(getActivity())) { + item.setVisible(false); + } } /** diff --git a/src/com/android/email/activity/setup/AccountSettings.java b/src/com/android/email/activity/setup/AccountSettings.java index a0e117485..ed5df08de 100644 --- a/src/com/android/email/activity/setup/AccountSettings.java +++ b/src/com/android/email/activity/setup/AccountSettings.java @@ -244,11 +244,6 @@ public class AccountSettings extends PreferenceActivity { return true; } - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - return shouldShowNewAccount(); - } - @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { @@ -307,40 +302,11 @@ public class AccountSettings extends PreferenceActivity { super.onBackPressed(); } - /** - * If the caller requested a specific account to be edited, switch to it. This is a one-shot, - * so the user is free to edit another account as well. - */ - @Override - public Header onGetNewHeader() { - Header result = mRequestedAccountHeader; - mRequestedAccountHeader = null; - return result; - } - private void enableDebugMenu() { mShowDebugMenu = true; invalidateHeaders(); } - /** - * Decide if "add account" should be shown - */ - private boolean shouldShowNewAccount() { - // If in single pane mode, only add accounts at top level - if (!onIsMultiPane()) { - return hasHeaders(); - } else { - // If in multi pane mode, only add accounts when showing a top level fragment - // Note: null is OK; This is the case when we first launch the activity - if ((mCurrentFragment != null) - && !(mCurrentFragment instanceof GeneralPreferences) - && !(mCurrentFragment instanceof DebugFragment) - && !(mCurrentFragment instanceof AccountSettingsFragment)) return false; - } - return true; - } - private void onAddNewAccount() { AccountSetupBasics.actionNewAccount(this); } diff --git a/src/com/android/email/activity/setup/AccountSettingsFragment.java b/src/com/android/email/activity/setup/AccountSettingsFragment.java index 1acc55ba2..443db2458 100644 --- a/src/com/android/email/activity/setup/AccountSettingsFragment.java +++ b/src/com/android/email/activity/setup/AccountSettingsFragment.java @@ -66,7 +66,7 @@ import java.util.ArrayList; * TODO: Can we defer calling addPreferencesFromResource() until after we load the account? This * could reduce flicker. */ -public class AccountSettingsFragment extends PreferenceFragment { +public class AccountSettingsFragment extends EmailPreferenceFragment { // Keys used for arguments bundle private static final String BUNDLE_KEY_ACCOUNT_ID = "AccountSettingsFragment.AccountId"; diff --git a/src/com/android/email/activity/setup/EmailPreferenceFragment.java b/src/com/android/email/activity/setup/EmailPreferenceFragment.java new file mode 100644 index 000000000..0c7c1e4a7 --- /dev/null +++ b/src/com/android/email/activity/setup/EmailPreferenceFragment.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2011 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.activity.UiUtilities; + +import android.os.Bundle; +import android.preference.PreferenceFragment; +import android.view.Menu; +import android.view.MenuInflater; + +public class EmailPreferenceFragment extends PreferenceFragment { + + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setHasOptionsMenu(true); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if (!UiUtilities.useTwoPane(getActivity())) { + menu.clear(); + } + } +} diff --git a/src/com/android/email/activity/setup/GeneralPreferences.java b/src/com/android/email/activity/setup/GeneralPreferences.java index b7c1cee11..a9c296c5e 100644 --- a/src/com/android/email/activity/setup/GeneralPreferences.java +++ b/src/com/android/email/activity/setup/GeneralPreferences.java @@ -21,7 +21,6 @@ import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceCategory; import android.preference.Preference.OnPreferenceChangeListener; -import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import android.widget.Toast; @@ -29,7 +28,8 @@ import com.android.email.Preferences; import com.android.email.R; import com.android.email.activity.UiUtilities; -public class GeneralPreferences extends PreferenceFragment implements OnPreferenceChangeListener { +public class GeneralPreferences extends EmailPreferenceFragment implements + OnPreferenceChangeListener { private static final String PREFERENCE_CATEGORY_KEY = "category_general_preferences";