blob: 96dc415da84961510650c7b09583c4864ad2f0d2 [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
Yorke Lee53a22302014-04-29 18:13:46 -070019import android.app.ActionBar;
Chiao Cheng94b10b52012-08-17 16:59:12 -070020import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070021import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080022import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.content.Context;
24import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080025import android.content.pm.PackageManager;
26import android.content.pm.ResolveInfo;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070027import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070028import android.content.res.Resources;
Chiao Cheng94b10b52012-08-17 16:59:12 -070029import android.net.Uri;
30import android.os.Bundle;
Yorke Leef5554ce2015-01-27 14:46:02 -080031import android.os.Trace;
Yorke Leec3766332013-07-31 11:13:16 -070032import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070033import android.support.v4.view.ViewPager;
Tyler Gunn9dc924c2014-09-12 09:33:50 -070034import android.telecom.PhoneAccount;
35import android.telecom.TelecomManager;
Yorke Lee53a22302014-04-29 18:13:46 -070036import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070037import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070038import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070039import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070040import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070041import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070042import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070043import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070044import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070045import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070046import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070047import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070048import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070049import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070050import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070051import android.view.animation.AnimationUtils;
Yorke Leec3766332013-07-31 11:13:16 -070052import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070053import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070054import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070055import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070056import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080057import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070058
Brian Attwellc311af12014-10-22 18:28:58 -070059import com.android.contacts.common.activity.TransactionSafeActivity;
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 Leefce269a2013-08-12 11:56:04 -070068import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070069import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070070import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070071import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070072import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080073import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070074import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080075import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070076import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070077import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070078import com.android.dialer.list.RegularSearchFragment;
79import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070080import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070081import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070082import com.android.dialer.settings.DialerSettingsActivity;
Andrew Lee247df6e2015-05-12 19:09:00 -070083import com.android.dialer.util.IntentUtil;
Yorke Lee7d20f822014-06-19 17:09:33 -070084import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070085import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070086import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070087import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070088import com.android.dialerbind.DatabaseHelperManager;
Yorke Lee2fec47b2014-08-05 18:16:27 -070089import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070090import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070091
Yorke Leed5c512a2015-01-30 14:42:53 -080092import junit.framework.Assert;
93
Yorke Leec3766332013-07-31 11:13:16 -070094import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080095import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070096
Chiao Cheng94b10b52012-08-17 16:59:12 -070097/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070098 * The dialer tab's title is 'phone', a more common name (see strings.xml).
99 */
Yorke Leec3766332013-07-31 11:13:16 -0700100public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700101 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700102 OnListFragmentScrolledListener,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700103 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700104 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700105 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700106 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700107 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700108 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700109 ViewPager.OnPageChangeListener,
110 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700111 private static final String TAG = "DialtactsActivity";
112
Ihab Awad526c0b82014-02-27 12:55:36 -0800113 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700114
Yorke Leef74011e2013-08-02 11:30:30 -0700115 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
116
Chiao Cheng94b10b52012-08-17 16:59:12 -0700117 /** @see #getCallOrigin() */
118 private static final String CALL_ORIGIN_DIALTACTS =
119 "com.android.dialer.DialtactsActivity";
120
Yorke Leeb207f8a2013-08-29 18:51:06 -0700121 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
122 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700123 private static final String KEY_SEARCH_QUERY = "search_query";
124 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700125 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700126
Yorke Leec3766332013-07-31 11:13:16 -0700127 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
128 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
129 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
130 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700131
Chiao Cheng94b10b52012-08-17 16:59:12 -0700132 /**
133 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
134 */
135 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
136
Yorke Leec3766332013-07-31 11:13:16 -0700137 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700138
Yorke Leef614f6f2014-10-03 10:44:19 -0700139 private FrameLayout mParentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700140
Yorke Leec3766332013-07-31 11:13:16 -0700141 /**
Yorke Leec3766332013-07-31 11:13:16 -0700142 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700143 */
Evan Charlton72d66252014-11-07 16:23:47 -0800144 protected DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700145
146 /**
147 * Fragment for searching phone numbers using the alphanumeric keyboard.
148 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700149 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700150
151 /**
152 * Fragment for searching phone numbers using the dialpad.
153 */
154 private SmartDialSearchFragment mSmartDialSearchFragment;
155
Yorke Leee00c9fe2014-04-12 12:42:06 -0700156 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700157 * Animation that slides in.
158 */
159 private Animation mSlideIn;
160
161 /**
162 * Animation that slides out.
163 */
164 private Animation mSlideOut;
165
Yorke Lee6c450eb2015-05-08 09:45:47 -0700166 AnimationListenerAdapter mSlideInListener = new AnimationListenerAdapter() {
167 @Override
168 public void onAnimationEnd(Animation animation) {
169 if (!isInSearchUi()) {
170 enterSearchUi(true /* isSmartDial */, mSearchQuery, false);
171 }
172 }
173 };
174
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700175 /**
176 * Listener for after slide out animation completes on dialer fragment.
177 */
178 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
179 @Override
180 public void onAnimationEnd(Animation animation) {
181 commitDialpadFragmentHide();
182 }
183 };
184
185 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700186 * Fragment containing the speed dial list, recents list, and all contacts list.
187 */
188 private ListsFragment mListsFragment;
189
Yorke Lee19e68ca2014-10-28 11:51:40 -0700190 /**
191 * Tracks whether onSaveInstanceState has been called. If true, no fragment transactions can
192 * be commited.
193 */
194 private boolean mStateSaved;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800195 private boolean mIsRestarting;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700196 private boolean mInDialpadSearch;
197 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700198 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700199 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700200 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700201
Yorke Leeef2b7382013-08-09 17:39:25 -0700202 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700203 * Whether or not the device is in landscape orientation.
204 */
205 private boolean mIsLandscape;
206
207 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700208 * True if the dialpad is only temporarily showing due to being in call
209 */
210 private boolean mInCallDialpadUp;
211
212 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700213 * True when this activity has been launched for the first time.
214 */
Yorke Lee98702de2013-08-06 12:03:32 -0700215 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700216
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700217 /**
218 * Search query to be applied to the SearchView in the ActionBar once
219 * onCreateOptionsMenu has been called.
220 */
221 private String mPendingSearchViewQuery;
222
Yorke Lee74edcdc2014-07-11 16:15:08 -0700223 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700224 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700225 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700226
Yorke Leeef2b7382013-08-09 17:39:25 -0700227 private String mSearchQuery;
228
Yorke Leefce269a2013-08-12 11:56:04 -0700229 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700230 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700231 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700232
Sai Cheemalapati41460652014-06-02 21:05:39 -0700233 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700234
Andrew Lee2423a2f2014-05-29 14:14:45 -0700235 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700236
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800237 /**
238 * The text returned from a voice search query. Set in {@link #onActivityResult} and used in
239 * {@link #onResume()} to populate the search box.
240 */
241 private String mVoiceSearchQuery;
242
Andrew Lee467de3d2015-03-17 15:47:24 -0700243 protected class OptionsPopupMenu extends PopupMenu {
Andrew Leee74a10e2014-05-16 14:31:40 -0700244 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700245 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700246 }
247
248 @Override
249 public void show() {
Yorke Leec16ea5a2015-05-19 15:51:01 -0700250 final boolean hasContactsPermission =
251 PermissionsUtil.hasContactsPermissions(DialtactsActivity.this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700252 final Menu menu = getMenu();
253 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700254 clearFrequents.setVisible(mListsFragment != null &&
255 mListsFragment.getSpeedDialFragment() != null &&
Yorke Leec16ea5a2015-05-19 15:51:01 -0700256 mListsFragment.getSpeedDialFragment().hasFrequents() && hasContactsPermission);
257
258 menu.findItem(R.id.menu_import_export).setVisible(hasContactsPermission);
259 menu.findItem(R.id.menu_add_contact).setVisible(hasContactsPermission);
Yorke Leeb7330e32015-05-22 15:55:22 -0700260
261 menu.findItem(R.id.menu_history).setVisible(
262 PermissionsUtil.hasPhonePermissions(DialtactsActivity.this));
Yorke Leee00c9fe2014-04-12 12:42:06 -0700263 super.show();
264 }
265 }
266
Chiao Cheng94b10b52012-08-17 16:59:12 -0700267 /**
Yorke Lee28266192014-05-01 10:05:52 -0700268 * Listener that listens to drag events and sends their x and y coordinates to a
269 * {@link DragDropController}.
270 */
271 private class LayoutOnDragListener implements OnDragListener {
272 @Override
273 public boolean onDrag(View v, DragEvent event) {
274 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700275 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700276 }
277 return true;
278 }
279 }
280
281 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700282 * Listener used to send search queries to the phone search fragment.
283 */
Yorke Lee53a22302014-04-29 18:13:46 -0700284 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700285 @Override
286 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
287 }
Yorke Leec3766332013-07-31 11:13:16 -0700288
Andrew Lee99a570c2014-05-15 14:18:50 -0700289 @Override
290 public void onTextChanged(CharSequence s, int start, int before, int count) {
291 final String newText = s.toString();
292 if (newText.equals(mSearchQuery)) {
293 // If the query hasn't changed (perhaps due to activity being destroyed
294 // and restored, or user launching the same DIAL intent twice), then there is
295 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700296 return;
297 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700298 if (DEBUG) {
299 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700300 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700301 }
Yorke Lee710709d2014-05-29 07:18:42 -0700302 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700303
Andrew Lee90374a72014-05-16 15:01:09 -0700304 // Show search fragment only when the query string is changed to non-empty text.
305 if (!TextUtils.isEmpty(newText)) {
306 // Call enterSearchUi only if we are switching search modes, or showing a search
307 // fragment for the first time.
308 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
309 (!mIsDialpadShown && mInRegularSearch);
310 if (!sameSearchMode) {
Yorke Lee6c450eb2015-05-08 09:45:47 -0700311 enterSearchUi(mIsDialpadShown, mSearchQuery, true /* animate */);
Andrew Lee90374a72014-05-16 15:01:09 -0700312 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700313 }
314
Andrew Leea8515422014-06-13 16:53:54 -0700315 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700316 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700317 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700318 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700319 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700320 }
321
322 @Override
323 public void afterTextChanged(Editable s) {
324 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700325 };
326
Andrew Leeb1903842014-05-15 16:11:24 -0700327
328 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700329 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700330 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700331 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700332 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700333 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700334 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700335 mActionBarController.onSearchBoxTapped();
Yorke Lee6c450eb2015-05-08 09:45:47 -0700336 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString(),
337 true /* animate */);
Andrew Leeb1903842014-05-15 16:11:24 -0700338 }
Andrew Leeb1903842014-05-15 16:11:24 -0700339 }
340 };
341
342 /**
343 * If the search term is empty and the user closes the soft keyboard, close the search UI.
344 */
345 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
346 @Override
347 public boolean onKey(View v, int keyCode, KeyEvent event) {
348 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
349 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700350 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700351 }
352 return false;
353 }
354 };
355
Chiao Cheng94b10b52012-08-17 16:59:12 -0700356 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700357 public boolean dispatchTouchEvent(MotionEvent ev) {
358 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
359 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
360 }
361 return super.dispatchTouchEvent(ev);
362
363 }
364
365 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700366 protected void onCreate(Bundle savedInstanceState) {
Yorke Leef5554ce2015-01-27 14:46:02 -0800367 Trace.beginSection(TAG + " onCreate");
Yorke Leec3766332013-07-31 11:13:16 -0700368 super.onCreate(savedInstanceState);
Yorke Leec16ea5a2015-05-19 15:51:01 -0700369
Yorke Lee98702de2013-08-06 12:03:32 -0700370 mFirstLaunch = true;
371
Andrew Lee2423a2f2014-05-29 14:14:45 -0700372 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700373 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700374
Yorke Leef5554ce2015-01-27 14:46:02 -0800375 Trace.beginSection(TAG + " setContentView");
Yorke Lee8898cd02013-08-08 10:24:27 -0700376 setContentView(R.layout.dialtacts_activity);
Yorke Leef5554ce2015-01-27 14:46:02 -0800377 Trace.endSection();
Yorke Lee9e91bb02014-03-05 17:50:50 -0800378 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700379
Yorke Leef5554ce2015-01-27 14:46:02 -0800380 Trace.beginSection(TAG + " setup Views");
Yorke Lee53a22302014-04-29 18:13:46 -0700381 final ActionBar actionBar = getActionBar();
382 actionBar.setCustomView(R.layout.search_edittext);
383 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700384 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700385
Andrew Lee04675a52014-06-05 18:36:20 -0700386 SearchEditTextLayout searchEditTextLayout =
Andrew Leee3f59a82015-02-26 12:06:35 -0800387 (SearchEditTextLayout) actionBar.getCustomView().findViewById(R.id.search_view_container);
Andrew Lee04675a52014-06-05 18:36:20 -0700388 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
389
Andrew Leee3f59a82015-02-26 12:06:35 -0800390 mActionBarController = new ActionBarController(this, searchEditTextLayout);
391
Andrew Lee04675a52014-06-05 18:36:20 -0700392 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700393 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700394 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
395 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
396 .setOnClickListener(mSearchViewOnClickListener);
397 searchEditTextLayout.findViewById(R.id.search_box_start_search)
398 .setOnClickListener(mSearchViewOnClickListener);
399 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700400 @Override
401 public void onBackButtonClicked() {
402 onBackPressed();
403 }
404 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700405
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700406 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700407 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700408
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700409 final View floatingActionButtonContainer = findViewById(
410 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700411 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
412 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700413 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700414 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700415
Andrew Lee04675a52014-06-05 18:36:20 -0700416 ImageButton optionsMenuButton =
417 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700418 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700419 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
420 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700421
Yorke Leed5c512a2015-01-30 14:42:53 -0800422 // Add the favorites fragment but only if savedInstanceState is null. Otherwise the
423 // fragment manager is responsible for recreating it.
Yorke Leec3766332013-07-31 11:13:16 -0700424 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800425 getFragmentManager().beginTransaction()
Andrew Lee6a866242015-05-05 18:21:45 +0000426 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800427 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700428 } else {
429 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700430 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
431 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700432 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700433 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700434 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700435 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700436
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700437 final boolean isLayoutRtl = DialerUtils.isRtl();
438 if (mIsLandscape) {
439 mSlideIn = AnimationUtils.loadAnimation(this,
440 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
441 mSlideOut = AnimationUtils.loadAnimation(this,
442 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
443 } else {
444 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
445 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
446 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700447
Yorke Lee2fec47b2014-08-05 18:16:27 -0700448 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
449 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
450
Yorke Lee6c450eb2015-05-08 09:45:47 -0700451 mSlideIn.setAnimationListener(mSlideInListener);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700452 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700453
Yorke Leef614f6f2014-10-03 10:44:19 -0700454 mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
455 mParentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700456 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700457 new ViewTreeObserver.OnGlobalLayoutListener() {
458 @Override
459 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700460 final ViewTreeObserver observer =
461 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700462 if (!observer.isAlive()) {
463 return;
464 }
465 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700466 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700467 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700468 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700469 }
470 });
Andrew Lee0c667702014-05-12 14:31:45 -0700471
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700472 setupActivityOverlay();
473
Yorke Leef5554ce2015-01-27 14:46:02 -0800474 Trace.endSection();
475
476 Trace.beginSection(TAG + " initialize smart dialing");
Yorke Lee0baa98b2013-08-22 10:55:16 -0700477 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700478 SmartDialPrefix.initializeNanpSettings(this);
Yorke Leef5554ce2015-01-27 14:46:02 -0800479 Trace.endSection();
480 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700481 }
482
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700483 private void setupActivityOverlay() {
484 final View activityOverlay = findViewById(R.id.activity_overlay);
485 activityOverlay.setOnTouchListener(new OnTouchListener() {
486 @Override
487 public boolean onTouch(View v, MotionEvent event) {
488 if (!mIsDialpadShown) {
489 maybeExitSearchUi();
490 }
491 return false;
492 }
493 });
494 }
495
Chiao Cheng94b10b52012-08-17 16:59:12 -0700496 @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 Lee19e68ca2014-10-28 11:51:40 -0700500 mStateSaved = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700501 if (mFirstLaunch) {
502 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700503 } else if (!phoneIsInUse() && mInCallDialpadUp) {
504 hideDialpadFragment(false, true);
505 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700506 } else if (mShowDialpadOnResume) {
507 showDialpadFragment(false);
508 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700509 }
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800510
511 // If there was a voice query result returned in the {@link #onActivityResult} callback, it
512 // will have been stashed in mVoiceSearchQuery since the search results fragment cannot be
513 // shown until onResume has completed. Active the search UI and set the search term now.
514 if (!TextUtils.isEmpty(mVoiceSearchQuery)) {
515 mActionBarController.onSearchBoxTapped();
516 mSearchView.setText(mVoiceSearchQuery);
517 mVoiceSearchQuery = null;
518 }
519
Yorke Lee98702de2013-08-06 12:03:32 -0700520 mFirstLaunch = false;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800521
522 if (mIsRestarting) {
523 // This is only called when the activity goes from resumed -> paused -> resumed, so it
524 // will not cause an extra view to be sent out on rotation
525 if (mIsDialpadShown) {
526 AnalyticsUtil.sendScreenView(mDialpadFragment, this);
527 }
528 mIsRestarting = false;
529 }
Yorke Lee53a22302014-04-29 18:13:46 -0700530 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700531 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700532 updateFloatingActionButtonControllerAlignment(false /* animate */);
Yorke Leef5554ce2015-01-27 14:46:02 -0800533 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700534 }
535
536 @Override
Yorke Lee7ee5c422014-11-04 10:29:32 -0800537 protected void onRestart() {
538 super.onRestart();
539 mIsRestarting = true;
540 }
541
542 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700543 protected void onPause() {
544 if (mClearSearchOnPause) {
545 hideDialpadAndSearchUi();
546 mClearSearchOnPause = false;
547 }
Yorke Lee19e68ca2014-10-28 11:51:40 -0700548 if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) {
549 commitDialpadFragmentHide();
550 }
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700551 super.onPause();
552 }
553
554 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700555 protected void onSaveInstanceState(Bundle outState) {
556 super.onSaveInstanceState(outState);
557 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700558 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
559 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700560 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700561 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700562 mActionBarController.saveInstanceState(outState);
Yorke Lee19e68ca2014-10-28 11:51:40 -0700563 mStateSaved = true;
Yorke Leeef2b7382013-08-09 17:39:25 -0700564 }
565
566 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700567 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700568 if (fragment instanceof DialpadFragment) {
569 mDialpadFragment = (DialpadFragment) fragment;
Yorke Leed5c512a2015-01-30 14:42:53 -0800570 if (!mIsDialpadShown && !mShowDialpadOnResume) {
Yorke Lee50aba882014-05-28 20:04:31 -0700571 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
572 transaction.hide(mDialpadFragment);
573 transaction.commit();
574 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700575 } else if (fragment instanceof SmartDialSearchFragment) {
576 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700577 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700578 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700579 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700580 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700581 } else if (fragment instanceof ListsFragment) {
582 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700583 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700584 }
Yorke Leec3766332013-07-31 11:13:16 -0700585 }
586
Alon Albertb453e5b2013-09-10 15:54:23 -0700587 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700588 final Intent intent = new Intent(this, DialerSettingsActivity.class);
589 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700590 }
591
Chiao Cheng94b10b52012-08-17 16:59:12 -0700592 @Override
593 public void onClick(View view) {
594 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700595 case R.id.floating_action_button:
Andrew Leefdfeaaf2015-05-05 14:10:35 -0700596 if (mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
Andrew Lee247df6e2015-05-12 19:09:00 -0700597 DialerUtils.startActivityWithErrorToast(
598 this,
599 IntentUtil.getNewContactIntent(),
600 R.string.add_contact_not_available);
Andrew Leefdfeaaf2015-05-05 14:10:35 -0700601 } else if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700602 mInCallDialpadUp = false;
603 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700604 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700605 break;
Yorke Leec3766332013-07-31 11:13:16 -0700606 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800607 try {
608 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
609 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
610 } catch (ActivityNotFoundException e) {
611 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
612 Toast.LENGTH_SHORT).show();
613 }
Yorke Leec3766332013-07-31 11:13:16 -0700614 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700615 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700616 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700617 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700618 default: {
619 Log.wtf(TAG, "Unexpected onClick event from " + view);
620 break;
621 }
622 }
623 }
624
Yorke Leec3766332013-07-31 11:13:16 -0700625 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700626 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700627 switch (item.getItemId()) {
628 case R.id.menu_history:
Andrew Lee69705be2015-05-04 17:24:01 -0700629 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
630 // CONTENT_TYPE, so that we always open our call log from our dialer
631 final Intent intent = new Intent(this, CallLogActivity.class);
632 startActivity(intent);
Yorke Lee86e21f72014-04-02 16:49:38 -0700633 break;
634 case R.id.menu_add_contact:
Andrew Lee247df6e2015-05-12 19:09:00 -0700635 DialerUtils.startActivityWithErrorToast(
636 this,
637 IntentUtil.getNewContactIntent(),
638 R.string.add_contact_not_available);
Yorke Lee86e21f72014-04-02 16:49:38 -0700639 break;
640 case R.id.menu_import_export:
641 // We hard-code the "contactsAreAvailable" argument because doing it properly would
642 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
643 // now in Dialtacts for (potential) performance reasons. Compare with how it is
644 // done in {@link PeopleActivity}.
645 ImportExportDialogFragment.show(getFragmentManager(), true,
646 DialtactsActivity.class);
647 return true;
648 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700649 ClearFrequentsDialog.show(getFragmentManager());
650 return true;
651 case R.id.menu_call_settings:
652 handleMenuSettings();
653 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700654 }
655 return false;
656 }
657
658 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700659 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
660 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
661 if (resultCode == RESULT_OK) {
662 final ArrayList<String> matches = data.getStringArrayListExtra(
663 RecognizerIntent.EXTRA_RESULTS);
664 if (matches.size() > 0) {
665 final String match = matches.get(0);
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800666 mVoiceSearchQuery = match;
Yorke Leec3766332013-07-31 11:13:16 -0700667 } else {
668 Log.e(TAG, "Voice search - nothing heard");
669 }
670 } else {
671 Log.e(TAG, "Voice search failed");
672 }
673 }
674 super.onActivityResult(requestCode, resultCode, data);
675 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700676
Andrew Lee2a58ab82014-05-15 02:16:04 -0700677 /**
678 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
679 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
680 * @see #onDialpadShown
681 */
Yorke Leec3766332013-07-31 11:13:16 -0700682 private void showDialpadFragment(boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700683 if (mIsDialpadShown || mStateSaved) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700684 return;
685 }
686 mIsDialpadShown = true;
Yorke Leed5c512a2015-01-30 14:42:53 -0800687
Yorke Lee7ee5c422014-11-04 10:29:32 -0800688 mListsFragment.setUserVisibleHint(false);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700689
Chiao Cheng94b10b52012-08-17 16:59:12 -0700690 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leed5c512a2015-01-30 14:42:53 -0800691 if (mDialpadFragment == null) {
692 mDialpadFragment = new DialpadFragment();
693 ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT);
694 } else {
695 ft.show(mDialpadFragment);
696 }
697
698 mDialpadFragment.setAnimate(animate);
699 AnalyticsUtil.sendScreenView(mDialpadFragment);
Yorke Leec3766332013-07-31 11:13:16 -0700700 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700701
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700702 if (animate) {
703 mFloatingActionButtonController.scaleOut();
704 } else {
705 mFloatingActionButtonController.setVisible(false);
706 }
Yorke Lee5253be02014-05-21 18:50:03 -0700707 mActionBarController.onDialpadUp();
708
Yorke Lee6c450eb2015-05-08 09:45:47 -0700709 mListsFragment.getView().animate().alpha(0).withLayer();
Yorke Leec3766332013-07-31 11:13:16 -0700710 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700711
Andrew Lee2a58ab82014-05-15 02:16:04 -0700712 /**
713 * Callback from child DialpadFragment when the dialpad is shown.
714 */
715 public void onDialpadShown() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800716 Assert.assertNotNull(mDialpadFragment);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700717 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700718 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700719 } else {
720 mDialpadFragment.setYFraction(0);
721 }
722
Andrew Lee2a58ab82014-05-15 02:16:04 -0700723 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700724 }
725
726 /**
727 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
728 * a callback after the hide animation ends.
729 * @see #commitDialpadFragmentHide
730 */
Yorke Leeca195042013-09-25 16:29:38 -0700731 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Yorke Lee791b4882015-05-15 10:52:27 -0700732 if (mDialpadFragment == null || mDialpadFragment.getView() == null) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700733 return;
734 }
Yorke Leef6673d32013-08-23 15:34:17 -0700735 if (clearDialpad) {
736 mDialpadFragment.clearDialpad();
737 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700738 if (!mIsDialpadShown) {
739 return;
Yorke Leec3766332013-07-31 11:13:16 -0700740 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700741 mIsDialpadShown = false;
742 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800743 mListsFragment.setUserVisibleHint(true);
744 mListsFragment.sendScreenViewForCurrentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700745
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700746 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700747
748 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700749 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700750 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700751 } else {
752 commitDialpadFragmentHide();
753 }
754
Yorke Lee5253be02014-05-21 18:50:03 -0700755 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700756
Andrew Leed4cde832014-05-16 15:56:48 -0700757 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700758 if (TextUtils.isEmpty(mSearchQuery)) {
759 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700760 }
Andrew Leed4cde832014-05-16 15:56:48 -0700761 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700762 }
763
764 /**
765 * Finishes hiding the dialpad fragment after any animations are completed.
766 */
767 private void commitDialpadFragmentHide() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800768 if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700769 final FragmentTransaction ft = getFragmentManager().beginTransaction();
770 ft.hide(mDialpadFragment);
771 ft.commit();
772 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700773 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700774 }
775
Andrew Lee2a58ab82014-05-15 02:16:04 -0700776 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700777 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700778 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700779 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700780 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700781 fragment = mRegularSearchFragment;
782 }
783 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700784 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700785 }
786 }
787
Yorke Lee5253be02014-05-21 18:50:03 -0700788 @Override
789 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700790 return mInDialpadSearch || mInRegularSearch;
791 }
792
Yorke Lee5253be02014-05-21 18:50:03 -0700793 @Override
794 public boolean hasSearchQuery() {
795 return !TextUtils.isEmpty(mSearchQuery);
796 }
797
798 @Override
799 public boolean shouldShowActionBar() {
800 return mListsFragment.shouldShowActionBar();
801 }
802
Yorke Leeb207f8a2013-08-29 18:51:06 -0700803 private void setNotInSearchUi() {
804 mInDialpadSearch = false;
805 mInRegularSearch = false;
806 }
807
Yorke Lee311969c2013-08-26 06:31:11 -0700808 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700809 if (mIsDialpadShown) {
810 hideDialpadFragment(false, true);
811 } else {
812 exitSearchUi();
813 }
Yorke Lee311969c2013-08-26 06:31:11 -0700814 }
815
Yorke Lee53a22302014-04-29 18:13:46 -0700816 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700817 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
818 if (canIntentBeHandled(voiceIntent)) {
819 mVoiceSearchButton.setVisibility(View.VISIBLE);
820 mVoiceSearchButton.setOnClickListener(this);
821 } else {
822 mVoiceSearchButton.setVisibility(View.GONE);
823 }
824 }
825
Andrew Lee467de3d2015-03-17 15:47:24 -0700826 protected OptionsPopupMenu buildOptionsMenu(View invoker) {
Andrew Leee74a10e2014-05-16 14:31:40 -0700827 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
828 popupMenu.inflate(R.menu.dialtacts_options);
829 popupMenu.setOnMenuItemClickListener(this);
830 return popupMenu;
831 }
832
Yorke Lee86e21f72014-04-02 16:49:38 -0700833 @Override
834 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700835 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700836 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700837 mPendingSearchViewQuery = null;
838 }
Yorke Leec16ea5a2015-05-19 15:51:01 -0700839 if (mActionBarController != null) {
840 mActionBarController.restoreActionBarOffset();
841 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700842 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700843 }
844
Chiao Cheng94b10b52012-08-17 16:59:12 -0700845 /**
846 * Returns true if the intent is due to hitting the green send key (hardware call button:
847 * KEYCODE_CALL) while in a call.
848 *
849 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700850 * @return true if the intent is due to hitting the green send key while in a call
851 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700852 private boolean isSendKeyWhileInCall(Intent intent) {
853 // If there is a call in progress and the user launched the dialer by hitting the call
854 // button, go straight to the in-call screen.
855 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700856
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700857 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700858 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700859 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700860 }
861
862 return false;
863 }
864
865 /**
866 * Sets the current tab based on the intent's request type
867 *
868 * @param intent Intent that contains information about which tab should be selected
869 */
Yorke Leec3766332013-07-31 11:13:16 -0700870 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700871 // 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 -0700872 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700873 finish();
874 return;
875 }
876
Yorke Leed5c512a2015-01-30 14:42:53 -0800877 final boolean phoneIsInUse = phoneIsInUse();
878 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
879 showDialpadFragment(false);
880 mDialpadFragment.setStartedFromNewIntent(true);
881 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
882 mInCallDialpadUp = true;
Yorke Lee35127cd2013-09-10 14:09:29 -0700883 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700884 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700885 }
886
887 @Override
888 public void onNewIntent(Intent newIntent) {
889 setIntent(newIntent);
Nancy Chen199b7f02014-11-05 15:03:00 -0800890 mStateSaved = false;
Yorke Leec3766332013-07-31 11:13:16 -0700891 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700892
Chiao Cheng94b10b52012-08-17 16:59:12 -0700893 invalidateOptionsMenu();
894 }
895
896 /** Returns true if the given intent contains a phone number to populate the dialer with */
897 private boolean isDialIntent(Intent intent) {
898 final String action = intent.getAction();
899 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
900 return true;
901 }
902 if (Intent.ACTION_VIEW.equals(action)) {
903 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700904 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700905 return true;
906 }
907 }
908 return false;
909 }
910
911 /**
912 * Returns an appropriate call origin for this Activity. May return null when no call origin
913 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
914 * for remembering the tab in which the user made a phone call, so the external app's DIAL
915 * request should not be counted.)
916 */
917 public String getCallOrigin() {
918 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
919 }
920
Chiao Cheng94b10b52012-08-17 16:59:12 -0700921 /**
Yorke Leec3766332013-07-31 11:13:16 -0700922 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700923 */
Yorke Lee6c450eb2015-05-08 09:45:47 -0700924 private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700925 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700926 // Weird race condition where fragment is doing work after the activity is destroyed
927 // due to talkback being on (b/10209937). Just return since we can't do any
928 // constructive here.
929 return;
930 }
931
Yorke Leeef2b7382013-08-09 17:39:25 -0700932 if (DEBUG) {
933 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
934 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700935
Yorke Leec3766332013-07-31 11:13:16 -0700936 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700937 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700938 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700939 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700940 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700941 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700942
Yorke Leeb207f8a2013-08-29 18:51:06 -0700943 final String tag;
944 if (smartDialSearch) {
945 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
946 } else {
947 tag = TAG_REGULAR_SEARCH_FRAGMENT;
948 }
949 mInDialpadSearch = smartDialSearch;
950 mInRegularSearch = !smartDialSearch;
951
Andrew Lee752956e2014-05-15 11:43:38 -0700952 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Yorke Lee6c450eb2015-05-08 09:45:47 -0700953 if (animate) {
954 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
955 } else {
956 transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
957 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700958 if (fragment == null) {
959 if (smartDialSearch) {
960 fragment = new SmartDialSearchFragment();
961 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700962 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700963 }
Andrew Leeb1903842014-05-15 16:11:24 -0700964 transaction.add(R.id.dialtacts_frame, fragment, tag);
965 } else {
966 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700967 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700968 // DialtactsActivity will provide the options menu
969 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700970 fragment.setShowEmptyListForNullQuery(true);
Yorke Lee6c450eb2015-05-08 09:45:47 -0700971 if (!smartDialSearch) {
972 fragment.setQueryString(query, false /* delaySelection */);
973 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700974 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700975
Yorke Lee6c450eb2015-05-08 09:45:47 -0700976 if (animate) {
977 mListsFragment.getView().animate().alpha(0).withLayer();
978 }
Yorke Lee7ee5c422014-11-04 10:29:32 -0800979 mListsFragment.setUserVisibleHint(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700980 }
981
982 /**
Yorke Leec3766332013-07-31 11:13:16 -0700983 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700984 */
Yorke Leec3766332013-07-31 11:13:16 -0700985 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700986 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700987 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -0700988 return;
989 }
Andrew Leeb1903842014-05-15 16:11:24 -0700990
Andrew Leeb1903842014-05-15 16:11:24 -0700991 mSearchView.setText(null);
Yorke Leed5c512a2015-01-30 14:42:53 -0800992
993 if (mDialpadFragment != null) {
994 mDialpadFragment.clearDialpad();
995 }
996
Yorke Leeb207f8a2013-08-29 18:51:06 -0700997 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700998
Andrew Leeb1903842014-05-15 16:11:24 -0700999 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -07001000 if (mSmartDialSearchFragment != null) {
1001 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -07001002 }
Andrew Leeb1903842014-05-15 16:11:24 -07001003 if (mRegularSearchFragment != null) {
1004 transaction.remove(mRegularSearchFragment);
1005 }
1006 transaction.commit();
1007
1008 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Leed5c512a2015-01-30 14:42:53 -08001009
1010 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
Yorke Lee7ee5c422014-11-04 10:29:32 -08001011 // If the dialpad fragment wasn't previously visible, then send a screen view because
1012 // we are exiting regular search. Otherwise, the screen view will be sent by
1013 // {@link #hideDialpadFragment}.
1014 mListsFragment.sendScreenViewForCurrentPosition();
1015 mListsFragment.setUserVisibleHint(true);
1016 }
1017
Yorke Lee5253be02014-05-21 18:50:03 -07001018 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001019 }
1020
Chiao Cheng94b10b52012-08-17 16:59:12 -07001021 @Override
Yorke Leec3766332013-07-31 11:13:16 -07001022 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -07001023 if (mStateSaved) {
1024 return;
1025 }
Andrew Lee2a58ab82014-05-15 02:16:04 -07001026 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -07001027 if (TextUtils.isEmpty(mSearchQuery) ||
1028 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
1029 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -07001030 exitSearchUi();
1031 }
Yorke Leef6673d32013-08-23 15:34:17 -07001032 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -07001033 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -07001034 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001035 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001036 } else {
1037 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001038 }
Yorke Leec3766332013-07-31 11:13:16 -07001039 }
1040
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001041 /**
1042 * @return True if the search UI was exited, false otherwise
1043 */
1044 private boolean maybeExitSearchUi() {
1045 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
1046 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001047 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001048 return true;
1049 }
1050 return false;
1051 }
1052
Yorke Leec3766332013-07-31 11:13:16 -07001053 @Override
1054 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -07001055 if (mSmartDialSearchFragment != null) {
1056 mSmartDialSearchFragment.setAddToContactNumber(query);
1057 }
Yorke Leec3766332013-07-31 11:13:16 -07001058 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
1059 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -07001060
1061 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001062 if (DEBUG) {
1063 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1064 }
1065 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1066 // This callback can happen if the dialpad fragment is recreated because of
1067 // activity destruction. In that case, don't update the search view because
1068 // that would bring the user back to the search fragment regardless of the
1069 // previous state of the application. Instead, just return here and let the
1070 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001071 if (!TextUtils.isEmpty(normalizedQuery)) {
1072 mPendingSearchViewQuery = normalizedQuery;
1073 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001074 return;
1075 }
Yorke Lee53a22302014-04-29 18:13:46 -07001076 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001077 }
1078 }
Yorke Leec3766332013-07-31 11:13:16 -07001079
1080 @Override
1081 public void onListFragmentScrollStateChange(int scrollState) {
1082 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001083 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -07001084 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001085 }
1086 }
1087
1088 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001089 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001090 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001091 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1092 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001093 }
1094
Yorke Leec3766332013-07-31 11:13:16 -07001095 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001096 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001097 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001098
Yorke Leeda0f9042013-12-05 14:25:51 -08001099 private boolean canIntentBeHandled(Intent intent) {
1100 final PackageManager packageManager = getPackageManager();
1101 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1102 PackageManager.MATCH_DEFAULT_ONLY);
1103 return resolveInfo != null && resolveInfo.size() > 0;
1104 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001105
Yorke Lee86e21f72014-04-02 16:49:38 -07001106 /**
1107 * Called when the user has long-pressed a contact tile to start a drag operation.
1108 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001109 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001110 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Lee18963442014-06-06 17:20:13 -07001111 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001112 }
1113
1114 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001115 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1116 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001117
Yorke Lee86e21f72014-04-02 16:49:38 -07001118 /**
1119 * Called when the user has released a contact tile after long-pressing it.
1120 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001121 @Override
1122 public void onDragFinished(int x, int y) {
Andrew Lee18963442014-06-06 17:20:13 -07001123 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001124 }
1125
1126 @Override
1127 public void onDroppedOnRemove() {}
1128
1129 /**
Yorke Leed999b712014-04-23 15:10:58 -07001130 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001131 * once it has been attached to the activity.
1132 */
1133 @Override
1134 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001135 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001136 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001137 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001138
1139 @Override
1140 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001141 // Specify call-origin so that users will see the previous tab instead of
1142 // CallLog screen (search UI will be automatically exited).
1143 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001144 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001145 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001146 }
1147
1148 @Override
1149 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001150 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1151 }
1152
1153 @Override
1154 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001155 Intent intent = isVideoCall ?
Andrew Lee247df6e2015-05-12 19:09:00 -07001156 IntentUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1157 IntentUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001158 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001159 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001160 }
1161
1162 @Override
1163 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001164 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001165 }
1166
1167 @Override
1168 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001169 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001170 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001171
Yorke Leecc4660d2014-04-24 11:22:57 -07001172 @Override
1173 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001174 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001175 // Only scroll the button when the first tab is selected. The button should scroll from
1176 // the middle to right position only on the transition from the first tab to the second
1177 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001178 // If the app is in RTL mode, we need to check against the second tab, rather than the
1179 // first. This is because if we are scrolling between the first and second tabs, the
1180 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1181 // reversal of the order of the tabs.
1182 final boolean isLayoutRtl = DialerUtils.isRtl();
1183 final boolean shouldScrollButton = position == (isLayoutRtl
1184 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1185 if (shouldScrollButton && !mIsLandscape) {
1186 mFloatingActionButtonController.onPageScrolled(
1187 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001188 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1189 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001190 }
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001191
1192 if (position == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
1193 mFloatingActionButtonController.changeIcon(
1194 getResources().getDrawable(R.drawable.ic_person_add_24dp),
1195 getResources().getString(R.string.search_shortcut_create_new_contact));
1196 } else {
1197 mFloatingActionButtonController.changeIcon(
1198 getResources().getDrawable(R.drawable.fab_ic_dial),
1199 getResources().getString(R.string.action_menu_dialpad_button));
1200 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001201 }
1202
1203 @Override
1204 public void onPageSelected(int position) {
Yorke Leecc4660d2014-04-24 11:22:57 -07001205 }
1206
1207 @Override
1208 public void onPageScrollStateChanged(int state) {
1209 }
1210
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001211 private TelecomManager getTelecomManager() {
1212 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001213 }
1214
Yorke Lee5253be02014-05-21 18:50:03 -07001215 @Override
1216 public boolean isActionBarShowing() {
1217 return mActionBarController.isActionBarShowing();
1218 }
1219
Yorke Leec98a5bb2014-10-28 16:12:05 -07001220 @Override
1221 public ActionBarController getActionBarController() {
1222 return mActionBarController;
1223 }
1224
Andrew Lee9da8fb42014-06-03 14:03:09 -07001225 public boolean isDialpadShown() {
1226 return mIsDialpadShown;
1227 }
1228
Yorke Lee5253be02014-05-21 18:50:03 -07001229 @Override
1230 public int getActionBarHideOffset() {
1231 return getActionBar().getHideOffset();
1232 }
1233
1234 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001235 public void setActionBarHideOffset(int offset) {
1236 getActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001237 }
1238
1239 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001240 public int getActionBarHeight() {
1241 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001242 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001243
1244 /**
1245 * Updates controller based on currently known information.
1246 *
1247 * @param animate Whether or not to animate the transition.
1248 */
1249 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001250 int align = (!mIsLandscape &&
1251 mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
Andrew Lee405a6e62014-08-20 15:02:16 -07001252 FloatingActionButtonController.ALIGN_MIDDLE :
1253 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001254 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001255 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001256}