blob: e240cf0aa8b8c2e9df86c7c96f9e5122c9bc7e86 [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 Leee00c9fe2014-04-12 12:42:06 -0700260 super.show();
261 }
262 }
263
Chiao Cheng94b10b52012-08-17 16:59:12 -0700264 /**
Yorke Lee28266192014-05-01 10:05:52 -0700265 * Listener that listens to drag events and sends their x and y coordinates to a
266 * {@link DragDropController}.
267 */
268 private class LayoutOnDragListener implements OnDragListener {
269 @Override
270 public boolean onDrag(View v, DragEvent event) {
271 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700272 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700273 }
274 return true;
275 }
276 }
277
278 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700279 * Listener used to send search queries to the phone search fragment.
280 */
Yorke Lee53a22302014-04-29 18:13:46 -0700281 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700282 @Override
283 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
284 }
Yorke Leec3766332013-07-31 11:13:16 -0700285
Andrew Lee99a570c2014-05-15 14:18:50 -0700286 @Override
287 public void onTextChanged(CharSequence s, int start, int before, int count) {
288 final String newText = s.toString();
289 if (newText.equals(mSearchQuery)) {
290 // If the query hasn't changed (perhaps due to activity being destroyed
291 // and restored, or user launching the same DIAL intent twice), then there is
292 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700293 return;
294 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700295 if (DEBUG) {
296 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700297 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700298 }
Yorke Lee710709d2014-05-29 07:18:42 -0700299 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700300
Andrew Lee90374a72014-05-16 15:01:09 -0700301 // Show search fragment only when the query string is changed to non-empty text.
302 if (!TextUtils.isEmpty(newText)) {
303 // Call enterSearchUi only if we are switching search modes, or showing a search
304 // fragment for the first time.
305 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
306 (!mIsDialpadShown && mInRegularSearch);
307 if (!sameSearchMode) {
Yorke Lee6c450eb2015-05-08 09:45:47 -0700308 enterSearchUi(mIsDialpadShown, mSearchQuery, true /* animate */);
Andrew Lee90374a72014-05-16 15:01:09 -0700309 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700310 }
311
Andrew Leea8515422014-06-13 16:53:54 -0700312 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700313 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700314 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700315 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700316 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700317 }
318
319 @Override
320 public void afterTextChanged(Editable s) {
321 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700322 };
323
Andrew Leeb1903842014-05-15 16:11:24 -0700324
325 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700326 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700327 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700328 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700329 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700330 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700331 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700332 mActionBarController.onSearchBoxTapped();
Yorke Lee6c450eb2015-05-08 09:45:47 -0700333 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString(),
334 true /* animate */);
Andrew Leeb1903842014-05-15 16:11:24 -0700335 }
Andrew Leeb1903842014-05-15 16:11:24 -0700336 }
337 };
338
339 /**
340 * If the search term is empty and the user closes the soft keyboard, close the search UI.
341 */
342 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
343 @Override
344 public boolean onKey(View v, int keyCode, KeyEvent event) {
345 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
346 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700347 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700348 }
349 return false;
350 }
351 };
352
Chiao Cheng94b10b52012-08-17 16:59:12 -0700353 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700354 public boolean dispatchTouchEvent(MotionEvent ev) {
355 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
356 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
357 }
358 return super.dispatchTouchEvent(ev);
359
360 }
361
362 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700363 protected void onCreate(Bundle savedInstanceState) {
Yorke Leef5554ce2015-01-27 14:46:02 -0800364 Trace.beginSection(TAG + " onCreate");
Yorke Leec3766332013-07-31 11:13:16 -0700365 super.onCreate(savedInstanceState);
Yorke Leec16ea5a2015-05-19 15:51:01 -0700366
Yorke Lee98702de2013-08-06 12:03:32 -0700367 mFirstLaunch = true;
368
Andrew Lee2423a2f2014-05-29 14:14:45 -0700369 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700370 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700371
Yorke Leef5554ce2015-01-27 14:46:02 -0800372 Trace.beginSection(TAG + " setContentView");
Yorke Lee8898cd02013-08-08 10:24:27 -0700373 setContentView(R.layout.dialtacts_activity);
Yorke Leef5554ce2015-01-27 14:46:02 -0800374 Trace.endSection();
Yorke Lee9e91bb02014-03-05 17:50:50 -0800375 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700376
Yorke Leef5554ce2015-01-27 14:46:02 -0800377 Trace.beginSection(TAG + " setup Views");
Yorke Lee53a22302014-04-29 18:13:46 -0700378 final ActionBar actionBar = getActionBar();
379 actionBar.setCustomView(R.layout.search_edittext);
380 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700381 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700382
Andrew Lee04675a52014-06-05 18:36:20 -0700383 SearchEditTextLayout searchEditTextLayout =
Andrew Leee3f59a82015-02-26 12:06:35 -0800384 (SearchEditTextLayout) actionBar.getCustomView().findViewById(R.id.search_view_container);
Andrew Lee04675a52014-06-05 18:36:20 -0700385 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
386
Andrew Leee3f59a82015-02-26 12:06:35 -0800387 mActionBarController = new ActionBarController(this, searchEditTextLayout);
388
Andrew Lee04675a52014-06-05 18:36:20 -0700389 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700390 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700391 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
392 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
393 .setOnClickListener(mSearchViewOnClickListener);
394 searchEditTextLayout.findViewById(R.id.search_box_start_search)
395 .setOnClickListener(mSearchViewOnClickListener);
396 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700397 @Override
398 public void onBackButtonClicked() {
399 onBackPressed();
400 }
401 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700402
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700403 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700404 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700405
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700406 final View floatingActionButtonContainer = findViewById(
407 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700408 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
409 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700410 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700411 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700412
Andrew Lee04675a52014-06-05 18:36:20 -0700413 ImageButton optionsMenuButton =
414 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700415 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700416 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
417 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700418
Yorke Leed5c512a2015-01-30 14:42:53 -0800419 // Add the favorites fragment but only if savedInstanceState is null. Otherwise the
420 // fragment manager is responsible for recreating it.
Yorke Leec3766332013-07-31 11:13:16 -0700421 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800422 getFragmentManager().beginTransaction()
Andrew Lee6a866242015-05-05 18:21:45 +0000423 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800424 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700425 } else {
426 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700427 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
428 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700429 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700430 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700431 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700432 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700433
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700434 final boolean isLayoutRtl = DialerUtils.isRtl();
435 if (mIsLandscape) {
436 mSlideIn = AnimationUtils.loadAnimation(this,
437 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
438 mSlideOut = AnimationUtils.loadAnimation(this,
439 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
440 } else {
441 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
442 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
443 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700444
Yorke Lee2fec47b2014-08-05 18:16:27 -0700445 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
446 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
447
Yorke Lee6c450eb2015-05-08 09:45:47 -0700448 mSlideIn.setAnimationListener(mSlideInListener);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700449 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700450
Yorke Leef614f6f2014-10-03 10:44:19 -0700451 mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
452 mParentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700453 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700454 new ViewTreeObserver.OnGlobalLayoutListener() {
455 @Override
456 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700457 final ViewTreeObserver observer =
458 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700459 if (!observer.isAlive()) {
460 return;
461 }
462 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700463 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700464 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700465 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700466 }
467 });
Andrew Lee0c667702014-05-12 14:31:45 -0700468
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700469 setupActivityOverlay();
470
Yorke Leef5554ce2015-01-27 14:46:02 -0800471 Trace.endSection();
472
473 Trace.beginSection(TAG + " initialize smart dialing");
Yorke Lee0baa98b2013-08-22 10:55:16 -0700474 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700475 SmartDialPrefix.initializeNanpSettings(this);
Yorke Leef5554ce2015-01-27 14:46:02 -0800476 Trace.endSection();
477 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700478 }
479
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700480 private void setupActivityOverlay() {
481 final View activityOverlay = findViewById(R.id.activity_overlay);
482 activityOverlay.setOnTouchListener(new OnTouchListener() {
483 @Override
484 public boolean onTouch(View v, MotionEvent event) {
485 if (!mIsDialpadShown) {
486 maybeExitSearchUi();
487 }
488 return false;
489 }
490 });
491 }
492
Chiao Cheng94b10b52012-08-17 16:59:12 -0700493 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700494 protected void onResume() {
Yorke Leef5554ce2015-01-27 14:46:02 -0800495 Trace.beginSection(TAG + " onResume");
Yorke Leec3766332013-07-31 11:13:16 -0700496 super.onResume();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700497 mStateSaved = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700498 if (mFirstLaunch) {
499 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700500 } else if (!phoneIsInUse() && mInCallDialpadUp) {
501 hideDialpadFragment(false, true);
502 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700503 } else if (mShowDialpadOnResume) {
504 showDialpadFragment(false);
505 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700506 }
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800507
508 // If there was a voice query result returned in the {@link #onActivityResult} callback, it
509 // will have been stashed in mVoiceSearchQuery since the search results fragment cannot be
510 // shown until onResume has completed. Active the search UI and set the search term now.
511 if (!TextUtils.isEmpty(mVoiceSearchQuery)) {
512 mActionBarController.onSearchBoxTapped();
513 mSearchView.setText(mVoiceSearchQuery);
514 mVoiceSearchQuery = null;
515 }
516
Yorke Lee98702de2013-08-06 12:03:32 -0700517 mFirstLaunch = false;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800518
519 if (mIsRestarting) {
520 // This is only called when the activity goes from resumed -> paused -> resumed, so it
521 // will not cause an extra view to be sent out on rotation
522 if (mIsDialpadShown) {
523 AnalyticsUtil.sendScreenView(mDialpadFragment, this);
524 }
525 mIsRestarting = false;
526 }
Yorke Lee53a22302014-04-29 18:13:46 -0700527 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700528 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700529 updateFloatingActionButtonControllerAlignment(false /* animate */);
Yorke Leef5554ce2015-01-27 14:46:02 -0800530 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700531 }
532
533 @Override
Yorke Lee7ee5c422014-11-04 10:29:32 -0800534 protected void onRestart() {
535 super.onRestart();
536 mIsRestarting = true;
537 }
538
539 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700540 protected void onPause() {
541 if (mClearSearchOnPause) {
542 hideDialpadAndSearchUi();
543 mClearSearchOnPause = false;
544 }
Yorke Lee19e68ca2014-10-28 11:51:40 -0700545 if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) {
546 commitDialpadFragmentHide();
547 }
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700548 super.onPause();
549 }
550
551 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700552 protected void onSaveInstanceState(Bundle outState) {
553 super.onSaveInstanceState(outState);
554 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700555 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
556 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700557 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700558 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700559 mActionBarController.saveInstanceState(outState);
Yorke Lee19e68ca2014-10-28 11:51:40 -0700560 mStateSaved = true;
Yorke Leeef2b7382013-08-09 17:39:25 -0700561 }
562
563 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700564 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700565 if (fragment instanceof DialpadFragment) {
566 mDialpadFragment = (DialpadFragment) fragment;
Yorke Leed5c512a2015-01-30 14:42:53 -0800567 if (!mIsDialpadShown && !mShowDialpadOnResume) {
Yorke Lee50aba882014-05-28 20:04:31 -0700568 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
569 transaction.hide(mDialpadFragment);
570 transaction.commit();
571 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700572 } else if (fragment instanceof SmartDialSearchFragment) {
573 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700574 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700575 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700576 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700577 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700578 } else if (fragment instanceof ListsFragment) {
579 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700580 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700581 }
Yorke Leec3766332013-07-31 11:13:16 -0700582 }
583
Alon Albertb453e5b2013-09-10 15:54:23 -0700584 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700585 final Intent intent = new Intent(this, DialerSettingsActivity.class);
586 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700587 }
588
Chiao Cheng94b10b52012-08-17 16:59:12 -0700589 @Override
590 public void onClick(View view) {
591 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700592 case R.id.floating_action_button:
Andrew Leefdfeaaf2015-05-05 14:10:35 -0700593 if (mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
Andrew Lee247df6e2015-05-12 19:09:00 -0700594 DialerUtils.startActivityWithErrorToast(
595 this,
596 IntentUtil.getNewContactIntent(),
597 R.string.add_contact_not_available);
Andrew Leefdfeaaf2015-05-05 14:10:35 -0700598 } else if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700599 mInCallDialpadUp = false;
600 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700601 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700602 break;
Yorke Leec3766332013-07-31 11:13:16 -0700603 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800604 try {
605 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
606 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
607 } catch (ActivityNotFoundException e) {
608 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
609 Toast.LENGTH_SHORT).show();
610 }
Yorke Leec3766332013-07-31 11:13:16 -0700611 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700612 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700613 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700614 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700615 default: {
616 Log.wtf(TAG, "Unexpected onClick event from " + view);
617 break;
618 }
619 }
620 }
621
Yorke Leec3766332013-07-31 11:13:16 -0700622 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700623 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700624 switch (item.getItemId()) {
625 case R.id.menu_history:
Andrew Lee69705be2015-05-04 17:24:01 -0700626 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
627 // CONTENT_TYPE, so that we always open our call log from our dialer
628 final Intent intent = new Intent(this, CallLogActivity.class);
629 startActivity(intent);
Yorke Lee86e21f72014-04-02 16:49:38 -0700630 break;
631 case R.id.menu_add_contact:
Andrew Lee247df6e2015-05-12 19:09:00 -0700632 DialerUtils.startActivityWithErrorToast(
633 this,
634 IntentUtil.getNewContactIntent(),
635 R.string.add_contact_not_available);
Yorke Lee86e21f72014-04-02 16:49:38 -0700636 break;
637 case R.id.menu_import_export:
638 // We hard-code the "contactsAreAvailable" argument because doing it properly would
639 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
640 // now in Dialtacts for (potential) performance reasons. Compare with how it is
641 // done in {@link PeopleActivity}.
642 ImportExportDialogFragment.show(getFragmentManager(), true,
643 DialtactsActivity.class);
644 return true;
645 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700646 ClearFrequentsDialog.show(getFragmentManager());
647 return true;
648 case R.id.menu_call_settings:
649 handleMenuSettings();
650 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700651 }
652 return false;
653 }
654
655 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700656 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
657 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
658 if (resultCode == RESULT_OK) {
659 final ArrayList<String> matches = data.getStringArrayListExtra(
660 RecognizerIntent.EXTRA_RESULTS);
661 if (matches.size() > 0) {
662 final String match = matches.get(0);
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800663 mVoiceSearchQuery = match;
Yorke Leec3766332013-07-31 11:13:16 -0700664 } else {
665 Log.e(TAG, "Voice search - nothing heard");
666 }
667 } else {
668 Log.e(TAG, "Voice search failed");
669 }
670 }
671 super.onActivityResult(requestCode, resultCode, data);
672 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700673
Andrew Lee2a58ab82014-05-15 02:16:04 -0700674 /**
675 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
676 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
677 * @see #onDialpadShown
678 */
Yorke Leec3766332013-07-31 11:13:16 -0700679 private void showDialpadFragment(boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700680 if (mIsDialpadShown || mStateSaved) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700681 return;
682 }
683 mIsDialpadShown = true;
Yorke Leed5c512a2015-01-30 14:42:53 -0800684
Yorke Lee7ee5c422014-11-04 10:29:32 -0800685 mListsFragment.setUserVisibleHint(false);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700686
Chiao Cheng94b10b52012-08-17 16:59:12 -0700687 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leed5c512a2015-01-30 14:42:53 -0800688 if (mDialpadFragment == null) {
689 mDialpadFragment = new DialpadFragment();
690 ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT);
691 } else {
692 ft.show(mDialpadFragment);
693 }
694
695 mDialpadFragment.setAnimate(animate);
696 AnalyticsUtil.sendScreenView(mDialpadFragment);
Yorke Leec3766332013-07-31 11:13:16 -0700697 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700698
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700699 if (animate) {
700 mFloatingActionButtonController.scaleOut();
701 } else {
702 mFloatingActionButtonController.setVisible(false);
703 }
Yorke Lee5253be02014-05-21 18:50:03 -0700704 mActionBarController.onDialpadUp();
705
Yorke Lee6c450eb2015-05-08 09:45:47 -0700706 mListsFragment.getView().animate().alpha(0).withLayer();
Yorke Leec3766332013-07-31 11:13:16 -0700707 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700708
Andrew Lee2a58ab82014-05-15 02:16:04 -0700709 /**
710 * Callback from child DialpadFragment when the dialpad is shown.
711 */
712 public void onDialpadShown() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800713 Assert.assertNotNull(mDialpadFragment);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700714 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700715 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700716 } else {
717 mDialpadFragment.setYFraction(0);
718 }
719
Andrew Lee2a58ab82014-05-15 02:16:04 -0700720 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700721 }
722
723 /**
724 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
725 * a callback after the hide animation ends.
726 * @see #commitDialpadFragmentHide
727 */
Yorke Leeca195042013-09-25 16:29:38 -0700728 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Yorke Lee791b4882015-05-15 10:52:27 -0700729 if (mDialpadFragment == null || mDialpadFragment.getView() == null) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700730 return;
731 }
Yorke Leef6673d32013-08-23 15:34:17 -0700732 if (clearDialpad) {
733 mDialpadFragment.clearDialpad();
734 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700735 if (!mIsDialpadShown) {
736 return;
Yorke Leec3766332013-07-31 11:13:16 -0700737 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700738 mIsDialpadShown = false;
739 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800740 mListsFragment.setUserVisibleHint(true);
741 mListsFragment.sendScreenViewForCurrentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700742
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700743 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700744
745 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700746 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700747 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700748 } else {
749 commitDialpadFragmentHide();
750 }
751
Yorke Lee5253be02014-05-21 18:50:03 -0700752 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700753
Andrew Leed4cde832014-05-16 15:56:48 -0700754 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700755 if (TextUtils.isEmpty(mSearchQuery)) {
756 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700757 }
Andrew Leed4cde832014-05-16 15:56:48 -0700758 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700759 }
760
761 /**
762 * Finishes hiding the dialpad fragment after any animations are completed.
763 */
764 private void commitDialpadFragmentHide() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800765 if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700766 final FragmentTransaction ft = getFragmentManager().beginTransaction();
767 ft.hide(mDialpadFragment);
768 ft.commit();
769 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700770 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700771 }
772
Andrew Lee2a58ab82014-05-15 02:16:04 -0700773 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700774 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700775 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700776 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700777 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700778 fragment = mRegularSearchFragment;
779 }
780 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700781 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700782 }
783 }
784
Yorke Lee5253be02014-05-21 18:50:03 -0700785 @Override
786 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700787 return mInDialpadSearch || mInRegularSearch;
788 }
789
Yorke Lee5253be02014-05-21 18:50:03 -0700790 @Override
791 public boolean hasSearchQuery() {
792 return !TextUtils.isEmpty(mSearchQuery);
793 }
794
795 @Override
796 public boolean shouldShowActionBar() {
797 return mListsFragment.shouldShowActionBar();
798 }
799
Yorke Leeb207f8a2013-08-29 18:51:06 -0700800 private void setNotInSearchUi() {
801 mInDialpadSearch = false;
802 mInRegularSearch = false;
803 }
804
Yorke Lee311969c2013-08-26 06:31:11 -0700805 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700806 if (mIsDialpadShown) {
807 hideDialpadFragment(false, true);
808 } else {
809 exitSearchUi();
810 }
Yorke Lee311969c2013-08-26 06:31:11 -0700811 }
812
Yorke Lee53a22302014-04-29 18:13:46 -0700813 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700814 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
815 if (canIntentBeHandled(voiceIntent)) {
816 mVoiceSearchButton.setVisibility(View.VISIBLE);
817 mVoiceSearchButton.setOnClickListener(this);
818 } else {
819 mVoiceSearchButton.setVisibility(View.GONE);
820 }
821 }
822
Andrew Lee467de3d2015-03-17 15:47:24 -0700823 protected OptionsPopupMenu buildOptionsMenu(View invoker) {
Andrew Leee74a10e2014-05-16 14:31:40 -0700824 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
825 popupMenu.inflate(R.menu.dialtacts_options);
826 popupMenu.setOnMenuItemClickListener(this);
827 return popupMenu;
828 }
829
Yorke Lee86e21f72014-04-02 16:49:38 -0700830 @Override
831 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700832 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700833 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700834 mPendingSearchViewQuery = null;
835 }
Yorke Leec16ea5a2015-05-19 15:51:01 -0700836 if (mActionBarController != null) {
837 mActionBarController.restoreActionBarOffset();
838 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700839 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700840 }
841
Chiao Cheng94b10b52012-08-17 16:59:12 -0700842 /**
843 * Returns true if the intent is due to hitting the green send key (hardware call button:
844 * KEYCODE_CALL) while in a call.
845 *
846 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700847 * @return true if the intent is due to hitting the green send key while in a call
848 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700849 private boolean isSendKeyWhileInCall(Intent intent) {
850 // If there is a call in progress and the user launched the dialer by hitting the call
851 // button, go straight to the in-call screen.
852 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700853
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700854 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700855 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700856 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700857 }
858
859 return false;
860 }
861
862 /**
863 * Sets the current tab based on the intent's request type
864 *
865 * @param intent Intent that contains information about which tab should be selected
866 */
Yorke Leec3766332013-07-31 11:13:16 -0700867 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700868 // 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 -0700869 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700870 finish();
871 return;
872 }
873
Yorke Leed5c512a2015-01-30 14:42:53 -0800874 final boolean phoneIsInUse = phoneIsInUse();
875 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
876 showDialpadFragment(false);
877 mDialpadFragment.setStartedFromNewIntent(true);
878 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
879 mInCallDialpadUp = true;
Yorke Lee35127cd2013-09-10 14:09:29 -0700880 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700881 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700882 }
883
884 @Override
885 public void onNewIntent(Intent newIntent) {
886 setIntent(newIntent);
Nancy Chen199b7f02014-11-05 15:03:00 -0800887 mStateSaved = false;
Yorke Leec3766332013-07-31 11:13:16 -0700888 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700889
Chiao Cheng94b10b52012-08-17 16:59:12 -0700890 invalidateOptionsMenu();
891 }
892
893 /** Returns true if the given intent contains a phone number to populate the dialer with */
894 private boolean isDialIntent(Intent intent) {
895 final String action = intent.getAction();
896 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
897 return true;
898 }
899 if (Intent.ACTION_VIEW.equals(action)) {
900 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700901 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700902 return true;
903 }
904 }
905 return false;
906 }
907
908 /**
909 * Returns an appropriate call origin for this Activity. May return null when no call origin
910 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
911 * for remembering the tab in which the user made a phone call, so the external app's DIAL
912 * request should not be counted.)
913 */
914 public String getCallOrigin() {
915 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
916 }
917
Chiao Cheng94b10b52012-08-17 16:59:12 -0700918 /**
Yorke Leec3766332013-07-31 11:13:16 -0700919 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700920 */
Yorke Lee6c450eb2015-05-08 09:45:47 -0700921 private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700922 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700923 // Weird race condition where fragment is doing work after the activity is destroyed
924 // due to talkback being on (b/10209937). Just return since we can't do any
925 // constructive here.
926 return;
927 }
928
Yorke Leeef2b7382013-08-09 17:39:25 -0700929 if (DEBUG) {
930 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
931 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700932
Yorke Leec3766332013-07-31 11:13:16 -0700933 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700934 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700935 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700936 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700937 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700938 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700939
Yorke Leeb207f8a2013-08-29 18:51:06 -0700940 final String tag;
941 if (smartDialSearch) {
942 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
943 } else {
944 tag = TAG_REGULAR_SEARCH_FRAGMENT;
945 }
946 mInDialpadSearch = smartDialSearch;
947 mInRegularSearch = !smartDialSearch;
948
Andrew Lee752956e2014-05-15 11:43:38 -0700949 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Yorke Lee6c450eb2015-05-08 09:45:47 -0700950 if (animate) {
951 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
952 } else {
953 transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
954 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700955 if (fragment == null) {
956 if (smartDialSearch) {
957 fragment = new SmartDialSearchFragment();
958 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700959 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700960 }
Andrew Leeb1903842014-05-15 16:11:24 -0700961 transaction.add(R.id.dialtacts_frame, fragment, tag);
962 } else {
963 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700964 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700965 // DialtactsActivity will provide the options menu
966 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700967 fragment.setShowEmptyListForNullQuery(true);
Yorke Lee6c450eb2015-05-08 09:45:47 -0700968 if (!smartDialSearch) {
969 fragment.setQueryString(query, false /* delaySelection */);
970 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700971 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700972
Yorke Lee6c450eb2015-05-08 09:45:47 -0700973 if (animate) {
974 mListsFragment.getView().animate().alpha(0).withLayer();
975 }
Yorke Lee7ee5c422014-11-04 10:29:32 -0800976 mListsFragment.setUserVisibleHint(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700977 }
978
979 /**
Yorke Leec3766332013-07-31 11:13:16 -0700980 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700981 */
Yorke Leec3766332013-07-31 11:13:16 -0700982 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700983 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700984 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -0700985 return;
986 }
Andrew Leeb1903842014-05-15 16:11:24 -0700987
Andrew Leeb1903842014-05-15 16:11:24 -0700988 mSearchView.setText(null);
Yorke Leed5c512a2015-01-30 14:42:53 -0800989
990 if (mDialpadFragment != null) {
991 mDialpadFragment.clearDialpad();
992 }
993
Yorke Leeb207f8a2013-08-29 18:51:06 -0700994 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700995
Andrew Leeb1903842014-05-15 16:11:24 -0700996 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700997 if (mSmartDialSearchFragment != null) {
998 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700999 }
Andrew Leeb1903842014-05-15 16:11:24 -07001000 if (mRegularSearchFragment != null) {
1001 transaction.remove(mRegularSearchFragment);
1002 }
1003 transaction.commit();
1004
1005 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Leed5c512a2015-01-30 14:42:53 -08001006
1007 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
Yorke Lee7ee5c422014-11-04 10:29:32 -08001008 // If the dialpad fragment wasn't previously visible, then send a screen view because
1009 // we are exiting regular search. Otherwise, the screen view will be sent by
1010 // {@link #hideDialpadFragment}.
1011 mListsFragment.sendScreenViewForCurrentPosition();
1012 mListsFragment.setUserVisibleHint(true);
1013 }
1014
Yorke Lee5253be02014-05-21 18:50:03 -07001015 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001016 }
1017
Chiao Cheng94b10b52012-08-17 16:59:12 -07001018 @Override
Yorke Leec3766332013-07-31 11:13:16 -07001019 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -07001020 if (mStateSaved) {
1021 return;
1022 }
Andrew Lee2a58ab82014-05-15 02:16:04 -07001023 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -07001024 if (TextUtils.isEmpty(mSearchQuery) ||
1025 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
1026 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -07001027 exitSearchUi();
1028 }
Yorke Leef6673d32013-08-23 15:34:17 -07001029 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -07001030 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -07001031 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001032 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001033 } else {
1034 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001035 }
Yorke Leec3766332013-07-31 11:13:16 -07001036 }
1037
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001038 /**
1039 * @return True if the search UI was exited, false otherwise
1040 */
1041 private boolean maybeExitSearchUi() {
1042 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
1043 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001044 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001045 return true;
1046 }
1047 return false;
1048 }
1049
Yorke Leec3766332013-07-31 11:13:16 -07001050 @Override
1051 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -07001052 if (mSmartDialSearchFragment != null) {
1053 mSmartDialSearchFragment.setAddToContactNumber(query);
1054 }
Yorke Leec3766332013-07-31 11:13:16 -07001055 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
1056 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -07001057
1058 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001059 if (DEBUG) {
1060 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1061 }
1062 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1063 // This callback can happen if the dialpad fragment is recreated because of
1064 // activity destruction. In that case, don't update the search view because
1065 // that would bring the user back to the search fragment regardless of the
1066 // previous state of the application. Instead, just return here and let the
1067 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001068 if (!TextUtils.isEmpty(normalizedQuery)) {
1069 mPendingSearchViewQuery = normalizedQuery;
1070 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001071 return;
1072 }
Yorke Lee53a22302014-04-29 18:13:46 -07001073 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001074 }
1075 }
Yorke Leec3766332013-07-31 11:13:16 -07001076
1077 @Override
1078 public void onListFragmentScrollStateChange(int scrollState) {
1079 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001080 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -07001081 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001082 }
1083 }
1084
1085 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001086 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001087 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001088 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1089 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001090 }
1091
Yorke Leec3766332013-07-31 11:13:16 -07001092 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001093 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001094 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001095
Yorke Leeda0f9042013-12-05 14:25:51 -08001096 private boolean canIntentBeHandled(Intent intent) {
1097 final PackageManager packageManager = getPackageManager();
1098 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1099 PackageManager.MATCH_DEFAULT_ONLY);
1100 return resolveInfo != null && resolveInfo.size() > 0;
1101 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001102
Yorke Lee86e21f72014-04-02 16:49:38 -07001103 /**
1104 * Called when the user has long-pressed a contact tile to start a drag operation.
1105 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001106 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001107 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Lee18963442014-06-06 17:20:13 -07001108 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001109 }
1110
1111 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001112 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1113 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001114
Yorke Lee86e21f72014-04-02 16:49:38 -07001115 /**
1116 * Called when the user has released a contact tile after long-pressing it.
1117 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001118 @Override
1119 public void onDragFinished(int x, int y) {
Andrew Lee18963442014-06-06 17:20:13 -07001120 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001121 }
1122
1123 @Override
1124 public void onDroppedOnRemove() {}
1125
1126 /**
Yorke Leed999b712014-04-23 15:10:58 -07001127 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001128 * once it has been attached to the activity.
1129 */
1130 @Override
1131 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001132 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001133 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001134 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001135
1136 @Override
1137 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001138 // Specify call-origin so that users will see the previous tab instead of
1139 // CallLog screen (search UI will be automatically exited).
1140 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001141 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001142 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001143 }
1144
1145 @Override
1146 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001147 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1148 }
1149
1150 @Override
1151 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001152 Intent intent = isVideoCall ?
Andrew Lee247df6e2015-05-12 19:09:00 -07001153 IntentUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1154 IntentUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001155 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001156 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001157 }
1158
1159 @Override
1160 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001161 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001162 }
1163
1164 @Override
1165 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001166 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001167 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001168
Yorke Leecc4660d2014-04-24 11:22:57 -07001169 @Override
1170 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001171 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001172 // Only scroll the button when the first tab is selected. The button should scroll from
1173 // the middle to right position only on the transition from the first tab to the second
1174 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001175 // If the app is in RTL mode, we need to check against the second tab, rather than the
1176 // first. This is because if we are scrolling between the first and second tabs, the
1177 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1178 // reversal of the order of the tabs.
1179 final boolean isLayoutRtl = DialerUtils.isRtl();
1180 final boolean shouldScrollButton = position == (isLayoutRtl
1181 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1182 if (shouldScrollButton && !mIsLandscape) {
1183 mFloatingActionButtonController.onPageScrolled(
1184 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001185 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1186 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001187 }
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001188
1189 if (position == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
1190 mFloatingActionButtonController.changeIcon(
1191 getResources().getDrawable(R.drawable.ic_person_add_24dp),
1192 getResources().getString(R.string.search_shortcut_create_new_contact));
1193 } else {
1194 mFloatingActionButtonController.changeIcon(
1195 getResources().getDrawable(R.drawable.fab_ic_dial),
1196 getResources().getString(R.string.action_menu_dialpad_button));
1197 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001198 }
1199
1200 @Override
1201 public void onPageSelected(int position) {
Yorke Leecc4660d2014-04-24 11:22:57 -07001202 }
1203
1204 @Override
1205 public void onPageScrollStateChanged(int state) {
1206 }
1207
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001208 private TelecomManager getTelecomManager() {
1209 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001210 }
1211
Yorke Lee5253be02014-05-21 18:50:03 -07001212 @Override
1213 public boolean isActionBarShowing() {
1214 return mActionBarController.isActionBarShowing();
1215 }
1216
Yorke Leec98a5bb2014-10-28 16:12:05 -07001217 @Override
1218 public ActionBarController getActionBarController() {
1219 return mActionBarController;
1220 }
1221
Andrew Lee9da8fb42014-06-03 14:03:09 -07001222 public boolean isDialpadShown() {
1223 return mIsDialpadShown;
1224 }
1225
Yorke Lee5253be02014-05-21 18:50:03 -07001226 @Override
1227 public int getActionBarHideOffset() {
1228 return getActionBar().getHideOffset();
1229 }
1230
1231 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001232 public void setActionBarHideOffset(int offset) {
1233 getActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001234 }
1235
1236 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001237 public int getActionBarHeight() {
1238 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001239 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001240
1241 /**
1242 * Updates controller based on currently known information.
1243 *
1244 * @param animate Whether or not to animate the transition.
1245 */
1246 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001247 int align = (!mIsLandscape &&
1248 mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
Andrew Lee405a6e62014-08-20 15:02:16 -07001249 FloatingActionButtonController.ALIGN_MIDDLE :
1250 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001251 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001252 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001253}