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