The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1 | /* |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 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 | |
Dmitri Plotnikov | 27834b2 | 2010-07-01 14:10:08 -0700 | [diff] [blame] | 17 | package com.android.contacts.activities; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 18 | |
Wenyi Wang | 303b949 | 2016-06-21 10:06:30 -0700 | [diff] [blame] | 19 | import android.accounts.Account; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 20 | import android.app.Fragment; |
| 21 | import android.app.FragmentManager; |
| 22 | import android.app.FragmentTransaction; |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 23 | import android.content.ContentResolver; |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 25 | import android.content.ContentUris; |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 26 | import android.content.Context; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 27 | import android.content.Intent; |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 28 | import android.content.SyncStatusObserver; |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 29 | import android.content.IntentFilter; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 30 | import android.net.Uri; |
| 31 | import android.os.Bundle; |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 32 | import android.os.Handler; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 33 | import android.provider.ContactsContract; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 34 | import android.provider.ContactsContract.ProviderStatus; |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 35 | import android.support.design.widget.CoordinatorLayout; |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 36 | import android.support.design.widget.Snackbar; |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 37 | import android.support.v4.content.LocalBroadcastManager; |
Walter Jang | 758f565 | 2016-04-05 09:29:56 -0700 | [diff] [blame] | 38 | import android.support.v4.view.GravityCompat; |
Xi Chen | 947c23d | 2016-06-30 20:23:52 -0700 | [diff] [blame] | 39 | import android.support.v4.widget.SwipeRefreshLayout; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 40 | import android.util.Log; |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 41 | import android.view.Gravity; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 42 | import android.view.KeyCharacterMap; |
| 43 | import android.view.KeyEvent; |
| 44 | import android.view.Menu; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 45 | import android.view.MenuItem; |
Wenyi Wang | 9cfe1af | 2016-04-07 18:06:08 -0700 | [diff] [blame] | 46 | import android.view.SubMenu; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 47 | import android.view.View; |
| 48 | import android.view.ViewGroup; |
Paul Soulos | 2b9563d | 2014-05-27 16:21:23 -0700 | [diff] [blame] | 49 | import android.widget.ImageButton; |
Jay Shrauner | d391f84 | 2014-11-26 11:14:24 -0800 | [diff] [blame] | 50 | import android.widget.Toast; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 51 | |
Cody Thomas | f32dc99 | 2016-05-11 10:56:04 -0700 | [diff] [blame] | 52 | import com.android.contacts.ContactSaveService; |
Wenyi Wang | bb22924 | 2016-05-25 16:04:13 -0700 | [diff] [blame] | 53 | import com.android.contacts.ContactsDrawerActivity; |
Dmitri Plotnikov | 27834b2 | 2010-07-01 14:10:08 -0700 | [diff] [blame] | 54 | import com.android.contacts.R; |
Xi Chen | 947c23d | 2016-06-30 20:23:52 -0700 | [diff] [blame] | 55 | import com.android.contacts.common.Experiments; |
Brian Attwell | bdd3264 | 2015-05-08 17:03:15 -0700 | [diff] [blame] | 56 | import com.android.contacts.common.activity.RequestPermissionsActivity; |
Chiao Cheng | 051f41d | 2012-12-04 15:42:42 -0800 | [diff] [blame] | 57 | import com.android.contacts.common.interactions.ImportExportDialogFragment; |
Chiao Cheng | a0233a0 | 2012-11-01 16:41:08 -0700 | [diff] [blame] | 58 | import com.android.contacts.common.list.ContactListFilter; |
Chiao Cheng | a0233a0 | 2012-11-01 16:41:08 -0700 | [diff] [blame] | 59 | import com.android.contacts.common.list.DirectoryListLoader; |
Wenyi Wang | bb22924 | 2016-05-25 16:04:13 -0700 | [diff] [blame] | 60 | import com.android.contacts.common.list.ProviderStatusWatcher; |
| 61 | import com.android.contacts.common.list.ProviderStatusWatcher.ProviderStatusListener; |
Walter Jang | a84fe61 | 2016-01-13 16:49:04 -0800 | [diff] [blame] | 62 | import com.android.contacts.common.logging.Logger; |
Walter Jang | 62a2074 | 2016-02-24 17:04:12 -0800 | [diff] [blame] | 63 | import com.android.contacts.common.logging.ScreenEvent.ScreenType; |
Wenyi Wang | bf69330 | 2016-06-14 12:49:03 -0700 | [diff] [blame] | 64 | import com.android.contacts.common.model.AccountTypeManager; |
| 65 | import com.android.contacts.common.model.account.AccountWithDataSet; |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 66 | import com.android.contacts.common.util.AccountFilterUtil; |
guanxiongliu | f597ec6 | 2016-01-25 19:49:42 -0800 | [diff] [blame] | 67 | import com.android.contacts.common.util.Constants; |
guanxiongliu | 5d7bb26 | 2016-01-29 16:43:45 -0800 | [diff] [blame] | 68 | import com.android.contacts.common.util.ImplicitIntentsUtil; |
guanxiongliu | 5d7bb26 | 2016-01-29 16:43:45 -0800 | [diff] [blame] | 69 | import com.android.contacts.common.widget.FloatingActionButtonController; |
guanxiongliu | f597ec6 | 2016-01-25 19:49:42 -0800 | [diff] [blame] | 70 | import com.android.contacts.editor.EditorIntents; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 71 | import com.android.contacts.group.GroupMembersFragment; |
Walter Jang | 5a49696 | 2016-09-09 18:32:50 -0700 | [diff] [blame^] | 72 | import com.android.contacts.group.GroupMetaData; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 73 | import com.android.contacts.group.GroupUtil; |
guanxiongliu | f597ec6 | 2016-01-25 19:49:42 -0800 | [diff] [blame] | 74 | import com.android.contacts.list.ContactsIntentResolver; |
| 75 | import com.android.contacts.list.ContactsRequest; |
| 76 | import com.android.contacts.list.ContactsUnavailableFragment; |
Walter Jang | e9ea4f0 | 2016-05-10 09:39:46 -0700 | [diff] [blame] | 77 | import com.android.contacts.list.DefaultContactBrowseListFragment; |
guanxiongliu | f597ec6 | 2016-01-25 19:49:42 -0800 | [diff] [blame] | 78 | import com.android.contacts.list.OnContactsUnavailableActionListener; |
Brian Attwell | 8a6f4ad | 2014-06-06 21:54:53 -0700 | [diff] [blame] | 79 | import com.android.contacts.quickcontact.QuickContactActivity; |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 80 | import com.android.contacts.util.SyncUtil; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 81 | import com.android.contactsbind.ObjectFactory; |
Walter Jang | 6367d2a | 2016-08-15 14:51:18 -0700 | [diff] [blame] | 82 | import com.android.contactsbind.experiments.Flags; |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 83 | import com.android.contacts.widget.FloatingActionButtonBehavior; |
Tadashi G. Takaoka | 57cf30f | 2009-09-21 19:54:39 +0900 | [diff] [blame] | 84 | |
Brian Attwell | 20510ec | 2015-02-27 16:10:45 -0800 | [diff] [blame] | 85 | import java.util.List; |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 86 | import java.util.concurrent.atomic.AtomicInteger; |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 87 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 88 | /** |
Brian Attwell | 2c1bfd0 | 2014-06-04 18:18:35 -0700 | [diff] [blame] | 89 | * Displays a list to browse contacts. |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 90 | */ |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 91 | public class PeopleActivity extends ContactsDrawerActivity implements ProviderStatusListener { |
Dmitri Plotnikov | 57d27da | 2009-09-28 18:06:11 -0700 | [diff] [blame] | 92 | |
Dave Santoro | 5e684a4 | 2011-06-10 13:23:35 -0700 | [diff] [blame] | 93 | private static final String TAG = "PeopleActivity"; |
Wenyi Wang | ca6018d | 2016-08-18 17:23:13 -0700 | [diff] [blame] | 94 | private static final String TAG_ALL = "contacts-all"; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 95 | private static final String TAG_UNAVAILABLE = "contacts-unavailable"; |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 96 | private static final String TAG_GROUP_VIEW = "contacts-groups"; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 97 | private static final String TAG_DUPLICATES = "contacts-duplicates"; |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 98 | private static final String TAG_SECOND_LEVEL = "second-level"; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 99 | // Tag for DuplicatesUtilFragment.java |
| 100 | public static final String TAG_DUPLICATES_UTIL = "DuplicatesUtilFragment"; |
| 101 | |
| 102 | private static final String KEY_GROUP_URI = "groupUri"; |
Wenyi Wang | ca6018d | 2016-08-18 17:23:13 -0700 | [diff] [blame] | 103 | |
Dmitri Plotnikov | ac0f783 | 2010-04-22 13:26:52 -0700 | [diff] [blame] | 104 | private ContactsIntentResolver mIntentResolver; |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 105 | private ContactsRequest mRequest; |
| 106 | |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 107 | private FloatingActionButtonController mFloatingActionButtonController; |
| 108 | private View mFloatingActionButtonContainer; |
| 109 | private boolean wasLastFabAnimationScaleIn = false; |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 110 | |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 111 | private ContactsUnavailableFragment mContactsUnavailableFragment; |
Makoto Onuki | c2bd613 | 2012-04-27 16:14:51 -0700 | [diff] [blame] | 112 | private ProviderStatusWatcher mProviderStatusWatcher; |
Brian Attwell | c3d202c | 2015-01-08 15:01:03 -0800 | [diff] [blame] | 113 | private Integer mProviderStatus; |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 114 | |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 115 | private BroadcastReceiver mSaveServiceListener; |
| 116 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 117 | private boolean mShouldSwitchToGroupView; |
| 118 | |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 119 | private CoordinatorLayout mLayoutRoot; |
| 120 | |
Daisuke Miyakawa | 95c5c2a | 2011-07-08 10:33:21 -0700 | [diff] [blame] | 121 | /** |
| 122 | * Showing a list of Contacts. Also used for showing search results in search mode. |
| 123 | */ |
Walter Jang | e9ea4f0 | 2016-05-10 09:39:46 -0700 | [diff] [blame] | 124 | private DefaultContactBrowseListFragment mAllFragment; |
Katherine Kuan | b5760b9 | 2011-06-01 16:19:40 -0700 | [diff] [blame] | 125 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 126 | private GroupMembersFragment mMembersFragment; |
| 127 | private Uri mGroupUri; |
Katherine Kuan | 58fc577 | 2011-07-04 10:08:32 -0700 | [diff] [blame] | 128 | |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 129 | /** |
| 130 | * True if this activity instance is a re-created one. i.e. set true after orientation change. |
| 131 | * This is set in {@link #onCreate} for later use in {@link #onStart}. |
| 132 | */ |
| 133 | private boolean mIsRecreatedInstance; |
| 134 | |
| 135 | /** |
| 136 | * If {@link #configureFragments(boolean)} is already called. Used to avoid calling it twice |
| 137 | * in {@link #onStart}. |
| 138 | * (This initialization only needs to be done once in onStart() when the Activity was just |
| 139 | * created from scratch -- i.e. onCreate() was just called) |
| 140 | */ |
| 141 | private boolean mFragmentInitialized; |
| 142 | |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 143 | /** Sequential ID assigned to each instance; used for logging */ |
| 144 | private final int mInstanceId; |
| 145 | private static final AtomicInteger sNextInstanceId = new AtomicInteger(); |
| 146 | |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 147 | private Object mStatusChangeListenerHandle; |
| 148 | |
| 149 | private final Handler mHandler = new Handler(); |
| 150 | |
| 151 | private SyncStatusObserver mSyncStatusObserver = new SyncStatusObserver() { |
| 152 | public void onStatusChanged(int which) { |
| 153 | mHandler.post(new Runnable() { |
| 154 | public void run() { |
| 155 | onSyncStateUpdated(); |
| 156 | } |
| 157 | }); |
| 158 | } |
| 159 | }; |
| 160 | |
| 161 | // Update sync status for accounts in current ContactListFilter |
| 162 | private void onSyncStateUpdated() { |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 163 | if (mAllFragment.getActionBarAdapter().isSearchMode() |
| 164 | || mAllFragment.getActionBarAdapter().isSelectionMode()) { |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 165 | return; |
| 166 | } |
| 167 | |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 168 | final ContactListFilter filter = mAllFragment.getFilter(); |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 169 | if (filter != null) { |
| 170 | final SwipeRefreshLayout swipeRefreshLayout = mAllFragment.getSwipeRefreshLayout(); |
| 171 | if (swipeRefreshLayout == null) { |
| 172 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 173 | Log.d(TAG, "Can not load swipeRefreshLayout, swipeRefreshLayout is null"); |
| 174 | } |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | final List<AccountWithDataSet> accounts = AccountTypeManager.getInstance(this) |
| 179 | .getAccounts(/* contactsWritableOnly */ true); |
| 180 | final List<Account> syncableAccounts = filter.getSyncableAccounts(accounts); |
| 181 | // If one of the accounts is active or pending, use spinning circle to indicate one of |
| 182 | // the syncs is in progress. |
| 183 | if (syncableAccounts != null && syncableAccounts.size() > 0) { |
| 184 | for (Account account: syncableAccounts) { |
Xi Chen | a455bd5 | 2016-07-25 17:00:22 -0700 | [diff] [blame] | 185 | if (SyncUtil.isSyncStatusPendingOrActive(account) |
| 186 | || SyncUtil.isUnsyncableGoogleAccount(account)) { |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 187 | swipeRefreshLayout.setRefreshing(true); |
| 188 | return; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | swipeRefreshLayout.setRefreshing(false); |
| 193 | } |
| 194 | } |
| 195 | |
Katherine Kuan | 9856fce | 2011-06-01 10:24:09 -0700 | [diff] [blame] | 196 | public PeopleActivity() { |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 197 | mInstanceId = sNextInstanceId.getAndIncrement(); |
Dmitri Plotnikov | 1540674 | 2010-05-07 09:22:49 -0700 | [diff] [blame] | 198 | mIntentResolver = new ContactsIntentResolver(this); |
Makoto Onuki | c2bd613 | 2012-04-27 16:14:51 -0700 | [diff] [blame] | 199 | mProviderStatusWatcher = ProviderStatusWatcher.getInstance(this); |
Dmitri Plotnikov | 6178cb4 | 2010-04-20 11:26:05 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 202 | @Override |
| 203 | public String toString() { |
| 204 | // Shown on logcat |
| 205 | return String.format("%s@%d", getClass().getSimpleName(), mInstanceId); |
| 206 | } |
| 207 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 208 | private boolean areContactsAvailable() { |
Wenyi Wang | 2f09e60 | 2015-10-28 11:34:23 -0700 | [diff] [blame] | 209 | return (mProviderStatus != null) && mProviderStatus.equals(ProviderStatus.STATUS_NORMAL); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Makoto Onuki | 50445e9 | 2011-07-12 10:28:12 -0700 | [diff] [blame] | 212 | /** |
| 213 | * Initialize fragments that are (or may not be) in the layout. |
| 214 | * |
| 215 | * For the fragments that are in the layout, we initialize them in |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 216 | * {@link #createViewsAndFragments()} after inflating the layout. |
Makoto Onuki | 50445e9 | 2011-07-12 10:28:12 -0700 | [diff] [blame] | 217 | * |
Brian Attwell | 2c1bfd0 | 2014-06-04 18:18:35 -0700 | [diff] [blame] | 218 | * However, the {@link ContactsUnavailableFragment} is a special fragment which may not |
| 219 | * be in the layout, so we have to do the initialization here. |
| 220 | * |
| 221 | * The ContactsUnavailableFragment is always created at runtime. |
Makoto Onuki | 50445e9 | 2011-07-12 10:28:12 -0700 | [diff] [blame] | 222 | */ |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 223 | @Override |
Dmitri Plotnikov | 92a6fdf | 2010-07-09 13:19:33 -0700 | [diff] [blame] | 224 | public void onAttachFragment(Fragment fragment) { |
Brian Attwell | 2c1bfd0 | 2014-06-04 18:18:35 -0700 | [diff] [blame] | 225 | if (fragment instanceof ContactsUnavailableFragment) { |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 226 | mContactsUnavailableFragment = (ContactsUnavailableFragment)fragment; |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 227 | mContactsUnavailableFragment.setOnContactsUnavailableActionListener( |
| 228 | new ContactsUnavailableFragmentListener()); |
Dmitri Plotnikov | 92a6fdf | 2010-07-09 13:19:33 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
| 232 | @Override |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 233 | protected void onCreate(Bundle savedState) { |
Makoto Onuki | 49627cc | 2011-08-28 13:56:48 -0700 | [diff] [blame] | 234 | if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) { |
| 235 | Log.d(Constants.PERFORMANCE_TAG, "PeopleActivity.onCreate start"); |
| 236 | } |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 237 | super.onCreate(savedState); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 238 | |
Brian Attwell | bdd3264 | 2015-05-08 17:03:15 -0700 | [diff] [blame] | 239 | if (RequestPermissionsActivity.startPermissionActivity(this)) { |
| 240 | return; |
| 241 | } |
| 242 | |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 243 | if (!processIntent(false)) { |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 244 | finish(); |
| 245 | return; |
| 246 | } |
Daisuke Miyakawa | a012aec | 2011-10-16 10:24:43 -0700 | [diff] [blame] | 247 | |
Makoto Onuki | c2bd613 | 2012-04-27 16:14:51 -0700 | [diff] [blame] | 248 | mProviderStatusWatcher.addListener(this); |
| 249 | |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 250 | mIsRecreatedInstance = (savedState != null); |
Wenyi Wang | 40e7910 | 2016-06-01 20:43:56 -0700 | [diff] [blame] | 251 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 252 | if (mIsRecreatedInstance) { |
| 253 | mGroupUri = savedState.getParcelable(KEY_GROUP_URI); |
| 254 | } |
| 255 | |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 256 | createViewsAndFragments(); |
Andrew Lee | 4b1af3f | 2014-04-23 10:23:55 -0700 | [diff] [blame] | 257 | |
Makoto Onuki | 49627cc | 2011-08-28 13:56:48 -0700 | [diff] [blame] | 258 | if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) { |
| 259 | Log.d(Constants.PERFORMANCE_TAG, "PeopleActivity.onCreate finish"); |
| 260 | } |
Sai Cheemalapati | 5b22108 | 2014-06-27 14:45:43 -0700 | [diff] [blame] | 261 | getWindow().setBackgroundDrawable(null); |
Tingting Wang | ac9596e | 2016-08-02 22:24:24 -0700 | [diff] [blame] | 262 | } |
Tingting Wang | dce1e68 | 2016-07-28 10:06:29 -0700 | [diff] [blame] | 263 | |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 264 | @Override |
| 265 | protected void onNewIntent(Intent intent) { |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 266 | if (GroupUtil.ACTION_CREATE_GROUP.equals(intent.getAction())) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 267 | mGroupUri = intent.getData(); |
| 268 | if (mGroupUri == null) { |
| 269 | toast(R.string.groupSavedErrorToast); |
| 270 | return; |
| 271 | } |
| 272 | if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "Received group URI " + mGroupUri); |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 273 | switchToOrUpdateGroupView(intent.getAction()); |
Walter Jang | 13710d5 | 2016-07-08 14:36:20 -0700 | [diff] [blame] | 274 | return; |
| 275 | } |
| 276 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 277 | if (isGroupDeleteAction(intent.getAction())) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 278 | toast(R.string.groupDeletedToast); |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 279 | popSecondLevel(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 280 | mCurrentView = ContactsView.ALL_CONTACTS; |
| 281 | showFabWithAnimation(/* showFab */ true); |
| 282 | return; |
| 283 | } |
| 284 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 285 | if (isGroupSaveAction(intent.getAction())) { |
| 286 | mGroupUri = intent.getData(); |
| 287 | if (mGroupUri == null) { |
| 288 | popSecondLevel(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 289 | toast(R.string.groupSavedErrorToast); |
| 290 | return; |
| 291 | } |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 292 | if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "Received group URI " + mGroupUri); |
| 293 | switchToOrUpdateGroupView(intent.getAction()); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 296 | setIntent(intent); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 297 | |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 298 | if (!processIntent(true)) { |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 299 | finish(); |
| 300 | return; |
| 301 | } |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 302 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 303 | mContactListFilterController.checkFilterValidity(false); |
| 304 | |
| 305 | if (!isInSecondLevel()) { |
| 306 | // Re-initialize ActionBarAdapter because {@link #onNewIntent(Intent)} doesn't invoke |
| 307 | // {@link Fragment#onActivityCreated(Bundle)} where we initialize ActionBarAdapter |
| 308 | // initially. |
| 309 | mAllFragment.setContactsRequest(mRequest); |
| 310 | mAllFragment.initializeActionBarAdapter(null); |
| 311 | } |
Katherine Kuan | be79b8f | 2011-11-09 20:54:43 -0800 | [diff] [blame] | 312 | |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 313 | // Re-configure fragments. |
| 314 | configureFragments(true /* from request */); |
Brian Attwell | 9cfa24c | 2015-05-04 12:31:37 -0700 | [diff] [blame] | 315 | initializeFabVisibility(); |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 316 | invalidateOptionsMenuIfNeeded(); |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 319 | private static boolean isGroupDeleteAction(String action) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 320 | return GroupUtil.ACTION_DELETE_GROUP.equals(action); |
| 321 | } |
| 322 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 323 | private static boolean isGroupSaveAction(String action) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 324 | return GroupUtil.ACTION_UPDATE_GROUP.equals(action) |
| 325 | || GroupUtil.ACTION_ADD_TO_GROUP.equals(action) |
| 326 | || GroupUtil.ACTION_REMOVE_FROM_GROUP.equals(action); |
| 327 | } |
| 328 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 329 | private void toast(int resId) { |
| 330 | if (resId >= 0) { |
| 331 | Toast.makeText(this, resId, Toast.LENGTH_SHORT).show(); |
| 332 | } |
| 333 | } |
| 334 | |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 335 | /** |
| 336 | * Resolve the intent and initialize {@link #mRequest}, and launch another activity if redirect |
| 337 | * is needed. |
| 338 | * |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 339 | * @param forNewIntent set true if it's called from {@link #onNewIntent(Intent)}. |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 340 | * @return {@code true} if {@link PeopleActivity} should continue running. {@code false} |
| 341 | * if it shouldn't, in which case the caller should finish() itself and shouldn't do |
| 342 | * farther initialization. |
| 343 | */ |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 344 | private boolean processIntent(boolean forNewIntent) { |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 345 | // Extract relevant information from the intent |
| 346 | mRequest = mIntentResolver.resolveIntent(getIntent()); |
Makoto Onuki | ea14605 | 2011-07-25 10:34:15 -0700 | [diff] [blame] | 347 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 348 | Log.d(TAG, this + " processIntent: forNewIntent=" + forNewIntent |
| 349 | + " intent=" + getIntent() + " request=" + mRequest); |
| 350 | } |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 351 | if (!mRequest.isValid()) { |
| 352 | setResult(RESULT_CANCELED); |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 353 | return false; |
Dmitri Plotnikov | 59fb48e | 2010-04-26 17:09:19 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Walter Jang | 1110d67 | 2016-07-25 17:55:12 +0000 | [diff] [blame] | 356 | switch (mRequest.getActionCode()) { |
| 357 | case ContactsRequest.ACTION_VIEW_CONTACT: { |
| 358 | final Intent intent = ImplicitIntentsUtil.composeQuickContactIntent( |
John Shao | 41c6886 | 2016-08-17 21:02:41 -0700 | [diff] [blame] | 359 | PeopleActivity.this, mRequest.getContactUri(), |
| 360 | QuickContactActivity.MODE_FULLY_EXPANDED); |
Walter Jang | 1110d67 | 2016-07-25 17:55:12 +0000 | [diff] [blame] | 361 | intent.putExtra(QuickContactActivity.EXTRA_PREVIOUS_SCREEN_TYPE, ScreenType.UNKNOWN); |
| 362 | ImplicitIntentsUtil.startActivityInApp(this, intent); |
| 363 | return false; |
| 364 | } |
| 365 | case ContactsRequest.ACTION_INSERT_GROUP: { |
| 366 | onCreateGroupMenuItemClicked(); |
| 367 | return true; |
| 368 | } |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 369 | case ContactsRequest.ACTION_VIEW_GROUP: |
| 370 | case ContactsRequest.ACTION_EDIT_GROUP: { |
| 371 | mShouldSwitchToGroupView = true; |
| 372 | return true; |
| 373 | } |
Dmitri Plotnikov | 27b97bc | 2010-10-07 18:06:09 -0700 | [diff] [blame] | 374 | } |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 375 | return true; |
| 376 | } |
| 377 | |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 378 | private void createViewsAndFragments() { |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 379 | setContentView(R.layout.people_activity); |
| 380 | |
| 381 | final FragmentManager fragmentManager = getFragmentManager(); |
| 382 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 383 | setUpAllFragment(fragmentManager); |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 384 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 385 | if (isGroupView()) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 386 | mMembersFragment = (GroupMembersFragment) |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 387 | fragmentManager.findFragmentByTag(TAG_GROUP_VIEW); |
Makoto Onuki | 4d788fc | 2011-07-12 10:00:10 -0700 | [diff] [blame] | 388 | } |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 389 | |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 390 | // Configure floating action button |
| 391 | mFloatingActionButtonContainer = findViewById(R.id.floating_action_button_container); |
| 392 | final ImageButton floatingActionButton |
| 393 | = (ImageButton) findViewById(R.id.floating_action_button); |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 394 | floatingActionButton.setOnClickListener(new View.OnClickListener() { |
| 395 | @Override |
| 396 | public void onClick(View v) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 397 | AccountFilterUtil.startEditorIntent(PeopleActivity.this, getIntent(), |
| 398 | mContactListFilterController.getFilter()); |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 399 | } |
| 400 | }); |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 401 | mFloatingActionButtonController = new FloatingActionButtonController(this, |
| 402 | mFloatingActionButtonContainer, floatingActionButton); |
Paul Soulos | 2b9563d | 2014-05-27 16:21:23 -0700 | [diff] [blame] | 403 | |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 404 | invalidateOptionsMenuIfNeeded(); |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 405 | |
| 406 | mLayoutRoot = (CoordinatorLayout) findViewById(R.id.root); |
| 407 | |
| 408 | // Setup the FAB to animate upwards when a snackbar is shown in this activity. |
| 409 | // Normally the layout_behavior attribute could be used for this but for some reason it |
| 410 | // throws a ClassNotFoundException so the layout parameters are set programmatically. |
| 411 | final CoordinatorLayout.LayoutParams fabParams = new CoordinatorLayout.LayoutParams( |
| 412 | (ViewGroup.MarginLayoutParams) mFloatingActionButtonContainer.getLayoutParams()); |
| 413 | fabParams.setBehavior(new FloatingActionButtonBehavior()); |
| 414 | fabParams.gravity = Gravity.BOTTOM | Gravity.END; |
| 415 | mFloatingActionButtonContainer.setLayoutParams(fabParams); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 416 | |
| 417 | if (mShouldSwitchToGroupView && !mIsRecreatedInstance) { |
| 418 | mGroupUri = mRequest.getContactUri(); |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 419 | switchToOrUpdateGroupView(GroupUtil.ACTION_SWITCH_GROUP); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 420 | mShouldSwitchToGroupView = false; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | private void setUpAllFragment(FragmentManager fragmentManager) { |
| 425 | mAllFragment = (DefaultContactBrowseListFragment) |
| 426 | fragmentManager.findFragmentByTag(TAG_ALL); |
| 427 | |
| 428 | if (mAllFragment == null) { |
| 429 | mAllFragment = new DefaultContactBrowseListFragment(); |
| 430 | mAllFragment.setAnimateOnLoad(true); |
| 431 | fragmentManager.beginTransaction() |
| 432 | .add(R.id.contacts_list_container, mAllFragment, TAG_ALL) |
| 433 | .commit(); |
| 434 | fragmentManager.executePendingTransactions(); |
| 435 | } |
| 436 | |
| 437 | mAllFragment.setContactsAvailable(areContactsAvailable()); |
| 438 | mAllFragment.setListType(); |
| 439 | mAllFragment.setContactsRequest(mRequest); |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 440 | } |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 441 | |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 442 | @Override |
| 443 | protected void onStart() { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 444 | if (!mFragmentInitialized && (!isInSecondLevel())) { |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 445 | mFragmentInitialized = true; |
| 446 | /* Configure fragments if we haven't. |
| 447 | * |
| 448 | * Note it's a one-shot initialization, so we want to do this in {@link #onCreate}. |
| 449 | * |
| 450 | * However, because this method may indirectly touch views in fragments but fragments |
| 451 | * created in {@link #configureContentView} using a {@link FragmentTransaction} will NOT |
| 452 | * have views until {@link Activity#onCreate} finishes (they would if they were inflated |
| 453 | * from a layout), we need to do it here in {@link #onStart()}. |
| 454 | * |
| 455 | * (When {@link Fragment#onCreateView} is called is different in the former case and |
| 456 | * in the latter case, unfortunately.) |
| 457 | * |
| 458 | * Also, we skip most of the work in it if the activity is a re-created one. |
| 459 | * (so the argument.) |
| 460 | */ |
| 461 | configureFragments(!mIsRecreatedInstance); |
Dmitri Plotnikov | fe42e55 | 2010-05-14 14:50:32 -0700 | [diff] [blame] | 462 | } |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 463 | super.onStart(); |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 466 | @Override |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame] | 467 | protected void onPause() { |
Makoto Onuki | c2bd613 | 2012-04-27 16:14:51 -0700 | [diff] [blame] | 468 | mProviderStatusWatcher.stop(); |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 469 | |
| 470 | LocalBroadcastManager.getInstance(this).unregisterReceiver(mSaveServiceListener); |
| 471 | |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame] | 472 | super.onPause(); |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 473 | |
| 474 | if (Flags.getInstance(this).getBoolean(Experiments.PULL_TO_REFRESH)) { |
| 475 | ContentResolver.removeStatusChangeListener(mStatusChangeListenerHandle); |
| 476 | onSyncStateUpdated(); |
| 477 | } |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | @Override |
| 481 | protected void onResume() { |
| 482 | super.onResume(); |
Josh Gargus | 697ab26 | 2012-05-04 11:11:34 -0700 | [diff] [blame] | 483 | |
Makoto Onuki | c2bd613 | 2012-04-27 16:14:51 -0700 | [diff] [blame] | 484 | mProviderStatusWatcher.start(); |
Josh Gargus | 697ab26 | 2012-05-04 11:11:34 -0700 | [diff] [blame] | 485 | updateViewConfiguration(true); |
Makoto Onuki | 4d788fc | 2011-07-12 10:00:10 -0700 | [diff] [blame] | 486 | |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 487 | if (Flags.getInstance(this).getBoolean(Experiments.PULL_TO_REFRESH)) { |
| 488 | mStatusChangeListenerHandle = ContentResolver.addStatusChangeListener( |
| 489 | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE |
| 490 | | ContentResolver.SYNC_OBSERVER_TYPE_PENDING |
| 491 | | ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, |
| 492 | mSyncStatusObserver); |
| 493 | onSyncStateUpdated(); |
| 494 | } |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 495 | if (!isInSecondLevel()) { |
| 496 | mAllFragment.maybeShowHamburgerFeatureHighlight(); |
| 497 | } |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 498 | initializeFabVisibility(); |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 499 | |
| 500 | mSaveServiceListener = new SaveServiceListener(); |
| 501 | LocalBroadcastManager.getInstance(this).registerReceiver(mSaveServiceListener, |
| 502 | new IntentFilter(ContactSaveService.BROADCAST_ACTION_GROUP_DELETED)); |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | @Override |
Makoto Onuki | 4d788fc | 2011-07-12 10:00:10 -0700 | [diff] [blame] | 506 | protected void onDestroy() { |
Makoto Onuki | c2bd613 | 2012-04-27 16:14:51 -0700 | [diff] [blame] | 507 | mProviderStatusWatcher.removeListener(this); |
Makoto Onuki | 4d788fc | 2011-07-12 10:00:10 -0700 | [diff] [blame] | 508 | super.onDestroy(); |
| 509 | } |
| 510 | |
Dmitri Plotnikov | 955846e | 2010-11-11 22:31:28 -0800 | [diff] [blame] | 511 | private void configureFragments(boolean fromRequest) { |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 512 | if (fromRequest) { |
Dmitri Plotnikov | 91ab5b4 | 2010-10-08 15:26:31 -0700 | [diff] [blame] | 513 | ContactListFilter filter = null; |
| 514 | int actionCode = mRequest.getActionCode(); |
Makoto Onuki | 53b427b | 2011-07-17 11:42:32 -0700 | [diff] [blame] | 515 | boolean searchMode = mRequest.isSearchMode(); |
Dmitri Plotnikov | 91ab5b4 | 2010-10-08 15:26:31 -0700 | [diff] [blame] | 516 | switch (actionCode) { |
| 517 | case ContactsRequest.ACTION_ALL_CONTACTS: |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 518 | filter = AccountFilterUtil.createContactsFilter(this); |
Dmitri Plotnikov | 91ab5b4 | 2010-10-08 15:26:31 -0700 | [diff] [blame] | 519 | break; |
| 520 | case ContactsRequest.ACTION_CONTACTS_WITH_PHONES: |
Katherine Kuan | be18de0 | 2011-06-07 12:38:29 -0700 | [diff] [blame] | 521 | filter = ContactListFilter.createFilterWithType( |
Dmitri Plotnikov | 91ab5b4 | 2010-10-08 15:26:31 -0700 | [diff] [blame] | 522 | ContactListFilter.FILTER_TYPE_WITH_PHONE_NUMBERS_ONLY); |
| 523 | break; |
| 524 | |
Dmitri Plotnikov | 91ab5b4 | 2010-10-08 15:26:31 -0700 | [diff] [blame] | 525 | case ContactsRequest.ACTION_FREQUENT: |
| 526 | case ContactsRequest.ACTION_STREQUENT: |
Dmitri Plotnikov | 91ab5b4 | 2010-10-08 15:26:31 -0700 | [diff] [blame] | 527 | case ContactsRequest.ACTION_STARRED: |
Frank Sposaro | 9e095d2 | 2011-07-07 15:18:38 -0700 | [diff] [blame] | 528 | case ContactsRequest.ACTION_VIEW_CONTACT: |
Daniel Lehmann | 52aa32d | 2012-03-08 17:29:27 -0800 | [diff] [blame] | 529 | default: |
Daniel Lehmann | 52aa32d | 2012-03-08 17:29:27 -0800 | [diff] [blame] | 530 | break; |
Makoto Onuki | ea14605 | 2011-07-25 10:34:15 -0700 | [diff] [blame] | 531 | } |
Dmitri Plotnikov | 91ab5b4 | 2010-10-08 15:26:31 -0700 | [diff] [blame] | 532 | |
| 533 | if (filter != null) { |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 534 | mAllFragment.setContactListFilter(filter); |
Makoto Onuki | 53b427b | 2011-07-17 11:42:32 -0700 | [diff] [blame] | 535 | searchMode = false; |
Dmitri Plotnikov | 009676f | 2010-10-08 12:13:57 -0700 | [diff] [blame] | 536 | } |
Dmitri Plotnikov | d959104 | 2010-11-23 09:25:03 -0800 | [diff] [blame] | 537 | |
| 538 | if (mRequest.getContactUri() != null) { |
Makoto Onuki | 53b427b | 2011-07-17 11:42:32 -0700 | [diff] [blame] | 539 | searchMode = false; |
Dmitri Plotnikov | d959104 | 2010-11-23 09:25:03 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 542 | if (!isInSecondLevel()) { |
| 543 | mAllFragment.getActionBarAdapter().setSearchMode(searchMode); |
| 544 | configureContactListFragmentForRequest(); |
| 545 | } |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 548 | if (!isInSecondLevel()) { |
| 549 | mAllFragment.configureContactListFragment(); |
| 550 | } |
Dmitri Plotnikov | 92a6fdf | 2010-07-09 13:19:33 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 553 | private void initializeFabVisibility() { |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 554 | mFloatingActionButtonContainer.setVisibility(shouldHideFab() ? View.GONE : View.VISIBLE); |
Brian Attwell | 9cfa24c | 2015-05-04 12:31:37 -0700 | [diff] [blame] | 555 | mFloatingActionButtonController.resetIn(); |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 556 | wasLastFabAnimationScaleIn = !shouldHideFab(); |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 559 | private boolean shouldHideFab() { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 560 | if (mAllFragment != null && mAllFragment.getActionBarAdapter() == null |
| 561 | || isInSecondLevel()) { |
| 562 | return true; |
| 563 | } |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 564 | return mAllFragment.getActionBarAdapter().isSearchMode() |
| 565 | || mAllFragment.getActionBarAdapter().isSelectionMode(); |
Wenyi Wang | bf69330 | 2016-06-14 12:49:03 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 568 | public void showFabWithAnimation(boolean showFab) { |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 569 | if (mFloatingActionButtonContainer == null) { |
| 570 | return; |
| 571 | } |
| 572 | if (showFab) { |
| 573 | if (!wasLastFabAnimationScaleIn) { |
| 574 | mFloatingActionButtonContainer.setVisibility(View.VISIBLE); |
| 575 | mFloatingActionButtonController.scaleIn(0); |
| 576 | } |
| 577 | wasLastFabAnimationScaleIn = true; |
| 578 | |
| 579 | } else { |
| 580 | if (wasLastFabAnimationScaleIn) { |
| 581 | mFloatingActionButtonContainer.setVisibility(View.VISIBLE); |
| 582 | mFloatingActionButtonController.scaleOut(); |
| 583 | } |
| 584 | wasLastFabAnimationScaleIn = false; |
| 585 | } |
| 586 | } |
| 587 | |
Makoto Onuki | 1db00f6 | 2011-10-19 12:40:12 -0700 | [diff] [blame] | 588 | private void setQueryTextToFragment(String query) { |
Daisuke Miyakawa | 95c5c2a | 2011-07-08 10:33:21 -0700 | [diff] [blame] | 589 | mAllFragment.setQueryString(query, true); |
Makoto Onuki | 1db00f6 | 2011-10-19 12:40:12 -0700 | [diff] [blame] | 590 | mAllFragment.setVisibleScrollbarEnabled(!mAllFragment.isSearchMode()); |
Katherine Kuan | 8268bbe | 2011-06-10 17:48:21 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Katherine Kuan | 0ff0e31 | 2011-06-08 17:43:51 -0700 | [diff] [blame] | 593 | private void configureContactListFragmentForRequest() { |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 594 | Uri contactUri = mRequest.getContactUri(); |
| 595 | if (contactUri != null) { |
Daisuke Miyakawa | 95c5c2a | 2011-07-08 10:33:21 -0700 | [diff] [blame] | 596 | mAllFragment.setSelectedContactUri(contactUri); |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 597 | } |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 598 | |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 599 | setQueryTextToFragment(mAllFragment.getActionBarAdapter().getQueryString()); |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 600 | |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 601 | if (mRequest.isDirectorySearchEnabled()) { |
Daisuke Miyakawa | 95c5c2a | 2011-07-08 10:33:21 -0700 | [diff] [blame] | 602 | mAllFragment.setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_DEFAULT); |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 603 | } else { |
Daisuke Miyakawa | 95c5c2a | 2011-07-08 10:33:21 -0700 | [diff] [blame] | 604 | mAllFragment.setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_NONE); |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 605 | } |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 608 | @Override |
| 609 | public void onProviderStatusChange() { |
Wenyi Wang | cb117bd | 2016-06-17 13:26:57 -0700 | [diff] [blame] | 610 | reloadGroupsAndFiltersIfNeeded(); |
Josh Gargus | 697ab26 | 2012-05-04 11:11:34 -0700 | [diff] [blame] | 611 | updateViewConfiguration(false); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Wenyi Wang | cb117bd | 2016-06-17 13:26:57 -0700 | [diff] [blame] | 614 | private void reloadGroupsAndFiltersIfNeeded() { |
| 615 | final int providerStatus = mProviderStatusWatcher.getProviderStatus(); |
| 616 | final Menu menu = mNavigationView.getMenu(); |
| 617 | final MenuItem groupsMenuItem = menu.findItem(R.id.nav_groups); |
| 618 | final SubMenu subMenu = groupsMenuItem.getSubMenu(); |
| 619 | |
| 620 | // Reload groups and filters if provider status changes to "normal" and there's no groups |
| 621 | // loaded or just a "Create new..." menu item is in the menu. |
| 622 | if (subMenu != null && subMenu.size() <= 1 && providerStatus == ProviderStatus.STATUS_NORMAL |
| 623 | && !mProviderStatus.equals(providerStatus)) { |
| 624 | loadGroupsAndFilters(); |
| 625 | } |
| 626 | } |
| 627 | |
Josh Gargus | 697ab26 | 2012-05-04 11:11:34 -0700 | [diff] [blame] | 628 | private void updateViewConfiguration(boolean forceUpdate) { |
Brian Attwell | c3d202c | 2015-01-08 15:01:03 -0800 | [diff] [blame] | 629 | int providerStatus = mProviderStatusWatcher.getProviderStatus(); |
Makoto Onuki | d8fa716 | 2012-05-16 13:45:48 -0700 | [diff] [blame] | 630 | if (!forceUpdate && (mProviderStatus != null) |
Brian Attwell | c3d202c | 2015-01-08 15:01:03 -0800 | [diff] [blame] | 631 | && (mProviderStatus.equals(providerStatus))) return; |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 632 | mProviderStatus = providerStatus; |
| 633 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 634 | final FragmentManager fragmentManager= getFragmentManager(); |
| 635 | final FragmentTransaction transaction = fragmentManager.beginTransaction(); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 636 | |
Wenyi Wang | f128ea8 | 2016-07-25 11:56:40 -0700 | [diff] [blame] | 637 | // Change in CP2's provider status may not take effect immediately, see b/30566908. |
| 638 | // So we need to handle the case where provider status is STATUS_EMPTY and there is |
| 639 | // actually at least one real account (not "local" account) on device. |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 640 | if (shouldShowList()) { |
Daisuke Miyakawa | 95c5c2a | 2011-07-08 10:33:21 -0700 | [diff] [blame] | 641 | if (mAllFragment != null) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 642 | transaction.show(mAllFragment); |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 643 | mAllFragment.setContactsAvailable(areContactsAvailable()); |
Daisuke Miyakawa | 95c5c2a | 2011-07-08 10:33:21 -0700 | [diff] [blame] | 644 | mAllFragment.setEnabled(true); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 645 | } |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 646 | if (mContactsUnavailableFragment != null) { |
| 647 | transaction.hide(mContactsUnavailableFragment); |
| 648 | } |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 649 | } else { |
guanxiongliu | 5d7bb26 | 2016-01-29 16:43:45 -0800 | [diff] [blame] | 650 | // Setting up the page so that the user can still use the app |
| 651 | // even without an account. |
Daisuke Miyakawa | 95c5c2a | 2011-07-08 10:33:21 -0700 | [diff] [blame] | 652 | if (mAllFragment != null) { |
| 653 | mAllFragment.setEnabled(false); |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 654 | transaction.hide(mAllFragment); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 655 | } |
| 656 | if (mContactsUnavailableFragment == null) { |
| 657 | mContactsUnavailableFragment = new ContactsUnavailableFragment(); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 658 | mContactsUnavailableFragment.setOnContactsUnavailableActionListener( |
| 659 | new ContactsUnavailableFragmentListener()); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 660 | transaction.add(R.id.contacts_list_container, mContactsUnavailableFragment, |
| 661 | TAG_UNAVAILABLE); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 662 | } |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 663 | transaction.show(mContactsUnavailableFragment); |
Makoto Onuki | d8fa716 | 2012-05-16 13:45:48 -0700 | [diff] [blame] | 664 | mContactsUnavailableFragment.updateStatus(mProviderStatus); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 665 | } |
| 666 | if (!transaction.isEmpty()) { |
| 667 | transaction.commit(); |
| 668 | fragmentManager.executePendingTransactions(); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 669 | } |
| 670 | |
Katherine Kuan | 8268bbe | 2011-06-10 17:48:21 -0700 | [diff] [blame] | 671 | invalidateOptionsMenuIfNeeded(); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 672 | } |
| 673 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 674 | private boolean shouldShowList() { |
| 675 | return mProviderStatus != null |
| 676 | && ((mProviderStatus.equals(ProviderStatus.STATUS_EMPTY) && hasNonLocalAccount()) |
| 677 | || mProviderStatus.equals(ProviderStatus.STATUS_NORMAL)); |
| 678 | } |
| 679 | |
Wenyi Wang | f128ea8 | 2016-07-25 11:56:40 -0700 | [diff] [blame] | 680 | // Returns true if there are real accounts (not "local" account) in the list of accounts. |
| 681 | private boolean hasNonLocalAccount() { |
| 682 | final List<AccountWithDataSet> allAccounts = |
| 683 | AccountTypeManager.getInstance(this).getAccounts(/* contactWritableOnly */ false); |
| 684 | if (allAccounts == null || allAccounts.size() == 0) { |
| 685 | return false; |
| 686 | } |
| 687 | if (allAccounts.size() > 1) { |
| 688 | return true; |
| 689 | } |
| 690 | return !allAccounts.get(0).isLocalAccount(); |
| 691 | } |
| 692 | |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 693 | private class ContactsUnavailableFragmentListener |
| 694 | implements OnContactsUnavailableActionListener { |
Chiao Cheng | 70f77ea | 2012-05-31 13:33:58 -0700 | [diff] [blame] | 695 | ContactsUnavailableFragmentListener() {} |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 696 | |
| 697 | @Override |
| 698 | public void onCreateNewContactAction() { |
Brian Attwell | c6100ff | 2015-02-19 21:35:36 -0800 | [diff] [blame] | 699 | ImplicitIntentsUtil.startActivityInApp(PeopleActivity.this, |
John Shao | 41c6886 | 2016-08-17 21:02:41 -0700 | [diff] [blame] | 700 | EditorIntents.createCompactInsertContactIntent(PeopleActivity.this)); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | @Override |
| 704 | public void onAddAccountAction() { |
Walter Jang | 5e19c23 | 2016-07-14 12:38:04 -0700 | [diff] [blame] | 705 | final Intent intent = ImplicitIntentsUtil.getIntentForAddingGoogleAccount(); |
Brian Attwell | c6100ff | 2015-02-19 21:35:36 -0800 | [diff] [blame] | 706 | ImplicitIntentsUtil.startActivityOutsideApp(PeopleActivity.this, intent); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | @Override |
| 710 | public void onImportContactsFromFileAction() { |
Wenyi Wang | 9379f4a | 2015-09-25 10:30:19 -0700 | [diff] [blame] | 711 | showImportExportDialogFragment(); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 712 | } |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 713 | } |
| 714 | |
Katherine Kuan | 8268bbe | 2011-06-10 17:48:21 -0700 | [diff] [blame] | 715 | private void invalidateOptionsMenuIfNeeded() { |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 716 | if (mAllFragment != null |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 717 | && mAllFragment.getOptionsMenuContactsAvailable() != areContactsAvailable()) { |
Katherine Kuan | 8268bbe | 2011-06-10 17:48:21 -0700 | [diff] [blame] | 718 | invalidateOptionsMenu(); |
Dmitri Plotnikov | 0cd0130 | 2010-12-17 18:41:57 -0800 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
Wenyi Wang | 9379f4a | 2015-09-25 10:30:19 -0700 | [diff] [blame] | 722 | private void showImportExportDialogFragment(){ |
Wenyi Wang | 46203dc | 2016-04-13 10:24:10 -0700 | [diff] [blame] | 723 | ImportExportDialogFragment.show(getFragmentManager(), areContactsAvailable(), |
| 724 | PeopleActivity.class, ImportExportDialogFragment.EXPORT_MODE_ALL_CONTACTS); |
Wenyi Wang | 9379f4a | 2015-09-25 10:30:19 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 727 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 728 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 729 | // TODO move to the fragment |
Dmitri Plotnikov | db3d143 | 2010-02-09 17:45:47 -0800 | [diff] [blame] | 730 | |
Brian Attwell | 20510ec | 2015-02-27 16:10:45 -0800 | [diff] [blame] | 731 | // Bring up the search UI if the user starts typing |
| 732 | final int unicodeChar = event.getUnicodeChar(); |
| 733 | if ((unicodeChar != 0) |
| 734 | // If COMBINING_ACCENT is set, it's not a unicode character. |
| 735 | && ((unicodeChar & KeyCharacterMap.COMBINING_ACCENT) == 0) |
| 736 | && !Character.isWhitespace(unicodeChar)) { |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 737 | if (mAllFragment.getActionBarAdapter().isSelectionMode()) { |
Brian Attwell | 20510ec | 2015-02-27 16:10:45 -0800 | [diff] [blame] | 738 | // Ignore keyboard input when in selection mode. |
| 739 | return true; |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 740 | } |
Brian Attwell | 20510ec | 2015-02-27 16:10:45 -0800 | [diff] [blame] | 741 | String query = new String(new int[]{unicodeChar}, 0, 1); |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 742 | if (!mAllFragment.getActionBarAdapter().isSearchMode()) { |
| 743 | mAllFragment.getActionBarAdapter().setSearchMode(true); |
| 744 | mAllFragment.getActionBarAdapter().setQueryString(query); |
Brian Attwell | 20510ec | 2015-02-27 16:10:45 -0800 | [diff] [blame] | 745 | return true; |
Daniel Lehmann | 7bb2add | 2010-07-14 21:15:17 -0700 | [diff] [blame] | 746 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | return super.onKeyDown(keyCode, event); |
| 750 | } |
| 751 | |
Dmitri Plotnikov | ab4d29f | 2010-10-28 12:43:54 -0700 | [diff] [blame] | 752 | @Override |
| 753 | public void onBackPressed() { |
Jay Shrauner | 7712aef | 2015-09-25 14:14:28 -0700 | [diff] [blame] | 754 | if (!isSafeToCommitTransactions()) { |
Jay Shrauner | c3fdc8f | 2015-09-16 10:29:52 -0700 | [diff] [blame] | 755 | return; |
| 756 | } |
| 757 | |
Wenyi Wang | bb22924 | 2016-05-25 16:04:13 -0700 | [diff] [blame] | 758 | if (mDrawer.isDrawerOpen(GravityCompat.START)) { |
| 759 | mDrawer.closeDrawer(GravityCompat.START); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 760 | } else if (isGroupView()) { |
| 761 | if (mMembersFragment.isEditMode()) { |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 762 | mMembersFragment.exitEditMode(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 763 | } else if (mMembersFragment.getActionBarAdapter().isSelectionMode()) { |
| 764 | mMembersFragment.getActionBarAdapter().setSelectionMode(false); |
| 765 | mMembersFragment.displayCheckBoxes(false); |
| 766 | } else if (mMembersFragment.getActionBarAdapter().isSearchMode()) { |
| 767 | mMembersFragment.getActionBarAdapter().setSearchMode(false); |
| 768 | } else { |
| 769 | switchToAllContacts(); |
| 770 | } |
| 771 | } else if (isDuplicatesView()) { |
| 772 | switchToAllContacts(); |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 773 | } else if (mAllFragment.getActionBarAdapter().isSelectionMode()) { |
| 774 | mAllFragment.getActionBarAdapter().setSelectionMode(false); |
Brian Attwell | 20510ec | 2015-02-27 16:10:45 -0800 | [diff] [blame] | 775 | mAllFragment.displayCheckBoxes(false); |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 776 | } else if (mAllFragment.getActionBarAdapter().isSearchMode()) { |
| 777 | mAllFragment.getActionBarAdapter().setSearchMode(false); |
Walter Jang | a84fe61 | 2016-01-13 16:49:04 -0800 | [diff] [blame] | 778 | if (mAllFragment.wasSearchResultClicked()) { |
| 779 | mAllFragment.resetSearchResultClicked(); |
| 780 | } else { |
Walter Jang | 62a2074 | 2016-02-24 17:04:12 -0800 | [diff] [blame] | 781 | Logger.logScreenView(this, ScreenType.SEARCH_EXIT); |
Walter Jang | 82c9033 | 2016-02-24 17:34:34 -0800 | [diff] [blame] | 782 | Logger.logSearchEvent(mAllFragment.createSearchState()); |
Walter Jang | a84fe61 | 2016-01-13 16:49:04 -0800 | [diff] [blame] | 783 | } |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 784 | } else if (!AccountFilterUtil.isAllContactsFilter(mAllFragment.getFilter()) |
| 785 | && !mAllFragment.isHidden()) { |
| 786 | // If mAllFragment is hidden, then mContactsUnavailableFragment is visible so we |
| 787 | // don't need to switch to all contacts. |
Wenyi Wang | 40e7910 | 2016-06-01 20:43:56 -0700 | [diff] [blame] | 788 | switchToAllContacts(); |
Dmitri Plotnikov | ab4d29f | 2010-10-28 12:43:54 -0700 | [diff] [blame] | 789 | } else { |
| 790 | super.onBackPressed(); |
| 791 | } |
| 792 | } |
| 793 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 794 | @Override |
| 795 | protected void onSaveInstanceState(Bundle outState) { |
| 796 | super.onSaveInstanceState(outState); |
| 797 | outState.putParcelable(KEY_GROUP_URI, mGroupUri); |
Tingting Wang | 2dc340c | 2016-07-05 22:31:58 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Wenyi Wang | bb22924 | 2016-05-25 16:04:13 -0700 | [diff] [blame] | 800 | @Override |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 801 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 802 | super.onRestoreInstanceState(savedInstanceState); |
| 803 | mGroupUri = savedInstanceState.getParcelable(KEY_GROUP_URI); |
Tingting Wang | 1243cb4 | 2016-08-05 16:42:21 -0700 | [diff] [blame] | 804 | } |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 805 | |
| 806 | private void onGroupDeleted(Intent intent) { |
Marcus Hagerott | 3c1153f | 2016-09-07 09:15:14 -0700 | [diff] [blame] | 807 | if (!ContactSaveService.canUndo(intent)) return; |
| 808 | |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 809 | Snackbar.make(mLayoutRoot, getString(R.string.groupDeletedToast), Snackbar.LENGTH_LONG) |
| 810 | .setAction(R.string.undo, new View.OnClickListener() { |
| 811 | @Override |
| 812 | public void onClick(View v) { |
| 813 | ContactSaveService.startService(PeopleActivity.this, |
| 814 | ContactSaveService.createUndoIntent(PeopleActivity.this, intent)); |
| 815 | } |
| 816 | }).show(); |
| 817 | } |
| 818 | |
| 819 | |
| 820 | private class SaveServiceListener extends BroadcastReceiver { |
| 821 | @Override |
| 822 | public void onReceive(Context context, Intent intent) { |
| 823 | switch (intent.getAction()) { |
| 824 | case ContactSaveService.BROADCAST_ACTION_GROUP_DELETED: |
| 825 | onGroupDeleted(intent); |
| 826 | break; |
| 827 | } |
| 828 | } |
| 829 | } |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 830 | |
| 831 | @Override |
| 832 | protected void onGroupMenuItemClicked(long groupId, String title) { |
| 833 | if (isGroupView() && mMembersFragment != null |
| 834 | && mMembersFragment.isCurrentGroup(groupId)) { |
| 835 | return; |
| 836 | } |
| 837 | mGroupUri = ContentUris.withAppendedId(ContactsContract.Groups.CONTENT_URI, groupId); |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 838 | switchToOrUpdateGroupView(GroupUtil.ACTION_SWITCH_GROUP); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | @Override |
| 842 | protected void onFilterMenuItemClicked(Intent intent) { |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 843 | // We must pop second level first to "restart" mAllFragment, before changing filter. |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 844 | if (isInSecondLevel()) { |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 845 | popSecondLevel(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 846 | showFabWithAnimation(/* showFab */ true); |
| 847 | } |
| 848 | mCurrentView = ContactsView.ACCOUNT_VIEW; |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 849 | super.onFilterMenuItemClicked(intent); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 852 | private void switchToOrUpdateGroupView(String action) { |
| 853 | if (mMembersFragment != null) { |
| 854 | mCurrentView = ContactsView.GROUP_VIEW; |
| 855 | mMembersFragment.updateDisplayedGroup(mGroupUri, action); |
| 856 | } else { |
| 857 | switchView(ContactsView.GROUP_VIEW); |
| 858 | } |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | @Override |
| 862 | protected void launchFindDuplicates() { |
| 863 | switchView(ContactsView.DUPLICATES); |
| 864 | } |
| 865 | |
| 866 | private void switchView(ContactsView contactsView) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 867 | mCurrentView = contactsView; |
| 868 | setUpNewFragment(); |
| 869 | } |
| 870 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 871 | private void setUpNewFragment() { |
| 872 | final FragmentManager fragmentManager = getFragmentManager(); |
| 873 | final FragmentTransaction transaction = fragmentManager.beginTransaction(); |
| 874 | if (isGroupView()) { |
| 875 | mMembersFragment = GroupMembersFragment.newInstance(mGroupUri); |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 876 | transaction.replace( |
| 877 | R.id.contacts_list_container, mMembersFragment, TAG_GROUP_VIEW); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 878 | } else if (isDuplicatesView()) { |
| 879 | final Fragment duplicatesFragment = ObjectFactory.getDuplicatesFragment(); |
| 880 | final Fragment duplicatesUtilFragment = ObjectFactory.getDuplicatesUtilFragment(); |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 881 | if (duplicatesFragment != null && duplicatesUtilFragment != null) { |
| 882 | duplicatesUtilFragment.setTargetFragment(duplicatesFragment, /* requestCode */ 0); |
| 883 | transaction.replace( |
| 884 | R.id.contacts_list_container, duplicatesFragment, TAG_DUPLICATES); |
| 885 | transaction.add(duplicatesUtilFragment, TAG_DUPLICATES_UTIL); |
| 886 | } |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 887 | } |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 888 | transaction.addToBackStack(TAG_SECOND_LEVEL); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 889 | transaction.commit(); |
| 890 | fragmentManager.executePendingTransactions(); |
| 891 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 892 | resetFilter(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 893 | showFabWithAnimation(/* showFab */ false); |
| 894 | } |
| 895 | |
| 896 | @Override |
| 897 | public void switchToAllContacts() { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 898 | if (isInSecondLevel()) { |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 899 | popSecondLevel(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 900 | } |
| 901 | mCurrentView = ContactsView.ALL_CONTACTS; |
| 902 | showFabWithAnimation(/* showFab */ true); |
| 903 | |
| 904 | super.switchToAllContacts(); |
| 905 | } |
| 906 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 907 | private void popSecondLevel() { |
| 908 | getFragmentManager().popBackStackImmediate( |
| 909 | TAG_SECOND_LEVEL, FragmentManager.POP_BACK_STACK_INCLUSIVE); |
| 910 | mMembersFragment = null; |
| 911 | } |
| 912 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 913 | @Override |
| 914 | protected DefaultContactBrowseListFragment getAllFragment() { |
| 915 | return mAllFragment; |
| 916 | } |
| 917 | |
| 918 | @Override |
| 919 | protected GroupMembersFragment getGroupFragment() { |
| 920 | return mMembersFragment; |
| 921 | } |
| 922 | |
| 923 | @Override |
Walter Jang | 5a49696 | 2016-09-09 18:32:50 -0700 | [diff] [blame^] | 924 | protected GroupMetaData getGroupMetaData() { |
| 925 | return mMembersFragment == null ? null : mMembersFragment.getGroupMetaData(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 926 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 927 | } |