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