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