Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1 | /* |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -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 | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.Animator.AnimatorListener; |
| 21 | import android.animation.AnimatorListenerAdapter; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 22 | import android.app.Activity; |
| 23 | import android.app.Fragment; |
| 24 | import android.app.FragmentManager; |
| 25 | import android.app.FragmentTransaction; |
Chiao Cheng | 073b5cf | 2012-12-07 11:36:00 -0800 | [diff] [blame] | 26 | import android.content.ActivityNotFoundException; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 29 | import android.content.pm.PackageManager; |
| 30 | import android.content.pm.ResolveInfo; |
Yorke Lee | 41a24b4 | 2013-11-13 16:14:41 -0800 | [diff] [blame] | 31 | import android.graphics.drawable.Drawable; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 32 | import android.net.Uri; |
| 33 | import android.os.Bundle; |
| 34 | import android.os.RemoteException; |
| 35 | import android.os.ServiceManager; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 36 | import android.provider.CallLog.Calls; |
| 37 | import android.provider.ContactsContract.Contacts; |
Yorke Lee | e142481 | 2013-09-04 18:24:48 -0700 | [diff] [blame] | 38 | import android.provider.ContactsContract.Intents; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 39 | import android.provider.ContactsContract.Intents.UI; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 40 | import android.speech.RecognizerIntent; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 41 | import android.telephony.TelephonyManager; |
| 42 | import android.text.Editable; |
Yorke Lee | 41a24b4 | 2013-11-13 16:14:41 -0800 | [diff] [blame] | 43 | import android.text.Spannable; |
| 44 | import android.text.SpannableStringBuilder; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 45 | import android.text.TextUtils; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 46 | import android.text.TextWatcher; |
Yorke Lee | 41a24b4 | 2013-11-13 16:14:41 -0800 | [diff] [blame] | 47 | import android.text.style.ImageSpan; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 48 | import android.util.Log; |
| 49 | import android.view.Menu; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 50 | import android.view.MenuItem; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 51 | import android.view.View; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 52 | import android.view.inputmethod.InputMethodManager; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 53 | import android.widget.AbsListView.OnScrollListener; |
| 54 | import android.widget.EditText; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 55 | import android.widget.PopupMenu; |
Chiao Cheng | 073b5cf | 2012-12-07 11:36:00 -0800 | [diff] [blame] | 56 | import android.widget.Toast; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 57 | |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 58 | import com.android.contacts.common.CallUtil; |
Chiao Cheng | 603ff68 | 2012-10-24 15:18:40 -0700 | [diff] [blame] | 59 | import com.android.contacts.common.activity.TransactionSafeActivity; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 60 | import com.android.contacts.common.dialog.ClearFrequentsDialog; |
| 61 | import com.android.contacts.common.interactions.ImportExportDialogFragment; |
Chiao Cheng | 8efbcf9 | 2012-12-04 17:43:02 -0800 | [diff] [blame] | 62 | import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 63 | import com.android.dialer.calllog.CallLogActivity; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 64 | import com.android.dialer.database.DialerDatabaseHelper; |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 65 | import com.android.dialer.dialpad.DialpadFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 66 | import com.android.dialer.dialpad.SmartDialNameMatcher; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 67 | import com.android.dialer.dialpad.SmartDialPrefix; |
Chiao Cheng | 1429f1a | 2012-11-01 16:35:28 -0700 | [diff] [blame] | 68 | import com.android.dialer.interactions.PhoneNumberInteraction; |
Yorke Lee | 8dd6200 | 2013-08-08 15:57:20 -0700 | [diff] [blame] | 69 | import com.android.dialer.list.AllContactsActivity; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame^] | 70 | import com.android.dialer.list.DragDropController; |
| 71 | import com.android.dialer.list.OnDragDropListener; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 72 | import com.android.dialer.list.OnListFragmentScrolledListener; |
Alon Albert | b453e5b | 2013-09-10 15:54:23 -0700 | [diff] [blame] | 73 | import com.android.dialer.list.PhoneFavoriteFragment; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame^] | 74 | import com.android.dialer.list.PhoneFavoriteTileView; |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 75 | import com.android.dialer.list.RegularSearchFragment; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame^] | 76 | import com.android.dialer.list.RemoveView; |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 77 | import com.android.dialer.list.SearchFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 78 | import com.android.dialer.list.SmartDialSearchFragment; |
Yorke Lee | 0baa98b | 2013-08-22 10:55:16 -0700 | [diff] [blame] | 79 | import com.android.dialerbind.DatabaseHelperManager; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 80 | import com.android.internal.telephony.ITelephony; |
| 81 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 82 | import java.util.ArrayList; |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 83 | import java.util.List; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 84 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 85 | /** |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 86 | * The dialer tab's title is 'phone', a more common name (see strings.xml). |
| 87 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 88 | public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener, |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 89 | DialpadFragment.OnDialpadQueryChangedListener, PopupMenu.OnMenuItemClickListener, |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 90 | OnListFragmentScrolledListener, |
Yorke Lee | 8dd6200 | 2013-08-08 15:57:20 -0700 | [diff] [blame] | 91 | DialpadFragment.OnDialpadFragmentStartedListener, |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame^] | 92 | PhoneFavoriteFragment.OnShowAllContactsListener, |
| 93 | PhoneFavoriteFragment.HostInterface, |
| 94 | OnDragDropListener { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 95 | private static final String TAG = "DialtactsActivity"; |
| 96 | |
| 97 | public static final boolean DEBUG = false; |
| 98 | |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 99 | public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences"; |
| 100 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 101 | /** Used to open Call Setting */ |
| 102 | private static final String PHONE_PACKAGE = "com.android.phone"; |
| 103 | private static final String CALL_SETTINGS_CLASS_NAME = |
| 104 | "com.android.phone.CallFeaturesSetting"; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 105 | /** @see #getCallOrigin() */ |
| 106 | private static final String CALL_ORIGIN_DIALTACTS = |
| 107 | "com.android.dialer.DialtactsActivity"; |
| 108 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 109 | private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui"; |
| 110 | private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui"; |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 111 | private static final String KEY_SEARCH_QUERY = "search_query"; |
| 112 | private static final String KEY_FIRST_LAUNCH = "first_launch"; |
| 113 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 114 | private static final String TAG_DIALPAD_FRAGMENT = "dialpad"; |
| 115 | private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search"; |
| 116 | private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial"; |
| 117 | private static final String TAG_FAVORITES_FRAGMENT = "favorites"; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 118 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 119 | /** |
| 120 | * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}. |
| 121 | */ |
| 122 | private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER"; |
| 123 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 124 | private static final int SUBACTIVITY_ACCOUNT_FILTER = 1; |
| 125 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 126 | private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 127 | |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame^] | 128 | private static final int FADE_ANIMATION_DURATION = 200; |
| 129 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 130 | private String mFilterText; |
| 131 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 132 | /** |
| 133 | * The main fragment displaying the user's favorites and frequent contacts |
| 134 | */ |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 135 | private PhoneFavoriteFragment mPhoneFavoriteFragment; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 136 | |
| 137 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 138 | * Fragment containing the dialpad that slides into view |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 139 | */ |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 140 | private DialpadFragment mDialpadFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | * Fragment for searching phone numbers using the alphanumeric keyboard. |
| 144 | */ |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 145 | private RegularSearchFragment mRegularSearchFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * Fragment for searching phone numbers using the dialpad. |
| 149 | */ |
| 150 | private SmartDialSearchFragment mSmartDialSearchFragment; |
| 151 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 152 | private View mMenuButton; |
| 153 | private View mCallHistoryButton; |
| 154 | private View mDialpadButton; |
Yorke Lee | 36c5413 | 2013-09-25 16:17:06 -0700 | [diff] [blame] | 155 | private PopupMenu mOverflowMenu; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 156 | |
| 157 | // Padding view used to shift the fragments up when the dialpad is shown. |
| 158 | private View mBottomPaddingView; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 159 | private View mFragmentsFrame; |
Yorke Lee | 5f3ad54 | 2013-10-08 08:14:36 -0700 | [diff] [blame] | 160 | private View mActionBar; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 161 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 162 | private boolean mInDialpadSearch; |
| 163 | private boolean mInRegularSearch; |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 164 | private boolean mClearSearchOnPause; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 165 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 166 | /** |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 167 | * True if the dialpad is only temporarily showing due to being in call |
| 168 | */ |
| 169 | private boolean mInCallDialpadUp; |
| 170 | |
| 171 | /** |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 172 | * True when this activity has been launched for the first time. |
| 173 | */ |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 174 | private boolean mFirstLaunch; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 175 | private View mSearchViewContainer; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame^] | 176 | private RemoveView mRemoveViewContainer; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 177 | private View mSearchViewCloseButton; |
| 178 | private View mVoiceSearchButton; |
| 179 | private EditText mSearchView; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 180 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 181 | private String mSearchQuery; |
| 182 | |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 183 | private DialerDatabaseHelper mDialerDatabaseHelper; |
| 184 | |
Yorke Lee | 36c5413 | 2013-09-25 16:17:06 -0700 | [diff] [blame] | 185 | private class OverflowPopupMenu extends PopupMenu { |
| 186 | public OverflowPopupMenu(Context context, View anchor) { |
| 187 | super(context, anchor); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public void show() { |
| 192 | final Menu menu = getMenu(); |
| 193 | final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents); |
| 194 | clearFrequents.setVisible(mPhoneFavoriteFragment.hasFrequents()); |
| 195 | super.show(); |
| 196 | } |
| 197 | } |
| 198 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 199 | /** |
| 200 | * Listener used when one of phone numbers in search UI is selected. This will initiate a |
| 201 | * phone call using the phone number. |
| 202 | */ |
| 203 | private final OnPhoneNumberPickerActionListener mPhoneNumberPickerActionListener = |
| 204 | new OnPhoneNumberPickerActionListener() { |
| 205 | @Override |
| 206 | public void onPickPhoneNumberAction(Uri dataUri) { |
| 207 | // Specify call-origin so that users will see the previous tab instead of |
| 208 | // CallLog screen (search UI will be automatically exited). |
| 209 | PhoneNumberInteraction.startInteractionForPhoneCall( |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 210 | DialtactsActivity.this, dataUri, getCallOrigin()); |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 211 | mClearSearchOnPause = true; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | @Override |
Jay Shrauner | 31a760b | 2013-07-26 09:34:49 -0700 | [diff] [blame] | 215 | public void onCallNumberDirectly(String phoneNumber) { |
| 216 | Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin()); |
| 217 | startActivity(intent); |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 218 | mClearSearchOnPause = true; |
Jay Shrauner | 31a760b | 2013-07-26 09:34:49 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | @Override |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 222 | public void onShortcutIntentCreated(Intent intent) { |
| 223 | Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring."); |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public void onHomeInActionBarSelected() { |
| 228 | exitSearchUi(); |
| 229 | } |
| 230 | }; |
| 231 | |
| 232 | /** |
| 233 | * Listener used to send search queries to the phone search fragment. |
| 234 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 235 | private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() { |
| 236 | @Override |
| 237 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 242 | final String newText = s.toString(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 243 | if (newText.equals(mSearchQuery)) { |
| 244 | // If the query hasn't changed (perhaps due to activity being destroyed |
| 245 | // and restored, or user launching the same DIAL intent twice), then there is |
| 246 | // no need to do anything here. |
| 247 | return; |
| 248 | } |
| 249 | mSearchQuery = newText; |
| 250 | if (DEBUG) { |
| 251 | Log.d(TAG, "onTextChange for mSearchView called with new query: " + s); |
| 252 | } |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 253 | final boolean dialpadSearch = isDialpadShowing(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 254 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 255 | // Show search result with non-empty text. Show a bare list otherwise. |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 256 | if (TextUtils.isEmpty(newText) && getInSearchUi()) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 257 | exitSearchUi(); |
| 258 | mSearchViewCloseButton.setVisibility(View.GONE); |
Yorke Lee | 3b82fc1 | 2013-09-09 08:42:38 -0700 | [diff] [blame] | 259 | mVoiceSearchButton.setVisibility(View.VISIBLE); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 260 | return; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 261 | } else if (!TextUtils.isEmpty(newText)) { |
| 262 | final boolean sameSearchMode = (dialpadSearch && mInDialpadSearch) || |
| 263 | (!dialpadSearch && mInRegularSearch); |
| 264 | if (!sameSearchMode) { |
| 265 | // call enterSearchUi only if we are switching search modes, or entering |
| 266 | // search ui for the first time |
| 267 | enterSearchUi(dialpadSearch, newText); |
| 268 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 269 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 270 | if (dialpadSearch && mSmartDialSearchFragment != null) { |
| 271 | mSmartDialSearchFragment.setQueryString(newText, false); |
| 272 | } else if (mRegularSearchFragment != null) { |
| 273 | mRegularSearchFragment.setQueryString(newText, false); |
| 274 | } |
| 275 | mSearchViewCloseButton.setVisibility(View.VISIBLE); |
Yorke Lee | 3b82fc1 | 2013-09-09 08:42:38 -0700 | [diff] [blame] | 276 | mVoiceSearchButton.setVisibility(View.GONE); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 277 | return; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 278 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | @Override |
| 282 | public void afterTextChanged(Editable s) { |
| 283 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 284 | }; |
| 285 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 286 | private boolean isDialpadShowing() { |
| 287 | return mDialpadFragment != null && mDialpadFragment.isVisible(); |
| 288 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 289 | |
| 290 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 291 | protected void onCreate(Bundle savedInstanceState) { |
| 292 | super.onCreate(savedInstanceState); |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 293 | mFirstLaunch = true; |
| 294 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 295 | final Intent intent = getIntent(); |
| 296 | fixIntent(intent); |
| 297 | |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 298 | setContentView(R.layout.dialtacts_activity); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 299 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 300 | getActionBar().hide(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 301 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 302 | // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState |
| 303 | // is null. Otherwise the fragment manager takes care of recreating these fragments. |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 304 | if (savedInstanceState == null) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 305 | final PhoneFavoriteFragment phoneFavoriteFragment = new PhoneFavoriteFragment(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 306 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 307 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 308 | ft.add(R.id.dialtacts_frame, phoneFavoriteFragment, TAG_FAVORITES_FRAGMENT); |
| 309 | ft.add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 310 | ft.commit(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 311 | } else { |
| 312 | mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 313 | mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI); |
| 314 | mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 315 | mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 318 | mBottomPaddingView = findViewById(R.id.dialtacts_bottom_padding); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 319 | mFragmentsFrame = findViewById(R.id.dialtacts_frame); |
Yorke Lee | 5f3ad54 | 2013-10-08 08:14:36 -0700 | [diff] [blame] | 320 | mActionBar = findViewById(R.id.fake_action_bar); |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame^] | 321 | mRemoveViewContainer = (RemoveView) findViewById(R.id.remove_view_container); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 322 | prepareSearchView(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 323 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 324 | if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction()) |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 325 | && savedInstanceState == null) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 326 | setupFilterText(intent); |
| 327 | } |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 328 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 329 | setupFakeActionBarItems(); |
| 330 | |
Yorke Lee | 0baa98b | 2013-08-22 10:55:16 -0700 | [diff] [blame] | 331 | mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this); |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 332 | SmartDialPrefix.initializeNanpSettings(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 336 | protected void onResume() { |
| 337 | super.onResume(); |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 338 | if (mFirstLaunch) { |
| 339 | displayFragment(getIntent()); |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 340 | } else if (!phoneIsInUse() && mInCallDialpadUp) { |
| 341 | hideDialpadFragment(false, true); |
| 342 | mInCallDialpadUp = false; |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 343 | } |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 344 | prepareVoiceSearchButton(); |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 345 | mFirstLaunch = false; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 346 | mDialerDatabaseHelper.startSmartDialUpdateThread(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | @Override |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 350 | protected void onPause() { |
| 351 | if (mClearSearchOnPause) { |
| 352 | hideDialpadAndSearchUi(); |
| 353 | mClearSearchOnPause = false; |
| 354 | } |
| 355 | super.onPause(); |
| 356 | } |
| 357 | |
| 358 | @Override |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 359 | protected void onSaveInstanceState(Bundle outState) { |
| 360 | super.onSaveInstanceState(outState); |
| 361 | outState.putString(KEY_SEARCH_QUERY, mSearchQuery); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 362 | outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch); |
| 363 | outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 364 | outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch); |
| 365 | } |
| 366 | |
| 367 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 368 | public void onAttachFragment(Fragment fragment) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 369 | if (fragment instanceof DialpadFragment) { |
| 370 | mDialpadFragment = (DialpadFragment) fragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 371 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 372 | transaction.hide(mDialpadFragment); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 373 | transaction.commit(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 374 | } else if (fragment instanceof SmartDialSearchFragment) { |
| 375 | mSmartDialSearchFragment = (SmartDialSearchFragment) fragment; |
Yorke Lee | 63ea4cd | 2013-08-12 11:04:47 -0700 | [diff] [blame] | 376 | mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener( |
| 377 | mPhoneNumberPickerActionListener); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 378 | } else if (fragment instanceof SearchFragment) { |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 379 | mRegularSearchFragment = (RegularSearchFragment) fragment; |
Yorke Lee | 63ea4cd | 2013-08-12 11:04:47 -0700 | [diff] [blame] | 380 | mRegularSearchFragment.setOnPhoneNumberPickerActionListener( |
| 381 | mPhoneNumberPickerActionListener); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 382 | } else if (fragment instanceof PhoneFavoriteFragment) { |
| 383 | mPhoneFavoriteFragment = (PhoneFavoriteFragment) fragment; |
Yorke Lee | 5781afe | 2013-08-12 11:12:59 -0700 | [diff] [blame] | 384 | mPhoneFavoriteFragment.setListener(mPhoneFavoriteListener); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 385 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 389 | public boolean onMenuItemClick(MenuItem item) { |
| 390 | switch (item.getItemId()) { |
| 391 | case R.id.menu_import_export: |
| 392 | // We hard-code the "contactsAreAvailable" argument because doing it properly would |
| 393 | // involve querying a {@link ProviderStatusLoader}, which we don't want to do right |
| 394 | // now in Dialtacts for (potential) performance reasons. Compare with how it is |
| 395 | // done in {@link PeopleActivity}. |
| 396 | ImportExportDialogFragment.show(getFragmentManager(), true, |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 397 | DialtactsActivity.class); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 398 | return true; |
| 399 | case R.id.menu_clear_frequents: |
| 400 | ClearFrequentsDialog.show(getFragmentManager()); |
| 401 | return true; |
Yorke Lee | 5e93197 | 2013-08-30 11:37:53 -0700 | [diff] [blame] | 402 | case R.id.menu_add_contact: |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 403 | try { |
| 404 | startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI)); |
| 405 | } catch (ActivityNotFoundException e) { |
| 406 | Toast toast = Toast.makeText(this, |
| 407 | R.string.add_contact_not_available, |
| 408 | Toast.LENGTH_SHORT); |
| 409 | toast.show(); |
| 410 | } |
| 411 | return true; |
| 412 | case R.id.menu_call_settings: |
Alon Albert | b453e5b | 2013-09-10 15:54:23 -0700 | [diff] [blame] | 413 | handleMenuSettings(); |
Yorke Lee | 5e93197 | 2013-08-30 11:37:53 -0700 | [diff] [blame] | 414 | return true; |
| 415 | case R.id.menu_all_contacts: |
| 416 | onShowAllContacts(); |
| 417 | return true; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 418 | } |
| 419 | return false; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Alon Albert | b453e5b | 2013-09-10 15:54:23 -0700 | [diff] [blame] | 422 | protected void handleMenuSettings() { |
| 423 | openTelephonySetting(this); |
| 424 | } |
| 425 | |
| 426 | public static void openTelephonySetting(Activity activity) { |
| 427 | final Intent settingsIntent = getCallSettingsIntent(); |
| 428 | activity.startActivity(settingsIntent); |
| 429 | } |
| 430 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 431 | @Override |
| 432 | public void onClick(View view) { |
| 433 | switch (view.getId()) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 434 | case R.id.overflow_menu: { |
Yorke Lee | 36c5413 | 2013-09-25 16:17:06 -0700 | [diff] [blame] | 435 | mOverflowMenu.show(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 436 | break; |
| 437 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 438 | case R.id.dialpad_button: |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 439 | // Reset the boolean flag that tracks whether the dialpad was up because |
| 440 | // we were in call. Regardless of whether it was true before, we want to |
| 441 | // show the dialpad because the user has explicitly clicked the dialpad |
| 442 | // button. |
| 443 | mInCallDialpadUp = false; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 444 | showDialpadFragment(true); |
| 445 | break; |
| 446 | case R.id.call_history_on_dialpad_button: |
| 447 | case R.id.call_history_button: |
Yorke Lee | f420a53 | 2013-08-09 15:16:10 -0700 | [diff] [blame] | 448 | // Use explicit CallLogActivity intent instead of ACTION_VIEW + |
| 449 | // CONTENT_TYPE, so that we always open our call log from our dialer |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 450 | final Intent intent = new Intent(this, CallLogActivity.class); |
| 451 | startActivity(intent); |
| 452 | break; |
| 453 | case R.id.search_close_button: |
| 454 | // Clear the search field |
| 455 | if (!TextUtils.isEmpty(mSearchView.getText())) { |
Yorke Lee | 2eafb7a | 2013-09-10 14:34:01 -0700 | [diff] [blame] | 456 | mDialpadFragment.clearDialpad(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 457 | mSearchView.setText(""); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 458 | } |
| 459 | break; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 460 | case R.id.voice_search_button: |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 461 | try { |
| 462 | startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), |
| 463 | ACTIVITY_REQUEST_CODE_VOICE_SEARCH); |
| 464 | } catch (ActivityNotFoundException e) { |
| 465 | Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available, |
| 466 | Toast.LENGTH_SHORT).show(); |
| 467 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 468 | break; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 469 | default: { |
| 470 | Log.wtf(TAG, "Unexpected onClick event from " + view); |
| 471 | break; |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 476 | @Override |
| 477 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 478 | if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) { |
| 479 | if (resultCode == RESULT_OK) { |
| 480 | final ArrayList<String> matches = data.getStringArrayListExtra( |
| 481 | RecognizerIntent.EXTRA_RESULTS); |
| 482 | if (matches.size() > 0) { |
| 483 | final String match = matches.get(0); |
| 484 | mSearchView.setText(match); |
| 485 | } else { |
| 486 | Log.e(TAG, "Voice search - nothing heard"); |
| 487 | } |
| 488 | } else { |
| 489 | Log.e(TAG, "Voice search failed"); |
| 490 | } |
| 491 | } |
| 492 | super.onActivityResult(requestCode, resultCode, data); |
| 493 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 494 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 495 | private void showDialpadFragment(boolean animate) { |
Yorke Lee | ea695cb | 2013-08-09 11:02:26 -0700 | [diff] [blame] | 496 | mDialpadFragment.setAdjustTranslationForAnimation(animate); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 497 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 498 | if (animate) { |
| 499 | ft.setCustomAnimations(R.anim.slide_in, 0); |
Yorke Lee | ea695cb | 2013-08-09 11:02:26 -0700 | [diff] [blame] | 500 | } else { |
| 501 | mDialpadFragment.setYFraction(0); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 502 | } |
| 503 | ft.show(mDialpadFragment); |
| 504 | ft.commit(); |
| 505 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 506 | |
Yorke Lee | ca19504 | 2013-09-25 16:29:38 -0700 | [diff] [blame] | 507 | public void hideDialpadFragment(boolean animate, boolean clearDialpad) { |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 508 | if (mDialpadFragment == null) return; |
| 509 | if (clearDialpad) { |
| 510 | mDialpadFragment.clearDialpad(); |
| 511 | } |
| 512 | if (!mDialpadFragment.isVisible()) return; |
Yorke Lee | ea695cb | 2013-08-09 11:02:26 -0700 | [diff] [blame] | 513 | mDialpadFragment.setAdjustTranslationForAnimation(animate); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 514 | final FragmentTransaction ft = getFragmentManager().beginTransaction(); |
| 515 | if (animate) { |
| 516 | ft.setCustomAnimations(0, R.anim.slide_out); |
| 517 | } |
| 518 | ft.hide(mDialpadFragment); |
| 519 | ft.commit(); |
| 520 | } |
| 521 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 522 | private void prepareSearchView() { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 523 | mSearchViewContainer = findViewById(R.id.search_view_container); |
| 524 | mSearchViewCloseButton = findViewById(R.id.search_close_button); |
| 525 | mSearchViewCloseButton.setOnClickListener(this); |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 526 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 527 | mSearchView = (EditText) findViewById(R.id.search_view); |
| 528 | mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); |
Yorke Lee | 41a24b4 | 2013-11-13 16:14:41 -0800 | [diff] [blame] | 529 | |
| 530 | final String hintText = getString(R.string.dialer_hint_find_contact); |
| 531 | |
| 532 | // The following code is used to insert an icon into a CharSequence (copied from |
| 533 | // SearchView) |
| 534 | final SpannableStringBuilder ssb = new SpannableStringBuilder(" "); // for the icon |
| 535 | ssb.append(hintText); |
| 536 | final Drawable searchIcon = getResources().getDrawable(R.drawable.ic_ab_search); |
| 537 | final int textSize = (int) (mSearchView.getTextSize() * 1.20); |
| 538 | searchIcon.setBounds(0, 0, textSize, textSize); |
| 539 | ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 540 | |
| 541 | mSearchView.setHint(ssb); |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 542 | |
| 543 | prepareVoiceSearchButton(); |
| 544 | } |
| 545 | |
| 546 | private void prepareVoiceSearchButton() { |
| 547 | mVoiceSearchButton = findViewById(R.id.voice_search_button); |
| 548 | final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); |
| 549 | if (canIntentBeHandled(voiceIntent)) { |
| 550 | mVoiceSearchButton.setVisibility(View.VISIBLE); |
| 551 | mVoiceSearchButton.setOnClickListener(this); |
| 552 | } else { |
| 553 | mVoiceSearchButton.setVisibility(View.GONE); |
| 554 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 557 | final AnimatorListener mHideListener = new AnimatorListenerAdapter() { |
| 558 | @Override |
| 559 | public void onAnimationEnd(Animator animation) { |
| 560 | mSearchViewContainer.setVisibility(View.GONE); |
| 561 | } |
| 562 | }; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 563 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 564 | private boolean getInSearchUi() { |
| 565 | return mInDialpadSearch || mInRegularSearch; |
| 566 | } |
| 567 | |
| 568 | private void setNotInSearchUi() { |
| 569 | mInDialpadSearch = false; |
| 570 | mInRegularSearch = false; |
| 571 | } |
| 572 | |
Yorke Lee | 311969c | 2013-08-26 06:31:11 -0700 | [diff] [blame] | 573 | private void hideDialpadAndSearchUi() { |
Yorke Lee | 7a06c44 | 2013-09-04 15:49:51 -0700 | [diff] [blame] | 574 | mSearchView.setText(null); |
Yorke Lee | 311969c | 2013-08-26 06:31:11 -0700 | [diff] [blame] | 575 | hideDialpadFragment(false, true); |
| 576 | } |
| 577 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 578 | public void hideSearchBar() { |
| 579 | hideSearchBar(true); |
Christine Chen | 9c1e065 | 2013-05-23 15:40:19 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 582 | public void hideSearchBar(boolean shiftView) { |
| 583 | if (shiftView) { |
| 584 | mSearchViewContainer.animate().cancel(); |
| 585 | mSearchViewContainer.setAlpha(1); |
| 586 | mSearchViewContainer.setTranslationY(0); |
| 587 | mSearchViewContainer.animate().withLayer().alpha(0).translationY(-mSearchView.getHeight()) |
| 588 | .setDuration(200).setListener(mHideListener); |
| 589 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 590 | mFragmentsFrame.animate().withLayer() |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 591 | .translationY(-mSearchViewContainer.getHeight()).setDuration(200).setListener( |
| 592 | new AnimatorListenerAdapter() { |
| 593 | @Override |
| 594 | public void onAnimationEnd(Animator animation) { |
| 595 | mBottomPaddingView.setVisibility(View.VISIBLE); |
Yorke Lee | 5f3ad54 | 2013-10-08 08:14:36 -0700 | [diff] [blame] | 596 | mFragmentsFrame.setTranslationY(0); |
| 597 | mActionBar.setVisibility(View.INVISIBLE); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 598 | } |
| 599 | }); |
| 600 | } else { |
| 601 | mSearchViewContainer.setTranslationY(-mSearchView.getHeight()); |
Yorke Lee | 5f3ad54 | 2013-10-08 08:14:36 -0700 | [diff] [blame] | 602 | mActionBar.setVisibility(View.INVISIBLE); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
| 606 | public void showSearchBar() { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 607 | mSearchViewContainer.animate().cancel(); |
| 608 | mSearchViewContainer.setAlpha(0); |
| 609 | mSearchViewContainer.setTranslationY(-mSearchViewContainer.getHeight()); |
| 610 | mSearchViewContainer.animate().withLayer().alpha(1).translationY(0).setDuration(200) |
| 611 | .setListener(new AnimatorListenerAdapter() { |
| 612 | @Override |
| 613 | public void onAnimationStart(Animator animation) { |
| 614 | mSearchViewContainer.setVisibility(View.VISIBLE); |
Yorke Lee | 5f3ad54 | 2013-10-08 08:14:36 -0700 | [diff] [blame] | 615 | mActionBar.setVisibility(View.VISIBLE); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 616 | } |
| 617 | }); |
| 618 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 619 | mFragmentsFrame.setTranslationY(-mSearchViewContainer.getHeight()); |
| 620 | mFragmentsFrame.animate().withLayer().translationY(0).setDuration(200) |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 621 | .setListener( |
| 622 | new AnimatorListenerAdapter() { |
| 623 | @Override |
| 624 | public void onAnimationStart(Animator animation) { |
| 625 | mBottomPaddingView.setVisibility(View.GONE); |
| 626 | } |
| 627 | }); |
| 628 | } |
| 629 | |
| 630 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 631 | public void setupFakeActionBarItems() { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 632 | mMenuButton = findViewById(R.id.overflow_menu); |
| 633 | if (mMenuButton != null) { |
| 634 | mMenuButton.setOnClickListener(this); |
Yorke Lee | 36c5413 | 2013-09-25 16:17:06 -0700 | [diff] [blame] | 635 | |
| 636 | mOverflowMenu = new OverflowPopupMenu(DialtactsActivity.this, mMenuButton); |
| 637 | final Menu menu = mOverflowMenu.getMenu(); |
| 638 | mOverflowMenu.inflate(R.menu.dialtacts_options); |
| 639 | mOverflowMenu.setOnMenuItemClickListener(this); |
| 640 | mMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener()); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | mCallHistoryButton = findViewById(R.id.call_history_button); |
| 644 | // mCallHistoryButton.setMinimumWidth(fakeMenuItemWidth); |
| 645 | mCallHistoryButton.setOnClickListener(this); |
| 646 | |
| 647 | mDialpadButton = findViewById(R.id.dialpad_button); |
| 648 | // DialpadButton.setMinimumWidth(fakeMenuItemWidth); |
| 649 | mDialpadButton.setOnClickListener(this); |
| 650 | } |
| 651 | |
| 652 | public void setupFakeActionBarItemsForDialpadFragment() { |
| 653 | final View callhistoryButton = findViewById(R.id.call_history_on_dialpad_button); |
| 654 | callhistoryButton.setOnClickListener(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | private void fixIntent(Intent intent) { |
| 658 | // This should be cleaned up: the call key used to send an Intent |
| 659 | // that just said to go to the recent calls list. It now sends this |
| 660 | // abstract action, but this class hasn't been rewritten to deal with it. |
| 661 | if (Intent.ACTION_CALL_BUTTON.equals(intent.getAction())) { |
| 662 | intent.setDataAndType(Calls.CONTENT_URI, Calls.CONTENT_TYPE); |
| 663 | intent.putExtra("call_key", true); |
| 664 | setIntent(intent); |
| 665 | } |
| 666 | } |
| 667 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 668 | /** |
| 669 | * Returns true if the intent is due to hitting the green send key (hardware call button: |
| 670 | * KEYCODE_CALL) while in a call. |
| 671 | * |
| 672 | * @param intent the intent that launched this activity |
| 673 | * @param recentCallsRequest true if the intent is requesting to view recent calls |
| 674 | * @return true if the intent is due to hitting the green send key while in a call |
| 675 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 676 | private boolean isSendKeyWhileInCall(Intent intent, boolean recentCallsRequest) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 677 | // If there is a call in progress go to the call screen |
| 678 | if (recentCallsRequest) { |
| 679 | final boolean callKey = intent.getBooleanExtra("call_key", false); |
| 680 | |
| 681 | try { |
| 682 | ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); |
| 683 | if (callKey && phone != null && phone.showCallScreen()) { |
| 684 | return true; |
| 685 | } |
| 686 | } catch (RemoteException e) { |
| 687 | Log.e(TAG, "Failed to handle send while in call", e); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | return false; |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * Sets the current tab based on the intent's request type |
| 696 | * |
| 697 | * @param intent Intent that contains information about which tab should be selected |
| 698 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 699 | private void displayFragment(Intent intent) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 700 | // If we got here by hitting send and we're in call forward along to the in-call activity |
| 701 | boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent.resolveType( |
| 702 | getContentResolver())); |
| 703 | if (isSendKeyWhileInCall(intent, recentCallsRequest)) { |
| 704 | finish(); |
| 705 | return; |
| 706 | } |
| 707 | |
Yorke Lee | 669b608 | 2013-09-17 15:43:38 -0700 | [diff] [blame] | 708 | if (mDialpadFragment != null) { |
| 709 | final boolean phoneIsInUse = phoneIsInUse(); |
| 710 | if (phoneIsInUse || isDialIntent(intent)) { |
| 711 | mDialpadFragment.setStartedFromNewIntent(true); |
| 712 | if (phoneIsInUse && !mDialpadFragment.isVisible()) { |
| 713 | mInCallDialpadUp = true; |
| 714 | } |
| 715 | showDialpadFragment(false); |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 716 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 717 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | @Override |
| 721 | public void onNewIntent(Intent newIntent) { |
| 722 | setIntent(newIntent); |
| 723 | fixIntent(newIntent); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 724 | displayFragment(newIntent); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 725 | final String action = newIntent.getAction(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 726 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 727 | invalidateOptionsMenu(); |
| 728 | } |
| 729 | |
| 730 | /** Returns true if the given intent contains a phone number to populate the dialer with */ |
| 731 | private boolean isDialIntent(Intent intent) { |
| 732 | final String action = intent.getAction(); |
| 733 | if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) { |
| 734 | return true; |
| 735 | } |
| 736 | if (Intent.ACTION_VIEW.equals(action)) { |
| 737 | final Uri data = intent.getData(); |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 738 | if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 739 | return true; |
| 740 | } |
| 741 | } |
| 742 | return false; |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Returns an appropriate call origin for this Activity. May return null when no call origin |
| 747 | * should be used (e.g. when some 3rd party application launched the screen. Call origin is |
| 748 | * for remembering the tab in which the user made a phone call, so the external app's DIAL |
| 749 | * request should not be counted.) |
| 750 | */ |
| 751 | public String getCallOrigin() { |
| 752 | return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null; |
| 753 | } |
| 754 | |
| 755 | /** |
| 756 | * Retrieves the filter text stored in {@link #setupFilterText(Intent)}. |
| 757 | * This text originally came from a FILTER_CONTACTS_ACTION intent received |
| 758 | * by this activity. The stored text will then be cleared after after this |
| 759 | * method returns. |
| 760 | * |
| 761 | * @return The stored filter text |
| 762 | */ |
| 763 | public String getAndClearFilterText() { |
| 764 | String filterText = mFilterText; |
| 765 | mFilterText = null; |
| 766 | return filterText; |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * Stores the filter text associated with a FILTER_CONTACTS_ACTION intent. |
| 771 | * This is so child activities can check if they are supposed to display a filter. |
| 772 | * |
| 773 | * @param intent The intent received in {@link #onNewIntent(Intent)} |
| 774 | */ |
| 775 | private void setupFilterText(Intent intent) { |
| 776 | // If the intent was relaunched from history, don't apply the filter text. |
| 777 | if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { |
| 778 | return; |
| 779 | } |
| 780 | String filter = intent.getStringExtra(UI.FILTER_TEXT_EXTRA_KEY); |
| 781 | if (filter != null && filter.length() > 0) { |
| 782 | mFilterText = filter; |
| 783 | } |
| 784 | } |
| 785 | |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 786 | private final PhoneFavoriteFragment.Listener mPhoneFavoriteListener = |
| 787 | new PhoneFavoriteFragment.Listener() { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 788 | @Override |
| 789 | public void onContactSelected(Uri contactUri) { |
| 790 | PhoneNumberInteraction.startInteractionForPhoneCall( |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 791 | DialtactsActivity.this, contactUri, getCallOrigin()); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | @Override |
| 795 | public void onCallNumberDirectly(String phoneNumber) { |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 796 | Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin()); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 797 | startActivity(intent); |
| 798 | } |
| 799 | }; |
| 800 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 801 | /* TODO krelease: This is only relevant for phones that have a hard button search key (i.e. |
| 802 | * Nexus S). Supporting it is a little more tricky because of the dialpad fragment might |
| 803 | * be showing when the search key is pressed so there is more state management involved. |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 804 | |
| 805 | @Override |
| 806 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
| 807 | Bundle appSearchData, boolean globalSearch) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 808 | if (mRegularSearchFragment != null && mRegularSearchFragment.isAdded() && !globalSearch) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 809 | if (mInSearchUi) { |
| 810 | if (mSearchView.hasFocus()) { |
| 811 | showInputMethod(mSearchView.findFocus()); |
| 812 | } else { |
| 813 | mSearchView.requestFocus(); |
| 814 | } |
| 815 | } else { |
| 816 | enterSearchUi(); |
| 817 | } |
| 818 | } else { |
| 819 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 820 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 821 | }*/ |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 822 | |
| 823 | private void showInputMethod(View view) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 824 | final InputMethodManager imm = (InputMethodManager) getSystemService( |
| 825 | Context.INPUT_METHOD_SERVICE); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 826 | if (imm != null) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 827 | imm.showSoftInput(view, 0); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
| 831 | private void hideInputMethod(View view) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 832 | final InputMethodManager imm = (InputMethodManager) getSystemService( |
| 833 | Context.INPUT_METHOD_SERVICE); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 834 | if (imm != null && view != null) { |
| 835 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 840 | * Shows the search fragment |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 841 | */ |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 842 | private void enterSearchUi(boolean smartDialSearch, String query) { |
Yorke Lee | 34bdf87 | 2013-08-15 14:11:50 -0700 | [diff] [blame] | 843 | if (getFragmentManager().isDestroyed()) { |
| 844 | // Weird race condition where fragment is doing work after the activity is destroyed |
| 845 | // due to talkback being on (b/10209937). Just return since we can't do any |
| 846 | // constructive here. |
| 847 | return; |
| 848 | } |
| 849 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 850 | if (DEBUG) { |
| 851 | Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch); |
| 852 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 853 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 854 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
| 855 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 856 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 857 | SearchFragment fragment; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 858 | if (mInDialpadSearch) { |
| 859 | transaction.remove(mSmartDialSearchFragment); |
| 860 | } else if (mInRegularSearch) { |
| 861 | transaction.remove(mRegularSearchFragment); |
| 862 | } else { |
| 863 | transaction.remove(mPhoneFavoriteFragment); |
| 864 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 865 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 866 | final String tag; |
| 867 | if (smartDialSearch) { |
| 868 | tag = TAG_SMARTDIAL_SEARCH_FRAGMENT; |
| 869 | } else { |
| 870 | tag = TAG_REGULAR_SEARCH_FRAGMENT; |
| 871 | } |
| 872 | mInDialpadSearch = smartDialSearch; |
| 873 | mInRegularSearch = !smartDialSearch; |
| 874 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 875 | fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag); |
| 876 | if (fragment == null) { |
| 877 | if (smartDialSearch) { |
| 878 | fragment = new SmartDialSearchFragment(); |
| 879 | } else { |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 880 | fragment = new RegularSearchFragment(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 881 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 882 | } |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 883 | transaction.replace(R.id.dialtacts_frame, fragment, tag); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 884 | transaction.addToBackStack(null); |
| 885 | fragment.setQueryString(query, false); |
| 886 | transaction.commit(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 890 | * Hides the search fragment |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 891 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 892 | private void exitSearchUi() { |
Yorke Lee | 3487db7 | 2013-09-26 17:12:06 -0700 | [diff] [blame] | 893 | // See related bug in enterSearchUI(); |
| 894 | if (getFragmentManager().isDestroyed()) { |
| 895 | return; |
| 896 | } |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 897 | // Go all the way back to the favorites fragment, regardless of how many times we |
| 898 | // transitioned between search fragments |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 899 | getFragmentManager().popBackStack(0, FragmentManager.POP_BACK_STACK_INCLUSIVE); |
| 900 | setNotInSearchUi(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | /** Returns an Intent to launch Call Settings screen */ |
| 904 | public static Intent getCallSettingsIntent() { |
| 905 | final Intent intent = new Intent(Intent.ACTION_MAIN); |
| 906 | intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME); |
| 907 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 908 | return intent; |
| 909 | } |
| 910 | |
| 911 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 912 | public void onBackPressed() { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 913 | if (mDialpadFragment != null && mDialpadFragment.isVisible()) { |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 914 | hideDialpadFragment(true, false); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 915 | } else if (getInSearchUi()) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 916 | mSearchView.setText(null); |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 917 | mDialpadFragment.clearDialpad(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 918 | } else { |
| 919 | super.onBackPressed(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 920 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | @Override |
| 924 | public void onDialpadQueryChanged(String query) { |
| 925 | final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query, |
| 926 | SmartDialNameMatcher.LATIN_SMART_DIAL_MAP); |
| 927 | if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 928 | if (DEBUG) { |
| 929 | Log.d(TAG, "onDialpadQueryChanged - new query: " + query); |
| 930 | } |
| 931 | if (mDialpadFragment == null || !mDialpadFragment.isVisible()) { |
| 932 | // This callback can happen if the dialpad fragment is recreated because of |
| 933 | // activity destruction. In that case, don't update the search view because |
| 934 | // that would bring the user back to the search fragment regardless of the |
| 935 | // previous state of the application. Instead, just return here and let the |
| 936 | // fragment manager correctly figure out whatever fragment was last displayed. |
| 937 | return; |
| 938 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 939 | mSearchView.setText(normalizedQuery); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 940 | } |
| 941 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 942 | |
| 943 | @Override |
| 944 | public void onListFragmentScrollStateChange(int scrollState) { |
| 945 | if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 946 | hideDialpadFragment(true, false); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 947 | hideInputMethod(getCurrentFocus()); |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 952 | public void onDialpadFragmentStarted() { |
| 953 | setupFakeActionBarItemsForDialpadFragment(); |
| 954 | } |
| 955 | |
| 956 | private boolean phoneIsInUse() { |
| 957 | final TelephonyManager tm = (TelephonyManager) getSystemService( |
| 958 | Context.TELEPHONY_SERVICE); |
| 959 | return tm.getCallState() != TelephonyManager.CALL_STATE_IDLE; |
| 960 | } |
Yorke Lee | 8dd6200 | 2013-08-08 15:57:20 -0700 | [diff] [blame] | 961 | |
| 962 | @Override |
| 963 | public void onShowAllContacts() { |
| 964 | final Intent intent = new Intent(this, AllContactsActivity.class); |
| 965 | startActivity(intent); |
| 966 | } |
Yorke Lee | e142481 | 2013-09-04 18:24:48 -0700 | [diff] [blame] | 967 | |
| 968 | public static Intent getAddNumberToContactIntent(CharSequence text) { |
| 969 | final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 970 | intent.putExtra(Intents.Insert.PHONE, text); |
| 971 | intent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 972 | return intent; |
| 973 | } |
| 974 | |
| 975 | public static Intent getInsertContactWithNameIntent(CharSequence text) { |
| 976 | final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI); |
| 977 | intent.putExtra(Intents.Insert.NAME, text); |
| 978 | return intent; |
| 979 | } |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 980 | |
| 981 | private boolean canIntentBeHandled(Intent intent) { |
| 982 | final PackageManager packageManager = getPackageManager(); |
| 983 | final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, |
| 984 | PackageManager.MATCH_DEFAULT_ONLY); |
| 985 | return resolveInfo != null && resolveInfo.size() > 0; |
| 986 | } |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame^] | 987 | |
| 988 | @Override |
| 989 | public void onDragStarted(int itemIndex, int x, int y, PhoneFavoriteTileView view) { |
| 990 | crossfadeViews(mRemoveViewContainer, mSearchViewContainer, FADE_ANIMATION_DURATION); |
| 991 | } |
| 992 | |
| 993 | @Override |
| 994 | public void onDragHovered(int itemIndex, int x, int y) {} |
| 995 | |
| 996 | @Override |
| 997 | public void onDragFinished(int x, int y) { |
| 998 | crossfadeViews(mSearchViewContainer, mRemoveViewContainer, FADE_ANIMATION_DURATION); |
| 999 | } |
| 1000 | |
| 1001 | @Override |
| 1002 | public void onDroppedOnRemove() {} |
| 1003 | |
| 1004 | /** |
| 1005 | * Allows the PhoneFavoriteFragment to attach the drag controller to mRemoveViewContainer |
| 1006 | * once it has been attached to the activity. |
| 1007 | */ |
| 1008 | @Override |
| 1009 | public void setDragDropController(DragDropController dragController) { |
| 1010 | mRemoveViewContainer.setDragDropController(dragController); |
| 1011 | } |
| 1012 | |
| 1013 | /** |
| 1014 | * Crossfades two views so that the first one appears while the other one is fading |
| 1015 | * out of view. |
| 1016 | */ |
| 1017 | private void crossfadeViews(final View fadeIn, final View fadeOut, int duration) { |
| 1018 | fadeOut.animate().alpha(0).setDuration(duration) |
| 1019 | .setListener(new AnimatorListenerAdapter() { |
| 1020 | @Override |
| 1021 | public void onAnimationEnd(Animator animation) { |
| 1022 | fadeOut.setVisibility(View.GONE); |
| 1023 | } |
| 1024 | }); |
| 1025 | |
| 1026 | fadeIn.setVisibility(View.VISIBLE); |
| 1027 | fadeIn.setAlpha(0); |
| 1028 | fadeIn.animate().alpha(1).setDuration(FADE_ANIMATION_DURATION) |
| 1029 | .setListener(null); |
| 1030 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1031 | } |