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 | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.Animator.AnimatorListener; |
| 21 | import android.animation.AnimatorListenerAdapter; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 22 | import android.app.Activity; |
| 23 | import android.app.Fragment; |
| 24 | import android.app.FragmentManager; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 25 | import android.app.FragmentManager.BackStackEntry; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 26 | import android.app.FragmentTransaction; |
Chiao Cheng | 073b5cf | 2012-12-07 11:36:00 -0800 | [diff] [blame] | 27 | import android.content.ActivityNotFoundException; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 30 | import android.net.Uri; |
| 31 | import android.os.Bundle; |
Yorke Lee | 02403e5 | 2013-09-24 07:24:39 -0700 | [diff] [blame] | 32 | import android.os.Handler; |
| 33 | import android.os.Message; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 34 | import android.os.RemoteException; |
| 35 | import android.os.ServiceManager; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 36 | import android.provider.CallLog.Calls; |
| 37 | import android.provider.ContactsContract.Contacts; |
Yorke Lee | e142481 | 2013-09-04 18:24:48 -0700 | [diff] [blame] | 38 | import android.provider.ContactsContract.Intents; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 39 | import android.provider.ContactsContract.Intents.UI; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 40 | import android.speech.RecognizerIntent; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 41 | import android.telephony.TelephonyManager; |
| 42 | import android.text.Editable; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 43 | import android.text.TextUtils; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 44 | import android.text.TextWatcher; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 45 | import android.util.Log; |
| 46 | import android.view.Menu; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 47 | import android.view.MenuItem; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 48 | import android.view.View; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 49 | import android.view.View.OnFocusChangeListener; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 50 | import android.view.inputmethod.InputMethodManager; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 51 | import android.widget.AbsListView.OnScrollListener; |
| 52 | import android.widget.EditText; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 53 | import android.widget.PopupMenu; |
Chiao Cheng | 073b5cf | 2012-12-07 11:36:00 -0800 | [diff] [blame] | 54 | import android.widget.Toast; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 55 | |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 56 | import com.android.contacts.common.CallUtil; |
Chiao Cheng | 603ff68 | 2012-10-24 15:18:40 -0700 | [diff] [blame] | 57 | import com.android.contacts.common.activity.TransactionSafeActivity; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 58 | import com.android.contacts.common.dialog.ClearFrequentsDialog; |
| 59 | import com.android.contacts.common.interactions.ImportExportDialogFragment; |
Chiao Cheng | 8efbcf9 | 2012-12-04 17:43:02 -0800 | [diff] [blame] | 60 | import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 61 | import com.android.dialer.calllog.CallLogActivity; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 62 | import com.android.dialer.database.DialerDatabaseHelper; |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 63 | import com.android.dialer.dialpad.DialpadFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 64 | import com.android.dialer.dialpad.SmartDialNameMatcher; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 65 | import com.android.dialer.dialpad.SmartDialPrefix; |
Chiao Cheng | 1429f1a | 2012-11-01 16:35:28 -0700 | [diff] [blame] | 66 | import com.android.dialer.interactions.PhoneNumberInteraction; |
Yorke Lee | 8dd6200 | 2013-08-08 15:57:20 -0700 | [diff] [blame] | 67 | import com.android.dialer.list.AllContactsActivity; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 68 | import com.android.dialer.list.OnListFragmentScrolledListener; |
Alon Albert | b453e5b | 2013-09-10 15:54:23 -0700 | [diff] [blame] | 69 | import com.android.dialer.list.PhoneFavoriteFragment; |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 70 | import com.android.dialer.list.RegularSearchFragment; |
| 71 | import com.android.dialer.list.SearchFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 72 | import com.android.dialer.list.SmartDialSearchFragment; |
Yorke Lee | 0baa98b | 2013-08-22 10:55:16 -0700 | [diff] [blame] | 73 | import com.android.dialerbind.DatabaseHelperManager; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 74 | import com.android.internal.telephony.ITelephony; |
| 75 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 76 | import java.util.ArrayList; |
| 77 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 78 | /** |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 79 | * The dialer tab's title is 'phone', a more common name (see strings.xml). |
| 80 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 81 | public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener, |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 82 | DialpadFragment.OnDialpadQueryChangedListener, PopupMenu.OnMenuItemClickListener, |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 83 | OnListFragmentScrolledListener, |
Yorke Lee | 8dd6200 | 2013-08-08 15:57:20 -0700 | [diff] [blame] | 84 | DialpadFragment.OnDialpadFragmentStartedListener, |
| 85 | PhoneFavoriteFragment.OnShowAllContactsListener { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 86 | private static final String TAG = "DialtactsActivity"; |
| 87 | |
| 88 | public static final boolean DEBUG = false; |
| 89 | |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 90 | public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences"; |
| 91 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 92 | /** Used to open Call Setting */ |
| 93 | private static final String PHONE_PACKAGE = "com.android.phone"; |
| 94 | private static final String CALL_SETTINGS_CLASS_NAME = |
| 95 | "com.android.phone.CallFeaturesSetting"; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 96 | /** @see #getCallOrigin() */ |
| 97 | private static final String CALL_ORIGIN_DIALTACTS = |
| 98 | "com.android.dialer.DialtactsActivity"; |
| 99 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 100 | private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui"; |
| 101 | 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] | 102 | private static final String KEY_SEARCH_QUERY = "search_query"; |
| 103 | private static final String KEY_FIRST_LAUNCH = "first_launch"; |
| 104 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 105 | private static final String TAG_DIALPAD_FRAGMENT = "dialpad"; |
| 106 | private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search"; |
| 107 | private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial"; |
| 108 | private static final String TAG_FAVORITES_FRAGMENT = "favorites"; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 109 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 110 | /** |
| 111 | * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}. |
| 112 | */ |
| 113 | private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER"; |
| 114 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 115 | private static final int SUBACTIVITY_ACCOUNT_FILTER = 1; |
| 116 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 117 | private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 118 | |
| 119 | private String mFilterText; |
| 120 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 121 | /** |
| 122 | * The main fragment displaying the user's favorites and frequent contacts |
| 123 | */ |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 124 | private PhoneFavoriteFragment mPhoneFavoriteFragment; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 125 | |
| 126 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 127 | * Fragment containing the dialpad that slides into view |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 128 | */ |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 129 | private DialpadFragment mDialpadFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * Fragment for searching phone numbers using the alphanumeric keyboard. |
| 133 | */ |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 134 | private RegularSearchFragment mRegularSearchFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 135 | |
| 136 | /** |
| 137 | * Fragment for searching phone numbers using the dialpad. |
| 138 | */ |
| 139 | private SmartDialSearchFragment mSmartDialSearchFragment; |
| 140 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 141 | private View mMenuButton; |
| 142 | private View mCallHistoryButton; |
| 143 | private View mDialpadButton; |
| 144 | |
| 145 | // Padding view used to shift the fragments up when the dialpad is shown. |
| 146 | private View mBottomPaddingView; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 147 | private View mFragmentsFrame; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 148 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 149 | private boolean mInDialpadSearch; |
| 150 | private boolean mInRegularSearch; |
| 151 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 152 | /** |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 153 | * True if the dialpad is only temporarily showing due to being in call |
| 154 | */ |
| 155 | private boolean mInCallDialpadUp; |
| 156 | |
| 157 | /** |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 158 | * True when this activity has been launched for the first time. |
| 159 | */ |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 160 | private boolean mFirstLaunch; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 161 | private View mSearchViewContainer; |
| 162 | private View mSearchViewCloseButton; |
| 163 | private View mVoiceSearchButton; |
| 164 | private EditText mSearchView; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 165 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 166 | private String mSearchQuery; |
| 167 | |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 168 | private DialerDatabaseHelper mDialerDatabaseHelper; |
| 169 | |
Yorke Lee | 02403e5 | 2013-09-24 07:24:39 -0700 | [diff] [blame] | 170 | private static final int EVENT_DELAYED_HIDE_SEARCH = 1; |
| 171 | |
| 172 | // Wait this much time (in ms) before hiding the search fragment after clicking on |
| 173 | // a search result to dial, to avoid jank |
| 174 | private static final int CLEAR_SEARCH_DELAY = 500; |
| 175 | |
| 176 | final Handler mHandler = new Handler() { |
| 177 | @Override |
| 178 | public void handleMessage(Message msg) { |
| 179 | if (msg.what == EVENT_DELAYED_HIDE_SEARCH) { |
| 180 | hideDialpadAndSearchUi(); |
| 181 | } |
| 182 | } |
| 183 | }; |
| 184 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 185 | /** |
| 186 | * Listener used when one of phone numbers in search UI is selected. This will initiate a |
| 187 | * phone call using the phone number. |
| 188 | */ |
| 189 | private final OnPhoneNumberPickerActionListener mPhoneNumberPickerActionListener = |
| 190 | new OnPhoneNumberPickerActionListener() { |
| 191 | @Override |
| 192 | public void onPickPhoneNumberAction(Uri dataUri) { |
| 193 | // Specify call-origin so that users will see the previous tab instead of |
| 194 | // CallLog screen (search UI will be automatically exited). |
| 195 | PhoneNumberInteraction.startInteractionForPhoneCall( |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 196 | DialtactsActivity.this, dataUri, getCallOrigin()); |
Yorke Lee | 02403e5 | 2013-09-24 07:24:39 -0700 | [diff] [blame] | 197 | mHandler.sendEmptyMessageDelayed(EVENT_DELAYED_HIDE_SEARCH, |
| 198 | CLEAR_SEARCH_DELAY); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | @Override |
Jay Shrauner | 31a760b | 2013-07-26 09:34:49 -0700 | [diff] [blame] | 202 | public void onCallNumberDirectly(String phoneNumber) { |
| 203 | Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin()); |
| 204 | startActivity(intent); |
Yorke Lee | 02403e5 | 2013-09-24 07:24:39 -0700 | [diff] [blame] | 205 | mHandler.sendEmptyMessageDelayed(EVENT_DELAYED_HIDE_SEARCH, |
| 206 | CLEAR_SEARCH_DELAY); |
Jay Shrauner | 31a760b | 2013-07-26 09:34:49 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | @Override |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 210 | public void onShortcutIntentCreated(Intent intent) { |
| 211 | Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring."); |
| 212 | } |
| 213 | |
| 214 | @Override |
| 215 | public void onHomeInActionBarSelected() { |
| 216 | exitSearchUi(); |
| 217 | } |
| 218 | }; |
| 219 | |
| 220 | /** |
| 221 | * Listener used to send search queries to the phone search fragment. |
| 222 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 223 | private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() { |
| 224 | @Override |
| 225 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 230 | final String newText = s.toString(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 231 | if (newText.equals(mSearchQuery)) { |
| 232 | // If the query hasn't changed (perhaps due to activity being destroyed |
| 233 | // and restored, or user launching the same DIAL intent twice), then there is |
| 234 | // no need to do anything here. |
| 235 | return; |
| 236 | } |
| 237 | mSearchQuery = newText; |
| 238 | if (DEBUG) { |
| 239 | Log.d(TAG, "onTextChange for mSearchView called with new query: " + s); |
| 240 | } |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 241 | final boolean dialpadSearch = isDialpadShowing(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 242 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 243 | // Show search result with non-empty text. Show a bare list otherwise. |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 244 | if (TextUtils.isEmpty(newText) && getInSearchUi()) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 245 | exitSearchUi(); |
| 246 | mSearchViewCloseButton.setVisibility(View.GONE); |
Yorke Lee | 3b82fc1 | 2013-09-09 08:42:38 -0700 | [diff] [blame] | 247 | mVoiceSearchButton.setVisibility(View.VISIBLE); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 248 | return; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 249 | } else if (!TextUtils.isEmpty(newText)) { |
| 250 | final boolean sameSearchMode = (dialpadSearch && mInDialpadSearch) || |
| 251 | (!dialpadSearch && mInRegularSearch); |
| 252 | if (!sameSearchMode) { |
| 253 | // call enterSearchUi only if we are switching search modes, or entering |
| 254 | // search ui for the first time |
| 255 | enterSearchUi(dialpadSearch, newText); |
| 256 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 257 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 258 | if (dialpadSearch && mSmartDialSearchFragment != null) { |
| 259 | mSmartDialSearchFragment.setQueryString(newText, false); |
| 260 | } else if (mRegularSearchFragment != null) { |
| 261 | mRegularSearchFragment.setQueryString(newText, false); |
| 262 | } |
| 263 | mSearchViewCloseButton.setVisibility(View.VISIBLE); |
Yorke Lee | 3b82fc1 | 2013-09-09 08:42:38 -0700 | [diff] [blame] | 264 | mVoiceSearchButton.setVisibility(View.GONE); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 265 | return; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 266 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | @Override |
| 270 | public void afterTextChanged(Editable s) { |
| 271 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 274 | private boolean isDialpadShowing() { |
| 275 | return mDialpadFragment != null && mDialpadFragment.isVisible(); |
| 276 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 277 | |
| 278 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 279 | protected void onCreate(Bundle savedInstanceState) { |
| 280 | super.onCreate(savedInstanceState); |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 281 | mFirstLaunch = true; |
| 282 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 283 | final Intent intent = getIntent(); |
| 284 | fixIntent(intent); |
| 285 | |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 286 | setContentView(R.layout.dialtacts_activity); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 287 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 288 | getActionBar().hide(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 289 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 290 | // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState |
| 291 | // is null. Otherwise the fragment manager takes care of recreating these fragments. |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 292 | if (savedInstanceState == null) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 293 | final PhoneFavoriteFragment phoneFavoriteFragment = new PhoneFavoriteFragment(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 294 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 295 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 296 | ft.add(R.id.dialtacts_frame, phoneFavoriteFragment, TAG_FAVORITES_FRAGMENT); |
| 297 | ft.add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 298 | ft.commit(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 299 | } else { |
| 300 | mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 301 | mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI); |
| 302 | mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 303 | mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 306 | mBottomPaddingView = findViewById(R.id.dialtacts_bottom_padding); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 307 | mFragmentsFrame = findViewById(R.id.dialtacts_frame); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 308 | prepareSearchView(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 309 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 310 | if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction()) |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 311 | && savedInstanceState == null) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 312 | setupFilterText(intent); |
| 313 | } |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 314 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 315 | setupFakeActionBarItems(); |
| 316 | |
Yorke Lee | 0baa98b | 2013-08-22 10:55:16 -0700 | [diff] [blame] | 317 | mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this); |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 318 | SmartDialPrefix.initializeNanpSettings(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 322 | protected void onResume() { |
| 323 | super.onResume(); |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 324 | if (mFirstLaunch) { |
| 325 | displayFragment(getIntent()); |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 326 | } else if (!phoneIsInUse() && mInCallDialpadUp) { |
| 327 | hideDialpadFragment(false, true); |
| 328 | mInCallDialpadUp = false; |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 329 | } |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 330 | |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 331 | mFirstLaunch = false; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 332 | mDialerDatabaseHelper.startSmartDialUpdateThread(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | @Override |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 336 | protected void onSaveInstanceState(Bundle outState) { |
| 337 | super.onSaveInstanceState(outState); |
| 338 | outState.putString(KEY_SEARCH_QUERY, mSearchQuery); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 339 | outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch); |
| 340 | outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 341 | outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch); |
| 342 | } |
| 343 | |
| 344 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 345 | public void onAttachFragment(Fragment fragment) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 346 | if (fragment instanceof DialpadFragment) { |
| 347 | mDialpadFragment = (DialpadFragment) fragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 348 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 349 | transaction.hide(mDialpadFragment); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 350 | transaction.commit(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 351 | } else if (fragment instanceof SmartDialSearchFragment) { |
| 352 | mSmartDialSearchFragment = (SmartDialSearchFragment) fragment; |
Yorke Lee | 63ea4cd | 2013-08-12 11:04:47 -0700 | [diff] [blame] | 353 | mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener( |
| 354 | mPhoneNumberPickerActionListener); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 355 | } else if (fragment instanceof SearchFragment) { |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 356 | mRegularSearchFragment = (RegularSearchFragment) fragment; |
Yorke Lee | 63ea4cd | 2013-08-12 11:04:47 -0700 | [diff] [blame] | 357 | mRegularSearchFragment.setOnPhoneNumberPickerActionListener( |
| 358 | mPhoneNumberPickerActionListener); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 359 | } else if (fragment instanceof PhoneFavoriteFragment) { |
| 360 | mPhoneFavoriteFragment = (PhoneFavoriteFragment) fragment; |
Yorke Lee | 5781afe | 2013-08-12 11:12:59 -0700 | [diff] [blame] | 361 | mPhoneFavoriteFragment.setListener(mPhoneFavoriteListener); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 362 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 366 | public boolean onMenuItemClick(MenuItem item) { |
| 367 | switch (item.getItemId()) { |
| 368 | case R.id.menu_import_export: |
| 369 | // We hard-code the "contactsAreAvailable" argument because doing it properly would |
| 370 | // involve querying a {@link ProviderStatusLoader}, which we don't want to do right |
| 371 | // now in Dialtacts for (potential) performance reasons. Compare with how it is |
| 372 | // done in {@link PeopleActivity}. |
| 373 | ImportExportDialogFragment.show(getFragmentManager(), true, |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 374 | DialtactsActivity.class); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 375 | return true; |
| 376 | case R.id.menu_clear_frequents: |
| 377 | ClearFrequentsDialog.show(getFragmentManager()); |
| 378 | return true; |
Yorke Lee | 5e93197 | 2013-08-30 11:37:53 -0700 | [diff] [blame] | 379 | case R.id.menu_add_contact: |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 380 | try { |
| 381 | startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI)); |
| 382 | } catch (ActivityNotFoundException e) { |
| 383 | Toast toast = Toast.makeText(this, |
| 384 | R.string.add_contact_not_available, |
| 385 | Toast.LENGTH_SHORT); |
| 386 | toast.show(); |
| 387 | } |
| 388 | return true; |
| 389 | case R.id.menu_call_settings: |
Alon Albert | b453e5b | 2013-09-10 15:54:23 -0700 | [diff] [blame] | 390 | handleMenuSettings(); |
Yorke Lee | 5e93197 | 2013-08-30 11:37:53 -0700 | [diff] [blame] | 391 | return true; |
| 392 | case R.id.menu_all_contacts: |
| 393 | onShowAllContacts(); |
| 394 | return true; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 395 | } |
| 396 | return false; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Alon Albert | b453e5b | 2013-09-10 15:54:23 -0700 | [diff] [blame] | 399 | protected void handleMenuSettings() { |
| 400 | openTelephonySetting(this); |
| 401 | } |
| 402 | |
| 403 | public static void openTelephonySetting(Activity activity) { |
| 404 | final Intent settingsIntent = getCallSettingsIntent(); |
| 405 | activity.startActivity(settingsIntent); |
| 406 | } |
| 407 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 408 | @Override |
| 409 | public void onClick(View view) { |
| 410 | switch (view.getId()) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 411 | case R.id.overflow_menu: { |
| 412 | final PopupMenu popupMenu = new PopupMenu(DialtactsActivity.this, view); |
| 413 | final Menu menu = popupMenu.getMenu(); |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 414 | popupMenu.inflate(R.menu.dialtacts_options); |
Yorke Lee | f420a53 | 2013-08-09 15:16:10 -0700 | [diff] [blame] | 415 | final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents); |
Yorke Lee | 0d391b4 | 2013-08-09 17:27:00 -0700 | [diff] [blame] | 416 | clearFrequents.setVisible(mPhoneFavoriteFragment.hasFrequents()); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 417 | popupMenu.setOnMenuItemClickListener(this); |
| 418 | popupMenu.show(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 419 | break; |
| 420 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 421 | case R.id.dialpad_button: |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 422 | // Reset the boolean flag that tracks whether the dialpad was up because |
| 423 | // we were in call. Regardless of whether it was true before, we want to |
| 424 | // show the dialpad because the user has explicitly clicked the dialpad |
| 425 | // button. |
| 426 | mInCallDialpadUp = false; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 427 | showDialpadFragment(true); |
| 428 | break; |
| 429 | case R.id.call_history_on_dialpad_button: |
| 430 | case R.id.call_history_button: |
Yorke Lee | f420a53 | 2013-08-09 15:16:10 -0700 | [diff] [blame] | 431 | // Use explicit CallLogActivity intent instead of ACTION_VIEW + |
| 432 | // CONTENT_TYPE, so that we always open our call log from our dialer |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 433 | final Intent intent = new Intent(this, CallLogActivity.class); |
| 434 | startActivity(intent); |
| 435 | break; |
| 436 | case R.id.search_close_button: |
| 437 | // Clear the search field |
| 438 | if (!TextUtils.isEmpty(mSearchView.getText())) { |
Yorke Lee | 2eafb7a | 2013-09-10 14:34:01 -0700 | [diff] [blame] | 439 | mDialpadFragment.clearDialpad(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 440 | mSearchView.setText(""); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 441 | } |
| 442 | break; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 443 | case R.id.voice_search_button: |
| 444 | final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); |
| 445 | startActivityForResult(voiceIntent, ACTIVITY_REQUEST_CODE_VOICE_SEARCH); |
| 446 | break; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 447 | default: { |
| 448 | Log.wtf(TAG, "Unexpected onClick event from " + view); |
| 449 | break; |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 454 | @Override |
| 455 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 456 | if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) { |
| 457 | if (resultCode == RESULT_OK) { |
| 458 | final ArrayList<String> matches = data.getStringArrayListExtra( |
| 459 | RecognizerIntent.EXTRA_RESULTS); |
| 460 | if (matches.size() > 0) { |
| 461 | final String match = matches.get(0); |
| 462 | mSearchView.setText(match); |
| 463 | } else { |
| 464 | Log.e(TAG, "Voice search - nothing heard"); |
| 465 | } |
| 466 | } else { |
| 467 | Log.e(TAG, "Voice search failed"); |
| 468 | } |
| 469 | } |
| 470 | super.onActivityResult(requestCode, resultCode, data); |
| 471 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 472 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 473 | private void showDialpadFragment(boolean animate) { |
Yorke Lee | ea695cb | 2013-08-09 11:02:26 -0700 | [diff] [blame] | 474 | mDialpadFragment.setAdjustTranslationForAnimation(animate); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 475 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 476 | if (animate) { |
| 477 | ft.setCustomAnimations(R.anim.slide_in, 0); |
Yorke Lee | ea695cb | 2013-08-09 11:02:26 -0700 | [diff] [blame] | 478 | } else { |
| 479 | mDialpadFragment.setYFraction(0); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 480 | } |
| 481 | ft.show(mDialpadFragment); |
| 482 | ft.commit(); |
| 483 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 484 | |
Yorke Lee | ca19504 | 2013-09-25 16:29:38 -0700 | [diff] [blame^] | 485 | public void hideDialpadFragment(boolean animate, boolean clearDialpad) { |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 486 | if (mDialpadFragment == null) return; |
| 487 | if (clearDialpad) { |
| 488 | mDialpadFragment.clearDialpad(); |
| 489 | } |
| 490 | if (!mDialpadFragment.isVisible()) return; |
Yorke Lee | ea695cb | 2013-08-09 11:02:26 -0700 | [diff] [blame] | 491 | mDialpadFragment.setAdjustTranslationForAnimation(animate); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 492 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
| 493 | if (animate) { |
| 494 | ft.setCustomAnimations(0, R.anim.slide_out); |
| 495 | } |
| 496 | ft.hide(mDialpadFragment); |
| 497 | ft.commit(); |
| 498 | } |
| 499 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 500 | private void prepareSearchView() { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 501 | mSearchViewContainer = findViewById(R.id.search_view_container); |
| 502 | mSearchViewCloseButton = findViewById(R.id.search_close_button); |
| 503 | mSearchViewCloseButton.setOnClickListener(this); |
| 504 | mVoiceSearchButton = findViewById(R.id.voice_search_button); |
| 505 | mVoiceSearchButton.setOnClickListener(this); |
| 506 | mSearchView = (EditText) findViewById(R.id.search_view); |
| 507 | mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); |
| 508 | mSearchView.setHint(getString(R.string.dialer_hint_find_contact)); |
| 509 | mSearchView.setOnFocusChangeListener(new OnFocusChangeListener() { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 510 | @Override |
| 511 | public void onFocusChange(View view, boolean hasFocus) { |
| 512 | if (hasFocus) { |
| 513 | showInputMethod(view.findFocus()); |
| 514 | } |
| 515 | } |
| 516 | }); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 519 | final AnimatorListener mHideListener = new AnimatorListenerAdapter() { |
| 520 | @Override |
| 521 | public void onAnimationEnd(Animator animation) { |
| 522 | mSearchViewContainer.setVisibility(View.GONE); |
| 523 | } |
| 524 | }; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 525 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 526 | private boolean getInSearchUi() { |
| 527 | return mInDialpadSearch || mInRegularSearch; |
| 528 | } |
| 529 | |
| 530 | private void setNotInSearchUi() { |
| 531 | mInDialpadSearch = false; |
| 532 | mInRegularSearch = false; |
| 533 | } |
| 534 | |
Yorke Lee | 311969c | 2013-08-26 06:31:11 -0700 | [diff] [blame] | 535 | private void hideDialpadAndSearchUi() { |
Yorke Lee | 7a06c44 | 2013-09-04 15:49:51 -0700 | [diff] [blame] | 536 | mSearchView.setText(null); |
Yorke Lee | 311969c | 2013-08-26 06:31:11 -0700 | [diff] [blame] | 537 | hideDialpadFragment(false, true); |
| 538 | } |
| 539 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 540 | public void hideSearchBar() { |
| 541 | hideSearchBar(true); |
Christine Chen | 9c1e065 | 2013-05-23 15:40:19 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 544 | public void hideSearchBar(boolean shiftView) { |
| 545 | if (shiftView) { |
| 546 | mSearchViewContainer.animate().cancel(); |
| 547 | mSearchViewContainer.setAlpha(1); |
| 548 | mSearchViewContainer.setTranslationY(0); |
| 549 | mSearchViewContainer.animate().withLayer().alpha(0).translationY(-mSearchView.getHeight()) |
| 550 | .setDuration(200).setListener(mHideListener); |
| 551 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 552 | mFragmentsFrame.animate().withLayer() |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 553 | .translationY(-mSearchViewContainer.getHeight()).setDuration(200).setListener( |
| 554 | new AnimatorListenerAdapter() { |
| 555 | @Override |
| 556 | public void onAnimationEnd(Animator animation) { |
| 557 | mBottomPaddingView.setVisibility(View.VISIBLE); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 558 | mFragmentsFrame.setTranslationY(0); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 559 | } |
| 560 | }); |
| 561 | } else { |
| 562 | mSearchViewContainer.setTranslationY(-mSearchView.getHeight()); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | public void showSearchBar() { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 567 | mSearchViewContainer.animate().cancel(); |
| 568 | mSearchViewContainer.setAlpha(0); |
| 569 | mSearchViewContainer.setTranslationY(-mSearchViewContainer.getHeight()); |
| 570 | mSearchViewContainer.animate().withLayer().alpha(1).translationY(0).setDuration(200) |
| 571 | .setListener(new AnimatorListenerAdapter() { |
| 572 | @Override |
| 573 | public void onAnimationStart(Animator animation) { |
| 574 | mSearchViewContainer.setVisibility(View.VISIBLE); |
| 575 | } |
| 576 | }); |
| 577 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 578 | mFragmentsFrame.setTranslationY(-mSearchViewContainer.getHeight()); |
| 579 | mFragmentsFrame.animate().withLayer().translationY(0).setDuration(200) |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 580 | .setListener( |
| 581 | new AnimatorListenerAdapter() { |
| 582 | @Override |
| 583 | public void onAnimationStart(Animator animation) { |
| 584 | mBottomPaddingView.setVisibility(View.GONE); |
| 585 | } |
| 586 | }); |
| 587 | } |
| 588 | |
| 589 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 590 | public void setupFakeActionBarItems() { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 591 | mMenuButton = findViewById(R.id.overflow_menu); |
| 592 | if (mMenuButton != null) { |
| 593 | mMenuButton.setOnClickListener(this); |
| 594 | } |
| 595 | |
| 596 | mCallHistoryButton = findViewById(R.id.call_history_button); |
| 597 | // mCallHistoryButton.setMinimumWidth(fakeMenuItemWidth); |
| 598 | mCallHistoryButton.setOnClickListener(this); |
| 599 | |
| 600 | mDialpadButton = findViewById(R.id.dialpad_button); |
| 601 | // DialpadButton.setMinimumWidth(fakeMenuItemWidth); |
| 602 | mDialpadButton.setOnClickListener(this); |
| 603 | } |
| 604 | |
| 605 | public void setupFakeActionBarItemsForDialpadFragment() { |
| 606 | final View callhistoryButton = findViewById(R.id.call_history_on_dialpad_button); |
| 607 | callhistoryButton.setOnClickListener(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | private void fixIntent(Intent intent) { |
| 611 | // This should be cleaned up: the call key used to send an Intent |
| 612 | // that just said to go to the recent calls list. It now sends this |
| 613 | // abstract action, but this class hasn't been rewritten to deal with it. |
| 614 | if (Intent.ACTION_CALL_BUTTON.equals(intent.getAction())) { |
| 615 | intent.setDataAndType(Calls.CONTENT_URI, Calls.CONTENT_TYPE); |
| 616 | intent.putExtra("call_key", true); |
| 617 | setIntent(intent); |
| 618 | } |
| 619 | } |
| 620 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 621 | /** |
| 622 | * Returns true if the intent is due to hitting the green send key (hardware call button: |
| 623 | * KEYCODE_CALL) while in a call. |
| 624 | * |
| 625 | * @param intent the intent that launched this activity |
| 626 | * @param recentCallsRequest true if the intent is requesting to view recent calls |
| 627 | * @return true if the intent is due to hitting the green send key while in a call |
| 628 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 629 | private boolean isSendKeyWhileInCall(Intent intent, boolean recentCallsRequest) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 630 | // If there is a call in progress go to the call screen |
| 631 | if (recentCallsRequest) { |
| 632 | final boolean callKey = intent.getBooleanExtra("call_key", false); |
| 633 | |
| 634 | try { |
| 635 | ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); |
| 636 | if (callKey && phone != null && phone.showCallScreen()) { |
| 637 | return true; |
| 638 | } |
| 639 | } catch (RemoteException e) { |
| 640 | Log.e(TAG, "Failed to handle send while in call", e); |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | return false; |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * Sets the current tab based on the intent's request type |
| 649 | * |
| 650 | * @param intent Intent that contains information about which tab should be selected |
| 651 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 652 | private void displayFragment(Intent intent) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 653 | // If we got here by hitting send and we're in call forward along to the in-call activity |
| 654 | boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent.resolveType( |
| 655 | getContentResolver())); |
| 656 | if (isSendKeyWhileInCall(intent, recentCallsRequest)) { |
| 657 | finish(); |
| 658 | return; |
| 659 | } |
| 660 | |
Yorke Lee | 669b608 | 2013-09-17 15:43:38 -0700 | [diff] [blame] | 661 | if (mDialpadFragment != null) { |
| 662 | final boolean phoneIsInUse = phoneIsInUse(); |
| 663 | if (phoneIsInUse || isDialIntent(intent)) { |
| 664 | mDialpadFragment.setStartedFromNewIntent(true); |
| 665 | if (phoneIsInUse && !mDialpadFragment.isVisible()) { |
| 666 | mInCallDialpadUp = true; |
| 667 | } |
| 668 | showDialpadFragment(false); |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 669 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 670 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | @Override |
| 674 | public void onNewIntent(Intent newIntent) { |
| 675 | setIntent(newIntent); |
| 676 | fixIntent(newIntent); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 677 | displayFragment(newIntent); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 678 | final String action = newIntent.getAction(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 679 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 680 | invalidateOptionsMenu(); |
| 681 | } |
| 682 | |
| 683 | /** Returns true if the given intent contains a phone number to populate the dialer with */ |
| 684 | private boolean isDialIntent(Intent intent) { |
| 685 | final String action = intent.getAction(); |
| 686 | if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) { |
| 687 | return true; |
| 688 | } |
| 689 | if (Intent.ACTION_VIEW.equals(action)) { |
| 690 | final Uri data = intent.getData(); |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 691 | if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 692 | return true; |
| 693 | } |
| 694 | } |
| 695 | return false; |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * Returns an appropriate call origin for this Activity. May return null when no call origin |
| 700 | * should be used (e.g. when some 3rd party application launched the screen. Call origin is |
| 701 | * for remembering the tab in which the user made a phone call, so the external app's DIAL |
| 702 | * request should not be counted.) |
| 703 | */ |
| 704 | public String getCallOrigin() { |
| 705 | return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null; |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Retrieves the filter text stored in {@link #setupFilterText(Intent)}. |
| 710 | * This text originally came from a FILTER_CONTACTS_ACTION intent received |
| 711 | * by this activity. The stored text will then be cleared after after this |
| 712 | * method returns. |
| 713 | * |
| 714 | * @return The stored filter text |
| 715 | */ |
| 716 | public String getAndClearFilterText() { |
| 717 | String filterText = mFilterText; |
| 718 | mFilterText = null; |
| 719 | return filterText; |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * Stores the filter text associated with a FILTER_CONTACTS_ACTION intent. |
| 724 | * This is so child activities can check if they are supposed to display a filter. |
| 725 | * |
| 726 | * @param intent The intent received in {@link #onNewIntent(Intent)} |
| 727 | */ |
| 728 | private void setupFilterText(Intent intent) { |
| 729 | // If the intent was relaunched from history, don't apply the filter text. |
| 730 | if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { |
| 731 | return; |
| 732 | } |
| 733 | String filter = intent.getStringExtra(UI.FILTER_TEXT_EXTRA_KEY); |
| 734 | if (filter != null && filter.length() > 0) { |
| 735 | mFilterText = filter; |
| 736 | } |
| 737 | } |
| 738 | |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 739 | private final PhoneFavoriteFragment.Listener mPhoneFavoriteListener = |
| 740 | new PhoneFavoriteFragment.Listener() { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 741 | @Override |
| 742 | public void onContactSelected(Uri contactUri) { |
| 743 | PhoneNumberInteraction.startInteractionForPhoneCall( |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 744 | DialtactsActivity.this, contactUri, getCallOrigin()); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | @Override |
| 748 | public void onCallNumberDirectly(String phoneNumber) { |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 749 | Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin()); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 750 | startActivity(intent); |
| 751 | } |
| 752 | }; |
| 753 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 754 | /* TODO krelease: This is only relevant for phones that have a hard button search key (i.e. |
| 755 | * Nexus S). Supporting it is a little more tricky because of the dialpad fragment might |
| 756 | * be showing when the search key is pressed so there is more state management involved. |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 757 | |
| 758 | @Override |
| 759 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
| 760 | Bundle appSearchData, boolean globalSearch) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 761 | if (mRegularSearchFragment != null && mRegularSearchFragment.isAdded() && !globalSearch) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 762 | if (mInSearchUi) { |
| 763 | if (mSearchView.hasFocus()) { |
| 764 | showInputMethod(mSearchView.findFocus()); |
| 765 | } else { |
| 766 | mSearchView.requestFocus(); |
| 767 | } |
| 768 | } else { |
| 769 | enterSearchUi(); |
| 770 | } |
| 771 | } else { |
| 772 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 773 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 774 | }*/ |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 775 | |
| 776 | private void showInputMethod(View view) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 777 | final InputMethodManager imm = (InputMethodManager) getSystemService( |
| 778 | Context.INPUT_METHOD_SERVICE); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 779 | if (imm != null) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 780 | imm.showSoftInput(view, 0); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
| 784 | private void hideInputMethod(View view) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 785 | final InputMethodManager imm = (InputMethodManager) getSystemService( |
| 786 | Context.INPUT_METHOD_SERVICE); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 787 | if (imm != null && view != null) { |
| 788 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 793 | * Shows the search fragment |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 794 | */ |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 795 | private void enterSearchUi(boolean smartDialSearch, String query) { |
Yorke Lee | 34bdf87 | 2013-08-15 14:11:50 -0700 | [diff] [blame] | 796 | if (getFragmentManager().isDestroyed()) { |
| 797 | // Weird race condition where fragment is doing work after the activity is destroyed |
| 798 | // due to talkback being on (b/10209937). Just return since we can't do any |
| 799 | // constructive here. |
| 800 | return; |
| 801 | } |
| 802 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 803 | if (DEBUG) { |
| 804 | Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch); |
| 805 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 806 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 807 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
| 808 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 809 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 810 | SearchFragment fragment; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 811 | if (mInDialpadSearch) { |
| 812 | transaction.remove(mSmartDialSearchFragment); |
| 813 | } else if (mInRegularSearch) { |
| 814 | transaction.remove(mRegularSearchFragment); |
| 815 | } else { |
| 816 | transaction.remove(mPhoneFavoriteFragment); |
| 817 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 818 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 819 | final String tag; |
| 820 | if (smartDialSearch) { |
| 821 | tag = TAG_SMARTDIAL_SEARCH_FRAGMENT; |
| 822 | } else { |
| 823 | tag = TAG_REGULAR_SEARCH_FRAGMENT; |
| 824 | } |
| 825 | mInDialpadSearch = smartDialSearch; |
| 826 | mInRegularSearch = !smartDialSearch; |
| 827 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 828 | fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag); |
| 829 | if (fragment == null) { |
| 830 | if (smartDialSearch) { |
| 831 | fragment = new SmartDialSearchFragment(); |
| 832 | } else { |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 833 | fragment = new RegularSearchFragment(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 834 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 835 | } |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 836 | transaction.replace(R.id.dialtacts_frame, fragment, tag); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 837 | transaction.addToBackStack(null); |
| 838 | fragment.setQueryString(query, false); |
| 839 | transaction.commit(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 843 | * Hides the search fragment |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 844 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 845 | private void exitSearchUi() { |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 846 | // Go all the way back to the favorites fragment, regardless of how many times we |
| 847 | // transitioned between search fragments |
| 848 | final BackStackEntry entry = getFragmentManager().getBackStackEntryAt(0); |
| 849 | getFragmentManager().popBackStack(0, FragmentManager.POP_BACK_STACK_INCLUSIVE); |
| 850 | setNotInSearchUi(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | /** Returns an Intent to launch Call Settings screen */ |
| 854 | public static Intent getCallSettingsIntent() { |
| 855 | final Intent intent = new Intent(Intent.ACTION_MAIN); |
| 856 | intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME); |
| 857 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 858 | return intent; |
| 859 | } |
| 860 | |
| 861 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 862 | public void onBackPressed() { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 863 | if (mDialpadFragment != null && mDialpadFragment.isVisible()) { |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 864 | hideDialpadFragment(true, false); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 865 | } else if (getInSearchUi()) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 866 | mSearchView.setText(null); |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 867 | mDialpadFragment.clearDialpad(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 868 | } else if (isTaskRoot()) { |
| 869 | // Instead of stopping, simply push this to the back of the stack. |
| 870 | // This is only done when running at the top of the stack; |
| 871 | // otherwise, we have been launched by someone else so need to |
| 872 | // allow the user to go back to the caller. |
| 873 | moveTaskToBack(false); |
| 874 | } else { |
| 875 | super.onBackPressed(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 876 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | @Override |
| 880 | public void onDialpadQueryChanged(String query) { |
| 881 | final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query, |
| 882 | SmartDialNameMatcher.LATIN_SMART_DIAL_MAP); |
| 883 | if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 884 | if (DEBUG) { |
| 885 | Log.d(TAG, "onDialpadQueryChanged - new query: " + query); |
| 886 | } |
| 887 | if (mDialpadFragment == null || !mDialpadFragment.isVisible()) { |
| 888 | // This callback can happen if the dialpad fragment is recreated because of |
| 889 | // activity destruction. In that case, don't update the search view because |
| 890 | // that would bring the user back to the search fragment regardless of the |
| 891 | // previous state of the application. Instead, just return here and let the |
| 892 | // fragment manager correctly figure out whatever fragment was last displayed. |
| 893 | return; |
| 894 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 895 | mSearchView.setText(normalizedQuery); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 896 | } |
| 897 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 898 | |
| 899 | @Override |
| 900 | public void onListFragmentScrollStateChange(int scrollState) { |
| 901 | if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 902 | hideDialpadFragment(true, false); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 903 | hideInputMethod(getCurrentFocus()); |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 908 | public void onDialpadFragmentStarted() { |
| 909 | setupFakeActionBarItemsForDialpadFragment(); |
| 910 | } |
| 911 | |
| 912 | private boolean phoneIsInUse() { |
| 913 | final TelephonyManager tm = (TelephonyManager) getSystemService( |
| 914 | Context.TELEPHONY_SERVICE); |
| 915 | return tm.getCallState() != TelephonyManager.CALL_STATE_IDLE; |
| 916 | } |
Yorke Lee | 8dd6200 | 2013-08-08 15:57:20 -0700 | [diff] [blame] | 917 | |
| 918 | @Override |
| 919 | public void onShowAllContacts() { |
| 920 | final Intent intent = new Intent(this, AllContactsActivity.class); |
| 921 | startActivity(intent); |
| 922 | } |
Yorke Lee | e142481 | 2013-09-04 18:24:48 -0700 | [diff] [blame] | 923 | |
| 924 | public static Intent getAddNumberToContactIntent(CharSequence text) { |
| 925 | final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 926 | intent.putExtra(Intents.Insert.PHONE, text); |
| 927 | intent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 928 | return intent; |
| 929 | } |
| 930 | |
| 931 | public static Intent getInsertContactWithNameIntent(CharSequence text) { |
| 932 | final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); |
| 933 | intent.putExtra(Intents.Insert.NAME, text); |
| 934 | return intent; |
| 935 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 936 | } |