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 | 917cb4a | 2016-12-13 17:42:18 -0800 | [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; |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
John Shao | 52dd5d7 | 2016-10-06 15:16:14 -0700 | [diff] [blame] | 24 | import android.content.ContentResolver; |
Marcus Hagerott | d6d5ad5 | 2016-10-25 19:25:38 -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; |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 28 | import android.content.IntentFilter; |
John Shao | 52dd5d7 | 2016-10-06 15:16:14 -0700 | [diff] [blame] | 29 | import android.content.SyncStatusObserver; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 30 | import android.content.res.Configuration; |
| 31 | import android.graphics.Color; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 32 | import android.net.Uri; |
| 33 | import android.os.Bundle; |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 34 | import android.os.Handler; |
Marcus Hagerott | d6d5ad5 | 2016-10-25 19:25:38 -0700 | [diff] [blame] | 35 | import android.provider.ContactsContract; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 36 | import android.provider.ContactsContract.Intents; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 37 | import android.provider.ContactsContract.ProviderStatus; |
Aravind Sreekumar | 7121285 | 2018-04-06 15:47:45 -0700 | [diff] [blame] | 38 | import androidx.annotation.LayoutRes; |
| 39 | import androidx.coordinatorlayout.widget.CoordinatorLayout; |
Aurimas Liutikas | 1f8811c | 2019-01-30 21:39:48 -0800 | [diff] [blame] | 40 | import com.google.android.material.snackbar.Snackbar; |
Aravind Sreekumar | 7121285 | 2018-04-06 15:47:45 -0700 | [diff] [blame] | 41 | import androidx.core.content.ContextCompat; |
| 42 | import androidx.localbroadcastmanager.content.LocalBroadcastManager; |
| 43 | import androidx.core.view.GravityCompat; |
| 44 | import androidx.drawerlayout.widget.DrawerLayout; |
| 45 | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| 46 | import androidx.appcompat.app.ActionBarDrawerToggle; |
| 47 | import androidx.appcompat.app.AppCompatActivity; |
| 48 | import androidx.appcompat.widget.Toolbar; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 49 | import android.util.Log; |
| 50 | import android.view.KeyCharacterMap; |
| 51 | import android.view.KeyEvent; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 52 | import android.view.LayoutInflater; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 53 | import android.view.View; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 54 | import android.view.ViewGroup; |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 55 | import android.view.accessibility.AccessibilityEvent; |
James Laskey | 6b712bc | 2016-11-22 11:02:09 -0800 | [diff] [blame] | 56 | import android.view.accessibility.AccessibilityManager; |
Paul Soulos | 2b9563d | 2014-05-27 16:21:23 -0700 | [diff] [blame] | 57 | import android.widget.ImageButton; |
Jay Shrauner | d391f84 | 2014-11-26 11:14:24 -0800 | [diff] [blame] | 58 | import android.widget.Toast; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 59 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 60 | import com.android.contacts.AppCompatContactsActivity; |
Cody Thomas | f32dc99 | 2016-05-11 10:56:04 -0700 | [diff] [blame] | 61 | import com.android.contacts.ContactSaveService; |
Dmitri Plotnikov | 27834b2 | 2010-07-01 14:10:08 -0700 | [diff] [blame] | 62 | import com.android.contacts.R; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 63 | import com.android.contacts.compat.CompatUtils; |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 64 | import com.android.contacts.drawer.DrawerFragment; |
| 65 | import com.android.contacts.drawer.DrawerFragment.DrawerFragmentListener; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 66 | import com.android.contacts.editor.ContactEditorFragment; |
| 67 | import com.android.contacts.editor.SelectAccountDialogFragment; |
| 68 | import com.android.contacts.group.GroupListItem; |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 69 | import com.android.contacts.group.GroupMembersFragment; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 70 | import com.android.contacts.group.GroupNameEditDialogFragment; |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 71 | import com.android.contacts.group.GroupUtil; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 72 | import com.android.contacts.list.AccountFilterActivity; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 73 | import com.android.contacts.list.ContactListFilter; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 74 | import com.android.contacts.list.ContactListFilterController; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 75 | import com.android.contacts.list.ContactListFilterController.ContactListFilterListener; |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 76 | import com.android.contacts.list.ContactsIntentResolver; |
| 77 | import com.android.contacts.list.ContactsRequest; |
| 78 | import com.android.contacts.list.ContactsUnavailableFragment; |
| 79 | import com.android.contacts.list.DefaultContactBrowseListFragment; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 80 | import com.android.contacts.list.MultiSelectContactsListFragment; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 81 | import com.android.contacts.list.ProviderStatusWatcher; |
| 82 | import com.android.contacts.list.ProviderStatusWatcher.ProviderStatusListener; |
| 83 | import com.android.contacts.logging.Logger; |
| 84 | import com.android.contacts.logging.ScreenEvent.ScreenType; |
| 85 | import com.android.contacts.model.AccountTypeManager; |
Marcus Hagerott | 75895e7 | 2016-12-12 17:21:57 -0800 | [diff] [blame] | 86 | import com.android.contacts.model.account.AccountInfo; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 87 | import com.android.contacts.model.account.AccountWithDataSet; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 88 | import com.android.contacts.preference.ContactsPreferenceActivity; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 89 | import com.android.contacts.util.AccountFilterUtil; |
| 90 | import com.android.contacts.util.Constants; |
| 91 | import com.android.contacts.util.ImplicitIntentsUtil; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 92 | import com.android.contacts.util.MaterialColorMapUtils; |
| 93 | import com.android.contacts.util.SharedPreferenceUtil; |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 94 | import com.android.contacts.util.SyncUtil; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 95 | import com.android.contacts.util.ViewUtil; |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 96 | import com.android.contacts.widget.FloatingActionButtonController; |
Wenyi Wang | f990506 | 2016-09-14 10:07:59 -0700 | [diff] [blame] | 97 | import com.android.contactsbind.FeatureHighlightHelper; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 98 | import com.android.contactsbind.HelpUtils; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 99 | import com.android.contactsbind.ObjectFactory; |
Gary Mai | f6b50e8 | 2017-01-26 15:32:49 -0800 | [diff] [blame] | 100 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 101 | import com.google.common.util.concurrent.Futures; |
Tadashi G. Takaoka | 57cf30f | 2009-09-21 19:54:39 +0900 | [diff] [blame] | 102 | |
Marcus Hagerott | 396aab7 | 2016-12-12 12:00:21 -0800 | [diff] [blame] | 103 | import java.util.Collections; |
Brian Attwell | 20510ec | 2015-02-27 16:10:45 -0800 | [diff] [blame] | 104 | import java.util.List; |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 105 | import java.util.concurrent.atomic.AtomicInteger; |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 106 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 107 | /** |
Brian Attwell | 2c1bfd0 | 2014-06-04 18:18:35 -0700 | [diff] [blame] | 108 | * Displays a list to browse contacts. |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 109 | */ |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 110 | public class PeopleActivity extends AppCompatContactsActivity implements |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 111 | DrawerFragmentListener, |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 112 | SelectAccountDialogFragment.Listener { |
| 113 | |
| 114 | /** Possible views of Contacts app. */ |
| 115 | public enum ContactsView { |
| 116 | NONE, |
| 117 | ALL_CONTACTS, |
| 118 | ASSISTANT, |
| 119 | GROUP_VIEW, |
| 120 | ACCOUNT_VIEW, |
| 121 | } |
Dmitri Plotnikov | 57d27da | 2009-09-28 18:06:11 -0700 | [diff] [blame] | 122 | |
Dave Santoro | 5e684a4 | 2011-06-10 13:23:35 -0700 | [diff] [blame] | 123 | private static final String TAG = "PeopleActivity"; |
Wenyi Wang | ca6018d | 2016-08-18 17:23:13 -0700 | [diff] [blame] | 124 | private static final String TAG_ALL = "contacts-all"; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 125 | private static final String TAG_UNAVAILABLE = "contacts-unavailable"; |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 126 | private static final String TAG_GROUP_VIEW = "contacts-groups"; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 127 | private static final String TAG_SELECT_ACCOUNT_DIALOG = "selectAccountDialog"; |
| 128 | private static final String TAG_GROUP_NAME_EDIT_DIALOG = "groupNameEditDialog"; |
| 129 | |
John Shao | 52dd5d7 | 2016-10-06 15:16:14 -0700 | [diff] [blame] | 130 | public static final String TAG_ASSISTANT = "contacts-assistant"; |
| 131 | public static final String TAG_SECOND_LEVEL = "second-level"; |
| 132 | public static final String TAG_THIRD_LEVEL = "third-level"; |
Gary Mai | f6b50e8 | 2017-01-26 15:32:49 -0800 | [diff] [blame] | 133 | public static final String TAG_ASSISTANT_HELPER = "assistant-helper"; |
John Shao | 52dd5d7 | 2016-10-06 15:16:14 -0700 | [diff] [blame] | 134 | public static final String TAG_DUPLICATES = "DuplicatesFragment"; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 135 | public static final String TAG_DUPLICATES_UTIL = "DuplicatesUtilFragment"; |
| 136 | |
| 137 | private static final String KEY_GROUP_URI = "groupUri"; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 138 | private static final String KEY_CONTACTS_VIEW = "contactsView"; |
| 139 | private static final String KEY_NEW_GROUP_ACCOUNT = "newGroupAccount"; |
| 140 | |
| 141 | private static final long DRAWER_CLOSE_DELAY = 300L; |
Wenyi Wang | ca6018d | 2016-08-18 17:23:13 -0700 | [diff] [blame] | 142 | |
Dmitri Plotnikov | ac0f783 | 2010-04-22 13:26:52 -0700 | [diff] [blame] | 143 | private ContactsIntentResolver mIntentResolver; |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 144 | private ContactsRequest mRequest; |
Marcus Hagerott | 396aab7 | 2016-12-12 12:00:21 -0800 | [diff] [blame] | 145 | private AccountTypeManager mAccountTypeManager; |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 146 | |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 147 | private FloatingActionButtonController mFloatingActionButtonController; |
| 148 | private View mFloatingActionButtonContainer; |
| 149 | private boolean wasLastFabAnimationScaleIn = false; |
Dmitri Plotnikov | fcfdffb | 2010-07-15 18:00:55 -0700 | [diff] [blame] | 150 | |
Makoto Onuki | c2bd613 | 2012-04-27 16:14:51 -0700 | [diff] [blame] | 151 | private ProviderStatusWatcher mProviderStatusWatcher; |
Brian Attwell | c3d202c | 2015-01-08 15:01:03 -0800 | [diff] [blame] | 152 | private Integer mProviderStatus; |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 153 | |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 154 | private BroadcastReceiver mSaveServiceListener; |
| 155 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 156 | private boolean mShouldSwitchToGroupView; |
| 157 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 158 | private ContactsView mCurrentView; |
| 159 | |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 160 | private CoordinatorLayout mLayoutRoot; |
| 161 | |
Daisuke Miyakawa | 95c5c2a | 2011-07-08 10:33:21 -0700 | [diff] [blame] | 162 | /** |
| 163 | * Showing a list of Contacts. Also used for showing search results in search mode. |
| 164 | */ |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 165 | private DefaultContactBrowseListFragment mContactsListFragment; |
Katherine Kuan | b5760b9 | 2011-06-01 16:19:40 -0700 | [diff] [blame] | 166 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 167 | private GroupMembersFragment mMembersFragment; |
| 168 | private Uri mGroupUri; |
Katherine Kuan | 58fc577 | 2011-07-04 10:08:32 -0700 | [diff] [blame] | 169 | |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 170 | /** |
| 171 | * True if this activity instance is a re-created one. i.e. set true after orientation change. |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 172 | */ |
| 173 | private boolean mIsRecreatedInstance; |
| 174 | |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 175 | private boolean mShouldSwitchToAllContacts; |
| 176 | |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 177 | /** Sequential ID assigned to each instance; used for logging */ |
| 178 | private final int mInstanceId; |
| 179 | private static final AtomicInteger sNextInstanceId = new AtomicInteger(); |
| 180 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 181 | private ContactListFilterController mContactListFilterController; |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 182 | |
| 183 | /** Navigation drawer related */ |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 184 | private DrawerLayout mDrawerLayout; |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 185 | private DrawerFragment mDrawerFragment; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 186 | private ContactsActionBarDrawerToggle mToggle; |
| 187 | private Toolbar mToolbar; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 188 | |
| 189 | // The account the new group will be created under. |
| 190 | private AccountWithDataSet mNewGroupAccount; |
| 191 | |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 192 | private Object mStatusChangeListenerHandle; |
| 193 | |
| 194 | private final Handler mHandler = new Handler(); |
| 195 | |
| 196 | private SyncStatusObserver mSyncStatusObserver = new SyncStatusObserver() { |
| 197 | public void onStatusChanged(int which) { |
| 198 | mHandler.post(new Runnable() { |
| 199 | public void run() { |
| 200 | onSyncStateUpdated(); |
| 201 | } |
| 202 | }); |
| 203 | } |
| 204 | }; |
| 205 | |
| 206 | // Update sync status for accounts in current ContactListFilter |
| 207 | private void onSyncStateUpdated() { |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 208 | if (isListFragmentInSearchMode() || isListFragmentInSelectionMode()) { |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 209 | return; |
| 210 | } |
| 211 | |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 212 | final ContactListFilter filter = mContactListFilterController.getFilter(); |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 213 | if (filter != null) { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 214 | final SwipeRefreshLayout swipeRefreshLayout = |
| 215 | mContactsListFragment.getSwipeRefreshLayout(); |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 216 | if (swipeRefreshLayout == null) { |
| 217 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 218 | Log.d(TAG, "Can not load swipeRefreshLayout, swipeRefreshLayout is null"); |
| 219 | } |
| 220 | return; |
| 221 | } |
| 222 | |
Marcus Hagerott | 396aab7 | 2016-12-12 12:00:21 -0800 | [diff] [blame] | 223 | final List<AccountWithDataSet> accounts; |
| 224 | if (filter.filterType == ContactListFilter.FILTER_TYPE_ACCOUNT && |
| 225 | filter.isGoogleAccountType()) { |
| 226 | accounts = Collections.singletonList(new AccountWithDataSet(filter.accountName, |
| 227 | filter.accountType, null)); |
| 228 | } else if (filter.shouldShowSyncState()) { |
Marcus Hagerott | 75895e7 | 2016-12-12 17:21:57 -0800 | [diff] [blame] | 229 | accounts = AccountInfo.extractAccounts( |
| 230 | mAccountTypeManager.getWritableGoogleAccounts()); |
Marcus Hagerott | 396aab7 | 2016-12-12 12:00:21 -0800 | [diff] [blame] | 231 | } else { |
| 232 | accounts = Collections.emptyList(); |
| 233 | } |
| 234 | if (SyncUtil.isAnySyncing(accounts)) { |
| 235 | return; |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 236 | } |
| 237 | swipeRefreshLayout.setRefreshing(false); |
| 238 | } |
| 239 | } |
| 240 | |
yaolu | 395c3f8 | 2016-10-18 11:13:39 -0700 | [diff] [blame] | 241 | public void showConnectionErrorMsg() { |
| 242 | Snackbar.make(mLayoutRoot, R.string.connection_error_message, Snackbar.LENGTH_LONG).show(); |
| 243 | } |
| 244 | |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 245 | private final ContactListFilterListener mFilterListener = new ContactListFilterListener() { |
| 246 | @Override |
| 247 | public void onContactListFilterChanged() { |
| 248 | final ContactListFilter filter = mContactListFilterController.getFilter(); |
| 249 | handleFilterChangeForFragment(filter); |
| 250 | handleFilterChangeForActivity(filter); |
| 251 | } |
| 252 | }; |
| 253 | |
| 254 | private final ProviderStatusListener mProviderStatusListener = new ProviderStatusListener() { |
| 255 | @Override |
| 256 | public void onProviderStatusChange() { |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 257 | // TODO see if it works with drawer fragment. |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 258 | updateViewConfiguration(false); |
| 259 | } |
| 260 | }; |
| 261 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 262 | private class ContactsActionBarDrawerToggle extends ActionBarDrawerToggle { |
| 263 | private boolean mMenuClickedBefore = SharedPreferenceUtil.getHamburgerMenuClickedBefore( |
| 264 | PeopleActivity.this); |
| 265 | |
| 266 | public ContactsActionBarDrawerToggle(AppCompatActivity activity, DrawerLayout drawerLayout, |
| 267 | Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes) { |
| 268 | super(activity, drawerLayout, toolbar, openDrawerContentDescRes, |
| 269 | closeDrawerContentDescRes); |
| 270 | } |
| 271 | |
| 272 | @Override |
| 273 | public void onDrawerOpened(View drawerView) { |
| 274 | super.onDrawerOpened(drawerView); |
| 275 | if (!mMenuClickedBefore) { |
| 276 | SharedPreferenceUtil.setHamburgerMenuClickedBefore(PeopleActivity.this); |
| 277 | mMenuClickedBefore = true; |
| 278 | } |
Wenyi Wang | a007a0d | 2017-03-20 10:41:01 -0700 | [diff] [blame] | 279 | drawerView.requestFocus(); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 280 | invalidateOptionsMenu(); |
| 281 | // Stop search and selection mode like Gmail and Keep. Otherwise, if user switches to |
| 282 | // another fragment in navigation drawer, the current search/selection mode will be |
| 283 | // overlaid by the action bar of the newly-created fragment. |
| 284 | stopSearchAndSelection(); |
| 285 | updateStatusBarBackground(); |
| 286 | } |
| 287 | |
| 288 | private void stopSearchAndSelection() { |
| 289 | final MultiSelectContactsListFragment listFragment; |
| 290 | if (isAllContactsView() || isAccountView()) { |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 291 | listFragment = getListFragment(); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 292 | } else if (isGroupView()) { |
| 293 | listFragment = getGroupFragment(); |
| 294 | } else { |
| 295 | listFragment = null; |
| 296 | } |
| 297 | if (listFragment == null) { |
| 298 | return; |
| 299 | } |
| 300 | final ActionBarAdapter actionBarAdapter = listFragment.getActionBarAdapter(); |
| 301 | if (actionBarAdapter == null) { |
| 302 | return; |
| 303 | } |
| 304 | if (actionBarAdapter.isSearchMode()) { |
| 305 | actionBarAdapter.setSearchMode(false); |
| 306 | } else if (actionBarAdapter.isSelectionMode()) { |
| 307 | actionBarAdapter.setSelectionMode(false); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public void onDrawerClosed(View view) { |
| 313 | super.onDrawerClosed(view); |
| 314 | invalidateOptionsMenu(); |
| 315 | } |
| 316 | |
| 317 | @Override |
| 318 | public void onDrawerStateChanged(int newState) { |
| 319 | super.onDrawerStateChanged(newState); |
| 320 | // Set transparent status bar when drawer starts to move. |
| 321 | if (newState != DrawerLayout.STATE_IDLE) { |
| 322 | updateStatusBarBackground(); |
| 323 | } |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
| 327 | |
Katherine Kuan | 9856fce | 2011-06-01 10:24:09 -0700 | [diff] [blame] | 328 | public PeopleActivity() { |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 329 | mInstanceId = sNextInstanceId.getAndIncrement(); |
Dmitri Plotnikov | 1540674 | 2010-05-07 09:22:49 -0700 | [diff] [blame] | 330 | mIntentResolver = new ContactsIntentResolver(this); |
Makoto Onuki | c2bd613 | 2012-04-27 16:14:51 -0700 | [diff] [blame] | 331 | mProviderStatusWatcher = ProviderStatusWatcher.getInstance(this); |
Dmitri Plotnikov | 6178cb4 | 2010-04-20 11:26:05 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 334 | @Override |
| 335 | public String toString() { |
| 336 | // Shown on logcat |
| 337 | return String.format("%s@%d", getClass().getSimpleName(), mInstanceId); |
| 338 | } |
| 339 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 340 | private boolean areContactsAvailable() { |
Wenyi Wang | 2f09e60 | 2015-10-28 11:34:23 -0700 | [diff] [blame] | 341 | return (mProviderStatus != null) && mProviderStatus.equals(ProviderStatus.STATUS_NORMAL); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 342 | } |
| 343 | |
Dmitri Plotnikov | 92a6fdf | 2010-07-09 13:19:33 -0700 | [diff] [blame] | 344 | @Override |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 345 | protected void onCreate(Bundle savedState) { |
Makoto Onuki | 49627cc | 2011-08-28 13:56:48 -0700 | [diff] [blame] | 346 | if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) { |
| 347 | Log.d(Constants.PERFORMANCE_TAG, "PeopleActivity.onCreate start"); |
| 348 | } |
yaolu | f31d697 | 2017-02-20 23:03:00 -0800 | [diff] [blame] | 349 | |
| 350 | // Make sure this is *before* calling super.onCreate |
| 351 | setTheme(R.style.PeopleActivityTheme); |
Dmitri Plotnikov | 08e1c4e | 2010-07-02 17:57:51 -0700 | [diff] [blame] | 352 | super.onCreate(savedState); |
yaolu | f31d697 | 2017-02-20 23:03:00 -0800 | [diff] [blame] | 353 | |
Marcus Hagerott | 396aab7 | 2016-12-12 12:00:21 -0800 | [diff] [blame] | 354 | mAccountTypeManager = AccountTypeManager.getInstance(this); |
Gary Mai | 5a924f3 | 2017-01-18 14:32:59 -0800 | [diff] [blame] | 355 | mContactListFilterController = ContactListFilterController.getInstance(this); |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 356 | |
Gary Mai | 1e899dc | 2017-02-07 15:08:53 -0800 | [diff] [blame] | 357 | RequestPermissionsActivity.startPermissionActivityIfNeeded(this); |
Brian Attwell | bdd3264 | 2015-05-08 17:03:15 -0700 | [diff] [blame] | 358 | |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 359 | if (!processIntent(false)) { |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 360 | finish(); |
| 361 | return; |
| 362 | } |
Daisuke Miyakawa | a012aec | 2011-10-16 10:24:43 -0700 | [diff] [blame] | 363 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 364 | mContactListFilterController.checkFilterValidity(false); |
| 365 | |
| 366 | super.setContentView(R.layout.contacts_drawer_activity); |
| 367 | |
| 368 | // Set up the action bar. |
| 369 | mToolbar = getView(R.id.toolbar); |
| 370 | setSupportActionBar(mToolbar); |
| 371 | |
| 372 | // Add shadow under toolbar. |
| 373 | ViewUtil.addRectangularOutlineProvider(findViewById(R.id.toolbar_parent), getResources()); |
| 374 | |
| 375 | // Set up hamburger button. |
| 376 | mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 377 | mDrawerFragment = (DrawerFragment) getFragmentManager().findFragmentById(R.id.drawer); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 378 | mToggle = new ContactsActionBarDrawerToggle(this, mDrawerLayout, mToolbar, |
| 379 | R.string.navigation_drawer_open, R.string.navigation_drawer_close); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 380 | mDrawerLayout.setDrawerListener(mToggle); |
| 381 | // Set fallback handler for when drawer is disabled. |
| 382 | mToggle.setToolbarNavigationClickListener(new View.OnClickListener() { |
| 383 | @Override |
| 384 | public void onClick(View v) { |
| 385 | onBackPressed(); |
| 386 | } |
| 387 | }); |
| 388 | |
| 389 | // Set up navigation mode. |
| 390 | if (savedState != null) { |
| 391 | mCurrentView = ContactsView.values()[savedState.getInt(KEY_CONTACTS_VIEW)]; |
| 392 | } else { |
| 393 | mCurrentView = ContactsView.ALL_CONTACTS; |
| 394 | } |
| 395 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 396 | if (savedState != null && savedState.containsKey(KEY_NEW_GROUP_ACCOUNT)) { |
| 397 | mNewGroupAccount = AccountWithDataSet.unstringify( |
| 398 | savedState.getString(KEY_NEW_GROUP_ACCOUNT)); |
| 399 | } |
| 400 | |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 401 | mContactListFilterController.addListener(mFilterListener); |
| 402 | mProviderStatusWatcher.addListener(mProviderStatusListener); |
Makoto Onuki | c2bd613 | 2012-04-27 16:14:51 -0700 | [diff] [blame] | 403 | |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 404 | mIsRecreatedInstance = (savedState != null); |
Wenyi Wang | 40e7910 | 2016-06-01 20:43:56 -0700 | [diff] [blame] | 405 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 406 | if (mIsRecreatedInstance) { |
| 407 | mGroupUri = savedState.getParcelable(KEY_GROUP_URI); |
| 408 | } |
| 409 | |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 410 | createViewsAndFragments(); |
Andrew Lee | 4b1af3f | 2014-04-23 10:23:55 -0700 | [diff] [blame] | 411 | |
Makoto Onuki | 49627cc | 2011-08-28 13:56:48 -0700 | [diff] [blame] | 412 | if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) { |
| 413 | Log.d(Constants.PERFORMANCE_TAG, "PeopleActivity.onCreate finish"); |
| 414 | } |
Sai Cheemalapati | 5b22108 | 2014-06-27 14:45:43 -0700 | [diff] [blame] | 415 | getWindow().setBackgroundDrawable(null); |
Tingting Wang | ac9596e | 2016-08-02 22:24:24 -0700 | [diff] [blame] | 416 | } |
Tingting Wang | dce1e68 | 2016-07-28 10:06:29 -0700 | [diff] [blame] | 417 | |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 418 | @Override |
| 419 | protected void onNewIntent(Intent intent) { |
Gary Mai | 4ac5629 | 2016-10-31 10:41:11 -0700 | [diff] [blame] | 420 | final String action = intent.getAction(); |
| 421 | if (GroupUtil.ACTION_CREATE_GROUP.equals(action)) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 422 | mGroupUri = intent.getData(); |
| 423 | if (mGroupUri == null) { |
| 424 | toast(R.string.groupSavedErrorToast); |
| 425 | return; |
| 426 | } |
| 427 | if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "Received group URI " + mGroupUri); |
yaolu | 9b6159c | 2016-10-24 23:31:49 -0700 | [diff] [blame] | 428 | switchView(ContactsView.GROUP_VIEW); |
Gary Mai | 4ac5629 | 2016-10-31 10:41:11 -0700 | [diff] [blame] | 429 | mMembersFragment.toastForSaveAction(action); |
Walter Jang | 13710d5 | 2016-07-08 14:36:20 -0700 | [diff] [blame] | 430 | return; |
| 431 | } |
| 432 | |
Gary Mai | 4ac5629 | 2016-10-31 10:41:11 -0700 | [diff] [blame] | 433 | if (isGroupSaveAction(action)) { |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 434 | mGroupUri = intent.getData(); |
| 435 | if (mGroupUri == null) { |
| 436 | popSecondLevel(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 437 | toast(R.string.groupSavedErrorToast); |
| 438 | return; |
| 439 | } |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 440 | if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "Received group URI " + mGroupUri); |
Gary Mai | 4ac5629 | 2016-10-31 10:41:11 -0700 | [diff] [blame] | 441 | // ACTION_REMOVE_FROM_GROUP doesn't reload data, so it shouldn't cause b/32223934 |
| 442 | // but it's necessary to use the previous fragment since |
| 443 | // GroupMembersFragment#mIsEditMode needs to be persisted between remove actions. |
| 444 | if (GroupUtil.ACTION_REMOVE_FROM_GROUP.equals(action)) { |
| 445 | switchToOrUpdateGroupView(action); |
| 446 | } else { |
| 447 | switchView(ContactsView.GROUP_VIEW); |
| 448 | } |
| 449 | mMembersFragment.toastForSaveAction(action); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 452 | setIntent(intent); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 453 | |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 454 | if (!processIntent(true)) { |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 455 | finish(); |
| 456 | return; |
| 457 | } |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 458 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 459 | mContactListFilterController.checkFilterValidity(false); |
| 460 | |
| 461 | if (!isInSecondLevel()) { |
| 462 | // Re-initialize ActionBarAdapter because {@link #onNewIntent(Intent)} doesn't invoke |
| 463 | // {@link Fragment#onActivityCreated(Bundle)} where we initialize ActionBarAdapter |
| 464 | // initially. |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 465 | mContactsListFragment.setParameters(/* ContactsRequest */ mRequest, |
| 466 | /* fromOnNewIntent */ true); |
| 467 | mContactsListFragment.initializeActionBarAdapter(null); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 468 | } |
Katherine Kuan | be79b8f | 2011-11-09 20:54:43 -0800 | [diff] [blame] | 469 | |
Brian Attwell | 9cfa24c | 2015-05-04 12:31:37 -0700 | [diff] [blame] | 470 | initializeFabVisibility(); |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 471 | invalidateOptionsMenuIfNeeded(); |
Dmitri Plotnikov | fa49a66 | 2011-01-13 11:04:56 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 474 | private static boolean isGroupSaveAction(String action) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 475 | return GroupUtil.ACTION_UPDATE_GROUP.equals(action) |
| 476 | || GroupUtil.ACTION_ADD_TO_GROUP.equals(action) |
| 477 | || GroupUtil.ACTION_REMOVE_FROM_GROUP.equals(action); |
| 478 | } |
| 479 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 480 | private void toast(int resId) { |
| 481 | if (resId >= 0) { |
| 482 | Toast.makeText(this, resId, Toast.LENGTH_SHORT).show(); |
| 483 | } |
| 484 | } |
| 485 | |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 486 | /** |
| 487 | * Resolve the intent and initialize {@link #mRequest}, and launch another activity if redirect |
| 488 | * is needed. |
| 489 | * |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 490 | * @param forNewIntent set true if it's called from {@link #onNewIntent(Intent)}. |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 491 | * @return {@code true} if {@link PeopleActivity} should continue running. {@code false} |
| 492 | * if it shouldn't, in which case the caller should finish() itself and shouldn't do |
| 493 | * farther initialization. |
| 494 | */ |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 495 | private boolean processIntent(boolean forNewIntent) { |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 496 | // Extract relevant information from the intent |
| 497 | mRequest = mIntentResolver.resolveIntent(getIntent()); |
Makoto Onuki | ea14605 | 2011-07-25 10:34:15 -0700 | [diff] [blame] | 498 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
Makoto Onuki | 6d9befe | 2011-07-17 11:00:12 -0700 | [diff] [blame] | 499 | Log.d(TAG, this + " processIntent: forNewIntent=" + forNewIntent |
| 500 | + " intent=" + getIntent() + " request=" + mRequest); |
| 501 | } |
Dmitri Plotnikov | 1ce1e7c | 2010-05-13 16:41:00 -0700 | [diff] [blame] | 502 | if (!mRequest.isValid()) { |
| 503 | setResult(RESULT_CANCELED); |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 504 | return false; |
Dmitri Plotnikov | 59fb48e | 2010-04-26 17:09:19 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Walter Jang | 1110d67 | 2016-07-25 17:55:12 +0000 | [diff] [blame] | 507 | switch (mRequest.getActionCode()) { |
| 508 | case ContactsRequest.ACTION_VIEW_CONTACT: { |
Walter Jang | 0396cf7 | 2016-09-21 13:23:29 -0700 | [diff] [blame] | 509 | ImplicitIntentsUtil.startQuickContact( |
| 510 | this, mRequest.getContactUri(), ScreenType.UNKNOWN); |
Walter Jang | 1110d67 | 2016-07-25 17:55:12 +0000 | [diff] [blame] | 511 | return false; |
| 512 | } |
| 513 | case ContactsRequest.ACTION_INSERT_GROUP: { |
| 514 | onCreateGroupMenuItemClicked(); |
| 515 | return true; |
| 516 | } |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 517 | case ContactsRequest.ACTION_VIEW_GROUP: |
| 518 | case ContactsRequest.ACTION_EDIT_GROUP: { |
| 519 | mShouldSwitchToGroupView = true; |
| 520 | return true; |
| 521 | } |
Dmitri Plotnikov | 27b97bc | 2010-10-07 18:06:09 -0700 | [diff] [blame] | 522 | } |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 523 | return true; |
| 524 | } |
| 525 | |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 526 | private void createViewsAndFragments() { |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 527 | setContentView(R.layout.people_activity); |
| 528 | |
| 529 | final FragmentManager fragmentManager = getFragmentManager(); |
| 530 | |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 531 | setUpListFragment(fragmentManager); |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 532 | |
Wenyi Wang | 17fe798 | 2016-10-05 13:54:09 -0700 | [diff] [blame] | 533 | mMembersFragment = (GroupMembersFragment) fragmentManager.findFragmentByTag(TAG_GROUP_VIEW); |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 534 | |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 535 | // Configure floating action button |
| 536 | mFloatingActionButtonContainer = findViewById(R.id.floating_action_button_container); |
| 537 | final ImageButton floatingActionButton |
| 538 | = (ImageButton) findViewById(R.id.floating_action_button); |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 539 | floatingActionButton.setOnClickListener(new View.OnClickListener() { |
| 540 | @Override |
| 541 | public void onClick(View v) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 542 | AccountFilterUtil.startEditorIntent(PeopleActivity.this, getIntent(), |
| 543 | mContactListFilterController.getFilter()); |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 544 | } |
| 545 | }); |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 546 | mFloatingActionButtonController = new FloatingActionButtonController(this, |
| 547 | mFloatingActionButtonContainer, floatingActionButton); |
Paul Soulos | 2b9563d | 2014-05-27 16:21:23 -0700 | [diff] [blame] | 548 | |
Makoto Onuki | 417ca49 | 2011-07-14 19:06:35 -0700 | [diff] [blame] | 549 | invalidateOptionsMenuIfNeeded(); |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 550 | |
| 551 | mLayoutRoot = (CoordinatorLayout) findViewById(R.id.root); |
| 552 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 553 | if (mShouldSwitchToGroupView && !mIsRecreatedInstance) { |
| 554 | mGroupUri = mRequest.getContactUri(); |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 555 | switchToOrUpdateGroupView(GroupUtil.ACTION_SWITCH_GROUP); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 556 | mShouldSwitchToGroupView = false; |
| 557 | } |
| 558 | } |
| 559 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 560 | @Override |
| 561 | public void setContentView(@LayoutRes int layoutResID) { |
| 562 | final ViewGroup parent = (ViewGroup) findViewById(R.id.content_frame); |
| 563 | if (parent != null) { |
| 564 | parent.removeAllViews(); |
| 565 | } |
| 566 | LayoutInflater.from(this).inflate(layoutResID, parent); |
| 567 | } |
| 568 | |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 569 | private void setUpListFragment(FragmentManager fragmentManager) { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 570 | mContactsListFragment = (DefaultContactBrowseListFragment) |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 571 | fragmentManager.findFragmentByTag(TAG_ALL); |
| 572 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 573 | if (mContactsListFragment == null) { |
| 574 | mContactsListFragment = new DefaultContactBrowseListFragment(); |
| 575 | mContactsListFragment.setAnimateOnLoad(true); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 576 | fragmentManager.beginTransaction() |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 577 | .add(R.id.contacts_list_container, mContactsListFragment, TAG_ALL) |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 578 | .commit(); |
| 579 | fragmentManager.executePendingTransactions(); |
| 580 | } |
| 581 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 582 | mContactsListFragment.setContactsAvailable(areContactsAvailable()); |
| 583 | mContactsListFragment.setListType(mContactListFilterController.getFilterListType()); |
| 584 | mContactsListFragment.setParameters(/* ContactsRequest */ mRequest, |
| 585 | /* fromOnNewIntent */ false); |
Dmitri Plotnikov | caf0bc7 | 2010-09-03 15:16:21 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Dmitri Plotnikov | 6e850a0 | 2010-10-28 10:46:21 -0700 | [diff] [blame] | 588 | @Override |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame] | 589 | protected void onPause() { |
Makoto Onuki | c2bd613 | 2012-04-27 16:14:51 -0700 | [diff] [blame] | 590 | mProviderStatusWatcher.stop(); |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 591 | |
| 592 | LocalBroadcastManager.getInstance(this).unregisterReceiver(mSaveServiceListener); |
| 593 | |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame] | 594 | super.onPause(); |
Xi Chen | 4a7a9ea | 2016-07-20 11:23:30 -0700 | [diff] [blame] | 595 | |
Walter Jang | 9adc9ef | 2016-11-02 18:50:38 -0700 | [diff] [blame] | 596 | ContentResolver.removeStatusChangeListener(mStatusChangeListenerHandle); |
| 597 | onSyncStateUpdated(); |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | @Override |
Sean Midford | fc4f692 | 2016-10-20 13:55:58 -0700 | [diff] [blame] | 601 | public void onMultiWindowModeChanged(boolean entering) { |
| 602 | initializeHomeVisibility(); |
| 603 | } |
| 604 | |
| 605 | @Override |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame] | 606 | protected void onResume() { |
| 607 | super.onResume(); |
Josh Gargus | 697ab26 | 2012-05-04 11:11:34 -0700 | [diff] [blame] | 608 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 609 | if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { |
| 610 | updateStatusBarBackground(); |
| 611 | } |
| 612 | |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 613 | if (mShouldSwitchToAllContacts) { |
| 614 | switchToAllContacts(); |
| 615 | } |
| 616 | |
Makoto Onuki | c2bd613 | 2012-04-27 16:14:51 -0700 | [diff] [blame] | 617 | mProviderStatusWatcher.start(); |
Josh Gargus | 697ab26 | 2012-05-04 11:11:34 -0700 | [diff] [blame] | 618 | updateViewConfiguration(true); |
Makoto Onuki | 4d788fc | 2011-07-12 10:00:10 -0700 | [diff] [blame] | 619 | |
Walter Jang | 9adc9ef | 2016-11-02 18:50:38 -0700 | [diff] [blame] | 620 | mStatusChangeListenerHandle = ContentResolver.addStatusChangeListener( |
| 621 | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE |
| 622 | | ContentResolver.SYNC_OBSERVER_TYPE_PENDING |
| 623 | | ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, |
| 624 | mSyncStatusObserver); |
| 625 | onSyncStateUpdated(); |
| 626 | |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 627 | initializeFabVisibility(); |
Sean Midford | fc4f692 | 2016-10-20 13:55:58 -0700 | [diff] [blame] | 628 | initializeHomeVisibility(); |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 629 | |
| 630 | mSaveServiceListener = new SaveServiceListener(); |
| 631 | LocalBroadcastManager.getInstance(this).registerReceiver(mSaveServiceListener, |
Marcus Hagerott | 819214d | 2016-09-29 14:58:27 -0700 | [diff] [blame] | 632 | new IntentFilter(ContactSaveService.BROADCAST_GROUP_DELETED)); |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 635 | public void updateStatusBarBackground() { |
| 636 | updateStatusBarBackground(/* color */ -1); |
| 637 | } |
| 638 | |
| 639 | public void updateStatusBarBackground(int color) { |
| 640 | if (!CompatUtils.isLollipopCompatible()) return; |
| 641 | if (color == -1) { |
| 642 | mDrawerLayout.setStatusBarBackgroundColor( |
| 643 | MaterialColorMapUtils.getStatusBarColor(this)); |
| 644 | } else { |
| 645 | mDrawerLayout.setStatusBarBackgroundColor(color); |
| 646 | } |
| 647 | mDrawerLayout.invalidate(); |
| 648 | getWindow().setStatusBarColor(Color.TRANSPARENT); |
| 649 | } |
| 650 | |
Dmitri Plotnikov | 174fdc2 | 2010-10-29 13:55:01 -0700 | [diff] [blame] | 651 | @Override |
Makoto Onuki | 4d788fc | 2011-07-12 10:00:10 -0700 | [diff] [blame] | 652 | protected void onDestroy() { |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 653 | mProviderStatusWatcher.removeListener(mProviderStatusListener); |
| 654 | mContactListFilterController.removeListener(mFilterListener); |
Makoto Onuki | 4d788fc | 2011-07-12 10:00:10 -0700 | [diff] [blame] | 655 | super.onDestroy(); |
| 656 | } |
| 657 | |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 658 | private void initializeFabVisibility() { |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 659 | mFloatingActionButtonContainer.setVisibility(shouldHideFab() ? View.GONE : View.VISIBLE); |
Brian Attwell | 9cfa24c | 2015-05-04 12:31:37 -0700 | [diff] [blame] | 660 | mFloatingActionButtonController.resetIn(); |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 661 | wasLastFabAnimationScaleIn = !shouldHideFab(); |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Sean Midford | fc4f692 | 2016-10-20 13:55:58 -0700 | [diff] [blame] | 664 | private void initializeHomeVisibility() { |
| 665 | // Remove the navigation icon if we return to the fragment in a search or select state |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 666 | if (getToolbar() != null && (isListFragmentInSelectionMode() |
| 667 | || isListFragmentInSearchMode() || isGroupsFragmentInSelectionMode() |
Sean Midford | fc4f692 | 2016-10-20 13:55:58 -0700 | [diff] [blame] | 668 | || isGroupsFragmentInSearchMode())) { |
| 669 | getToolbar().setNavigationIcon(null); |
| 670 | } |
| 671 | } |
| 672 | |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 673 | private boolean shouldHideFab() { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 674 | if (mContactsListFragment != null && mContactsListFragment.getActionBarAdapter() == null |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 675 | || isInSecondLevel()) { |
| 676 | return true; |
| 677 | } |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 678 | return isListFragmentInSearchMode() |
| 679 | || isListFragmentInSelectionMode(); |
Wenyi Wang | bf69330 | 2016-06-14 12:49:03 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Wenyi Wang | 587b8f2 | 2016-08-17 17:40:45 -0700 | [diff] [blame] | 682 | public void showFabWithAnimation(boolean showFab) { |
Brian Attwell | 865847b | 2015-04-20 14:40:17 -0700 | [diff] [blame] | 683 | if (mFloatingActionButtonContainer == null) { |
| 684 | return; |
| 685 | } |
| 686 | if (showFab) { |
| 687 | if (!wasLastFabAnimationScaleIn) { |
| 688 | mFloatingActionButtonContainer.setVisibility(View.VISIBLE); |
| 689 | mFloatingActionButtonController.scaleIn(0); |
| 690 | } |
| 691 | wasLastFabAnimationScaleIn = true; |
| 692 | |
| 693 | } else { |
| 694 | if (wasLastFabAnimationScaleIn) { |
| 695 | mFloatingActionButtonContainer.setVisibility(View.VISIBLE); |
| 696 | mFloatingActionButtonController.scaleOut(); |
| 697 | } |
| 698 | wasLastFabAnimationScaleIn = false; |
| 699 | } |
| 700 | } |
| 701 | |
Josh Gargus | 697ab26 | 2012-05-04 11:11:34 -0700 | [diff] [blame] | 702 | private void updateViewConfiguration(boolean forceUpdate) { |
Brian Attwell | c3d202c | 2015-01-08 15:01:03 -0800 | [diff] [blame] | 703 | int providerStatus = mProviderStatusWatcher.getProviderStatus(); |
Makoto Onuki | d8fa716 | 2012-05-16 13:45:48 -0700 | [diff] [blame] | 704 | if (!forceUpdate && (mProviderStatus != null) |
Brian Attwell | c3d202c | 2015-01-08 15:01:03 -0800 | [diff] [blame] | 705 | && (mProviderStatus.equals(providerStatus))) return; |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 706 | mProviderStatus = providerStatus; |
| 707 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 708 | final FragmentManager fragmentManager= getFragmentManager(); |
| 709 | final FragmentTransaction transaction = fragmentManager.beginTransaction(); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 710 | |
Wenyi Wang | f128ea8 | 2016-07-25 11:56:40 -0700 | [diff] [blame] | 711 | // Change in CP2's provider status may not take effect immediately, see b/30566908. |
| 712 | // So we need to handle the case where provider status is STATUS_EMPTY and there is |
| 713 | // actually at least one real account (not "local" account) on device. |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 714 | if (shouldShowList()) { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 715 | if (mContactsListFragment != null) { |
Marcus Hagerott | 89c5129 | 2016-11-08 15:05:38 -0800 | [diff] [blame] | 716 | final Fragment unavailableFragment = fragmentManager |
| 717 | .findFragmentByTag(TAG_UNAVAILABLE); |
| 718 | if (unavailableFragment != null) { |
| 719 | transaction.remove(unavailableFragment); |
| 720 | } |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 721 | if (mContactsListFragment.isHidden()) { |
| 722 | transaction.show(mContactsListFragment); |
Marcus Hagerott | 89c5129 | 2016-11-08 15:05:38 -0800 | [diff] [blame] | 723 | } |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 724 | mContactsListFragment.setContactsAvailable(areContactsAvailable()); |
| 725 | mContactsListFragment.setEnabled(true); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 726 | } |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 727 | } else { |
guanxiongliu | 5d7bb26 | 2016-01-29 16:43:45 -0800 | [diff] [blame] | 728 | // Setting up the page so that the user can still use the app |
| 729 | // even without an account. |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 730 | if (mContactsListFragment != null) { |
| 731 | mContactsListFragment.setEnabled(false); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 732 | } |
Marcus Hagerott | 89c5129 | 2016-11-08 15:05:38 -0800 | [diff] [blame] | 733 | final ContactsUnavailableFragment fragment = new ContactsUnavailableFragment(); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 734 | transaction.hide(mContactsListFragment); |
Marcus Hagerott | 89c5129 | 2016-11-08 15:05:38 -0800 | [diff] [blame] | 735 | transaction.replace(R.id.contacts_unavailable_container, fragment, TAG_UNAVAILABLE); |
| 736 | fragment.updateStatus(mProviderStatus); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 737 | } |
| 738 | if (!transaction.isEmpty()) { |
yingrenw | aa21e96 | 2018-01-23 15:54:49 +0800 | [diff] [blame] | 739 | transaction.commitAllowingStateLoss(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 740 | fragmentManager.executePendingTransactions(); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 741 | } |
| 742 | |
Katherine Kuan | 8268bbe | 2011-06-10 17:48:21 -0700 | [diff] [blame] | 743 | invalidateOptionsMenuIfNeeded(); |
Dmitri Plotnikov | 8b82646 | 2010-11-17 14:52:24 -0800 | [diff] [blame] | 744 | } |
| 745 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 746 | private boolean shouldShowList() { |
| 747 | return mProviderStatus != null |
Marcus Hagerott | 396aab7 | 2016-12-12 12:00:21 -0800 | [diff] [blame] | 748 | && ((mProviderStatus.equals(ProviderStatus.STATUS_EMPTY) |
| 749 | && mAccountTypeManager.hasNonLocalAccount()) |
| 750 | || mProviderStatus.equals(ProviderStatus.STATUS_NORMAL)); |
Wenyi Wang | f128ea8 | 2016-07-25 11:56:40 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Katherine Kuan | 8268bbe | 2011-06-10 17:48:21 -0700 | [diff] [blame] | 753 | private void invalidateOptionsMenuIfNeeded() { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 754 | if (mContactsListFragment != null |
| 755 | && mContactsListFragment.getOptionsMenuContactsAvailable() |
| 756 | != areContactsAvailable()) { |
Katherine Kuan | 8268bbe | 2011-06-10 17:48:21 -0700 | [diff] [blame] | 757 | invalidateOptionsMenu(); |
Dmitri Plotnikov | 0cd0130 | 2010-12-17 18:41:57 -0800 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
Dmitri Plotnikov | 8e86b75 | 2010-02-22 17:47:57 -0800 | [diff] [blame] | 761 | @Override |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 762 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Wenyi Wang | ff3f119 | 2017-03-22 18:22:32 -0700 | [diff] [blame] | 763 | // If the drawer is open, consume KEYCODE_BACK event only. |
Wenyi Wang | cc5ea44 | 2017-03-20 18:16:58 -0700 | [diff] [blame] | 764 | if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { |
Wenyi Wang | ff3f119 | 2017-03-22 18:22:32 -0700 | [diff] [blame] | 765 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
| 766 | // Should eventually go to onBackPressed(). |
| 767 | return super.onKeyDown(keyCode, event); |
| 768 | } |
Wenyi Wang | cc5ea44 | 2017-03-20 18:16:58 -0700 | [diff] [blame] | 769 | return false; |
| 770 | } |
Brian Attwell | 20510ec | 2015-02-27 16:10:45 -0800 | [diff] [blame] | 771 | // Bring up the search UI if the user starts typing |
| 772 | final int unicodeChar = event.getUnicodeChar(); |
| 773 | if ((unicodeChar != 0) |
| 774 | // If COMBINING_ACCENT is set, it's not a unicode character. |
| 775 | && ((unicodeChar & KeyCharacterMap.COMBINING_ACCENT) == 0) |
| 776 | && !Character.isWhitespace(unicodeChar)) { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 777 | if (mContactsListFragment.onKeyDown(unicodeChar)) { |
Brian Attwell | 20510ec | 2015-02-27 16:10:45 -0800 | [diff] [blame] | 778 | return true; |
Daniel Lehmann | 7bb2add | 2010-07-14 21:15:17 -0700 | [diff] [blame] | 779 | } |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | return super.onKeyDown(keyCode, event); |
| 783 | } |
| 784 | |
Dmitri Plotnikov | ab4d29f | 2010-10-28 12:43:54 -0700 | [diff] [blame] | 785 | @Override |
| 786 | public void onBackPressed() { |
Jay Shrauner | 7712aef | 2015-09-25 14:14:28 -0700 | [diff] [blame] | 787 | if (!isSafeToCommitTransactions()) { |
Jay Shrauner | c3fdc8f | 2015-09-16 10:29:52 -0700 | [diff] [blame] | 788 | return; |
| 789 | } |
| 790 | |
Wenyi Wang | f990506 | 2016-09-14 10:07:59 -0700 | [diff] [blame] | 791 | // Handle the back event in drawer first. |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 792 | if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 793 | closeDrawer(); |
Wenyi Wang | 51819e8 | 2016-09-12 11:57:51 -0700 | [diff] [blame] | 794 | return; |
Wenyi Wang | f990506 | 2016-09-14 10:07:59 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | // Handle the back event in "second level". |
| 798 | if (isGroupView()) { |
| 799 | onBackPressedGroupView(); |
| 800 | return; |
| 801 | } |
| 802 | |
John Shao | 52dd5d7 | 2016-10-06 15:16:14 -0700 | [diff] [blame] | 803 | if (isAssistantView()) { |
| 804 | onBackPressedAssistantView(); |
Wenyi Wang | f990506 | 2016-09-14 10:07:59 -0700 | [diff] [blame] | 805 | return; |
| 806 | } |
| 807 | |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 808 | // If feature highlight is present, let it handle the back event before |
| 809 | // mContactsListFragment. |
Wenyi Wang | f990506 | 2016-09-14 10:07:59 -0700 | [diff] [blame] | 810 | if (FeatureHighlightHelper.tryRemoveHighlight(this)) { |
| 811 | return; |
| 812 | } |
| 813 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 814 | // Handle the back event in "first level" - mContactsListFragment. |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 815 | if (maybeHandleInListFragment()) { |
Wenyi Wang | f990506 | 2016-09-14 10:07:59 -0700 | [diff] [blame] | 816 | return; |
| 817 | } |
| 818 | |
| 819 | super.onBackPressed(); |
| 820 | } |
| 821 | |
| 822 | private void onBackPressedGroupView() { |
| 823 | if (mMembersFragment.isEditMode()) { |
| 824 | mMembersFragment.exitEditMode(); |
| 825 | } else if (mMembersFragment.getActionBarAdapter().isSelectionMode()) { |
| 826 | mMembersFragment.getActionBarAdapter().setSelectionMode(false); |
| 827 | mMembersFragment.displayCheckBoxes(false); |
| 828 | } else if (mMembersFragment.getActionBarAdapter().isSearchMode()) { |
| 829 | mMembersFragment.getActionBarAdapter().setSearchMode(false); |
| 830 | } else { |
| 831 | switchToAllContacts(); |
| 832 | } |
| 833 | } |
| 834 | |
John Shao | 52dd5d7 | 2016-10-06 15:16:14 -0700 | [diff] [blame] | 835 | private void onBackPressedAssistantView() { |
Gary Mai | f6b50e8 | 2017-01-26 15:32:49 -0800 | [diff] [blame] | 836 | if (!isInThirdLevel()) { |
John Shao | 52dd5d7 | 2016-10-06 15:16:14 -0700 | [diff] [blame] | 837 | switchToAllContacts(); |
| 838 | } else { |
| 839 | setDrawerLockMode(/* enabled */ true); |
Gary Mai | f6b50e8 | 2017-01-26 15:32:49 -0800 | [diff] [blame] | 840 | super.onBackPressed(); |
John Shao | 52dd5d7 | 2016-10-06 15:16:14 -0700 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | |
Wenyi Wang | f990506 | 2016-09-14 10:07:59 -0700 | [diff] [blame] | 844 | // Returns true if back event is handled in this method. |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 845 | private boolean maybeHandleInListFragment() { |
| 846 | if (isListFragmentInSelectionMode()) { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 847 | mContactsListFragment.getActionBarAdapter().setSelectionMode(false); |
Wenyi Wang | f990506 | 2016-09-14 10:07:59 -0700 | [diff] [blame] | 848 | return true; |
| 849 | } |
| 850 | |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 851 | if (isListFragmentInSearchMode()) { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 852 | mContactsListFragment.getActionBarAdapter().setSearchMode(false); |
| 853 | if (mContactsListFragment.wasSearchResultClicked()) { |
| 854 | mContactsListFragment.resetSearchResultClicked(); |
Walter Jang | a84fe61 | 2016-01-13 16:49:04 -0800 | [diff] [blame] | 855 | } else { |
Walter Jang | 62a2074 | 2016-02-24 17:04:12 -0800 | [diff] [blame] | 856 | Logger.logScreenView(this, ScreenType.SEARCH_EXIT); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 857 | Logger.logSearchEvent(mContactsListFragment.createSearchState()); |
Walter Jang | a84fe61 | 2016-01-13 16:49:04 -0800 | [diff] [blame] | 858 | } |
Wenyi Wang | f990506 | 2016-09-14 10:07:59 -0700 | [diff] [blame] | 859 | return true; |
| 860 | } |
| 861 | |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 862 | if (!AccountFilterUtil.isAllContactsFilter(mContactListFilterController.getFilter()) |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 863 | && !mContactsListFragment.isHidden()) { |
| 864 | // If mContactsListFragment is hidden, then mContactsUnavailableFragment is visible so we |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 865 | // don't need to switch to all contacts. |
Wenyi Wang | 40e7910 | 2016-06-01 20:43:56 -0700 | [diff] [blame] | 866 | switchToAllContacts(); |
Wenyi Wang | f990506 | 2016-09-14 10:07:59 -0700 | [diff] [blame] | 867 | return true; |
Dmitri Plotnikov | ab4d29f | 2010-10-28 12:43:54 -0700 | [diff] [blame] | 868 | } |
Wenyi Wang | f990506 | 2016-09-14 10:07:59 -0700 | [diff] [blame] | 869 | |
| 870 | return false; |
Dmitri Plotnikov | ab4d29f | 2010-10-28 12:43:54 -0700 | [diff] [blame] | 871 | } |
| 872 | |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 873 | private boolean isListFragmentInSelectionMode() { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 874 | return mContactsListFragment != null && mContactsListFragment.getActionBarAdapter() != null |
| 875 | && mContactsListFragment.getActionBarAdapter().isSelectionMode(); |
Wenyi Wang | ed9f974 | 2016-09-08 13:50:39 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 878 | private boolean isListFragmentInSearchMode() { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 879 | return mContactsListFragment != null && mContactsListFragment.getActionBarAdapter() != null |
| 880 | && mContactsListFragment.getActionBarAdapter().isSearchMode(); |
Wenyi Wang | ed9f974 | 2016-09-08 13:50:39 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Sean Midford | fc4f692 | 2016-10-20 13:55:58 -0700 | [diff] [blame] | 883 | private boolean isGroupsFragmentInSelectionMode() { |
| 884 | return mMembersFragment != null && mMembersFragment.getActionBarAdapter() != null |
| 885 | && mMembersFragment.getActionBarAdapter().isSelectionMode(); |
| 886 | } |
| 887 | |
| 888 | private boolean isGroupsFragmentInSearchMode() { |
| 889 | return mMembersFragment != null && mMembersFragment.getActionBarAdapter() != null |
| 890 | && mMembersFragment.getActionBarAdapter().isSearchMode(); |
| 891 | } |
| 892 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 893 | @Override |
| 894 | protected void onSaveInstanceState(Bundle outState) { |
| 895 | super.onSaveInstanceState(outState); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 896 | if (mNewGroupAccount != null) { |
| 897 | outState.putString(KEY_NEW_GROUP_ACCOUNT, mNewGroupAccount.stringify()); |
| 898 | } |
| 899 | outState.putInt(KEY_CONTACTS_VIEW, mCurrentView.ordinal()); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 900 | outState.putParcelable(KEY_GROUP_URI, mGroupUri); |
Tingting Wang | 2dc340c | 2016-07-05 22:31:58 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Wenyi Wang | bb22924 | 2016-05-25 16:04:13 -0700 | [diff] [blame] | 903 | @Override |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 904 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 905 | super.onRestoreInstanceState(savedInstanceState); |
| 906 | mGroupUri = savedInstanceState.getParcelable(KEY_GROUP_URI); |
Tingting Wang | 1243cb4 | 2016-08-05 16:42:21 -0700 | [diff] [blame] | 907 | } |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 908 | |
Gary Mai | 4ac5629 | 2016-10-31 10:41:11 -0700 | [diff] [blame] | 909 | private void onGroupDeleted(final Intent intent) { |
Marcus Hagerott | 3c1153f | 2016-09-07 09:15:14 -0700 | [diff] [blame] | 910 | if (!ContactSaveService.canUndo(intent)) return; |
| 911 | |
James Laskey | 6b712bc | 2016-11-22 11:02:09 -0800 | [diff] [blame] | 912 | final AccessibilityManager am = |
| 913 | (AccessibilityManager) getSystemService(Context.ACCESSIBILITY_SERVICE); |
James Laskey | 692c961 | 2016-11-30 10:13:01 -0800 | [diff] [blame] | 914 | //TODO set to INDEFINITE and track user interaction to dismiss b/33208886 |
| 915 | final int accessibilityLength = 15000; |
| 916 | final int length = am.isEnabled() ? accessibilityLength : Snackbar.LENGTH_LONG; |
James Laskey | 6b712bc | 2016-11-22 11:02:09 -0800 | [diff] [blame] | 917 | final String message = getString(R.string.groupDeletedToast); |
| 918 | |
| 919 | final Snackbar snackbar = Snackbar.make(mLayoutRoot, message, length) |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 920 | .setAction(R.string.undo, new View.OnClickListener() { |
| 921 | @Override |
| 922 | public void onClick(View v) { |
| 923 | ContactSaveService.startService(PeopleActivity.this, |
| 924 | ContactSaveService.createUndoIntent(PeopleActivity.this, intent)); |
| 925 | } |
James Laskey | 6b712bc | 2016-11-22 11:02:09 -0800 | [diff] [blame] | 926 | }).setActionTextColor(ContextCompat.getColor(this, R.color.snackbar_action_text)); |
| 927 | |
| 928 | // Announce for a11y talkback |
| 929 | mLayoutRoot.announceForAccessibility(message); |
| 930 | mLayoutRoot.announceForAccessibility(getString(R.string.undo)); |
| 931 | |
| 932 | snackbar.show(); |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 933 | } |
| 934 | |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 935 | private class SaveServiceListener extends BroadcastReceiver { |
| 936 | @Override |
| 937 | public void onReceive(Context context, Intent intent) { |
| 938 | switch (intent.getAction()) { |
Marcus Hagerott | 819214d | 2016-09-29 14:58:27 -0700 | [diff] [blame] | 939 | case ContactSaveService.BROADCAST_GROUP_DELETED: |
Marcus Hagerott | bea2b85 | 2016-08-11 14:55:52 -0700 | [diff] [blame] | 940 | onGroupDeleted(intent); |
| 941 | break; |
| 942 | } |
| 943 | } |
| 944 | } |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 945 | |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 946 | private void onGroupMenuItemClicked(long groupId) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 947 | if (isGroupView() && mMembersFragment != null |
Marcus Hagerott | d6d5ad5 | 2016-10-25 19:25:38 -0700 | [diff] [blame] | 948 | && mMembersFragment.isCurrentGroup(groupId)) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 949 | return; |
| 950 | } |
Marcus Hagerott | d6d5ad5 | 2016-10-25 19:25:38 -0700 | [diff] [blame] | 951 | mGroupUri = ContentUris.withAppendedId(ContactsContract.Groups.CONTENT_URI, groupId); |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 952 | switchToOrUpdateGroupView(GroupUtil.ACTION_SWITCH_GROUP); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 955 | private void onFilterMenuItemClicked(Intent intent) { |
| 956 | // We must pop second level first to "restart" mContactsListFragment before changing filter. |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 957 | if (isInSecondLevel()) { |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 958 | popSecondLevel(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 959 | showFabWithAnimation(/* showFab */ true); |
Marcus Hagerott | 45451ea | 2016-10-25 20:05:26 -0700 | [diff] [blame] | 960 | // HACK: swap the current filter to force listeners to update because the group |
| 961 | // member view no longer changes the filter. Fix for b/32223767 |
| 962 | final ContactListFilter current = mContactListFilterController.getFilter(); |
| 963 | mContactListFilterController.setContactListFilter( |
| 964 | AccountFilterUtil.createContactsFilter(this), false); |
| 965 | mContactListFilterController.setContactListFilter(current, false); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 966 | } |
| 967 | mCurrentView = ContactsView.ACCOUNT_VIEW; |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 968 | AccountFilterUtil.handleAccountFilterResult(mContactListFilterController, |
| 969 | AppCompatActivity.RESULT_OK, intent); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 970 | } |
| 971 | |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 972 | private void switchToOrUpdateGroupView(String action) { |
Wenyi Wang | 17fe798 | 2016-10-05 13:54:09 -0700 | [diff] [blame] | 973 | // If group fragment is active and visible, we simply update it. |
| 974 | if (mMembersFragment != null && !mMembersFragment.isInactive()) { |
Wenyi Wang | f660607 | 2016-10-03 17:34:53 -0700 | [diff] [blame] | 975 | mMembersFragment.updateExistingGroupFragment(mGroupUri, action); |
Wenyi Wang | 17fe798 | 2016-10-05 13:54:09 -0700 | [diff] [blame] | 976 | } else { |
| 977 | switchView(ContactsView.GROUP_VIEW); |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 978 | } |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 979 | } |
| 980 | |
John Shao | 52dd5d7 | 2016-10-06 15:16:14 -0700 | [diff] [blame] | 981 | protected void launchAssistant() { |
| 982 | switchView(ContactsView.ASSISTANT); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | private void switchView(ContactsView contactsView) { |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 986 | mCurrentView = contactsView; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 987 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 988 | final FragmentManager fragmentManager = getFragmentManager(); |
| 989 | final FragmentTransaction transaction = fragmentManager.beginTransaction(); |
Gary Mai | f6b50e8 | 2017-01-26 15:32:49 -0800 | [diff] [blame] | 990 | popSecondLevel(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 991 | if (isGroupView()) { |
yaolu | 4c07509 | 2016-10-19 22:23:00 -0700 | [diff] [blame] | 992 | mMembersFragment = GroupMembersFragment.newInstance(mGroupUri); |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 993 | transaction.replace( |
| 994 | R.id.contacts_list_container, mMembersFragment, TAG_GROUP_VIEW); |
Gary Mai | 4ac5629 | 2016-10-31 10:41:11 -0700 | [diff] [blame] | 995 | } else if (isAssistantView()) { |
John Shao | 5b1ffdc | 2016-11-08 13:51:00 -0800 | [diff] [blame] | 996 | Fragment uiFragment = fragmentManager.findFragmentByTag(TAG_ASSISTANT); |
Sean Midford | b96df94 | 2016-11-11 17:54:49 -0800 | [diff] [blame] | 997 | Fragment unavailableFragment = fragmentManager.findFragmentByTag(TAG_UNAVAILABLE); |
John Shao | a3ce3c7 | 2016-10-11 14:58:57 -0700 | [diff] [blame] | 998 | if (uiFragment == null) { |
John Shao | 5b1ffdc | 2016-11-08 13:51:00 -0800 | [diff] [blame] | 999 | uiFragment = ObjectFactory.getAssistantFragment(); |
John Shao | a3ce3c7 | 2016-10-11 14:58:57 -0700 | [diff] [blame] | 1000 | } |
Sean Midford | b96df94 | 2016-11-11 17:54:49 -0800 | [diff] [blame] | 1001 | if (unavailableFragment != null) { |
| 1002 | transaction.remove(unavailableFragment); |
| 1003 | } |
John Shao | 5b1ffdc | 2016-11-08 13:51:00 -0800 | [diff] [blame] | 1004 | transaction.replace(R.id.contacts_list_container, uiFragment, TAG_ASSISTANT); |
Wenyi Wang | 17fe798 | 2016-10-05 13:54:09 -0700 | [diff] [blame] | 1005 | resetToolBarStatusBarColor(); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 1006 | } |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 1007 | transaction.addToBackStack(TAG_SECOND_LEVEL); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 1008 | transaction.commit(); |
| 1009 | fragmentManager.executePendingTransactions(); |
| 1010 | |
| 1011 | showFabWithAnimation(/* showFab */ false); |
| 1012 | } |
| 1013 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 1014 | public void switchToAllContacts() { |
Gary Mai | f6b50e8 | 2017-01-26 15:32:49 -0800 | [diff] [blame] | 1015 | popSecondLevel(); |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 1016 | mShouldSwitchToAllContacts = false; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 1017 | mCurrentView = ContactsView.ALL_CONTACTS; |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1018 | mDrawerFragment.setNavigationItemChecked(ContactsView.ALL_CONTACTS); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 1019 | showFabWithAnimation(/* showFab */ true); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1020 | mContactsListFragment.scrollToTop(); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1021 | resetFilter(); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1022 | setTitle(getString(R.string.contactsList)); |
| 1023 | } |
| 1024 | |
| 1025 | private void resetFilter() { |
| 1026 | final Intent intent = new Intent(); |
| 1027 | final ContactListFilter filter = AccountFilterUtil.createContactsFilter(this); |
| 1028 | intent.putExtra(AccountFilterActivity.EXTRA_CONTACT_LIST_FILTER, filter); |
| 1029 | AccountFilterUtil.handleAccountFilterResult( |
| 1030 | mContactListFilterController, AppCompatActivity.RESULT_OK, intent); |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Wenyi Wang | 92d7e51 | 2016-10-03 14:57:19 -0700 | [diff] [blame] | 1033 | // Reset toolbar and status bar color to Contacts theme color. |
| 1034 | private void resetToolBarStatusBarColor() { |
| 1035 | findViewById(R.id.toolbar_frame).setBackgroundColor( |
| 1036 | ContextCompat.getColor(this, R.color.primary_color)); |
| 1037 | updateStatusBarBackground(ContextCompat.getColor(this, R.color.primary_color_dark)); |
Wenyi Wang | cc8f272 | 2016-09-07 14:52:32 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
Wenyi Wang | de61df7 | 2017-01-04 18:00:49 -0800 | [diff] [blame] | 1040 | protected DefaultContactBrowseListFragment getListFragment() { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1041 | return mContactsListFragment; |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Wenyi Wang | 7967545 | 2016-08-17 10:43:28 -0700 | [diff] [blame] | 1044 | protected GroupMembersFragment getGroupFragment() { |
| 1045 | return mMembersFragment; |
| 1046 | } |
| 1047 | |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 1048 | private void handleFilterChangeForFragment(ContactListFilter filter) { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1049 | if (mContactsListFragment.canSetActionBar()) { |
| 1050 | mContactsListFragment.setFilterAndUpdateTitle(filter); |
James Laskey | 1842bb2 | 2016-10-20 14:38:04 -0700 | [diff] [blame] | 1051 | // Scroll to top after filter is changed. |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1052 | mContactsListFragment.scrollToTop(); |
James Laskey | 1842bb2 | 2016-10-20 14:38:04 -0700 | [diff] [blame] | 1053 | } |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | private void handleFilterChangeForActivity(ContactListFilter filter) { |
Marcus Hagerott | 74295d3 | 2016-10-26 10:46:28 -0700 | [diff] [blame] | 1057 | // The filter was changed while this activity was in the background. If we're in the |
| 1058 | // assistant view Switch to the main contacts list when we resume to prevent |
| 1059 | // b/31838582 and b/31829161 |
| 1060 | // TODO: this is a hack; we need to do some cleanup of the contact list filter stuff |
| 1061 | if (isAssistantView() && filter.isContactsFilterType()) { |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 1062 | mShouldSwitchToAllContacts = true; |
| 1063 | } |
| 1064 | |
Wenyi Wang | 32912eb | 2016-09-29 17:17:07 -0700 | [diff] [blame] | 1065 | if (CompatUtils.isNCompatible()) { |
| 1066 | getWindow().getDecorView() |
| 1067 | .sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 1068 | } |
| 1069 | invalidateOptionsMenu(); |
| 1070 | } |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1071 | |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1072 | public void updateDrawerGroupMenu(long groupId) { |
| 1073 | if (mDrawerFragment != null) { |
| 1074 | mDrawerFragment.updateGroupMenu(groupId); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | public void setDrawerLockMode(boolean enabled) { |
| 1079 | // Prevent drawer from being opened by sliding from the start of screen. |
| 1080 | mDrawerLayout.setDrawerLockMode(enabled ? DrawerLayout.LOCK_MODE_UNLOCKED |
| 1081 | : DrawerLayout.LOCK_MODE_LOCKED_CLOSED); |
| 1082 | |
| 1083 | // Order of these statements matter. |
| 1084 | // Display back button and disable drawer indicator. |
| 1085 | if (enabled) { |
| 1086 | getSupportActionBar().setDisplayHomeAsUpEnabled(false); |
| 1087 | mToggle.setDrawerIndicatorEnabled(true); |
| 1088 | } else { |
| 1089 | mToggle.setDrawerIndicatorEnabled(false); |
| 1090 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
| 1091 | } |
| 1092 | } |
| 1093 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1094 | public Toolbar getToolbar() { |
| 1095 | return mToolbar; |
| 1096 | } |
| 1097 | |
| 1098 | @Override |
| 1099 | protected void onPostCreate(Bundle savedInstanceState) { |
| 1100 | super.onPostCreate(savedInstanceState); |
| 1101 | mToggle.syncState(); |
| 1102 | } |
| 1103 | |
| 1104 | @Override |
| 1105 | public void onConfigurationChanged(Configuration newConfig) { |
| 1106 | super.onConfigurationChanged(newConfig); |
| 1107 | mToggle.onConfigurationChanged(newConfig); |
| 1108 | } |
| 1109 | |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1110 | protected void onCreateGroupMenuItemClicked() { |
| 1111 | // Select the account to create the group |
| 1112 | final Bundle extras = getIntent().getExtras(); |
| 1113 | final Account account = extras == null ? null : |
| 1114 | (Account) extras.getParcelable(Intents.Insert.EXTRA_ACCOUNT); |
| 1115 | if (account == null) { |
| 1116 | selectAccountForNewGroup(); |
| 1117 | } else { |
| 1118 | final String dataSet = extras == null |
| 1119 | ? null : extras.getString(Intents.Insert.EXTRA_DATA_SET); |
| 1120 | final AccountWithDataSet accountWithDataSet = new AccountWithDataSet( |
| 1121 | account.name, account.type, dataSet); |
| 1122 | onAccountChosen(accountWithDataSet, /* extraArgs */ null); |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | private void selectAccountForNewGroup() { |
Wenyi Wang | b8b86d1 | 2017-01-07 16:16:52 -0800 | [diff] [blame] | 1127 | // This should never block because the DrawerFragment loads the accounts and the |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1128 | // "Create Label" item only exists when that loading finishes |
| 1129 | final List<AccountInfo> accounts = Futures.getUnchecked(AccountTypeManager.getInstance(this) |
| 1130 | .filterAccountsAsync(AccountTypeManager.AccountFilter.GROUPS_WRITABLE)); |
| 1131 | if (accounts.isEmpty()) { |
| 1132 | // We shouldn't present the add group button if there are no writable accounts |
| 1133 | // but check it since it's possible we are started with an Intent. |
| 1134 | Toast.makeText(this, R.string.groupCreateFailedToast, Toast.LENGTH_SHORT).show(); |
| 1135 | return; |
| 1136 | } |
| 1137 | // If there is a single writable account, use it w/o showing a dialog. |
| 1138 | if (accounts.size() == 1) { |
| 1139 | onAccountChosen(accounts.get(0).getAccount(), /* extraArgs */ null); |
| 1140 | return; |
| 1141 | } |
| 1142 | SelectAccountDialogFragment.show(getFragmentManager(), R.string.dialog_new_group_account, |
| 1143 | AccountTypeManager.AccountFilter.GROUPS_WRITABLE, /* extraArgs */ null, |
| 1144 | TAG_SELECT_ACCOUNT_DIALOG); |
| 1145 | } |
| 1146 | |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1147 | // Implementation of SelectAccountDialogFragment.Listener |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1148 | @Override |
| 1149 | public void onAccountChosen(AccountWithDataSet account, Bundle extraArgs) { |
| 1150 | mNewGroupAccount = account; |
| 1151 | GroupNameEditDialogFragment.newInstanceForCreation( |
| 1152 | mNewGroupAccount, GroupUtil.ACTION_CREATE_GROUP) |
| 1153 | .show(getFragmentManager(), TAG_GROUP_NAME_EDIT_DIALOG); |
| 1154 | } |
| 1155 | |
| 1156 | @Override |
| 1157 | public void onAccountSelectorCancelled() { |
| 1158 | } |
| 1159 | |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1160 | // Implementation of DrawerFragmentListener |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1161 | @Override |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1162 | public void onDrawerItemClicked(){ |
| 1163 | closeDrawer(); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1164 | } |
| 1165 | |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1166 | @Override |
| 1167 | public void onContactsViewSelected(ContactsView mode) { |
| 1168 | if (mode == ContactsView.ALL_CONTACTS) { |
| 1169 | switchToAllContacts(); |
| 1170 | } else if (mode == ContactsView.ASSISTANT) { |
| 1171 | launchAssistant(); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1172 | } else { |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1173 | throw new IllegalStateException("Unknown view " + mode); |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | @Override |
| 1178 | public void onCreateLabelButtonClicked() { |
| 1179 | onCreateGroupMenuItemClicked(); |
| 1180 | } |
| 1181 | |
| 1182 | @Override |
| 1183 | public void onOpenSettings() { |
| 1184 | new Handler().postDelayed(new Runnable() { |
| 1185 | @Override |
| 1186 | public void run() { |
| 1187 | startActivity(createPreferenceIntent()); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1188 | } |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1189 | }, DRAWER_CLOSE_DELAY); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1190 | } |
| 1191 | |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1192 | @Override |
| 1193 | public void onLaunchHelpFeedback() { |
| 1194 | HelpUtils.launchHelpAndFeedbackForMainScreen(this); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1195 | } |
| 1196 | |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1197 | @Override |
| 1198 | public void onGroupViewSelected(GroupListItem groupListItem) { |
| 1199 | onGroupMenuItemClicked(groupListItem.getGroupId()); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1200 | } |
| 1201 | |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1202 | @Override |
| 1203 | public void onAccountViewSelected(ContactListFilter filter) { |
| 1204 | final Intent intent = new Intent(); |
| 1205 | intent.putExtra(AccountFilterActivity.EXTRA_CONTACT_LIST_FILTER, filter); |
| 1206 | onFilterMenuItemClicked(intent); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | public boolean isGroupView() { |
| 1210 | return mCurrentView == ContactsView.GROUP_VIEW; |
| 1211 | } |
| 1212 | |
| 1213 | protected boolean isAssistantView() { |
| 1214 | return mCurrentView == ContactsView.ASSISTANT; |
| 1215 | } |
| 1216 | |
| 1217 | protected boolean isAllContactsView() { |
| 1218 | return mCurrentView == ContactsView.ALL_CONTACTS; |
| 1219 | } |
| 1220 | |
| 1221 | protected boolean isAccountView() { |
| 1222 | return mCurrentView == ContactsView.ACCOUNT_VIEW; |
| 1223 | } |
| 1224 | |
| 1225 | public boolean isInSecondLevel() { |
Gary Mai | ee49cd9 | 2017-01-30 18:28:51 -0800 | [diff] [blame] | 1226 | return isGroupView() || isAssistantView(); |
Gary Mai | f6b50e8 | 2017-01-26 15:32:49 -0800 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | private boolean isInThirdLevel() { |
| 1230 | return isLastBackStackTag(TAG_THIRD_LEVEL); |
| 1231 | } |
| 1232 | |
| 1233 | private boolean isLastBackStackTag(String tag) { |
| 1234 | final int count = getFragmentManager().getBackStackEntryCount(); |
| 1235 | if (count > 0) { |
| 1236 | final FragmentManager.BackStackEntry last = |
| 1237 | getFragmentManager().getBackStackEntryAt(count - 1); |
| 1238 | if (tag == null) { |
| 1239 | return last.getName() == null; |
| 1240 | } |
| 1241 | return tag.equals(last.getName()); |
| 1242 | } |
| 1243 | return false; |
| 1244 | } |
| 1245 | |
| 1246 | private void popSecondLevel() { |
| 1247 | getFragmentManager().popBackStackImmediate( |
| 1248 | TAG_ASSISTANT_HELPER, FragmentManager.POP_BACK_STACK_INCLUSIVE); |
| 1249 | getFragmentManager().popBackStackImmediate( |
| 1250 | TAG_SECOND_LEVEL, FragmentManager.POP_BACK_STACK_INCLUSIVE); |
| 1251 | mMembersFragment = null; |
| 1252 | resetToolBarStatusBarColor(); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1253 | } |
| 1254 | |
Wenyi Wang | 2829deb | 2017-01-04 14:05:13 -0800 | [diff] [blame] | 1255 | public void closeDrawer() { |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1256 | mDrawerLayout.closeDrawer(GravityCompat.START); |
Wenyi Wang | 917cb4a | 2016-12-13 17:42:18 -0800 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | private Intent createPreferenceIntent() { |
| 1260 | final Intent intent = new Intent(this, ContactsPreferenceActivity.class); |
| 1261 | intent.putExtra(ContactsPreferenceActivity.EXTRA_NEW_LOCAL_PROFILE, |
| 1262 | ContactEditorFragment.INTENT_EXTRA_NEW_LOCAL_PROFILE); |
| 1263 | return intent; |
| 1264 | } |
| 1265 | |
Walter Jang | cea8212 | 2017-01-05 20:38:38 +0000 | [diff] [blame] | 1266 | |
The Android Open Source Project | 7aa0e4c | 2009-03-03 19:32:21 -0800 | [diff] [blame] | 1267 | } |