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