blob: 6f8f341670e70458954ac7b8a58a53599c858e40 [file] [log] [blame]
Chiao Cheng94b10b52012-08-17 16:59:12 -07001/*
Yorke Leec3766332013-07-31 11:13:16 -07002 * Copyright (C) 2013 The Android Open Source Project
Chiao Cheng94b10b52012-08-17 16:59:12 -07003 *
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
17package com.android.dialer;
18
Chiao Cheng94b10b52012-08-17 16:59:12 -070019import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070020import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080021import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070022import android.content.Context;
23import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080024import android.content.pm.PackageManager;
25import android.content.pm.ResolveInfo;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070026import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070027import android.content.res.Resources;
Chiao Cheng94b10b52012-08-17 16:59:12 -070028import android.net.Uri;
29import android.os.Bundle;
Yorke Leef5554ce2015-01-27 14:46:02 -080030import android.os.Trace;
Nancy Chen019713e2015-07-06 18:25:24 -070031import android.provider.CallLog.Calls;
Yorke Leec3766332013-07-31 11:13:16 -070032import android.speech.RecognizerIntent;
Nancy Chenf3d9f822015-09-11 00:47:31 -040033import android.support.design.widget.CoordinatorLayout;
Yorke Leecc4660d2014-04-24 11:22:57 -070034import android.support.v4.view.ViewPager;
Nancy Chen44898ad2015-08-13 12:03:47 -070035import android.support.v7.app.ActionBar;
Tyler Gunn9dc924c2014-09-12 09:33:50 -070036import android.telecom.PhoneAccount;
Yorke Lee53a22302014-04-29 18:13:46 -070037import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070038import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070039import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070040import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070041import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070042import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070043import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070044import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070045import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070046import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070047import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070048import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070049import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070050import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070051import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070052import android.view.animation.AnimationUtils;
Yorke Leec3766332013-07-31 11:13:16 -070053import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070054import android.widget.EditText;
Andrew Leea73e1892014-05-13 13:21:16 -070055import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070056import android.widget.PopupMenu;
Anne Rong35208002015-07-22 16:27:37 -070057import android.widget.TextView;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080058import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070059
Yorke Leec3766332013-07-31 11:13:16 -070060import com.android.contacts.common.dialog.ClearFrequentsDialog;
61import com.android.contacts.common.interactions.ImportExportDialogFragment;
Nancy Chen0d3a7392014-08-12 14:44:53 -070062import com.android.contacts.common.interactions.TouchPointManager;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080063import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Yorke Leec16ea5a2015-05-19 15:51:01 -070064import com.android.contacts.common.util.PermissionsUtil;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070065import com.android.contacts.common.widget.FloatingActionButtonController;
Brian Attwellbeab3bb2014-10-27 12:24:49 -070066import com.android.contacts.commonbind.analytics.AnalyticsUtil;
Yorke Leec3766332013-07-31 11:13:16 -070067import com.android.dialer.calllog.CallLogActivity;
Yorke Lee38019af2015-07-14 17:05:38 -070068import com.android.dialer.calllog.CallLogFragment;
Yorke Leefce269a2013-08-12 11:56:04 -070069import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070070import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070071import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070072import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070073import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080074import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070075import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080076import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070077import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070078import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070079import com.android.dialer.list.RegularSearchFragment;
80import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070081import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070082import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070083import com.android.dialer.settings.DialerSettingsActivity;
Andrew Lee247df6e2015-05-12 19:09:00 -070084import com.android.dialer.util.IntentUtil;
Yorke Lee827a90f2015-09-17 18:10:58 -070085import com.android.dialer.util.TelecomUtil;
Yorke Leee3a2d132015-09-14 16:52:08 -070086import com.android.dialer.util.IntentUtil.CallIntentBuilder;
Yorke Lee7d20f822014-06-19 17:09:33 -070087import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070088import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070089import com.android.dialer.widget.SearchEditTextLayout;
Andrew Lee6324f702015-06-16 14:45:58 -070090import com.android.dialer.widget.SearchEditTextLayout.Callback;
Yorke Lee0baa98b2013-08-22 10:55:16 -070091import com.android.dialerbind.DatabaseHelperManager;
Yorke Leec8d6e162015-09-14 18:43:27 -070092import com.android.incallui.Call.LogState;
Yorke Lee2fec47b2014-08-05 18:16:27 -070093import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070094import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070095
Yorke Leed5c512a2015-01-30 14:42:53 -080096import junit.framework.Assert;
97
Yorke Leec3766332013-07-31 11:13:16 -070098import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080099import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -0700100
Chiao Cheng94b10b52012-08-17 16:59:12 -0700101/**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700102 * The dialer tab's title is 'phone', a more common name (see strings.xml).
103 */
Yorke Leec3766332013-07-31 11:13:16 -0700104public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700105 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700106 OnListFragmentScrolledListener,
Yorke Lee38019af2015-07-14 17:05:38 -0700107 CallLogFragment.HostInterface,
Yorke Lee575ae382015-07-16 11:36:07 -0700108 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700109 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700110 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700111 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700112 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700113 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700114 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700115 ViewPager.OnPageChangeListener,
116 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700117 private static final String TAG = "DialtactsActivity";
118
Yorke Lee7cc61492015-06-01 14:59:33 -0700119 public static final boolean DEBUG = false;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700120
Yorke Leef74011e2013-08-02 11:30:30 -0700121 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
122
Yorke Leeb207f8a2013-08-29 18:51:06 -0700123 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
124 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700125 private static final String KEY_SEARCH_QUERY = "search_query";
126 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700127 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700128
Yorke Leec3766332013-07-31 11:13:16 -0700129 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
130 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
131 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
132 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700133
Chiao Cheng94b10b52012-08-17 16:59:12 -0700134 /**
135 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
136 */
137 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
Andrew Lee75d5b2d2015-06-19 16:53:54 -0700138 public static final String EXTRA_SHOW_TAB = "EXTRA_SHOW_TAB";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700139
Yorke Leec3766332013-07-31 11:13:16 -0700140 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700141
Andrew Lee6324f702015-06-16 14:45:58 -0700142 private static final int FAB_SCALE_IN_DELAY_MS = 300;
143
Nancy Chenf3d9f822015-09-11 00:47:31 -0400144 private CoordinatorLayout mParentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700145
Yorke Leec3766332013-07-31 11:13:16 -0700146 /**
Yorke Leec3766332013-07-31 11:13:16 -0700147 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700148 */
Evan Charlton72d66252014-11-07 16:23:47 -0800149 protected DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700150
151 /**
152 * Fragment for searching phone numbers using the alphanumeric keyboard.
153 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700154 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700155
156 /**
157 * Fragment for searching phone numbers using the dialpad.
158 */
159 private SmartDialSearchFragment mSmartDialSearchFragment;
160
Yorke Leee00c9fe2014-04-12 12:42:06 -0700161 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700162 * Animation that slides in.
163 */
164 private Animation mSlideIn;
165
166 /**
167 * Animation that slides out.
168 */
169 private Animation mSlideOut;
170
Yorke Lee6c450eb2015-05-08 09:45:47 -0700171 AnimationListenerAdapter mSlideInListener = new AnimationListenerAdapter() {
172 @Override
173 public void onAnimationEnd(Animation animation) {
Yorke Lee81a313d2015-06-01 14:53:59 -0700174 maybeEnterSearchUi();
Yorke Lee6c450eb2015-05-08 09:45:47 -0700175 }
176 };
177
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700178 /**
179 * Listener for after slide out animation completes on dialer fragment.
180 */
181 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
182 @Override
183 public void onAnimationEnd(Animation animation) {
184 commitDialpadFragmentHide();
185 }
186 };
187
188 /**
Andrew Lee4de59fb2015-08-13 15:20:08 -0700189 * Fragment containing the speed dial list, call history list, and all contacts list.
Yorke Leee00c9fe2014-04-12 12:42:06 -0700190 */
191 private ListsFragment mListsFragment;
192
Yorke Lee19e68ca2014-10-28 11:51:40 -0700193 /**
194 * Tracks whether onSaveInstanceState has been called. If true, no fragment transactions can
195 * be commited.
196 */
197 private boolean mStateSaved;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800198 private boolean mIsRestarting;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700199 private boolean mInDialpadSearch;
200 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700201 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700202 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700203 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700204
Yorke Leeef2b7382013-08-09 17:39:25 -0700205 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700206 * Whether or not the device is in landscape orientation.
207 */
208 private boolean mIsLandscape;
209
210 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700211 * True if the dialpad is only temporarily showing due to being in call
212 */
213 private boolean mInCallDialpadUp;
214
215 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700216 * True when this activity has been launched for the first time.
217 */
Yorke Lee98702de2013-08-06 12:03:32 -0700218 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700219
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700220 /**
221 * Search query to be applied to the SearchView in the ActionBar once
222 * onCreateOptionsMenu has been called.
223 */
224 private String mPendingSearchViewQuery;
225
Yorke Lee74edcdc2014-07-11 16:15:08 -0700226 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700227 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700228 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700229
Yorke Leeef2b7382013-08-09 17:39:25 -0700230 private String mSearchQuery;
231
Yorke Leefce269a2013-08-12 11:56:04 -0700232 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700233 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700234 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700235
Sai Cheemalapati41460652014-06-02 21:05:39 -0700236 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700237
Andrew Lee2423a2f2014-05-29 14:14:45 -0700238 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700239
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800240 /**
241 * The text returned from a voice search query. Set in {@link #onActivityResult} and used in
242 * {@link #onResume()} to populate the search box.
243 */
244 private String mVoiceSearchQuery;
245
Andrew Lee467de3d2015-03-17 15:47:24 -0700246 protected class OptionsPopupMenu extends PopupMenu {
Andrew Leee74a10e2014-05-16 14:31:40 -0700247 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700248 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700249 }
250
251 @Override
252 public void show() {
Yorke Leec16ea5a2015-05-19 15:51:01 -0700253 final boolean hasContactsPermission =
254 PermissionsUtil.hasContactsPermissions(DialtactsActivity.this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700255 final Menu menu = getMenu();
256 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700257 clearFrequents.setVisible(mListsFragment != null &&
258 mListsFragment.getSpeedDialFragment() != null &&
Yorke Leec16ea5a2015-05-19 15:51:01 -0700259 mListsFragment.getSpeedDialFragment().hasFrequents() && hasContactsPermission);
260
261 menu.findItem(R.id.menu_import_export).setVisible(hasContactsPermission);
262 menu.findItem(R.id.menu_add_contact).setVisible(hasContactsPermission);
Yorke Leeb7330e32015-05-22 15:55:22 -0700263
264 menu.findItem(R.id.menu_history).setVisible(
265 PermissionsUtil.hasPhonePermissions(DialtactsActivity.this));
Yorke Leee00c9fe2014-04-12 12:42:06 -0700266 super.show();
267 }
268 }
269
Chiao Cheng94b10b52012-08-17 16:59:12 -0700270 /**
Yorke Lee28266192014-05-01 10:05:52 -0700271 * Listener that listens to drag events and sends their x and y coordinates to a
272 * {@link DragDropController}.
273 */
274 private class LayoutOnDragListener implements OnDragListener {
275 @Override
276 public boolean onDrag(View v, DragEvent event) {
277 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700278 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700279 }
280 return true;
281 }
282 }
283
284 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700285 * Listener used to send search queries to the phone search fragment.
286 */
Yorke Lee53a22302014-04-29 18:13:46 -0700287 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700288 @Override
289 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
290 }
Yorke Leec3766332013-07-31 11:13:16 -0700291
Andrew Lee99a570c2014-05-15 14:18:50 -0700292 @Override
293 public void onTextChanged(CharSequence s, int start, int before, int count) {
294 final String newText = s.toString();
295 if (newText.equals(mSearchQuery)) {
296 // If the query hasn't changed (perhaps due to activity being destroyed
297 // and restored, or user launching the same DIAL intent twice), then there is
298 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700299 return;
300 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700301 if (DEBUG) {
302 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700303 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700304 }
Yorke Lee710709d2014-05-29 07:18:42 -0700305 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700306
Andrew Lee90374a72014-05-16 15:01:09 -0700307 // Show search fragment only when the query string is changed to non-empty text.
308 if (!TextUtils.isEmpty(newText)) {
309 // Call enterSearchUi only if we are switching search modes, or showing a search
310 // fragment for the first time.
311 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
312 (!mIsDialpadShown && mInRegularSearch);
313 if (!sameSearchMode) {
Yorke Lee6c450eb2015-05-08 09:45:47 -0700314 enterSearchUi(mIsDialpadShown, mSearchQuery, true /* animate */);
Andrew Lee90374a72014-05-16 15:01:09 -0700315 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700316 }
317
Andrew Leea8515422014-06-13 16:53:54 -0700318 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700319 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700320 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700321 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700322 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700323 }
324
325 @Override
326 public void afterTextChanged(Editable s) {
327 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700328 };
329
Andrew Leeb1903842014-05-15 16:11:24 -0700330
331 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700332 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700333 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700334 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700335 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700336 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700337 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700338 mActionBarController.onSearchBoxTapped();
Yorke Lee6c450eb2015-05-08 09:45:47 -0700339 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString(),
340 true /* animate */);
Andrew Leeb1903842014-05-15 16:11:24 -0700341 }
Andrew Leeb1903842014-05-15 16:11:24 -0700342 }
343 };
344
345 /**
Andrew Lee6324f702015-06-16 14:45:58 -0700346 * Handles the user closing the soft keyboard.
Andrew Leeb1903842014-05-15 16:11:24 -0700347 */
348 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
349 @Override
350 public boolean onKey(View v, int keyCode, KeyEvent event) {
Andrew Lee6324f702015-06-16 14:45:58 -0700351 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
352 if (TextUtils.isEmpty(mSearchView.getText().toString())) {
353 // If the search term is empty, close the search UI.
354 maybeExitSearchUi();
355 } else {
356 // If the search term is not empty, show the dialpad fab.
357 showFabInSearchUi();
358 }
Andrew Leeb1903842014-05-15 16:11:24 -0700359 }
360 return false;
361 }
362 };
363
Chiao Cheng94b10b52012-08-17 16:59:12 -0700364 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700365 public boolean dispatchTouchEvent(MotionEvent ev) {
366 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
367 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
368 }
369 return super.dispatchTouchEvent(ev);
Nancy Chen49db1ad2014-08-18 20:10:17 -0700370 }
371
372 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700373 protected void onCreate(Bundle savedInstanceState) {
Yorke Leef5554ce2015-01-27 14:46:02 -0800374 Trace.beginSection(TAG + " onCreate");
Yorke Leec3766332013-07-31 11:13:16 -0700375 super.onCreate(savedInstanceState);
Yorke Leec16ea5a2015-05-19 15:51:01 -0700376
Yorke Lee98702de2013-08-06 12:03:32 -0700377 mFirstLaunch = true;
378
Andrew Lee2423a2f2014-05-29 14:14:45 -0700379 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700380 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700381
Yorke Leef5554ce2015-01-27 14:46:02 -0800382 Trace.beginSection(TAG + " setContentView");
Yorke Lee8898cd02013-08-08 10:24:27 -0700383 setContentView(R.layout.dialtacts_activity);
Yorke Leef5554ce2015-01-27 14:46:02 -0800384 Trace.endSection();
Yorke Lee9e91bb02014-03-05 17:50:50 -0800385 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700386
Yorke Leef5554ce2015-01-27 14:46:02 -0800387 Trace.beginSection(TAG + " setup Views");
Nancy Chen44898ad2015-08-13 12:03:47 -0700388 final ActionBar actionBar = getSupportActionBar();
Yorke Lee53a22302014-04-29 18:13:46 -0700389 actionBar.setCustomView(R.layout.search_edittext);
390 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700391 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700392
Anne Rong35208002015-07-22 16:27:37 -0700393 SearchEditTextLayout searchEditTextLayout = (SearchEditTextLayout) actionBar
394 .getCustomView().findViewById(R.id.search_view_container);
Andrew Lee04675a52014-06-05 18:36:20 -0700395 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
396
Andrew Leee3f59a82015-02-26 12:06:35 -0800397 mActionBarController = new ActionBarController(this, searchEditTextLayout);
398
Andrew Lee04675a52014-06-05 18:36:20 -0700399 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700400 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700401 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
402 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
403 .setOnClickListener(mSearchViewOnClickListener);
404 searchEditTextLayout.findViewById(R.id.search_box_start_search)
405 .setOnClickListener(mSearchViewOnClickListener);
Yorke Lee7a6f1892015-06-27 13:21:48 -0700406 searchEditTextLayout.setOnClickListener(mSearchViewOnClickListener);
Andrew Lee6324f702015-06-16 14:45:58 -0700407 searchEditTextLayout.setCallback(new SearchEditTextLayout.Callback() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700408 @Override
409 public void onBackButtonClicked() {
410 onBackPressed();
411 }
Andrew Lee6324f702015-06-16 14:45:58 -0700412
413 @Override
414 public void onSearchViewClicked() {
415 // Hide FAB, as the keyboard is shown.
416 mFloatingActionButtonController.scaleOut();
417 }
Yorke Lee11ca39e2014-05-19 20:31:37 -0700418 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700419
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700420 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700421 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700422
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700423 final View floatingActionButtonContainer = findViewById(
424 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700425 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
426 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700427 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700428 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700429
Andrew Lee04675a52014-06-05 18:36:20 -0700430 ImageButton optionsMenuButton =
431 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700432 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700433 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
434 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700435
Yorke Leed5c512a2015-01-30 14:42:53 -0800436 // Add the favorites fragment but only if savedInstanceState is null. Otherwise the
437 // fragment manager is responsible for recreating it.
Yorke Leec3766332013-07-31 11:13:16 -0700438 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800439 getFragmentManager().beginTransaction()
Andrew Lee6a866242015-05-05 18:21:45 +0000440 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800441 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700442 } else {
443 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700444 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
445 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700446 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700447 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700448 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700449 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700450
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700451 final boolean isLayoutRtl = DialerUtils.isRtl();
452 if (mIsLandscape) {
453 mSlideIn = AnimationUtils.loadAnimation(this,
454 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
455 mSlideOut = AnimationUtils.loadAnimation(this,
456 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
457 } else {
458 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
459 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
460 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700461
Yorke Lee2fec47b2014-08-05 18:16:27 -0700462 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
463 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
464
Yorke Lee6c450eb2015-05-08 09:45:47 -0700465 mSlideIn.setAnimationListener(mSlideInListener);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700466 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700467
Nancy Chenf3d9f822015-09-11 00:47:31 -0400468 mParentLayout = (CoordinatorLayout) findViewById(R.id.dialtacts_mainlayout);
Yorke Leef614f6f2014-10-03 10:44:19 -0700469 mParentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700470 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700471 new ViewTreeObserver.OnGlobalLayoutListener() {
472 @Override
473 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700474 final ViewTreeObserver observer =
475 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700476 if (!observer.isAlive()) {
477 return;
478 }
479 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700480 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700481 mFloatingActionButtonController.setScreenWidth(screenWidth);
Andrew Lee6324f702015-06-16 14:45:58 -0700482 mFloatingActionButtonController.align(
483 getFabAlignment(), false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700484 }
485 });
Andrew Lee0c667702014-05-12 14:31:45 -0700486
Yorke Leef5554ce2015-01-27 14:46:02 -0800487 Trace.endSection();
488
489 Trace.beginSection(TAG + " initialize smart dialing");
Yorke Lee0baa98b2013-08-22 10:55:16 -0700490 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700491 SmartDialPrefix.initializeNanpSettings(this);
Yorke Leef5554ce2015-01-27 14:46:02 -0800492 Trace.endSection();
493 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700494 }
495
496 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700497 protected void onResume() {
Yorke Leef5554ce2015-01-27 14:46:02 -0800498 Trace.beginSection(TAG + " onResume");
Yorke Leec3766332013-07-31 11:13:16 -0700499 super.onResume();
Yorke Lee2a613022015-07-01 14:28:13 -0700500
Yorke Lee19e68ca2014-10-28 11:51:40 -0700501 mStateSaved = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700502 if (mFirstLaunch) {
503 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700504 } else if (!phoneIsInUse() && mInCallDialpadUp) {
505 hideDialpadFragment(false, true);
506 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700507 } else if (mShowDialpadOnResume) {
508 showDialpadFragment(false);
509 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700510 }
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800511
512 // If there was a voice query result returned in the {@link #onActivityResult} callback, it
513 // will have been stashed in mVoiceSearchQuery since the search results fragment cannot be
514 // shown until onResume has completed. Active the search UI and set the search term now.
515 if (!TextUtils.isEmpty(mVoiceSearchQuery)) {
516 mActionBarController.onSearchBoxTapped();
517 mSearchView.setText(mVoiceSearchQuery);
518 mVoiceSearchQuery = null;
519 }
520
Yorke Lee98702de2013-08-06 12:03:32 -0700521 mFirstLaunch = false;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800522
523 if (mIsRestarting) {
524 // This is only called when the activity goes from resumed -> paused -> resumed, so it
525 // will not cause an extra view to be sent out on rotation
526 if (mIsDialpadShown) {
527 AnalyticsUtil.sendScreenView(mDialpadFragment, this);
528 }
529 mIsRestarting = false;
530 }
Andrew Lee75d5b2d2015-06-19 16:53:54 -0700531
Yorke Lee53a22302014-04-29 18:13:46 -0700532 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700533 mDialerDatabaseHelper.startSmartDialUpdateThread();
Andrew Lee6324f702015-06-16 14:45:58 -0700534 mFloatingActionButtonController.align(getFabAlignment(), false /* animate */);
Nancy Chend5de03b2015-07-01 09:20:45 -0700535
Yorke Lee49aa5bf2015-09-10 15:53:43 -0700536 if (Calls.CONTENT_TYPE.equals(getIntent().getType())) {
537 // Externally specified extras take precedence to EXTRA_SHOW_TAB, which is only
538 // used internally.
539 final Bundle extras = getIntent().getExtras();
540 if (extras != null
541 && extras.getInt(Calls.EXTRA_CALL_TYPE_FILTER) == Calls.VOICEMAIL_TYPE) {
542 mListsFragment.showTab(ListsFragment.TAB_INDEX_VOICEMAIL);
543 } else {
544 mListsFragment.showTab(ListsFragment.TAB_INDEX_HISTORY);
545 }
546 } else if (getIntent().hasExtra(EXTRA_SHOW_TAB)) {
Nancy Chend5de03b2015-07-01 09:20:45 -0700547 int index = getIntent().getIntExtra(EXTRA_SHOW_TAB, ListsFragment.TAB_INDEX_SPEED_DIAL);
548 if (index < mListsFragment.getTabCount()) {
549 mListsFragment.showTab(index);
550 }
551 }
552
Anne Rong35208002015-07-22 16:27:37 -0700553 setSearchBoxHint();
554
Yorke Leef5554ce2015-01-27 14:46:02 -0800555 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700556 }
557
558 @Override
Yorke Lee7ee5c422014-11-04 10:29:32 -0800559 protected void onRestart() {
560 super.onRestart();
561 mIsRestarting = true;
562 }
563
564 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700565 protected void onPause() {
566 if (mClearSearchOnPause) {
567 hideDialpadAndSearchUi();
568 mClearSearchOnPause = false;
569 }
Yorke Lee19e68ca2014-10-28 11:51:40 -0700570 if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) {
571 commitDialpadFragmentHide();
572 }
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700573 super.onPause();
574 }
575
576 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700577 protected void onSaveInstanceState(Bundle outState) {
578 super.onSaveInstanceState(outState);
579 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700580 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
581 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700582 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700583 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700584 mActionBarController.saveInstanceState(outState);
Yorke Lee19e68ca2014-10-28 11:51:40 -0700585 mStateSaved = true;
Yorke Leeef2b7382013-08-09 17:39:25 -0700586 }
587
588 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700589 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700590 if (fragment instanceof DialpadFragment) {
591 mDialpadFragment = (DialpadFragment) fragment;
Yorke Leed5c512a2015-01-30 14:42:53 -0800592 if (!mIsDialpadShown && !mShowDialpadOnResume) {
Yorke Lee50aba882014-05-28 20:04:31 -0700593 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
594 transaction.hide(mDialpadFragment);
595 transaction.commit();
596 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700597 } else if (fragment instanceof SmartDialSearchFragment) {
598 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700599 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700600 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700601 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700602 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700603 } else if (fragment instanceof ListsFragment) {
604 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700605 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700606 }
Yorke Leec3766332013-07-31 11:13:16 -0700607 }
608
Alon Albertb453e5b2013-09-10 15:54:23 -0700609 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700610 final Intent intent = new Intent(this, DialerSettingsActivity.class);
611 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700612 }
613
Chiao Cheng94b10b52012-08-17 16:59:12 -0700614 @Override
615 public void onClick(View view) {
616 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700617 case R.id.floating_action_button:
Yorke Leedeab5c52015-07-27 17:03:11 -0700618 if (mListsFragment.getCurrentTabIndex()
619 == ListsFragment.TAB_INDEX_ALL_CONTACTS && !mInRegularSearch) {
Andrew Lee247df6e2015-05-12 19:09:00 -0700620 DialerUtils.startActivityWithErrorToast(
621 this,
622 IntentUtil.getNewContactIntent(),
623 R.string.add_contact_not_available);
Andrew Leefdfeaaf2015-05-05 14:10:35 -0700624 } else if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700625 mInCallDialpadUp = false;
626 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700627 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700628 break;
Yorke Leec3766332013-07-31 11:13:16 -0700629 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800630 try {
631 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
632 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
633 } catch (ActivityNotFoundException e) {
634 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
635 Toast.LENGTH_SHORT).show();
636 }
Yorke Leec3766332013-07-31 11:13:16 -0700637 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700638 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700639 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700640 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700641 default: {
642 Log.wtf(TAG, "Unexpected onClick event from " + view);
643 break;
644 }
645 }
646 }
647
Yorke Leec3766332013-07-31 11:13:16 -0700648 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700649 public boolean onMenuItemClick(MenuItem item) {
Jay Shrauner193cfc52015-09-25 14:13:16 -0700650 if (!isSafeToCommitTransactions()) {
Jay Shrauner119b0652015-09-17 12:00:18 -0700651 return true;
652 }
653
Yorke Lee86e21f72014-04-02 16:49:38 -0700654 switch (item.getItemId()) {
655 case R.id.menu_history:
Andrew Lee69705be2015-05-04 17:24:01 -0700656 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
657 // CONTENT_TYPE, so that we always open our call log from our dialer
658 final Intent intent = new Intent(this, CallLogActivity.class);
659 startActivity(intent);
Yorke Lee86e21f72014-04-02 16:49:38 -0700660 break;
661 case R.id.menu_add_contact:
Andrew Lee247df6e2015-05-12 19:09:00 -0700662 DialerUtils.startActivityWithErrorToast(
663 this,
664 IntentUtil.getNewContactIntent(),
665 R.string.add_contact_not_available);
Yorke Lee86e21f72014-04-02 16:49:38 -0700666 break;
667 case R.id.menu_import_export:
668 // We hard-code the "contactsAreAvailable" argument because doing it properly would
669 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
670 // now in Dialtacts for (potential) performance reasons. Compare with how it is
671 // done in {@link PeopleActivity}.
Wenyi Wang5953e8c2015-09-24 15:38:14 -0700672 if (mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) {
673 ImportExportDialogFragment.show(getFragmentManager(), true,
674 DialtactsActivity.class, ImportExportDialogFragment.EXPORT_MODE_FAVORITES);
675 } else {
676 ImportExportDialogFragment.show(getFragmentManager(), true,
677 DialtactsActivity.class, ImportExportDialogFragment.EXPORT_MODE_DEFAULT);
678 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700679 return true;
680 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700681 ClearFrequentsDialog.show(getFragmentManager());
682 return true;
683 case R.id.menu_call_settings:
684 handleMenuSettings();
685 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700686 }
687 return false;
688 }
689
690 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700691 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
692 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
693 if (resultCode == RESULT_OK) {
694 final ArrayList<String> matches = data.getStringArrayListExtra(
695 RecognizerIntent.EXTRA_RESULTS);
696 if (matches.size() > 0) {
697 final String match = matches.get(0);
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800698 mVoiceSearchQuery = match;
Yorke Leec3766332013-07-31 11:13:16 -0700699 } else {
700 Log.e(TAG, "Voice search - nothing heard");
701 }
702 } else {
703 Log.e(TAG, "Voice search failed");
704 }
705 }
706 super.onActivityResult(requestCode, resultCode, data);
707 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700708
Andrew Lee2a58ab82014-05-15 02:16:04 -0700709 /**
Nancy Chenea7c0b82015-08-31 17:18:41 -0700710 * Update the number of unread voicemails (potentially other tabs) displayed next to the tab
711 * icon.
712 */
713 public void updateTabUnreadCounts() {
714 mListsFragment.updateTabUnreadCounts();
715 }
716
717 /**
Andrew Lee2a58ab82014-05-15 02:16:04 -0700718 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
719 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
720 * @see #onDialpadShown
721 */
Yorke Leec3766332013-07-31 11:13:16 -0700722 private void showDialpadFragment(boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700723 if (mIsDialpadShown || mStateSaved) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700724 return;
725 }
726 mIsDialpadShown = true;
Yorke Leed5c512a2015-01-30 14:42:53 -0800727
Yorke Lee7ee5c422014-11-04 10:29:32 -0800728 mListsFragment.setUserVisibleHint(false);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700729
Chiao Cheng94b10b52012-08-17 16:59:12 -0700730 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leed5c512a2015-01-30 14:42:53 -0800731 if (mDialpadFragment == null) {
732 mDialpadFragment = new DialpadFragment();
733 ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT);
734 } else {
735 ft.show(mDialpadFragment);
736 }
737
738 mDialpadFragment.setAnimate(animate);
739 AnalyticsUtil.sendScreenView(mDialpadFragment);
Yorke Leec3766332013-07-31 11:13:16 -0700740 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700741
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700742 if (animate) {
743 mFloatingActionButtonController.scaleOut();
744 } else {
745 mFloatingActionButtonController.setVisible(false);
Yorke Lee81a313d2015-06-01 14:53:59 -0700746 maybeEnterSearchUi();
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700747 }
Yorke Lee5253be02014-05-21 18:50:03 -0700748 mActionBarController.onDialpadUp();
749
Yorke Lee6c450eb2015-05-08 09:45:47 -0700750 mListsFragment.getView().animate().alpha(0).withLayer();
Yorke Leec3766332013-07-31 11:13:16 -0700751 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700752
Andrew Lee2a58ab82014-05-15 02:16:04 -0700753 /**
754 * Callback from child DialpadFragment when the dialpad is shown.
755 */
756 public void onDialpadShown() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800757 Assert.assertNotNull(mDialpadFragment);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700758 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700759 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700760 } else {
761 mDialpadFragment.setYFraction(0);
762 }
763
Andrew Lee2a58ab82014-05-15 02:16:04 -0700764 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700765 }
766
767 /**
768 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
769 * a callback after the hide animation ends.
770 * @see #commitDialpadFragmentHide
771 */
Yorke Leeca195042013-09-25 16:29:38 -0700772 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Yorke Lee791b4882015-05-15 10:52:27 -0700773 if (mDialpadFragment == null || mDialpadFragment.getView() == null) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700774 return;
775 }
Yorke Leef6673d32013-08-23 15:34:17 -0700776 if (clearDialpad) {
777 mDialpadFragment.clearDialpad();
778 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700779 if (!mIsDialpadShown) {
780 return;
Yorke Leec3766332013-07-31 11:13:16 -0700781 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700782 mIsDialpadShown = false;
783 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800784 mListsFragment.setUserVisibleHint(true);
785 mListsFragment.sendScreenViewForCurrentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700786
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700787 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700788
Andrew Lee6324f702015-06-16 14:45:58 -0700789 mFloatingActionButtonController.align(getFabAlignment(), animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700790 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700791 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700792 } else {
793 commitDialpadFragmentHide();
794 }
795
Yorke Lee5253be02014-05-21 18:50:03 -0700796 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700797
Andrew Leed4cde832014-05-16 15:56:48 -0700798 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700799 if (TextUtils.isEmpty(mSearchQuery)) {
800 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700801 }
Andrew Leed4cde832014-05-16 15:56:48 -0700802 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700803 }
804
805 /**
806 * Finishes hiding the dialpad fragment after any animations are completed.
807 */
808 private void commitDialpadFragmentHide() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800809 if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700810 final FragmentTransaction ft = getFragmentManager().beginTransaction();
811 ft.hide(mDialpadFragment);
812 ft.commit();
813 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700814 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700815 }
816
Andrew Lee2a58ab82014-05-15 02:16:04 -0700817 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700818 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700819 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700820 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700821 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700822 fragment = mRegularSearchFragment;
823 }
824 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700825 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700826 }
827 }
828
Yorke Lee5253be02014-05-21 18:50:03 -0700829 @Override
830 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700831 return mInDialpadSearch || mInRegularSearch;
832 }
833
Yorke Lee5253be02014-05-21 18:50:03 -0700834 @Override
835 public boolean hasSearchQuery() {
836 return !TextUtils.isEmpty(mSearchQuery);
837 }
838
839 @Override
840 public boolean shouldShowActionBar() {
841 return mListsFragment.shouldShowActionBar();
842 }
843
Yorke Leeb207f8a2013-08-29 18:51:06 -0700844 private void setNotInSearchUi() {
845 mInDialpadSearch = false;
846 mInRegularSearch = false;
847 }
848
Yorke Lee311969c2013-08-26 06:31:11 -0700849 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700850 if (mIsDialpadShown) {
851 hideDialpadFragment(false, true);
852 } else {
853 exitSearchUi();
854 }
Yorke Lee311969c2013-08-26 06:31:11 -0700855 }
856
Yorke Lee53a22302014-04-29 18:13:46 -0700857 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700858 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
859 if (canIntentBeHandled(voiceIntent)) {
860 mVoiceSearchButton.setVisibility(View.VISIBLE);
861 mVoiceSearchButton.setOnClickListener(this);
862 } else {
863 mVoiceSearchButton.setVisibility(View.GONE);
864 }
865 }
866
Anne Rong35208002015-07-22 16:27:37 -0700867 protected int getSearchBoxHint () {
868 return R.string.dialer_hint_find_contact;
869 }
870
871 /**
872 * Sets the hint text for the contacts search box
873 */
874 private void setSearchBoxHint() {
Nancy Chen44898ad2015-08-13 12:03:47 -0700875 SearchEditTextLayout searchEditTextLayout = (SearchEditTextLayout) getSupportActionBar()
Anne Rong35208002015-07-22 16:27:37 -0700876 .getCustomView().findViewById(R.id.search_view_container);
877 ((TextView) searchEditTextLayout.findViewById(R.id.search_box_start_search))
878 .setHint(getSearchBoxHint());
879 }
880
Andrew Lee467de3d2015-03-17 15:47:24 -0700881 protected OptionsPopupMenu buildOptionsMenu(View invoker) {
Andrew Leee74a10e2014-05-16 14:31:40 -0700882 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
883 popupMenu.inflate(R.menu.dialtacts_options);
884 popupMenu.setOnMenuItemClickListener(this);
885 return popupMenu;
886 }
887
Yorke Lee86e21f72014-04-02 16:49:38 -0700888 @Override
889 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700890 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700891 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700892 mPendingSearchViewQuery = null;
893 }
Yorke Leec16ea5a2015-05-19 15:51:01 -0700894 if (mActionBarController != null) {
895 mActionBarController.restoreActionBarOffset();
896 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700897 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700898 }
899
Chiao Cheng94b10b52012-08-17 16:59:12 -0700900 /**
901 * Returns true if the intent is due to hitting the green send key (hardware call button:
902 * KEYCODE_CALL) while in a call.
903 *
904 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700905 * @return true if the intent is due to hitting the green send key while in a call
906 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700907 private boolean isSendKeyWhileInCall(Intent intent) {
908 // If there is a call in progress and the user launched the dialer by hitting the call
909 // button, go straight to the in-call screen.
910 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700911
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700912 if (callKey) {
Yorke Lee762b3572015-09-18 12:54:59 -0700913 TelecomUtil.showInCallScreen(this, false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700914 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700915 }
916
917 return false;
918 }
919
920 /**
921 * Sets the current tab based on the intent's request type
922 *
923 * @param intent Intent that contains information about which tab should be selected
924 */
Yorke Leec3766332013-07-31 11:13:16 -0700925 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700926 // If we got here by hitting send and we're in call forward along to the in-call activity
Yorke Lee62e995c2014-03-28 10:02:56 -0700927 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700928 finish();
929 return;
930 }
931
Yorke Leed77017d2015-08-31 16:19:43 -0700932 final boolean showDialpadChooser = phoneIsInUse() && !DialpadFragment.isAddCallMode(intent);
933 if (showDialpadChooser || (intent.getData() != null && isDialIntent(intent))) {
Yorke Leed5c512a2015-01-30 14:42:53 -0800934 showDialpadFragment(false);
935 mDialpadFragment.setStartedFromNewIntent(true);
Yorke Leed77017d2015-08-31 16:19:43 -0700936 if (showDialpadChooser && !mDialpadFragment.isVisible()) {
Yorke Leed5c512a2015-01-30 14:42:53 -0800937 mInCallDialpadUp = true;
Yorke Lee35127cd2013-09-10 14:09:29 -0700938 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700939 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700940 }
941
942 @Override
943 public void onNewIntent(Intent newIntent) {
944 setIntent(newIntent);
Yorke Lee24d034f2015-07-01 12:34:50 -0700945
Nancy Chen199b7f02014-11-05 15:03:00 -0800946 mStateSaved = false;
Yorke Leec3766332013-07-31 11:13:16 -0700947 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700948
Chiao Cheng94b10b52012-08-17 16:59:12 -0700949 invalidateOptionsMenu();
950 }
951
952 /** Returns true if the given intent contains a phone number to populate the dialer with */
953 private boolean isDialIntent(Intent intent) {
954 final String action = intent.getAction();
955 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
956 return true;
957 }
958 if (Intent.ACTION_VIEW.equals(action)) {
959 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700960 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700961 return true;
962 }
963 }
964 return false;
965 }
966
967 /**
Yorke Leec3766332013-07-31 11:13:16 -0700968 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700969 */
Yorke Lee6c450eb2015-05-08 09:45:47 -0700970 private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700971 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700972 // Weird race condition where fragment is doing work after the activity is destroyed
973 // due to talkback being on (b/10209937). Just return since we can't do any
974 // constructive here.
975 return;
976 }
977
Yorke Leeef2b7382013-08-09 17:39:25 -0700978 if (DEBUG) {
979 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
980 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700981
Yorke Leec3766332013-07-31 11:13:16 -0700982 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700983 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700984 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700985 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700986 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700987 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700988
Yorke Leeb207f8a2013-08-29 18:51:06 -0700989 final String tag;
990 if (smartDialSearch) {
991 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
992 } else {
993 tag = TAG_REGULAR_SEARCH_FRAGMENT;
994 }
995 mInDialpadSearch = smartDialSearch;
996 mInRegularSearch = !smartDialSearch;
997
Andrew Lee6324f702015-06-16 14:45:58 -0700998 mFloatingActionButtonController.scaleOut();
999
Andrew Lee752956e2014-05-15 11:43:38 -07001000 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Yorke Lee6c450eb2015-05-08 09:45:47 -07001001 if (animate) {
1002 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
1003 } else {
1004 transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
1005 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001006 if (fragment == null) {
1007 if (smartDialSearch) {
1008 fragment = new SmartDialSearchFragment();
1009 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -07001010 fragment = new RegularSearchFragment();
Andrew Lee6324f702015-06-16 14:45:58 -07001011 fragment.setOnTouchListener(new View.OnTouchListener() {
1012 @Override
1013 public boolean onTouch(View v, MotionEvent event) {
1014 // Show the FAB when the user touches the lists fragment and the soft
1015 // keyboard is hidden.
1016 showFabInSearchUi();
1017 return false;
1018 }
1019 });
Yorke Leeef2b7382013-08-09 17:39:25 -07001020 }
Andrew Leeb1903842014-05-15 16:11:24 -07001021 transaction.add(R.id.dialtacts_frame, fragment, tag);
1022 } else {
1023 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -07001024 }
Yorke Lee86e21f72014-04-02 16:49:38 -07001025 // DialtactsActivity will provide the options menu
1026 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -07001027 fragment.setShowEmptyListForNullQuery(true);
Yorke Lee6c450eb2015-05-08 09:45:47 -07001028 if (!smartDialSearch) {
1029 fragment.setQueryString(query, false /* delaySelection */);
1030 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001031 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -07001032
Yorke Lee6c450eb2015-05-08 09:45:47 -07001033 if (animate) {
1034 mListsFragment.getView().animate().alpha(0).withLayer();
1035 }
Yorke Lee7ee5c422014-11-04 10:29:32 -08001036 mListsFragment.setUserVisibleHint(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001037 }
1038
1039 /**
Yorke Leec3766332013-07-31 11:13:16 -07001040 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -07001041 */
Yorke Leec3766332013-07-31 11:13:16 -07001042 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -07001043 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -07001044 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -07001045 return;
1046 }
Andrew Leeb1903842014-05-15 16:11:24 -07001047
Andrew Leeb1903842014-05-15 16:11:24 -07001048 mSearchView.setText(null);
Yorke Leed5c512a2015-01-30 14:42:53 -08001049
1050 if (mDialpadFragment != null) {
1051 mDialpadFragment.clearDialpad();
1052 }
1053
Yorke Leeb207f8a2013-08-29 18:51:06 -07001054 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -07001055
Andrew Lee6324f702015-06-16 14:45:58 -07001056 // Restore the FAB for the lists fragment.
1057 if (getFabAlignment() != FloatingActionButtonController.ALIGN_END) {
1058 mFloatingActionButtonController.setVisible(false);
1059 }
1060 mFloatingActionButtonController.scaleIn(FAB_SCALE_IN_DELAY_MS);
1061 onPageScrolled(mListsFragment.getCurrentTabIndex(), 0 /* offset */, 0 /* pixelOffset */);
1062 onPageSelected(mListsFragment.getCurrentTabIndex());
1063
Andrew Leeb1903842014-05-15 16:11:24 -07001064 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -07001065 if (mSmartDialSearchFragment != null) {
1066 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -07001067 }
Andrew Leeb1903842014-05-15 16:11:24 -07001068 if (mRegularSearchFragment != null) {
1069 transaction.remove(mRegularSearchFragment);
1070 }
1071 transaction.commit();
1072
1073 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Leed5c512a2015-01-30 14:42:53 -08001074
1075 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
Yorke Lee7ee5c422014-11-04 10:29:32 -08001076 // If the dialpad fragment wasn't previously visible, then send a screen view because
1077 // we are exiting regular search. Otherwise, the screen view will be sent by
1078 // {@link #hideDialpadFragment}.
1079 mListsFragment.sendScreenViewForCurrentPosition();
1080 mListsFragment.setUserVisibleHint(true);
1081 }
1082
Yorke Lee5253be02014-05-21 18:50:03 -07001083 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001084 }
1085
Chiao Cheng94b10b52012-08-17 16:59:12 -07001086 @Override
Yorke Leec3766332013-07-31 11:13:16 -07001087 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -07001088 if (mStateSaved) {
1089 return;
1090 }
Andrew Lee2a58ab82014-05-15 02:16:04 -07001091 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -07001092 if (TextUtils.isEmpty(mSearchQuery) ||
1093 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
1094 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -07001095 exitSearchUi();
1096 }
Yorke Leef6673d32013-08-23 15:34:17 -07001097 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -07001098 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -07001099 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001100 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001101 } else {
1102 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001103 }
Yorke Leec3766332013-07-31 11:13:16 -07001104 }
1105
Yorke Lee81a313d2015-06-01 14:53:59 -07001106 private void maybeEnterSearchUi() {
1107 if (!isInSearchUi()) {
1108 enterSearchUi(true /* isSmartDial */, mSearchQuery, false);
1109 }
1110 }
1111
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001112 /**
1113 * @return True if the search UI was exited, false otherwise
1114 */
1115 private boolean maybeExitSearchUi() {
1116 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
1117 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001118 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001119 return true;
1120 }
1121 return false;
1122 }
1123
Andrew Lee6324f702015-06-16 14:45:58 -07001124 private void showFabInSearchUi() {
1125 mFloatingActionButtonController.changeIcon(
1126 getResources().getDrawable(R.drawable.fab_ic_dial),
1127 getResources().getString(R.string.action_menu_dialpad_button));
1128 mFloatingActionButtonController.align(getFabAlignment(), false /* animate */);
1129 mFloatingActionButtonController.scaleIn(FAB_SCALE_IN_DELAY_MS);
1130 }
1131
Yorke Leec3766332013-07-31 11:13:16 -07001132 @Override
1133 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -07001134 if (mSmartDialSearchFragment != null) {
1135 mSmartDialSearchFragment.setAddToContactNumber(query);
1136 }
Yorke Leec3766332013-07-31 11:13:16 -07001137 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
1138 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -07001139
1140 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001141 if (DEBUG) {
1142 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1143 }
1144 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1145 // This callback can happen if the dialpad fragment is recreated because of
1146 // activity destruction. In that case, don't update the search view because
1147 // that would bring the user back to the search fragment regardless of the
1148 // previous state of the application. Instead, just return here and let the
1149 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001150 if (!TextUtils.isEmpty(normalizedQuery)) {
1151 mPendingSearchViewQuery = normalizedQuery;
1152 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001153 return;
1154 }
Yorke Lee53a22302014-04-29 18:13:46 -07001155 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001156 }
Santos Cordon83131712015-04-16 21:25:35 -07001157
1158 try {
1159 if (mDialpadFragment != null && mDialpadFragment.isVisible()) {
1160 mDialpadFragment.process_quote_emergency_unquote(normalizedQuery);
1161 }
1162 } catch (Exception ignored) {
1163 // Skip any exceptions for this piece of code
1164 }
Yorke Lee575ae382015-07-16 11:36:07 -07001165 }
Santos Cordon83131712015-04-16 21:25:35 -07001166
Yorke Lee575ae382015-07-16 11:36:07 -07001167 @Override
1168 public boolean onDialpadSpacerTouchWithEmptyQuery() {
1169 if (mInDialpadSearch && mSmartDialSearchFragment != null
1170 && !mSmartDialSearchFragment.isShowingPermissionRequest()) {
1171 hideDialpadFragment(true /* animate */, true /* clearDialpad */);
1172 return true;
1173 }
1174 return false;
Chiao Cheng94b10b52012-08-17 16:59:12 -07001175 }
Yorke Leec3766332013-07-31 11:13:16 -07001176
1177 @Override
1178 public void onListFragmentScrollStateChange(int scrollState) {
1179 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001180 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -07001181 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001182 }
1183 }
1184
1185 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001186 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001187 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001188 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1189 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001190 }
1191
Yorke Leec3766332013-07-31 11:13:16 -07001192 private boolean phoneIsInUse() {
Yorke Lee827a90f2015-09-17 18:10:58 -07001193 return TelecomUtil.isInCall(this);
Yorke Leec3766332013-07-31 11:13:16 -07001194 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001195
Yorke Leeda0f9042013-12-05 14:25:51 -08001196 private boolean canIntentBeHandled(Intent intent) {
1197 final PackageManager packageManager = getPackageManager();
1198 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1199 PackageManager.MATCH_DEFAULT_ONLY);
1200 return resolveInfo != null && resolveInfo.size() > 0;
1201 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001202
Yorke Lee86e21f72014-04-02 16:49:38 -07001203 /**
1204 * Called when the user has long-pressed a contact tile to start a drag operation.
1205 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001206 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001207 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Lee18963442014-06-06 17:20:13 -07001208 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001209 }
1210
1211 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001212 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1213 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001214
Yorke Lee86e21f72014-04-02 16:49:38 -07001215 /**
1216 * Called when the user has released a contact tile after long-pressing it.
1217 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001218 @Override
1219 public void onDragFinished(int x, int y) {
Andrew Lee18963442014-06-06 17:20:13 -07001220 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001221 }
1222
1223 @Override
1224 public void onDroppedOnRemove() {}
1225
1226 /**
Yorke Leed999b712014-04-23 15:10:58 -07001227 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001228 * once it has been attached to the activity.
1229 */
1230 @Override
1231 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001232 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001233 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001234 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001235
Yorke Lee38019af2015-07-14 17:05:38 -07001236 /**
1237 * Implemented to satisfy {@link SpeedDialFragment.HostInterface}
1238 */
1239 @Override
1240 public void showAllContactsTab() {
1241 if (mListsFragment != null) {
1242 mListsFragment.showTab(ListsFragment.TAB_INDEX_ALL_CONTACTS);
1243 }
1244 }
1245
1246 /**
1247 * Implemented to satisfy {@link CallLogFragment.HostInterface}
1248 */
1249 @Override
1250 public void showDialpad() {
1251 showDialpadFragment(true);
1252 }
1253
Yorke Leee00c9fe2014-04-12 12:42:06 -07001254 @Override
Yorke Leec8d6e162015-09-14 18:43:27 -07001255 public void onPickPhoneNumberAction(Uri dataUri, int callInitiationType) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001256 mClearSearchOnPause = true;
Yorke Leec8d6e162015-09-14 18:43:27 -07001257 PhoneNumberInteraction.startInteractionForPhoneCall(
1258 DialtactsActivity.this, dataUri, callInitiationType);
Yorke Leee00c9fe2014-04-12 12:42:06 -07001259 }
1260
1261 @Override
Yorke Leec8d6e162015-09-14 18:43:27 -07001262 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall,
1263 int callInitiationType) {
Yorke Lee24d034f2015-07-01 12:34:50 -07001264 if (phoneNumber == null) {
1265 // Invalid phone number, but let the call go through so that InCallUI can show
1266 // an error message.
1267 phoneNumber = "";
1268 }
Yorke Leee3a2d132015-09-14 16:52:08 -07001269
1270 final Intent intent = new CallIntentBuilder(phoneNumber)
1271 .setIsVideoCall(isVideoCall)
Yorke Leec8d6e162015-09-14 18:43:27 -07001272 .setCallInitiationType(callInitiationType)
Yorke Leee3a2d132015-09-14 16:52:08 -07001273 .build();
1274
Yorke Lee7d20f822014-06-19 17:09:33 -07001275 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001276 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001277 }
1278
1279 @Override
1280 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001281 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001282 }
1283
1284 @Override
1285 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001286 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001287 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001288
Yorke Leecc4660d2014-04-24 11:22:57 -07001289 @Override
1290 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Andrew Lee432d4b52015-05-20 16:52:00 -07001291 int tabIndex = mListsFragment.getCurrentTabIndex();
1292
Andrew Lee4de59fb2015-08-13 15:20:08 -07001293 // Scroll the button from center to end when moving from the Speed Dial to Call History tab.
1294 // In RTL, scroll when the current tab is Call History instead, since the order of the tabs
1295 // is reversed and the ViewPager returns the left tab position during scroll.
Andrew Lee432d4b52015-05-20 16:52:00 -07001296 boolean isRtl = DialerUtils.isRtl();
1297 if (!isRtl && tabIndex == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
1298 mFloatingActionButtonController.onPageScrolled(positionOffset);
Andrew Lee4de59fb2015-08-13 15:20:08 -07001299 } else if (isRtl && tabIndex == ListsFragment.TAB_INDEX_HISTORY && !mIsLandscape) {
Andrew Lee432d4b52015-05-20 16:52:00 -07001300 mFloatingActionButtonController.onPageScrolled(1 - positionOffset);
1301 } else if (tabIndex != ListsFragment.TAB_INDEX_SPEED_DIAL) {
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001302 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001303 }
Andrew Lee432d4b52015-05-20 16:52:00 -07001304 }
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001305
Andrew Lee432d4b52015-05-20 16:52:00 -07001306 @Override
1307 public void onPageSelected(int position) {
1308 int tabIndex = mListsFragment.getCurrentTabIndex();
1309 if (tabIndex == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001310 mFloatingActionButtonController.changeIcon(
1311 getResources().getDrawable(R.drawable.ic_person_add_24dp),
1312 getResources().getString(R.string.search_shortcut_create_new_contact));
1313 } else {
1314 mFloatingActionButtonController.changeIcon(
1315 getResources().getDrawable(R.drawable.fab_ic_dial),
1316 getResources().getString(R.string.action_menu_dialpad_button));
1317 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001318 }
1319
1320 @Override
Yorke Leecc4660d2014-04-24 11:22:57 -07001321 public void onPageScrollStateChanged(int state) {
1322 }
1323
Yorke Lee5253be02014-05-21 18:50:03 -07001324 @Override
1325 public boolean isActionBarShowing() {
1326 return mActionBarController.isActionBarShowing();
1327 }
1328
Yorke Leec98a5bb2014-10-28 16:12:05 -07001329 @Override
1330 public ActionBarController getActionBarController() {
1331 return mActionBarController;
1332 }
1333
Yorke Lee6bc67162015-06-27 14:03:25 -07001334 @Override
Andrew Lee9da8fb42014-06-03 14:03:09 -07001335 public boolean isDialpadShown() {
1336 return mIsDialpadShown;
1337 }
1338
Yorke Lee5253be02014-05-21 18:50:03 -07001339 @Override
Yorke Lee6bc67162015-06-27 14:03:25 -07001340 public int getDialpadHeight() {
1341 if (mDialpadFragment != null) {
1342 return mDialpadFragment.getDialpadHeight();
1343 }
1344 return 0;
1345 }
1346
1347 @Override
Yorke Lee5253be02014-05-21 18:50:03 -07001348 public int getActionBarHideOffset() {
Nancy Chen44898ad2015-08-13 12:03:47 -07001349 return getSupportActionBar().getHideOffset();
Yorke Lee5253be02014-05-21 18:50:03 -07001350 }
1351
1352 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001353 public void setActionBarHideOffset(int offset) {
Nancy Chen44898ad2015-08-13 12:03:47 -07001354 getSupportActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001355 }
1356
1357 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001358 public int getActionBarHeight() {
1359 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001360 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001361
Andrew Lee6324f702015-06-16 14:45:58 -07001362 private int getFabAlignment() {
1363 if (!mIsLandscape && !isInSearchUi() &&
1364 mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) {
1365 return FloatingActionButtonController.ALIGN_MIDDLE;
1366 }
1367 return FloatingActionButtonController.ALIGN_END;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001368 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001369}