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