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