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