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