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