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