am df1a68eb: am 43106e9d: Merge "Extend MailboxSettings to handle full folder list" into ub-gmail-ur14-dev

* commit 'df1a68ebd07b0912091a7f78e3428ef5d179c90a':
  Extend MailboxSettings to handle full folder list
This commit is contained in:
Tony Mantler 2014-08-20 21:27:53 +00:00 committed by Android Git Automerger
commit bfd1be2c6e
5 changed files with 130 additions and 43 deletions

View File

@ -822,4 +822,7 @@
<!-- Gmail name for redirecting during account setup -->
<string name="gmail_name">Gmail</string>
<!-- Name for preference entry which leads to the per-folder sync settings activity -->
<string name="folder_sync_settings_pref_title">Folder sync settings</string>
</resources>

View File

@ -53,23 +53,23 @@
android:entryValues="@array/account_settings_check_frequency_values"
android:dialogTitle="@string/account_settings_mail_check_frequency_label" />
<!-- Reserve order#2 here for window size (if inserted) -->
<!-- Reserve order#2,3 here for window size (if inserted) -->
<CheckBoxPreference
android:key="account_sync_email"
android:order="3"
android:order="4"
android:defaultValue="true"
android:title="@string/account_settings_sync_email_enable"
android:summary="@string/account_settings_sync_email_summary" />
<CheckBoxPreference
android:key="account_sync_contacts"
android:order="4"
android:order="5"
android:defaultValue="true"
android:title="@string/account_settings_sync_contacts_enable"
android:summary="@string/account_settings_sync_contacts_summary" />
<CheckBoxPreference
android:key="account_sync_calendar"
android:order="5"
android:order="6"
android:defaultValue="true"
android:title="@string/account_settings_sync_calendar_enable"
android:summary="@string/account_settings_sync_calendar_summary" />
@ -77,7 +77,7 @@
<!-- (will hide on POP3 accounts) -->
<CheckBoxPreference
android:key="account_background_attachments"
android:order="6"
android:order="7"
android:title="@string/account_settings_background_attachments_label"
android:summary="@string/account_settings_background_attachments_summary" />

View File

@ -37,9 +37,11 @@ import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen;
import android.provider.CalendarContract;
import android.provider.ContactsContract;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
@ -89,6 +91,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment
private static final String PREFERENCE_QUICK_RESPONSES = "account_quick_responses";
private static final String PREFERENCE_FREQUENCY = "account_check_frequency";
private static final String PREFERENCE_SYNC_WINDOW = "account_sync_window";
private static final String PREFERENCE_SYNC_SETTINGS = "account_sync_settings";
private static final String PREFERENCE_SYNC_EMAIL = "account_sync_email";
private static final String PREFERENCE_SYNC_CONTACTS = "account_sync_contacts";
private static final String PREFERENCE_SYNC_CALENDAR = "account_sync_calendar";
@ -121,6 +124,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment
private EditTextPreference mAccountSignature;
private ListPreference mCheckFrequency;
private ListPreference mSyncWindow;
private Preference mSyncSettings;
private CheckBoxPreference mInboxVibrate;
private Preference mInboxRingtone;
@ -211,7 +215,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment
}
@Override
public void onSaveInstanceState(Bundle outstate) {
public void onSaveInstanceState(@NonNull Bundle outstate) {
super.onSaveInstanceState(outstate);
if (mCheckFrequency != null) {
outstate.putCharSequenceArray(SAVESTATE_SYNC_INTERVAL_STRINGS,
@ -269,6 +273,18 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment
mInboxRingtone.setSummary(summary);
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
@NonNull Preference preference) {
final String key = preference.getKey();
if (key.equals(PREFERENCE_SYNC_SETTINGS)) {
startActivity(MailboxSettings.getIntent(getActivity(), mUiAccount.allFolderListUri));
return true;
} else {
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
}
/**
* Listen to all preference changes in this class.
* @param preference The changed Preference
@ -417,7 +433,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment
@Override
public Map<String, Object> loadInBackground() {
final Map<String, Object> map = new HashMap<String, Object>();
final Map<String, Object> map = new HashMap<>();
final Account account;
if (!TextUtils.isEmpty(mAccountEmail)) {
@ -571,7 +587,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment
@SuppressWarnings("unused") // temporarily unused pending policy UI
private ArrayList<String> getSystemPoliciesList(Policy policy) {
Resources res = mContext.getResources();
ArrayList<String> policies = new ArrayList<String>();
ArrayList<String> policies = new ArrayList<>();
if (policy.mPasswordMode != Policy.PASSWORD_MODE_NONE) {
policies.add(res.getString(R.string.policy_require_password));
}
@ -718,6 +734,15 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment
// Must correspond to the hole in the XML file that's reserved.
mSyncWindow.setOrder(2);
mSyncWindow.setOnPreferenceChangeListener(this);
if (mSyncSettings == null) {
mSyncSettings = new Preference(mContext);
mSyncSettings.setKey(PREFERENCE_SYNC_SETTINGS);
dataUsageCategory.addPreference(mSyncSettings);
}
mSyncSettings.setTitle(R.string.folder_sync_settings_pref_title);
mSyncSettings.setOrder(3);
}
final PreferenceCategory folderPrefs =

View File

@ -21,13 +21,13 @@ import android.app.Fragment;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import com.android.email.R;
import com.android.emailcommon.utility.IntentUtilities;
import com.android.mail.providers.Folder;
import com.android.mail.providers.UIProvider.EditSettingsExtras;
import com.android.mail.ui.settings.MailPreferenceActivity;
import com.android.mail.utils.Utils;
@ -110,8 +110,7 @@ public class EmailPreferenceActivity extends MailPreferenceActivity {
// main screen.
// android.accounts.Account acct = i.getParcelableExtra("account");
} else if (i.hasExtra(EditSettingsExtras.EXTRA_FOLDER)) {
launchMailboxSettings(i);
return;
throw new IllegalArgumentException("EXTRA_FOLDER is no longer supported");
} else {
// Otherwise, we're called from within the Email app and look for our extras
final long accountId = IntentUtilities.getAccountIdFromIntent(i);
@ -124,8 +123,11 @@ public class EmailPreferenceActivity extends MailPreferenceActivity {
}
mShowDebugMenu = i.getBooleanExtra(EXTRA_ENABLE_DEBUG, false);
getActionBar().setDisplayOptions(
ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
final ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setDisplayOptions(
ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
}
mFeedbackUri = Utils.getValidUri(getString(R.string.email_feedback_uri));
}
@ -134,7 +136,7 @@ public class EmailPreferenceActivity extends MailPreferenceActivity {
* Listen for secret sequence and, if heard, enable debug menu
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
if (event.getKeyCode() == SECRET_KEY_CODES[mSecretKeyCodeIndex]) {
mSecretKeyCodeIndex++;
if (mSecretKeyCodeIndex == SECRET_KEY_CODES.length) {
@ -193,20 +195,6 @@ public class EmailPreferenceActivity extends MailPreferenceActivity {
return true;
}
private void launchMailboxSettings(Intent intent) {
final Folder folder = intent.getParcelableExtra(EditSettingsExtras.EXTRA_FOLDER);
// TODO: determine from the account if we should navigate to the mailbox settings.
// See bug 6242668
// Get the mailbox id from the folder
final long mailboxId =
Long.parseLong(folder.folderUri.fullUri.getPathSegments().get(1));
MailboxSettings.start(this, mailboxId);
finish();
}
private void enableDebugMenu() {
mShowDebugMenu = true;
invalidateHeaders();
@ -245,7 +233,7 @@ public class EmailPreferenceActivity extends MailPreferenceActivity {
* @param position The header's position in the list.
*/
@Override
public void onHeaderClick(Header header, int position) {
public void onHeaderClick(@NonNull Header header, int position) {
// Secret keys: Click 10x to enable debug settings
if (position == 0) {
mNumGeneralHeaderClicked++;

View File

@ -17,14 +17,15 @@
package com.android.email.activity.setup;
import android.app.ActionBar;
import android.app.Activity;
import android.app.LoaderManager;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
@ -33,6 +34,7 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.MenuItem;
@ -45,12 +47,16 @@ import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.provider.Policy;
import com.android.emailcommon.utility.EmailAsyncTask;
import com.android.emailcommon.utility.Utility;
import com.android.mail.providers.Folder;
import com.android.mail.providers.UIProvider;
import com.android.mail.ui.MailAsyncTaskLoader;
import com.android.mail.utils.LogUtils;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -64,18 +70,19 @@ import java.util.Map;
* #onDestroy()}, unless it's called for configuration changes.
*/
public class MailboxSettings extends PreferenceActivity {
private static final String EXTRA_MAILBOX_ID = "MAILBOX_ID";
private static final String EXTRA_FOLDERS_URI = "FOLDERS_URI";
private static final int FOLDERS_LOADER_ID = 0;
private Uri mFoldersUri;
private final List<Folder> mFolders = new ArrayList<>();
/**
* Starts the activity for a mailbox.
* Starts the activity
*/
public static void start(Activity parent, long mailboxId) {
Intent i = new Intent(parent, MailboxSettings.class);
i.putExtra(EXTRA_SHOW_FRAGMENT, MailboxSettingsFragment.class.getName());
final Bundle b = new Bundle(1);
b.putLong(EXTRA_MAILBOX_ID, mailboxId);
i.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, b);
parent.startActivity(i);
public static Intent getIntent(Context context, Uri foldersUri) {
final Intent i = new Intent(context, MailboxSettings.class);
i.putExtra(EXTRA_FOLDERS_URI, foldersUri);
return i;
}
@Override
@ -86,11 +93,34 @@ public class MailboxSettings extends PreferenceActivity {
if (actionBar != null) {
actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
}
mFoldersUri = getIntent().getParcelableExtra(EXTRA_FOLDERS_URI);
if (mFoldersUri != null) {
getLoaderManager().initLoader(FOLDERS_LOADER_ID, null,
new MailboxSettingsFolderLoaderCallbacks());
}
}
@Override
public boolean onIsMultiPane() {
return false;
public void onBuildHeaders(List<Header> target) {
if (mFolders.isEmpty()) {
final Header dummy = new Header();
dummy.titleRes = R.string.mailbox_name_display_inbox;
target.add(dummy);
} else {
for (final Folder f : mFolders) {
final Header h = new Header();
if (!TextUtils.isEmpty(f.hierarchicalDesc)) {
h.title = f.hierarchicalDesc;
} else {
h.title = f.name;
}
h.fragment = MailboxSettingsFragment.class.getName();
h.fragmentArguments = MailboxSettingsFragment.getArguments(f.id);
target.add(h);
}
}
}
@Override
@ -145,7 +175,42 @@ public class MailboxSettings extends PreferenceActivity {
pref.setSummary(pref.getEntry());
}
private class MailboxSettingsFolderLoaderCallbacks
implements LoaderManager.LoaderCallbacks<Cursor> {
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
return new CursorLoader(MailboxSettings.this, mFoldersUri,
UIProvider.FOLDERS_PROJECTION, null, null, null);
}
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
if (cursor == null) {
return;
}
mFolders.clear();
while(cursor.moveToNext()) {
final Folder folder = new Folder(cursor);
if (!folder.supportsCapability(UIProvider.FolderCapabilities.IS_VIRTUAL) &&
!folder.isTrash() && !folder.isDraft() && !folder.isOutbox()) {
mFolders.add(folder);
}
}
invalidateHeaders();
}
@Override
public void onLoaderReset(Loader<Cursor> cursorLoader) {
mFolders.clear();
}
}
public static class MailboxSettingsFragment extends PreferenceFragment {
private static final String EXTRA_MAILBOX_ID = "MailboxId";
private static final String BUNDLE_MAILBOX = "MailboxSettings.mailbox";
private static final String BUNDLE_MAX_LOOKBACK = "MailboxSettings.maxLookback";
private static final String BUNDLE_SYNC_ENABLED_VALUE = "MailboxSettings.syncEnabled";
@ -161,6 +226,12 @@ public class MailboxSettings extends PreferenceActivity {
private CheckBoxPreference mSyncEnabledPref;
private ListPreference mSyncLookbackPref;
private static Bundle getArguments(long mailboxId) {
final Bundle b = new Bundle(1);
b.putLong(EXTRA_MAILBOX_ID, mailboxId);
return b;
}
public MailboxSettingsFragment() {}
@Override
@ -198,7 +269,7 @@ public class MailboxSettings extends PreferenceActivity {
}
@Override
public void onSaveInstanceState(Bundle outState) {
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(BUNDLE_MAILBOX, mMailbox);
outState.putInt(BUNDLE_MAX_LOOKBACK, mMaxLookback);
@ -240,7 +311,7 @@ public class MailboxSettings extends PreferenceActivity {
@Override
public Map<String, Object> loadInBackground() {
final Map<String, Object> result = new HashMap<String, Object>();
final Map<String, Object> result = new HashMap<>();
final Mailbox mailbox = Mailbox.restoreMailboxWithId(getContext(), mMailboxId);
result.put(RESULT_KEY_MAILBOX, mailbox);