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