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