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