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