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