Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.dialer.app; |
| 18 | |
| 19 | import android.app.Fragment; |
| 20 | import android.app.FragmentTransaction; |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 21 | import android.app.KeyguardManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 22 | import android.content.ActivityNotFoundException; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.pm.PackageManager; |
| 26 | import android.content.pm.ResolveInfo; |
| 27 | import android.content.res.Configuration; |
| 28 | import android.content.res.Resources; |
| 29 | import android.database.Cursor; |
| 30 | import android.net.Uri; |
| 31 | import android.os.Bundle; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 32 | import android.os.SystemClock; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 33 | import android.os.Trace; |
| 34 | import android.provider.CallLog.Calls; |
calderwoodra | 73b51d5 | 2017-12-08 20:52:56 -0800 | [diff] [blame] | 35 | import android.provider.ContactsContract.QuickContact; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 36 | import android.speech.RecognizerIntent; |
| 37 | import android.support.annotation.MainThread; |
| 38 | import android.support.annotation.NonNull; |
| 39 | import android.support.annotation.VisibleForTesting; |
| 40 | import android.support.design.widget.CoordinatorLayout; |
Eric Erfanian | fc37b02 | 2017-03-21 10:11:17 -0700 | [diff] [blame] | 41 | import android.support.design.widget.FloatingActionButton; |
calderwoodra | 6007f52 | 2017-10-09 16:59:04 -0700 | [diff] [blame] | 42 | import android.support.design.widget.FloatingActionButton.OnVisibilityChangedListener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 43 | import android.support.design.widget.Snackbar; |
| 44 | import android.support.v4.app.ActivityCompat; |
| 45 | import android.support.v4.view.ViewPager; |
| 46 | import android.support.v7.app.ActionBar; |
| 47 | import android.telecom.PhoneAccount; |
| 48 | import android.text.Editable; |
| 49 | import android.text.TextUtils; |
| 50 | import android.text.TextWatcher; |
| 51 | import android.view.DragEvent; |
| 52 | import android.view.Gravity; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 53 | import android.view.Menu; |
| 54 | import android.view.MenuItem; |
| 55 | import android.view.MotionEvent; |
| 56 | import android.view.View; |
| 57 | import android.view.View.OnDragListener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 58 | import android.view.animation.Animation; |
| 59 | import android.view.animation.AnimationUtils; |
| 60 | import android.widget.AbsListView.OnScrollListener; |
| 61 | import android.widget.EditText; |
| 62 | import android.widget.ImageButton; |
calderwoodra | 73b51d5 | 2017-12-08 20:52:56 -0800 | [diff] [blame] | 63 | import android.widget.ImageView; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 64 | import android.widget.PopupMenu; |
| 65 | import android.widget.TextView; |
| 66 | import android.widget.Toast; |
| 67 | import com.android.contacts.common.dialog.ClearFrequentsDialog; |
| 68 | import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; |
| 69 | import com.android.contacts.common.list.PhoneNumberListAdapter; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 70 | import com.android.contacts.common.list.PhoneNumberPickerFragment.CursorReranker; |
| 71 | import com.android.contacts.common.list.PhoneNumberPickerFragment.OnLoadFinishedListener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 72 | import com.android.dialer.animation.AnimUtils; |
| 73 | import com.android.dialer.animation.AnimationListenerAdapter; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 74 | import com.android.dialer.app.calllog.CallLogActivity; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 75 | import com.android.dialer.app.calllog.CallLogAdapter; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 76 | import com.android.dialer.app.calllog.CallLogFragment; |
| 77 | import com.android.dialer.app.calllog.CallLogNotificationsService; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 78 | import com.android.dialer.app.calllog.IntentProvider; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 79 | import com.android.dialer.app.list.DialtactsPagerAdapter; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 80 | import com.android.dialer.app.list.DialtactsPagerAdapter.TabIndex; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 81 | import com.android.dialer.app.list.DragDropController; |
| 82 | import com.android.dialer.app.list.ListsFragment; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 83 | import com.android.dialer.app.list.OldSpeedDialFragment; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 84 | import com.android.dialer.app.list.OnDragDropListener; |
| 85 | import com.android.dialer.app.list.OnListFragmentScrolledListener; |
| 86 | import com.android.dialer.app.list.PhoneFavoriteSquareTileView; |
| 87 | import com.android.dialer.app.list.RegularSearchFragment; |
| 88 | import com.android.dialer.app.list.SearchFragment; |
| 89 | import com.android.dialer.app.list.SmartDialSearchFragment; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 90 | import com.android.dialer.app.settings.DialerSettingsActivity; |
| 91 | import com.android.dialer.app.widget.ActionBarController; |
| 92 | import com.android.dialer.app.widget.SearchEditTextLayout; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 93 | import com.android.dialer.callcomposer.CallComposerActivity; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 94 | import com.android.dialer.calldetails.CallDetailsActivity; |
| 95 | import com.android.dialer.callintent.CallInitiationType; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 96 | import com.android.dialer.callintent.CallIntentBuilder; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 97 | import com.android.dialer.callintent.CallSpecificAppData; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 98 | import com.android.dialer.common.Assert; |
| 99 | import com.android.dialer.common.LogUtil; |
calderwoodra | 9d197d0 | 2017-11-15 15:41:54 -0800 | [diff] [blame] | 100 | import com.android.dialer.common.UiUtil; |
calderwoodra | 97d0b5e | 2018-01-26 12:11:26 -0800 | [diff] [blame] | 101 | import com.android.dialer.common.concurrent.DialerExecutorComponent; |
calderwoodra | 6007f52 | 2017-10-09 16:59:04 -0700 | [diff] [blame] | 102 | import com.android.dialer.common.concurrent.ThreadUtil; |
linyuh | c9b3581 | 2017-12-28 09:58:34 -0800 | [diff] [blame] | 103 | import com.android.dialer.compat.CompatUtils; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 104 | import com.android.dialer.configprovider.ConfigProviderBindings; |
| 105 | import com.android.dialer.constants.ActivityRequestCodes; |
Android Dialer | 3f4a319 | 2017-09-20 17:59:44 -0700 | [diff] [blame] | 106 | import com.android.dialer.contactsfragment.ContactsFragment; |
calderwoodra | 73b51d5 | 2017-12-08 20:52:56 -0800 | [diff] [blame] | 107 | import com.android.dialer.contactsfragment.ContactsFragment.OnContactSelectedListener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 108 | import com.android.dialer.database.Database; |
| 109 | import com.android.dialer.database.DialerDatabaseHelper; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 110 | import com.android.dialer.dialpadview.DialpadFragment; |
| 111 | import com.android.dialer.dialpadview.DialpadFragment.DialpadListener; |
| 112 | import com.android.dialer.dialpadview.DialpadFragment.LastOutgoingCallCallback; |
roldenburg | 19c6c25 | 2017-12-13 15:58:01 -0800 | [diff] [blame] | 113 | import com.android.dialer.duo.DuoComponent; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 114 | import com.android.dialer.interactions.PhoneNumberInteraction; |
| 115 | import com.android.dialer.interactions.PhoneNumberInteraction.InteractionErrorCode; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 116 | import com.android.dialer.logging.DialerImpression; |
calderwoodra | 73b51d5 | 2017-12-08 20:52:56 -0800 | [diff] [blame] | 117 | import com.android.dialer.logging.InteractionEvent; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 118 | import com.android.dialer.logging.Logger; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 119 | import com.android.dialer.logging.ScreenEvent; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 120 | import com.android.dialer.logging.UiAction; |
zachh | 7a96dc7 | 2018-02-20 22:16:03 -0800 | [diff] [blame] | 121 | import com.android.dialer.metrics.Metrics; |
| 122 | import com.android.dialer.metrics.MetricsComponent; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 123 | import com.android.dialer.p13n.inference.P13nRanking; |
| 124 | import com.android.dialer.p13n.inference.protocol.P13nRanker; |
| 125 | import com.android.dialer.p13n.inference.protocol.P13nRanker.P13nRefreshCompleteListener; |
| 126 | import com.android.dialer.p13n.logging.P13nLogger; |
| 127 | import com.android.dialer.p13n.logging.P13nLogging; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 128 | import com.android.dialer.performancereport.PerformanceReport; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 129 | import com.android.dialer.postcall.PostCall; |
twyen | 0efc840 | 2017-11-07 15:39:15 -0800 | [diff] [blame] | 130 | import com.android.dialer.precall.PreCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 131 | import com.android.dialer.proguard.UsedByReflection; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 132 | import com.android.dialer.searchfragment.list.NewSearchFragment; |
calderwoodra | 32257fd | 2017-10-25 15:01:37 -0700 | [diff] [blame] | 133 | import com.android.dialer.searchfragment.list.NewSearchFragment.SearchFragmentListener; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 134 | import com.android.dialer.simulator.Simulator; |
| 135 | import com.android.dialer.simulator.SimulatorComponent; |
linyuh | bf4bb05 | 2017-12-21 15:42:00 -0800 | [diff] [blame] | 136 | import com.android.dialer.smartdial.util.SmartDialNameMatcher; |
| 137 | import com.android.dialer.smartdial.util.SmartDialPrefix; |
linyuh | 168d09c | 2017-10-26 17:04:30 -0700 | [diff] [blame] | 138 | import com.android.dialer.storage.StorageComponent; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 139 | import com.android.dialer.telecom.TelecomUtil; |
| 140 | import com.android.dialer.util.DialerUtils; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 141 | import com.android.dialer.util.PermissionsUtil; |
| 142 | import com.android.dialer.util.TouchPointManager; |
| 143 | import com.android.dialer.util.TransactionSafeActivity; |
| 144 | import com.android.dialer.util.ViewUtil; |
calderwoodra | 6007f52 | 2017-10-09 16:59:04 -0700 | [diff] [blame] | 145 | import com.android.dialer.widget.FloatingActionButtonController; |
twyen | 891fe0f | 2017-10-17 14:59:15 -0700 | [diff] [blame] | 146 | import com.google.common.base.Optional; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 147 | import java.util.ArrayList; |
| 148 | import java.util.Arrays; |
| 149 | import java.util.List; |
| 150 | import java.util.Locale; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 151 | import java.util.concurrent.TimeUnit; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 152 | |
| 153 | /** The dialer tab's title is 'phone', a more common name (see strings.xml). */ |
| 154 | @UsedByReflection(value = "AndroidManifest-app.xml") |
| 155 | public class DialtactsActivity extends TransactionSafeActivity |
| 156 | implements View.OnClickListener, |
| 157 | DialpadFragment.OnDialpadQueryChangedListener, |
| 158 | OnListFragmentScrolledListener, |
| 159 | CallLogFragment.HostInterface, |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 160 | CallLogAdapter.OnActionModeStateChangedListener, |
Android Dialer | 3f4a319 | 2017-09-20 17:59:44 -0700 | [diff] [blame] | 161 | ContactsFragment.OnContactsListScrolledListener, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 162 | DialpadFragment.HostInterface, |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 163 | OldSpeedDialFragment.HostInterface, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 164 | SearchFragment.HostInterface, |
| 165 | OnDragDropListener, |
| 166 | OnPhoneNumberPickerActionListener, |
| 167 | PopupMenu.OnMenuItemClickListener, |
| 168 | ViewPager.OnPageChangeListener, |
| 169 | ActionBarController.ActivityUi, |
| 170 | PhoneNumberInteraction.InteractionErrorListener, |
| 171 | PhoneNumberInteraction.DisambigDialogDismissedListener, |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 172 | ActivityCompat.OnRequestPermissionsResultCallback, |
calderwoodra | c377012 | 2017-10-13 16:36:17 -0700 | [diff] [blame] | 173 | DialpadListener, |
calderwoodra | 73b51d5 | 2017-12-08 20:52:56 -0800 | [diff] [blame] | 174 | SearchFragmentListener, |
| 175 | OnContactSelectedListener { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 176 | |
| 177 | public static final boolean DEBUG = false; |
| 178 | @VisibleForTesting public static final String TAG_DIALPAD_FRAGMENT = "dialpad"; |
| 179 | private static final String ACTION_SHOW_TAB = "ACTION_SHOW_TAB"; |
| 180 | @VisibleForTesting public static final String EXTRA_SHOW_TAB = "EXTRA_SHOW_TAB"; |
| 181 | public static final String EXTRA_CLEAR_NEW_VOICEMAILS = "EXTRA_CLEAR_NEW_VOICEMAILS"; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 182 | private static final String KEY_LAST_TAB = "last_tab"; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 183 | private static final String TAG = "DialtactsActivity"; |
| 184 | private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui"; |
| 185 | private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui"; |
calderwoodra | 5071526 | 2017-09-08 09:20:08 -0700 | [diff] [blame] | 186 | private static final String KEY_IN_NEW_SEARCH_UI = "in_new_search_ui"; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 187 | private static final String KEY_SEARCH_QUERY = "search_query"; |
calderwoodra | 9d197d0 | 2017-11-15 15:41:54 -0800 | [diff] [blame] | 188 | private static final String KEY_DIALPAD_QUERY = "dialpad_query"; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 189 | private static final String KEY_FIRST_LAUNCH = "first_launch"; |
linyuh | c9b3581 | 2017-12-28 09:58:34 -0800 | [diff] [blame] | 190 | private static final String KEY_SAVED_LANGUAGE_CODE = "saved_language_code"; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 191 | private static final String KEY_WAS_CONFIGURATION_CHANGE = "was_configuration_change"; |
| 192 | private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown"; |
calderwoodra | 218fff3 | 2017-09-19 11:20:31 -0700 | [diff] [blame] | 193 | private static final String KEY_FAB_VISIBLE = "fab_visible"; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 194 | private static final String TAG_NEW_SEARCH_FRAGMENT = "new_search"; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 195 | private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search"; |
| 196 | private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial"; |
| 197 | private static final String TAG_FAVORITES_FRAGMENT = "favorites"; |
| 198 | /** Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}. */ |
| 199 | private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER"; |
| 200 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 201 | private static final int FAB_SCALE_IN_DELAY_MS = 300; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 202 | |
| 203 | /** |
| 204 | * Minimum time the history tab must have been selected for it to be marked as seen in onStop() |
| 205 | */ |
| 206 | private static final long HISTORY_TAB_SEEN_TIMEOUT = TimeUnit.SECONDS.toMillis(3); |
| 207 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 208 | private static Optional<Boolean> voiceSearchEnabledForTest = Optional.absent(); |
twyen | 891fe0f | 2017-10-17 14:59:15 -0700 | [diff] [blame] | 209 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 210 | /** Fragment containing the dialpad that slides into view */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 211 | protected DialpadFragment dialpadFragment; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 212 | |
Android Dialer | 3f4a319 | 2017-09-20 17:59:44 -0700 | [diff] [blame] | 213 | /** Root layout of DialtactsActivity */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 214 | private CoordinatorLayout parentLayout; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 215 | /** Fragment for searching phone numbers using the alphanumeric keyboard. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 216 | private RegularSearchFragment regularSearchFragment; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 217 | |
| 218 | /** Fragment for searching phone numbers using the dialpad. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 219 | private SmartDialSearchFragment smartDialSearchFragment; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 220 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 221 | /** new Fragment for search phone numbers using the keyboard and the dialpad. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 222 | private NewSearchFragment newSearchFragment; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 223 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 224 | /** Animation that slides in. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 225 | private Animation slideIn; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 226 | |
| 227 | /** Animation that slides out. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 228 | private Animation slideOut; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 229 | /** Fragment containing the speed dial list, call history list, and all contacts list. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 230 | private ListsFragment listsFragment; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 231 | /** |
| 232 | * Tracks whether onSaveInstanceState has been called. If true, no fragment transactions can be |
| 233 | * commited. |
| 234 | */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 235 | private boolean stateSaved; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 236 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 237 | private boolean isKeyboardOpen; |
| 238 | private boolean inNewSearch; |
| 239 | private boolean isRestarting; |
| 240 | private boolean inDialpadSearch; |
| 241 | private boolean inRegularSearch; |
| 242 | private boolean clearSearchOnPause; |
| 243 | private boolean isDialpadShown; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 244 | /** Whether or not the device is in landscape orientation. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 245 | private boolean isLandscape; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 246 | /** True if the dialpad is only temporarily showing due to being in call */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 247 | private boolean inCallDialpadUp; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 248 | /** True when this activity has been launched for the first time. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 249 | private boolean firstLaunch; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 250 | /** |
| 251 | * Search query to be applied to the SearchView in the ActionBar once onCreateOptionsMenu has been |
| 252 | * called. |
| 253 | */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 254 | private String pendingSearchViewQuery; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 255 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 256 | private PopupMenu overflowMenu; |
| 257 | private EditText searchView; |
| 258 | private SearchEditTextLayout searchEditTextLayout; |
| 259 | private View voiceSearchButton; |
| 260 | private String searchQuery; |
| 261 | private String dialpadQuery; |
| 262 | private DialerDatabaseHelper dialerDatabaseHelper; |
| 263 | private DragDropController dragDropController; |
| 264 | private ActionBarController actionBarController; |
| 265 | private FloatingActionButtonController floatingActionButtonController; |
linyuh | c9b3581 | 2017-12-28 09:58:34 -0800 | [diff] [blame] | 266 | private String savedLanguageCode; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 267 | private boolean wasConfigurationChange; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 268 | private long timeTabSelected; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 269 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 270 | private P13nLogger p13nLogger; |
| 271 | private P13nRanker p13nRanker; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 272 | public boolean isMultiSelectModeEnabled; |
| 273 | |
| 274 | private boolean isLastTabEnabled; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 275 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 276 | AnimationListenerAdapter slideInListener = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 277 | new AnimationListenerAdapter() { |
| 278 | @Override |
| 279 | public void onAnimationEnd(Animation animation) { |
| 280 | maybeEnterSearchUi(); |
| 281 | } |
| 282 | }; |
| 283 | /** Listener for after slide out animation completes on dialer fragment. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 284 | AnimationListenerAdapter slideOutListener = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 285 | new AnimationListenerAdapter() { |
| 286 | @Override |
| 287 | public void onAnimationEnd(Animation animation) { |
| 288 | commitDialpadFragmentHide(); |
| 289 | } |
| 290 | }; |
| 291 | /** Listener used to send search queries to the phone search fragment. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 292 | private final TextWatcher phoneSearchQueryTextListener = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 293 | new TextWatcher() { |
| 294 | @Override |
| 295 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {} |
| 296 | |
| 297 | @Override |
| 298 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 299 | final String newText = s.toString(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 300 | if (newText.equals(searchQuery)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 301 | // If the query hasn't changed (perhaps due to activity being destroyed |
| 302 | // and restored, or user launching the same DIAL intent twice), then there is |
| 303 | // no need to do anything here. |
| 304 | return; |
| 305 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 306 | |
| 307 | if (count != 0) { |
| 308 | PerformanceReport.recordClick(UiAction.Type.TEXT_CHANGE_WITH_INPUT); |
| 309 | } |
| 310 | |
wangqi | e9f94c7 | 2017-11-10 11:51:50 -0800 | [diff] [blame] | 311 | LogUtil.v("DialtactsActivity.onTextChanged", "called with new query: " + newText); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 312 | LogUtil.v("DialtactsActivity.onTextChanged", "previous query: " + searchQuery); |
| 313 | searchQuery = newText; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 314 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 315 | // TODO(calderwoodra): show p13n when newText is empty. |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 316 | // Show search fragment only when the query string is changed to non-empty text. |
| 317 | if (!TextUtils.isEmpty(newText)) { |
| 318 | // Call enterSearchUi only if we are switching search modes, or showing a search |
| 319 | // fragment for the first time. |
| 320 | final boolean sameSearchMode = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 321 | (isDialpadShown && inDialpadSearch) || (!isDialpadShown && inRegularSearch); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 322 | if (!sameSearchMode) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 323 | enterSearchUi(isDialpadShown, searchQuery, true /* animate */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 327 | if (smartDialSearchFragment != null && smartDialSearchFragment.isVisible()) { |
| 328 | smartDialSearchFragment.setQueryString(searchQuery); |
| 329 | } else if (regularSearchFragment != null && regularSearchFragment.isVisible()) { |
| 330 | regularSearchFragment.setQueryString(searchQuery); |
| 331 | } else if (newSearchFragment != null && newSearchFragment.isVisible()) { |
| 332 | newSearchFragment.setQuery(searchQuery, getCallInitiationType()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
| 336 | @Override |
| 337 | public void afterTextChanged(Editable s) {} |
| 338 | }; |
| 339 | /** Open the search UI when the user clicks on the search box. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 340 | private final View.OnClickListener searchViewOnClickListener = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 341 | new View.OnClickListener() { |
| 342 | @Override |
| 343 | public void onClick(View v) { |
| 344 | if (!isInSearchUi()) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 345 | PerformanceReport.recordClick(UiAction.Type.OPEN_SEARCH); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 346 | actionBarController.onSearchBoxTapped(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 347 | enterSearchUi( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 348 | false /* smartDialSearch */, searchView.getText().toString(), true /* animate */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | }; |
| 352 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 353 | private int actionBarHeight; |
| 354 | private int previouslySelectedTabIndex; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 355 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 356 | /** |
| 357 | * The text returned from a voice search query. Set in {@link #onActivityResult} and used in |
| 358 | * {@link #onResume()} to populate the search box. |
| 359 | */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 360 | private String voiceSearchQuery; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 361 | |
| 362 | /** |
| 363 | * @param tab the TAB_INDEX_* constant in {@link ListsFragment} |
| 364 | * @return A intent that will open the DialtactsActivity into the specified tab. The intent for |
| 365 | * each tab will be unique. |
| 366 | */ |
| 367 | public static Intent getShowTabIntent(Context context, int tab) { |
| 368 | Intent intent = new Intent(context, DialtactsActivity.class); |
| 369 | intent.setAction(ACTION_SHOW_TAB); |
| 370 | intent.putExtra(DialtactsActivity.EXTRA_SHOW_TAB, tab); |
| 371 | intent.setData( |
| 372 | new Uri.Builder() |
| 373 | .scheme("intent") |
| 374 | .authority(context.getPackageName()) |
| 375 | .appendPath(TAG) |
| 376 | .appendQueryParameter(DialtactsActivity.EXTRA_SHOW_TAB, String.valueOf(tab)) |
| 377 | .build()); |
| 378 | |
| 379 | return intent; |
| 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 384 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 385 | TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); |
| 386 | } |
| 387 | return super.dispatchTouchEvent(ev); |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | protected void onCreate(Bundle savedInstanceState) { |
| 392 | Trace.beginSection(TAG + " onCreate"); |
zachh | 6050ec2 | 2017-09-21 16:02:35 -0700 | [diff] [blame] | 393 | LogUtil.enterBlock("DialtactsActivity.onCreate"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 394 | super.onCreate(savedInstanceState); |
| 395 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 396 | firstLaunch = true; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 397 | isLastTabEnabled = ConfigProviderBindings.get(this).getBoolean("last_tab_enabled", false); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 398 | |
| 399 | final Resources resources = getResources(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 400 | actionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 401 | |
| 402 | Trace.beginSection(TAG + " setContentView"); |
| 403 | setContentView(R.layout.dialtacts_activity); |
| 404 | Trace.endSection(); |
| 405 | getWindow().setBackgroundDrawable(null); |
| 406 | |
| 407 | Trace.beginSection(TAG + " setup Views"); |
| 408 | final ActionBar actionBar = getActionBarSafely(); |
| 409 | actionBar.setCustomView(R.layout.search_edittext); |
| 410 | actionBar.setDisplayShowCustomEnabled(true); |
| 411 | actionBar.setBackgroundDrawable(null); |
| 412 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 413 | searchEditTextLayout = actionBar.getCustomView().findViewById(R.id.search_view_container); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 414 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 415 | actionBarController = new ActionBarController(this, searchEditTextLayout); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 416 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 417 | searchView = searchEditTextLayout.findViewById(R.id.search_view); |
| 418 | searchView.addTextChangedListener(phoneSearchQueryTextListener); |
| 419 | searchView.setHint(getSearchBoxHint()); |
calderwoodra | 5071526 | 2017-09-08 09:20:08 -0700 | [diff] [blame] | 420 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 421 | voiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button); |
| 422 | searchEditTextLayout |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 423 | .findViewById(R.id.search_box_collapsed) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 424 | .setOnClickListener(searchViewOnClickListener); |
| 425 | searchEditTextLayout |
calderwoodra | 5071526 | 2017-09-08 09:20:08 -0700 | [diff] [blame] | 426 | .findViewById(R.id.search_back_button) |
| 427 | .setOnClickListener(v -> exitSearchUi()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 428 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 429 | isLandscape = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 430 | getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 431 | previouslySelectedTabIndex = DialtactsPagerAdapter.TAB_INDEX_SPEED_DIAL; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 432 | FloatingActionButton floatingActionButton = findViewById(R.id.floating_action_button); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 433 | floatingActionButton.setOnClickListener(this); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 434 | floatingActionButtonController = new FloatingActionButtonController(this, floatingActionButton); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 435 | |
| 436 | ImageButton optionsMenuButton = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 437 | searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 438 | optionsMenuButton.setOnClickListener(this); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 439 | overflowMenu = buildOptionsMenu(optionsMenuButton); |
| 440 | optionsMenuButton.setOnTouchListener(overflowMenu.getDragToOpenListener()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 441 | |
| 442 | // Add the favorites fragment but only if savedInstanceState is null. Otherwise the |
| 443 | // fragment manager is responsible for recreating it. |
| 444 | if (savedInstanceState == null) { |
| 445 | getFragmentManager() |
| 446 | .beginTransaction() |
| 447 | .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT) |
| 448 | .commit(); |
| 449 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 450 | searchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY); |
| 451 | dialpadQuery = savedInstanceState.getString(KEY_DIALPAD_QUERY); |
| 452 | inRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI); |
| 453 | inDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI); |
| 454 | inNewSearch = savedInstanceState.getBoolean(KEY_IN_NEW_SEARCH_UI); |
| 455 | firstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH); |
linyuh | c9b3581 | 2017-12-28 09:58:34 -0800 | [diff] [blame] | 456 | savedLanguageCode = savedInstanceState.getString(KEY_SAVED_LANGUAGE_CODE); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 457 | wasConfigurationChange = savedInstanceState.getBoolean(KEY_WAS_CONFIGURATION_CHANGE); |
| 458 | isDialpadShown = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN); |
| 459 | floatingActionButtonController.setVisible(savedInstanceState.getBoolean(KEY_FAB_VISIBLE)); |
| 460 | actionBarController.restoreInstanceState(savedInstanceState); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | final boolean isLayoutRtl = ViewUtil.isRtl(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 464 | if (isLandscape) { |
| 465 | slideIn = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 466 | AnimationUtils.loadAnimation( |
| 467 | this, isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 468 | slideOut = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 469 | AnimationUtils.loadAnimation( |
| 470 | this, isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right); |
| 471 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 472 | slideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom); |
| 473 | slideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 474 | } |
| 475 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 476 | slideIn.setInterpolator(AnimUtils.EASE_IN); |
| 477 | slideOut.setInterpolator(AnimUtils.EASE_OUT); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 478 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 479 | slideIn.setAnimationListener(slideInListener); |
| 480 | slideOut.setAnimationListener(slideOutListener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 481 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 482 | parentLayout = (CoordinatorLayout) findViewById(R.id.dialtacts_mainlayout); |
| 483 | parentLayout.setOnDragListener(new LayoutOnDragListener()); |
Eric Erfanian | fc37b02 | 2017-03-21 10:11:17 -0700 | [diff] [blame] | 484 | ViewUtil.doOnGlobalLayout( |
| 485 | floatingActionButton, |
| 486 | view -> { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 487 | int screenWidth = parentLayout.getWidth(); |
| 488 | floatingActionButtonController.setScreenWidth(screenWidth); |
| 489 | floatingActionButtonController.align(getFabAlignment(), false /* animate */); |
Eric Erfanian | fc37b02 | 2017-03-21 10:11:17 -0700 | [diff] [blame] | 490 | }); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 491 | |
| 492 | Trace.endSection(); |
| 493 | |
| 494 | Trace.beginSection(TAG + " initialize smart dialing"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 495 | dialerDatabaseHelper = Database.get(this).getDatabaseHelper(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 496 | SmartDialPrefix.initializeNanpSettings(this); |
| 497 | Trace.endSection(); |
| 498 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 499 | p13nLogger = P13nLogging.get(getApplicationContext()); |
| 500 | p13nRanker = P13nRanking.get(getApplicationContext()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 501 | Trace.endSection(); |
calderwoodra | 71eae26 | 2017-11-30 13:19:42 -0800 | [diff] [blame] | 502 | |
| 503 | // Update the new search fragment to the correct position and the ActionBar's visibility. |
| 504 | if (ConfigProviderBindings.get(this).getBoolean("enable_new_search_fragment", false)) { |
| 505 | updateSearchFragmentPosition(); |
| 506 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | @NonNull |
| 510 | private ActionBar getActionBarSafely() { |
| 511 | return Assert.isNotNull(getSupportActionBar()); |
| 512 | } |
| 513 | |
| 514 | @Override |
| 515 | protected void onResume() { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 516 | LogUtil.enterBlock("DialtactsActivity.onResume"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 517 | Trace.beginSection(TAG + " onResume"); |
| 518 | super.onResume(); |
| 519 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 520 | // Some calls may not be recorded (eg. from quick contact), |
| 521 | // so we should restart recording after these calls. (Recorded call is stopped) |
| 522 | PostCall.restartPerformanceRecordingIfARecentCallExist(this); |
| 523 | if (!PerformanceReport.isRecording()) { |
| 524 | PerformanceReport.startRecording(); |
| 525 | } |
| 526 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 527 | stateSaved = false; |
| 528 | if (firstLaunch) { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 529 | LogUtil.i("DialtactsActivity.onResume", "mFirstLaunch true, displaying fragment"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 530 | displayFragment(getIntent()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 531 | } else if (!phoneIsInUse() && inCallDialpadUp) { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 532 | LogUtil.i("DialtactsActivity.onResume", "phone not in use, hiding dialpad fragment"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 533 | hideDialpadFragment(false, true); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 534 | inCallDialpadUp = false; |
| 535 | } else if (isDialpadShown) { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 536 | LogUtil.i("DialtactsActivity.onResume", "showing dialpad on resume"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 537 | showDialpadFragment(false); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 538 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 539 | PostCall.promptUserForMessageIfNecessary(this, parentLayout); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 540 | } |
| 541 | |
twyen | bd73e9d | 2017-09-26 16:06:32 -0700 | [diff] [blame] | 542 | // On M the fragment manager does not restore the hidden state of a fragment from |
| 543 | // savedInstanceState so it must be hidden again. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 544 | if (!isDialpadShown && dialpadFragment != null && !dialpadFragment.isHidden()) { |
twyen | bd73e9d | 2017-09-26 16:06:32 -0700 | [diff] [blame] | 545 | LogUtil.i( |
| 546 | "DialtactsActivity.onResume", "mDialpadFragment attached but not hidden, forcing hide"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 547 | getFragmentManager().beginTransaction().hide(dialpadFragment).commit(); |
twyen | bd73e9d | 2017-09-26 16:06:32 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 550 | // If there was a voice query result returned in the {@link #onActivityResult} callback, it |
| 551 | // will have been stashed in mVoiceSearchQuery since the search results fragment cannot be |
| 552 | // shown until onResume has completed. Active the search UI and set the search term now. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 553 | if (!TextUtils.isEmpty(voiceSearchQuery)) { |
| 554 | actionBarController.onSearchBoxTapped(); |
| 555 | searchView.setText(voiceSearchQuery); |
| 556 | voiceSearchQuery = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 557 | } |
| 558 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 559 | if (isRestarting) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 560 | // This is only called when the activity goes from resumed -> paused -> resumed, so it |
| 561 | // will not cause an extra view to be sent out on rotation |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 562 | if (isDialpadShown) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 563 | Logger.get(this).logScreenView(ScreenEvent.Type.DIALPAD, this); |
| 564 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 565 | isRestarting = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | prepareVoiceSearchButton(); |
linyuh | c9b3581 | 2017-12-28 09:58:34 -0800 | [diff] [blame] | 569 | |
| 570 | // Start the thread that updates the smart dial database if |
| 571 | // (1) the activity is not recreated with a new configuration, or |
| 572 | // (2) the activity is recreated with a new configuration but the change is a language change. |
| 573 | boolean isLanguageChanged = |
| 574 | !CompatUtils.getLocale(this).getISO3Language().equals(savedLanguageCode); |
| 575 | if (!wasConfigurationChange || isLanguageChanged) { |
| 576 | dialerDatabaseHelper.startSmartDialUpdateThread(/* forceUpdate = */ isLanguageChanged); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 577 | } |
linyuh | c9b3581 | 2017-12-28 09:58:34 -0800 | [diff] [blame] | 578 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 579 | if (isDialpadShown) { |
| 580 | floatingActionButtonController.scaleOut(); |
zachh | 6050ec2 | 2017-09-21 16:02:35 -0700 | [diff] [blame] | 581 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 582 | floatingActionButtonController.align(getFabAlignment(), false /* animate */); |
zachh | 6050ec2 | 2017-09-21 16:02:35 -0700 | [diff] [blame] | 583 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 584 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 585 | if (firstLaunch) { |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 586 | // Only process the Intent the first time onResume() is called after receiving it |
| 587 | if (Calls.CONTENT_TYPE.equals(getIntent().getType())) { |
| 588 | // Externally specified extras take precedence to EXTRA_SHOW_TAB, which is only |
| 589 | // used internally. |
| 590 | final Bundle extras = getIntent().getExtras(); |
| 591 | if (extras != null && extras.getInt(Calls.EXTRA_CALL_TYPE_FILTER) == Calls.VOICEMAIL_TYPE) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 592 | listsFragment.showTab(DialtactsPagerAdapter.TAB_INDEX_VOICEMAIL); |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 593 | Logger.get(this).logImpression(DialerImpression.Type.VVM_NOTIFICATION_CLICKED); |
| 594 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 595 | listsFragment.showTab(DialtactsPagerAdapter.TAB_INDEX_HISTORY); |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 596 | } |
| 597 | } else if (getIntent().hasExtra(EXTRA_SHOW_TAB)) { |
| 598 | int index = |
| 599 | getIntent().getIntExtra(EXTRA_SHOW_TAB, DialtactsPagerAdapter.TAB_INDEX_SPEED_DIAL); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 600 | if (index < listsFragment.getTabCount()) { |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 601 | // Hide dialpad since this is an explicit intent to show a specific tab, which is coming |
| 602 | // from missed call or voicemail notification. |
| 603 | hideDialpadFragment(false, false); |
| 604 | exitSearchUi(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 605 | listsFragment.showTab(index); |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 606 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 607 | } |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 608 | |
| 609 | if (getIntent().getBooleanExtra(EXTRA_CLEAR_NEW_VOICEMAILS, false)) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 610 | LogUtil.i("DialtactsActivity.onResume", "clearing all new voicemails"); |
| 611 | CallLogNotificationsService.markAllNewVoicemailsAsOld(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 612 | } |
weijiaxu | 650e7cc | 2017-10-31 12:38:54 -0700 | [diff] [blame] | 613 | // add 1 sec delay to get memory snapshot so that dialer wont react slowly on resume. |
| 614 | ThreadUtil.postDelayedOnUiThread( |
weijiaxu | c950a9b | 2017-11-06 16:39:04 -0800 | [diff] [blame] | 615 | () -> |
zachh | 7a96dc7 | 2018-02-20 22:16:03 -0800 | [diff] [blame] | 616 | MetricsComponent.get(this) |
| 617 | .metrics() |
| 618 | .recordMemory(Metrics.DIALTACTS_ON_RESUME_MEMORY_EVENT_NAME), |
weijiaxu | 650e7cc | 2017-10-31 12:38:54 -0700 | [diff] [blame] | 619 | 1000); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 620 | } |
| 621 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 622 | firstLaunch = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 623 | |
| 624 | setSearchBoxHint(); |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 625 | timeTabSelected = SystemClock.elapsedRealtime(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 626 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 627 | p13nLogger.reset(); |
| 628 | p13nRanker.refresh( |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 629 | new P13nRefreshCompleteListener() { |
| 630 | @Override |
| 631 | public void onP13nRefreshComplete() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 632 | // TODO(strongarm): make zero-query search results visible |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 633 | } |
| 634 | }); |
| 635 | Trace.endSection(); |
| 636 | } |
| 637 | |
| 638 | @Override |
| 639 | protected void onRestart() { |
| 640 | super.onRestart(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 641 | isRestarting = true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | @Override |
| 645 | protected void onPause() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 646 | if (clearSearchOnPause) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 647 | hideDialpadAndSearchUi(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 648 | clearSearchOnPause = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 649 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 650 | if (slideOut.hasStarted() && !slideOut.hasEnded()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 651 | commitDialpadFragmentHide(); |
| 652 | } |
| 653 | super.onPause(); |
| 654 | } |
| 655 | |
| 656 | @Override |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 657 | protected void onStop() { |
| 658 | super.onStop(); |
| 659 | boolean timeoutElapsed = |
| 660 | SystemClock.elapsedRealtime() - timeTabSelected >= HISTORY_TAB_SEEN_TIMEOUT; |
| 661 | boolean isOnHistoryTab = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 662 | listsFragment.getCurrentTabIndex() == DialtactsPagerAdapter.TAB_INDEX_HISTORY; |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 663 | if (isOnHistoryTab |
| 664 | && timeoutElapsed |
| 665 | && !isChangingConfigurations() |
| 666 | && !getSystemService(KeyguardManager.class).isKeyguardLocked()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 667 | listsFragment.markMissedCallsAsReadAndRemoveNotifications(); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 668 | } |
linyuh | 168d09c | 2017-10-26 17:04:30 -0700 | [diff] [blame] | 669 | StorageComponent.get(this) |
| 670 | .unencryptedSharedPrefs() |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 671 | .edit() |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 672 | .putInt(KEY_LAST_TAB, listsFragment.getCurrentTabIndex()) |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 673 | .apply(); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | @Override |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 677 | protected void onSaveInstanceState(Bundle outState) { |
zachh | 6050ec2 | 2017-09-21 16:02:35 -0700 | [diff] [blame] | 678 | LogUtil.enterBlock("DialtactsActivity.onSaveInstanceState"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 679 | super.onSaveInstanceState(outState); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 680 | outState.putString(KEY_SEARCH_QUERY, searchQuery); |
| 681 | outState.putString(KEY_DIALPAD_QUERY, dialpadQuery); |
linyuh | c9b3581 | 2017-12-28 09:58:34 -0800 | [diff] [blame] | 682 | outState.putString(KEY_SAVED_LANGUAGE_CODE, CompatUtils.getLocale(this).getISO3Language()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 683 | outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, inRegularSearch); |
| 684 | outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, inDialpadSearch); |
| 685 | outState.putBoolean(KEY_IN_NEW_SEARCH_UI, inNewSearch); |
| 686 | outState.putBoolean(KEY_FIRST_LAUNCH, firstLaunch); |
| 687 | outState.putBoolean(KEY_IS_DIALPAD_SHOWN, isDialpadShown); |
| 688 | outState.putBoolean(KEY_FAB_VISIBLE, floatingActionButtonController.isVisible()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 689 | outState.putBoolean(KEY_WAS_CONFIGURATION_CHANGE, isChangingConfigurations()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 690 | actionBarController.saveInstanceState(outState); |
| 691 | stateSaved = true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | @Override |
| 695 | public void onAttachFragment(final Fragment fragment) { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 696 | LogUtil.i("DialtactsActivity.onAttachFragment", "fragment: %s", fragment); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 697 | if (fragment instanceof DialpadFragment) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 698 | dialpadFragment = (DialpadFragment) fragment; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 699 | } else if (fragment instanceof SmartDialSearchFragment) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 700 | smartDialSearchFragment = (SmartDialSearchFragment) fragment; |
| 701 | smartDialSearchFragment.setOnPhoneNumberPickerActionListener(this); |
| 702 | if (!TextUtils.isEmpty(dialpadQuery)) { |
| 703 | smartDialSearchFragment.setAddToContactNumber(dialpadQuery); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 704 | } |
| 705 | } else if (fragment instanceof SearchFragment) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 706 | regularSearchFragment = (RegularSearchFragment) fragment; |
| 707 | regularSearchFragment.setOnPhoneNumberPickerActionListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 708 | } else if (fragment instanceof ListsFragment) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 709 | listsFragment = (ListsFragment) fragment; |
| 710 | listsFragment.addOnPageChangeListener(this); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 711 | } else if (fragment instanceof NewSearchFragment) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 712 | newSearchFragment = (NewSearchFragment) fragment; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 713 | updateSearchFragmentPosition(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 714 | } |
| 715 | if (fragment instanceof SearchFragment) { |
| 716 | final SearchFragment searchFragment = (SearchFragment) fragment; |
| 717 | searchFragment.setReranker( |
| 718 | new CursorReranker() { |
| 719 | @Override |
| 720 | @MainThread |
| 721 | public Cursor rerankCursor(Cursor data) { |
| 722 | Assert.isMainThread(); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 723 | String queryString = searchFragment.getQueryString(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 724 | return p13nRanker.rankCursor(data, queryString == null ? 0 : queryString.length()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 725 | } |
| 726 | }); |
| 727 | searchFragment.addOnLoadFinishedListener( |
| 728 | new OnLoadFinishedListener() { |
| 729 | @Override |
| 730 | public void onLoadFinished() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 731 | p13nLogger.onSearchQuery( |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 732 | searchFragment.getQueryString(), |
| 733 | (PhoneNumberListAdapter) searchFragment.getAdapter()); |
| 734 | } |
| 735 | }); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | protected void handleMenuSettings() { |
| 740 | final Intent intent = new Intent(this, DialerSettingsActivity.class); |
| 741 | startActivity(intent); |
| 742 | } |
| 743 | |
Android Dialer | 3f89169 | 2017-10-25 11:43:41 -0700 | [diff] [blame] | 744 | public boolean isListsFragmentVisible() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 745 | return listsFragment.getUserVisibleHint(); |
Android Dialer | 3f4a319 | 2017-09-20 17:59:44 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 748 | @Override |
| 749 | public void onClick(View view) { |
| 750 | int resId = view.getId(); |
| 751 | if (resId == R.id.floating_action_button) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 752 | if (!isDialpadShown) { |
yueg | 49df7f6 | 2017-09-12 15:15:27 -0700 | [diff] [blame] | 753 | LogUtil.i( |
| 754 | "DialtactsActivity.onClick", "floating action button clicked, going to show dialpad"); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 755 | PerformanceReport.recordClick(UiAction.Type.OPEN_DIALPAD); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 756 | inCallDialpadUp = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 757 | showDialpadFragment(true); |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 758 | PostCall.closePrompt(); |
yueg | 49df7f6 | 2017-09-12 15:15:27 -0700 | [diff] [blame] | 759 | } else { |
| 760 | LogUtil.i( |
| 761 | "DialtactsActivity.onClick", |
| 762 | "floating action button clicked, but dialpad is already showing"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 763 | } |
| 764 | } else if (resId == R.id.voice_search_button) { |
| 765 | try { |
| 766 | startActivityForResult( |
| 767 | new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 768 | ActivityRequestCodes.DIALTACTS_VOICE_SEARCH); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 769 | } catch (ActivityNotFoundException e) { |
| 770 | Toast.makeText( |
| 771 | DialtactsActivity.this, R.string.voice_search_not_available, Toast.LENGTH_SHORT) |
| 772 | .show(); |
| 773 | } |
| 774 | } else if (resId == R.id.dialtacts_options_menu_button) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 775 | overflowMenu.show(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 776 | } else { |
| 777 | Assert.fail("Unexpected onClick event from " + view); |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | @Override |
| 782 | public boolean onMenuItemClick(MenuItem item) { |
| 783 | if (!isSafeToCommitTransactions()) { |
| 784 | return true; |
| 785 | } |
| 786 | |
| 787 | int resId = item.getItemId(); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 788 | if (resId == R.id.menu_history) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 789 | PerformanceReport.recordClick(UiAction.Type.OPEN_CALL_HISTORY); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 790 | final Intent intent = new Intent(this, CallLogActivity.class); |
| 791 | startActivity(intent); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 792 | } else if (resId == R.id.menu_clear_frequents) { |
| 793 | ClearFrequentsDialog.show(getFragmentManager()); |
| 794 | Logger.get(this).logScreenView(ScreenEvent.Type.CLEAR_FREQUENTS, this); |
| 795 | return true; |
| 796 | } else if (resId == R.id.menu_call_settings) { |
| 797 | handleMenuSettings(); |
| 798 | Logger.get(this).logScreenView(ScreenEvent.Type.SETTINGS, this); |
| 799 | return true; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 800 | } else if (resId == R.id.menu_new_ui_launcher_shortcut) { |
calderwoodra | 9f16e17 | 2018-01-29 19:18:14 -0800 | [diff] [blame] | 801 | MainComponent.createNewUiLauncherShortcut(this); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 802 | return true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 803 | } |
| 804 | return false; |
| 805 | } |
| 806 | |
| 807 | @Override |
| 808 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 809 | LogUtil.i( |
| 810 | "DialtactsActivity.onActivityResult", |
| 811 | "requestCode:%d, resultCode:%d", |
| 812 | requestCode, |
| 813 | resultCode); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 814 | if (requestCode == ActivityRequestCodes.DIALTACTS_VOICE_SEARCH) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 815 | if (resultCode == RESULT_OK) { |
| 816 | final ArrayList<String> matches = |
| 817 | data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); |
| 818 | if (matches.size() > 0) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 819 | voiceSearchQuery = matches.get(0); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 820 | } else { |
| 821 | LogUtil.i("DialtactsActivity.onActivityResult", "voice search - nothing heard"); |
| 822 | } |
| 823 | } else { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 824 | LogUtil.e("DialtactsActivity.onActivityResult", "voice search failed"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 825 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 826 | } else if (requestCode == ActivityRequestCodes.DIALTACTS_CALL_COMPOSER) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 827 | if (resultCode == RESULT_FIRST_USER) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 828 | LogUtil.i( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 829 | "DialtactsActivity.onActivityResult", "returned from call composer, error occurred"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 830 | String message = |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 831 | getString( |
| 832 | R.string.call_composer_connection_failed, |
| 833 | data.getStringExtra(CallComposerActivity.KEY_CONTACT_NAME)); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 834 | Snackbar.make(parentLayout, message, Snackbar.LENGTH_LONG).show(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 835 | } else { |
| 836 | LogUtil.i("DialtactsActivity.onActivityResult", "returned from call composer, no error"); |
| 837 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 838 | } else if (requestCode == ActivityRequestCodes.DIALTACTS_CALL_DETAILS) { |
| 839 | if (resultCode == RESULT_OK |
| 840 | && data != null |
| 841 | && data.getBooleanExtra(CallDetailsActivity.EXTRA_HAS_ENRICHED_CALL_DATA, false)) { |
| 842 | String number = data.getStringExtra(CallDetailsActivity.EXTRA_PHONE_NUMBER); |
| 843 | int snackbarDurationMillis = 5_000; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 844 | Snackbar.make(parentLayout, getString(R.string.ec_data_deleted), snackbarDurationMillis) |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 845 | .setAction( |
| 846 | R.string.view_conversation, |
| 847 | v -> startActivity(IntentProvider.getSendSmsIntentProvider(number).getIntent(this))) |
| 848 | .setActionTextColor(getResources().getColor(R.color.dialer_snackbar_action_text_color)) |
| 849 | .show(); |
| 850 | } |
roldenburg | 19c6c25 | 2017-12-13 15:58:01 -0800 | [diff] [blame] | 851 | } else if (requestCode == ActivityRequestCodes.DIALTACTS_DUO) { |
| 852 | // We just returned from starting Duo for a task. Reload our reachability data since it |
| 853 | // may have changed after a user finished activating Duo. |
| 854 | DuoComponent.get(this).getDuo().reloadReachability(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 855 | } |
| 856 | super.onActivityResult(requestCode, resultCode, data); |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * Update the number of unread voicemails (potentially other tabs) displayed next to the tab icon. |
| 861 | */ |
| 862 | public void updateTabUnreadCounts() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 863 | listsFragment.updateTabUnreadCounts(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | /** |
| 867 | * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual |
| 868 | * updates are handled by a callback which is invoked after the dialpad fragment is shown. |
| 869 | * |
| 870 | * @see #onDialpadShown |
| 871 | */ |
| 872 | private void showDialpadFragment(boolean animate) { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 873 | LogUtil.i("DialtactActivity.showDialpadFragment", "animate: %b", animate); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 874 | if (isDialpadShown) { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 875 | LogUtil.i("DialtactsActivity.showDialpadFragment", "dialpad already shown"); |
| 876 | return; |
| 877 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 878 | if (stateSaved) { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 879 | LogUtil.i("DialtactsActivity.showDialpadFragment", "state already saved"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 880 | return; |
| 881 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 882 | isDialpadShown = true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 883 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 884 | listsFragment.setUserVisibleHint(false); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 885 | |
| 886 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 887 | if (dialpadFragment == null) { |
| 888 | dialpadFragment = new DialpadFragment(); |
| 889 | ft.add(R.id.dialtacts_container, dialpadFragment, TAG_DIALPAD_FRAGMENT); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 890 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 891 | ft.show(dialpadFragment); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 892 | } |
| 893 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 894 | dialpadFragment.setAnimate(animate); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 895 | Logger.get(this).logScreenView(ScreenEvent.Type.DIALPAD, this); |
| 896 | ft.commit(); |
| 897 | |
| 898 | if (animate) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 899 | floatingActionButtonController.scaleOut(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 900 | maybeEnterSearchUi(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 901 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 902 | floatingActionButtonController.scaleOut(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 903 | maybeEnterSearchUi(); |
| 904 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 905 | actionBarController.onDialpadUp(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 906 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 907 | Assert.isNotNull(listsFragment.getView()).animate().alpha(0).withLayer(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 908 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 909 | // adjust the title, so the user will know where we're at when the activity start/resumes. |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 910 | setTitle(R.string.launcherDialpadActivityLabel); |
| 911 | } |
| 912 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 913 | @Override |
| 914 | public void getLastOutgoingCall(LastOutgoingCallCallback callback) { |
calderwoodra | 97d0b5e | 2018-01-26 12:11:26 -0800 | [diff] [blame] | 915 | DialerExecutorComponent.get(this) |
| 916 | .dialerExecutorFactory() |
| 917 | .createUiTaskBuilder( |
| 918 | getFragmentManager(), "Query last phone number", Calls::getLastOutgoingCall) |
| 919 | .onSuccess(output -> callback.lastOutgoingCall(output)) |
| 920 | .build() |
| 921 | .executeParallel(this); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 924 | /** Callback from child DialpadFragment when the dialpad is shown. */ |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 925 | @Override |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 926 | public void onDialpadShown() { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 927 | LogUtil.enterBlock("DialtactsActivity.onDialpadShown"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 928 | Assert.isNotNull(dialpadFragment); |
| 929 | if (dialpadFragment.getAnimate()) { |
| 930 | Assert.isNotNull(dialpadFragment.getView()).startAnimation(slideIn); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 931 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 932 | dialpadFragment.setYFraction(0); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | updateSearchFragmentPosition(); |
| 936 | } |
| 937 | |
calderwoodra | 5071526 | 2017-09-08 09:20:08 -0700 | [diff] [blame] | 938 | @Override |
| 939 | public void onCallPlacedFromDialpad() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 940 | clearSearchOnPause = true; |
calderwoodra | 5071526 | 2017-09-08 09:20:08 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Android Dialer | 3f4a319 | 2017-09-20 17:59:44 -0700 | [diff] [blame] | 943 | @Override |
Android Dialer | e8d7752 | 2017-10-16 11:33:58 -0700 | [diff] [blame] | 944 | public void onContactsListScrolled(boolean isDragging) { |
Android Dialer | 3f4a319 | 2017-09-20 17:59:44 -0700 | [diff] [blame] | 945 | // intentionally empty. |
| 946 | } |
| 947 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 948 | /** |
| 949 | * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in a |
| 950 | * callback after the hide animation ends. |
| 951 | * |
| 952 | * @see #commitDialpadFragmentHide |
| 953 | */ |
calderwoodra | 5071526 | 2017-09-08 09:20:08 -0700 | [diff] [blame] | 954 | private void hideDialpadFragment(boolean animate, boolean clearDialpad) { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 955 | LogUtil.enterBlock("DialtactsActivity.hideDialpadFragment"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 956 | if (dialpadFragment == null || dialpadFragment.getView() == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 957 | return; |
| 958 | } |
| 959 | if (clearDialpad) { |
| 960 | // Temporarily disable accessibility when we clear the dialpad, since it should be |
| 961 | // invisible and should not announce anything. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 962 | dialpadFragment |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 963 | .getDigitsWidget() |
| 964 | .setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 965 | dialpadFragment.clearDialpad(); |
| 966 | dialpadFragment |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 967 | .getDigitsWidget() |
| 968 | .setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO); |
| 969 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 970 | if (!isDialpadShown) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 971 | return; |
| 972 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 973 | isDialpadShown = false; |
| 974 | dialpadFragment.setAnimate(animate); |
| 975 | listsFragment.setUserVisibleHint(true); |
| 976 | listsFragment.sendScreenViewForCurrentPosition(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 977 | |
| 978 | updateSearchFragmentPosition(); |
| 979 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 980 | floatingActionButtonController.align(getFabAlignment(), animate); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 981 | if (animate) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 982 | dialpadFragment.getView().startAnimation(slideOut); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 983 | } else { |
| 984 | commitDialpadFragmentHide(); |
| 985 | } |
| 986 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 987 | actionBarController.onDialpadDown(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 988 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 989 | // reset the title to normal. |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 990 | setTitle(R.string.launcherActivityLabel); |
| 991 | } |
| 992 | |
| 993 | /** Finishes hiding the dialpad fragment after any animations are completed. */ |
| 994 | private void commitDialpadFragmentHide() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 995 | if (!stateSaved && dialpadFragment != null && !dialpadFragment.isHidden() && !isDestroyed()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 996 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 997 | ft.hide(dialpadFragment); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 998 | ft.commit(); |
| 999 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1000 | floatingActionButtonController.scaleIn(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | private void updateSearchFragmentPosition() { |
| 1004 | SearchFragment fragment = null; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1005 | if (smartDialSearchFragment != null) { |
| 1006 | fragment = smartDialSearchFragment; |
| 1007 | } else if (regularSearchFragment != null) { |
| 1008 | fragment = regularSearchFragment; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1009 | } |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1010 | LogUtil.d( |
| 1011 | "DialtactsActivity.updateSearchFragmentPosition", |
| 1012 | "fragment: %s, isVisible: %b", |
| 1013 | fragment, |
| 1014 | fragment != null && fragment.isVisible()); |
| 1015 | if (fragment != null) { |
| 1016 | // We need to force animation here even when fragment is not visible since it might not be |
| 1017 | // visible immediately after screen orientation change and dialpad height would not be |
| 1018 | // available immediately which is required to update position. By forcing an animation, |
| 1019 | // position will be updated after a delay by when the dialpad height would be available. |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1020 | fragment.updatePosition(true /* animate */); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1021 | } else if (newSearchFragment != null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1022 | int animationDuration = getResources().getInteger(R.integer.dialpad_slide_in_duration); |
| 1023 | int actionbarHeight = getResources().getDimensionPixelSize(R.dimen.action_bar_height_large); |
| 1024 | int shadowHeight = getResources().getDrawable(R.drawable.search_shadow).getIntrinsicHeight(); |
| 1025 | int start = isDialpadShown() ? actionbarHeight - shadowHeight : 0; |
| 1026 | int end = isDialpadShown() ? 0 : actionbarHeight - shadowHeight; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1027 | newSearchFragment.animatePosition(start, end, animationDuration); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | @Override |
| 1032 | public boolean isInSearchUi() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1033 | return inDialpadSearch || inRegularSearch || inNewSearch; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | @Override |
| 1037 | public boolean hasSearchQuery() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1038 | return !TextUtils.isEmpty(searchQuery); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1039 | } |
| 1040 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1041 | private void setNotInSearchUi() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1042 | inDialpadSearch = false; |
| 1043 | inRegularSearch = false; |
| 1044 | inNewSearch = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | private void hideDialpadAndSearchUi() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1048 | if (isDialpadShown) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1049 | hideDialpadFragment(false, true); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1050 | } |
calderwoodra | e51ca38 | 2017-11-21 10:54:36 -0800 | [diff] [blame] | 1051 | exitSearchUi(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | private void prepareVoiceSearchButton() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1055 | searchEditTextLayout.setVoiceSearchEnabled(isVoiceSearchEnabled()); |
| 1056 | voiceSearchButton.setOnClickListener(this); |
twyen | 891fe0f | 2017-10-17 14:59:15 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | private boolean isVoiceSearchEnabled() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1060 | if (voiceSearchEnabledForTest.isPresent()) { |
| 1061 | return voiceSearchEnabledForTest.get(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1062 | } |
twyen | 891fe0f | 2017-10-17 14:59:15 -0700 | [diff] [blame] | 1063 | return canIntentBeHandled(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | public boolean isNearbyPlacesSearchEnabled() { |
| 1067 | return false; |
| 1068 | } |
| 1069 | |
| 1070 | protected int getSearchBoxHint() { |
| 1071 | return R.string.dialer_hint_find_contact; |
| 1072 | } |
| 1073 | |
| 1074 | /** Sets the hint text for the contacts search box */ |
| 1075 | private void setSearchBoxHint() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1076 | ((TextView) searchEditTextLayout.findViewById(R.id.search_box_start_search)) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1077 | .setHint(getSearchBoxHint()); |
| 1078 | } |
| 1079 | |
| 1080 | protected OptionsPopupMenu buildOptionsMenu(View invoker) { |
| 1081 | final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker); |
| 1082 | popupMenu.inflate(R.menu.dialtacts_options); |
| 1083 | popupMenu.setOnMenuItemClickListener(this); |
| 1084 | return popupMenu; |
| 1085 | } |
| 1086 | |
| 1087 | @Override |
| 1088 | public boolean onCreateOptionsMenu(Menu menu) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1089 | if (pendingSearchViewQuery != null) { |
| 1090 | searchView.setText(pendingSearchViewQuery); |
| 1091 | pendingSearchViewQuery = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1092 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1093 | if (actionBarController != null) { |
| 1094 | actionBarController.restoreActionBarOffset(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1095 | } |
| 1096 | return false; |
| 1097 | } |
| 1098 | |
| 1099 | /** |
| 1100 | * Returns true if the intent is due to hitting the green send key (hardware call button: |
| 1101 | * KEYCODE_CALL) while in a call. |
| 1102 | * |
| 1103 | * @param intent the intent that launched this activity |
| 1104 | * @return true if the intent is due to hitting the green send key while in a call |
| 1105 | */ |
| 1106 | private boolean isSendKeyWhileInCall(Intent intent) { |
| 1107 | // If there is a call in progress and the user launched the dialer by hitting the call |
| 1108 | // button, go straight to the in-call screen. |
| 1109 | final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction()); |
| 1110 | |
| 1111 | // When KEYCODE_CALL event is handled it dispatches an intent with the ACTION_CALL_BUTTON. |
| 1112 | // Besides of checking the intent action, we must check if the phone is really during a |
| 1113 | // call in order to decide whether to ignore the event or continue to display the activity. |
| 1114 | if (callKey && phoneIsInUse()) { |
| 1115 | TelecomUtil.showInCallScreen(this, false); |
| 1116 | return true; |
| 1117 | } |
| 1118 | |
| 1119 | return false; |
| 1120 | } |
| 1121 | |
| 1122 | /** |
| 1123 | * Sets the current tab based on the intent's request type |
| 1124 | * |
| 1125 | * @param intent Intent that contains information about which tab should be selected |
| 1126 | */ |
| 1127 | private void displayFragment(Intent intent) { |
| 1128 | // If we got here by hitting send and we're in call forward along to the in-call activity |
| 1129 | if (isSendKeyWhileInCall(intent)) { |
| 1130 | finish(); |
| 1131 | return; |
| 1132 | } |
| 1133 | |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 1134 | boolean showDialpadChooser = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1135 | !ACTION_SHOW_TAB.equals(intent.getAction()) |
| 1136 | && phoneIsInUse() |
| 1137 | && !DialpadFragment.isAddCallMode(intent); |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 1138 | boolean isDialIntent = intent.getData() != null && isDialIntent(intent); |
calderwoodra | 48cce92 | 2017-09-14 14:28:46 -0700 | [diff] [blame] | 1139 | boolean isAddCallIntent = DialpadFragment.isAddCallMode(intent); |
| 1140 | if (showDialpadChooser || isDialIntent || isAddCallIntent) { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 1141 | LogUtil.i( |
| 1142 | "DialtactsActivity.displayFragment", |
calderwoodra | 48cce92 | 2017-09-14 14:28:46 -0700 | [diff] [blame] | 1143 | "show dialpad fragment (showDialpadChooser: %b, isDialIntent: %b, isAddCallIntent: %b)", |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 1144 | showDialpadChooser, |
calderwoodra | 48cce92 | 2017-09-14 14:28:46 -0700 | [diff] [blame] | 1145 | isDialIntent, |
| 1146 | isAddCallIntent); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1147 | showDialpadFragment(false); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1148 | dialpadFragment.setStartedFromNewIntent(true); |
| 1149 | if (showDialpadChooser && !dialpadFragment.isVisible()) { |
| 1150 | inCallDialpadUp = true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1151 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1152 | } else if (isLastTabEnabled) { |
| 1153 | @TabIndex |
| 1154 | int tabIndex = |
linyuh | 168d09c | 2017-10-26 17:04:30 -0700 | [diff] [blame] | 1155 | StorageComponent.get(this) |
| 1156 | .unencryptedSharedPrefs() |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1157 | .getInt(KEY_LAST_TAB, DialtactsPagerAdapter.TAB_INDEX_SPEED_DIAL); |
| 1158 | // If voicemail tab is saved and its availability changes, we still move to the voicemail tab |
| 1159 | // but it is quickly removed and shown the contacts tab. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1160 | if (listsFragment != null) { |
| 1161 | listsFragment.showTab(tabIndex); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1162 | PerformanceReport.setStartingTabIndex(tabIndex); |
| 1163 | } else { |
| 1164 | PerformanceReport.setStartingTabIndex(DialtactsPagerAdapter.TAB_INDEX_SPEED_DIAL); |
| 1165 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | @Override |
| 1170 | public void onNewIntent(Intent newIntent) { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 1171 | LogUtil.enterBlock("DialtactsActivity.onNewIntent"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1172 | setIntent(newIntent); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1173 | firstLaunch = true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1174 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1175 | stateSaved = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1176 | displayFragment(newIntent); |
| 1177 | |
| 1178 | invalidateOptionsMenu(); |
| 1179 | } |
| 1180 | |
| 1181 | /** Returns true if the given intent contains a phone number to populate the dialer with */ |
| 1182 | private boolean isDialIntent(Intent intent) { |
| 1183 | final String action = intent.getAction(); |
| 1184 | if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) { |
| 1185 | return true; |
| 1186 | } |
| 1187 | if (Intent.ACTION_VIEW.equals(action)) { |
| 1188 | final Uri data = intent.getData(); |
| 1189 | if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) { |
| 1190 | return true; |
| 1191 | } |
| 1192 | } |
| 1193 | return false; |
| 1194 | } |
| 1195 | |
| 1196 | /** Shows the search fragment */ |
| 1197 | private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 1198 | LogUtil.i("DialtactsActivity.enterSearchUi", "smart dial: %b", smartDialSearch); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1199 | if (stateSaved || getFragmentManager().isDestroyed()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1200 | // Weird race condition where fragment is doing work after the activity is destroyed |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 1201 | // due to talkback being on (a bug). Just return since we can't do any |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1202 | // constructive here. |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 1203 | LogUtil.i( |
| 1204 | "DialtactsActivity.enterSearchUi", |
| 1205 | "not entering search UI (mStateSaved: %b, isDestroyed: %b)", |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1206 | stateSaved, |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 1207 | getFragmentManager().isDestroyed()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1208 | return; |
| 1209 | } |
| 1210 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1211 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1212 | if (inDialpadSearch && smartDialSearchFragment != null) { |
| 1213 | transaction.remove(smartDialSearchFragment); |
| 1214 | } else if (inRegularSearch && regularSearchFragment != null) { |
| 1215 | transaction.remove(regularSearchFragment); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | final String tag; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1219 | inDialpadSearch = false; |
| 1220 | inRegularSearch = false; |
| 1221 | inNewSearch = false; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1222 | boolean useNewSearch = |
| 1223 | ConfigProviderBindings.get(this).getBoolean("enable_new_search_fragment", false); |
| 1224 | if (useNewSearch) { |
| 1225 | tag = TAG_NEW_SEARCH_FRAGMENT; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1226 | inNewSearch = true; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1227 | } else if (smartDialSearch) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1228 | tag = TAG_SMARTDIAL_SEARCH_FRAGMENT; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1229 | inDialpadSearch = true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1230 | } else { |
| 1231 | tag = TAG_REGULAR_SEARCH_FRAGMENT; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1232 | inRegularSearch = true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1233 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1234 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1235 | floatingActionButtonController.scaleOut(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1236 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1237 | if (animate) { |
| 1238 | transaction.setCustomAnimations(android.R.animator.fade_in, 0); |
| 1239 | } else { |
| 1240 | transaction.setTransition(FragmentTransaction.TRANSIT_NONE); |
| 1241 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1242 | |
| 1243 | Fragment fragment = getFragmentManager().findFragmentByTag(tag); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1244 | if (fragment == null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1245 | if (useNewSearch) { |
calderwoodra | 218fff3 | 2017-09-19 11:20:31 -0700 | [diff] [blame] | 1246 | fragment = NewSearchFragment.newInstance(!isDialpadShown()); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1247 | } else if (smartDialSearch) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1248 | fragment = new SmartDialSearchFragment(); |
| 1249 | } else { |
| 1250 | fragment = Bindings.getLegacy(this).newRegularSearchFragment(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1251 | ((SearchFragment) fragment) |
| 1252 | .setOnTouchListener( |
| 1253 | (v, event) -> { |
| 1254 | // Show the FAB when the user touches the lists fragment and the soft |
| 1255 | // keyboard is hidden. |
| 1256 | hideDialpadFragment(true, false); |
| 1257 | v.performClick(); |
| 1258 | return false; |
| 1259 | }); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1260 | } |
| 1261 | transaction.add(R.id.dialtacts_frame, fragment, tag); |
| 1262 | } else { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1263 | // TODO(calderwoodra): if this is a transition from dialpad to searchbar, animate fragment |
| 1264 | // down, and vice versa. Perhaps just add a coordinator behavior with the search bar. |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1265 | transaction.show(fragment); |
| 1266 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1267 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1268 | // DialtactsActivity will provide the options menu |
| 1269 | fragment.setHasOptionsMenu(false); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1270 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1271 | // Will show empty list if P13nRanker is not enabled. Else, re-ranked list by the ranker. |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1272 | if (!useNewSearch) { |
| 1273 | ((SearchFragment) fragment) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1274 | .setShowEmptyListForNullQuery(p13nRanker.shouldShowEmptyListForNullQuery()); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1275 | } else { |
| 1276 | // TODO(calderwoodra): add p13n ranker to new search. |
| 1277 | } |
| 1278 | |
| 1279 | if (!smartDialSearch && !useNewSearch) { |
| 1280 | ((SearchFragment) fragment).setQueryString(query); |
| 1281 | } else if (useNewSearch) { |
calderwoodra | af3cc17 | 2017-09-01 23:28:21 -0700 | [diff] [blame] | 1282 | ((NewSearchFragment) fragment).setQuery(query, getCallInitiationType()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1283 | } |
| 1284 | transaction.commit(); |
| 1285 | |
| 1286 | if (animate) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1287 | Assert.isNotNull(listsFragment.getView()).animate().alpha(0).withLayer(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1288 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1289 | listsFragment.setUserVisibleHint(false); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1290 | |
| 1291 | if (smartDialSearch) { |
| 1292 | Logger.get(this).logScreenView(ScreenEvent.Type.SMART_DIAL_SEARCH, this); |
| 1293 | } else { |
| 1294 | Logger.get(this).logScreenView(ScreenEvent.Type.REGULAR_SEARCH, this); |
| 1295 | } |
| 1296 | } |
| 1297 | |
| 1298 | /** Hides the search fragment */ |
| 1299 | private void exitSearchUi() { |
zachh | cc2cde0 | 2017-08-31 12:34:18 -0700 | [diff] [blame] | 1300 | LogUtil.enterBlock("DialtactsActivity.exitSearchUi"); |
| 1301 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1302 | // See related bug in enterSearchUI(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1303 | if (getFragmentManager().isDestroyed() || stateSaved) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1304 | return; |
| 1305 | } |
| 1306 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1307 | searchView.setText(null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1308 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1309 | if (dialpadFragment != null) { |
| 1310 | dialpadFragment.clearDialpad(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | setNotInSearchUi(); |
| 1314 | |
calderwoodra | 6007f52 | 2017-10-09 16:59:04 -0700 | [diff] [blame] | 1315 | // There are four states the fab can be in: |
| 1316 | // - Not visible and should remain not visible (do nothing) |
| 1317 | // - Not visible (move then show the fab) |
| 1318 | // - Visible, in the correct position (do nothing) |
| 1319 | // - Visible, in the wrong position (hide, move, then show the fab) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1320 | if (floatingActionButtonController.isVisible() |
calderwoodra | 6007f52 | 2017-10-09 16:59:04 -0700 | [diff] [blame] | 1321 | && getFabAlignment() != FloatingActionButtonController.ALIGN_END) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1322 | floatingActionButtonController.scaleOut( |
calderwoodra | 6007f52 | 2017-10-09 16:59:04 -0700 | [diff] [blame] | 1323 | new OnVisibilityChangedListener() { |
| 1324 | @Override |
| 1325 | public void onHidden(FloatingActionButton floatingActionButton) { |
| 1326 | super.onHidden(floatingActionButton); |
| 1327 | onPageScrolled( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1328 | listsFragment.getCurrentTabIndex(), 0 /* offset */, 0 /* pixelOffset */); |
| 1329 | floatingActionButtonController.scaleIn(); |
calderwoodra | 6007f52 | 2017-10-09 16:59:04 -0700 | [diff] [blame] | 1330 | } |
| 1331 | }); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1332 | } else if (!floatingActionButtonController.isVisible() && listsFragment.shouldShowFab()) { |
| 1333 | onPageScrolled(listsFragment.getCurrentTabIndex(), 0 /* offset */, 0 /* pixelOffset */); |
calderwoodra | 6007f52 | 2017-10-09 16:59:04 -0700 | [diff] [blame] | 1334 | ThreadUtil.getUiThreadHandler() |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1335 | .postDelayed(() -> floatingActionButtonController.scaleIn(), FAB_SCALE_IN_DELAY_MS); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1336 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1337 | |
| 1338 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1339 | if (smartDialSearchFragment != null) { |
| 1340 | transaction.remove(smartDialSearchFragment); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1341 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1342 | if (regularSearchFragment != null) { |
| 1343 | transaction.remove(regularSearchFragment); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1344 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1345 | if (newSearchFragment != null) { |
| 1346 | transaction.remove(newSearchFragment); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1347 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1348 | transaction.commit(); |
| 1349 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1350 | Assert.isNotNull(listsFragment.getView()).animate().alpha(1).withLayer(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1351 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1352 | if (dialpadFragment == null || !dialpadFragment.isVisible()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1353 | // If the dialpad fragment wasn't previously visible, then send a screen view because |
| 1354 | // we are exiting regular search. Otherwise, the screen view will be sent by |
| 1355 | // {@link #hideDialpadFragment}. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1356 | listsFragment.sendScreenViewForCurrentPosition(); |
| 1357 | listsFragment.setUserVisibleHint(true); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1358 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1359 | onPageSelected(listsFragment.getCurrentTabIndex()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1360 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1361 | actionBarController.onSearchUiExited(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | @Override |
| 1365 | public void onBackPressed() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1366 | PerformanceReport.recordClick(UiAction.Type.PRESS_ANDROID_BACK_BUTTON); |
| 1367 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1368 | if (stateSaved) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1369 | return; |
| 1370 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1371 | if (isDialpadShown) { |
calderwoodra | ed4e11d | 2017-09-05 18:24:47 -0700 | [diff] [blame] | 1372 | hideDialpadFragment(true, false); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1373 | if (TextUtils.isEmpty(dialpadQuery)) { |
calderwoodra | ecb0456 | 2017-09-16 07:34:05 -0700 | [diff] [blame] | 1374 | exitSearchUi(); |
| 1375 | } |
calderwoodra | ed4e11d | 2017-09-05 18:24:47 -0700 | [diff] [blame] | 1376 | } else if (isInSearchUi()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1377 | if (isKeyboardOpen) { |
| 1378 | DialerUtils.hideInputMethod(parentLayout); |
calderwoodra | 5071526 | 2017-09-08 09:20:08 -0700 | [diff] [blame] | 1379 | PerformanceReport.recordClick(UiAction.Type.HIDE_KEYBOARD_IN_SEARCH); |
| 1380 | } else { |
| 1381 | exitSearchUi(); |
| 1382 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1383 | } else { |
| 1384 | super.onBackPressed(); |
| 1385 | } |
| 1386 | } |
| 1387 | |
calderwoodra | 5071526 | 2017-09-08 09:20:08 -0700 | [diff] [blame] | 1388 | @Override |
| 1389 | public void onConfigurationChanged(Configuration configuration) { |
| 1390 | super.onConfigurationChanged(configuration); |
| 1391 | // Checks whether a hardware keyboard is available |
| 1392 | if (configuration.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1393 | isKeyboardOpen = true; |
calderwoodra | 5071526 | 2017-09-08 09:20:08 -0700 | [diff] [blame] | 1394 | } else if (configuration.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1395 | isKeyboardOpen = false; |
calderwoodra | 5071526 | 2017-09-08 09:20:08 -0700 | [diff] [blame] | 1396 | } |
| 1397 | } |
| 1398 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1399 | private void maybeEnterSearchUi() { |
| 1400 | if (!isInSearchUi()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1401 | enterSearchUi(true /* isSmartDial */, searchQuery, false); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1402 | } |
| 1403 | } |
| 1404 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1405 | @Override |
| 1406 | public void onDialpadQueryChanged(String query) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1407 | dialpadQuery = query; |
| 1408 | if (smartDialSearchFragment != null) { |
| 1409 | smartDialSearchFragment.setAddToContactNumber(query); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1410 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1411 | if (newSearchFragment != null) { |
| 1412 | newSearchFragment.setRawNumber(query); |
wangqi | e9f94c7 | 2017-11-10 11:51:50 -0800 | [diff] [blame] | 1413 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1414 | final String normalizedQuery = |
linyuh | ab14653 | 2017-12-19 11:28:51 -0800 | [diff] [blame] | 1415 | SmartDialNameMatcher.normalizeNumber(/* context = */ this, query); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1416 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1417 | if (!TextUtils.equals(searchView.getText(), normalizedQuery)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1418 | if (DEBUG) { |
| 1419 | LogUtil.v("DialtactsActivity.onDialpadQueryChanged", "new query: " + query); |
| 1420 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1421 | if (dialpadFragment == null || !dialpadFragment.isVisible()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1422 | // This callback can happen if the dialpad fragment is recreated because of |
| 1423 | // activity destruction. In that case, don't update the search view because |
| 1424 | // that would bring the user back to the search fragment regardless of the |
| 1425 | // previous state of the application. Instead, just return here and let the |
| 1426 | // fragment manager correctly figure out whatever fragment was last displayed. |
| 1427 | if (!TextUtils.isEmpty(normalizedQuery)) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1428 | pendingSearchViewQuery = normalizedQuery; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1429 | } |
| 1430 | return; |
| 1431 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1432 | searchView.setText(normalizedQuery); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | try { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1436 | if (dialpadFragment != null && dialpadFragment.isVisible()) { |
| 1437 | dialpadFragment.process_quote_emergency_unquote(normalizedQuery); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1438 | } |
| 1439 | } catch (Exception ignored) { |
| 1440 | // Skip any exceptions for this piece of code |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | @Override |
| 1445 | public boolean onDialpadSpacerTouchWithEmptyQuery() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1446 | if (inDialpadSearch |
| 1447 | && smartDialSearchFragment != null |
| 1448 | && !smartDialSearchFragment.isShowingPermissionRequest()) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1449 | PerformanceReport.recordClick(UiAction.Type.CLOSE_DIALPAD); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1450 | hideDialpadFragment(true /* animate */, true /* clearDialpad */); |
| 1451 | return true; |
| 1452 | } |
| 1453 | return false; |
| 1454 | } |
| 1455 | |
| 1456 | @Override |
calderwoodra | 76cf7e1 | 2018-02-28 17:10:18 -0800 | [diff] [blame] | 1457 | public boolean shouldShowDialpadChooser() { |
| 1458 | // Show the dialpad chooser if we're in a call |
| 1459 | return true; |
| 1460 | } |
| 1461 | |
| 1462 | @Override |
calderwoodra | 70a4b09 | 2018-01-17 13:17:27 -0800 | [diff] [blame] | 1463 | public void onSearchListTouch() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1464 | if (isDialpadShown) { |
calderwoodra | 9d197d0 | 2017-11-15 15:41:54 -0800 | [diff] [blame] | 1465 | PerformanceReport.recordClick(UiAction.Type.CLOSE_DIALPAD); |
| 1466 | hideDialpadFragment(true, false); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1467 | if (TextUtils.isEmpty(dialpadQuery)) { |
calderwoodra | 9d197d0 | 2017-11-15 15:41:54 -0800 | [diff] [blame] | 1468 | exitSearchUi(); |
| 1469 | } |
calderwoodra | 9d197d0 | 2017-11-15 15:41:54 -0800 | [diff] [blame] | 1470 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1471 | UiUtil.hideKeyboardFrom(this, searchEditTextLayout); |
calderwoodra | 9d197d0 | 2017-11-15 15:41:54 -0800 | [diff] [blame] | 1472 | } |
calderwoodra | 9d197d0 | 2017-11-15 15:41:54 -0800 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | @Override |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1476 | public void onListFragmentScrollStateChange(int scrollState) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1477 | PerformanceReport.recordScrollStateChange(scrollState); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1478 | if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { |
| 1479 | hideDialpadFragment(true, false); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1480 | DialerUtils.hideInputMethod(parentLayout); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | @Override |
| 1485 | public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount, int totalItemCount) { |
| 1486 | // TODO: No-op for now. This should eventually show/hide the actionBar based on |
| 1487 | // interactions with the ListsFragments. |
| 1488 | } |
| 1489 | |
| 1490 | private boolean phoneIsInUse() { |
wangqi | fff6fcf | 2017-08-31 15:30:58 -0700 | [diff] [blame] | 1491 | return TelecomUtil.isInManagedCall(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | private boolean canIntentBeHandled(Intent intent) { |
| 1495 | final PackageManager packageManager = getPackageManager(); |
| 1496 | final List<ResolveInfo> resolveInfo = |
| 1497 | packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 1498 | return resolveInfo != null && resolveInfo.size() > 0; |
| 1499 | } |
| 1500 | |
| 1501 | /** Called when the user has long-pressed a contact tile to start a drag operation. */ |
| 1502 | @Override |
| 1503 | public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1504 | listsFragment.showRemoveView(true); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | @Override |
| 1508 | public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {} |
| 1509 | |
| 1510 | /** Called when the user has released a contact tile after long-pressing it. */ |
| 1511 | @Override |
| 1512 | public void onDragFinished(int x, int y) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1513 | listsFragment.showRemoveView(false); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | @Override |
| 1517 | public void onDroppedOnRemove() {} |
| 1518 | |
calderwoodra | 37d05a2 | 2018-01-30 14:50:44 -0800 | [diff] [blame] | 1519 | @Override |
| 1520 | public ImageView getDragShadowOverlay() { |
| 1521 | return findViewById(R.id.contact_tile_drag_shadow_overlay); |
| 1522 | } |
| 1523 | |
calderwoodra | ebc59e2 | 2018-02-24 02:33:40 -0800 | [diff] [blame] | 1524 | @Override |
| 1525 | public void setHasFrequents(boolean hasFrequents) { |
| 1526 | // No-op |
| 1527 | } |
| 1528 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1529 | /** |
| 1530 | * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer once it has |
| 1531 | * been attached to the activity. |
| 1532 | */ |
| 1533 | @Override |
| 1534 | public void setDragDropController(DragDropController dragController) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1535 | dragDropController = dragController; |
| 1536 | listsFragment.getRemoveView().setDragDropController(dragController); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1537 | } |
| 1538 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1539 | /** Implemented to satisfy {@link OldSpeedDialFragment.HostInterface} */ |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1540 | @Override |
| 1541 | public void showAllContactsTab() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1542 | if (listsFragment != null) { |
| 1543 | listsFragment.showTab(DialtactsPagerAdapter.TAB_INDEX_ALL_CONTACTS); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | /** Implemented to satisfy {@link CallLogFragment.HostInterface} */ |
| 1548 | @Override |
| 1549 | public void showDialpad() { |
| 1550 | showDialpadFragment(true); |
| 1551 | } |
| 1552 | |
| 1553 | @Override |
| 1554 | public void enableFloatingButton(boolean enabled) { |
| 1555 | LogUtil.d("DialtactsActivity.enableFloatingButton", "enable: %b", enabled); |
| 1556 | // Floating button shouldn't be enabled when dialpad is shown. |
| 1557 | if (!isDialpadShown() || !enabled) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1558 | floatingActionButtonController.setVisible(enabled); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | @Override |
| 1563 | public void onPickDataUri( |
| 1564 | Uri dataUri, boolean isVideoCall, CallSpecificAppData callSpecificAppData) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1565 | clearSearchOnPause = true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1566 | PhoneNumberInteraction.startInteractionForPhoneCall( |
| 1567 | DialtactsActivity.this, dataUri, isVideoCall, callSpecificAppData); |
| 1568 | } |
| 1569 | |
| 1570 | @Override |
| 1571 | public void onPickPhoneNumber( |
| 1572 | String phoneNumber, boolean isVideoCall, CallSpecificAppData callSpecificAppData) { |
| 1573 | if (phoneNumber == null) { |
| 1574 | // Invalid phone number, but let the call go through so that InCallUI can show |
| 1575 | // an error message. |
| 1576 | phoneNumber = ""; |
| 1577 | } |
twyen | 0efc840 | 2017-11-07 15:39:15 -0800 | [diff] [blame] | 1578 | PreCall.start( |
| 1579 | this, |
erfanian | 04ac93d | 2017-10-09 15:12:22 -0700 | [diff] [blame] | 1580 | new CallIntentBuilder(phoneNumber, callSpecificAppData) |
| 1581 | .setIsVideoCall(isVideoCall) |
twyen | 0efc840 | 2017-11-07 15:39:15 -0800 | [diff] [blame] | 1582 | .setAllowAssistedDial(callSpecificAppData.getAllowAssistedDialing())); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1583 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1584 | clearSearchOnPause = true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | @Override |
| 1588 | public void onHomeInActionBarSelected() { |
| 1589 | exitSearchUi(); |
| 1590 | } |
| 1591 | |
| 1592 | @Override |
| 1593 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { |
calderwoodra | 9873647 | 2017-11-30 15:21:47 -0800 | [diff] [blame] | 1594 | // FAB does not move with the new favorites UI |
| 1595 | if (newFavoritesIsEnabled()) { |
| 1596 | return; |
| 1597 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1598 | int tabIndex = listsFragment.getCurrentTabIndex(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1599 | |
| 1600 | // Scroll the button from center to end when moving from the Speed Dial to Call History tab. |
| 1601 | // In RTL, scroll when the current tab is Call History instead, since the order of the tabs |
| 1602 | // is reversed and the ViewPager returns the left tab position during scroll. |
| 1603 | boolean isRtl = ViewUtil.isRtl(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1604 | if (!isRtl && tabIndex == DialtactsPagerAdapter.TAB_INDEX_SPEED_DIAL && !isLandscape) { |
| 1605 | floatingActionButtonController.onPageScrolled(positionOffset); |
| 1606 | } else if (isRtl && tabIndex == DialtactsPagerAdapter.TAB_INDEX_HISTORY && !isLandscape) { |
| 1607 | floatingActionButtonController.onPageScrolled(1 - positionOffset); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1608 | } else if (tabIndex != DialtactsPagerAdapter.TAB_INDEX_SPEED_DIAL) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1609 | floatingActionButtonController.onPageScrolled(1); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1610 | } |
| 1611 | } |
| 1612 | |
| 1613 | @Override |
| 1614 | public void onPageSelected(int position) { |
| 1615 | updateMissedCalls(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1616 | int tabIndex = listsFragment.getCurrentTabIndex(); |
| 1617 | if (tabIndex != previouslySelectedTabIndex) { |
| 1618 | floatingActionButtonController.scaleIn(); |
calderwoodra | 6007f52 | 2017-10-09 16:59:04 -0700 | [diff] [blame] | 1619 | } |
Android Dialer | b7dba5a | 2017-11-07 21:22:15 -0800 | [diff] [blame] | 1620 | LogUtil.i("DialtactsActivity.onPageSelected", "tabIndex: %d", tabIndex); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1621 | previouslySelectedTabIndex = tabIndex; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1622 | timeTabSelected = SystemClock.elapsedRealtime(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | @Override |
| 1626 | public void onPageScrollStateChanged(int state) {} |
| 1627 | |
| 1628 | @Override |
| 1629 | public boolean isActionBarShowing() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1630 | return actionBarController.isActionBarShowing(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | @Override |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1634 | public boolean isDialpadShown() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1635 | return isDialpadShown; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | @Override |
| 1639 | public int getDialpadHeight() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1640 | if (dialpadFragment != null) { |
| 1641 | return dialpadFragment.getDialpadHeight(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1642 | } |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | @Override |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1647 | public void setActionBarHideOffset(int offset) { |
| 1648 | getActionBarSafely().setHideOffset(offset); |
| 1649 | } |
| 1650 | |
| 1651 | @Override |
| 1652 | public int getActionBarHeight() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1653 | return actionBarHeight; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1654 | } |
| 1655 | |
calderwoodra | 6007f52 | 2017-10-09 16:59:04 -0700 | [diff] [blame] | 1656 | @VisibleForTesting |
| 1657 | public int getFabAlignment() { |
calderwoodra | 9873647 | 2017-11-30 15:21:47 -0800 | [diff] [blame] | 1658 | if (!newFavoritesIsEnabled() |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1659 | && !isLandscape |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1660 | && !isInSearchUi() |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1661 | && listsFragment.getCurrentTabIndex() == DialtactsPagerAdapter.TAB_INDEX_SPEED_DIAL) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1662 | return FloatingActionButtonController.ALIGN_MIDDLE; |
| 1663 | } |
| 1664 | return FloatingActionButtonController.ALIGN_END; |
| 1665 | } |
| 1666 | |
| 1667 | private void updateMissedCalls() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1668 | if (previouslySelectedTabIndex == DialtactsPagerAdapter.TAB_INDEX_HISTORY) { |
| 1669 | listsFragment.markMissedCallsAsReadAndRemoveNotifications(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | @Override |
| 1674 | public void onDisambigDialogDismissed() { |
| 1675 | // Don't do anything; the app will remain open with favorites tiles displayed. |
| 1676 | } |
| 1677 | |
| 1678 | @Override |
| 1679 | public void interactionError(@InteractionErrorCode int interactionErrorCode) { |
| 1680 | switch (interactionErrorCode) { |
| 1681 | case InteractionErrorCode.USER_LEAVING_ACTIVITY: |
| 1682 | // This is expected to happen if the user exits the activity before the interaction occurs. |
| 1683 | return; |
| 1684 | case InteractionErrorCode.CONTACT_NOT_FOUND: |
| 1685 | case InteractionErrorCode.CONTACT_HAS_NO_NUMBER: |
| 1686 | case InteractionErrorCode.OTHER_ERROR: |
| 1687 | default: |
| 1688 | // All other error codes are unexpected. For example, it should be impossible to start an |
| 1689 | // interaction with an invalid contact from the Dialtacts activity. |
| 1690 | Assert.fail("PhoneNumberInteraction error: " + interactionErrorCode); |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | @Override |
| 1695 | public void onRequestPermissionsResult( |
| 1696 | int requestCode, String[] permissions, int[] grantResults) { |
| 1697 | // This should never happen; it should be impossible to start an interaction without the |
| 1698 | // contacts permission from the Dialtacts activity. |
| 1699 | Assert.fail( |
| 1700 | String.format( |
| 1701 | Locale.US, |
| 1702 | "Permissions requested unexpectedly: %d/%s/%s", |
| 1703 | requestCode, |
| 1704 | Arrays.toString(permissions), |
| 1705 | Arrays.toString(grantResults))); |
| 1706 | } |
| 1707 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1708 | @Override |
| 1709 | public void onActionModeStateChanged(boolean isEnabled) { |
| 1710 | isMultiSelectModeEnabled = isEnabled; |
| 1711 | } |
| 1712 | |
| 1713 | @Override |
| 1714 | public boolean isActionModeStateEnabled() { |
| 1715 | return isMultiSelectModeEnabled; |
| 1716 | } |
| 1717 | |
| 1718 | private CallInitiationType.Type getCallInitiationType() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1719 | return isDialpadShown |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1720 | ? CallInitiationType.Type.DIALPAD |
| 1721 | : CallInitiationType.Type.REGULAR_SEARCH; |
| 1722 | } |
| 1723 | |
calderwoodra | c377012 | 2017-10-13 16:36:17 -0700 | [diff] [blame] | 1724 | @Override |
calderwoodra | e51ca38 | 2017-11-21 10:54:36 -0800 | [diff] [blame] | 1725 | public void onCallPlacedFromSearch() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1726 | DialerUtils.hideInputMethod(parentLayout); |
| 1727 | clearSearchOnPause = true; |
calderwoodra | 32257fd | 2017-10-25 15:01:37 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
calderwoodra | f53ba7b | 2018-03-12 18:30:32 -0700 | [diff] [blame^] | 1730 | @Override |
| 1731 | public void requestingPermission() {} |
| 1732 | |
Android Dialer | b7dba5a | 2017-11-07 21:22:15 -0800 | [diff] [blame] | 1733 | protected int getPreviouslySelectedTabIndex() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1734 | return previouslySelectedTabIndex; |
Android Dialer | b7dba5a | 2017-11-07 21:22:15 -0800 | [diff] [blame] | 1735 | } |
| 1736 | |
calderwoodra | 73b51d5 | 2017-12-08 20:52:56 -0800 | [diff] [blame] | 1737 | @Override |
| 1738 | public void onContactSelected(ImageView photo, Uri contactUri, long contactId) { |
| 1739 | Logger.get(this) |
| 1740 | .logInteraction(InteractionEvent.Type.OPEN_QUICK_CONTACT_FROM_CONTACTS_FRAGMENT_ITEM); |
| 1741 | QuickContact.showQuickContact( |
| 1742 | this, photo, contactUri, QuickContact.MODE_LARGE, null /* excludeMimes */); |
| 1743 | } |
| 1744 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1745 | /** Popup menu accessible from the search bar */ |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1746 | protected class OptionsPopupMenu extends PopupMenu { |
| 1747 | |
| 1748 | public OptionsPopupMenu(Context context, View anchor) { |
| 1749 | super(context, anchor, Gravity.END); |
| 1750 | } |
| 1751 | |
| 1752 | @Override |
| 1753 | public void show() { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1754 | Menu menu = getMenu(); |
| 1755 | MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1756 | clearFrequents.setVisible( |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 1757 | PermissionsUtil.hasContactsReadPermissions(DialtactsActivity.this) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1758 | && listsFragment != null |
| 1759 | && listsFragment.hasFrequents()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1760 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1761 | menu.findItem(R.id.menu_history) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1762 | .setVisible(PermissionsUtil.hasPhonePermissions(DialtactsActivity.this)); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1763 | |
| 1764 | Context context = DialtactsActivity.this.getApplicationContext(); |
| 1765 | MenuItem simulatorMenuItem = menu.findItem(R.id.menu_simulator_submenu); |
| 1766 | Simulator simulator = SimulatorComponent.get(context).getSimulator(); |
| 1767 | if (simulator.shouldShow()) { |
| 1768 | simulatorMenuItem.setVisible(true); |
weijiaxu | 6b91ad3 | 2017-12-14 15:10:31 -0800 | [diff] [blame] | 1769 | simulatorMenuItem.setActionProvider(simulator.getActionProvider(DialtactsActivity.this)); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1770 | } else { |
| 1771 | simulatorMenuItem.setVisible(false); |
| 1772 | } |
| 1773 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1774 | menu.findItem(R.id.menu_new_ui_launcher_shortcut) |
calderwoodra | 9f16e17 | 2018-01-29 19:18:14 -0800 | [diff] [blame] | 1775 | .setVisible(MainComponent.isNewUiEnabled(context)); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1776 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1777 | super.show(); |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | /** |
| 1782 | * Listener that listens to drag events and sends their x and y coordinates to a {@link |
| 1783 | * DragDropController}. |
| 1784 | */ |
| 1785 | private class LayoutOnDragListener implements OnDragListener { |
| 1786 | |
| 1787 | @Override |
| 1788 | public boolean onDrag(View v, DragEvent event) { |
| 1789 | if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1790 | dragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1791 | } |
| 1792 | return true; |
| 1793 | } |
| 1794 | } |
twyen | 891fe0f | 2017-10-17 14:59:15 -0700 | [diff] [blame] | 1795 | |
| 1796 | @VisibleForTesting |
| 1797 | static void setVoiceSearchEnabledForTest(Optional<Boolean> enabled) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1798 | voiceSearchEnabledForTest = enabled; |
twyen | 891fe0f | 2017-10-17 14:59:15 -0700 | [diff] [blame] | 1799 | } |
calderwoodra | 9873647 | 2017-11-30 15:21:47 -0800 | [diff] [blame] | 1800 | |
| 1801 | private boolean newFavoritesIsEnabled() { |
| 1802 | return ConfigProviderBindings.get(this).getBoolean("enable_new_favorites_tab", false); |
| 1803 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1804 | } |