blob: 61aeed5b0e70c01de1b8228c80a621584818c11f [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
Brian Attwellc311af12014-10-22 18:28:58 -070062import com.android.contacts.common.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070063import com.android.contacts.common.dialog.ClearFrequentsDialog;
64import com.android.contacts.common.interactions.ImportExportDialogFragment;
Nancy Chen0d3a7392014-08-12 14:44:53 -070065import com.android.contacts.common.interactions.TouchPointManager;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080066import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070067import com.android.contacts.common.widget.FloatingActionButtonController;
Brian Attwellbeab3bb2014-10-27 12:24:49 -070068import com.android.contacts.commonbind.analytics.AnalyticsUtil;
Yorke Leec3766332013-07-31 11:13:16 -070069import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070070import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070071import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070072import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070073import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070074import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080075import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070076import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080077import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070078import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070079import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070080import com.android.dialer.list.RegularSearchFragment;
81import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070082import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070083import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070084import com.android.dialer.settings.DialerSettingsActivity;
Brian Attwell82043242015-02-03 14:13:58 -080085import com.android.dialer.util.PrivilegedCallUtil;
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 Leed5c512a2015-01-30 14:42:53 -080094import junit.framework.Assert;
95
Yorke Leec3766332013-07-31 11:13:16 -070096import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080097import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070098
Chiao Cheng94b10b52012-08-17 16:59:12 -070099/**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700100 * The dialer tab's title is 'phone', a more common name (see strings.xml).
101 */
Yorke Leec3766332013-07-31 11:13:16 -0700102public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700103 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700104 OnListFragmentScrolledListener,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700105 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700106 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700107 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700108 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700109 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700110 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700111 ViewPager.OnPageChangeListener,
112 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700113 private static final String TAG = "DialtactsActivity";
114
Ihab Awad526c0b82014-02-27 12:55:36 -0800115 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700116
Yorke Leef74011e2013-08-02 11:30:30 -0700117 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
118
Chiao Cheng94b10b52012-08-17 16:59:12 -0700119 /** @see #getCallOrigin() */
120 private static final String CALL_ORIGIN_DIALTACTS =
121 "com.android.dialer.DialtactsActivity";
122
Yorke Leeb207f8a2013-08-29 18:51:06 -0700123 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
124 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700125 private static final String KEY_SEARCH_QUERY = "search_query";
126 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700127 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700128
Yorke Leec3766332013-07-31 11:13:16 -0700129 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
130 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
131 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
132 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700133
Chiao Cheng94b10b52012-08-17 16:59:12 -0700134 /**
135 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
136 */
137 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
138
Yorke Leec3766332013-07-31 11:13:16 -0700139 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700140
Yorke Leef614f6f2014-10-03 10:44:19 -0700141 private FrameLayout mParentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700142
Yorke Leec3766332013-07-31 11:13:16 -0700143 /**
Yorke Leec3766332013-07-31 11:13:16 -0700144 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700145 */
Evan Charlton72d66252014-11-07 16:23:47 -0800146 protected DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700147
148 /**
149 * Fragment for searching phone numbers using the alphanumeric keyboard.
150 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700151 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700152
153 /**
154 * Fragment for searching phone numbers using the dialpad.
155 */
156 private SmartDialSearchFragment mSmartDialSearchFragment;
157
Yorke Leee00c9fe2014-04-12 12:42:06 -0700158 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700159 * Animation that slides in.
160 */
161 private Animation mSlideIn;
162
163 /**
164 * Animation that slides out.
165 */
166 private Animation mSlideOut;
167
168 /**
169 * Listener for after slide out animation completes on dialer fragment.
170 */
171 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
172 @Override
173 public void onAnimationEnd(Animation animation) {
174 commitDialpadFragmentHide();
175 }
176 };
177
178 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700179 * Fragment containing the speed dial list, recents list, and all contacts list.
180 */
181 private ListsFragment mListsFragment;
182
Yorke Lee19e68ca2014-10-28 11:51:40 -0700183 /**
184 * Tracks whether onSaveInstanceState has been called. If true, no fragment transactions can
185 * be commited.
186 */
187 private boolean mStateSaved;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800188 private boolean mIsRestarting;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700189 private boolean mInDialpadSearch;
190 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700191 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700192 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700193 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700194
Yorke Leeef2b7382013-08-09 17:39:25 -0700195 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700196 * Whether or not the device is in landscape orientation.
197 */
198 private boolean mIsLandscape;
199
200 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700201 * The position of the currently selected tab in the attached {@link ListsFragment}.
202 */
203 private int mCurrentTabPosition = 0;
204
205 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700206 * True if the dialpad is only temporarily showing due to being in call
207 */
208 private boolean mInCallDialpadUp;
209
210 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700211 * True when this activity has been launched for the first time.
212 */
Yorke Lee98702de2013-08-06 12:03:32 -0700213 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700214
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700215 /**
216 * Search query to be applied to the SearchView in the ActionBar once
217 * onCreateOptionsMenu has been called.
218 */
219 private String mPendingSearchViewQuery;
220
Yorke Lee74edcdc2014-07-11 16:15:08 -0700221 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700222 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700223 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700224
Yorke Leeef2b7382013-08-09 17:39:25 -0700225 private String mSearchQuery;
226
Yorke Leefce269a2013-08-12 11:56:04 -0700227 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700228 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700229 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700230
Sai Cheemalapati41460652014-06-02 21:05:39 -0700231 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700232
Andrew Lee2423a2f2014-05-29 14:14:45 -0700233 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700234
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800235 /**
236 * The text returned from a voice search query. Set in {@link #onActivityResult} and used in
237 * {@link #onResume()} to populate the search box.
238 */
239 private String mVoiceSearchQuery;
240
Andrew Leee74a10e2014-05-16 14:31:40 -0700241 private class OptionsPopupMenu extends PopupMenu {
242 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700243 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700244 }
245
246 @Override
247 public void show() {
248 final Menu menu = getMenu();
249 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700250 clearFrequents.setVisible(mListsFragment != null &&
251 mListsFragment.getSpeedDialFragment() != null &&
252 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700253 super.show();
254 }
255 }
256
Chiao Cheng94b10b52012-08-17 16:59:12 -0700257 /**
Yorke Lee28266192014-05-01 10:05:52 -0700258 * Listener that listens to drag events and sends their x and y coordinates to a
259 * {@link DragDropController}.
260 */
261 private class LayoutOnDragListener implements OnDragListener {
262 @Override
263 public boolean onDrag(View v, DragEvent event) {
264 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700265 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700266 }
267 return true;
268 }
269 }
270
271 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700272 * Listener used to send search queries to the phone search fragment.
273 */
Yorke Lee53a22302014-04-29 18:13:46 -0700274 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700275 @Override
276 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
277 }
Yorke Leec3766332013-07-31 11:13:16 -0700278
Andrew Lee99a570c2014-05-15 14:18:50 -0700279 @Override
280 public void onTextChanged(CharSequence s, int start, int before, int count) {
281 final String newText = s.toString();
282 if (newText.equals(mSearchQuery)) {
283 // If the query hasn't changed (perhaps due to activity being destroyed
284 // and restored, or user launching the same DIAL intent twice), then there is
285 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700286 return;
287 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700288 if (DEBUG) {
289 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700290 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700291 }
Yorke Lee710709d2014-05-29 07:18:42 -0700292 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700293
Andrew Lee90374a72014-05-16 15:01:09 -0700294 // Show search fragment only when the query string is changed to non-empty text.
295 if (!TextUtils.isEmpty(newText)) {
296 // Call enterSearchUi only if we are switching search modes, or showing a search
297 // fragment for the first time.
298 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
299 (!mIsDialpadShown && mInRegularSearch);
300 if (!sameSearchMode) {
301 enterSearchUi(mIsDialpadShown, mSearchQuery);
302 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700303 }
304
Andrew Leea8515422014-06-13 16:53:54 -0700305 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700306 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700307 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700308 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700309 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700310 }
311
312 @Override
313 public void afterTextChanged(Editable s) {
314 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700315 };
316
Andrew Leeb1903842014-05-15 16:11:24 -0700317
318 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700319 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700320 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700321 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700322 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700323 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700324 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700325 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700326 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
327 }
Andrew Leeb1903842014-05-15 16:11:24 -0700328 }
329 };
330
331 /**
332 * If the search term is empty and the user closes the soft keyboard, close the search UI.
333 */
334 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
335 @Override
336 public boolean onKey(View v, int keyCode, KeyEvent event) {
337 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
338 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700339 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700340 }
341 return false;
342 }
343 };
344
Chiao Cheng94b10b52012-08-17 16:59:12 -0700345 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700346 public boolean dispatchTouchEvent(MotionEvent ev) {
347 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
348 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
349 }
350 return super.dispatchTouchEvent(ev);
351
352 }
353
354 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700355 protected void onCreate(Bundle savedInstanceState) {
Yorke Leef5554ce2015-01-27 14:46:02 -0800356 Trace.beginSection(TAG + " onCreate");
Yorke Leec3766332013-07-31 11:13:16 -0700357 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700358 mFirstLaunch = true;
359
Andrew Lee2423a2f2014-05-29 14:14:45 -0700360 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700361 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700362
Yorke Leef5554ce2015-01-27 14:46:02 -0800363 Trace.beginSection(TAG + " setContentView");
Yorke Lee8898cd02013-08-08 10:24:27 -0700364 setContentView(R.layout.dialtacts_activity);
Yorke Leef5554ce2015-01-27 14:46:02 -0800365 Trace.endSection();
Yorke Lee9e91bb02014-03-05 17:50:50 -0800366 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700367
Yorke Leef5554ce2015-01-27 14:46:02 -0800368 Trace.beginSection(TAG + " setup Views");
Yorke Lee53a22302014-04-29 18:13:46 -0700369 final ActionBar actionBar = getActionBar();
370 actionBar.setCustomView(R.layout.search_edittext);
371 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700372 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700373
Andrew Lee04675a52014-06-05 18:36:20 -0700374 SearchEditTextLayout searchEditTextLayout =
Andrew Leee3f59a82015-02-26 12:06:35 -0800375 (SearchEditTextLayout) actionBar.getCustomView().findViewById(R.id.search_view_container);
Andrew Lee04675a52014-06-05 18:36:20 -0700376 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
377
Andrew Leee3f59a82015-02-26 12:06:35 -0800378 mActionBarController = new ActionBarController(this, searchEditTextLayout);
379
Andrew Lee04675a52014-06-05 18:36:20 -0700380 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700381 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700382 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
383 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
384 .setOnClickListener(mSearchViewOnClickListener);
385 searchEditTextLayout.findViewById(R.id.search_box_start_search)
386 .setOnClickListener(mSearchViewOnClickListener);
387 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700388 @Override
389 public void onBackButtonClicked() {
390 onBackPressed();
391 }
392 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700393
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700394 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700395 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700396
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700397 final View floatingActionButtonContainer = findViewById(
398 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700399 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
400 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700401 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700402 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700403
Andrew Lee04675a52014-06-05 18:36:20 -0700404 ImageButton optionsMenuButton =
405 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700406 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700407 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
408 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700409
Yorke Leed5c512a2015-01-30 14:42:53 -0800410 // Add the favorites fragment but only if savedInstanceState is null. Otherwise the
411 // fragment manager is responsible for recreating it.
Yorke Leec3766332013-07-31 11:13:16 -0700412 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800413 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700414 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800415 .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 Leed5c512a2015-01-30 14:42:53 -0800557 if (!mIsDialpadShown && !mShowDialpadOnResume) {
Yorke Lee50aba882014-05-28 20:04:31 -0700558 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;
Yorke Leed5c512a2015-01-30 14:42:53 -0800670
Yorke Lee7ee5c422014-11-04 10:29:32 -0800671 mListsFragment.setUserVisibleHint(false);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700672
Chiao Cheng94b10b52012-08-17 16:59:12 -0700673 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leed5c512a2015-01-30 14:42:53 -0800674 if (mDialpadFragment == null) {
675 mDialpadFragment = new DialpadFragment();
676 ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT);
677 } else {
678 ft.show(mDialpadFragment);
679 }
680
681 mDialpadFragment.setAnimate(animate);
682 AnalyticsUtil.sendScreenView(mDialpadFragment);
Yorke Leec3766332013-07-31 11:13:16 -0700683 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700684
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700685 if (animate) {
686 mFloatingActionButtonController.scaleOut();
687 } else {
688 mFloatingActionButtonController.setVisible(false);
689 }
Yorke Lee5253be02014-05-21 18:50:03 -0700690 mActionBarController.onDialpadUp();
691
Andrew Leeb1903842014-05-15 16:11:24 -0700692 if (!isInSearchUi()) {
693 enterSearchUi(true /* isSmartDial */, mSearchQuery);
694 }
Yorke Leec3766332013-07-31 11:13:16 -0700695 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700696
Andrew Lee2a58ab82014-05-15 02:16:04 -0700697 /**
698 * Callback from child DialpadFragment when the dialpad is shown.
699 */
700 public void onDialpadShown() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800701 Assert.assertNotNull(mDialpadFragment);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700702 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700703 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700704 } else {
705 mDialpadFragment.setYFraction(0);
706 }
707
Andrew Lee2a58ab82014-05-15 02:16:04 -0700708 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700709 }
710
711 /**
712 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
713 * a callback after the hide animation ends.
714 * @see #commitDialpadFragmentHide
715 */
Yorke Leeca195042013-09-25 16:29:38 -0700716 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700717 if (mDialpadFragment == null) {
718 return;
719 }
Yorke Leef6673d32013-08-23 15:34:17 -0700720 if (clearDialpad) {
721 mDialpadFragment.clearDialpad();
722 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700723 if (!mIsDialpadShown) {
724 return;
Yorke Leec3766332013-07-31 11:13:16 -0700725 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700726 mIsDialpadShown = false;
727 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800728 mListsFragment.setUserVisibleHint(true);
729 mListsFragment.sendScreenViewForCurrentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700730
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700731 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700732
733 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700734 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700735 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700736 } else {
737 commitDialpadFragmentHide();
738 }
739
Yorke Lee5253be02014-05-21 18:50:03 -0700740 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700741
Andrew Leed4cde832014-05-16 15:56:48 -0700742 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700743 if (TextUtils.isEmpty(mSearchQuery)) {
744 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700745 }
Andrew Leed4cde832014-05-16 15:56:48 -0700746 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700747 }
748
749 /**
750 * Finishes hiding the dialpad fragment after any animations are completed.
751 */
752 private void commitDialpadFragmentHide() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800753 if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700754 final FragmentTransaction ft = getFragmentManager().beginTransaction();
755 ft.hide(mDialpadFragment);
756 ft.commit();
757 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700758 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700759 }
760
Andrew Lee2a58ab82014-05-15 02:16:04 -0700761 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700762 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700763 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700764 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700765 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700766 fragment = mRegularSearchFragment;
767 }
768 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700769 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700770 }
771 }
772
Yorke Lee5253be02014-05-21 18:50:03 -0700773 @Override
774 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700775 return mInDialpadSearch || mInRegularSearch;
776 }
777
Yorke Lee5253be02014-05-21 18:50:03 -0700778 @Override
779 public boolean hasSearchQuery() {
780 return !TextUtils.isEmpty(mSearchQuery);
781 }
782
783 @Override
784 public boolean shouldShowActionBar() {
785 return mListsFragment.shouldShowActionBar();
786 }
787
Yorke Leeb207f8a2013-08-29 18:51:06 -0700788 private void setNotInSearchUi() {
789 mInDialpadSearch = false;
790 mInRegularSearch = false;
791 }
792
Yorke Lee311969c2013-08-26 06:31:11 -0700793 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700794 if (mIsDialpadShown) {
795 hideDialpadFragment(false, true);
796 } else {
797 exitSearchUi();
798 }
Yorke Lee311969c2013-08-26 06:31:11 -0700799 }
800
Yorke Lee53a22302014-04-29 18:13:46 -0700801 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700802 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
803 if (canIntentBeHandled(voiceIntent)) {
804 mVoiceSearchButton.setVisibility(View.VISIBLE);
805 mVoiceSearchButton.setOnClickListener(this);
806 } else {
807 mVoiceSearchButton.setVisibility(View.GONE);
808 }
809 }
810
Andrew Leee74a10e2014-05-16 14:31:40 -0700811 private OptionsPopupMenu buildOptionsMenu(View invoker) {
812 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
813 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700814 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700815 popupMenu.setOnMenuItemClickListener(this);
816 return popupMenu;
817 }
818
Yorke Lee86e21f72014-04-02 16:49:38 -0700819 @Override
820 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700821 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700822 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700823 mPendingSearchViewQuery = null;
824 }
Yorke Leea524ae52014-08-05 18:01:05 -0700825 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700826 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700827 }
828
Chiao Cheng94b10b52012-08-17 16:59:12 -0700829 /**
830 * Returns true if the intent is due to hitting the green send key (hardware call button:
831 * KEYCODE_CALL) while in a call.
832 *
833 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700834 * @return true if the intent is due to hitting the green send key while in a call
835 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700836 private boolean isSendKeyWhileInCall(Intent intent) {
837 // If there is a call in progress and the user launched the dialer by hitting the call
838 // button, go straight to the in-call screen.
839 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700840
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700841 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700842 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700843 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700844 }
845
846 return false;
847 }
848
849 /**
850 * Sets the current tab based on the intent's request type
851 *
852 * @param intent Intent that contains information about which tab should be selected
853 */
Yorke Leec3766332013-07-31 11:13:16 -0700854 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700855 // 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 -0700856 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700857 finish();
858 return;
859 }
860
Yorke Leed5c512a2015-01-30 14:42:53 -0800861 final boolean phoneIsInUse = phoneIsInUse();
862 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
863 showDialpadFragment(false);
864 mDialpadFragment.setStartedFromNewIntent(true);
865 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
866 mInCallDialpadUp = true;
Yorke Lee35127cd2013-09-10 14:09:29 -0700867 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700868 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700869 }
870
871 @Override
872 public void onNewIntent(Intent newIntent) {
873 setIntent(newIntent);
Nancy Chen199b7f02014-11-05 15:03:00 -0800874 mStateSaved = false;
Yorke Leec3766332013-07-31 11:13:16 -0700875 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700876
Chiao Cheng94b10b52012-08-17 16:59:12 -0700877 invalidateOptionsMenu();
878 }
879
880 /** Returns true if the given intent contains a phone number to populate the dialer with */
881 private boolean isDialIntent(Intent intent) {
882 final String action = intent.getAction();
883 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
884 return true;
885 }
886 if (Intent.ACTION_VIEW.equals(action)) {
887 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700888 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700889 return true;
890 }
891 }
892 return false;
893 }
894
895 /**
896 * Returns an appropriate call origin for this Activity. May return null when no call origin
897 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
898 * for remembering the tab in which the user made a phone call, so the external app's DIAL
899 * request should not be counted.)
900 */
901 public String getCallOrigin() {
902 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
903 }
904
Chiao Cheng94b10b52012-08-17 16:59:12 -0700905 /**
Yorke Leec3766332013-07-31 11:13:16 -0700906 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700907 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700908 private void enterSearchUi(boolean smartDialSearch, String query) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700909 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700910 // Weird race condition where fragment is doing work after the activity is destroyed
911 // due to talkback being on (b/10209937). Just return since we can't do any
912 // constructive here.
913 return;
914 }
915
Yorke Leeef2b7382013-08-09 17:39:25 -0700916 if (DEBUG) {
917 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
918 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700919
Yorke Leec3766332013-07-31 11:13:16 -0700920 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700921 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700922 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700923 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700924 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700925 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700926
Yorke Leeb207f8a2013-08-29 18:51:06 -0700927 final String tag;
928 if (smartDialSearch) {
929 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
930 } else {
931 tag = TAG_REGULAR_SEARCH_FRAGMENT;
932 }
933 mInDialpadSearch = smartDialSearch;
934 mInRegularSearch = !smartDialSearch;
935
Andrew Lee752956e2014-05-15 11:43:38 -0700936 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700937 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700938 if (fragment == null) {
939 if (smartDialSearch) {
940 fragment = new SmartDialSearchFragment();
941 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700942 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700943 }
Andrew Leeb1903842014-05-15 16:11:24 -0700944 transaction.add(R.id.dialtacts_frame, fragment, tag);
945 } else {
946 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700947 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700948 // DialtactsActivity will provide the options menu
949 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700950 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700951 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700952 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700953
954 mListsFragment.getView().animate().alpha(0).withLayer();
Yorke Lee7ee5c422014-11-04 10:29:32 -0800955 mListsFragment.setUserVisibleHint(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700956 }
957
958 /**
Yorke Leec3766332013-07-31 11:13:16 -0700959 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700960 */
Yorke Leec3766332013-07-31 11:13:16 -0700961 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700962 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700963 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -0700964 return;
965 }
Andrew Leeb1903842014-05-15 16:11:24 -0700966
Andrew Leeb1903842014-05-15 16:11:24 -0700967 mSearchView.setText(null);
Yorke Leed5c512a2015-01-30 14:42:53 -0800968
969 if (mDialpadFragment != null) {
970 mDialpadFragment.clearDialpad();
971 }
972
Yorke Leeb207f8a2013-08-29 18:51:06 -0700973 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700974
Andrew Leeb1903842014-05-15 16:11:24 -0700975 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700976 if (mSmartDialSearchFragment != null) {
977 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700978 }
Andrew Leeb1903842014-05-15 16:11:24 -0700979 if (mRegularSearchFragment != null) {
980 transaction.remove(mRegularSearchFragment);
981 }
982 transaction.commit();
983
984 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Leed5c512a2015-01-30 14:42:53 -0800985
986 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
Yorke Lee7ee5c422014-11-04 10:29:32 -0800987 // If the dialpad fragment wasn't previously visible, then send a screen view because
988 // we are exiting regular search. Otherwise, the screen view will be sent by
989 // {@link #hideDialpadFragment}.
990 mListsFragment.sendScreenViewForCurrentPosition();
991 mListsFragment.setUserVisibleHint(true);
992 }
993
Yorke Lee5253be02014-05-21 18:50:03 -0700994 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700995 }
996
Chiao Cheng94b10b52012-08-17 16:59:12 -0700997 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700998 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700999 if (mStateSaved) {
1000 return;
1001 }
Andrew Lee2a58ab82014-05-15 02:16:04 -07001002 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -07001003 if (TextUtils.isEmpty(mSearchQuery) ||
1004 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
1005 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -07001006 exitSearchUi();
1007 }
Yorke Leef6673d32013-08-23 15:34:17 -07001008 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -07001009 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -07001010 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001011 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001012 } else {
1013 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001014 }
Yorke Leec3766332013-07-31 11:13:16 -07001015 }
1016
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001017 /**
1018 * @return True if the search UI was exited, false otherwise
1019 */
1020 private boolean maybeExitSearchUi() {
1021 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
1022 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001023 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001024 return true;
1025 }
1026 return false;
1027 }
1028
Yorke Leec3766332013-07-31 11:13:16 -07001029 @Override
1030 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -07001031 if (mSmartDialSearchFragment != null) {
1032 mSmartDialSearchFragment.setAddToContactNumber(query);
1033 }
Yorke Leec3766332013-07-31 11:13:16 -07001034 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
1035 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -07001036
1037 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001038 if (DEBUG) {
1039 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1040 }
1041 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1042 // This callback can happen if the dialpad fragment is recreated because of
1043 // activity destruction. In that case, don't update the search view because
1044 // that would bring the user back to the search fragment regardless of the
1045 // previous state of the application. Instead, just return here and let the
1046 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001047 if (!TextUtils.isEmpty(normalizedQuery)) {
1048 mPendingSearchViewQuery = normalizedQuery;
1049 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001050 return;
1051 }
Yorke Lee53a22302014-04-29 18:13:46 -07001052 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001053 }
1054 }
Yorke Leec3766332013-07-31 11:13:16 -07001055
1056 @Override
1057 public void onListFragmentScrollStateChange(int scrollState) {
1058 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001059 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -07001060 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001061 }
1062 }
1063
1064 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001065 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001066 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001067 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1068 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001069 }
1070
Yorke Leec3766332013-07-31 11:13:16 -07001071 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001072 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001073 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001074
Yorke Leee1424812013-09-04 18:24:48 -07001075 public static Intent getAddNumberToContactIntent(CharSequence text) {
Tyler Gunn1513fec2014-12-05 14:19:00 -08001076 return getAddToContactIntent(null /* name */, text /* phoneNumber */,
1077 -1 /* phoneNumberType */);
1078 }
1079
1080 public static Intent getAddToContactIntent(CharSequence name, CharSequence phoneNumber,
1081 int phoneNumberType) {
1082 Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1083 intent.putExtra(Intents.Insert.PHONE, phoneNumber);
1084 // Only include the name and phone type extras if they are specified (the method
1085 // getAddNumberToContactIntent does not use them).
1086 if (name != null) {
1087 intent.putExtra(Intents.Insert.NAME, name);
1088 }
1089 if (phoneNumberType != -1) {
1090 intent.putExtra(Intents.Insert.PHONE_TYPE, phoneNumberType);
1091 }
Yorke Leee1424812013-09-04 18:24:48 -07001092 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1093 return intent;
1094 }
1095
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 Lee6a1461a2014-04-21 16:27:14 -07001103 @Override
1104 public void showCallHistory() {
1105 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1106 // CONTENT_TYPE, so that we always open our call log from our dialer
1107 final Intent intent = new Intent(this, CallLogActivity.class);
1108 startActivity(intent);
1109 }
1110
Yorke Lee86e21f72014-04-02 16:49:38 -07001111 /**
1112 * Called when the user has long-pressed a contact tile to start a drag operation.
1113 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001114 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001115 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Lee18963442014-06-06 17:20:13 -07001116 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001117 }
1118
1119 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001120 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1121 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001122
Yorke Lee86e21f72014-04-02 16:49:38 -07001123 /**
1124 * Called when the user has released a contact tile after long-pressing it.
1125 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001126 @Override
1127 public void onDragFinished(int x, int y) {
Andrew Lee18963442014-06-06 17:20:13 -07001128 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001129 }
1130
1131 @Override
1132 public void onDroppedOnRemove() {}
1133
1134 /**
Yorke Leed999b712014-04-23 15:10:58 -07001135 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001136 * once it has been attached to the activity.
1137 */
1138 @Override
1139 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001140 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001141 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001142 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001143
1144 @Override
1145 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001146 // Specify call-origin so that users will see the previous tab instead of
1147 // CallLog screen (search UI will be automatically exited).
1148 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001149 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001150 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001151 }
1152
1153 @Override
1154 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001155 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1156 }
1157
1158 @Override
1159 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001160 Intent intent = isVideoCall ?
Brian Attwell82043242015-02-03 14:13:58 -08001161 PrivilegedCallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1162 PrivilegedCallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001163 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001164 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001165 }
1166
1167 @Override
1168 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001169 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001170 }
1171
1172 @Override
1173 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001174 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001175 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001176
Yorke Leecc4660d2014-04-24 11:22:57 -07001177 @Override
1178 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001179 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001180 // Only scroll the button when the first tab is selected. The button should scroll from
1181 // the middle to right position only on the transition from the first tab to the second
1182 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001183 // If the app is in RTL mode, we need to check against the second tab, rather than the
1184 // first. This is because if we are scrolling between the first and second tabs, the
1185 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1186 // reversal of the order of the tabs.
1187 final boolean isLayoutRtl = DialerUtils.isRtl();
1188 final boolean shouldScrollButton = position == (isLayoutRtl
1189 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1190 if (shouldScrollButton && !mIsLandscape) {
1191 mFloatingActionButtonController.onPageScrolled(
1192 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001193 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1194 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001195 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001196 }
1197
1198 @Override
1199 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001200 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001201 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001202 }
1203
1204 @Override
1205 public void onPageScrollStateChanged(int state) {
1206 }
1207
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001208 private TelephonyManager getTelephonyManager() {
1209 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1210 }
1211
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001212 private TelecomManager getTelecomManager() {
1213 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001214 }
1215
Yorke Lee5253be02014-05-21 18:50:03 -07001216 @Override
1217 public boolean isActionBarShowing() {
1218 return mActionBarController.isActionBarShowing();
1219 }
1220
Yorke Leec98a5bb2014-10-28 16:12:05 -07001221 @Override
1222 public ActionBarController getActionBarController() {
1223 return mActionBarController;
1224 }
1225
Andrew Lee9da8fb42014-06-03 14:03:09 -07001226 public boolean isDialpadShown() {
1227 return mIsDialpadShown;
1228 }
1229
Yorke Lee5253be02014-05-21 18:50:03 -07001230 @Override
1231 public int getActionBarHideOffset() {
1232 return getActionBar().getHideOffset();
1233 }
1234
1235 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001236 public void setActionBarHideOffset(int offset) {
1237 getActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001238 }
1239
1240 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001241 public int getActionBarHeight() {
1242 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001243 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001244
1245 /**
1246 * Updates controller based on currently known information.
1247 *
1248 * @param animate Whether or not to animate the transition.
1249 */
1250 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Lee405a6e62014-08-20 15:02:16 -07001251 int align = (!mIsLandscape && mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
1252 FloatingActionButtonController.ALIGN_MIDDLE :
1253 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001254 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001255 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001256}