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