Merge "Add "System Folders" settings" into jb-ub-mail

This commit is contained in:
Marc Blank 2012-09-10 11:52:10 -07:00 committed by Android (Google) Code Review
commit d8b2b8aebd
7 changed files with 137 additions and 10 deletions

View File

@ -988,6 +988,14 @@ as <xliff:g id="filename">%s</xliff:g>.</string>
<!-- On Settings screen, section heading -->
<string name="account_settings_policies">Security policies</string>
<string name="system_folders_title">System folders</string>
<string name="system_folders_trash_title">Trash folder</string>
<string name="system_folders_trash_summary">Select your server\'s trash folder</string>
<string name="system_folders_trash_dlg">Select your server\'s trash folder</string>
<string name="system_folders_sent_title">Sent items folder</string>
<string name="system_folders_sent_summary">Select your server\'s sent items folder</string>
<string name="system_folders_sent_dlg">Select your server\'s sent items folder</string>
<!-- On settings screen, dialog heading informing user to edit a quick response -->
<string name="edit_quick_response_dialog">Edit quick response</string>
<!-- On settings screen, edit quick response dialog's "save" button -->

View File

@ -120,6 +120,28 @@
</PreferenceCategory>
<PreferenceCategory
android:key="system_folders"
android:title="@string/system_folders_title">
<Preference
android:key="system_folders_trash"
android:layout="?android:attr/preferenceLayoutChild"
android:title="@string/system_folders_trash_title"
android:summary="@string/system_folders_trash_summary"
android:dialogTitle="@string/system_folders_trash_dlg"
/>
<Preference
android:key="system_folders_sent"
android:layout="?android:attr/preferenceLayoutChild"
android:title="@string/system_folders_sent_title"
android:summary="@string/system_folders_sent_summary"
android:dialogTitle="@string/system_folders_sent_dlg"
/>
</PreferenceCategory>
<PreferenceCategory
android:key="account_servers"
android:title="@string/account_settings_servers">

View File

@ -18,10 +18,14 @@ package com.android.email.activity.setup;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Vibrator;
@ -38,15 +42,19 @@ import android.util.Log;
import com.android.email.R;
import com.android.email.SecurityPolicy;
import com.android.email.provider.FolderPickerActivity;
import com.android.email.service.EmailServiceUtils;
import com.android.email.service.EmailServiceUtils.EmailServiceInfo;
import com.android.email2.ui.MailActivityEmail;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.MailboxColumns;
import com.android.emailcommon.provider.HostAuth;
import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.provider.Policy;
import com.android.emailcommon.utility.Utility;
import com.android.mail.providers.UIProvider;
import java.util.ArrayList;
@ -89,6 +97,10 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
private static final String PREFERENCE_SYNC_CALENDAR = "account_sync_calendar";
private static final String PREFERENCE_SYNC_EMAIL = "account_sync_email";
private static final String PREFERENCE_SYSTEM_FOLDERS = "system_folders";
private static final String PREFERENCE_SYSTEM_FOLDERS_TRASH = "system_folders_trash";
private static final String PREFERENCE_SYSTEM_FOLDERS_SENT = "system_folders_sent";
// These strings must match account_settings_vibrate_when_* strings in strings.xml
private static final String PREFERENCE_VALUE_VIBRATE_WHEN_ALWAYS = "always";
private static final String PREFERENCE_VALUE_VIBRATE_WHEN_SILENT = "silent";
@ -528,6 +540,28 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
dataUsageCategory.addPreference(mSyncWindow);
}
PreferenceCategory folderPrefs =
(PreferenceCategory) findPreference(PREFERENCE_SYSTEM_FOLDERS);
if (info.requiresSetup) {
Preference trashPreference =
(Preference) findPreference(PREFERENCE_SYSTEM_FOLDERS_TRASH);
Intent i = new Intent(mContext, FolderPickerActivity.class);
Uri uri = EmailContent.CONTENT_URI.buildUpon().appendQueryParameter(
"account", Long.toString(mAccount.mId)).build();
i.setData(uri);
i.putExtra(FolderPickerActivity.MAILBOX_TYPE_EXTRA, Mailbox.TYPE_TRASH);
trashPreference.setIntent(i);
Preference sentPreference =
(Preference) findPreference(PREFERENCE_SYSTEM_FOLDERS_SENT);
i = new Intent(mContext, FolderPickerActivity.class);
i.setData(uri);
i.putExtra(FolderPickerActivity.MAILBOX_TYPE_EXTRA, Mailbox.TYPE_SENT);
sentPreference.setIntent(i);
} else {
getPreferenceScreen().removePreference(folderPrefs);
}
mAccountBackgroundAttachments = (CheckBoxPreference)
findPreference(PREFERENCE_BACKGROUND_ATTACHMENTS);
if (!info.offerAttachmentPreload) {

View File

@ -39,10 +39,13 @@ import com.android.mail.providers.Folder;
public class FolderPickerActivity extends Activity implements FolderPickerCallback {
private static final String TAG = "FolderPickerActivity";
public static final String MAILBOX_TYPE_EXTRA = "mailbox_type";
private long mAccountId;
private int mMailboxType;
private AccountObserver mAccountObserver;
private String mAccountName;
private boolean mInSetup = true;
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
@ -66,10 +69,12 @@ public class FolderPickerActivity extends Activity implements FolderPickerCallba
finish();
return;
}
mMailboxType = Mailbox.TYPE_TRASH;
// We act a bit differently if we're coming to set up the trash after account creation
mInSetup = !i.hasExtra(MAILBOX_TYPE_EXTRA);
mMailboxType = i.getIntExtra(MAILBOX_TYPE_EXTRA, Mailbox.TYPE_TRASH);
long trashMailboxId = Mailbox.findMailboxOfType(this, mAccountId, Mailbox.TYPE_TRASH);
// If we already have a trash mailbox, we're done (race?)
if (trashMailboxId != Mailbox.NO_MAILBOX) {
// If we already have a trash mailbox, we're done (if in setup; a race?)
if (trashMailboxId != Mailbox.NO_MAILBOX && mInSetup) {
Log.w(TAG, "Trash folder already exists");
finish();
return;
@ -165,7 +170,8 @@ public class FolderPickerActivity extends Activity implements FolderPickerCallba
private void startPicker(Uri uri, int headerId) {
String header = getString(headerId, mAccountName);
FolderSelectionDialog dialog = new FolderSelectionDialog(this, uri, this, header);
FolderPickerDialog dialog =
new FolderPickerDialog(this, uri, this, header, !mInSetup);
dialog.show();
}
@ -201,4 +207,8 @@ public class FolderPickerActivity extends Activity implements FolderPickerCallba
}
finish();
}
public void cancel() {
finish();
}
}

View File

@ -21,4 +21,5 @@ import com.android.mail.providers.Folder;
public interface FolderPickerCallback {
public void select(Folder folder);
public void cancel();
}

View File

@ -34,28 +34,29 @@ import com.android.mail.providers.Folder;
import com.android.mail.providers.UIProvider;
import com.android.mail.ui.FolderSelectorAdapter;
import com.android.mail.ui.FolderSelectorAdapter.FolderRow;
import com.android.mail.ui.HierarchicalFolderSelectorAdapter;
import com.android.mail.ui.SeparatedFolderListAdapter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
public class FolderSelectionDialog implements OnClickListener, OnMultiChoiceClickListener {
public class FolderPickerDialog implements OnClickListener, OnMultiChoiceClickListener,
OnCancelListener {
private final AlertDialog mDialog;
private final HashMap<Folder, Boolean> mCheckedState;
private final SeparatedFolderListAdapter mAdapter;
private final FolderPickerCallback mCallback;
public FolderSelectionDialog(final Context context, Uri uri,
FolderPickerCallback callback, String header) {
public FolderPickerDialog(final Context context, Uri uri,
FolderPickerCallback callback, String header, boolean cancelable) {
mCallback = callback;
// Mapping of a folder's uri to its checked state
mCheckedState = new HashMap<Folder, Boolean>();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(header);
builder.setPositiveButton(R.string.ok, this);
builder.setCancelable(false);
builder.setCancelable(cancelable);
builder.setOnCancelListener(this);
// TODO: Do this on a background thread
final Cursor foldersCursor = context.getContentResolver().query(
uri, UIProvider.FOLDERS_PROJECTION, null, null, null);
@ -63,7 +64,7 @@ public class FolderSelectionDialog implements OnClickListener, OnMultiChoiceClic
mAdapter = new SeparatedFolderListAdapter(context);
String[] headers = context.getResources()
.getStringArray(R.array.moveto_folder_sections);
mAdapter.addSection(new HierarchicalFolderSelectorAdapter(context,
mAdapter.addSection(new FolderPickerSelectorAdapter(context,
foldersCursor, new HashSet<String>(), true, headers[2]));
builder.setAdapter(mAdapter, this);
} finally {
@ -151,4 +152,9 @@ public class FolderSelectionDialog implements OnClickListener, OnMultiChoiceClic
mCheckedState.put(row.getFolder(), isChecked);
mDialog.getListView().setItemChecked(which, false);
}
@Override
public void onCancel(DialogInterface dialog) {
mCallback.cancel();
}
}

View File

@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (C) 2012 Google Inc.
* Licensed to 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.provider;
import android.content.Context;
import android.database.Cursor;
import com.android.mail.providers.Folder;
import com.android.mail.providers.UIProvider.FolderCapabilities;
import com.android.mail.providers.UIProvider.FolderType;
import com.android.mail.ui.HierarchicalFolderSelectorAdapter;
import java.util.Set;
public class FolderPickerSelectorAdapter extends HierarchicalFolderSelectorAdapter {
public FolderPickerSelectorAdapter(Context context, Cursor folders,
Set<String> initiallySelected, boolean single, String header) {
super(context, folders, initiallySelected, single, header);
}
/**
* Return whether the supplied folder meets the requirements to be displayed
* in the folder list.
*/
protected boolean meetsRequirements(Folder folder) {
// We only want to show the non-Trash folders that can accept moved messages
return folder.supportsCapability(FolderCapabilities.CAN_ACCEPT_MOVED_MESSAGES) ||
folder.type == FolderType.TRASH;
}
}