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; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 38 | import android.speech.RecognizerIntent; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 39 | import android.telephony.TelephonyManager; |
| 40 | import android.text.Editable; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 41 | import android.text.TextUtils; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 42 | import android.text.TextWatcher; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 43 | import android.util.Log; |
| 44 | import android.view.Menu; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 45 | import android.view.MenuItem; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 46 | import android.view.View; |
Yorke Lee | b0d1976 | 2014-03-05 14:43:28 -0800 | [diff] [blame] | 47 | import android.view.ViewGroup.LayoutParams; |
| 48 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 49 | import android.view.inputmethod.InputMethodManager; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 50 | import android.widget.AbsListView.OnScrollListener; |
| 51 | import android.widget.EditText; |
Yorke Lee | b0d1976 | 2014-03-05 14:43:28 -0800 | [diff] [blame] | 52 | import android.widget.LinearLayout; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 53 | import android.widget.PopupMenu; |
Chiao Cheng | 073b5cf | 2012-12-07 11:36:00 -0800 | [diff] [blame] | 54 | import android.widget.Toast; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 55 | |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 56 | import com.android.contacts.common.CallUtil; |
Chiao Cheng | 603ff68 | 2012-10-24 15:18:40 -0700 | [diff] [blame] | 57 | import com.android.contacts.common.activity.TransactionSafeActivity; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 58 | import com.android.contacts.common.dialog.ClearFrequentsDialog; |
| 59 | import com.android.contacts.common.interactions.ImportExportDialogFragment; |
Chiao Cheng | 8efbcf9 | 2012-12-04 17:43:02 -0800 | [diff] [blame] | 60 | import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 61 | import com.android.dialer.calllog.CallLogActivity; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 62 | import com.android.dialer.database.DialerDatabaseHelper; |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 63 | import com.android.dialer.dialpad.DialpadFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 64 | import com.android.dialer.dialpad.SmartDialNameMatcher; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 65 | import com.android.dialer.dialpad.SmartDialPrefix; |
Chiao Cheng | 1429f1a | 2012-11-01 16:35:28 -0700 | [diff] [blame] | 66 | import com.android.dialer.interactions.PhoneNumberInteraction; |
Yorke Lee | 8dd6200 | 2013-08-08 15:57:20 -0700 | [diff] [blame] | 67 | import com.android.dialer.list.AllContactsActivity; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 68 | import com.android.dialer.list.DragDropController; |
| 69 | import com.android.dialer.list.OnDragDropListener; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 70 | import com.android.dialer.list.OnListFragmentScrolledListener; |
Alon Albert | b453e5b | 2013-09-10 15:54:23 -0700 | [diff] [blame] | 71 | import com.android.dialer.list.PhoneFavoriteFragment; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 72 | import com.android.dialer.list.PhoneFavoriteTileView; |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 73 | import com.android.dialer.list.RegularSearchFragment; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 74 | import com.android.dialer.list.RemoveView; |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 75 | import com.android.dialer.list.SearchFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 76 | import com.android.dialer.list.SmartDialSearchFragment; |
Yorke Lee | 0baa98b | 2013-08-22 10:55:16 -0700 | [diff] [blame] | 77 | import com.android.dialerbind.DatabaseHelperManager; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 78 | import com.android.internal.telephony.ITelephony; |
| 79 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 80 | import java.util.ArrayList; |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 81 | import java.util.List; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 82 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 83 | /** |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 84 | * The dialer tab's title is 'phone', a more common name (see strings.xml). |
| 85 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 86 | public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener, |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 87 | DialpadFragment.OnDialpadQueryChangedListener, PopupMenu.OnMenuItemClickListener, |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 88 | OnListFragmentScrolledListener, |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 89 | DialpadFragment.HostInterface, |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 90 | PhoneFavoriteFragment.OnShowAllContactsListener, |
| 91 | PhoneFavoriteFragment.HostInterface, |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 92 | OnDragDropListener, View.OnLongClickListener { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 93 | private static final String TAG = "DialtactsActivity"; |
| 94 | |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 95 | public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 96 | |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 97 | public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences"; |
| 98 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 99 | /** Used to open Call Setting */ |
| 100 | private static final String PHONE_PACKAGE = "com.android.phone"; |
| 101 | private static final String CALL_SETTINGS_CLASS_NAME = |
| 102 | "com.android.phone.CallFeaturesSetting"; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 103 | /** @see #getCallOrigin() */ |
| 104 | private static final String CALL_ORIGIN_DIALTACTS = |
| 105 | "com.android.dialer.DialtactsActivity"; |
| 106 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 107 | private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui"; |
| 108 | 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] | 109 | private static final String KEY_SEARCH_QUERY = "search_query"; |
| 110 | private static final String KEY_FIRST_LAUNCH = "first_launch"; |
| 111 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 112 | private static final String TAG_DIALPAD_FRAGMENT = "dialpad"; |
| 113 | private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search"; |
| 114 | private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial"; |
| 115 | private static final String TAG_FAVORITES_FRAGMENT = "favorites"; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 116 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 117 | /** |
| 118 | * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}. |
| 119 | */ |
| 120 | private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER"; |
| 121 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 122 | private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 123 | |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 124 | private static final int ANIMATION_DURATION = 200; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 125 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 126 | private String mFilterText; |
| 127 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 128 | /** |
| 129 | * The main fragment displaying the user's favorites and frequent contacts |
| 130 | */ |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 131 | private PhoneFavoriteFragment mPhoneFavoriteFragment; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 132 | |
| 133 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 134 | * Fragment containing the dialpad that slides into view |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 135 | */ |
Yorke Lee | f74011e | 2013-08-02 11:30:30 -0700 | [diff] [blame] | 136 | private DialpadFragment mDialpadFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * Fragment for searching phone numbers using the alphanumeric keyboard. |
| 140 | */ |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 141 | private RegularSearchFragment mRegularSearchFragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * Fragment for searching phone numbers using the dialpad. |
| 145 | */ |
| 146 | private SmartDialSearchFragment mSmartDialSearchFragment; |
| 147 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 148 | private View mMenuButton; |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 149 | private View mFakeActionBar; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 150 | private View mCallHistoryButton; |
| 151 | private View mDialpadButton; |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 152 | private View mDialButton; |
Yorke Lee | 36c5413 | 2013-09-25 16:17:06 -0700 | [diff] [blame] | 153 | private PopupMenu mOverflowMenu; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 154 | |
Yorke Lee | b0d1976 | 2014-03-05 14:43:28 -0800 | [diff] [blame] | 155 | // Padding view used to shift the fragment frame up when the dialpad is shown so that |
| 156 | // the contents of the fragment frame continue to exist in a layout of the same height |
| 157 | private View mFragmentsSpacer; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 158 | private View mFragmentsFrame; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 159 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 160 | private boolean mInDialpadSearch; |
| 161 | private boolean mInRegularSearch; |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 162 | private boolean mClearSearchOnPause; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 163 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 164 | /** |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 165 | * True if the dialpad is only temporarily showing due to being in call |
| 166 | */ |
| 167 | private boolean mInCallDialpadUp; |
| 168 | |
| 169 | /** |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 170 | * True when this activity has been launched for the first time. |
| 171 | */ |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 172 | private boolean mFirstLaunch; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 173 | private View mSearchViewContainer; |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 174 | private RemoveView mRemoveViewContainer; |
Yorke Lee | 94f4904 | 2014-03-03 14:03:08 -0800 | [diff] [blame] | 175 | // This view points to the Framelayout that houses both the search view and remove view |
| 176 | // containers. |
| 177 | private View mSearchAndRemoveViewContainer; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 178 | private View mSearchViewCloseButton; |
| 179 | private View mVoiceSearchButton; |
| 180 | private EditText mSearchView; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 181 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 182 | private String mSearchQuery; |
| 183 | |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 184 | private DialerDatabaseHelper mDialerDatabaseHelper; |
| 185 | |
Yorke Lee | 36c5413 | 2013-09-25 16:17:06 -0700 | [diff] [blame] | 186 | private class OverflowPopupMenu extends PopupMenu { |
| 187 | public OverflowPopupMenu(Context context, View anchor) { |
| 188 | super(context, anchor); |
| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public void show() { |
| 193 | final Menu menu = getMenu(); |
| 194 | final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents); |
| 195 | clearFrequents.setVisible(mPhoneFavoriteFragment.hasFrequents()); |
| 196 | super.show(); |
| 197 | } |
| 198 | } |
| 199 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 200 | /** |
| 201 | * Listener used when one of phone numbers in search UI is selected. This will initiate a |
| 202 | * phone call using the phone number. |
| 203 | */ |
| 204 | private final OnPhoneNumberPickerActionListener mPhoneNumberPickerActionListener = |
| 205 | new OnPhoneNumberPickerActionListener() { |
| 206 | @Override |
| 207 | public void onPickPhoneNumberAction(Uri dataUri) { |
| 208 | // Specify call-origin so that users will see the previous tab instead of |
| 209 | // CallLog screen (search UI will be automatically exited). |
| 210 | PhoneNumberInteraction.startInteractionForPhoneCall( |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 211 | DialtactsActivity.this, dataUri, getCallOrigin()); |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 212 | mClearSearchOnPause = true; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | @Override |
Jay Shrauner | 31a760b | 2013-07-26 09:34:49 -0700 | [diff] [blame] | 216 | public void onCallNumberDirectly(String phoneNumber) { |
| 217 | Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin()); |
| 218 | startActivity(intent); |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 219 | mClearSearchOnPause = true; |
Jay Shrauner | 31a760b | 2013-07-26 09:34:49 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | @Override |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 223 | public void onShortcutIntentCreated(Intent intent) { |
| 224 | Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring."); |
| 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public void onHomeInActionBarSelected() { |
| 229 | exitSearchUi(); |
| 230 | } |
| 231 | }; |
| 232 | |
| 233 | /** |
| 234 | * Listener used to send search queries to the phone search fragment. |
| 235 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 236 | private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() { |
| 237 | @Override |
| 238 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 243 | final String newText = s.toString(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 244 | if (newText.equals(mSearchQuery)) { |
| 245 | // If the query hasn't changed (perhaps due to activity being destroyed |
| 246 | // and restored, or user launching the same DIAL intent twice), then there is |
| 247 | // no need to do anything here. |
| 248 | return; |
| 249 | } |
| 250 | mSearchQuery = newText; |
| 251 | if (DEBUG) { |
| 252 | Log.d(TAG, "onTextChange for mSearchView called with new query: " + s); |
| 253 | } |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 254 | final boolean dialpadSearch = isDialpadShowing(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 255 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 256 | // Show search result with non-empty text. Show a bare list otherwise. |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 257 | if (TextUtils.isEmpty(newText) && getInSearchUi()) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 258 | exitSearchUi(); |
| 259 | mSearchViewCloseButton.setVisibility(View.GONE); |
Yorke Lee | 3b82fc1 | 2013-09-09 08:42:38 -0700 | [diff] [blame] | 260 | mVoiceSearchButton.setVisibility(View.VISIBLE); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 261 | return; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 262 | } else if (!TextUtils.isEmpty(newText)) { |
| 263 | final boolean sameSearchMode = (dialpadSearch && mInDialpadSearch) || |
| 264 | (!dialpadSearch && mInRegularSearch); |
| 265 | if (!sameSearchMode) { |
| 266 | // call enterSearchUi only if we are switching search modes, or entering |
| 267 | // search ui for the first time |
| 268 | enterSearchUi(dialpadSearch, newText); |
| 269 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 270 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 271 | if (dialpadSearch && mSmartDialSearchFragment != null) { |
| 272 | mSmartDialSearchFragment.setQueryString(newText, false); |
| 273 | } else if (mRegularSearchFragment != null) { |
| 274 | mRegularSearchFragment.setQueryString(newText, false); |
| 275 | } |
| 276 | mSearchViewCloseButton.setVisibility(View.VISIBLE); |
Yorke Lee | 3b82fc1 | 2013-09-09 08:42:38 -0700 | [diff] [blame] | 277 | mVoiceSearchButton.setVisibility(View.GONE); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 278 | return; |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 279 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | @Override |
| 283 | public void afterTextChanged(Editable s) { |
| 284 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 287 | private boolean isDialpadShowing() { |
| 288 | return mDialpadFragment != null && mDialpadFragment.isVisible(); |
| 289 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 290 | |
| 291 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 292 | protected void onCreate(Bundle savedInstanceState) { |
| 293 | super.onCreate(savedInstanceState); |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 294 | mFirstLaunch = true; |
| 295 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 296 | final Intent intent = getIntent(); |
| 297 | fixIntent(intent); |
| 298 | |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 299 | setContentView(R.layout.dialtacts_activity); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 300 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 301 | getActionBar().hide(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 302 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 303 | // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState |
| 304 | // is null. Otherwise the fragment manager takes care of recreating these fragments. |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 305 | if (savedInstanceState == null) { |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 306 | getFragmentManager().beginTransaction() |
| 307 | .add(R.id.dialtacts_frame, new PhoneFavoriteFragment(), TAG_FAVORITES_FRAGMENT) |
| 308 | .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT) |
| 309 | .commit(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 310 | } else { |
| 311 | mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 312 | mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI); |
| 313 | mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 314 | mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 317 | mFragmentsFrame = findViewById(R.id.dialtacts_frame); |
Yorke Lee | b0d1976 | 2014-03-05 14:43:28 -0800 | [diff] [blame] | 318 | mFragmentsSpacer = findViewById(R.id.contact_tile_frame_spacer); |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 319 | |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 320 | mRemoveViewContainer = (RemoveView) findViewById(R.id.remove_view_container); |
Yorke Lee | b0d1976 | 2014-03-05 14:43:28 -0800 | [diff] [blame] | 321 | mSearchAndRemoveViewContainer = findViewById(R.id.search_and_remove_view_container); |
| 322 | |
| 323 | // When the first global layout pass is completed (and mSearchAndRemoveViewContainer has |
| 324 | // been assigned a valid height), assign that height to mFragmentsSpacer as well. |
| 325 | mSearchAndRemoveViewContainer.getViewTreeObserver().addOnGlobalLayoutListener( |
| 326 | new OnGlobalLayoutListener() { |
| 327 | @Override |
| 328 | public void onGlobalLayout() { |
| 329 | mSearchAndRemoveViewContainer.getViewTreeObserver() |
| 330 | .removeOnGlobalLayoutListener(this); |
| 331 | mFragmentsSpacer.setLayoutParams( |
| 332 | new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, |
| 333 | mSearchAndRemoveViewContainer.getHeight())); |
| 334 | } |
| 335 | }); |
| 336 | |
| 337 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 338 | prepareSearchView(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 339 | |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 340 | hideDialpadFragment(false, false); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 341 | setupFakeActionBarItems(); |
| 342 | |
Yorke Lee | 0baa98b | 2013-08-22 10:55:16 -0700 | [diff] [blame] | 343 | mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this); |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 344 | SmartDialPrefix.initializeNanpSettings(this); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 348 | protected void onResume() { |
| 349 | super.onResume(); |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 350 | if (mFirstLaunch) { |
| 351 | displayFragment(getIntent()); |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 352 | } else if (!phoneIsInUse() && mInCallDialpadUp) { |
| 353 | hideDialpadFragment(false, true); |
| 354 | mInCallDialpadUp = false; |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 355 | } |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 356 | prepareVoiceSearchButton(); |
Yorke Lee | 98702de | 2013-08-06 12:03:32 -0700 | [diff] [blame] | 357 | mFirstLaunch = false; |
Yorke Lee | fce269a | 2013-08-12 11:56:04 -0700 | [diff] [blame] | 358 | mDialerDatabaseHelper.startSmartDialUpdateThread(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | @Override |
Yorke Lee | 8e5c8b1 | 2013-10-01 14:37:55 -0700 | [diff] [blame] | 362 | protected void onPause() { |
| 363 | if (mClearSearchOnPause) { |
| 364 | hideDialpadAndSearchUi(); |
| 365 | mClearSearchOnPause = false; |
| 366 | } |
| 367 | super.onPause(); |
| 368 | } |
| 369 | |
| 370 | @Override |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 371 | protected void onSaveInstanceState(Bundle outState) { |
| 372 | super.onSaveInstanceState(outState); |
| 373 | outState.putString(KEY_SEARCH_QUERY, mSearchQuery); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 374 | outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch); |
| 375 | outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 376 | outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch); |
| 377 | } |
| 378 | |
| 379 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 380 | public void onAttachFragment(Fragment fragment) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 381 | if (fragment instanceof DialpadFragment) { |
| 382 | mDialpadFragment = (DialpadFragment) fragment; |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 383 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 384 | transaction.hide(mDialpadFragment); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 385 | transaction.commit(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 386 | } else if (fragment instanceof SmartDialSearchFragment) { |
| 387 | mSmartDialSearchFragment = (SmartDialSearchFragment) fragment; |
Yorke Lee | 63ea4cd | 2013-08-12 11:04:47 -0700 | [diff] [blame] | 388 | mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener( |
| 389 | mPhoneNumberPickerActionListener); |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 390 | if (mFragmentsFrame != null) { |
| 391 | mFragmentsFrame.setAlpha(1.0f); |
| 392 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 393 | } else if (fragment instanceof SearchFragment) { |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 394 | mRegularSearchFragment = (RegularSearchFragment) fragment; |
Yorke Lee | 63ea4cd | 2013-08-12 11:04:47 -0700 | [diff] [blame] | 395 | mRegularSearchFragment.setOnPhoneNumberPickerActionListener( |
| 396 | mPhoneNumberPickerActionListener); |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 397 | if (mFragmentsFrame != null) { |
| 398 | mFragmentsFrame.setAlpha(1.0f); |
| 399 | } |
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) |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 618 | .translationY(-height).setDuration(ANIMATION_DURATION) |
Yorke Lee | 94f4904 | 2014-03-03 14:03:08 -0800 | [diff] [blame] | 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() |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 622 | .translationY(-height).setDuration(ANIMATION_DURATION).setListener( |
Yorke Lee | 94f4904 | 2014-03-03 14:03:08 -0800 | [diff] [blame] | 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 | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 633 | |
| 634 | if (!mInDialpadSearch && !mInRegularSearch) { |
| 635 | // If the favorites fragment is showing, fade to blank. |
| 636 | mFragmentsFrame.animate().alpha(0.0f); |
| 637 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | public void showSearchBar() { |
Yorke Lee | 94f4904 | 2014-03-03 14:03:08 -0800 | [diff] [blame] | 641 | final int height = mSearchAndRemoveViewContainer.getHeight(); |
| 642 | mSearchAndRemoveViewContainer.animate().cancel(); |
| 643 | mSearchAndRemoveViewContainer.setAlpha(0); |
| 644 | mSearchAndRemoveViewContainer.setTranslationY(-height); |
| 645 | mSearchAndRemoveViewContainer.animate().withLayer().alpha(1).translationY(0) |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 646 | .setDuration(ANIMATION_DURATION).setListener(new AnimatorListenerAdapter() { |
Yorke Lee | 94f4904 | 2014-03-03 14:03:08 -0800 | [diff] [blame] | 647 | @Override |
| 648 | public void onAnimationStart(Animator animation) { |
| 649 | mSearchAndRemoveViewContainer.setVisibility(View.VISIBLE); |
| 650 | } |
| 651 | }); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 652 | |
Yorke Lee | 94f4904 | 2014-03-03 14:03:08 -0800 | [diff] [blame] | 653 | mFragmentsFrame.setTranslationY(-height); |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 654 | mFragmentsFrame.animate().withLayer().translationY(0).setDuration(ANIMATION_DURATION) |
| 655 | .alpha(1.0f) |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 656 | .setListener( |
| 657 | new AnimatorListenerAdapter() { |
| 658 | @Override |
| 659 | public void onAnimationStart(Animator animation) { |
Yorke Lee | b0d1976 | 2014-03-05 14:43:28 -0800 | [diff] [blame] | 660 | // Hide the fragment spacer now that the search box will |
| 661 | // be displayed again |
| 662 | mFragmentsSpacer.setVisibility(View.GONE); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 663 | } |
| 664 | }); |
| 665 | } |
| 666 | |
| 667 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 668 | public void setupFakeActionBarItems() { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 669 | mMenuButton = findViewById(R.id.overflow_menu); |
| 670 | if (mMenuButton != null) { |
| 671 | mMenuButton.setOnClickListener(this); |
Yorke Lee | 36c5413 | 2013-09-25 16:17:06 -0700 | [diff] [blame] | 672 | |
| 673 | mOverflowMenu = new OverflowPopupMenu(DialtactsActivity.this, mMenuButton); |
| 674 | final Menu menu = mOverflowMenu.getMenu(); |
| 675 | mOverflowMenu.inflate(R.menu.dialtacts_options); |
| 676 | mOverflowMenu.setOnMenuItemClickListener(this); |
| 677 | mMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener()); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 680 | mFakeActionBar = findViewById(R.id.fake_action_bar); |
| 681 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 682 | mCallHistoryButton = findViewById(R.id.call_history_button); |
| 683 | // mCallHistoryButton.setMinimumWidth(fakeMenuItemWidth); |
| 684 | mCallHistoryButton.setOnClickListener(this); |
| 685 | |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 686 | mDialButton = findViewById(R.id.dial_button); |
| 687 | mDialButton.setOnClickListener(this); |
| 688 | mDialButton.setOnLongClickListener(this); |
| 689 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 690 | mDialpadButton = findViewById(R.id.dialpad_button); |
| 691 | // DialpadButton.setMinimumWidth(fakeMenuItemWidth); |
| 692 | mDialpadButton.setOnClickListener(this); |
| 693 | } |
| 694 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 695 | private void fixIntent(Intent intent) { |
| 696 | // This should be cleaned up: the call key used to send an Intent |
| 697 | // that just said to go to the recent calls list. It now sends this |
| 698 | // abstract action, but this class hasn't been rewritten to deal with it. |
| 699 | if (Intent.ACTION_CALL_BUTTON.equals(intent.getAction())) { |
| 700 | intent.setDataAndType(Calls.CONTENT_URI, Calls.CONTENT_TYPE); |
| 701 | intent.putExtra("call_key", true); |
| 702 | setIntent(intent); |
| 703 | } |
| 704 | } |
| 705 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 706 | /** |
| 707 | * Returns true if the intent is due to hitting the green send key (hardware call button: |
| 708 | * KEYCODE_CALL) while in a call. |
| 709 | * |
| 710 | * @param intent the intent that launched this activity |
| 711 | * @param recentCallsRequest true if the intent is requesting to view recent calls |
| 712 | * @return true if the intent is due to hitting the green send key while in a call |
| 713 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 714 | private boolean isSendKeyWhileInCall(Intent intent, boolean recentCallsRequest) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 715 | // If there is a call in progress go to the call screen |
| 716 | if (recentCallsRequest) { |
| 717 | final boolean callKey = intent.getBooleanExtra("call_key", false); |
| 718 | |
| 719 | try { |
| 720 | ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); |
| 721 | if (callKey && phone != null && phone.showCallScreen()) { |
| 722 | return true; |
| 723 | } |
| 724 | } catch (RemoteException e) { |
| 725 | Log.e(TAG, "Failed to handle send while in call", e); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | return false; |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * Sets the current tab based on the intent's request type |
| 734 | * |
| 735 | * @param intent Intent that contains information about which tab should be selected |
| 736 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 737 | private void displayFragment(Intent intent) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 738 | // If we got here by hitting send and we're in call forward along to the in-call activity |
| 739 | boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent.resolveType( |
| 740 | getContentResolver())); |
| 741 | if (isSendKeyWhileInCall(intent, recentCallsRequest)) { |
| 742 | finish(); |
| 743 | return; |
| 744 | } |
| 745 | |
Yorke Lee | 669b608 | 2013-09-17 15:43:38 -0700 | [diff] [blame] | 746 | if (mDialpadFragment != null) { |
| 747 | final boolean phoneIsInUse = phoneIsInUse(); |
| 748 | if (phoneIsInUse || isDialIntent(intent)) { |
| 749 | mDialpadFragment.setStartedFromNewIntent(true); |
| 750 | if (phoneIsInUse && !mDialpadFragment.isVisible()) { |
| 751 | mInCallDialpadUp = true; |
| 752 | } |
| 753 | showDialpadFragment(false); |
Yorke Lee | 35127cd | 2013-09-10 14:09:29 -0700 | [diff] [blame] | 754 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 755 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | @Override |
| 759 | public void onNewIntent(Intent newIntent) { |
| 760 | setIntent(newIntent); |
| 761 | fixIntent(newIntent); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 762 | displayFragment(newIntent); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 763 | final String action = newIntent.getAction(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 764 | |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 765 | invalidateOptionsMenu(); |
| 766 | } |
| 767 | |
| 768 | /** Returns true if the given intent contains a phone number to populate the dialer with */ |
| 769 | private boolean isDialIntent(Intent intent) { |
| 770 | final String action = intent.getAction(); |
| 771 | if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) { |
| 772 | return true; |
| 773 | } |
| 774 | if (Intent.ACTION_VIEW.equals(action)) { |
| 775 | final Uri data = intent.getData(); |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 776 | if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 777 | return true; |
| 778 | } |
| 779 | } |
| 780 | return false; |
| 781 | } |
| 782 | |
| 783 | /** |
| 784 | * Returns an appropriate call origin for this Activity. May return null when no call origin |
| 785 | * should be used (e.g. when some 3rd party application launched the screen. Call origin is |
| 786 | * for remembering the tab in which the user made a phone call, so the external app's DIAL |
| 787 | * request should not be counted.) |
| 788 | */ |
| 789 | public String getCallOrigin() { |
| 790 | return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null; |
| 791 | } |
| 792 | |
Yorke Lee | 8898cd0 | 2013-08-08 10:24:27 -0700 | [diff] [blame] | 793 | private final PhoneFavoriteFragment.Listener mPhoneFavoriteListener = |
| 794 | new PhoneFavoriteFragment.Listener() { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 795 | @Override |
| 796 | public void onContactSelected(Uri contactUri) { |
| 797 | PhoneNumberInteraction.startInteractionForPhoneCall( |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 798 | DialtactsActivity.this, contactUri, getCallOrigin()); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | @Override |
| 802 | public void onCallNumberDirectly(String phoneNumber) { |
Chiao Cheng | 9d4f3b2 | 2012-09-05 16:00:16 -0700 | [diff] [blame] | 803 | Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin()); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 804 | startActivity(intent); |
| 805 | } |
| 806 | }; |
| 807 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 808 | /* TODO krelease: This is only relevant for phones that have a hard button search key (i.e. |
| 809 | * Nexus S). Supporting it is a little more tricky because of the dialpad fragment might |
| 810 | * 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] | 811 | |
| 812 | @Override |
| 813 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
| 814 | Bundle appSearchData, boolean globalSearch) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 815 | if (mRegularSearchFragment != null && mRegularSearchFragment.isAdded() && !globalSearch) { |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 816 | if (mInSearchUi) { |
| 817 | if (mSearchView.hasFocus()) { |
| 818 | showInputMethod(mSearchView.findFocus()); |
| 819 | } else { |
| 820 | mSearchView.requestFocus(); |
| 821 | } |
| 822 | } else { |
| 823 | enterSearchUi(); |
| 824 | } |
| 825 | } else { |
| 826 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 827 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 828 | }*/ |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 829 | |
| 830 | private void showInputMethod(View view) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 831 | final InputMethodManager imm = (InputMethodManager) getSystemService( |
| 832 | Context.INPUT_METHOD_SERVICE); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 833 | if (imm != null) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 834 | imm.showSoftInput(view, 0); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | |
| 838 | private void hideInputMethod(View view) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 839 | final InputMethodManager imm = (InputMethodManager) getSystemService( |
| 840 | Context.INPUT_METHOD_SERVICE); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 841 | if (imm != null && view != null) { |
| 842 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0); |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 847 | * Shows the search fragment |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 848 | */ |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 849 | private void enterSearchUi(boolean smartDialSearch, String query) { |
Yorke Lee | 34bdf87 | 2013-08-15 14:11:50 -0700 | [diff] [blame] | 850 | if (getFragmentManager().isDestroyed()) { |
| 851 | // Weird race condition where fragment is doing work after the activity is destroyed |
| 852 | // due to talkback being on (b/10209937). Just return since we can't do any |
| 853 | // constructive here. |
| 854 | return; |
| 855 | } |
| 856 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 857 | if (DEBUG) { |
| 858 | Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch); |
| 859 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 860 | |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 861 | final FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 862 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 863 | SearchFragment fragment; |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 864 | if (mInDialpadSearch) { |
| 865 | transaction.remove(mSmartDialSearchFragment); |
| 866 | } else if (mInRegularSearch) { |
| 867 | transaction.remove(mRegularSearchFragment); |
| 868 | } else { |
| 869 | transaction.remove(mPhoneFavoriteFragment); |
| 870 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 871 | |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 872 | final String tag; |
| 873 | if (smartDialSearch) { |
| 874 | tag = TAG_SMARTDIAL_SEARCH_FRAGMENT; |
| 875 | } else { |
| 876 | tag = TAG_REGULAR_SEARCH_FRAGMENT; |
| 877 | } |
| 878 | mInDialpadSearch = smartDialSearch; |
| 879 | mInRegularSearch = !smartDialSearch; |
| 880 | |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 881 | fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag); |
| 882 | if (fragment == null) { |
| 883 | if (smartDialSearch) { |
| 884 | fragment = new SmartDialSearchFragment(); |
| 885 | } else { |
Jay Shrauner | 2e5b34b | 2013-08-29 10:52:40 -0700 | [diff] [blame] | 886 | fragment = new RegularSearchFragment(); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 887 | } |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 888 | } |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 889 | transaction.replace(R.id.dialtacts_frame, fragment, tag); |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 890 | transaction.addToBackStack(null); |
| 891 | fragment.setQueryString(query, false); |
| 892 | transaction.commit(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | /** |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 896 | * Hides the search fragment |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 897 | */ |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 898 | private void exitSearchUi() { |
Yorke Lee | 3487db7 | 2013-09-26 17:12:06 -0700 | [diff] [blame] | 899 | // See related bug in enterSearchUI(); |
| 900 | if (getFragmentManager().isDestroyed()) { |
| 901 | return; |
| 902 | } |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 903 | // Go all the way back to the favorites fragment, regardless of how many times we |
| 904 | // transitioned between search fragments |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 905 | getFragmentManager().popBackStack(0, FragmentManager.POP_BACK_STACK_INCLUSIVE); |
| 906 | setNotInSearchUi(); |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 907 | |
| 908 | if (isDialpadShowing()) { |
| 909 | mFragmentsFrame.setAlpha(0); |
| 910 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /** Returns an Intent to launch Call Settings screen */ |
| 914 | public static Intent getCallSettingsIntent() { |
| 915 | final Intent intent = new Intent(Intent.ACTION_MAIN); |
| 916 | intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME); |
| 917 | intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 918 | return intent; |
| 919 | } |
| 920 | |
| 921 | @Override |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 922 | public void onBackPressed() { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 923 | if (mDialpadFragment != null && mDialpadFragment.isVisible()) { |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 924 | hideDialpadFragment(true, false); |
Yorke Lee | b207f8a | 2013-08-29 18:51:06 -0700 | [diff] [blame] | 925 | } else if (getInSearchUi()) { |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 926 | mSearchView.setText(null); |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 927 | mDialpadFragment.clearDialpad(); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 928 | } else { |
| 929 | super.onBackPressed(); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 930 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | @Override |
| 934 | public void onDialpadQueryChanged(String query) { |
| 935 | final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query, |
| 936 | SmartDialNameMatcher.LATIN_SMART_DIAL_MAP); |
| 937 | if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) { |
Yorke Lee | ef2b738 | 2013-08-09 17:39:25 -0700 | [diff] [blame] | 938 | if (DEBUG) { |
| 939 | Log.d(TAG, "onDialpadQueryChanged - new query: " + query); |
| 940 | } |
| 941 | if (mDialpadFragment == null || !mDialpadFragment.isVisible()) { |
| 942 | // This callback can happen if the dialpad fragment is recreated because of |
| 943 | // activity destruction. In that case, don't update the search view because |
| 944 | // that would bring the user back to the search fragment regardless of the |
| 945 | // previous state of the application. Instead, just return here and let the |
| 946 | // fragment manager correctly figure out whatever fragment was last displayed. |
| 947 | return; |
| 948 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 949 | mSearchView.setText(normalizedQuery); |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 950 | } |
| 951 | } |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 952 | |
| 953 | @Override |
| 954 | public void onListFragmentScrollStateChange(int scrollState) { |
| 955 | if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { |
Yorke Lee | f6673d3 | 2013-08-23 15:34:17 -0700 | [diff] [blame] | 956 | hideDialpadFragment(true, false); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 957 | hideInputMethod(getCurrentFocus()); |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | @Override |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 962 | public void setDialButtonEnabled(boolean enabled) { |
| 963 | mDialButton.setEnabled(enabled); |
| 964 | } |
| 965 | |
| 966 | @Override |
| 967 | public void setDialButtonContainerVisible(boolean visible) { |
| 968 | mFakeActionBar.setVisibility(visible ? View.VISIBLE : View.GONE); |
Yorke Lee | c376633 | 2013-07-31 11:13:16 -0700 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | private boolean phoneIsInUse() { |
| 972 | final TelephonyManager tm = (TelephonyManager) getSystemService( |
| 973 | Context.TELEPHONY_SERVICE); |
| 974 | return tm.getCallState() != TelephonyManager.CALL_STATE_IDLE; |
| 975 | } |
Yorke Lee | 8dd6200 | 2013-08-08 15:57:20 -0700 | [diff] [blame] | 976 | |
| 977 | @Override |
| 978 | public void onShowAllContacts() { |
| 979 | final Intent intent = new Intent(this, AllContactsActivity.class); |
| 980 | startActivity(intent); |
| 981 | } |
Yorke Lee | e142481 | 2013-09-04 18:24:48 -0700 | [diff] [blame] | 982 | |
| 983 | public static Intent getAddNumberToContactIntent(CharSequence text) { |
| 984 | final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 985 | intent.putExtra(Intents.Insert.PHONE, text); |
| 986 | intent.setType(Contacts.CONTENT_ITEM_TYPE); |
| 987 | return intent; |
| 988 | } |
| 989 | |
Yorke Lee | da0f904 | 2013-12-05 14:25:51 -0800 | [diff] [blame] | 990 | private boolean canIntentBeHandled(Intent intent) { |
| 991 | final PackageManager packageManager = getPackageManager(); |
| 992 | final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, |
| 993 | PackageManager.MATCH_DEFAULT_ONLY); |
| 994 | return resolveInfo != null && resolveInfo.size() > 0; |
| 995 | } |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 996 | |
| 997 | @Override |
| 998 | public void onDragStarted(int itemIndex, int x, int y, PhoneFavoriteTileView view) { |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 999 | crossfadeViews(mRemoveViewContainer, mSearchViewContainer, ANIMATION_DURATION); |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | @Override |
| 1003 | public void onDragHovered(int itemIndex, int x, int y) {} |
| 1004 | |
| 1005 | @Override |
| 1006 | public void onDragFinished(int x, int y) { |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 1007 | crossfadeViews(mSearchViewContainer, mRemoveViewContainer, ANIMATION_DURATION); |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | @Override |
| 1011 | public void onDroppedOnRemove() {} |
| 1012 | |
| 1013 | /** |
| 1014 | * Allows the PhoneFavoriteFragment to attach the drag controller to mRemoveViewContainer |
| 1015 | * once it has been attached to the activity. |
| 1016 | */ |
| 1017 | @Override |
| 1018 | public void setDragDropController(DragDropController dragController) { |
| 1019 | mRemoveViewContainer.setDragDropController(dragController); |
| 1020 | } |
| 1021 | |
| 1022 | /** |
| 1023 | * Crossfades two views so that the first one appears while the other one is fading |
| 1024 | * out of view. |
| 1025 | */ |
| 1026 | private void crossfadeViews(final View fadeIn, final View fadeOut, int duration) { |
| 1027 | fadeOut.animate().alpha(0).setDuration(duration) |
| 1028 | .setListener(new AnimatorListenerAdapter() { |
| 1029 | @Override |
| 1030 | public void onAnimationEnd(Animator animation) { |
| 1031 | fadeOut.setVisibility(View.GONE); |
| 1032 | } |
| 1033 | }); |
| 1034 | |
| 1035 | fadeIn.setVisibility(View.VISIBLE); |
| 1036 | fadeIn.setAlpha(0); |
Yorke Lee | 7eccf45 | 2014-03-14 12:52:42 -0700 | [diff] [blame^] | 1037 | fadeIn.animate().alpha(1).setDuration(ANIMATION_DURATION) |
Yorke Lee | 3cefcc6 | 2014-01-16 11:26:46 -0800 | [diff] [blame] | 1038 | .setListener(null); |
| 1039 | } |
Ihab Awad | 526c0b8 | 2014-02-27 12:55:36 -0800 | [diff] [blame] | 1040 | |
| 1041 | private boolean shouldShowOnscreenDialButton() { |
| 1042 | return getResources().getBoolean(R.bool.config_show_onscreen_dial_button); |
| 1043 | } |
Chiao Cheng | 94b10b5 | 2012-08-17 16:59:12 -0700 | [diff] [blame] | 1044 | } |