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