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