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