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