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