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