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