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