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