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