Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1 | /* |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.dialer; |
| 18 | |
Yorke Lee | 135e465 | 2015-10-23 18:12:51 -0700 | [diff] [blame] | 19 | import com.google.common.annotations.VisibleForTesting; |
| 20 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 21 | import android.app.Fragment; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 22 | import android.app.FragmentTransaction; |
Chiao Cheng | 073b5cf | 2012-12-07 11:36:00 -0800 | [diff] [blame] | 23 | import android.content.ActivityNotFoundException; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 26 | import android.content.pm.PackageManager; |
| 27 | import android.content.pm.ResolveInfo; |
Sai Cheemalapati | 82d6da5 | 2014-06-03 13:54:23 -0700 | [diff] [blame] | 28 | import android.content.res.Configuration; |
Andrew Lee | 2423a2f | 2014-05-29 14:14:45 -0700 | [diff] [blame] | 29 | import android.content.res.Resources; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 30 | import android.net.Uri; |
| 31 | import android.os.Bundle; |
Yorke Lee | f5554ce | 2015-01-27 14:46:02 -0800 | [diff] [blame] | 32 | import android.os.Trace; |
Nancy Chen | 019713e | 2015-07-06 18:25:24 -0700 | [diff] [blame] | 33 | import android.provider.CallLog.Calls; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 34 | import android.speech.RecognizerIntent; |
Nancy Chen | f3d9f82 | 2015-09-11 00:47:31 -0400 | [diff] [blame] | 35 | import android.support.design.widget.CoordinatorLayout; |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 36 | import android.support.v4.view.ViewPager; |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 37 | import android.support.v7.app.ActionBar; |
Tyler Gunn | 9dc924c | 2014-09-12 09:33:50 -0700 | [diff] [blame] | 38 | import android.telecom.PhoneAccount; |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 39 | import android.text.Editable; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 40 | import android.text.TextUtils; |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 41 | import android.text.TextWatcher; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 42 | import android.util.Log; |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 43 | import android.view.DragEvent; |
Yorke Lee | 74edcdc | 2014-07-11 16:15:08 -0700 | [diff] [blame] | 44 | import android.view.Gravity; |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 45 | import android.view.KeyEvent; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 46 | import android.view.Menu; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 47 | import android.view.MenuItem; |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 48 | import android.view.MotionEvent; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 49 | import android.view.View; |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 50 | import android.view.View.OnDragListener; |
Ihab Awad | 9134e25 | 2014-07-09 12:32:52 -0700 | [diff] [blame] | 51 | import android.view.ViewTreeObserver; |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 52 | import android.view.animation.Animation; |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 53 | import android.view.animation.AnimationUtils; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 54 | import android.widget.AbsListView.OnScrollListener; |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 55 | import android.widget.EditText; |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 56 | import android.widget.ImageButton; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 57 | import android.widget.PopupMenu; |
Anne Rong | 3520800 | 2015-07-22 16:27:37 -0700 | [diff] [blame] | 58 | import android.widget.TextView; |
Chiao Cheng | 073b5cf | 2012-12-07 11:36:00 -0800 | [diff] [blame] | 59 | import android.widget.Toast; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 60 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 61 | import com.android.contacts.common.dialog.ClearFrequentsDialog; |
| 62 | import com.android.contacts.common.interactions.ImportExportDialogFragment; |
Nancy Chen | 0d3a739 | 2014-08-12 14:44:53 -0700 | [diff] [blame] | 63 | import com.android.contacts.common.interactions.TouchPointManager; |
Chiao Cheng | 8efbcf9 | 2012-12-04 17:43:02 -0800 | [diff] [blame] | 64 | import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; |
Yorke Lee | c16ea5a | 2015-05-19 15:51:01 -0700 | [diff] [blame] | 65 | import com.android.contacts.common.util.PermissionsUtil; |
Sai Cheemalapati | c4969ea | 2014-06-04 16:35:16 -0700 | [diff] [blame] | 66 | import com.android.contacts.common.widget.FloatingActionButtonController; |
Brian Attwell | beab3bb | 2014-10-27 12:24:49 -0700 | [diff] [blame] | 67 | import com.android.contacts.commonbind.analytics.AnalyticsUtil; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 68 | import com.android.dialer.calllog.CallLogActivity; |
Yorke Lee | 38019af | 2015-07-14 17:05:38 -0700 | [diff] [blame] | 69 | import com.android.dialer.calllog.CallLogFragment; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 70 | import com.android.dialer.database.DialerDatabaseHelper; |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 71 | import com.android.dialer.dialpad.DialpadFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 72 | import com.android.dialer.dialpad.SmartDialNameMatcher; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 73 | import com.android.dialer.dialpad.SmartDialPrefix; |
Chiao Cheng | 1429f1a | 2012-11-01 16:35:28 -0700 | [diff] [blame] | 74 | import com.android.dialer.interactions.PhoneNumberInteraction; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 75 | import com.android.dialer.list.DragDropController; |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 76 | import com.android.dialer.list.ListsFragment; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 77 | import com.android.dialer.list.OnDragDropListener; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 78 | import com.android.dialer.list.OnListFragmentScrolledListener; |
Yorke Lee | efb2d9c | 2014-04-18 14:05:01 -0700 | [diff] [blame] | 79 | import com.android.dialer.list.PhoneFavoriteSquareTileView; |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 80 | import com.android.dialer.list.RegularSearchFragment; |
| 81 | import com.android.dialer.list.SearchFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 82 | import com.android.dialer.list.SmartDialSearchFragment; |
Ihab Awad | 9134e25 | 2014-07-09 12:32:52 -0700 | [diff] [blame] | 83 | import com.android.dialer.list.SpeedDialFragment; |
Yorke Lee | 6e0fd6b | 2015-11-04 20:44:25 -0800 | [diff] [blame] | 84 | import com.android.dialer.logging.Logger; |
Yorke Lee | 58e68a9 | 2015-11-06 10:35:30 -0800 | [diff] [blame] | 85 | import com.android.dialer.logging.ScreenEvent; |
Yorke Lee | af6f195 | 2014-07-14 19:13:16 -0700 | [diff] [blame] | 86 | import com.android.dialer.settings.DialerSettingsActivity; |
Yorke Lee | 7d20f82 | 2014-06-19 17:09:33 -0700 | [diff] [blame] | 87 | import com.android.dialer.util.DialerUtils; |
Ta-wei Yen | e3cae63 | 2015-10-27 16:09:09 -0700 | [diff] [blame] | 88 | import com.android.dialer.util.IntentUtil; |
| 89 | import com.android.dialer.util.IntentUtil.CallIntentBuilder; |
| 90 | import com.android.dialer.util.TelecomUtil; |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 91 | import com.android.dialer.widget.ActionBarController; |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 92 | import com.android.dialer.widget.SearchEditTextLayout; |
Yorke Lee | 0baa98b | 2013-08-22 10:55:16 -0700 | [diff] [blame] | 93 | import com.android.dialerbind.DatabaseHelperManager; |
Yorke Lee | 807afd8 | 2015-10-12 10:03:07 -0700 | [diff] [blame] | 94 | import com.android.dialerbind.ObjectFactory; |
Yorke Lee | 2fec47b | 2014-08-05 18:16:27 -0700 | [diff] [blame] | 95 | import com.android.phone.common.animation.AnimUtils; |
Sai Cheemalapati | fd723ca | 2014-06-19 12:30:07 -0700 | [diff] [blame] | 96 | import com.android.phone.common.animation.AnimationListenerAdapter; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 97 | |
Yorke Lee | d5c512a | 2015-01-30 14:42:53 -0800 | [diff] [blame] | 98 | import junit.framework.Assert; |
| 99 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 100 | import java.util.ArrayList; |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 101 | import java.util.List; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 102 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 103 | /** |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 104 | * The dialer tab's title is 'phone', a more common name (see strings.xml). |
| 105 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 106 | public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener, |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 107 | DialpadFragment.OnDialpadQueryChangedListener, |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 108 | OnListFragmentScrolledListener, |
Yorke Lee | 38019af | 2015-07-14 17:05:38 -0700 | [diff] [blame] | 109 | CallLogFragment.HostInterface, |
Yorke Lee | 575ae38 | 2015-07-16 11:36:07 -0700 | [diff] [blame] | 110 | DialpadFragment.HostInterface, |
Yorke Lee | 6a1461a | 2014-04-21 16:27:14 -0700 | [diff] [blame] | 111 | ListsFragment.HostInterface, |
Yorke Lee | d999b71 | 2014-04-23 15:10:58 -0700 | [diff] [blame] | 112 | SpeedDialFragment.HostInterface, |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 113 | SearchFragment.HostInterface, |
Andrew Lee | 752956e | 2014-05-15 11:43:38 -0700 | [diff] [blame] | 114 | OnDragDropListener, |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 115 | OnPhoneNumberPickerActionListener, |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 116 | PopupMenu.OnMenuItemClickListener, |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 117 | ViewPager.OnPageChangeListener, |
| 118 | ActionBarController.ActivityUi { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 119 | private static final String TAG = "DialtactsActivity"; |
| 120 | |
Yorke Lee | 7cc6149 | 2015-06-01 14:59:33 -0700 | [diff] [blame] | 121 | public static final boolean DEBUG = false; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 122 | |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 123 | public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences"; |
| 124 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 125 | private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui"; |
| 126 | private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui"; |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 127 | private static final String KEY_SEARCH_QUERY = "search_query"; |
| 128 | private static final String KEY_FIRST_LAUNCH = "first_launch"; |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 129 | private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown"; |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 130 | |
Yorke Lee | 135e465 | 2015-10-23 18:12:51 -0700 | [diff] [blame] | 131 | @VisibleForTesting |
| 132 | public static final String TAG_DIALPAD_FRAGMENT = "dialpad"; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 133 | private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search"; |
| 134 | private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial"; |
| 135 | private static final String TAG_FAVORITES_FRAGMENT = "favorites"; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 136 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 137 | /** |
| 138 | * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}. |
| 139 | */ |
| 140 | private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER"; |
Andrew Lee | 75d5b2d | 2015-06-19 16:53:54 -0700 | [diff] [blame] | 141 | public static final String EXTRA_SHOW_TAB = "EXTRA_SHOW_TAB"; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 142 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 143 | private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 144 | |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 145 | private static final int FAB_SCALE_IN_DELAY_MS = 300; |
| 146 | |
Nancy Chen | f3d9f82 | 2015-09-11 00:47:31 -0400 | [diff] [blame] | 147 | private CoordinatorLayout mParentLayout; |
Andrew Lee | 0c66770 | 2014-05-12 14:31:45 -0700 | [diff] [blame] | 148 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 149 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 150 | * Fragment containing the dialpad that slides into view |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 151 | */ |
Evan Charlton | 72d6625 | 2014-11-07 16:23:47 -0800 | [diff] [blame] | 152 | protected DialpadFragment mDialpadFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 153 | |
| 154 | /** |
| 155 | * Fragment for searching phone numbers using the alphanumeric keyboard. |
| 156 | */ |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 157 | private RegularSearchFragment mRegularSearchFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 158 | |
| 159 | /** |
| 160 | * Fragment for searching phone numbers using the dialpad. |
| 161 | */ |
| 162 | private SmartDialSearchFragment mSmartDialSearchFragment; |
| 163 | |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 164 | /** |
Sai Cheemalapati | 82d6da5 | 2014-06-03 13:54:23 -0700 | [diff] [blame] | 165 | * Animation that slides in. |
| 166 | */ |
| 167 | private Animation mSlideIn; |
| 168 | |
| 169 | /** |
| 170 | * Animation that slides out. |
| 171 | */ |
| 172 | private Animation mSlideOut; |
| 173 | |
Yorke Lee | 6c450eb | 2015-05-08 09:45:47 -0700 | [diff] [blame] | 174 | AnimationListenerAdapter mSlideInListener = new AnimationListenerAdapter() { |
| 175 | @Override |
| 176 | public void onAnimationEnd(Animation animation) { |
Yorke Lee | 81a313d | 2015-06-01 14:53:59 -0700 | [diff] [blame] | 177 | maybeEnterSearchUi(); |
Yorke Lee | 6c450eb | 2015-05-08 09:45:47 -0700 | [diff] [blame] | 178 | } |
| 179 | }; |
| 180 | |
Sai Cheemalapati | 82d6da5 | 2014-06-03 13:54:23 -0700 | [diff] [blame] | 181 | /** |
| 182 | * Listener for after slide out animation completes on dialer fragment. |
| 183 | */ |
| 184 | AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() { |
| 185 | @Override |
| 186 | public void onAnimationEnd(Animation animation) { |
| 187 | commitDialpadFragmentHide(); |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | /** |
Andrew Lee | 4de59fb | 2015-08-13 15:20:08 -0700 | [diff] [blame] | 192 | * Fragment containing the speed dial list, call history list, and all contacts list. |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 193 | */ |
| 194 | private ListsFragment mListsFragment; |
| 195 | |
Yorke Lee | 19e68ca | 2014-10-28 11:51:40 -0700 | [diff] [blame] | 196 | /** |
| 197 | * Tracks whether onSaveInstanceState has been called. If true, no fragment transactions can |
| 198 | * be commited. |
| 199 | */ |
| 200 | private boolean mStateSaved; |
Yorke Lee | 7ee5c42 | 2014-11-04 10:29:32 -0800 | [diff] [blame] | 201 | private boolean mIsRestarting; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 202 | private boolean mInDialpadSearch; |
| 203 | private boolean mInRegularSearch; |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 204 | private boolean mClearSearchOnPause; |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 205 | private boolean mIsDialpadShown; |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 206 | private boolean mShowDialpadOnResume; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 207 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 208 | /** |
Sai Cheemalapati | 4146065 | 2014-06-02 21:05:39 -0700 | [diff] [blame] | 209 | * Whether or not the device is in landscape orientation. |
| 210 | */ |
| 211 | private boolean mIsLandscape; |
| 212 | |
| 213 | /** |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 214 | * True if the dialpad is only temporarily showing due to being in call |
| 215 | */ |
| 216 | private boolean mInCallDialpadUp; |
| 217 | |
| 218 | /** |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 219 | * True when this activity has been launched for the first time. |
| 220 | */ |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 221 | private boolean mFirstLaunch; |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 222 | |
Yorke Lee | 3c9e7cd | 2014-04-16 11:37:21 -0700 | [diff] [blame] | 223 | /** |
| 224 | * Search query to be applied to the SearchView in the ActionBar once |
| 225 | * onCreateOptionsMenu has been called. |
| 226 | */ |
| 227 | private String mPendingSearchViewQuery; |
| 228 | |
Yorke Lee | 74edcdc | 2014-07-11 16:15:08 -0700 | [diff] [blame] | 229 | private PopupMenu mOverflowMenu; |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 230 | private EditText mSearchView; |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 231 | private View mVoiceSearchButton; |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 232 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 233 | private String mSearchQuery; |
Yorke Lee | d9a9316 | 2015-10-14 09:39:05 -0700 | [diff] [blame] | 234 | private String mDialpadQuery; |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 235 | |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 236 | private DialerDatabaseHelper mDialerDatabaseHelper; |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 237 | private DragDropController mDragDropController; |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 238 | private ActionBarController mActionBarController; |
Sai Cheemalapati | c4969ea | 2014-06-04 16:35:16 -0700 | [diff] [blame] | 239 | |
Sai Cheemalapati | 4146065 | 2014-06-02 21:05:39 -0700 | [diff] [blame] | 240 | private FloatingActionButtonController mFloatingActionButtonController; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 241 | |
Andrew Lee | 2423a2f | 2014-05-29 14:14:45 -0700 | [diff] [blame] | 242 | private int mActionBarHeight; |
Andrew Lee | 2423a2f | 2014-05-29 14:14:45 -0700 | [diff] [blame] | 243 | |
Tyler Gunn | c1cfae5 | 2014-11-20 13:22:54 -0800 | [diff] [blame] | 244 | /** |
| 245 | * The text returned from a voice search query. Set in {@link #onActivityResult} and used in |
| 246 | * {@link #onResume()} to populate the search box. |
| 247 | */ |
| 248 | private String mVoiceSearchQuery; |
| 249 | |
Andrew Lee | 467de3d | 2015-03-17 15:47:24 -0700 | [diff] [blame] | 250 | protected class OptionsPopupMenu extends PopupMenu { |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 251 | public OptionsPopupMenu(Context context, View anchor) { |
Yorke Lee | 74edcdc | 2014-07-11 16:15:08 -0700 | [diff] [blame] | 252 | super(context, anchor, Gravity.END); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | @Override |
| 256 | public void show() { |
Yorke Lee | c16ea5a | 2015-05-19 15:51:01 -0700 | [diff] [blame] | 257 | final boolean hasContactsPermission = |
| 258 | PermissionsUtil.hasContactsPermissions(DialtactsActivity.this); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 259 | final Menu menu = getMenu(); |
| 260 | final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents); |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 261 | clearFrequents.setVisible(mListsFragment != null && |
| 262 | mListsFragment.getSpeedDialFragment() != null && |
Yorke Lee | c16ea5a | 2015-05-19 15:51:01 -0700 | [diff] [blame] | 263 | mListsFragment.getSpeedDialFragment().hasFrequents() && hasContactsPermission); |
| 264 | |
| 265 | menu.findItem(R.id.menu_import_export).setVisible(hasContactsPermission); |
| 266 | menu.findItem(R.id.menu_add_contact).setVisible(hasContactsPermission); |
Yorke Lee | b7330e3 | 2015-05-22 15:55:22 -0700 | [diff] [blame] | 267 | |
| 268 | menu.findItem(R.id.menu_history).setVisible( |
| 269 | PermissionsUtil.hasPhonePermissions(DialtactsActivity.this)); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 270 | super.show(); |
| 271 | } |
| 272 | } |
| 273 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 274 | /** |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 275 | * Listener that listens to drag events and sends their x and y coordinates to a |
| 276 | * {@link DragDropController}. |
| 277 | */ |
| 278 | private class LayoutOnDragListener implements OnDragListener { |
| 279 | @Override |
| 280 | public boolean onDrag(View v, DragEvent event) { |
| 281 | if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { |
Andrew Lee | 1896344 | 2014-06-06 17:20:13 -0700 | [diff] [blame] | 282 | mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY()); |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 283 | } |
| 284 | return true; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /** |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 289 | * Listener used to send search queries to the phone search fragment. |
| 290 | */ |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 291 | private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() { |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 292 | @Override |
| 293 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 294 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 295 | |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 296 | @Override |
| 297 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 298 | final String newText = s.toString(); |
| 299 | if (newText.equals(mSearchQuery)) { |
| 300 | // If the query hasn't changed (perhaps due to activity being destroyed |
| 301 | // and restored, or user launching the same DIAL intent twice), then there is |
| 302 | // no need to do anything here. |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 303 | return; |
| 304 | } |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 305 | if (DEBUG) { |
| 306 | Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText); |
Yorke Lee | 710709d | 2014-05-29 07:18:42 -0700 | [diff] [blame] | 307 | Log.d(TAG, "Previous Query: " + mSearchQuery); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 308 | } |
Yorke Lee | 710709d | 2014-05-29 07:18:42 -0700 | [diff] [blame] | 309 | mSearchQuery = newText; |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 310 | |
Andrew Lee | 90374a7 | 2014-05-16 15:01:09 -0700 | [diff] [blame] | 311 | // Show search fragment only when the query string is changed to non-empty text. |
| 312 | if (!TextUtils.isEmpty(newText)) { |
| 313 | // Call enterSearchUi only if we are switching search modes, or showing a search |
| 314 | // fragment for the first time. |
| 315 | final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) || |
| 316 | (!mIsDialpadShown && mInRegularSearch); |
| 317 | if (!sameSearchMode) { |
Yorke Lee | 6c450eb | 2015-05-08 09:45:47 -0700 | [diff] [blame] | 318 | enterSearchUi(mIsDialpadShown, mSearchQuery, true /* animate */); |
Andrew Lee | 90374a7 | 2014-05-16 15:01:09 -0700 | [diff] [blame] | 319 | } |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Andrew Lee | a851542 | 2014-06-13 16:53:54 -0700 | [diff] [blame] | 322 | if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) { |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 323 | mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */); |
Andrew Lee | a851542 | 2014-06-13 16:53:54 -0700 | [diff] [blame] | 324 | } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) { |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 325 | mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */); |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 326 | } |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public void afterTextChanged(Editable s) { |
| 331 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 332 | }; |
| 333 | |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 334 | |
| 335 | /** |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 336 | * Open the search UI when the user clicks on the search box. |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 337 | */ |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 338 | private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() { |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 339 | @Override |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 340 | public void onClick(View v) { |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 341 | if (!isInSearchUi()) { |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 342 | mActionBarController.onSearchBoxTapped(); |
Yorke Lee | 6c450eb | 2015-05-08 09:45:47 -0700 | [diff] [blame] | 343 | enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString(), |
| 344 | true /* animate */); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 345 | } |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 346 | } |
| 347 | }; |
| 348 | |
| 349 | /** |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 350 | * Handles the user closing the soft keyboard. |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 351 | */ |
| 352 | private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() { |
| 353 | @Override |
| 354 | public boolean onKey(View v, int keyCode, KeyEvent event) { |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 355 | if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { |
| 356 | if (TextUtils.isEmpty(mSearchView.getText().toString())) { |
| 357 | // If the search term is empty, close the search UI. |
| 358 | maybeExitSearchUi(); |
| 359 | } else { |
| 360 | // If the search term is not empty, show the dialpad fab. |
| 361 | showFabInSearchUi(); |
| 362 | } |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 363 | } |
| 364 | return false; |
| 365 | } |
| 366 | }; |
| 367 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 368 | @Override |
Nancy Chen | 49db1ad | 2014-08-18 20:10:17 -0700 | [diff] [blame] | 369 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 370 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { |
| 371 | TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY()); |
| 372 | } |
| 373 | return super.dispatchTouchEvent(ev); |
Nancy Chen | 49db1ad | 2014-08-18 20:10:17 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 377 | protected void onCreate(Bundle savedInstanceState) { |
Yorke Lee | f5554ce | 2015-01-27 14:46:02 -0800 | [diff] [blame] | 378 | Trace.beginSection(TAG + " onCreate"); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 379 | super.onCreate(savedInstanceState); |
Yorke Lee | c16ea5a | 2015-05-19 15:51:01 -0700 | [diff] [blame] | 380 | |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 381 | mFirstLaunch = true; |
| 382 | |
Andrew Lee | 2423a2f | 2014-05-29 14:14:45 -0700 | [diff] [blame] | 383 | final Resources resources = getResources(); |
Nancy Chen | b8170de | 2014-07-28 10:41:08 -0700 | [diff] [blame] | 384 | mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large); |
Andrew Lee | 2423a2f | 2014-05-29 14:14:45 -0700 | [diff] [blame] | 385 | |
Yorke Lee | f5554ce | 2015-01-27 14:46:02 -0800 | [diff] [blame] | 386 | Trace.beginSection(TAG + " setContentView"); |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 387 | setContentView(R.layout.dialtacts_activity); |
Yorke Lee | f5554ce | 2015-01-27 14:46:02 -0800 | [diff] [blame] | 388 | Trace.endSection(); |
Yorke Lee | 9e91bb0 | 2014-03-05 17:50:50 -0800 | [diff] [blame] | 389 | getWindow().setBackgroundDrawable(null); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 390 | |
Yorke Lee | f5554ce | 2015-01-27 14:46:02 -0800 | [diff] [blame] | 391 | Trace.beginSection(TAG + " setup Views"); |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 392 | final ActionBar actionBar = getSupportActionBar(); |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 393 | actionBar.setCustomView(R.layout.search_edittext); |
| 394 | actionBar.setDisplayShowCustomEnabled(true); |
Yorke Lee | bcef940 | 2014-05-21 15:33:00 -0700 | [diff] [blame] | 395 | actionBar.setBackgroundDrawable(null); |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 396 | |
Anne Rong | 3520800 | 2015-07-22 16:27:37 -0700 | [diff] [blame] | 397 | SearchEditTextLayout searchEditTextLayout = (SearchEditTextLayout) actionBar |
| 398 | .getCustomView().findViewById(R.id.search_view_container); |
Andrew Lee | 04675a5 | 2014-06-05 18:36:20 -0700 | [diff] [blame] | 399 | searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener); |
| 400 | |
Andrew Lee | e3f59a8 | 2015-02-26 12:06:35 -0800 | [diff] [blame] | 401 | mActionBarController = new ActionBarController(this, searchEditTextLayout); |
| 402 | |
Andrew Lee | 04675a5 | 2014-06-05 18:36:20 -0700 | [diff] [blame] | 403 | mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view); |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 404 | mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); |
Andrew Lee | 04675a5 | 2014-06-05 18:36:20 -0700 | [diff] [blame] | 405 | mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button); |
| 406 | searchEditTextLayout.findViewById(R.id.search_magnifying_glass) |
| 407 | .setOnClickListener(mSearchViewOnClickListener); |
| 408 | searchEditTextLayout.findViewById(R.id.search_box_start_search) |
| 409 | .setOnClickListener(mSearchViewOnClickListener); |
Yorke Lee | 7a6f189 | 2015-06-27 13:21:48 -0700 | [diff] [blame] | 410 | searchEditTextLayout.setOnClickListener(mSearchViewOnClickListener); |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 411 | searchEditTextLayout.setCallback(new SearchEditTextLayout.Callback() { |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 412 | @Override |
| 413 | public void onBackButtonClicked() { |
| 414 | onBackPressed(); |
| 415 | } |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 416 | |
| 417 | @Override |
| 418 | public void onSearchViewClicked() { |
| 419 | // Hide FAB, as the keyboard is shown. |
| 420 | mFloatingActionButtonController.scaleOut(); |
| 421 | } |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 422 | }); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 423 | |
Sai Cheemalapati | c4969ea | 2014-06-04 16:35:16 -0700 | [diff] [blame] | 424 | mIsLandscape = getResources().getConfiguration().orientation |
Sai Cheemalapati | 4146065 | 2014-06-02 21:05:39 -0700 | [diff] [blame] | 425 | == Configuration.ORIENTATION_LANDSCAPE; |
Nancy Chen | 8e06629 | 2014-06-18 17:16:10 -0700 | [diff] [blame] | 426 | |
Sai Cheemalapati | c4969ea | 2014-06-04 16:35:16 -0700 | [diff] [blame] | 427 | final View floatingActionButtonContainer = findViewById( |
| 428 | R.id.floating_action_button_container); |
Andrew Lee | 405a6e6 | 2014-08-20 15:02:16 -0700 | [diff] [blame] | 429 | ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button); |
| 430 | floatingActionButton.setOnClickListener(this); |
Sai Cheemalapati | c4969ea | 2014-06-04 16:35:16 -0700 | [diff] [blame] | 431 | mFloatingActionButtonController = new FloatingActionButtonController(this, |
Andrew Lee | 405a6e6 | 2014-08-20 15:02:16 -0700 | [diff] [blame] | 432 | floatingActionButtonContainer, floatingActionButton); |
Sai Cheemalapati | 4146065 | 2014-06-02 21:05:39 -0700 | [diff] [blame] | 433 | |
Andrew Lee | 04675a5 | 2014-06-05 18:36:20 -0700 | [diff] [blame] | 434 | ImageButton optionsMenuButton = |
| 435 | (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button); |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 436 | optionsMenuButton.setOnClickListener(this); |
Yorke Lee | 74edcdc | 2014-07-11 16:15:08 -0700 | [diff] [blame] | 437 | mOverflowMenu = buildOptionsMenu(searchEditTextLayout); |
| 438 | optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener()); |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 439 | |
Yorke Lee | d5c512a | 2015-01-30 14:42:53 -0800 | [diff] [blame] | 440 | // Add the favorites fragment but only if savedInstanceState is null. Otherwise the |
| 441 | // fragment manager is responsible for recreating it. |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 442 | if (savedInstanceState == null) { |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 443 | getFragmentManager().beginTransaction() |
Andrew Lee | 6a86624 | 2015-05-05 18:21:45 +0000 | [diff] [blame] | 444 | .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT) |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 445 | .commit(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 446 | } else { |
| 447 | mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 448 | mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI); |
| 449 | mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 450 | mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH); |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 451 | mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN); |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 452 | mActionBarController.restoreInstanceState(savedInstanceState); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 453 | } |
Sai Cheemalapati | 82d6da5 | 2014-06-03 13:54:23 -0700 | [diff] [blame] | 454 | |
Tyler Gunn | bf7a95e | 2014-08-12 12:16:28 -0700 | [diff] [blame] | 455 | final boolean isLayoutRtl = DialerUtils.isRtl(); |
| 456 | if (mIsLandscape) { |
| 457 | mSlideIn = AnimationUtils.loadAnimation(this, |
| 458 | isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right); |
| 459 | mSlideOut = AnimationUtils.loadAnimation(this, |
| 460 | isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right); |
| 461 | } else { |
| 462 | mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom); |
| 463 | mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom); |
| 464 | } |
Sai Cheemalapati | 82d6da5 | 2014-06-03 13:54:23 -0700 | [diff] [blame] | 465 | |
Yorke Lee | 2fec47b | 2014-08-05 18:16:27 -0700 | [diff] [blame] | 466 | mSlideIn.setInterpolator(AnimUtils.EASE_IN); |
| 467 | mSlideOut.setInterpolator(AnimUtils.EASE_OUT); |
| 468 | |
Yorke Lee | 6c450eb | 2015-05-08 09:45:47 -0700 | [diff] [blame] | 469 | mSlideIn.setAnimationListener(mSlideInListener); |
Sai Cheemalapati | 82d6da5 | 2014-06-03 13:54:23 -0700 | [diff] [blame] | 470 | mSlideOut.setAnimationListener(mSlideOutListener); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 471 | |
Nancy Chen | f3d9f82 | 2015-09-11 00:47:31 -0400 | [diff] [blame] | 472 | mParentLayout = (CoordinatorLayout) findViewById(R.id.dialtacts_mainlayout); |
Yorke Lee | f614f6f | 2014-10-03 10:44:19 -0700 | [diff] [blame] | 473 | mParentLayout.setOnDragListener(new LayoutOnDragListener()); |
Sai Cheemalapati | c4969ea | 2014-06-04 16:35:16 -0700 | [diff] [blame] | 474 | floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener( |
Sai Cheemalapati | 4146065 | 2014-06-02 21:05:39 -0700 | [diff] [blame] | 475 | new ViewTreeObserver.OnGlobalLayoutListener() { |
| 476 | @Override |
| 477 | public void onGlobalLayout() { |
Andrew Lee | 405a6e6 | 2014-08-20 15:02:16 -0700 | [diff] [blame] | 478 | final ViewTreeObserver observer = |
| 479 | floatingActionButtonContainer.getViewTreeObserver(); |
Sai Cheemalapati | c4969ea | 2014-06-04 16:35:16 -0700 | [diff] [blame] | 480 | if (!observer.isAlive()) { |
| 481 | return; |
| 482 | } |
| 483 | observer.removeOnGlobalLayoutListener(this); |
Yorke Lee | f614f6f | 2014-10-03 10:44:19 -0700 | [diff] [blame] | 484 | int screenWidth = mParentLayout.getWidth(); |
Sai Cheemalapati | 4146065 | 2014-06-02 21:05:39 -0700 | [diff] [blame] | 485 | mFloatingActionButtonController.setScreenWidth(screenWidth); |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 486 | mFloatingActionButtonController.align( |
| 487 | getFabAlignment(), false /* animate */); |
Sai Cheemalapati | 4146065 | 2014-06-02 21:05:39 -0700 | [diff] [blame] | 488 | } |
| 489 | }); |
Andrew Lee | 0c66770 | 2014-05-12 14:31:45 -0700 | [diff] [blame] | 490 | |
Yorke Lee | f5554ce | 2015-01-27 14:46:02 -0800 | [diff] [blame] | 491 | Trace.endSection(); |
| 492 | |
| 493 | Trace.beginSection(TAG + " initialize smart dialing"); |
Yorke Lee | 0baa98b | 2013-08-22 10:55:16 -0700 | [diff] [blame] | 494 | mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this); |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 495 | SmartDialPrefix.initializeNanpSettings(this); |
Yorke Lee | f5554ce | 2015-01-27 14:46:02 -0800 | [diff] [blame] | 496 | Trace.endSection(); |
| 497 | Trace.endSection(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 501 | protected void onResume() { |
Yorke Lee | f5554ce | 2015-01-27 14:46:02 -0800 | [diff] [blame] | 502 | Trace.beginSection(TAG + " onResume"); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 503 | super.onResume(); |
Yorke Lee | 2a61302 | 2015-07-01 14:28:13 -0700 | [diff] [blame] | 504 | |
Yorke Lee | 19e68ca | 2014-10-28 11:51:40 -0700 | [diff] [blame] | 505 | mStateSaved = false; |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 506 | if (mFirstLaunch) { |
| 507 | displayFragment(getIntent()); |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 508 | } else if (!phoneIsInUse() && mInCallDialpadUp) { |
| 509 | hideDialpadFragment(false, true); |
| 510 | mInCallDialpadUp = false; |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 511 | } else if (mShowDialpadOnResume) { |
| 512 | showDialpadFragment(false); |
| 513 | mShowDialpadOnResume = false; |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 514 | } |
Tyler Gunn | c1cfae5 | 2014-11-20 13:22:54 -0800 | [diff] [blame] | 515 | |
| 516 | // If there was a voice query result returned in the {@link #onActivityResult} callback, it |
| 517 | // will have been stashed in mVoiceSearchQuery since the search results fragment cannot be |
| 518 | // shown until onResume has completed. Active the search UI and set the search term now. |
| 519 | if (!TextUtils.isEmpty(mVoiceSearchQuery)) { |
| 520 | mActionBarController.onSearchBoxTapped(); |
| 521 | mSearchView.setText(mVoiceSearchQuery); |
| 522 | mVoiceSearchQuery = null; |
| 523 | } |
| 524 | |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 525 | mFirstLaunch = false; |
Yorke Lee | 7ee5c42 | 2014-11-04 10:29:32 -0800 | [diff] [blame] | 526 | |
| 527 | if (mIsRestarting) { |
| 528 | // This is only called when the activity goes from resumed -> paused -> resumed, so it |
| 529 | // will not cause an extra view to be sent out on rotation |
| 530 | if (mIsDialpadShown) { |
Yorke Lee | 58e68a9 | 2015-11-06 10:35:30 -0800 | [diff] [blame] | 531 | Logger.logScreenView(ScreenEvent.DIALPAD, this); |
Yorke Lee | 7ee5c42 | 2014-11-04 10:29:32 -0800 | [diff] [blame] | 532 | } |
| 533 | mIsRestarting = false; |
| 534 | } |
Andrew Lee | 75d5b2d | 2015-06-19 16:53:54 -0700 | [diff] [blame] | 535 | |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 536 | prepareVoiceSearchButton(); |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 537 | mDialerDatabaseHelper.startSmartDialUpdateThread(); |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 538 | mFloatingActionButtonController.align(getFabAlignment(), false /* animate */); |
Nancy Chen | d5de03b | 2015-07-01 09:20:45 -0700 | [diff] [blame] | 539 | |
Yorke Lee | 49aa5bf | 2015-09-10 15:53:43 -0700 | [diff] [blame] | 540 | if (Calls.CONTENT_TYPE.equals(getIntent().getType())) { |
| 541 | // Externally specified extras take precedence to EXTRA_SHOW_TAB, which is only |
| 542 | // used internally. |
| 543 | final Bundle extras = getIntent().getExtras(); |
| 544 | if (extras != null |
| 545 | && extras.getInt(Calls.EXTRA_CALL_TYPE_FILTER) == Calls.VOICEMAIL_TYPE) { |
| 546 | mListsFragment.showTab(ListsFragment.TAB_INDEX_VOICEMAIL); |
| 547 | } else { |
| 548 | mListsFragment.showTab(ListsFragment.TAB_INDEX_HISTORY); |
| 549 | } |
| 550 | } else if (getIntent().hasExtra(EXTRA_SHOW_TAB)) { |
Nancy Chen | d5de03b | 2015-07-01 09:20:45 -0700 | [diff] [blame] | 551 | int index = getIntent().getIntExtra(EXTRA_SHOW_TAB, ListsFragment.TAB_INDEX_SPEED_DIAL); |
| 552 | if (index < mListsFragment.getTabCount()) { |
| 553 | mListsFragment.showTab(index); |
| 554 | } |
| 555 | } |
| 556 | |
Anne Rong | 3520800 | 2015-07-22 16:27:37 -0700 | [diff] [blame] | 557 | setSearchBoxHint(); |
| 558 | |
Yorke Lee | f5554ce | 2015-01-27 14:46:02 -0800 | [diff] [blame] | 559 | Trace.endSection(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | @Override |
Yorke Lee | 7ee5c42 | 2014-11-04 10:29:32 -0800 | [diff] [blame] | 563 | protected void onRestart() { |
| 564 | super.onRestart(); |
| 565 | mIsRestarting = true; |
| 566 | } |
| 567 | |
| 568 | @Override |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 569 | protected void onPause() { |
| 570 | if (mClearSearchOnPause) { |
| 571 | hideDialpadAndSearchUi(); |
| 572 | mClearSearchOnPause = false; |
| 573 | } |
Yorke Lee | 19e68ca | 2014-10-28 11:51:40 -0700 | [diff] [blame] | 574 | if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) { |
| 575 | commitDialpadFragmentHide(); |
| 576 | } |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 577 | super.onPause(); |
| 578 | } |
| 579 | |
| 580 | @Override |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 581 | protected void onSaveInstanceState(Bundle outState) { |
| 582 | super.onSaveInstanceState(outState); |
| 583 | outState.putString(KEY_SEARCH_QUERY, mSearchQuery); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 584 | outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch); |
| 585 | outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 586 | outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch); |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 587 | outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown); |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 588 | mActionBarController.saveInstanceState(outState); |
Yorke Lee | 19e68ca | 2014-10-28 11:51:40 -0700 | [diff] [blame] | 589 | mStateSaved = true; |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 593 | public void onAttachFragment(Fragment fragment) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 594 | if (fragment instanceof DialpadFragment) { |
| 595 | mDialpadFragment = (DialpadFragment) fragment; |
Yorke Lee | d5c512a | 2015-01-30 14:42:53 -0800 | [diff] [blame] | 596 | if (!mIsDialpadShown && !mShowDialpadOnResume) { |
Yorke Lee | 50aba88 | 2014-05-28 20:04:31 -0700 | [diff] [blame] | 597 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
| 598 | transaction.hide(mDialpadFragment); |
| 599 | transaction.commit(); |
| 600 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 601 | } else if (fragment instanceof SmartDialSearchFragment) { |
| 602 | mSmartDialSearchFragment = (SmartDialSearchFragment) fragment; |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 603 | mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this); |
Yorke Lee | d9a9316 | 2015-10-14 09:39:05 -0700 | [diff] [blame] | 604 | if (!TextUtils.isEmpty(mDialpadQuery)) { |
| 605 | mSmartDialSearchFragment.setAddToContactNumber(mDialpadQuery); |
| 606 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 607 | } else if (fragment instanceof SearchFragment) { |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 608 | mRegularSearchFragment = (RegularSearchFragment) fragment; |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 609 | mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 610 | } else if (fragment instanceof ListsFragment) { |
| 611 | mListsFragment = (ListsFragment) fragment; |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 612 | mListsFragment.addOnPageChangeListener(this); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 613 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Alon Albert | b453e5b | 2013-09-10 15:54:23 -0700 | [diff] [blame] | 616 | protected void handleMenuSettings() { |
Yorke Lee | af6f195 | 2014-07-14 19:13:16 -0700 | [diff] [blame] | 617 | final Intent intent = new Intent(this, DialerSettingsActivity.class); |
| 618 | startActivity(intent); |
Alon Albert | b453e5b | 2013-09-10 15:54:23 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 621 | @Override |
| 622 | public void onClick(View view) { |
| 623 | switch (view.getId()) { |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 624 | case R.id.floating_action_button: |
Yorke Lee | deab5c5 | 2015-07-27 17:03:11 -0700 | [diff] [blame] | 625 | if (mListsFragment.getCurrentTabIndex() |
| 626 | == ListsFragment.TAB_INDEX_ALL_CONTACTS && !mInRegularSearch) { |
Andrew Lee | 247df6e | 2015-05-12 19:09:00 -0700 | [diff] [blame] | 627 | DialerUtils.startActivityWithErrorToast( |
| 628 | this, |
| 629 | IntentUtil.getNewContactIntent(), |
| 630 | R.string.add_contact_not_available); |
Andrew Lee | fdfeaaf | 2015-05-05 14:10:35 -0700 | [diff] [blame] | 631 | } else if (!mIsDialpadShown) { |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 632 | mInCallDialpadUp = false; |
| 633 | showDialpadFragment(true); |
Andrew Lee | a73e189 | 2014-05-13 13:21:16 -0700 | [diff] [blame] | 634 | } |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 635 | break; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 636 | case R.id.voice_search_button: |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 637 | try { |
| 638 | startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), |
| 639 | ACTIVITY_REQUEST_CODE_VOICE_SEARCH); |
| 640 | } catch (ActivityNotFoundException e) { |
| 641 | Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available, |
| 642 | Toast.LENGTH_SHORT).show(); |
| 643 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 644 | break; |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 645 | case R.id.dialtacts_options_menu_button: |
Yorke Lee | 74edcdc | 2014-07-11 16:15:08 -0700 | [diff] [blame] | 646 | mOverflowMenu.show(); |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 647 | break; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 648 | default: { |
| 649 | Log.wtf(TAG, "Unexpected onClick event from " + view); |
| 650 | break; |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 655 | @Override |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 656 | public boolean onMenuItemClick(MenuItem item) { |
Jay Shrauner | 193cfc5 | 2015-09-25 14:13:16 -0700 | [diff] [blame] | 657 | if (!isSafeToCommitTransactions()) { |
Jay Shrauner | 119b065 | 2015-09-17 12:00:18 -0700 | [diff] [blame] | 658 | return true; |
| 659 | } |
| 660 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 661 | switch (item.getItemId()) { |
| 662 | case R.id.menu_history: |
Andrew Lee | 69705be | 2015-05-04 17:24:01 -0700 | [diff] [blame] | 663 | // Use explicit CallLogActivity intent instead of ACTION_VIEW + |
| 664 | // CONTENT_TYPE, so that we always open our call log from our dialer |
| 665 | final Intent intent = new Intent(this, CallLogActivity.class); |
| 666 | startActivity(intent); |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 667 | break; |
| 668 | case R.id.menu_add_contact: |
Andrew Lee | 247df6e | 2015-05-12 19:09:00 -0700 | [diff] [blame] | 669 | DialerUtils.startActivityWithErrorToast( |
| 670 | this, |
| 671 | IntentUtil.getNewContactIntent(), |
| 672 | R.string.add_contact_not_available); |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 673 | break; |
| 674 | case R.id.menu_import_export: |
| 675 | // We hard-code the "contactsAreAvailable" argument because doing it properly would |
| 676 | // involve querying a {@link ProviderStatusLoader}, which we don't want to do right |
| 677 | // now in Dialtacts for (potential) performance reasons. Compare with how it is |
| 678 | // done in {@link PeopleActivity}. |
Wenyi Wang | 5953e8c | 2015-09-24 15:38:14 -0700 | [diff] [blame] | 679 | if (mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) { |
| 680 | ImportExportDialogFragment.show(getFragmentManager(), true, |
| 681 | DialtactsActivity.class, ImportExportDialogFragment.EXPORT_MODE_FAVORITES); |
| 682 | } else { |
| 683 | ImportExportDialogFragment.show(getFragmentManager(), true, |
| 684 | DialtactsActivity.class, ImportExportDialogFragment.EXPORT_MODE_DEFAULT); |
| 685 | } |
Yorke Lee | 58e68a9 | 2015-11-06 10:35:30 -0800 | [diff] [blame] | 686 | Logger.logScreenView(ScreenEvent.IMPORT_EXPORT_CONTACTS, this); |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 687 | return true; |
| 688 | case R.id.menu_clear_frequents: |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 689 | ClearFrequentsDialog.show(getFragmentManager()); |
Yorke Lee | 58e68a9 | 2015-11-06 10:35:30 -0800 | [diff] [blame] | 690 | Logger.logScreenView(ScreenEvent.CLEAR_FREQUENTS, this); |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 691 | return true; |
| 692 | case R.id.menu_call_settings: |
| 693 | handleMenuSettings(); |
Yorke Lee | 58e68a9 | 2015-11-06 10:35:30 -0800 | [diff] [blame] | 694 | Logger.logScreenView(ScreenEvent.SETTINGS, this); |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 695 | return true; |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 696 | } |
| 697 | return false; |
| 698 | } |
| 699 | |
| 700 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 701 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 702 | if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) { |
| 703 | if (resultCode == RESULT_OK) { |
| 704 | final ArrayList<String> matches = data.getStringArrayListExtra( |
| 705 | RecognizerIntent.EXTRA_RESULTS); |
| 706 | if (matches.size() > 0) { |
| 707 | final String match = matches.get(0); |
Tyler Gunn | c1cfae5 | 2014-11-20 13:22:54 -0800 | [diff] [blame] | 708 | mVoiceSearchQuery = match; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 709 | } else { |
| 710 | Log.e(TAG, "Voice search - nothing heard"); |
| 711 | } |
| 712 | } else { |
| 713 | Log.e(TAG, "Voice search failed"); |
| 714 | } |
| 715 | } |
| 716 | super.onActivityResult(requestCode, resultCode, data); |
| 717 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 718 | |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 719 | /** |
Nancy Chen | ea7c0b8 | 2015-08-31 17:18:41 -0700 | [diff] [blame] | 720 | * Update the number of unread voicemails (potentially other tabs) displayed next to the tab |
| 721 | * icon. |
| 722 | */ |
| 723 | public void updateTabUnreadCounts() { |
| 724 | mListsFragment.updateTabUnreadCounts(); |
| 725 | } |
| 726 | |
| 727 | /** |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 728 | * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual |
| 729 | * updates are handled by a callback which is invoked after the dialpad fragment is shown. |
| 730 | * @see #onDialpadShown |
| 731 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 732 | private void showDialpadFragment(boolean animate) { |
Yorke Lee | 19e68ca | 2014-10-28 11:51:40 -0700 | [diff] [blame] | 733 | if (mIsDialpadShown || mStateSaved) { |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 734 | return; |
| 735 | } |
| 736 | mIsDialpadShown = true; |
Yorke Lee | d5c512a | 2015-01-30 14:42:53 -0800 | [diff] [blame] | 737 | |
Yorke Lee | 7ee5c42 | 2014-11-04 10:29:32 -0800 | [diff] [blame] | 738 | mListsFragment.setUserVisibleHint(false); |
Andrew Lee | cdfa6c6 | 2014-05-06 15:33:35 -0700 | [diff] [blame] | 739 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 740 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
Yorke Lee | d5c512a | 2015-01-30 14:42:53 -0800 | [diff] [blame] | 741 | if (mDialpadFragment == null) { |
| 742 | mDialpadFragment = new DialpadFragment(); |
| 743 | ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT); |
| 744 | } else { |
| 745 | ft.show(mDialpadFragment); |
| 746 | } |
| 747 | |
| 748 | mDialpadFragment.setAnimate(animate); |
Yorke Lee | 58e68a9 | 2015-11-06 10:35:30 -0800 | [diff] [blame] | 749 | Logger.logScreenView(ScreenEvent.DIALPAD, this); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 750 | ft.commit(); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 751 | |
Yorke Lee | 29ae4ae | 2014-09-09 16:30:34 -0700 | [diff] [blame] | 752 | if (animate) { |
| 753 | mFloatingActionButtonController.scaleOut(); |
| 754 | } else { |
| 755 | mFloatingActionButtonController.setVisible(false); |
Yorke Lee | 81a313d | 2015-06-01 14:53:59 -0700 | [diff] [blame] | 756 | maybeEnterSearchUi(); |
Yorke Lee | 29ae4ae | 2014-09-09 16:30:34 -0700 | [diff] [blame] | 757 | } |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 758 | mActionBarController.onDialpadUp(); |
| 759 | |
Yorke Lee | 6c450eb | 2015-05-08 09:45:47 -0700 | [diff] [blame] | 760 | mListsFragment.getView().animate().alpha(0).withLayer(); |
Ta-wei Yen | e3cae63 | 2015-10-27 16:09:09 -0700 | [diff] [blame] | 761 | |
| 762 | //adjust the title, so the user will know where we're at when the activity start/resumes. |
| 763 | setTitle(R.string.launcherDialpadActivityLabel); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 764 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 765 | |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 766 | /** |
| 767 | * Callback from child DialpadFragment when the dialpad is shown. |
| 768 | */ |
| 769 | public void onDialpadShown() { |
Yorke Lee | d5c512a | 2015-01-30 14:42:53 -0800 | [diff] [blame] | 770 | Assert.assertNotNull(mDialpadFragment); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 771 | if (mDialpadFragment.getAnimate()) { |
Sai Cheemalapati | 82d6da5 | 2014-06-03 13:54:23 -0700 | [diff] [blame] | 772 | mDialpadFragment.getView().startAnimation(mSlideIn); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 773 | } else { |
| 774 | mDialpadFragment.setYFraction(0); |
| 775 | } |
| 776 | |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 777 | updateSearchFragmentPosition(); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /** |
| 781 | * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in |
| 782 | * a callback after the hide animation ends. |
| 783 | * @see #commitDialpadFragmentHide |
| 784 | */ |
Yorke Lee | ca19504 | 2013-09-25 16:29:38 -0700 | [diff] [blame] | 785 | public void hideDialpadFragment(boolean animate, boolean clearDialpad) { |
Yorke Lee | 791b488 | 2015-05-15 10:52:27 -0700 | [diff] [blame] | 786 | if (mDialpadFragment == null || mDialpadFragment.getView() == null) { |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 787 | return; |
| 788 | } |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 789 | if (clearDialpad) { |
| 790 | mDialpadFragment.clearDialpad(); |
| 791 | } |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 792 | if (!mIsDialpadShown) { |
| 793 | return; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 794 | } |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 795 | mIsDialpadShown = false; |
| 796 | mDialpadFragment.setAnimate(animate); |
Yorke Lee | 7ee5c42 | 2014-11-04 10:29:32 -0800 | [diff] [blame] | 797 | mListsFragment.setUserVisibleHint(true); |
| 798 | mListsFragment.sendScreenViewForCurrentPosition(); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 799 | |
Andrew Lee | dbe9a8c | 2014-05-16 15:18:40 -0700 | [diff] [blame] | 800 | updateSearchFragmentPosition(); |
Sai Cheemalapati | c4969ea | 2014-06-04 16:35:16 -0700 | [diff] [blame] | 801 | |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 802 | mFloatingActionButtonController.align(getFabAlignment(), animate); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 803 | if (animate) { |
Sai Cheemalapati | 82d6da5 | 2014-06-03 13:54:23 -0700 | [diff] [blame] | 804 | mDialpadFragment.getView().startAnimation(mSlideOut); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 805 | } else { |
| 806 | commitDialpadFragmentHide(); |
| 807 | } |
| 808 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 809 | mActionBarController.onDialpadDown(); |
Yorke Lee | 11ca39e | 2014-05-19 20:31:37 -0700 | [diff] [blame] | 810 | |
Andrew Lee | d4cde83 | 2014-05-16 15:56:48 -0700 | [diff] [blame] | 811 | if (isInSearchUi()) { |
Andrew Lee | 44e3daf | 2014-05-19 14:28:16 -0700 | [diff] [blame] | 812 | if (TextUtils.isEmpty(mSearchQuery)) { |
| 813 | exitSearchUi(); |
Andrew Lee | 44e3daf | 2014-05-19 14:28:16 -0700 | [diff] [blame] | 814 | } |
Andrew Lee | d4cde83 | 2014-05-16 15:56:48 -0700 | [diff] [blame] | 815 | } |
Ta-wei Yen | e3cae63 | 2015-10-27 16:09:09 -0700 | [diff] [blame] | 816 | //reset the title to normal. |
| 817 | setTitle(R.string.launcherActivityLabel); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /** |
| 821 | * Finishes hiding the dialpad fragment after any animations are completed. |
| 822 | */ |
| 823 | private void commitDialpadFragmentHide() { |
Yorke Lee | d5c512a | 2015-01-30 14:42:53 -0800 | [diff] [blame] | 824 | if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) { |
Yorke Lee | 19e68ca | 2014-10-28 11:51:40 -0700 | [diff] [blame] | 825 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
| 826 | ft.hide(mDialpadFragment); |
| 827 | ft.commit(); |
| 828 | } |
Andrew Lee | 405a6e6 | 2014-08-20 15:02:16 -0700 | [diff] [blame] | 829 | mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 832 | private void updateSearchFragmentPosition() { |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 833 | SearchFragment fragment = null; |
Andrew Lee | dbe9a8c | 2014-05-16 15:18:40 -0700 | [diff] [blame] | 834 | if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) { |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 835 | fragment = mSmartDialSearchFragment; |
Andrew Lee | dbe9a8c | 2014-05-16 15:18:40 -0700 | [diff] [blame] | 836 | } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) { |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 837 | fragment = mRegularSearchFragment; |
| 838 | } |
| 839 | if (fragment != null && fragment.isVisible()) { |
Andrew Lee | 9da8fb4 | 2014-06-03 14:03:09 -0700 | [diff] [blame] | 840 | fragment.updatePosition(true /* animate */); |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 844 | @Override |
| 845 | public boolean isInSearchUi() { |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 846 | return mInDialpadSearch || mInRegularSearch; |
| 847 | } |
| 848 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 849 | @Override |
| 850 | public boolean hasSearchQuery() { |
| 851 | return !TextUtils.isEmpty(mSearchQuery); |
| 852 | } |
| 853 | |
| 854 | @Override |
| 855 | public boolean shouldShowActionBar() { |
| 856 | return mListsFragment.shouldShowActionBar(); |
| 857 | } |
| 858 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 859 | private void setNotInSearchUi() { |
| 860 | mInDialpadSearch = false; |
| 861 | mInRegularSearch = false; |
| 862 | } |
| 863 | |
Yorke Lee | 311969c | 2013-08-26 06:31:11 -0700 | [diff] [blame] | 864 | private void hideDialpadAndSearchUi() { |
Yorke Lee | 710709d | 2014-05-29 07:18:42 -0700 | [diff] [blame] | 865 | if (mIsDialpadShown) { |
| 866 | hideDialpadFragment(false, true); |
| 867 | } else { |
| 868 | exitSearchUi(); |
| 869 | } |
Yorke Lee | 311969c | 2013-08-26 06:31:11 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 872 | private void prepareVoiceSearchButton() { |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 873 | final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); |
| 874 | if (canIntentBeHandled(voiceIntent)) { |
| 875 | mVoiceSearchButton.setVisibility(View.VISIBLE); |
| 876 | mVoiceSearchButton.setOnClickListener(this); |
| 877 | } else { |
| 878 | mVoiceSearchButton.setVisibility(View.GONE); |
| 879 | } |
| 880 | } |
| 881 | |
Yorke Lee | e9c8233 | 2015-10-06 14:21:53 -0700 | [diff] [blame] | 882 | public boolean isNearbyPlacesSearchEnabled() { |
| 883 | return false; |
| 884 | } |
| 885 | |
Anne Rong | 3520800 | 2015-07-22 16:27:37 -0700 | [diff] [blame] | 886 | protected int getSearchBoxHint () { |
| 887 | return R.string.dialer_hint_find_contact; |
| 888 | } |
| 889 | |
| 890 | /** |
| 891 | * Sets the hint text for the contacts search box |
| 892 | */ |
| 893 | private void setSearchBoxHint() { |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 894 | SearchEditTextLayout searchEditTextLayout = (SearchEditTextLayout) getSupportActionBar() |
Anne Rong | 3520800 | 2015-07-22 16:27:37 -0700 | [diff] [blame] | 895 | .getCustomView().findViewById(R.id.search_view_container); |
| 896 | ((TextView) searchEditTextLayout.findViewById(R.id.search_box_start_search)) |
| 897 | .setHint(getSearchBoxHint()); |
| 898 | } |
| 899 | |
Andrew Lee | 467de3d | 2015-03-17 15:47:24 -0700 | [diff] [blame] | 900 | protected OptionsPopupMenu buildOptionsMenu(View invoker) { |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 901 | final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker); |
| 902 | popupMenu.inflate(R.menu.dialtacts_options); |
| 903 | popupMenu.setOnMenuItemClickListener(this); |
| 904 | return popupMenu; |
| 905 | } |
| 906 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 907 | @Override |
| 908 | public boolean onCreateOptionsMenu(Menu menu) { |
Yorke Lee | 3c9e7cd | 2014-04-16 11:37:21 -0700 | [diff] [blame] | 909 | if (mPendingSearchViewQuery != null) { |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 910 | mSearchView.setText(mPendingSearchViewQuery); |
Yorke Lee | 3c9e7cd | 2014-04-16 11:37:21 -0700 | [diff] [blame] | 911 | mPendingSearchViewQuery = null; |
| 912 | } |
Yorke Lee | c16ea5a | 2015-05-19 15:51:01 -0700 | [diff] [blame] | 913 | if (mActionBarController != null) { |
| 914 | mActionBarController.restoreActionBarOffset(); |
| 915 | } |
Andrew Lee | e74a10e | 2014-05-16 14:31:40 -0700 | [diff] [blame] | 916 | return false; |
Ihab Awad | fb00cb8 | 2014-03-18 16:19:00 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 919 | /** |
| 920 | * Returns true if the intent is due to hitting the green send key (hardware call button: |
| 921 | * KEYCODE_CALL) while in a call. |
| 922 | * |
| 923 | * @param intent the intent that launched this activity |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 924 | * @return true if the intent is due to hitting the green send key while in a call |
| 925 | */ |
Yorke Lee | 62e995c | 2014-03-28 10:02:56 -0700 | [diff] [blame] | 926 | private boolean isSendKeyWhileInCall(Intent intent) { |
| 927 | // If there is a call in progress and the user launched the dialer by hitting the call |
| 928 | // button, go straight to the in-call screen. |
| 929 | final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction()); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 930 | |
Santos Cordon | 1d7ef6a | 2014-05-29 21:46:33 -0700 | [diff] [blame] | 931 | if (callKey) { |
Yorke Lee | 762b357 | 2015-09-18 12:54:59 -0700 | [diff] [blame] | 932 | TelecomUtil.showInCallScreen(this, false); |
Santos Cordon | 1d7ef6a | 2014-05-29 21:46:33 -0700 | [diff] [blame] | 933 | return true; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | return false; |
| 937 | } |
| 938 | |
| 939 | /** |
| 940 | * Sets the current tab based on the intent's request type |
| 941 | * |
| 942 | * @param intent Intent that contains information about which tab should be selected |
| 943 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 944 | private void displayFragment(Intent intent) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 945 | // If we got here by hitting send and we're in call forward along to the in-call activity |
Yorke Lee | 62e995c | 2014-03-28 10:02:56 -0700 | [diff] [blame] | 946 | if (isSendKeyWhileInCall(intent)) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 947 | finish(); |
| 948 | return; |
| 949 | } |
| 950 | |
Yorke Lee | d77017d | 2015-08-31 16:19:43 -0700 | [diff] [blame] | 951 | final boolean showDialpadChooser = phoneIsInUse() && !DialpadFragment.isAddCallMode(intent); |
| 952 | if (showDialpadChooser || (intent.getData() != null && isDialIntent(intent))) { |
Yorke Lee | d5c512a | 2015-01-30 14:42:53 -0800 | [diff] [blame] | 953 | showDialpadFragment(false); |
| 954 | mDialpadFragment.setStartedFromNewIntent(true); |
Yorke Lee | d77017d | 2015-08-31 16:19:43 -0700 | [diff] [blame] | 955 | if (showDialpadChooser && !mDialpadFragment.isVisible()) { |
Yorke Lee | d5c512a | 2015-01-30 14:42:53 -0800 | [diff] [blame] | 956 | mInCallDialpadUp = true; |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 957 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 958 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | @Override |
| 962 | public void onNewIntent(Intent newIntent) { |
| 963 | setIntent(newIntent); |
Yorke Lee | 24d034f | 2015-07-01 12:34:50 -0700 | [diff] [blame] | 964 | |
Nancy Chen | 199b7f0 | 2014-11-05 15:03:00 -0800 | [diff] [blame] | 965 | mStateSaved = false; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 966 | displayFragment(newIntent); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 967 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 968 | invalidateOptionsMenu(); |
| 969 | } |
| 970 | |
| 971 | /** Returns true if the given intent contains a phone number to populate the dialer with */ |
| 972 | private boolean isDialIntent(Intent intent) { |
| 973 | final String action = intent.getAction(); |
| 974 | if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) { |
| 975 | return true; |
| 976 | } |
| 977 | if (Intent.ACTION_VIEW.equals(action)) { |
| 978 | final Uri data = intent.getData(); |
Jay Shrauner | ae274c0 | 2014-09-06 10:09:24 -0700 | [diff] [blame] | 979 | if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 980 | return true; |
| 981 | } |
| 982 | } |
| 983 | return false; |
| 984 | } |
| 985 | |
| 986 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 987 | * Shows the search fragment |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 988 | */ |
Yorke Lee | 6c450eb | 2015-05-08 09:45:47 -0700 | [diff] [blame] | 989 | private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) { |
Yorke Lee | 19e68ca | 2014-10-28 11:51:40 -0700 | [diff] [blame] | 990 | if (mStateSaved || getFragmentManager().isDestroyed()) { |
Yorke Lee | 34bdf87 | 2013-08-15 14:11:50 -0700 | [diff] [blame] | 991 | // Weird race condition where fragment is doing work after the activity is destroyed |
| 992 | // due to talkback being on (b/10209937). Just return since we can't do any |
| 993 | // constructive here. |
| 994 | return; |
| 995 | } |
| 996 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 997 | if (DEBUG) { |
| 998 | Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch); |
| 999 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 1000 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1001 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1002 | if (mInDialpadSearch && mSmartDialSearchFragment != null) { |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 1003 | transaction.remove(mSmartDialSearchFragment); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1004 | } else if (mInRegularSearch && mRegularSearchFragment != null) { |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 1005 | transaction.remove(mRegularSearchFragment); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 1006 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 1007 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 1008 | final String tag; |
| 1009 | if (smartDialSearch) { |
| 1010 | tag = TAG_SMARTDIAL_SEARCH_FRAGMENT; |
| 1011 | } else { |
| 1012 | tag = TAG_REGULAR_SEARCH_FRAGMENT; |
| 1013 | } |
| 1014 | mInDialpadSearch = smartDialSearch; |
| 1015 | mInRegularSearch = !smartDialSearch; |
| 1016 | |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 1017 | mFloatingActionButtonController.scaleOut(); |
| 1018 | |
Andrew Lee | 752956e | 2014-05-15 11:43:38 -0700 | [diff] [blame] | 1019 | SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag); |
Yorke Lee | 6c450eb | 2015-05-08 09:45:47 -0700 | [diff] [blame] | 1020 | if (animate) { |
| 1021 | transaction.setCustomAnimations(android.R.animator.fade_in, 0); |
| 1022 | } else { |
| 1023 | transaction.setTransition(FragmentTransaction.TRANSIT_NONE); |
| 1024 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 1025 | if (fragment == null) { |
| 1026 | if (smartDialSearch) { |
| 1027 | fragment = new SmartDialSearchFragment(); |
| 1028 | } else { |
Yorke Lee | 807afd8 | 2015-10-12 10:03:07 -0700 | [diff] [blame] | 1029 | fragment = ObjectFactory.newRegularSearchFragment(); |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 1030 | fragment.setOnTouchListener(new View.OnTouchListener() { |
| 1031 | @Override |
| 1032 | public boolean onTouch(View v, MotionEvent event) { |
| 1033 | // Show the FAB when the user touches the lists fragment and the soft |
| 1034 | // keyboard is hidden. |
| 1035 | showFabInSearchUi(); |
| 1036 | return false; |
| 1037 | } |
| 1038 | }); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 1039 | } |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 1040 | transaction.add(R.id.dialtacts_frame, fragment, tag); |
| 1041 | } else { |
| 1042 | transaction.show(fragment); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 1043 | } |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 1044 | // DialtactsActivity will provide the options menu |
| 1045 | fragment.setHasOptionsMenu(false); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 1046 | fragment.setShowEmptyListForNullQuery(true); |
Yorke Lee | 6c450eb | 2015-05-08 09:45:47 -0700 | [diff] [blame] | 1047 | if (!smartDialSearch) { |
| 1048 | fragment.setQueryString(query, false /* delaySelection */); |
| 1049 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 1050 | transaction.commit(); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 1051 | |
Yorke Lee | 6c450eb | 2015-05-08 09:45:47 -0700 | [diff] [blame] | 1052 | if (animate) { |
| 1053 | mListsFragment.getView().animate().alpha(0).withLayer(); |
| 1054 | } |
Yorke Lee | 7ee5c42 | 2014-11-04 10:29:32 -0800 | [diff] [blame] | 1055 | mListsFragment.setUserVisibleHint(false); |
Yorke Lee | f96bb18 | 2015-11-10 10:06:21 -0800 | [diff] [blame^] | 1056 | |
| 1057 | if (smartDialSearch) { |
| 1058 | Logger.logScreenView(ScreenEvent.SMART_DIAL_SEARCH, this); |
| 1059 | } else { |
| 1060 | Logger.logScreenView(ScreenEvent.REGULAR_SEARCH, this); |
| 1061 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1065 | * Hides the search fragment |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1066 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1067 | private void exitSearchUi() { |
Yorke Lee | 3487db7 | 2013-09-26 17:12:06 -0700 | [diff] [blame] | 1068 | // See related bug in enterSearchUI(); |
Yorke Lee | 19e68ca | 2014-10-28 11:51:40 -0700 | [diff] [blame] | 1069 | if (getFragmentManager().isDestroyed() || mStateSaved) { |
Yorke Lee | 3487db7 | 2013-09-26 17:12:06 -0700 | [diff] [blame] | 1070 | return; |
| 1071 | } |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 1072 | |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 1073 | mSearchView.setText(null); |
Yorke Lee | d5c512a | 2015-01-30 14:42:53 -0800 | [diff] [blame] | 1074 | |
| 1075 | if (mDialpadFragment != null) { |
| 1076 | mDialpadFragment.clearDialpad(); |
| 1077 | } |
| 1078 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 1079 | setNotInSearchUi(); |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame] | 1080 | |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 1081 | // Restore the FAB for the lists fragment. |
| 1082 | if (getFabAlignment() != FloatingActionButtonController.ALIGN_END) { |
| 1083 | mFloatingActionButtonController.setVisible(false); |
| 1084 | } |
| 1085 | mFloatingActionButtonController.scaleIn(FAB_SCALE_IN_DELAY_MS); |
| 1086 | onPageScrolled(mListsFragment.getCurrentTabIndex(), 0 /* offset */, 0 /* pixelOffset */); |
| 1087 | onPageSelected(mListsFragment.getCurrentTabIndex()); |
| 1088 | |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 1089 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 1090 | if (mSmartDialSearchFragment != null) { |
| 1091 | transaction.remove(mSmartDialSearchFragment); |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame] | 1092 | } |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 1093 | if (mRegularSearchFragment != null) { |
| 1094 | transaction.remove(mRegularSearchFragment); |
| 1095 | } |
| 1096 | transaction.commit(); |
| 1097 | |
| 1098 | mListsFragment.getView().animate().alpha(1).withLayer(); |
Yorke Lee | d5c512a | 2015-01-30 14:42:53 -0800 | [diff] [blame] | 1099 | |
| 1100 | if (mDialpadFragment == null || !mDialpadFragment.isVisible()) { |
Yorke Lee | 7ee5c42 | 2014-11-04 10:29:32 -0800 | [diff] [blame] | 1101 | // If the dialpad fragment wasn't previously visible, then send a screen view because |
| 1102 | // we are exiting regular search. Otherwise, the screen view will be sent by |
| 1103 | // {@link #hideDialpadFragment}. |
| 1104 | mListsFragment.sendScreenViewForCurrentPosition(); |
| 1105 | mListsFragment.setUserVisibleHint(true); |
| 1106 | } |
| 1107 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 1108 | mActionBarController.onSearchUiExited(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1111 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1112 | public void onBackPressed() { |
Yorke Lee | 19e68ca | 2014-10-28 11:51:40 -0700 | [diff] [blame] | 1113 | if (mStateSaved) { |
| 1114 | return; |
| 1115 | } |
Andrew Lee | 2a58ab8 | 2014-05-15 02:16:04 -0700 | [diff] [blame] | 1116 | if (mIsDialpadShown) { |
Andrew Lee | 9fd8f25 | 2014-06-13 17:09:26 -0700 | [diff] [blame] | 1117 | if (TextUtils.isEmpty(mSearchQuery) || |
| 1118 | (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible() |
| 1119 | && mSmartDialSearchFragment.getAdapter().getCount() == 0)) { |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 1120 | exitSearchUi(); |
| 1121 | } |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 1122 | hideDialpadFragment(true, false); |
Andrew Lee | b190384 | 2014-05-15 16:11:24 -0700 | [diff] [blame] | 1123 | } else if (isInSearchUi()) { |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 1124 | exitSearchUi(); |
Yorke Lee | f614f6f | 2014-10-03 10:44:19 -0700 | [diff] [blame] | 1125 | DialerUtils.hideInputMethod(mParentLayout); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1126 | } else { |
| 1127 | super.onBackPressed(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1128 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
Yorke Lee | 81a313d | 2015-06-01 14:53:59 -0700 | [diff] [blame] | 1131 | private void maybeEnterSearchUi() { |
| 1132 | if (!isInSearchUi()) { |
| 1133 | enterSearchUi(true /* isSmartDial */, mSearchQuery, false); |
| 1134 | } |
| 1135 | } |
| 1136 | |
Yorke Lee | c7b2a0e | 2014-05-20 17:21:25 -0700 | [diff] [blame] | 1137 | /** |
| 1138 | * @return True if the search UI was exited, false otherwise |
| 1139 | */ |
| 1140 | private boolean maybeExitSearchUi() { |
| 1141 | if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) { |
| 1142 | exitSearchUi(); |
Yorke Lee | f614f6f | 2014-10-03 10:44:19 -0700 | [diff] [blame] | 1143 | DialerUtils.hideInputMethod(mParentLayout); |
Yorke Lee | c7b2a0e | 2014-05-20 17:21:25 -0700 | [diff] [blame] | 1144 | return true; |
| 1145 | } |
| 1146 | return false; |
| 1147 | } |
| 1148 | |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 1149 | private void showFabInSearchUi() { |
| 1150 | mFloatingActionButtonController.changeIcon( |
| 1151 | getResources().getDrawable(R.drawable.fab_ic_dial), |
| 1152 | getResources().getString(R.string.action_menu_dialpad_button)); |
| 1153 | mFloatingActionButtonController.align(getFabAlignment(), false /* animate */); |
| 1154 | mFloatingActionButtonController.scaleIn(FAB_SCALE_IN_DELAY_MS); |
| 1155 | } |
| 1156 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1157 | @Override |
| 1158 | public void onDialpadQueryChanged(String query) { |
Yorke Lee | d9a9316 | 2015-10-14 09:39:05 -0700 | [diff] [blame] | 1159 | mDialpadQuery = query; |
Yorke Lee | 4663587 | 2014-04-11 11:20:15 -0700 | [diff] [blame] | 1160 | if (mSmartDialSearchFragment != null) { |
| 1161 | mSmartDialSearchFragment.setAddToContactNumber(query); |
| 1162 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1163 | final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query, |
| 1164 | SmartDialNameMatcher.LATIN_SMART_DIAL_MAP); |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 1165 | |
| 1166 | if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 1167 | if (DEBUG) { |
| 1168 | Log.d(TAG, "onDialpadQueryChanged - new query: " + query); |
| 1169 | } |
| 1170 | if (mDialpadFragment == null || !mDialpadFragment.isVisible()) { |
| 1171 | // This callback can happen if the dialpad fragment is recreated because of |
| 1172 | // activity destruction. In that case, don't update the search view because |
| 1173 | // that would bring the user back to the search fragment regardless of the |
| 1174 | // previous state of the application. Instead, just return here and let the |
| 1175 | // fragment manager correctly figure out whatever fragment was last displayed. |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 1176 | if (!TextUtils.isEmpty(normalizedQuery)) { |
| 1177 | mPendingSearchViewQuery = normalizedQuery; |
| 1178 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 1179 | return; |
| 1180 | } |
Yorke Lee | 53a2230 | 2014-04-29 18:13:46 -0700 | [diff] [blame] | 1181 | mSearchView.setText(normalizedQuery); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1182 | } |
Santos Cordon | 8313171 | 2015-04-16 21:25:35 -0700 | [diff] [blame] | 1183 | |
| 1184 | try { |
| 1185 | if (mDialpadFragment != null && mDialpadFragment.isVisible()) { |
| 1186 | mDialpadFragment.process_quote_emergency_unquote(normalizedQuery); |
| 1187 | } |
| 1188 | } catch (Exception ignored) { |
| 1189 | // Skip any exceptions for this piece of code |
| 1190 | } |
Yorke Lee | 575ae38 | 2015-07-16 11:36:07 -0700 | [diff] [blame] | 1191 | } |
Santos Cordon | 8313171 | 2015-04-16 21:25:35 -0700 | [diff] [blame] | 1192 | |
Yorke Lee | 575ae38 | 2015-07-16 11:36:07 -0700 | [diff] [blame] | 1193 | @Override |
| 1194 | public boolean onDialpadSpacerTouchWithEmptyQuery() { |
| 1195 | if (mInDialpadSearch && mSmartDialSearchFragment != null |
| 1196 | && !mSmartDialSearchFragment.isShowingPermissionRequest()) { |
| 1197 | hideDialpadFragment(true /* animate */, true /* clearDialpad */); |
| 1198 | return true; |
| 1199 | } |
| 1200 | return false; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1201 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1202 | |
| 1203 | @Override |
| 1204 | public void onListFragmentScrollStateChange(int scrollState) { |
| 1205 | if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 1206 | hideDialpadFragment(true, false); |
Yorke Lee | f614f6f | 2014-10-03 10:44:19 -0700 | [diff] [blame] | 1207 | DialerUtils.hideInputMethod(mParentLayout); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | @Override |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 1212 | public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount, |
Andrew Lee | 99a570c | 2014-05-15 14:18:50 -0700 | [diff] [blame] | 1213 | int totalItemCount) { |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1214 | // TODO: No-op for now. This should eventually show/hide the actionBar based on |
| 1215 | // interactions with the ListsFragments. |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1218 | private boolean phoneIsInUse() { |
Yorke Lee | 827a90f | 2015-09-17 18:10:58 -0700 | [diff] [blame] | 1219 | return TelecomUtil.isInCall(this); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 1220 | } |
Yorke Lee | 8dd6200 | 2013-08-08 15:57:20 -0700 | [diff] [blame] | 1221 | |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 1222 | private boolean canIntentBeHandled(Intent intent) { |
| 1223 | final PackageManager packageManager = getPackageManager(); |
| 1224 | final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, |
| 1225 | PackageManager.MATCH_DEFAULT_ONLY); |
| 1226 | return resolveInfo != null && resolveInfo.size() > 0; |
| 1227 | } |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1228 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 1229 | /** |
| 1230 | * Called when the user has long-pressed a contact tile to start a drag operation. |
| 1231 | */ |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1232 | @Override |
Yorke Lee | efb2d9c | 2014-04-18 14:05:01 -0700 | [diff] [blame] | 1233 | public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) { |
Andrew Lee | 1896344 | 2014-06-06 17:20:13 -0700 | [diff] [blame] | 1234 | mListsFragment.showRemoveView(true); |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | @Override |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 1238 | public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) { |
| 1239 | } |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1240 | |
Yorke Lee | 86e21f7 | 2014-04-02 16:49:38 -0700 | [diff] [blame] | 1241 | /** |
| 1242 | * Called when the user has released a contact tile after long-pressing it. |
| 1243 | */ |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1244 | @Override |
| 1245 | public void onDragFinished(int x, int y) { |
Andrew Lee | 1896344 | 2014-06-06 17:20:13 -0700 | [diff] [blame] | 1246 | mListsFragment.showRemoveView(false); |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | @Override |
| 1250 | public void onDroppedOnRemove() {} |
| 1251 | |
| 1252 | /** |
Yorke Lee | d999b71 | 2014-04-23 15:10:58 -0700 | [diff] [blame] | 1253 | * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1254 | * once it has been attached to the activity. |
| 1255 | */ |
| 1256 | @Override |
| 1257 | public void setDragDropController(DragDropController dragController) { |
Yorke Lee | 2826619 | 2014-05-01 10:05:52 -0700 | [diff] [blame] | 1258 | mDragDropController = dragController; |
Andrew Lee | 1896344 | 2014-06-06 17:20:13 -0700 | [diff] [blame] | 1259 | mListsFragment.getRemoveView().setDragDropController(dragController); |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1260 | } |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1261 | |
Yorke Lee | 38019af | 2015-07-14 17:05:38 -0700 | [diff] [blame] | 1262 | /** |
| 1263 | * Implemented to satisfy {@link SpeedDialFragment.HostInterface} |
| 1264 | */ |
| 1265 | @Override |
| 1266 | public void showAllContactsTab() { |
| 1267 | if (mListsFragment != null) { |
| 1268 | mListsFragment.showTab(ListsFragment.TAB_INDEX_ALL_CONTACTS); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | /** |
| 1273 | * Implemented to satisfy {@link CallLogFragment.HostInterface} |
| 1274 | */ |
| 1275 | @Override |
| 1276 | public void showDialpad() { |
| 1277 | showDialpadFragment(true); |
| 1278 | } |
| 1279 | |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1280 | @Override |
Anne Rong | 071d0a4 | 2015-09-29 15:15:26 -0700 | [diff] [blame] | 1281 | public void onPickDataUri(Uri dataUri, int callInitiationType) { |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 1282 | mClearSearchOnPause = true; |
Yorke Lee | c8d6e16 | 2015-09-14 18:43:27 -0700 | [diff] [blame] | 1283 | PhoneNumberInteraction.startInteractionForPhoneCall( |
| 1284 | DialtactsActivity.this, dataUri, callInitiationType); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | @Override |
Anne Rong | 071d0a4 | 2015-09-29 15:15:26 -0700 | [diff] [blame] | 1288 | public void onPickPhoneNumber(String phoneNumber, boolean isVideoCall, int callInitiationType) { |
Yorke Lee | 24d034f | 2015-07-01 12:34:50 -0700 | [diff] [blame] | 1289 | if (phoneNumber == null) { |
| 1290 | // Invalid phone number, but let the call go through so that InCallUI can show |
| 1291 | // an error message. |
| 1292 | phoneNumber = ""; |
| 1293 | } |
Yorke Lee | e3a2d13 | 2015-09-14 16:52:08 -0700 | [diff] [blame] | 1294 | |
| 1295 | final Intent intent = new CallIntentBuilder(phoneNumber) |
| 1296 | .setIsVideoCall(isVideoCall) |
Yorke Lee | c8d6e16 | 2015-09-14 18:43:27 -0700 | [diff] [blame] | 1297 | .setCallInitiationType(callInitiationType) |
Yorke Lee | e3a2d13 | 2015-09-14 16:52:08 -0700 | [diff] [blame] | 1298 | .build(); |
| 1299 | |
Yorke Lee | 7d20f82 | 2014-06-19 17:09:33 -0700 | [diff] [blame] | 1300 | DialerUtils.startActivityWithErrorToast(this, intent); |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 1301 | mClearSearchOnPause = true; |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | @Override |
| 1305 | public void onShortcutIntentCreated(Intent intent) { |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 1306 | Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring."); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | @Override |
| 1310 | public void onHomeInActionBarSelected() { |
Yorke Lee | 4e28c1d | 2014-05-13 15:38:10 -0700 | [diff] [blame] | 1311 | exitSearchUi(); |
Yorke Lee | e00c9fe | 2014-04-12 12:42:06 -0700 | [diff] [blame] | 1312 | } |
Yorke Lee | 33932ff | 2014-04-16 13:34:32 -0700 | [diff] [blame] | 1313 | |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 1314 | @Override |
| 1315 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { |
Andrew Lee | 432d4b5 | 2015-05-20 16:52:00 -0700 | [diff] [blame] | 1316 | int tabIndex = mListsFragment.getCurrentTabIndex(); |
| 1317 | |
Andrew Lee | 4de59fb | 2015-08-13 15:20:08 -0700 | [diff] [blame] | 1318 | // Scroll the button from center to end when moving from the Speed Dial to Call History tab. |
| 1319 | // In RTL, scroll when the current tab is Call History instead, since the order of the tabs |
| 1320 | // is reversed and the ViewPager returns the left tab position during scroll. |
Andrew Lee | 432d4b5 | 2015-05-20 16:52:00 -0700 | [diff] [blame] | 1321 | boolean isRtl = DialerUtils.isRtl(); |
| 1322 | if (!isRtl && tabIndex == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) { |
| 1323 | mFloatingActionButtonController.onPageScrolled(positionOffset); |
Andrew Lee | 4de59fb | 2015-08-13 15:20:08 -0700 | [diff] [blame] | 1324 | } else if (isRtl && tabIndex == ListsFragment.TAB_INDEX_HISTORY && !mIsLandscape) { |
Andrew Lee | 432d4b5 | 2015-05-20 16:52:00 -0700 | [diff] [blame] | 1325 | mFloatingActionButtonController.onPageScrolled(1 - positionOffset); |
| 1326 | } else if (tabIndex != ListsFragment.TAB_INDEX_SPEED_DIAL) { |
Sai Cheemalapati | 00a3d5d | 2014-06-13 10:22:26 -0700 | [diff] [blame] | 1327 | mFloatingActionButtonController.onPageScrolled(1); |
Sai Cheemalapati | c4969ea | 2014-06-04 16:35:16 -0700 | [diff] [blame] | 1328 | } |
Andrew Lee | 432d4b5 | 2015-05-20 16:52:00 -0700 | [diff] [blame] | 1329 | } |
Andrew Lee | fdfeaaf | 2015-05-05 14:10:35 -0700 | [diff] [blame] | 1330 | |
Andrew Lee | 432d4b5 | 2015-05-20 16:52:00 -0700 | [diff] [blame] | 1331 | @Override |
| 1332 | public void onPageSelected(int position) { |
| 1333 | int tabIndex = mListsFragment.getCurrentTabIndex(); |
| 1334 | if (tabIndex == ListsFragment.TAB_INDEX_ALL_CONTACTS) { |
Andrew Lee | fdfeaaf | 2015-05-05 14:10:35 -0700 | [diff] [blame] | 1335 | mFloatingActionButtonController.changeIcon( |
| 1336 | getResources().getDrawable(R.drawable.ic_person_add_24dp), |
| 1337 | getResources().getString(R.string.search_shortcut_create_new_contact)); |
| 1338 | } else { |
| 1339 | mFloatingActionButtonController.changeIcon( |
| 1340 | getResources().getDrawable(R.drawable.fab_ic_dial), |
| 1341 | getResources().getString(R.string.action_menu_dialpad_button)); |
| 1342 | } |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | @Override |
Yorke Lee | cc4660d | 2014-04-24 11:22:57 -0700 | [diff] [blame] | 1346 | public void onPageScrollStateChanged(int state) { |
| 1347 | } |
| 1348 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 1349 | @Override |
| 1350 | public boolean isActionBarShowing() { |
| 1351 | return mActionBarController.isActionBarShowing(); |
| 1352 | } |
| 1353 | |
Yorke Lee | c98a5bb | 2014-10-28 16:12:05 -0700 | [diff] [blame] | 1354 | @Override |
| 1355 | public ActionBarController getActionBarController() { |
| 1356 | return mActionBarController; |
| 1357 | } |
| 1358 | |
Yorke Lee | 6bc6716 | 2015-06-27 14:03:25 -0700 | [diff] [blame] | 1359 | @Override |
Andrew Lee | 9da8fb4 | 2014-06-03 14:03:09 -0700 | [diff] [blame] | 1360 | public boolean isDialpadShown() { |
| 1361 | return mIsDialpadShown; |
| 1362 | } |
| 1363 | |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 1364 | @Override |
Yorke Lee | 6bc6716 | 2015-06-27 14:03:25 -0700 | [diff] [blame] | 1365 | public int getDialpadHeight() { |
| 1366 | if (mDialpadFragment != null) { |
| 1367 | return mDialpadFragment.getDialpadHeight(); |
| 1368 | } |
| 1369 | return 0; |
| 1370 | } |
| 1371 | |
| 1372 | @Override |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 1373 | public int getActionBarHideOffset() { |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 1374 | return getSupportActionBar().getHideOffset(); |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | @Override |
Yorke Lee | c98a5bb | 2014-10-28 16:12:05 -0700 | [diff] [blame] | 1378 | public void setActionBarHideOffset(int offset) { |
Nancy Chen | 44898ad | 2015-08-13 12:03:47 -0700 | [diff] [blame] | 1379 | getSupportActionBar().setHideOffset(offset); |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | @Override |
Yorke Lee | c98a5bb | 2014-10-28 16:12:05 -0700 | [diff] [blame] | 1383 | public int getActionBarHeight() { |
| 1384 | return mActionBarHeight; |
Yorke Lee | 5253be0 | 2014-05-21 18:50:03 -0700 | [diff] [blame] | 1385 | } |
Sai Cheemalapati | c4969ea | 2014-06-04 16:35:16 -0700 | [diff] [blame] | 1386 | |
Andrew Lee | 6324f70 | 2015-06-16 14:45:58 -0700 | [diff] [blame] | 1387 | private int getFabAlignment() { |
| 1388 | if (!mIsLandscape && !isInSearchUi() && |
| 1389 | mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) { |
| 1390 | return FloatingActionButtonController.ALIGN_MIDDLE; |
| 1391 | } |
| 1392 | return FloatingActionButtonController.ALIGN_END; |
Sai Cheemalapati | c4969ea | 2014-06-04 16:35:16 -0700 | [diff] [blame] | 1393 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1394 | } |