From 5208a9e51ed3bed2e07d0caa504f6d428ed50bb1 Mon Sep 17 00:00:00 2001 From: Yingren Wang Date: Sun, 7 Jul 2024 15:44:25 +0200 Subject: [PATCH 1/2] Contacts selection enhancements 1. Add "Select all" menu to allow user select all contacts. 2. Support to share multiple contacts asynchronously because share large contacts in main thread will leads to ANR. 3. Fix force close when more than 1000 selected contacts need to be deleted. Also add dialog to tell user contacts deletion progress. 4. Set max size as 9 when link multiple contacts. Submitted on behalf of a third-party: Linux Foundation License rights, if any, to the submission are granted solely by the copyright owner of such submission under its applicable intellectual property. 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. Bug: https://issuetracker.google.com/issue?id=111044725&query=111044725 Change-Id: https://android-review.googlesource.com/q/Iac1d1e2802124cb4cb3b266b8529264633847cbd --- res/menu/people_options.xml | 5 + res/values/ids.xml | 3 + res/values/strings.xml | 6 + .../android/contacts/ContactSaveService.java | 23 ++ .../ContactMultiDeletionInteraction.java | 51 ++- .../ContactMultiShareInteraction.java | 304 ++++++++++++++++++ .../DefaultContactBrowseListFragment.java | 53 +-- .../list/MultiSelectContactsListFragment.java | 17 + 8 files changed, 412 insertions(+), 50 deletions(-) create mode 100644 src/com/android/contacts/interactions/ContactMultiShareInteraction.java diff --git a/res/menu/people_options.xml b/res/menu/people_options.xml index 5fb0f2eb62..18707e3363 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 fb6fc5ad3d..6b36baff24 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 d87be0ba3a..a5feaf4cb2 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 30e4f820df..8778ced0d6 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 47b76a5399..c76b93b692 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 0000000000..599254c8a6 --- /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 fd6fc8cb89..265f5d6066 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 83b1ec910b..d7935c935b 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(); -- GitLab From 94a8a11470b4df4e4c913665925124de4d747586 Mon Sep 17 00:00:00 2001 From: tcecyk Date: Sun, 7 Jul 2024 15:58:23 +0200 Subject: [PATCH 2/2] add copyright notice and bsd license for ContactMultiShareInteraction.java --- NOTICE | 36 ++++++++++++++++++++++++++++++++++++ assets/licenses.html | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/NOTICE b/NOTICE index 88c063d9a9..b801c8a2bf 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 c24ed6306d..5efc5843b9 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.
+
+ -- GitLab