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