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