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