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