diff --git a/NOTICE b/NOTICE index 88c063d9a9245cea436eaa1ce8a30d0e1f47d0c6..b801c8a2bff298b866f6dc25dd99ef4df717c722 100644 --- a/NOTICE +++ b/NOTICE @@ -559,3 +559,39 @@ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +----------------------------------------------------------------------- +Notice for git commit 5208a9e51ed3bed2e07d0caa504f6d428ed50bb1 - spanning: +- the whole of ContactMultiShareInteraction.java +- showProgressDialog() in ContactMultiDeletionInteraction.java +- setSelectedAll() in MultiSelectContactsListFragment.java +- createDeleteMultipleContactsIntent() in ContactSaveService.java + +Copyright (c) 2019, The Linux Foundation. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS +BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/assets/licenses.html b/assets/licenses.html index c24ed6306db2fee1066cf534ec54a29c39fc4385..5efc5843b90a88b1120ccbf8c21ca6c3137bf3db 100644 --- a/assets/licenses.html +++ b/assets/licenses.html @@ -243,5 +243,42 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +

Notice for Contacts selection enhancements

+
+Notice for git commit 5208a9e51ed3bed2e07d0caa504f6d428ed50bb1 - spanning:
+- git commit 5208a9e51ed3bed2e07d0caa504f6d428ed50bb1
+- the whole of ContactMultiShareInteraction.java
+- showProgressDialog() in ContactMultiDeletionInteraction.java
+- setSelectedAll() in MultiSelectContactsListFragment.java
+- createDeleteMultipleContactsIntent() in ContactSaveService.java
+
+Copyright (c) 2019, The Linux Foundation. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+    * Neither the name of The Linux Foundation nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ diff --git a/res/menu/people_options.xml b/res/menu/people_options.xml index 5fb0f2eb62fcb07618f96b73ff3acaa98f466829..18707e336375f6cef881bfae39a78b11a37af2d0 100644 --- a/res/menu/people_options.xml +++ b/res/menu/people_options.xml @@ -45,4 +45,9 @@ android:title="@string/menu_joinAggregate" contacts:showAsAction="ifRoom"/> + + diff --git a/res/values/ids.xml b/res/values/ids.xml index fb6fc5ad3d91687cedbbb3a611006a316c2b28af..6b36baff248c69d1dab8c705abad77d2d6a5e2ab 100644 --- a/res/values/ids.xml +++ b/res/values/ids.xml @@ -25,6 +25,9 @@ + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index d87be0ba3aa5ae522afcdc4663a8937d967bc49e..a5feaf4cb2df6e8910029ab9b6426b83c740eee1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -232,6 +232,9 @@ Delete + + Deleting contacts + The contact doesn\'t exist. @@ -366,6 +369,9 @@ Share + + Select all + Add to contacts diff --git a/src/com/android/contacts/ContactSaveService.java b/src/com/android/contacts/ContactSaveService.java index 30e4f820dffd99d2d25bbbb280be59da1947be10..8778ced0d6e793ca0036fb693b2c9fa4c2c5debf 100755 --- a/src/com/android/contacts/ContactSaveService.java +++ b/src/com/android/contacts/ContactSaveService.java @@ -170,6 +170,9 @@ public class ContactSaveService extends IntentService { public static final int RESULT_UNKNOWN = 0; public static final int RESULT_SUCCESS = 1; public static final int RESULT_FAILURE = 2; + public static final int CONTACTS_DELETE_STARTED = 0; + public static final int CONTACTS_DELETE_INCREMENT = 1; + public static final int CONTACTS_DELETE_COMPLETE = 2; private static final HashSet ALLOWED_DATA_COLUMNS = Sets.newHashSet( Data.MIMETYPE, @@ -1187,10 +1190,19 @@ public class ContactSaveService extends IntentService { */ public static Intent createDeleteMultipleContactsIntent(Context context, long[] contactIds, final String[] names) { + return createDeleteMultipleContactsIntent(context, contactIds, names, /* receiver = */null); + } + + /** + * Creates an intent that can be sent to this service to delete multiple contacts. + */ + public static Intent createDeleteMultipleContactsIntent(Context context, + long[] contactIds, final String[] names, ResultReceiver receiver) { Intent serviceIntent = new Intent(context, ContactSaveService.class); serviceIntent.setAction(ContactSaveService.ACTION_DELETE_MULTIPLE_CONTACTS); serviceIntent.putExtra(ContactSaveService.EXTRA_CONTACT_IDS, contactIds); serviceIntent.putExtra(ContactSaveService.EXTRA_DISPLAY_NAME_ARRAY, names); + serviceIntent.putExtra(ContactSaveService.EXTRA_RESULT_RECEIVER, receiver); return serviceIntent; } @@ -1210,9 +1222,13 @@ public class ContactSaveService extends IntentService { Log.e(TAG, "Invalid arguments for deleteMultipleContacts request"); return; } + final ResultReceiver receiver = intent.getParcelableExtra( + ContactSaveService.EXTRA_RESULT_RECEIVER); + notifyActionProgress(CONTACTS_DELETE_STARTED, receiver); for (long contactId : contactIds) { final Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); getContentResolver().delete(contactUri, null, null); + notifyActionProgress(CONTACTS_DELETE_INCREMENT, receiver); } final String[] names = intent.getStringArrayExtra( ContactSaveService.EXTRA_DISPLAY_NAME_ARRAY); @@ -1235,6 +1251,7 @@ public class ContactSaveService extends IntentService { R.string.contacts_deleted_many_named_toast, (Object[]) names); } + notifyActionProgress(CONTACTS_DELETE_COMPLETE, receiver); mMainHandler.post(new Runnable() { @Override public void run() { @@ -1244,6 +1261,12 @@ public class ContactSaveService extends IntentService { }); } + private void notifyActionProgress(int state, ResultReceiver receiver) { + if (receiver != null) { + receiver.send(state, new Bundle()); + } + } + /** * Creates an intent that can be sent to this service to split a contact into it's constituent * pieces. This will set the raw contact ids to {@link AggregationExceptions#TYPE_AUTOMATIC} so diff --git a/src/com/android/contacts/interactions/ContactMultiDeletionInteraction.java b/src/com/android/contacts/interactions/ContactMultiDeletionInteraction.java index 47b76a5399fe6739ad6f5447bf9327a51e5d202f..c76b93b6923c34b1a67f392513e9a2954076d220 100644 --- a/src/com/android/contacts/interactions/ContactMultiDeletionInteraction.java +++ b/src/com/android/contacts/interactions/ContactMultiDeletionInteraction.java @@ -21,6 +21,7 @@ import android.app.AlertDialog; import android.app.Fragment; import android.app.FragmentManager; import android.app.LoaderManager.LoaderCallbacks; +import android.app.ProgressDialog; import android.content.Context; import android.content.CursorLoader; import android.content.DialogInterface; @@ -28,7 +29,9 @@ import android.content.DialogInterface.OnDismissListener; import android.content.Loader; import android.database.Cursor; import android.os.Bundle; +import android.os.Handler; import android.provider.ContactsContract.RawContacts; +import android.support.v4.os.ResultReceiver; import android.text.TextUtils; import android.util.Log; @@ -82,6 +85,7 @@ public class ContactMultiDeletionInteraction extends Fragment private TreeSet mContactIds; private Context mContext; private AlertDialog mDialog; + private ProgressDialog mProgressDialog; private MultiContactDeleteListener mListener; /** @@ -165,19 +169,17 @@ public class ContactMultiDeletionInteraction extends Fragment public Loader onCreateLoader(int id, Bundle args) { final TreeSet contactIds = (TreeSet) args.getSerializable(ARG_CONTACT_IDS); final Object[] parameterObject = contactIds.toArray(); - final String[] parameters = new String[contactIds.size()]; - final StringBuilder builder = new StringBuilder(); + final StringBuilder builder = new StringBuilder(RawContacts.CONTACT_ID + " in ("); for (int i = 0; i < contactIds.size(); i++) { - parameters[i] = String.valueOf(parameterObject[i]); - builder.append(RawContacts.CONTACT_ID + " =?"); - if (i == contactIds.size() -1) { - break; + if (i > 0) { + builder.append(","); } - builder.append(" OR "); + builder.append(String.valueOf(parameterObject[i])); } + builder.append(")"); return new CursorLoader(mContext, RawContacts.CONTENT_URI, RAW_CONTACT_PROJECTION, - builder.toString(), parameters, null); + builder.toString(), null, null); } @Override @@ -310,9 +312,40 @@ public class ContactMultiDeletionInteraction extends Fragment } } + private void showProgressDialog() { + CharSequence title = getString(R.string.delete_contacts_title); + + mProgressDialog = new ProgressDialog(mContext); + mProgressDialog.setTitle(title); + mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + mProgressDialog.setProgress(0); + mProgressDialog.setMax(mContactIds.size()); + mProgressDialog.setCancelable(false); + mProgressDialog.show(); + } + protected void doDeleteContact(long[] contactIds, final String[] names) { + ResultReceiver receiver = new ResultReceiver(new Handler()) { + @Override + protected void onReceiveResult(int resultCode, Bundle resultData) { + super.onReceiveResult(resultCode, resultData); + switch (resultCode){ + case ContactSaveService.CONTACTS_DELETE_STARTED: + showProgressDialog(); + break; + case ContactSaveService.CONTACTS_DELETE_INCREMENT: + mProgressDialog.incrementProgressBy(1); + break; + case ContactSaveService.CONTACTS_DELETE_COMPLETE: + mProgressDialog.dismiss(); + mProgressDialog = null; + break; + } + } + }; + mContext.startService(ContactSaveService.createDeleteMultipleContactsIntent(mContext, - contactIds, names)); + contactIds, names, receiver)); mListener.onDeletionFinished(); } diff --git a/src/com/android/contacts/interactions/ContactMultiShareInteraction.java b/src/com/android/contacts/interactions/ContactMultiShareInteraction.java new file mode 100644 index 0000000000000000000000000000000000000000..599254c8a6ab15f587429778545a21cb50844d30 --- /dev/null +++ b/src/com/android/contacts/interactions/ContactMultiShareInteraction.java @@ -0,0 +1,304 @@ +/* + * Copyright (c) 2019, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Copyright (C) 2015 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.contacts.interactions; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Fragment; +import android.app.FragmentManager; +import android.app.LoaderManager.LoaderCallbacks; +import android.app.ProgressDialog; +import android.content.ActivityNotFoundException; +import android.content.AsyncTaskLoader; +import android.content.Context; +import android.content.ContentUris; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.DialogInterface.OnDismissListener; +import android.content.Intent; +import android.content.Loader; +import android.net.Uri; +import android.os.Bundle; +import android.provider.ContactsContract; +import android.text.TextUtils; +import android.util.Log; +import android.widget.Toast; + +import com.android.contacts.ContactSaveService; +import com.android.contacts.R; + +import java.util.List; +import java.util.TreeSet; +/** + * An interaction invoked to share multiple contacts. + */ +public class ContactMultiShareInteraction extends Fragment + implements LoaderCallbacks { + + public static final int ACTIVITY_REQUEST_CODE_SHARE = 0; + + private static final String FRAGMENT_TAG = "shareMultipleContacts"; + private static final String TAG = "ContactMultiShare"; + private static final String KEY_ACTIVE = "active"; + private static final String KEY_CONTACTS_IDS = "contactIds"; + private static final String ARG_CONTACT_IDS = "contactIds"; + + private boolean mIsLoaderActive; + private TreeSet mContactIds; + private Context mContext; + private static ProgressDialog mProgressDialog; + + /** + * Starts the interaction. + * + * @param hostFragment the fragment within which to start the interaction + * @param contactIds the IDs of contacts to be shared + * @return the newly created interaction + */ + public static ContactMultiShareInteraction start( + Fragment hostFragment, TreeSet contactIds) { + if (contactIds == null) { + return null; + } + + final FragmentManager fragmentManager = hostFragment.getFragmentManager(); + ContactMultiShareInteraction fragment = + (ContactMultiShareInteraction) fragmentManager.findFragmentByTag(FRAGMENT_TAG); + if (fragment == null) { + fragment = new ContactMultiShareInteraction(); + fragment.setContactIds(contactIds); + fragmentManager.beginTransaction().add(fragment, FRAGMENT_TAG) + .commitAllowingStateLoss(); + } else { + fragment.setContactIds(contactIds); + } + return fragment; + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + mContext = activity; + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + if (mProgressDialog != null && mProgressDialog.isShowing()) { + mProgressDialog.setOnDismissListener(null); + mProgressDialog.dismiss(); + mProgressDialog = null; + } + } + + public void setContactIds(TreeSet contactIds) { + mContactIds = contactIds; + mIsLoaderActive = true; + if (isStarted()) { + Bundle args = new Bundle(); + args.putSerializable(ARG_CONTACT_IDS, mContactIds); + getLoaderManager().restartLoader(R.id.dialog_share_multiple_contact_loader_id, + args, this); + showDialog(); + } + } + + private boolean isStarted() { + return isAdded(); + } + + @Override + public void onStart() { + if (mIsLoaderActive) { + Bundle args = new Bundle(); + args.putSerializable(ARG_CONTACT_IDS, mContactIds); + getLoaderManager().initLoader( + R.id.dialog_share_multiple_contact_loader_id, args, this); + showDialog(); + } + super.onStart(); + } + + @Override + public void onStop() { + super.onStop(); + if (mProgressDialog != null) { + mProgressDialog.dismiss(); + } + } + + @Override + public Loader onCreateLoader(int id, Bundle args) { + final TreeSet contactIds = (TreeSet) args.getSerializable(ARG_CONTACT_IDS); + return new ShareContactsLoader(mContext, contactIds); + } + + @Override + public void onLoadFinished(Loader loader, String uriList) { + if (mProgressDialog != null){ + mProgressDialog.dismiss(); + mProgressDialog = null; + } + + if (!mIsLoaderActive) { + return; + } + + if (TextUtils.isEmpty(uriList)) { + Log.e(TAG, "Failed to load contacts"); + return; + } + + final Uri uri = Uri.withAppendedPath( + ContactsContract.Contacts.CONTENT_MULTI_VCARD_URI, + Uri.encode(uriList)); + final Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType(ContactsContract.Contacts.CONTENT_VCARD_TYPE); + intent.putExtra(Intent.EXTRA_STREAM, uri); + try { + startActivityForResult(Intent.createChooser(intent, mContext.getResources().getQuantityString( + R.plurals.title_share_via,/* quantity */ mContactIds.size())) + , ACTIVITY_REQUEST_CODE_SHARE); + } catch (final ActivityNotFoundException ex) { + Toast.makeText(getContext(), R.string.share_error, Toast.LENGTH_SHORT).show(); + } + + // We don't want onLoadFinished() calls any more, which may come when the database is + // updating. + getLoaderManager().destroyLoader(R.id.dialog_share_multiple_contact_loader_id); + } + + @Override + public void onLoaderReset(Loader loader) { + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(KEY_ACTIVE, mIsLoaderActive); + outState.putSerializable(KEY_CONTACTS_IDS, mContactIds); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + if (savedInstanceState != null) { + mIsLoaderActive = savedInstanceState.getBoolean(KEY_ACTIVE); + mContactIds = (TreeSet) savedInstanceState.getSerializable(KEY_CONTACTS_IDS); + } + } + + private void cancelLoad() { + Loader loader = getLoaderManager().getLoader(R.id.dialog_share_multiple_contact_loader_id); + if (loader != null) { + loader.cancelLoad(); + } + } + + private void showDialog() { + CharSequence title = getString(R.string.exporting_contact_list_title); + + mProgressDialog = new ProgressDialog(mContext); + mProgressDialog.setTitle(title); + mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + mProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, + getString(android.R.string.cancel), (OnClickListener)null); + mProgressDialog.setProgress(0); + mProgressDialog.setMax(mContactIds.size()); + mProgressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + cancelLoad(); + mIsLoaderActive = false; + mProgressDialog = null; + } + }); + + mProgressDialog.show(); + } + + private static class ShareContactsLoader extends AsyncTaskLoader{ + private TreeSet mSelectedContactIds; + + public ShareContactsLoader(Context context, TreeSet contactIds) { + super(context); + mSelectedContactIds = contactIds; + } + + @Override + protected void onStartLoading() { + forceLoad(); + } + + @Override + public String loadInBackground() { + final StringBuilder uriListBuilder = new StringBuilder(); + for (Long contactId : mSelectedContactIds) { + if (!isLoadInBackgroundCanceled()) { + final Uri contactUri = ContentUris.withAppendedId( + ContactsContract.Contacts.CONTENT_URI, contactId); + final Uri lookupUri = ContactsContract.Contacts.getLookupUri( + getContext().getContentResolver(), contactUri); + if (lookupUri == null) { + continue; + } + final List pathSegments = lookupUri.getPathSegments(); + if (pathSegments.size() < 2) { + continue; + } + final String lookupKey = pathSegments.get(pathSegments.size() - 2); + if (uriListBuilder.length() > 0) { + uriListBuilder.append(':'); + } + uriListBuilder.append(Uri.encode(lookupKey)); + if (mProgressDialog != null) { + mProgressDialog.incrementProgressBy(1); + } + } + + } + return uriListBuilder.toString(); + } + } +} diff --git a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java index fd6fc8cb89497b47ca138a1f1ee8f7ff248a4a55..265f5d6066d0575ec2013e46867d6d9084bfb955 100644 --- a/src/com/android/contacts/list/DefaultContactBrowseListFragment.java +++ b/src/com/android/contacts/list/DefaultContactBrowseListFragment.java @@ -66,6 +66,7 @@ import com.android.contacts.compat.CompatUtils; import com.android.contacts.interactions.ContactDeletionInteraction; import com.android.contacts.interactions.ContactMultiDeletionInteraction; import com.android.contacts.interactions.ContactMultiDeletionInteraction.MultiContactDeleteListener; +import com.android.contacts.interactions.ContactMultiShareInteraction; import com.android.contacts.logging.ListEvent; import com.android.contacts.logging.Logger; import com.android.contacts.logging.ScreenEvent; @@ -1014,8 +1015,10 @@ public class DefaultContactBrowseListFragment extends ContactBrowseListFragment && getSelectedContactIds().size() != 0; makeMenuItemVisible(menu, R.id.menu_share, showSelectedContactOptions); makeMenuItemVisible(menu, R.id.menu_delete, showSelectedContactOptions); + makeMenuItemVisible(menu, R.id.menu_select_all, !isSearchOrSelectionMode); final boolean showLinkContactsOptions = mActionBarAdapter.isSelectionMode() - && getSelectedContactIds().size() > 1; + && getSelectedContactIds().size() > 1 + && getSelectedContactIds().size() <= 9; makeMenuItemVisible(menu, R.id.menu_join, showLinkContactsOptions); // Debug options need to be visible even in search mode. @@ -1084,6 +1087,10 @@ public class DefaultContactBrowseListFragment extends ContactBrowseListFragment intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); ImplicitIntentsUtil.startActivityOutsideApp(getContext(), intent); return true; + } else if (id == R.id.menu_select_all) { + mActionBarAdapter.setSelectionMode(true); + mActivity.invalidateOptionsMenu(); + setSelectedAll(); } return super.onOptionsItemSelected(item); } @@ -1093,45 +1100,9 @@ public class DefaultContactBrowseListFragment extends ContactBrowseListFragment * handling large numbers of contacts. I don't expect this to be a problem. */ private void shareSelectedContacts() { - final StringBuilder uriListBuilder = new StringBuilder(); - for (Long contactId : getSelectedContactIds()) { - final Uri contactUri = ContentUris.withAppendedId( - ContactsContract.Contacts.CONTENT_URI, contactId); - final Uri lookupUri = ContactsContract.Contacts.getLookupUri( - getContext().getContentResolver(), contactUri); - if (lookupUri == null) { - continue; - } - final List pathSegments = lookupUri.getPathSegments(); - if (pathSegments.size() < 2) { - continue; - } - final String lookupKey = pathSegments.get(pathSegments.size() - 2); - if (uriListBuilder.length() > 0) { - uriListBuilder.append(':'); - } - uriListBuilder.append(Uri.encode(lookupKey)); - } - if (uriListBuilder.length() == 0) { - return; - } - final Uri uri = Uri.withAppendedPath( - ContactsContract.Contacts.CONTENT_MULTI_VCARD_URI, - Uri.encode(uriListBuilder.toString())); - final Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType(ContactsContract.Contacts.CONTENT_VCARD_TYPE); - intent.putExtra(Intent.EXTRA_STREAM, uri); - try { - MessageFormat msgFormat = new MessageFormat( - getResources().getString(R.string.title_share_via), - Locale.getDefault()); - Map arguments = new HashMap<>(); - arguments.put("count", getSelectedContactIds().size()); - startActivityForResult(Intent.createChooser(intent, msgFormat.format(arguments)) - , ACTIVITY_REQUEST_CODE_SHARE); - } catch (final ActivityNotFoundException ex) { - Toast.makeText(getContext(), R.string.share_error, Toast.LENGTH_SHORT).show(); - } + final ContactMultiShareInteraction multiShareInteraction = + ContactMultiShareInteraction.start(this, getSelectedContactIds()); + mActionBarAdapter.setSelectionMode(false); } private void joinSelectedContacts() { @@ -1181,7 +1152,7 @@ public class DefaultContactBrowseListFragment extends ContactBrowseListFragment if (resultCode == Activity.RESULT_OK) { onPickerResult(data); } - case ACTIVITY_REQUEST_CODE_SHARE: + case ContactMultiShareInteraction.ACTIVITY_REQUEST_CODE_SHARE: Logger.logListEvent(ListEvent.ActionType.SHARE, /* listType */ getListTypeIncludingSearch(), /* count */ getAdapter().getCount(), /* clickedIndex */ -1, diff --git a/src/com/android/contacts/list/MultiSelectContactsListFragment.java b/src/com/android/contacts/list/MultiSelectContactsListFragment.java index 83b1ec910bc61c3916c460448e254be638173ece..d7935c935bbcca1de7c8562cf35a82835e790f59 100644 --- a/src/com/android/contacts/list/MultiSelectContactsListFragment.java +++ b/src/com/android/contacts/list/MultiSelectContactsListFragment.java @@ -193,6 +193,23 @@ public abstract class MultiSelectContactsListFragment allContactIds = new TreeSet(); + for (int i = 0; i < getAdapter().getCount(); i++) { + final long contactId = getContactId(i); + if (contactId < 0) { + return; + } + allContactIds.add(contactId); + } + if (getAdapter().isDisplayingCheckBoxes()) { + getAdapter().setSelectedContactIds(allContactIds); + } + } + private long getContactId(int position) { final int contactIdColumnIndex = getAdapter().getContactColumnIdIndex();