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