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