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