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