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