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