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