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
This commit is contained in:
Mindy Pereira 2011-11-18 13:54:57 -08:00
parent 6fc728b7cd
commit f579eb8ac3
5 changed files with 53 additions and 37 deletions

View File

@ -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);
}
}
/**

View File

@ -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);
}

View File

@ -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";

View File

@ -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();
}
}
}

View File

@ -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";