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