blob: beec280f5969d26987e6b34b950340ba2256ea38 [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;
Chiao Cheng94b10b52012-08-17 16:59:12 -070032import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070033import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070034import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070035import android.support.v4.view.ViewPager;
Tyler Gunn9dc924c2014-09-12 09:33:50 -070036import android.telecom.PhoneAccount;
37import android.telecom.TelecomManager;
Yorke Leec3766332013-07-31 11:13:16 -070038import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070039import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070040import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070041import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070043import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070044import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070045import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070046import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070047import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070048import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070049import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070050import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070051import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070052import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070053import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070054import android.view.animation.AnimationUtils;
Yorke Leec3766332013-07-31 11:13:16 -070055import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070056import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070057import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070058import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070059import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080060import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070061
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070062import com.android.contacts.common.CallUtil;
Brian Attwellc311af12014-10-22 18:28:58 -070063import com.android.contacts.common.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070064import com.android.contacts.common.dialog.ClearFrequentsDialog;
65import com.android.contacts.common.interactions.ImportExportDialogFragment;
Nancy Chen0d3a7392014-08-12 14:44:53 -070066import com.android.contacts.common.interactions.TouchPointManager;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080067import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070068import com.android.contacts.common.widget.FloatingActionButtonController;
Brian Attwellbeab3bb2014-10-27 12:24:49 -070069import com.android.contacts.commonbind.analytics.AnalyticsUtil;
Yorke Leec3766332013-07-31 11:13:16 -070070import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070071import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070072import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070073import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070074import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070075import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080076import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070077import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080078import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070079import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070080import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070081import com.android.dialer.list.RegularSearchFragment;
82import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070083import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070084import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070085import com.android.dialer.settings.DialerSettingsActivity;
Yorke Lee7d20f822014-06-19 17:09:33 -070086import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070087import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070088import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070089import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070090import com.android.dialerbind.DatabaseHelperManager;
Yorke Lee2fec47b2014-08-05 18:16:27 -070091import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070092import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070093
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
166 /**
167 * Listener for after slide out animation completes on dialer fragment.
168 */
169 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
170 @Override
171 public void onAnimationEnd(Animation animation) {
172 commitDialpadFragmentHide();
173 }
174 };
175
176 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700177 * Fragment containing the speed dial list, recents list, and all contacts list.
178 */
179 private ListsFragment mListsFragment;
180
Yorke Lee19e68ca2014-10-28 11:51:40 -0700181 /**
182 * Tracks whether onSaveInstanceState has been called. If true, no fragment transactions can
183 * be commited.
184 */
185 private boolean mStateSaved;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800186 private boolean mIsRestarting;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700187 private boolean mInDialpadSearch;
188 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700189 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700190 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700191 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700192
Yorke Leeef2b7382013-08-09 17:39:25 -0700193 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700194 * Whether or not the device is in landscape orientation.
195 */
196 private boolean mIsLandscape;
197
198 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700199 * The position of the currently selected tab in the attached {@link ListsFragment}.
200 */
201 private int mCurrentTabPosition = 0;
202
203 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700204 * True if the dialpad is only temporarily showing due to being in call
205 */
206 private boolean mInCallDialpadUp;
207
208 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700209 * True when this activity has been launched for the first time.
210 */
Yorke Lee98702de2013-08-06 12:03:32 -0700211 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700212
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700213 /**
214 * Search query to be applied to the SearchView in the ActionBar once
215 * onCreateOptionsMenu has been called.
216 */
217 private String mPendingSearchViewQuery;
218
Yorke Lee74edcdc2014-07-11 16:15:08 -0700219 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700220 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700221 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700222
Yorke Leeef2b7382013-08-09 17:39:25 -0700223 private String mSearchQuery;
224
Yorke Leefce269a2013-08-12 11:56:04 -0700225 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700226 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700227 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700228
Sai Cheemalapati41460652014-06-02 21:05:39 -0700229 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700230
Andrew Lee2423a2f2014-05-29 14:14:45 -0700231 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700232
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800233 /**
234 * The text returned from a voice search query. Set in {@link #onActivityResult} and used in
235 * {@link #onResume()} to populate the search box.
236 */
237 private String mVoiceSearchQuery;
238
Andrew Leee74a10e2014-05-16 14:31:40 -0700239 private class OptionsPopupMenu extends PopupMenu {
240 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700241 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700242 }
243
244 @Override
245 public void show() {
246 final Menu menu = getMenu();
247 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700248 clearFrequents.setVisible(mListsFragment != null &&
249 mListsFragment.getSpeedDialFragment() != null &&
250 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700251 super.show();
252 }
253 }
254
Chiao Cheng94b10b52012-08-17 16:59:12 -0700255 /**
Yorke Lee28266192014-05-01 10:05:52 -0700256 * Listener that listens to drag events and sends their x and y coordinates to a
257 * {@link DragDropController}.
258 */
259 private class LayoutOnDragListener implements OnDragListener {
260 @Override
261 public boolean onDrag(View v, DragEvent event) {
262 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700263 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700264 }
265 return true;
266 }
267 }
268
269 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700270 * Listener used to send search queries to the phone search fragment.
271 */
Yorke Lee53a22302014-04-29 18:13:46 -0700272 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700273 @Override
274 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
275 }
Yorke Leec3766332013-07-31 11:13:16 -0700276
Andrew Lee99a570c2014-05-15 14:18:50 -0700277 @Override
278 public void onTextChanged(CharSequence s, int start, int before, int count) {
279 final String newText = s.toString();
280 if (newText.equals(mSearchQuery)) {
281 // If the query hasn't changed (perhaps due to activity being destroyed
282 // and restored, or user launching the same DIAL intent twice), then there is
283 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700284 return;
285 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700286 if (DEBUG) {
287 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700288 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700289 }
Yorke Lee710709d2014-05-29 07:18:42 -0700290 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700291
Andrew Lee90374a72014-05-16 15:01:09 -0700292 // Show search fragment only when the query string is changed to non-empty text.
293 if (!TextUtils.isEmpty(newText)) {
294 // Call enterSearchUi only if we are switching search modes, or showing a search
295 // fragment for the first time.
296 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
297 (!mIsDialpadShown && mInRegularSearch);
298 if (!sameSearchMode) {
299 enterSearchUi(mIsDialpadShown, mSearchQuery);
300 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700301 }
302
Andrew Leea8515422014-06-13 16:53:54 -0700303 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700304 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700305 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700306 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700307 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700308 }
309
310 @Override
311 public void afterTextChanged(Editable s) {
312 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700313 };
314
Andrew Leeb1903842014-05-15 16:11:24 -0700315
316 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700317 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700318 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700319 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700320 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700321 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700322 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700323 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700324 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
325 }
Andrew Leeb1903842014-05-15 16:11:24 -0700326 }
327 };
328
329 /**
330 * If the search term is empty and the user closes the soft keyboard, close the search UI.
331 */
332 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
333 @Override
334 public boolean onKey(View v, int keyCode, KeyEvent event) {
335 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
336 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700337 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700338 }
339 return false;
340 }
341 };
342
Chiao Cheng94b10b52012-08-17 16:59:12 -0700343 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700344 public boolean dispatchTouchEvent(MotionEvent ev) {
345 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
346 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
347 }
348 return super.dispatchTouchEvent(ev);
349
350 }
351
352 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700353 protected void onCreate(Bundle savedInstanceState) {
Yorke Leef5554ce2015-01-27 14:46:02 -0800354 Trace.beginSection(TAG + " onCreate");
Yorke Leec3766332013-07-31 11:13:16 -0700355 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700356 mFirstLaunch = true;
357
Andrew Lee2423a2f2014-05-29 14:14:45 -0700358 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700359 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700360
Yorke Leef5554ce2015-01-27 14:46:02 -0800361 Trace.beginSection(TAG + " setContentView");
Yorke Lee8898cd02013-08-08 10:24:27 -0700362 setContentView(R.layout.dialtacts_activity);
Yorke Leef5554ce2015-01-27 14:46:02 -0800363 Trace.endSection();
Yorke Lee9e91bb02014-03-05 17:50:50 -0800364 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700365
Yorke Leef5554ce2015-01-27 14:46:02 -0800366 Trace.beginSection(TAG + " setup Views");
Yorke Lee53a22302014-04-29 18:13:46 -0700367 final ActionBar actionBar = getActionBar();
368 actionBar.setCustomView(R.layout.search_edittext);
369 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700370 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700371
Yorke Lee5253be02014-05-21 18:50:03 -0700372 mActionBarController = new ActionBarController(this,
373 (SearchEditTextLayout) actionBar.getCustomView());
374
Andrew Lee04675a52014-06-05 18:36:20 -0700375 SearchEditTextLayout searchEditTextLayout =
376 (SearchEditTextLayout) actionBar.getCustomView();
377 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
378
379 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700380 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700381 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
382 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
383 .setOnClickListener(mSearchViewOnClickListener);
384 searchEditTextLayout.findViewById(R.id.search_box_start_search)
385 .setOnClickListener(mSearchViewOnClickListener);
386 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700387 @Override
388 public void onBackButtonClicked() {
389 onBackPressed();
390 }
391 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700392
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700393 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700394 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700395
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700396 final View floatingActionButtonContainer = findViewById(
397 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700398 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
399 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700400 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700401 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700402
Andrew Lee04675a52014-06-05 18:36:20 -0700403 ImageButton optionsMenuButton =
404 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700405 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700406 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
407 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700408
Yorke Leeef2b7382013-08-09 17:39:25 -0700409 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
410 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700411 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800412 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700413 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800414 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
415 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700416 } else {
417 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700418 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
419 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700420 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700421 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700422 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700423 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700424
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700425 final boolean isLayoutRtl = DialerUtils.isRtl();
426 if (mIsLandscape) {
427 mSlideIn = AnimationUtils.loadAnimation(this,
428 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
429 mSlideOut = AnimationUtils.loadAnimation(this,
430 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
431 } else {
432 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
433 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
434 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700435
Yorke Lee2fec47b2014-08-05 18:16:27 -0700436 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
437 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
438
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700439 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700440
Yorke Leef614f6f2014-10-03 10:44:19 -0700441 mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
442 mParentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700443 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700444 new ViewTreeObserver.OnGlobalLayoutListener() {
445 @Override
446 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700447 final ViewTreeObserver observer =
448 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700449 if (!observer.isAlive()) {
450 return;
451 }
452 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700453 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700454 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700455 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700456 }
457 });
Andrew Lee0c667702014-05-12 14:31:45 -0700458
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700459 setupActivityOverlay();
460
Yorke Leef5554ce2015-01-27 14:46:02 -0800461 Trace.endSection();
462
463 Trace.beginSection(TAG + " initialize smart dialing");
Yorke Lee0baa98b2013-08-22 10:55:16 -0700464 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700465 SmartDialPrefix.initializeNanpSettings(this);
Yorke Leef5554ce2015-01-27 14:46:02 -0800466 Trace.endSection();
467 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700468 }
469
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700470 private void setupActivityOverlay() {
471 final View activityOverlay = findViewById(R.id.activity_overlay);
472 activityOverlay.setOnTouchListener(new OnTouchListener() {
473 @Override
474 public boolean onTouch(View v, MotionEvent event) {
475 if (!mIsDialpadShown) {
476 maybeExitSearchUi();
477 }
478 return false;
479 }
480 });
481 }
482
Chiao Cheng94b10b52012-08-17 16:59:12 -0700483 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700484 protected void onResume() {
Yorke Leef5554ce2015-01-27 14:46:02 -0800485 Trace.beginSection(TAG + " onResume");
Yorke Leec3766332013-07-31 11:13:16 -0700486 super.onResume();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700487 mStateSaved = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700488 if (mFirstLaunch) {
489 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700490 } else if (!phoneIsInUse() && mInCallDialpadUp) {
491 hideDialpadFragment(false, true);
492 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700493 } else if (mShowDialpadOnResume) {
494 showDialpadFragment(false);
495 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700496 }
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800497
498 // If there was a voice query result returned in the {@link #onActivityResult} callback, it
499 // will have been stashed in mVoiceSearchQuery since the search results fragment cannot be
500 // shown until onResume has completed. Active the search UI and set the search term now.
501 if (!TextUtils.isEmpty(mVoiceSearchQuery)) {
502 mActionBarController.onSearchBoxTapped();
503 mSearchView.setText(mVoiceSearchQuery);
504 mVoiceSearchQuery = null;
505 }
506
Yorke Lee98702de2013-08-06 12:03:32 -0700507 mFirstLaunch = false;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800508
509 if (mIsRestarting) {
510 // This is only called when the activity goes from resumed -> paused -> resumed, so it
511 // will not cause an extra view to be sent out on rotation
512 if (mIsDialpadShown) {
513 AnalyticsUtil.sendScreenView(mDialpadFragment, this);
514 }
515 mIsRestarting = false;
516 }
Yorke Lee53a22302014-04-29 18:13:46 -0700517 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700518 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700519 updateFloatingActionButtonControllerAlignment(false /* animate */);
Yorke Leef5554ce2015-01-27 14:46:02 -0800520 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700521 }
522
523 @Override
Yorke Lee7ee5c422014-11-04 10:29:32 -0800524 protected void onRestart() {
525 super.onRestart();
526 mIsRestarting = true;
527 }
528
529 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700530 protected void onPause() {
531 if (mClearSearchOnPause) {
532 hideDialpadAndSearchUi();
533 mClearSearchOnPause = false;
534 }
Yorke Lee19e68ca2014-10-28 11:51:40 -0700535 if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) {
536 commitDialpadFragmentHide();
537 }
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700538 super.onPause();
539 }
540
541 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700542 protected void onSaveInstanceState(Bundle outState) {
543 super.onSaveInstanceState(outState);
544 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700545 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
546 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700547 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700548 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700549 mActionBarController.saveInstanceState(outState);
Yorke Lee19e68ca2014-10-28 11:51:40 -0700550 mStateSaved = true;
Yorke Leeef2b7382013-08-09 17:39:25 -0700551 }
552
553 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700554 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700555 if (fragment instanceof DialpadFragment) {
556 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700557 if (!mShowDialpadOnResume) {
558 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
559 transaction.hide(mDialpadFragment);
560 transaction.commit();
561 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700562 } else if (fragment instanceof SmartDialSearchFragment) {
563 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700564 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700565 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700566 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700567 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700568 } else if (fragment instanceof ListsFragment) {
569 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700570 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700571 }
Yorke Leec3766332013-07-31 11:13:16 -0700572 }
573
Alon Albertb453e5b2013-09-10 15:54:23 -0700574 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700575 final Intent intent = new Intent(this, DialerSettingsActivity.class);
576 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700577 }
578
Chiao Cheng94b10b52012-08-17 16:59:12 -0700579 @Override
580 public void onClick(View view) {
581 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700582 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700583 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700584 mInCallDialpadUp = false;
585 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700586 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700587 break;
Yorke Leec3766332013-07-31 11:13:16 -0700588 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800589 try {
590 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
591 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
592 } catch (ActivityNotFoundException e) {
593 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
594 Toast.LENGTH_SHORT).show();
595 }
Yorke Leec3766332013-07-31 11:13:16 -0700596 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700597 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700598 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700599 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700600 default: {
601 Log.wtf(TAG, "Unexpected onClick event from " + view);
602 break;
603 }
604 }
605 }
606
Yorke Leec3766332013-07-31 11:13:16 -0700607 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700608 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700609 switch (item.getItemId()) {
610 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700611 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700612 break;
613 case R.id.menu_add_contact:
614 try {
615 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
616 } catch (ActivityNotFoundException e) {
617 Toast toast = Toast.makeText(this,
618 R.string.add_contact_not_available,
619 Toast.LENGTH_SHORT);
620 toast.show();
621 }
622 break;
623 case R.id.menu_import_export:
624 // We hard-code the "contactsAreAvailable" argument because doing it properly would
625 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
626 // now in Dialtacts for (potential) performance reasons. Compare with how it is
627 // done in {@link PeopleActivity}.
628 ImportExportDialogFragment.show(getFragmentManager(), true,
629 DialtactsActivity.class);
630 return true;
631 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700632 ClearFrequentsDialog.show(getFragmentManager());
633 return true;
634 case R.id.menu_call_settings:
635 handleMenuSettings();
636 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700637 }
638 return false;
639 }
640
641 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700642 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
643 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
644 if (resultCode == RESULT_OK) {
645 final ArrayList<String> matches = data.getStringArrayListExtra(
646 RecognizerIntent.EXTRA_RESULTS);
647 if (matches.size() > 0) {
648 final String match = matches.get(0);
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800649 mVoiceSearchQuery = match;
Yorke Leec3766332013-07-31 11:13:16 -0700650 } else {
651 Log.e(TAG, "Voice search - nothing heard");
652 }
653 } else {
654 Log.e(TAG, "Voice search failed");
655 }
656 }
657 super.onActivityResult(requestCode, resultCode, data);
658 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700659
Andrew Lee2a58ab82014-05-15 02:16:04 -0700660 /**
661 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
662 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
663 * @see #onDialpadShown
664 */
Yorke Leec3766332013-07-31 11:13:16 -0700665 private void showDialpadFragment(boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700666 if (mIsDialpadShown || mStateSaved) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700667 return;
668 }
669 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700670 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800671 mListsFragment.setUserVisibleHint(false);
Brian Attwellbeab3bb2014-10-27 12:24:49 -0700672 AnalyticsUtil.sendScreenView(mDialpadFragment);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700673
Chiao Cheng94b10b52012-08-17 16:59:12 -0700674 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700675 ft.show(mDialpadFragment);
676 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700677
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700678 if (animate) {
679 mFloatingActionButtonController.scaleOut();
680 } else {
681 mFloatingActionButtonController.setVisible(false);
682 }
Yorke Lee5253be02014-05-21 18:50:03 -0700683 mActionBarController.onDialpadUp();
684
Andrew Leeb1903842014-05-15 16:11:24 -0700685 if (!isInSearchUi()) {
686 enterSearchUi(true /* isSmartDial */, mSearchQuery);
687 }
Yorke Leec3766332013-07-31 11:13:16 -0700688 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700689
Andrew Lee2a58ab82014-05-15 02:16:04 -0700690 /**
691 * Callback from child DialpadFragment when the dialpad is shown.
692 */
693 public void onDialpadShown() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700694 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700695 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700696 } else {
697 mDialpadFragment.setYFraction(0);
698 }
699
Andrew Lee2a58ab82014-05-15 02:16:04 -0700700 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700701 }
702
703 /**
704 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
705 * a callback after the hide animation ends.
706 * @see #commitDialpadFragmentHide
707 */
Yorke Leeca195042013-09-25 16:29:38 -0700708 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700709 if (mDialpadFragment == null) {
710 return;
711 }
Yorke Leef6673d32013-08-23 15:34:17 -0700712 if (clearDialpad) {
713 mDialpadFragment.clearDialpad();
714 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700715 if (!mIsDialpadShown) {
716 return;
Yorke Leec3766332013-07-31 11:13:16 -0700717 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700718 mIsDialpadShown = false;
719 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800720 mListsFragment.setUserVisibleHint(true);
721 mListsFragment.sendScreenViewForCurrentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700722
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700723 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700724
725 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700726 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700727 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700728 } else {
729 commitDialpadFragmentHide();
730 }
731
Yorke Lee5253be02014-05-21 18:50:03 -0700732 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700733
Andrew Leed4cde832014-05-16 15:56:48 -0700734 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700735 if (TextUtils.isEmpty(mSearchQuery)) {
736 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700737 }
Andrew Leed4cde832014-05-16 15:56:48 -0700738 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700739 }
740
741 /**
742 * Finishes hiding the dialpad fragment after any animations are completed.
743 */
744 private void commitDialpadFragmentHide() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700745 if (!mStateSaved && !mDialpadFragment.isHidden()) {
746 final FragmentTransaction ft = getFragmentManager().beginTransaction();
747 ft.hide(mDialpadFragment);
748 ft.commit();
749 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700750 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700751 }
752
Andrew Lee2a58ab82014-05-15 02:16:04 -0700753 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700754 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700755 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700756 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700757 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700758 fragment = mRegularSearchFragment;
759 }
760 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700761 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700762 }
763 }
764
Yorke Lee5253be02014-05-21 18:50:03 -0700765 @Override
766 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700767 return mInDialpadSearch || mInRegularSearch;
768 }
769
Yorke Lee5253be02014-05-21 18:50:03 -0700770 @Override
771 public boolean hasSearchQuery() {
772 return !TextUtils.isEmpty(mSearchQuery);
773 }
774
775 @Override
776 public boolean shouldShowActionBar() {
777 return mListsFragment.shouldShowActionBar();
778 }
779
Yorke Leeb207f8a2013-08-29 18:51:06 -0700780 private void setNotInSearchUi() {
781 mInDialpadSearch = false;
782 mInRegularSearch = false;
783 }
784
Yorke Lee311969c2013-08-26 06:31:11 -0700785 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700786 if (mIsDialpadShown) {
787 hideDialpadFragment(false, true);
788 } else {
789 exitSearchUi();
790 }
Yorke Lee311969c2013-08-26 06:31:11 -0700791 }
792
Yorke Lee53a22302014-04-29 18:13:46 -0700793 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700794 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
795 if (canIntentBeHandled(voiceIntent)) {
796 mVoiceSearchButton.setVisibility(View.VISIBLE);
797 mVoiceSearchButton.setOnClickListener(this);
798 } else {
799 mVoiceSearchButton.setVisibility(View.GONE);
800 }
801 }
802
Andrew Leee74a10e2014-05-16 14:31:40 -0700803 private OptionsPopupMenu buildOptionsMenu(View invoker) {
804 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
805 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700806 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700807 popupMenu.setOnMenuItemClickListener(this);
808 return popupMenu;
809 }
810
Yorke Lee86e21f72014-04-02 16:49:38 -0700811 @Override
812 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700813 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700814 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700815 mPendingSearchViewQuery = null;
816 }
Yorke Leea524ae52014-08-05 18:01:05 -0700817 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700818 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700819 }
820
Chiao Cheng94b10b52012-08-17 16:59:12 -0700821 /**
822 * Returns true if the intent is due to hitting the green send key (hardware call button:
823 * KEYCODE_CALL) while in a call.
824 *
825 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700826 * @return true if the intent is due to hitting the green send key while in a call
827 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700828 private boolean isSendKeyWhileInCall(Intent intent) {
829 // If there is a call in progress and the user launched the dialer by hitting the call
830 // button, go straight to the in-call screen.
831 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700832
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700833 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700834 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700835 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700836 }
837
838 return false;
839 }
840
841 /**
842 * Sets the current tab based on the intent's request type
843 *
844 * @param intent Intent that contains information about which tab should be selected
845 */
Yorke Leec3766332013-07-31 11:13:16 -0700846 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700847 // 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 -0700848 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700849 finish();
850 return;
851 }
852
Yorke Lee669b6082013-09-17 15:43:38 -0700853 if (mDialpadFragment != null) {
854 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700855 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700856 mDialpadFragment.setStartedFromNewIntent(true);
857 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
858 mInCallDialpadUp = true;
859 }
860 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700861 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700862 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700863 }
864
865 @Override
866 public void onNewIntent(Intent newIntent) {
867 setIntent(newIntent);
Nancy Chen199b7f02014-11-05 15:03:00 -0800868 mStateSaved = false;
Yorke Leec3766332013-07-31 11:13:16 -0700869 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700870
Chiao Cheng94b10b52012-08-17 16:59:12 -0700871 invalidateOptionsMenu();
872 }
873
874 /** Returns true if the given intent contains a phone number to populate the dialer with */
875 private boolean isDialIntent(Intent intent) {
876 final String action = intent.getAction();
877 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
878 return true;
879 }
880 if (Intent.ACTION_VIEW.equals(action)) {
881 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700882 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700883 return true;
884 }
885 }
886 return false;
887 }
888
889 /**
890 * Returns an appropriate call origin for this Activity. May return null when no call origin
891 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
892 * for remembering the tab in which the user made a phone call, so the external app's DIAL
893 * request should not be counted.)
894 */
895 public String getCallOrigin() {
896 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
897 }
898
Chiao Cheng94b10b52012-08-17 16:59:12 -0700899 /**
Yorke Leec3766332013-07-31 11:13:16 -0700900 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700901 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700902 private void enterSearchUi(boolean smartDialSearch, String query) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700903 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700904 // Weird race condition where fragment is doing work after the activity is destroyed
905 // due to talkback being on (b/10209937). Just return since we can't do any
906 // constructive here.
907 return;
908 }
909
Yorke Leeef2b7382013-08-09 17:39:25 -0700910 if (DEBUG) {
911 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
912 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700913
Yorke Leec3766332013-07-31 11:13:16 -0700914 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700915 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700916 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700917 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700918 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700919 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700920
Yorke Leeb207f8a2013-08-29 18:51:06 -0700921 final String tag;
922 if (smartDialSearch) {
923 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
924 } else {
925 tag = TAG_REGULAR_SEARCH_FRAGMENT;
926 }
927 mInDialpadSearch = smartDialSearch;
928 mInRegularSearch = !smartDialSearch;
929
Andrew Lee752956e2014-05-15 11:43:38 -0700930 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700931 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700932 if (fragment == null) {
933 if (smartDialSearch) {
934 fragment = new SmartDialSearchFragment();
935 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700936 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700937 }
Andrew Leeb1903842014-05-15 16:11:24 -0700938 transaction.add(R.id.dialtacts_frame, fragment, tag);
939 } else {
940 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700941 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700942 // DialtactsActivity will provide the options menu
943 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700944 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700945 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700946 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700947
948 mListsFragment.getView().animate().alpha(0).withLayer();
Yorke Lee7ee5c422014-11-04 10:29:32 -0800949 mListsFragment.setUserVisibleHint(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700950 }
951
952 /**
Yorke Leec3766332013-07-31 11:13:16 -0700953 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700954 */
Yorke Leec3766332013-07-31 11:13:16 -0700955 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700956 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700957 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -0700958 return;
959 }
Andrew Leeb1903842014-05-15 16:11:24 -0700960
Andrew Leeb1903842014-05-15 16:11:24 -0700961 mSearchView.setText(null);
962 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700963 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700964
Andrew Leeb1903842014-05-15 16:11:24 -0700965 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700966 if (mSmartDialSearchFragment != null) {
967 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700968 }
Andrew Leeb1903842014-05-15 16:11:24 -0700969 if (mRegularSearchFragment != null) {
970 transaction.remove(mRegularSearchFragment);
971 }
972 transaction.commit();
973
974 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee7ee5c422014-11-04 10:29:32 -0800975 if (!mDialpadFragment.isVisible()) {
976 // If the dialpad fragment wasn't previously visible, then send a screen view because
977 // we are exiting regular search. Otherwise, the screen view will be sent by
978 // {@link #hideDialpadFragment}.
979 mListsFragment.sendScreenViewForCurrentPosition();
980 mListsFragment.setUserVisibleHint(true);
981 }
982
Yorke Lee5253be02014-05-21 18:50:03 -0700983 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700984 }
985
Chiao Cheng94b10b52012-08-17 16:59:12 -0700986 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700987 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700988 if (mStateSaved) {
989 return;
990 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700991 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700992 if (TextUtils.isEmpty(mSearchQuery) ||
993 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
994 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700995 exitSearchUi();
996 }
Yorke Leef6673d32013-08-23 15:34:17 -0700997 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700998 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700999 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001000 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001001 } else {
1002 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001003 }
Yorke Leec3766332013-07-31 11:13:16 -07001004 }
1005
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001006 /**
1007 * @return True if the search UI was exited, false otherwise
1008 */
1009 private boolean maybeExitSearchUi() {
1010 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
1011 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001012 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001013 return true;
1014 }
1015 return false;
1016 }
1017
Yorke Leec3766332013-07-31 11:13:16 -07001018 @Override
1019 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -07001020 if (mSmartDialSearchFragment != null) {
1021 mSmartDialSearchFragment.setAddToContactNumber(query);
1022 }
Yorke Leec3766332013-07-31 11:13:16 -07001023 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
1024 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -07001025
1026 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001027 if (DEBUG) {
1028 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1029 }
1030 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1031 // This callback can happen if the dialpad fragment is recreated because of
1032 // activity destruction. In that case, don't update the search view because
1033 // that would bring the user back to the search fragment regardless of the
1034 // previous state of the application. Instead, just return here and let the
1035 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001036 if (!TextUtils.isEmpty(normalizedQuery)) {
1037 mPendingSearchViewQuery = normalizedQuery;
1038 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001039 return;
1040 }
Yorke Lee53a22302014-04-29 18:13:46 -07001041 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001042 }
1043 }
Yorke Leec3766332013-07-31 11:13:16 -07001044
1045 @Override
1046 public void onListFragmentScrollStateChange(int scrollState) {
1047 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001048 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -07001049 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001050 }
1051 }
1052
1053 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001054 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001055 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001056 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1057 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001058 }
1059
Yorke Leec3766332013-07-31 11:13:16 -07001060 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001061 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001062 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001063
Yorke Leee1424812013-09-04 18:24:48 -07001064 public static Intent getAddNumberToContactIntent(CharSequence text) {
Tyler Gunn1513fec2014-12-05 14:19:00 -08001065 return getAddToContactIntent(null /* name */, text /* phoneNumber */,
1066 -1 /* phoneNumberType */);
1067 }
1068
1069 public static Intent getAddToContactIntent(CharSequence name, CharSequence phoneNumber,
1070 int phoneNumberType) {
1071 Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1072 intent.putExtra(Intents.Insert.PHONE, phoneNumber);
1073 // Only include the name and phone type extras if they are specified (the method
1074 // getAddNumberToContactIntent does not use them).
1075 if (name != null) {
1076 intent.putExtra(Intents.Insert.NAME, name);
1077 }
1078 if (phoneNumberType != -1) {
1079 intent.putExtra(Intents.Insert.PHONE_TYPE, phoneNumberType);
1080 }
Yorke Leee1424812013-09-04 18:24:48 -07001081 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1082 return intent;
1083 }
1084
Yorke Leeda0f9042013-12-05 14:25:51 -08001085 private boolean canIntentBeHandled(Intent intent) {
1086 final PackageManager packageManager = getPackageManager();
1087 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1088 PackageManager.MATCH_DEFAULT_ONLY);
1089 return resolveInfo != null && resolveInfo.size() > 0;
1090 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001091
Yorke Lee6a1461a2014-04-21 16:27:14 -07001092 @Override
1093 public void showCallHistory() {
1094 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1095 // CONTENT_TYPE, so that we always open our call log from our dialer
1096 final Intent intent = new Intent(this, CallLogActivity.class);
1097 startActivity(intent);
1098 }
1099
Yorke Lee86e21f72014-04-02 16:49:38 -07001100 /**
1101 * Called when the user has long-pressed a contact tile to start a drag operation.
1102 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001103 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001104 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001105 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001106 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001107 }
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 Leee9e0ba62014-05-30 14:03:05 -07001120 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001121 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001122 }
Andrew Lee18963442014-06-06 17:20:13 -07001123 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001124 }
1125
1126 @Override
1127 public void onDroppedOnRemove() {}
1128
1129 /**
Yorke Leed999b712014-04-23 15:10:58 -07001130 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001131 * once it has been attached to the activity.
1132 */
1133 @Override
1134 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001135 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001136 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001137 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001138
1139 @Override
1140 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001141 // Specify call-origin so that users will see the previous tab instead of
1142 // CallLog screen (search UI will be automatically exited).
1143 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001144 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001145 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001146 }
1147
1148 @Override
1149 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001150 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1151 }
1152
1153 @Override
1154 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001155 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001156 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1157 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001158 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001159 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001160 }
1161
1162 @Override
1163 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001164 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001165 }
1166
1167 @Override
1168 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001169 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001170 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001171
Yorke Leecc4660d2014-04-24 11:22:57 -07001172 @Override
1173 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001174 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001175 // Only scroll the button when the first tab is selected. The button should scroll from
1176 // the middle to right position only on the transition from the first tab to the second
1177 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001178 // If the app is in RTL mode, we need to check against the second tab, rather than the
1179 // first. This is because if we are scrolling between the first and second tabs, the
1180 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1181 // reversal of the order of the tabs.
1182 final boolean isLayoutRtl = DialerUtils.isRtl();
1183 final boolean shouldScrollButton = position == (isLayoutRtl
1184 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1185 if (shouldScrollButton && !mIsLandscape) {
1186 mFloatingActionButtonController.onPageScrolled(
1187 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001188 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1189 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001190 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001191 }
1192
1193 @Override
1194 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001195 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001196 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001197 }
1198
1199 @Override
1200 public void onPageScrollStateChanged(int state) {
1201 }
1202
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001203 private TelephonyManager getTelephonyManager() {
1204 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1205 }
1206
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001207 private TelecomManager getTelecomManager() {
1208 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001209 }
1210
Yorke Lee5253be02014-05-21 18:50:03 -07001211 @Override
1212 public boolean isActionBarShowing() {
1213 return mActionBarController.isActionBarShowing();
1214 }
1215
Yorke Leec98a5bb2014-10-28 16:12:05 -07001216 @Override
1217 public ActionBarController getActionBarController() {
1218 return mActionBarController;
1219 }
1220
Andrew Lee9da8fb42014-06-03 14:03:09 -07001221 public boolean isDialpadShown() {
1222 return mIsDialpadShown;
1223 }
1224
Yorke Lee5253be02014-05-21 18:50:03 -07001225 @Override
1226 public int getActionBarHideOffset() {
1227 return getActionBar().getHideOffset();
1228 }
1229
1230 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001231 public void setActionBarHideOffset(int offset) {
1232 getActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001233 }
1234
1235 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001236 public int getActionBarHeight() {
1237 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001238 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001239
1240 /**
1241 * Updates controller based on currently known information.
1242 *
1243 * @param animate Whether or not to animate the transition.
1244 */
1245 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Lee405a6e62014-08-20 15:02:16 -07001246 int align = (!mIsLandscape && mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
1247 FloatingActionButtonController.ALIGN_MIDDLE :
1248 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001249 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001250 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001251}