Sean Midford | ff6f1bb | 2016-10-12 09:48:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.contacts.list; |
| 17 | |
Sean Midford | b460f44 | 2016-10-13 10:42:35 -0700 | [diff] [blame] | 18 | import android.content.Intent; |
Sean Midford | 4b2ccd2 | 2016-10-14 13:03:49 -0700 | [diff] [blame] | 19 | import android.os.Bundle; |
Sean Midford | 9970f30 | 2016-11-07 12:23:45 -0800 | [diff] [blame^] | 20 | import android.text.TextUtils; |
Sean Midford | ff6f1bb | 2016-10-12 09:48:23 -0700 | [diff] [blame] | 21 | import android.view.LayoutInflater; |
Sean Midford | b460f44 | 2016-10-13 10:42:35 -0700 | [diff] [blame] | 22 | import android.view.Menu; |
| 23 | import android.view.MenuInflater; |
| 24 | import android.view.MenuItem; |
Sean Midford | ff6f1bb | 2016-10-12 09:48:23 -0700 | [diff] [blame] | 25 | import android.view.View; |
| 26 | import android.view.ViewGroup; |
| 27 | |
Sean Midford | b460f44 | 2016-10-13 10:42:35 -0700 | [diff] [blame] | 28 | import com.android.contacts.R; |
Sean Midford | ff6f1bb | 2016-10-12 09:48:23 -0700 | [diff] [blame] | 29 | import com.android.contacts.common.logging.ListEvent; |
Sean Midford | 9970f30 | 2016-11-07 12:23:45 -0800 | [diff] [blame^] | 30 | import com.android.contacts.group.GroupUtil; |
Sean Midford | ff6f1bb | 2016-10-12 09:48:23 -0700 | [diff] [blame] | 31 | |
Sean Midford | 9970f30 | 2016-11-07 12:23:45 -0800 | [diff] [blame^] | 32 | import java.util.List; |
Sean Midford | 4b2ccd2 | 2016-10-14 13:03:49 -0700 | [diff] [blame] | 33 | import java.util.TreeSet; |
| 34 | |
Sean Midford | ff6f1bb | 2016-10-12 09:48:23 -0700 | [diff] [blame] | 35 | /** Displays a list of emails with check boxes. */ |
| 36 | public class MultiSelectEmailAddressesListFragment |
| 37 | extends MultiSelectContactsListFragment<MultiSelectEmailAddressesListAdapter>{ |
| 38 | |
| 39 | public MultiSelectEmailAddressesListFragment() { |
| 40 | setPhotoLoaderEnabled(true); |
| 41 | setSectionHeaderDisplayEnabled(true); |
| 42 | setSearchMode(false); |
Sean Midford | b460f44 | 2016-10-13 10:42:35 -0700 | [diff] [blame] | 43 | setHasOptionsMenu(true); |
Sean Midford | ff6f1bb | 2016-10-12 09:48:23 -0700 | [diff] [blame] | 44 | setListType(ListEvent.ListType.PICK_EMAIL); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public MultiSelectEmailAddressesListAdapter createListAdapter() { |
| 49 | final MultiSelectEmailAddressesListAdapter adapter = |
| 50 | new MultiSelectEmailAddressesListAdapter(getActivity()); |
| 51 | adapter.setArguments(getArguments()); |
| 52 | return adapter; |
| 53 | } |
| 54 | |
| 55 | @Override |
Sean Midford | b460f44 | 2016-10-13 10:42:35 -0700 | [diff] [blame] | 56 | public void onSelectedContactsChangedViaCheckBox() { |
| 57 | onSelectedContactsChanged(); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public void onCreateOptionsMenu(Menu menu, final MenuInflater inflater) { |
| 62 | super.onCreateOptionsMenu(menu, inflater); |
| 63 | inflater.inflate(R.menu.items_multi_select, menu); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public void onPrepareOptionsMenu(Menu menu) { |
| 68 | final MenuItem item = menu.findItem(R.id.menu_send); |
| 69 | item.setVisible(getAdapter().hasSelectedItems()); |
| 70 | item.getActionView().setOnClickListener(new View.OnClickListener() { |
| 71 | @Override |
| 72 | public void onClick(View v) { |
| 73 | onOptionsItemSelected(item); |
| 74 | } |
| 75 | }); |
| 76 | } |
| 77 | |
| 78 | @Override |
Sean Midford | 9970f30 | 2016-11-07 12:23:45 -0800 | [diff] [blame^] | 79 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 80 | getActivity().finish(); |
| 81 | } |
| 82 | |
| 83 | @Override |
Sean Midford | b460f44 | 2016-10-13 10:42:35 -0700 | [diff] [blame] | 84 | public boolean onOptionsItemSelected(MenuItem item) { |
| 85 | switch(item.getItemId()) { |
| 86 | case R.id.menu_send: { |
| 87 | final String scheme = getActivity().getIntent().getStringExtra( |
| 88 | UiIntentActions.SELECTION_SEND_SCHEME); |
| 89 | final String title= getActivity().getIntent().getStringExtra( |
| 90 | UiIntentActions.SELECTION_SEND_TITLE); |
Sean Midford | 9970f30 | 2016-11-07 12:23:45 -0800 | [diff] [blame^] | 91 | final List<String> items = GroupUtil.getSendToDataForIds( |
| 92 | getActivity(), getAdapter().getSelectedContactIdsArray(), scheme); |
| 93 | final String list = TextUtils.join(",", items); |
| 94 | GroupUtil.startSendToSelectionActivity(this, list, scheme, title); |
Sean Midford | b460f44 | 2016-10-13 10:42:35 -0700 | [diff] [blame] | 95 | return true; |
| 96 | } |
| 97 | } |
| 98 | return super.onOptionsItemSelected(item); |
| 99 | } |
| 100 | |
| 101 | @Override |
Sean Midford | 4b2ccd2 | 2016-10-14 13:03:49 -0700 | [diff] [blame] | 102 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 103 | Bundle savedInstanceState) { |
| 104 | final long[] selectedIds = getActivity().getIntent().getLongArrayExtra( |
| 105 | UiIntentActions.SELECTION_DEFAULT_SELECTION); |
| 106 | if (selectedIds != null && selectedIds.length != 0) { |
| 107 | final TreeSet<Long> selectedIdsTree = new TreeSet<>(); |
| 108 | for (int i = 0; i < selectedIds.length; i++) { |
| 109 | selectedIdsTree.add(selectedIds[i]); |
| 110 | } |
| 111 | getAdapter().setSelectedContactIds(selectedIdsTree); |
| 112 | onSelectedContactsChanged(); |
| 113 | } |
| 114 | return super.onCreateView(inflater, container, savedInstanceState); |
| 115 | } |
| 116 | |
| 117 | @Override |
Sean Midford | ff6f1bb | 2016-10-12 09:48:23 -0700 | [diff] [blame] | 118 | public void onStart() { |
| 119 | super.onStart(); |
| 120 | displayCheckBoxes(true); |
Sean Midford | 4b2ccd2 | 2016-10-14 13:03:49 -0700 | [diff] [blame] | 121 | |
| 122 | final long[] itemIds = getActivity().getIntent().getLongArrayExtra( |
| 123 | UiIntentActions.SELECTION_ITEM_LIST); |
| 124 | final boolean[] selectedFlags = getActivity().getIntent().getBooleanArrayExtra( |
| 125 | UiIntentActions.SELECTION_DEFAULT_SELECTION); |
| 126 | if (itemIds != null && selectedFlags != null && itemIds.length == selectedFlags.length) { |
| 127 | TreeSet<Long> selectedIds = new TreeSet<>(); |
| 128 | for (int i = 0; i < itemIds.length; i++) { |
| 129 | if (selectedFlags[i]) { |
| 130 | selectedIds.add(itemIds[i]); |
| 131 | } |
| 132 | } |
| 133 | getAdapter().setSelectedContactIds(selectedIds); |
| 134 | onSelectedContactsChanged(); |
| 135 | } |
Sean Midford | ff6f1bb | 2016-10-12 09:48:23 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | @Override |
| 139 | protected boolean onItemLongClick(int position, long id) { |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | protected View inflateView(LayoutInflater inflater, ViewGroup container) { |
| 145 | return inflater.inflate(com.android.contacts.common.R.layout.contact_list_content, null); |
| 146 | } |
| 147 | } |