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