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