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