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