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