blob: 502b8457ac6aca59f7681d5474a69a9b7a8d8b34 [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 Leee1424812013-09-04 18:24:48 -070032import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070033import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070034import android.support.v4.view.ViewPager;
Tyler Gunn9dc924c2014-09-12 09:33:50 -070035import android.telecom.PhoneAccount;
36import android.telecom.TelecomManager;
Yorke Leec3766332013-07-31 11:13:16 -070037import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070038import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070039import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070040import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070041import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070042import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070043import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070044import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070045import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070046import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070047import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070049import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070050import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070051import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070052import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070053import android.view.animation.AnimationUtils;
Yorke Leec3766332013-07-31 11:13:16 -070054import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070055import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070056import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070057import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070058import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080059import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070060
Brian Attwellc311af12014-10-22 18:28:58 -070061import com.android.contacts.common.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070062import com.android.contacts.common.dialog.ClearFrequentsDialog;
63import com.android.contacts.common.interactions.ImportExportDialogFragment;
Nancy Chen0d3a7392014-08-12 14:44:53 -070064import com.android.contacts.common.interactions.TouchPointManager;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080065import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070066import com.android.contacts.common.widget.FloatingActionButtonController;
Brian Attwellbeab3bb2014-10-27 12:24:49 -070067import com.android.contacts.commonbind.analytics.AnalyticsUtil;
Yorke Leec3766332013-07-31 11:13:16 -070068import com.android.dialer.calllog.CallLogActivity;
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 Lee7d20f822014-06-19 17:09:33 -070085import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070086import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070087import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070088import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070089import com.android.dialerbind.DatabaseHelperManager;
Yorke Lee2fec47b2014-08-05 18:16:27 -070090import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070091import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070092
Yorke Leed5c512a2015-01-30 14:42:53 -080093import junit.framework.Assert;
94
Yorke Leec3766332013-07-31 11:13:16 -070095import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080096import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070097
Chiao Cheng94b10b52012-08-17 16:59:12 -070098/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070099 * The dialer tab's title is 'phone', a more common name (see strings.xml).
100 */
Yorke Leec3766332013-07-31 11:13:16 -0700101public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700102 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700103 OnListFragmentScrolledListener,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700104 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700105 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700106 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700107 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700108 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700109 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700110 ViewPager.OnPageChangeListener,
111 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700112 private static final String TAG = "DialtactsActivity";
113
Ihab Awad526c0b82014-02-27 12:55:36 -0800114 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700115
Yorke Leef74011e2013-08-02 11:30:30 -0700116 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
117
Chiao Cheng94b10b52012-08-17 16:59:12 -0700118 /** @see #getCallOrigin() */
119 private static final String CALL_ORIGIN_DIALTACTS =
120 "com.android.dialer.DialtactsActivity";
121
Yorke Leeb207f8a2013-08-29 18:51:06 -0700122 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
123 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700124 private static final String KEY_SEARCH_QUERY = "search_query";
125 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700126 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700127
Yorke Leec3766332013-07-31 11:13:16 -0700128 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
129 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
130 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
131 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700132
Chiao Cheng94b10b52012-08-17 16:59:12 -0700133 /**
134 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
135 */
136 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
137
Yorke Leec3766332013-07-31 11:13:16 -0700138 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700139
Yorke Leef614f6f2014-10-03 10:44:19 -0700140 private FrameLayout mParentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700141
Yorke Leec3766332013-07-31 11:13:16 -0700142 /**
Yorke Leec3766332013-07-31 11:13:16 -0700143 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700144 */
Evan Charlton72d66252014-11-07 16:23:47 -0800145 protected DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700146
147 /**
148 * Fragment for searching phone numbers using the alphanumeric keyboard.
149 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700150 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700151
152 /**
153 * Fragment for searching phone numbers using the dialpad.
154 */
155 private SmartDialSearchFragment mSmartDialSearchFragment;
156
Yorke Leee00c9fe2014-04-12 12:42:06 -0700157 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700158 * Animation that slides in.
159 */
160 private Animation mSlideIn;
161
162 /**
163 * Animation that slides out.
164 */
165 private Animation mSlideOut;
166
Yorke Lee6c450eb2015-05-08 09:45:47 -0700167 AnimationListenerAdapter mSlideInListener = new AnimationListenerAdapter() {
168 @Override
169 public void onAnimationEnd(Animation animation) {
170 if (!isInSearchUi()) {
171 enterSearchUi(true /* isSmartDial */, mSearchQuery, false);
172 }
173 }
174 };
175
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700176 /**
177 * Listener for after slide out animation completes on dialer fragment.
178 */
179 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
180 @Override
181 public void onAnimationEnd(Animation animation) {
182 commitDialpadFragmentHide();
183 }
184 };
185
186 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700187 * Fragment containing the speed dial list, recents list, and all contacts list.
188 */
189 private ListsFragment mListsFragment;
190
Yorke Lee19e68ca2014-10-28 11:51:40 -0700191 /**
192 * Tracks whether onSaveInstanceState has been called. If true, no fragment transactions can
193 * be commited.
194 */
195 private boolean mStateSaved;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800196 private boolean mIsRestarting;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700197 private boolean mInDialpadSearch;
198 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700199 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700200 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700201 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700202
Yorke Leeef2b7382013-08-09 17:39:25 -0700203 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700204 * Whether or not the device is in landscape orientation.
205 */
206 private boolean mIsLandscape;
207
208 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700209 * True if the dialpad is only temporarily showing due to being in call
210 */
211 private boolean mInCallDialpadUp;
212
213 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700214 * True when this activity has been launched for the first time.
215 */
Yorke Lee98702de2013-08-06 12:03:32 -0700216 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700217
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700218 /**
219 * Search query to be applied to the SearchView in the ActionBar once
220 * onCreateOptionsMenu has been called.
221 */
222 private String mPendingSearchViewQuery;
223
Yorke Lee74edcdc2014-07-11 16:15:08 -0700224 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700225 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700226 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700227
Yorke Leeef2b7382013-08-09 17:39:25 -0700228 private String mSearchQuery;
229
Yorke Leefce269a2013-08-12 11:56:04 -0700230 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700231 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700232 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700233
Sai Cheemalapati41460652014-06-02 21:05:39 -0700234 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700235
Andrew Lee2423a2f2014-05-29 14:14:45 -0700236 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700237
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800238 /**
239 * The text returned from a voice search query. Set in {@link #onActivityResult} and used in
240 * {@link #onResume()} to populate the search box.
241 */
242 private String mVoiceSearchQuery;
243
Andrew Lee467de3d2015-03-17 15:47:24 -0700244 protected class OptionsPopupMenu extends PopupMenu {
Andrew Leee74a10e2014-05-16 14:31:40 -0700245 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700246 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700247 }
248
249 @Override
250 public void show() {
251 final Menu menu = getMenu();
252 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700253 clearFrequents.setVisible(mListsFragment != null &&
254 mListsFragment.getSpeedDialFragment() != null &&
255 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700256 super.show();
257 }
258 }
259
Chiao Cheng94b10b52012-08-17 16:59:12 -0700260 /**
Yorke Lee28266192014-05-01 10:05:52 -0700261 * Listener that listens to drag events and sends their x and y coordinates to a
262 * {@link DragDropController}.
263 */
264 private class LayoutOnDragListener implements OnDragListener {
265 @Override
266 public boolean onDrag(View v, DragEvent event) {
267 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700268 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700269 }
270 return true;
271 }
272 }
273
274 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700275 * Listener used to send search queries to the phone search fragment.
276 */
Yorke Lee53a22302014-04-29 18:13:46 -0700277 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700278 @Override
279 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
280 }
Yorke Leec3766332013-07-31 11:13:16 -0700281
Andrew Lee99a570c2014-05-15 14:18:50 -0700282 @Override
283 public void onTextChanged(CharSequence s, int start, int before, int count) {
284 final String newText = s.toString();
285 if (newText.equals(mSearchQuery)) {
286 // If the query hasn't changed (perhaps due to activity being destroyed
287 // and restored, or user launching the same DIAL intent twice), then there is
288 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700289 return;
290 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700291 if (DEBUG) {
292 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700293 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700294 }
Yorke Lee710709d2014-05-29 07:18:42 -0700295 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700296
Andrew Lee90374a72014-05-16 15:01:09 -0700297 // Show search fragment only when the query string is changed to non-empty text.
298 if (!TextUtils.isEmpty(newText)) {
299 // Call enterSearchUi only if we are switching search modes, or showing a search
300 // fragment for the first time.
301 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
302 (!mIsDialpadShown && mInRegularSearch);
303 if (!sameSearchMode) {
Yorke Lee6c450eb2015-05-08 09:45:47 -0700304 enterSearchUi(mIsDialpadShown, mSearchQuery, true /* animate */);
Andrew Lee90374a72014-05-16 15:01:09 -0700305 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700306 }
307
Andrew Leea8515422014-06-13 16:53:54 -0700308 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700309 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700310 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700311 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700312 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700313 }
314
315 @Override
316 public void afterTextChanged(Editable s) {
317 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700318 };
319
Andrew Leeb1903842014-05-15 16:11:24 -0700320
321 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700322 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700323 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700324 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700325 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700326 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700327 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700328 mActionBarController.onSearchBoxTapped();
Yorke Lee6c450eb2015-05-08 09:45:47 -0700329 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString(),
330 true /* animate */);
Andrew Leeb1903842014-05-15 16:11:24 -0700331 }
Andrew Leeb1903842014-05-15 16:11:24 -0700332 }
333 };
334
335 /**
336 * If the search term is empty and the user closes the soft keyboard, close the search UI.
337 */
338 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
339 @Override
340 public boolean onKey(View v, int keyCode, KeyEvent event) {
341 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
342 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700343 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700344 }
345 return false;
346 }
347 };
348
Chiao Cheng94b10b52012-08-17 16:59:12 -0700349 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700350 public boolean dispatchTouchEvent(MotionEvent ev) {
351 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
352 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
353 }
354 return super.dispatchTouchEvent(ev);
355
356 }
357
358 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700359 protected void onCreate(Bundle savedInstanceState) {
Yorke Leef5554ce2015-01-27 14:46:02 -0800360 Trace.beginSection(TAG + " onCreate");
Yorke Leec3766332013-07-31 11:13:16 -0700361 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700362 mFirstLaunch = true;
363
Andrew Lee2423a2f2014-05-29 14:14:45 -0700364 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700365 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700366
Yorke Leef5554ce2015-01-27 14:46:02 -0800367 Trace.beginSection(TAG + " setContentView");
Yorke Lee8898cd02013-08-08 10:24:27 -0700368 setContentView(R.layout.dialtacts_activity);
Yorke Leef5554ce2015-01-27 14:46:02 -0800369 Trace.endSection();
Yorke Lee9e91bb02014-03-05 17:50:50 -0800370 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700371
Yorke Leef5554ce2015-01-27 14:46:02 -0800372 Trace.beginSection(TAG + " setup Views");
Yorke Lee53a22302014-04-29 18:13:46 -0700373 final ActionBar actionBar = getActionBar();
374 actionBar.setCustomView(R.layout.search_edittext);
375 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700376 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700377
Andrew Lee04675a52014-06-05 18:36:20 -0700378 SearchEditTextLayout searchEditTextLayout =
Andrew Leee3f59a82015-02-26 12:06:35 -0800379 (SearchEditTextLayout) actionBar.getCustomView().findViewById(R.id.search_view_container);
Andrew Lee04675a52014-06-05 18:36:20 -0700380 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
381
Andrew Leee3f59a82015-02-26 12:06:35 -0800382 mActionBarController = new ActionBarController(this, searchEditTextLayout);
383
Andrew Lee04675a52014-06-05 18:36:20 -0700384 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700385 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700386 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
387 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
388 .setOnClickListener(mSearchViewOnClickListener);
389 searchEditTextLayout.findViewById(R.id.search_box_start_search)
390 .setOnClickListener(mSearchViewOnClickListener);
391 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700392 @Override
393 public void onBackButtonClicked() {
394 onBackPressed();
395 }
396 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700397
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700398 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700399 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700400
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700401 final View floatingActionButtonContainer = findViewById(
402 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700403 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
404 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700405 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700406 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700407
Andrew Lee04675a52014-06-05 18:36:20 -0700408 ImageButton optionsMenuButton =
409 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700410 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700411 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
412 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700413
Yorke Leed5c512a2015-01-30 14:42:53 -0800414 // Add the favorites fragment but only if savedInstanceState is null. Otherwise the
415 // fragment manager is responsible for recreating it.
Yorke Leec3766332013-07-31 11:13:16 -0700416 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800417 getFragmentManager().beginTransaction()
Andrew Lee6a866242015-05-05 18:21:45 +0000418 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800419 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700420 } else {
421 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700422 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
423 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700424 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700425 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700426 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700427 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700428
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700429 final boolean isLayoutRtl = DialerUtils.isRtl();
430 if (mIsLandscape) {
431 mSlideIn = AnimationUtils.loadAnimation(this,
432 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
433 mSlideOut = AnimationUtils.loadAnimation(this,
434 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
435 } else {
436 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
437 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
438 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700439
Yorke Lee2fec47b2014-08-05 18:16:27 -0700440 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
441 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
442
Yorke Lee6c450eb2015-05-08 09:45:47 -0700443 mSlideIn.setAnimationListener(mSlideInListener);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700444 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700445
Yorke Leef614f6f2014-10-03 10:44:19 -0700446 mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
447 mParentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700448 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700449 new ViewTreeObserver.OnGlobalLayoutListener() {
450 @Override
451 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700452 final ViewTreeObserver observer =
453 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700454 if (!observer.isAlive()) {
455 return;
456 }
457 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700458 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700459 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700460 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700461 }
462 });
Andrew Lee0c667702014-05-12 14:31:45 -0700463
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700464 setupActivityOverlay();
465
Yorke Leef5554ce2015-01-27 14:46:02 -0800466 Trace.endSection();
467
468 Trace.beginSection(TAG + " initialize smart dialing");
Yorke Lee0baa98b2013-08-22 10:55:16 -0700469 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700470 SmartDialPrefix.initializeNanpSettings(this);
Yorke Leef5554ce2015-01-27 14:46:02 -0800471 Trace.endSection();
472 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700473 }
474
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700475 private void setupActivityOverlay() {
476 final View activityOverlay = findViewById(R.id.activity_overlay);
477 activityOverlay.setOnTouchListener(new OnTouchListener() {
478 @Override
479 public boolean onTouch(View v, MotionEvent event) {
480 if (!mIsDialpadShown) {
481 maybeExitSearchUi();
482 }
483 return false;
484 }
485 });
486 }
487
Chiao Cheng94b10b52012-08-17 16:59:12 -0700488 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700489 protected void onResume() {
Yorke Leef5554ce2015-01-27 14:46:02 -0800490 Trace.beginSection(TAG + " onResume");
Yorke Leec3766332013-07-31 11:13:16 -0700491 super.onResume();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700492 mStateSaved = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700493 if (mFirstLaunch) {
494 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700495 } else if (!phoneIsInUse() && mInCallDialpadUp) {
496 hideDialpadFragment(false, true);
497 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700498 } else if (mShowDialpadOnResume) {
499 showDialpadFragment(false);
500 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700501 }
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800502
503 // If there was a voice query result returned in the {@link #onActivityResult} callback, it
504 // will have been stashed in mVoiceSearchQuery since the search results fragment cannot be
505 // shown until onResume has completed. Active the search UI and set the search term now.
506 if (!TextUtils.isEmpty(mVoiceSearchQuery)) {
507 mActionBarController.onSearchBoxTapped();
508 mSearchView.setText(mVoiceSearchQuery);
509 mVoiceSearchQuery = null;
510 }
511
Yorke Lee98702de2013-08-06 12:03:32 -0700512 mFirstLaunch = false;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800513
514 if (mIsRestarting) {
515 // This is only called when the activity goes from resumed -> paused -> resumed, so it
516 // will not cause an extra view to be sent out on rotation
517 if (mIsDialpadShown) {
518 AnalyticsUtil.sendScreenView(mDialpadFragment, this);
519 }
520 mIsRestarting = false;
521 }
Yorke Lee53a22302014-04-29 18:13:46 -0700522 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700523 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700524 updateFloatingActionButtonControllerAlignment(false /* animate */);
Yorke Leef5554ce2015-01-27 14:46:02 -0800525 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700526 }
527
528 @Override
Yorke Lee7ee5c422014-11-04 10:29:32 -0800529 protected void onRestart() {
530 super.onRestart();
531 mIsRestarting = true;
532 }
533
534 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700535 protected void onPause() {
536 if (mClearSearchOnPause) {
537 hideDialpadAndSearchUi();
538 mClearSearchOnPause = false;
539 }
Yorke Lee19e68ca2014-10-28 11:51:40 -0700540 if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) {
541 commitDialpadFragmentHide();
542 }
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700543 super.onPause();
544 }
545
546 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700547 protected void onSaveInstanceState(Bundle outState) {
548 super.onSaveInstanceState(outState);
549 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700550 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
551 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700552 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700553 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700554 mActionBarController.saveInstanceState(outState);
Yorke Lee19e68ca2014-10-28 11:51:40 -0700555 mStateSaved = true;
Yorke Leeef2b7382013-08-09 17:39:25 -0700556 }
557
558 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700559 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700560 if (fragment instanceof DialpadFragment) {
561 mDialpadFragment = (DialpadFragment) fragment;
Yorke Leed5c512a2015-01-30 14:42:53 -0800562 if (!mIsDialpadShown && !mShowDialpadOnResume) {
Yorke Lee50aba882014-05-28 20:04:31 -0700563 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
564 transaction.hide(mDialpadFragment);
565 transaction.commit();
566 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700567 } else if (fragment instanceof SmartDialSearchFragment) {
568 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700569 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700570 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700571 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700572 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700573 } else if (fragment instanceof ListsFragment) {
574 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700575 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700576 }
Yorke Leec3766332013-07-31 11:13:16 -0700577 }
578
Alon Albertb453e5b2013-09-10 15:54:23 -0700579 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700580 final Intent intent = new Intent(this, DialerSettingsActivity.class);
581 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700582 }
583
Chiao Cheng94b10b52012-08-17 16:59:12 -0700584 @Override
585 public void onClick(View view) {
586 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700587 case R.id.floating_action_button:
Andrew Lee432d4b52015-05-20 16:52:00 -0700588 if (mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
Andrew Lee247df6e2015-05-12 19:09:00 -0700589 DialerUtils.startActivityWithErrorToast(
590 this,
591 IntentUtil.getNewContactIntent(),
592 R.string.add_contact_not_available);
Andrew Leefdfeaaf2015-05-05 14:10:35 -0700593 } else if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700594 mInCallDialpadUp = false;
595 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700596 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700597 break;
Yorke Leec3766332013-07-31 11:13:16 -0700598 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800599 try {
600 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
601 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
602 } catch (ActivityNotFoundException e) {
603 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
604 Toast.LENGTH_SHORT).show();
605 }
Yorke Leec3766332013-07-31 11:13:16 -0700606 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700607 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700608 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700609 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700610 default: {
611 Log.wtf(TAG, "Unexpected onClick event from " + view);
612 break;
613 }
614 }
615 }
616
Yorke Leec3766332013-07-31 11:13:16 -0700617 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700618 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700619 switch (item.getItemId()) {
620 case R.id.menu_history:
Andrew Lee69705be2015-05-04 17:24:01 -0700621 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
622 // CONTENT_TYPE, so that we always open our call log from our dialer
623 final Intent intent = new Intent(this, CallLogActivity.class);
624 startActivity(intent);
Yorke Lee86e21f72014-04-02 16:49:38 -0700625 break;
626 case R.id.menu_add_contact:
Andrew Lee247df6e2015-05-12 19:09:00 -0700627 DialerUtils.startActivityWithErrorToast(
628 this,
629 IntentUtil.getNewContactIntent(),
630 R.string.add_contact_not_available);
Yorke Lee86e21f72014-04-02 16:49:38 -0700631 break;
632 case R.id.menu_import_export:
633 // We hard-code the "contactsAreAvailable" argument because doing it properly would
634 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
635 // now in Dialtacts for (potential) performance reasons. Compare with how it is
636 // done in {@link PeopleActivity}.
637 ImportExportDialogFragment.show(getFragmentManager(), true,
638 DialtactsActivity.class);
639 return true;
640 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700641 ClearFrequentsDialog.show(getFragmentManager());
642 return true;
643 case R.id.menu_call_settings:
644 handleMenuSettings();
645 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700646 }
647 return false;
648 }
649
650 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700651 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
652 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
653 if (resultCode == RESULT_OK) {
654 final ArrayList<String> matches = data.getStringArrayListExtra(
655 RecognizerIntent.EXTRA_RESULTS);
656 if (matches.size() > 0) {
657 final String match = matches.get(0);
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800658 mVoiceSearchQuery = match;
Yorke Leec3766332013-07-31 11:13:16 -0700659 } else {
660 Log.e(TAG, "Voice search - nothing heard");
661 }
662 } else {
663 Log.e(TAG, "Voice search failed");
664 }
665 }
666 super.onActivityResult(requestCode, resultCode, data);
667 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700668
Andrew Lee2a58ab82014-05-15 02:16:04 -0700669 /**
670 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
671 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
672 * @see #onDialpadShown
673 */
Yorke Leec3766332013-07-31 11:13:16 -0700674 private void showDialpadFragment(boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700675 if (mIsDialpadShown || mStateSaved) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700676 return;
677 }
678 mIsDialpadShown = true;
Yorke Leed5c512a2015-01-30 14:42:53 -0800679
Yorke Lee7ee5c422014-11-04 10:29:32 -0800680 mListsFragment.setUserVisibleHint(false);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700681
Chiao Cheng94b10b52012-08-17 16:59:12 -0700682 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leed5c512a2015-01-30 14:42:53 -0800683 if (mDialpadFragment == null) {
684 mDialpadFragment = new DialpadFragment();
685 ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT);
686 } else {
687 ft.show(mDialpadFragment);
688 }
689
690 mDialpadFragment.setAnimate(animate);
691 AnalyticsUtil.sendScreenView(mDialpadFragment);
Yorke Leec3766332013-07-31 11:13:16 -0700692 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700693
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700694 if (animate) {
695 mFloatingActionButtonController.scaleOut();
696 } else {
697 mFloatingActionButtonController.setVisible(false);
698 }
Yorke Lee5253be02014-05-21 18:50:03 -0700699 mActionBarController.onDialpadUp();
700
Yorke Lee6c450eb2015-05-08 09:45:47 -0700701 mListsFragment.getView().animate().alpha(0).withLayer();
Yorke Leec3766332013-07-31 11:13:16 -0700702 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700703
Andrew Lee2a58ab82014-05-15 02:16:04 -0700704 /**
705 * Callback from child DialpadFragment when the dialpad is shown.
706 */
707 public void onDialpadShown() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800708 Assert.assertNotNull(mDialpadFragment);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700709 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700710 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700711 } else {
712 mDialpadFragment.setYFraction(0);
713 }
714
Andrew Lee2a58ab82014-05-15 02:16:04 -0700715 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700716 }
717
718 /**
719 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
720 * a callback after the hide animation ends.
721 * @see #commitDialpadFragmentHide
722 */
Yorke Leeca195042013-09-25 16:29:38 -0700723 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Yorke Lee791b4882015-05-15 10:52:27 -0700724 if (mDialpadFragment == null || mDialpadFragment.getView() == null) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700725 return;
726 }
Yorke Leef6673d32013-08-23 15:34:17 -0700727 if (clearDialpad) {
728 mDialpadFragment.clearDialpad();
729 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700730 if (!mIsDialpadShown) {
731 return;
Yorke Leec3766332013-07-31 11:13:16 -0700732 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700733 mIsDialpadShown = false;
734 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800735 mListsFragment.setUserVisibleHint(true);
736 mListsFragment.sendScreenViewForCurrentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700737
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700738 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700739
740 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700741 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700742 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700743 } else {
744 commitDialpadFragmentHide();
745 }
746
Yorke Lee5253be02014-05-21 18:50:03 -0700747 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700748
Andrew Leed4cde832014-05-16 15:56:48 -0700749 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700750 if (TextUtils.isEmpty(mSearchQuery)) {
751 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700752 }
Andrew Leed4cde832014-05-16 15:56:48 -0700753 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700754 }
755
756 /**
757 * Finishes hiding the dialpad fragment after any animations are completed.
758 */
759 private void commitDialpadFragmentHide() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800760 if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700761 final FragmentTransaction ft = getFragmentManager().beginTransaction();
762 ft.hide(mDialpadFragment);
763 ft.commit();
764 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700765 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700766 }
767
Andrew Lee2a58ab82014-05-15 02:16:04 -0700768 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700769 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700770 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700771 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700772 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700773 fragment = mRegularSearchFragment;
774 }
775 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700776 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700777 }
778 }
779
Yorke Lee5253be02014-05-21 18:50:03 -0700780 @Override
781 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700782 return mInDialpadSearch || mInRegularSearch;
783 }
784
Yorke Lee5253be02014-05-21 18:50:03 -0700785 @Override
786 public boolean hasSearchQuery() {
787 return !TextUtils.isEmpty(mSearchQuery);
788 }
789
790 @Override
791 public boolean shouldShowActionBar() {
792 return mListsFragment.shouldShowActionBar();
793 }
794
Yorke Leeb207f8a2013-08-29 18:51:06 -0700795 private void setNotInSearchUi() {
796 mInDialpadSearch = false;
797 mInRegularSearch = false;
798 }
799
Yorke Lee311969c2013-08-26 06:31:11 -0700800 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700801 if (mIsDialpadShown) {
802 hideDialpadFragment(false, true);
803 } else {
804 exitSearchUi();
805 }
Yorke Lee311969c2013-08-26 06:31:11 -0700806 }
807
Yorke Lee53a22302014-04-29 18:13:46 -0700808 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700809 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
810 if (canIntentBeHandled(voiceIntent)) {
811 mVoiceSearchButton.setVisibility(View.VISIBLE);
812 mVoiceSearchButton.setOnClickListener(this);
813 } else {
814 mVoiceSearchButton.setVisibility(View.GONE);
815 }
816 }
817
Andrew Lee467de3d2015-03-17 15:47:24 -0700818 protected OptionsPopupMenu buildOptionsMenu(View invoker) {
Andrew Leee74a10e2014-05-16 14:31:40 -0700819 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
820 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700821 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700822 popupMenu.setOnMenuItemClickListener(this);
823 return popupMenu;
824 }
825
Yorke Lee86e21f72014-04-02 16:49:38 -0700826 @Override
827 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700828 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700829 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700830 mPendingSearchViewQuery = null;
831 }
Yorke Leea524ae52014-08-05 18:01:05 -0700832 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700833 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700834 }
835
Chiao Cheng94b10b52012-08-17 16:59:12 -0700836 /**
837 * Returns true if the intent is due to hitting the green send key (hardware call button:
838 * KEYCODE_CALL) while in a call.
839 *
840 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700841 * @return true if the intent is due to hitting the green send key while in a call
842 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700843 private boolean isSendKeyWhileInCall(Intent intent) {
844 // If there is a call in progress and the user launched the dialer by hitting the call
845 // button, go straight to the in-call screen.
846 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700847
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700848 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700849 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700850 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700851 }
852
853 return false;
854 }
855
856 /**
857 * Sets the current tab based on the intent's request type
858 *
859 * @param intent Intent that contains information about which tab should be selected
860 */
Yorke Leec3766332013-07-31 11:13:16 -0700861 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700862 // 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 -0700863 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700864 finish();
865 return;
866 }
867
Yorke Leed5c512a2015-01-30 14:42:53 -0800868 final boolean phoneIsInUse = phoneIsInUse();
869 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
870 showDialpadFragment(false);
871 mDialpadFragment.setStartedFromNewIntent(true);
872 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
873 mInCallDialpadUp = true;
Yorke Lee35127cd2013-09-10 14:09:29 -0700874 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700875 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700876 }
877
878 @Override
879 public void onNewIntent(Intent newIntent) {
880 setIntent(newIntent);
Nancy Chen199b7f02014-11-05 15:03:00 -0800881 mStateSaved = false;
Yorke Leec3766332013-07-31 11:13:16 -0700882 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700883
Chiao Cheng94b10b52012-08-17 16:59:12 -0700884 invalidateOptionsMenu();
885 }
886
887 /** Returns true if the given intent contains a phone number to populate the dialer with */
888 private boolean isDialIntent(Intent intent) {
889 final String action = intent.getAction();
890 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
891 return true;
892 }
893 if (Intent.ACTION_VIEW.equals(action)) {
894 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700895 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700896 return true;
897 }
898 }
899 return false;
900 }
901
902 /**
903 * Returns an appropriate call origin for this Activity. May return null when no call origin
904 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
905 * for remembering the tab in which the user made a phone call, so the external app's DIAL
906 * request should not be counted.)
907 */
908 public String getCallOrigin() {
909 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
910 }
911
Chiao Cheng94b10b52012-08-17 16:59:12 -0700912 /**
Yorke Leec3766332013-07-31 11:13:16 -0700913 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700914 */
Yorke Lee6c450eb2015-05-08 09:45:47 -0700915 private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700916 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700917 // Weird race condition where fragment is doing work after the activity is destroyed
918 // due to talkback being on (b/10209937). Just return since we can't do any
919 // constructive here.
920 return;
921 }
922
Yorke Leeef2b7382013-08-09 17:39:25 -0700923 if (DEBUG) {
924 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
925 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700926
Yorke Leec3766332013-07-31 11:13:16 -0700927 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700928 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700929 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700930 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700931 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700932 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700933
Yorke Leeb207f8a2013-08-29 18:51:06 -0700934 final String tag;
935 if (smartDialSearch) {
936 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
937 } else {
938 tag = TAG_REGULAR_SEARCH_FRAGMENT;
939 }
940 mInDialpadSearch = smartDialSearch;
941 mInRegularSearch = !smartDialSearch;
942
Andrew Lee752956e2014-05-15 11:43:38 -0700943 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Yorke Lee6c450eb2015-05-08 09:45:47 -0700944 if (animate) {
945 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
946 } else {
947 transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
948 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700949 if (fragment == null) {
950 if (smartDialSearch) {
951 fragment = new SmartDialSearchFragment();
952 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700953 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700954 }
Andrew Leeb1903842014-05-15 16:11:24 -0700955 transaction.add(R.id.dialtacts_frame, fragment, tag);
956 } else {
957 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700958 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700959 // DialtactsActivity will provide the options menu
960 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700961 fragment.setShowEmptyListForNullQuery(true);
Yorke Lee6c450eb2015-05-08 09:45:47 -0700962 if (!smartDialSearch) {
963 fragment.setQueryString(query, false /* delaySelection */);
964 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700965 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700966
Yorke Lee6c450eb2015-05-08 09:45:47 -0700967 if (animate) {
968 mListsFragment.getView().animate().alpha(0).withLayer();
969 }
Yorke Lee7ee5c422014-11-04 10:29:32 -0800970 mListsFragment.setUserVisibleHint(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700971 }
972
973 /**
Yorke Leec3766332013-07-31 11:13:16 -0700974 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700975 */
Yorke Leec3766332013-07-31 11:13:16 -0700976 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700977 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700978 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -0700979 return;
980 }
Andrew Leeb1903842014-05-15 16:11:24 -0700981
Andrew Leeb1903842014-05-15 16:11:24 -0700982 mSearchView.setText(null);
Yorke Leed5c512a2015-01-30 14:42:53 -0800983
984 if (mDialpadFragment != null) {
985 mDialpadFragment.clearDialpad();
986 }
987
Yorke Leeb207f8a2013-08-29 18:51:06 -0700988 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700989
Andrew Leeb1903842014-05-15 16:11:24 -0700990 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700991 if (mSmartDialSearchFragment != null) {
992 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700993 }
Andrew Leeb1903842014-05-15 16:11:24 -0700994 if (mRegularSearchFragment != null) {
995 transaction.remove(mRegularSearchFragment);
996 }
997 transaction.commit();
998
999 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Leed5c512a2015-01-30 14:42:53 -08001000
1001 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
Yorke Lee7ee5c422014-11-04 10:29:32 -08001002 // If the dialpad fragment wasn't previously visible, then send a screen view because
1003 // we are exiting regular search. Otherwise, the screen view will be sent by
1004 // {@link #hideDialpadFragment}.
1005 mListsFragment.sendScreenViewForCurrentPosition();
1006 mListsFragment.setUserVisibleHint(true);
1007 }
1008
Yorke Lee5253be02014-05-21 18:50:03 -07001009 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001010 }
1011
Chiao Cheng94b10b52012-08-17 16:59:12 -07001012 @Override
Yorke Leec3766332013-07-31 11:13:16 -07001013 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -07001014 if (mStateSaved) {
1015 return;
1016 }
Andrew Lee2a58ab82014-05-15 02:16:04 -07001017 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -07001018 if (TextUtils.isEmpty(mSearchQuery) ||
1019 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
1020 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -07001021 exitSearchUi();
1022 }
Yorke Leef6673d32013-08-23 15:34:17 -07001023 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -07001024 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -07001025 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001026 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001027 } else {
1028 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001029 }
Yorke Leec3766332013-07-31 11:13:16 -07001030 }
1031
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001032 /**
1033 * @return True if the search UI was exited, false otherwise
1034 */
1035 private boolean maybeExitSearchUi() {
1036 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
1037 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001038 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001039 return true;
1040 }
1041 return false;
1042 }
1043
Yorke Leec3766332013-07-31 11:13:16 -07001044 @Override
1045 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -07001046 if (mSmartDialSearchFragment != null) {
1047 mSmartDialSearchFragment.setAddToContactNumber(query);
1048 }
Yorke Leec3766332013-07-31 11:13:16 -07001049 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
1050 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -07001051
1052 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001053 if (DEBUG) {
1054 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1055 }
1056 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1057 // This callback can happen if the dialpad fragment is recreated because of
1058 // activity destruction. In that case, don't update the search view because
1059 // that would bring the user back to the search fragment regardless of the
1060 // previous state of the application. Instead, just return here and let the
1061 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001062 if (!TextUtils.isEmpty(normalizedQuery)) {
1063 mPendingSearchViewQuery = normalizedQuery;
1064 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001065 return;
1066 }
Yorke Lee53a22302014-04-29 18:13:46 -07001067 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001068 }
1069 }
Yorke Leec3766332013-07-31 11:13:16 -07001070
1071 @Override
1072 public void onListFragmentScrollStateChange(int scrollState) {
1073 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001074 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -07001075 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001076 }
1077 }
1078
1079 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001080 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001081 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001082 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1083 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001084 }
1085
Yorke Leec3766332013-07-31 11:13:16 -07001086 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001087 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001088 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001089
Yorke Leeda0f9042013-12-05 14:25:51 -08001090 private boolean canIntentBeHandled(Intent intent) {
1091 final PackageManager packageManager = getPackageManager();
1092 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1093 PackageManager.MATCH_DEFAULT_ONLY);
1094 return resolveInfo != null && resolveInfo.size() > 0;
1095 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001096
Yorke Lee86e21f72014-04-02 16:49:38 -07001097 /**
1098 * Called when the user has long-pressed a contact tile to start a drag operation.
1099 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001100 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001101 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Lee18963442014-06-06 17:20:13 -07001102 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001103 }
1104
1105 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001106 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1107 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001108
Yorke Lee86e21f72014-04-02 16:49:38 -07001109 /**
1110 * Called when the user has released a contact tile after long-pressing it.
1111 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001112 @Override
1113 public void onDragFinished(int x, int y) {
Andrew Lee18963442014-06-06 17:20:13 -07001114 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001115 }
1116
1117 @Override
1118 public void onDroppedOnRemove() {}
1119
1120 /**
Yorke Leed999b712014-04-23 15:10:58 -07001121 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001122 * once it has been attached to the activity.
1123 */
1124 @Override
1125 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001126 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001127 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001128 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001129
1130 @Override
1131 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001132 // Specify call-origin so that users will see the previous tab instead of
1133 // CallLog screen (search UI will be automatically exited).
1134 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001135 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001136 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001137 }
1138
1139 @Override
1140 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001141 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1142 }
1143
1144 @Override
1145 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001146 Intent intent = isVideoCall ?
Andrew Lee247df6e2015-05-12 19:09:00 -07001147 IntentUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1148 IntentUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001149 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001150 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001151 }
1152
1153 @Override
1154 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001155 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001156 }
1157
1158 @Override
1159 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001160 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001161 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001162
Yorke Leecc4660d2014-04-24 11:22:57 -07001163 @Override
1164 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Andrew Lee432d4b52015-05-20 16:52:00 -07001165 int tabIndex = mListsFragment.getCurrentTabIndex();
1166
1167 // Scroll the button from center to end when moving from the Speed Dial to Recents tab.
1168 // In RTL, scroll when the current tab is Recents instead of Speed Dial, because the order
1169 // of the tabs is reversed and the ViewPager returns the left tab position during scroll.
1170 boolean isRtl = DialerUtils.isRtl();
1171 if (!isRtl && tabIndex == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
1172 mFloatingActionButtonController.onPageScrolled(positionOffset);
1173 } else if (isRtl && tabIndex == ListsFragment.TAB_INDEX_RECENTS && !mIsLandscape) {
1174 mFloatingActionButtonController.onPageScrolled(1 - positionOffset);
1175 } else if (tabIndex != ListsFragment.TAB_INDEX_SPEED_DIAL) {
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001176 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001177 }
Andrew Lee432d4b52015-05-20 16:52:00 -07001178 }
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001179
Andrew Lee432d4b52015-05-20 16:52:00 -07001180 @Override
1181 public void onPageSelected(int position) {
1182 int tabIndex = mListsFragment.getCurrentTabIndex();
1183 if (tabIndex == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001184 mFloatingActionButtonController.changeIcon(
1185 getResources().getDrawable(R.drawable.ic_person_add_24dp),
1186 getResources().getString(R.string.search_shortcut_create_new_contact));
1187 } else {
1188 mFloatingActionButtonController.changeIcon(
1189 getResources().getDrawable(R.drawable.fab_ic_dial),
1190 getResources().getString(R.string.action_menu_dialpad_button));
1191 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001192 }
1193
1194 @Override
Yorke Leecc4660d2014-04-24 11:22:57 -07001195 public void onPageScrollStateChanged(int state) {
1196 }
1197
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001198 private TelecomManager getTelecomManager() {
1199 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001200 }
1201
Yorke Lee5253be02014-05-21 18:50:03 -07001202 @Override
1203 public boolean isActionBarShowing() {
1204 return mActionBarController.isActionBarShowing();
1205 }
1206
Yorke Leec98a5bb2014-10-28 16:12:05 -07001207 @Override
1208 public ActionBarController getActionBarController() {
1209 return mActionBarController;
1210 }
1211
Andrew Lee9da8fb42014-06-03 14:03:09 -07001212 public boolean isDialpadShown() {
1213 return mIsDialpadShown;
1214 }
1215
Yorke Lee5253be02014-05-21 18:50:03 -07001216 @Override
1217 public int getActionBarHideOffset() {
1218 return getActionBar().getHideOffset();
1219 }
1220
1221 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001222 public void setActionBarHideOffset(int offset) {
1223 getActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001224 }
1225
1226 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001227 public int getActionBarHeight() {
1228 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001229 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001230
1231 /**
1232 * Updates controller based on currently known information.
1233 *
1234 * @param animate Whether or not to animate the transition.
1235 */
1236 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001237 int align = (!mIsLandscape &&
Andrew Lee432d4b52015-05-20 16:52:00 -07001238 mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
Andrew Lee405a6e62014-08-20 15:02:16 -07001239 FloatingActionButtonController.ALIGN_MIDDLE :
1240 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001241 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001242 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001243}