blob: 70cf4a69c19b26444cff2ff399399bfd161f6073 [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;
Yorke Leeb82e8da2015-04-18 14:37:50 -070085import com.android.dialer.util.CallIntentUtil;
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 Lee35127cd2013-09-10 14:09:29 -0700201 * True if the dialpad is only temporarily showing due to being in call
202 */
203 private boolean mInCallDialpadUp;
204
205 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700206 * True when this activity has been launched for the first time.
207 */
Yorke Lee98702de2013-08-06 12:03:32 -0700208 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700209
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700210 /**
211 * Search query to be applied to the SearchView in the ActionBar once
212 * onCreateOptionsMenu has been called.
213 */
214 private String mPendingSearchViewQuery;
215
Yorke Lee74edcdc2014-07-11 16:15:08 -0700216 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700217 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700218 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700219
Yorke Leeef2b7382013-08-09 17:39:25 -0700220 private String mSearchQuery;
221
Yorke Leefce269a2013-08-12 11:56:04 -0700222 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700223 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700224 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700225
Sai Cheemalapati41460652014-06-02 21:05:39 -0700226 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700227
Andrew Lee2423a2f2014-05-29 14:14:45 -0700228 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700229
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800230 /**
231 * The text returned from a voice search query. Set in {@link #onActivityResult} and used in
232 * {@link #onResume()} to populate the search box.
233 */
234 private String mVoiceSearchQuery;
235
Andrew Lee467de3d2015-03-17 15:47:24 -0700236 protected class OptionsPopupMenu extends PopupMenu {
Andrew Leee74a10e2014-05-16 14:31:40 -0700237 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700238 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700239 }
240
241 @Override
242 public void show() {
243 final Menu menu = getMenu();
244 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700245 clearFrequents.setVisible(mListsFragment != null &&
246 mListsFragment.getSpeedDialFragment() != null &&
247 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700248 super.show();
249 }
250 }
251
Chiao Cheng94b10b52012-08-17 16:59:12 -0700252 /**
Yorke Lee28266192014-05-01 10:05:52 -0700253 * Listener that listens to drag events and sends their x and y coordinates to a
254 * {@link DragDropController}.
255 */
256 private class LayoutOnDragListener implements OnDragListener {
257 @Override
258 public boolean onDrag(View v, DragEvent event) {
259 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700260 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700261 }
262 return true;
263 }
264 }
265
266 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700267 * Listener used to send search queries to the phone search fragment.
268 */
Yorke Lee53a22302014-04-29 18:13:46 -0700269 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700270 @Override
271 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
272 }
Yorke Leec3766332013-07-31 11:13:16 -0700273
Andrew Lee99a570c2014-05-15 14:18:50 -0700274 @Override
275 public void onTextChanged(CharSequence s, int start, int before, int count) {
276 final String newText = s.toString();
277 if (newText.equals(mSearchQuery)) {
278 // If the query hasn't changed (perhaps due to activity being destroyed
279 // and restored, or user launching the same DIAL intent twice), then there is
280 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700281 return;
282 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700283 if (DEBUG) {
284 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700285 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700286 }
Yorke Lee710709d2014-05-29 07:18:42 -0700287 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700288
Andrew Lee90374a72014-05-16 15:01:09 -0700289 // Show search fragment only when the query string is changed to non-empty text.
290 if (!TextUtils.isEmpty(newText)) {
291 // Call enterSearchUi only if we are switching search modes, or showing a search
292 // fragment for the first time.
293 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
294 (!mIsDialpadShown && mInRegularSearch);
295 if (!sameSearchMode) {
296 enterSearchUi(mIsDialpadShown, mSearchQuery);
297 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700298 }
299
Andrew Leea8515422014-06-13 16:53:54 -0700300 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700301 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700302 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700303 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700304 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700305 }
306
307 @Override
308 public void afterTextChanged(Editable s) {
309 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700310 };
311
Andrew Leeb1903842014-05-15 16:11:24 -0700312
313 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700314 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700315 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700316 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700317 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700318 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700319 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700320 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700321 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
322 }
Andrew Leeb1903842014-05-15 16:11:24 -0700323 }
324 };
325
326 /**
327 * If the search term is empty and the user closes the soft keyboard, close the search UI.
328 */
329 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
330 @Override
331 public boolean onKey(View v, int keyCode, KeyEvent event) {
332 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
333 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700334 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700335 }
336 return false;
337 }
338 };
339
Chiao Cheng94b10b52012-08-17 16:59:12 -0700340 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700341 public boolean dispatchTouchEvent(MotionEvent ev) {
342 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
343 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
344 }
345 return super.dispatchTouchEvent(ev);
346
347 }
348
349 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700350 protected void onCreate(Bundle savedInstanceState) {
Yorke Leef5554ce2015-01-27 14:46:02 -0800351 Trace.beginSection(TAG + " onCreate");
Yorke Leec3766332013-07-31 11:13:16 -0700352 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700353 mFirstLaunch = true;
354
Andrew Lee2423a2f2014-05-29 14:14:45 -0700355 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700356 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700357
Yorke Leef5554ce2015-01-27 14:46:02 -0800358 Trace.beginSection(TAG + " setContentView");
Yorke Lee8898cd02013-08-08 10:24:27 -0700359 setContentView(R.layout.dialtacts_activity);
Yorke Leef5554ce2015-01-27 14:46:02 -0800360 Trace.endSection();
Yorke Lee9e91bb02014-03-05 17:50:50 -0800361 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700362
Yorke Leef5554ce2015-01-27 14:46:02 -0800363 Trace.beginSection(TAG + " setup Views");
Yorke Lee53a22302014-04-29 18:13:46 -0700364 final ActionBar actionBar = getActionBar();
365 actionBar.setCustomView(R.layout.search_edittext);
366 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700367 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700368
Andrew Lee04675a52014-06-05 18:36:20 -0700369 SearchEditTextLayout searchEditTextLayout =
Andrew Leee3f59a82015-02-26 12:06:35 -0800370 (SearchEditTextLayout) actionBar.getCustomView().findViewById(R.id.search_view_container);
Andrew Lee04675a52014-06-05 18:36:20 -0700371 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
372
Andrew Leee3f59a82015-02-26 12:06:35 -0800373 mActionBarController = new ActionBarController(this, searchEditTextLayout);
374
Andrew Lee04675a52014-06-05 18:36:20 -0700375 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700376 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700377 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
378 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
379 .setOnClickListener(mSearchViewOnClickListener);
380 searchEditTextLayout.findViewById(R.id.search_box_start_search)
381 .setOnClickListener(mSearchViewOnClickListener);
382 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700383 @Override
384 public void onBackButtonClicked() {
385 onBackPressed();
386 }
387 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700388
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700389 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700390 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700391
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700392 final View floatingActionButtonContainer = findViewById(
393 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700394 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
395 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700396 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700397 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700398
Andrew Lee04675a52014-06-05 18:36:20 -0700399 ImageButton optionsMenuButton =
400 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700401 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700402 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
403 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700404
Yorke Leed5c512a2015-01-30 14:42:53 -0800405 // Add the favorites fragment but only if savedInstanceState is null. Otherwise the
406 // fragment manager is responsible for recreating it.
Yorke Leec3766332013-07-31 11:13:16 -0700407 if (savedInstanceState == null) {
Andrew Leed10eef22015-05-01 15:40:10 -0700408 mListsFragment = new ListsFragment();
Ihab Awad526c0b82014-02-27 12:55:36 -0800409 getFragmentManager().beginTransaction()
Andrew Leed10eef22015-05-01 15:40:10 -0700410 .add(R.id.dialtacts_frame, mListsFragment, TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800411 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700412 } else {
413 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700414 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
415 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700416 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700417 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700418 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700419 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700420
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700421 final boolean isLayoutRtl = DialerUtils.isRtl();
422 if (mIsLandscape) {
423 mSlideIn = AnimationUtils.loadAnimation(this,
424 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
425 mSlideOut = AnimationUtils.loadAnimation(this,
426 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
427 } else {
428 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
429 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
430 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700431
Yorke Lee2fec47b2014-08-05 18:16:27 -0700432 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
433 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
434
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700435 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700436
Yorke Leef614f6f2014-10-03 10:44:19 -0700437 mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
438 mParentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700439 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700440 new ViewTreeObserver.OnGlobalLayoutListener() {
441 @Override
442 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700443 final ViewTreeObserver observer =
444 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700445 if (!observer.isAlive()) {
446 return;
447 }
448 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700449 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700450 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700451 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700452 }
453 });
Andrew Lee0c667702014-05-12 14:31:45 -0700454
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700455 setupActivityOverlay();
456
Yorke Leef5554ce2015-01-27 14:46:02 -0800457 Trace.endSection();
458
459 Trace.beginSection(TAG + " initialize smart dialing");
Yorke Lee0baa98b2013-08-22 10:55:16 -0700460 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700461 SmartDialPrefix.initializeNanpSettings(this);
Yorke Leef5554ce2015-01-27 14:46:02 -0800462 Trace.endSection();
463 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700464 }
465
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700466 private void setupActivityOverlay() {
467 final View activityOverlay = findViewById(R.id.activity_overlay);
468 activityOverlay.setOnTouchListener(new OnTouchListener() {
469 @Override
470 public boolean onTouch(View v, MotionEvent event) {
471 if (!mIsDialpadShown) {
472 maybeExitSearchUi();
473 }
474 return false;
475 }
476 });
477 }
478
Chiao Cheng94b10b52012-08-17 16:59:12 -0700479 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700480 protected void onResume() {
Yorke Leef5554ce2015-01-27 14:46:02 -0800481 Trace.beginSection(TAG + " onResume");
Yorke Leec3766332013-07-31 11:13:16 -0700482 super.onResume();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700483 mStateSaved = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700484 if (mFirstLaunch) {
485 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700486 } else if (!phoneIsInUse() && mInCallDialpadUp) {
487 hideDialpadFragment(false, true);
488 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700489 } else if (mShowDialpadOnResume) {
490 showDialpadFragment(false);
491 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700492 }
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800493
494 // If there was a voice query result returned in the {@link #onActivityResult} callback, it
495 // will have been stashed in mVoiceSearchQuery since the search results fragment cannot be
496 // shown until onResume has completed. Active the search UI and set the search term now.
497 if (!TextUtils.isEmpty(mVoiceSearchQuery)) {
498 mActionBarController.onSearchBoxTapped();
499 mSearchView.setText(mVoiceSearchQuery);
500 mVoiceSearchQuery = null;
501 }
502
Yorke Lee98702de2013-08-06 12:03:32 -0700503 mFirstLaunch = false;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800504
505 if (mIsRestarting) {
506 // This is only called when the activity goes from resumed -> paused -> resumed, so it
507 // will not cause an extra view to be sent out on rotation
508 if (mIsDialpadShown) {
509 AnalyticsUtil.sendScreenView(mDialpadFragment, this);
510 }
511 mIsRestarting = false;
512 }
Yorke Lee53a22302014-04-29 18:13:46 -0700513 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700514 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700515 updateFloatingActionButtonControllerAlignment(false /* animate */);
Yorke Leef5554ce2015-01-27 14:46:02 -0800516 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700517 }
518
519 @Override
Yorke Lee7ee5c422014-11-04 10:29:32 -0800520 protected void onRestart() {
521 super.onRestart();
522 mIsRestarting = true;
523 }
524
525 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700526 protected void onPause() {
527 if (mClearSearchOnPause) {
528 hideDialpadAndSearchUi();
529 mClearSearchOnPause = false;
530 }
Yorke Lee19e68ca2014-10-28 11:51:40 -0700531 if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) {
532 commitDialpadFragmentHide();
533 }
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700534 super.onPause();
535 }
536
537 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700538 protected void onSaveInstanceState(Bundle outState) {
539 super.onSaveInstanceState(outState);
540 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700541 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
542 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700543 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700544 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700545 mActionBarController.saveInstanceState(outState);
Yorke Lee19e68ca2014-10-28 11:51:40 -0700546 mStateSaved = true;
Yorke Leeef2b7382013-08-09 17:39:25 -0700547 }
548
549 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700550 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700551 if (fragment instanceof DialpadFragment) {
552 mDialpadFragment = (DialpadFragment) fragment;
Yorke Leed5c512a2015-01-30 14:42:53 -0800553 if (!mIsDialpadShown && !mShowDialpadOnResume) {
Yorke Lee50aba882014-05-28 20:04:31 -0700554 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
555 transaction.hide(mDialpadFragment);
556 transaction.commit();
557 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700558 } else if (fragment instanceof SmartDialSearchFragment) {
559 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700560 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700561 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700562 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700563 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700564 } else if (fragment instanceof ListsFragment) {
565 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700566 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700567 }
Yorke Leec3766332013-07-31 11:13:16 -0700568 }
569
Alon Albertb453e5b2013-09-10 15:54:23 -0700570 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700571 final Intent intent = new Intent(this, DialerSettingsActivity.class);
572 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700573 }
574
Chiao Cheng94b10b52012-08-17 16:59:12 -0700575 @Override
576 public void onClick(View view) {
577 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700578 case R.id.floating_action_button:
Andrew Leefdfeaaf2015-05-05 14:10:35 -0700579 if (mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
580 sendAddNewContactIntent();
581 } else if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700582 mInCallDialpadUp = false;
583 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700584 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700585 break;
Yorke Leec3766332013-07-31 11:13:16 -0700586 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800587 try {
588 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
589 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
590 } catch (ActivityNotFoundException e) {
591 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
592 Toast.LENGTH_SHORT).show();
593 }
Yorke Leec3766332013-07-31 11:13:16 -0700594 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700595 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700596 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700597 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700598 default: {
599 Log.wtf(TAG, "Unexpected onClick event from " + view);
600 break;
601 }
602 }
603 }
604
Yorke Leec3766332013-07-31 11:13:16 -0700605 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700606 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700607 switch (item.getItemId()) {
608 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700609 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700610 break;
611 case R.id.menu_add_contact:
Andrew Leefdfeaaf2015-05-05 14:10:35 -0700612 sendAddNewContactIntent();
Yorke Lee86e21f72014-04-02 16:49:38 -0700613 break;
614 case R.id.menu_import_export:
615 // We hard-code the "contactsAreAvailable" argument because doing it properly would
616 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
617 // now in Dialtacts for (potential) performance reasons. Compare with how it is
618 // done in {@link PeopleActivity}.
619 ImportExportDialogFragment.show(getFragmentManager(), true,
620 DialtactsActivity.class);
621 return true;
622 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700623 ClearFrequentsDialog.show(getFragmentManager());
624 return true;
625 case R.id.menu_call_settings:
626 handleMenuSettings();
627 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700628 }
629 return false;
630 }
631
632 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700633 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
634 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
635 if (resultCode == RESULT_OK) {
636 final ArrayList<String> matches = data.getStringArrayListExtra(
637 RecognizerIntent.EXTRA_RESULTS);
638 if (matches.size() > 0) {
639 final String match = matches.get(0);
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800640 mVoiceSearchQuery = match;
Yorke Leec3766332013-07-31 11:13:16 -0700641 } else {
642 Log.e(TAG, "Voice search - nothing heard");
643 }
644 } else {
645 Log.e(TAG, "Voice search failed");
646 }
647 }
648 super.onActivityResult(requestCode, resultCode, data);
649 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700650
Andrew Lee2a58ab82014-05-15 02:16:04 -0700651 /**
652 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
653 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
654 * @see #onDialpadShown
655 */
Yorke Leec3766332013-07-31 11:13:16 -0700656 private void showDialpadFragment(boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700657 if (mIsDialpadShown || mStateSaved) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700658 return;
659 }
660 mIsDialpadShown = true;
Yorke Leed5c512a2015-01-30 14:42:53 -0800661
Yorke Lee7ee5c422014-11-04 10:29:32 -0800662 mListsFragment.setUserVisibleHint(false);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700663
Chiao Cheng94b10b52012-08-17 16:59:12 -0700664 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leed5c512a2015-01-30 14:42:53 -0800665 if (mDialpadFragment == null) {
666 mDialpadFragment = new DialpadFragment();
667 ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT);
668 } else {
669 ft.show(mDialpadFragment);
670 }
671
672 mDialpadFragment.setAnimate(animate);
673 AnalyticsUtil.sendScreenView(mDialpadFragment);
Yorke Leec3766332013-07-31 11:13:16 -0700674 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700675
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700676 if (animate) {
677 mFloatingActionButtonController.scaleOut();
678 } else {
679 mFloatingActionButtonController.setVisible(false);
680 }
Yorke Lee5253be02014-05-21 18:50:03 -0700681 mActionBarController.onDialpadUp();
682
Andrew Leeb1903842014-05-15 16:11:24 -0700683 if (!isInSearchUi()) {
684 enterSearchUi(true /* isSmartDial */, mSearchQuery);
685 }
Yorke Leec3766332013-07-31 11:13:16 -0700686 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700687
Andrew Lee2a58ab82014-05-15 02:16:04 -0700688 /**
689 * Callback from child DialpadFragment when the dialpad is shown.
690 */
691 public void onDialpadShown() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800692 Assert.assertNotNull(mDialpadFragment);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700693 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700694 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700695 } else {
696 mDialpadFragment.setYFraction(0);
697 }
698
Andrew Lee2a58ab82014-05-15 02:16:04 -0700699 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700700 }
701
702 /**
703 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
704 * a callback after the hide animation ends.
705 * @see #commitDialpadFragmentHide
706 */
Yorke Leeca195042013-09-25 16:29:38 -0700707 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700708 if (mDialpadFragment == null) {
709 return;
710 }
Yorke Leef6673d32013-08-23 15:34:17 -0700711 if (clearDialpad) {
712 mDialpadFragment.clearDialpad();
713 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700714 if (!mIsDialpadShown) {
715 return;
Yorke Leec3766332013-07-31 11:13:16 -0700716 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700717 mIsDialpadShown = false;
718 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800719 mListsFragment.setUserVisibleHint(true);
720 mListsFragment.sendScreenViewForCurrentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700721
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700722 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700723
724 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700725 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700726 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700727 } else {
728 commitDialpadFragmentHide();
729 }
730
Yorke Lee5253be02014-05-21 18:50:03 -0700731 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700732
Andrew Leed4cde832014-05-16 15:56:48 -0700733 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700734 if (TextUtils.isEmpty(mSearchQuery)) {
735 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700736 }
Andrew Leed4cde832014-05-16 15:56:48 -0700737 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700738 }
739
740 /**
741 * Finishes hiding the dialpad fragment after any animations are completed.
742 */
743 private void commitDialpadFragmentHide() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800744 if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700745 final FragmentTransaction ft = getFragmentManager().beginTransaction();
746 ft.hide(mDialpadFragment);
747 ft.commit();
748 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700749 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700750 }
751
Andrew Lee2a58ab82014-05-15 02:16:04 -0700752 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700753 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700754 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700755 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700756 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700757 fragment = mRegularSearchFragment;
758 }
759 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700760 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700761 }
762 }
763
Yorke Lee5253be02014-05-21 18:50:03 -0700764 @Override
765 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700766 return mInDialpadSearch || mInRegularSearch;
767 }
768
Yorke Lee5253be02014-05-21 18:50:03 -0700769 @Override
770 public boolean hasSearchQuery() {
771 return !TextUtils.isEmpty(mSearchQuery);
772 }
773
774 @Override
775 public boolean shouldShowActionBar() {
776 return mListsFragment.shouldShowActionBar();
777 }
778
Yorke Leeb207f8a2013-08-29 18:51:06 -0700779 private void setNotInSearchUi() {
780 mInDialpadSearch = false;
781 mInRegularSearch = false;
782 }
783
Yorke Lee311969c2013-08-26 06:31:11 -0700784 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700785 if (mIsDialpadShown) {
786 hideDialpadFragment(false, true);
787 } else {
788 exitSearchUi();
789 }
Yorke Lee311969c2013-08-26 06:31:11 -0700790 }
791
Yorke Lee53a22302014-04-29 18:13:46 -0700792 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700793 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
794 if (canIntentBeHandled(voiceIntent)) {
795 mVoiceSearchButton.setVisibility(View.VISIBLE);
796 mVoiceSearchButton.setOnClickListener(this);
797 } else {
798 mVoiceSearchButton.setVisibility(View.GONE);
799 }
800 }
801
Andrew Lee467de3d2015-03-17 15:47:24 -0700802 protected OptionsPopupMenu buildOptionsMenu(View invoker) {
Andrew Leee74a10e2014-05-16 14:31:40 -0700803 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
804 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700805 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700806 popupMenu.setOnMenuItemClickListener(this);
807 return popupMenu;
808 }
809
Yorke Lee86e21f72014-04-02 16:49:38 -0700810 @Override
811 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700812 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700813 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700814 mPendingSearchViewQuery = null;
815 }
Yorke Leea524ae52014-08-05 18:01:05 -0700816 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700817 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700818 }
819
Chiao Cheng94b10b52012-08-17 16:59:12 -0700820 /**
821 * Returns true if the intent is due to hitting the green send key (hardware call button:
822 * KEYCODE_CALL) while in a call.
823 *
824 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700825 * @return true if the intent is due to hitting the green send key while in a call
826 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700827 private boolean isSendKeyWhileInCall(Intent intent) {
828 // If there is a call in progress and the user launched the dialer by hitting the call
829 // button, go straight to the in-call screen.
830 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700831
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700832 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700833 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700834 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700835 }
836
837 return false;
838 }
839
840 /**
841 * Sets the current tab based on the intent's request type
842 *
843 * @param intent Intent that contains information about which tab should be selected
844 */
Yorke Leec3766332013-07-31 11:13:16 -0700845 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700846 // 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 -0700847 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700848 finish();
849 return;
850 }
851
Yorke Leed5c512a2015-01-30 14:42:53 -0800852 final boolean phoneIsInUse = phoneIsInUse();
853 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
854 showDialpadFragment(false);
855 mDialpadFragment.setStartedFromNewIntent(true);
856 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
857 mInCallDialpadUp = true;
Yorke Lee35127cd2013-09-10 14:09:29 -0700858 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700859 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700860 }
861
862 @Override
863 public void onNewIntent(Intent newIntent) {
864 setIntent(newIntent);
Nancy Chen199b7f02014-11-05 15:03:00 -0800865 mStateSaved = false;
Yorke Leec3766332013-07-31 11:13:16 -0700866 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700867
Chiao Cheng94b10b52012-08-17 16:59:12 -0700868 invalidateOptionsMenu();
869 }
870
871 /** Returns true if the given intent contains a phone number to populate the dialer with */
872 private boolean isDialIntent(Intent intent) {
873 final String action = intent.getAction();
874 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
875 return true;
876 }
877 if (Intent.ACTION_VIEW.equals(action)) {
878 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700879 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700880 return true;
881 }
882 }
883 return false;
884 }
885
886 /**
887 * Returns an appropriate call origin for this Activity. May return null when no call origin
888 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
889 * for remembering the tab in which the user made a phone call, so the external app's DIAL
890 * request should not be counted.)
891 */
892 public String getCallOrigin() {
893 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
894 }
895
Chiao Cheng94b10b52012-08-17 16:59:12 -0700896 /**
Yorke Leec3766332013-07-31 11:13:16 -0700897 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700898 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700899 private void enterSearchUi(boolean smartDialSearch, String query) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700900 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700901 // Weird race condition where fragment is doing work after the activity is destroyed
902 // due to talkback being on (b/10209937). Just return since we can't do any
903 // constructive here.
904 return;
905 }
906
Yorke Leeef2b7382013-08-09 17:39:25 -0700907 if (DEBUG) {
908 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
909 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700910
Yorke Leec3766332013-07-31 11:13:16 -0700911 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700912 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700913 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700914 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700915 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700916 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700917
Yorke Leeb207f8a2013-08-29 18:51:06 -0700918 final String tag;
919 if (smartDialSearch) {
920 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
921 } else {
922 tag = TAG_REGULAR_SEARCH_FRAGMENT;
923 }
924 mInDialpadSearch = smartDialSearch;
925 mInRegularSearch = !smartDialSearch;
926
Andrew Lee752956e2014-05-15 11:43:38 -0700927 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700928 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700929 if (fragment == null) {
930 if (smartDialSearch) {
931 fragment = new SmartDialSearchFragment();
932 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700933 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700934 }
Andrew Leeb1903842014-05-15 16:11:24 -0700935 transaction.add(R.id.dialtacts_frame, fragment, tag);
936 } else {
937 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700938 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700939 // DialtactsActivity will provide the options menu
940 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700941 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700942 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700943 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700944
945 mListsFragment.getView().animate().alpha(0).withLayer();
Yorke Lee7ee5c422014-11-04 10:29:32 -0800946 mListsFragment.setUserVisibleHint(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700947 }
948
949 /**
Yorke Leec3766332013-07-31 11:13:16 -0700950 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700951 */
Yorke Leec3766332013-07-31 11:13:16 -0700952 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700953 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700954 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -0700955 return;
956 }
Andrew Leeb1903842014-05-15 16:11:24 -0700957
Andrew Leeb1903842014-05-15 16:11:24 -0700958 mSearchView.setText(null);
Yorke Leed5c512a2015-01-30 14:42:53 -0800959
960 if (mDialpadFragment != null) {
961 mDialpadFragment.clearDialpad();
962 }
963
Yorke Leeb207f8a2013-08-29 18:51:06 -0700964 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700965
Andrew Leeb1903842014-05-15 16:11:24 -0700966 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700967 if (mSmartDialSearchFragment != null) {
968 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700969 }
Andrew Leeb1903842014-05-15 16:11:24 -0700970 if (mRegularSearchFragment != null) {
971 transaction.remove(mRegularSearchFragment);
972 }
973 transaction.commit();
974
975 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Leed5c512a2015-01-30 14:42:53 -0800976
977 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
Yorke Lee7ee5c422014-11-04 10:29:32 -0800978 // If the dialpad fragment wasn't previously visible, then send a screen view because
979 // we are exiting regular search. Otherwise, the screen view will be sent by
980 // {@link #hideDialpadFragment}.
981 mListsFragment.sendScreenViewForCurrentPosition();
982 mListsFragment.setUserVisibleHint(true);
983 }
984
Yorke Lee5253be02014-05-21 18:50:03 -0700985 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700986 }
987
Chiao Cheng94b10b52012-08-17 16:59:12 -0700988 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700989 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700990 if (mStateSaved) {
991 return;
992 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700993 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700994 if (TextUtils.isEmpty(mSearchQuery) ||
995 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
996 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700997 exitSearchUi();
998 }
Yorke Leef6673d32013-08-23 15:34:17 -0700999 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -07001000 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -07001001 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001002 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001003 } else {
1004 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001005 }
Yorke Leec3766332013-07-31 11:13:16 -07001006 }
1007
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001008 /**
1009 * @return True if the search UI was exited, false otherwise
1010 */
1011 private boolean maybeExitSearchUi() {
1012 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
1013 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001014 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001015 return true;
1016 }
1017 return false;
1018 }
1019
Yorke Leec3766332013-07-31 11:13:16 -07001020 @Override
1021 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -07001022 if (mSmartDialSearchFragment != null) {
1023 mSmartDialSearchFragment.setAddToContactNumber(query);
1024 }
Yorke Leec3766332013-07-31 11:13:16 -07001025 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
1026 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -07001027
1028 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001029 if (DEBUG) {
1030 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1031 }
1032 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1033 // This callback can happen if the dialpad fragment is recreated because of
1034 // activity destruction. In that case, don't update the search view because
1035 // that would bring the user back to the search fragment regardless of the
1036 // previous state of the application. Instead, just return here and let the
1037 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001038 if (!TextUtils.isEmpty(normalizedQuery)) {
1039 mPendingSearchViewQuery = normalizedQuery;
1040 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001041 return;
1042 }
Yorke Lee53a22302014-04-29 18:13:46 -07001043 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001044 }
1045 }
Yorke Leec3766332013-07-31 11:13:16 -07001046
1047 @Override
1048 public void onListFragmentScrollStateChange(int scrollState) {
1049 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001050 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -07001051 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001052 }
1053 }
1054
1055 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001056 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001057 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001058 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1059 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001060 }
1061
Yorke Leec3766332013-07-31 11:13:16 -07001062 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001063 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001064 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001065
Yorke Leee1424812013-09-04 18:24:48 -07001066 public static Intent getAddNumberToContactIntent(CharSequence text) {
Tyler Gunn1513fec2014-12-05 14:19:00 -08001067 return getAddToContactIntent(null /* name */, text /* phoneNumber */,
1068 -1 /* phoneNumberType */);
1069 }
1070
1071 public static Intent getAddToContactIntent(CharSequence name, CharSequence phoneNumber,
1072 int phoneNumberType) {
1073 Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1074 intent.putExtra(Intents.Insert.PHONE, phoneNumber);
1075 // Only include the name and phone type extras if they are specified (the method
1076 // getAddNumberToContactIntent does not use them).
1077 if (name != null) {
1078 intent.putExtra(Intents.Insert.NAME, name);
1079 }
1080 if (phoneNumberType != -1) {
1081 intent.putExtra(Intents.Insert.PHONE_TYPE, phoneNumberType);
1082 }
Yorke Leee1424812013-09-04 18:24:48 -07001083 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1084 return intent;
1085 }
1086
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001087 private void sendAddNewContactIntent() {
1088 try {
1089 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
1090 } catch (ActivityNotFoundException e) {
1091 Toast toast = Toast.makeText(this,
1092 R.string.add_contact_not_available,
1093 Toast.LENGTH_SHORT);
1094 toast.show();
1095 }
1096 }
1097
Yorke Leeda0f9042013-12-05 14:25:51 -08001098 private boolean canIntentBeHandled(Intent intent) {
1099 final PackageManager packageManager = getPackageManager();
1100 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1101 PackageManager.MATCH_DEFAULT_ONLY);
1102 return resolveInfo != null && resolveInfo.size() > 0;
1103 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001104
Yorke Lee6a1461a2014-04-21 16:27:14 -07001105 @Override
1106 public void showCallHistory() {
1107 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1108 // CONTENT_TYPE, so that we always open our call log from our dialer
1109 final Intent intent = new Intent(this, CallLogActivity.class);
1110 startActivity(intent);
1111 }
1112
Yorke Lee86e21f72014-04-02 16:49:38 -07001113 /**
1114 * Called when the user has long-pressed a contact tile to start a drag operation.
1115 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001116 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001117 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Lee18963442014-06-06 17:20:13 -07001118 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001119 }
1120
1121 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001122 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1123 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001124
Yorke Lee86e21f72014-04-02 16:49:38 -07001125 /**
1126 * Called when the user has released a contact tile after long-pressing it.
1127 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001128 @Override
1129 public void onDragFinished(int x, int y) {
Andrew Lee18963442014-06-06 17:20:13 -07001130 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001131 }
1132
1133 @Override
1134 public void onDroppedOnRemove() {}
1135
1136 /**
Yorke Leed999b712014-04-23 15:10:58 -07001137 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001138 * once it has been attached to the activity.
1139 */
1140 @Override
1141 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001142 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001143 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001144 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001145
1146 @Override
1147 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001148 // Specify call-origin so that users will see the previous tab instead of
1149 // CallLog screen (search UI will be automatically exited).
1150 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001151 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001152 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001153 }
1154
1155 @Override
1156 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001157 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1158 }
1159
1160 @Override
1161 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001162 Intent intent = isVideoCall ?
Yorke Leeb82e8da2015-04-18 14:37:50 -07001163 CallIntentUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1164 CallIntentUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001165 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001166 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001167 }
1168
1169 @Override
1170 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001171 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001172 }
1173
1174 @Override
1175 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001176 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001177 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001178
Yorke Leecc4660d2014-04-24 11:22:57 -07001179 @Override
1180 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001181 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001182 // Only scroll the button when the first tab is selected. The button should scroll from
1183 // the middle to right position only on the transition from the first tab to the second
1184 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001185 // If the app is in RTL mode, we need to check against the second tab, rather than the
1186 // first. This is because if we are scrolling between the first and second tabs, the
1187 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1188 // reversal of the order of the tabs.
1189 final boolean isLayoutRtl = DialerUtils.isRtl();
1190 final boolean shouldScrollButton = position == (isLayoutRtl
1191 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1192 if (shouldScrollButton && !mIsLandscape) {
1193 mFloatingActionButtonController.onPageScrolled(
1194 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001195 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1196 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001197 }
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001198
1199 if (position == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
1200 mFloatingActionButtonController.changeIcon(
1201 getResources().getDrawable(R.drawable.ic_person_add_24dp),
1202 getResources().getString(R.string.search_shortcut_create_new_contact));
1203 } else {
1204 mFloatingActionButtonController.changeIcon(
1205 getResources().getDrawable(R.drawable.fab_ic_dial),
1206 getResources().getString(R.string.action_menu_dialpad_button));
1207 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001208 }
1209
1210 @Override
1211 public void onPageSelected(int position) {
Yorke Leecc4660d2014-04-24 11:22:57 -07001212 }
1213
1214 @Override
1215 public void onPageScrollStateChanged(int state) {
1216 }
1217
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001218 private TelecomManager getTelecomManager() {
1219 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001220 }
1221
Yorke Lee5253be02014-05-21 18:50:03 -07001222 @Override
1223 public boolean isActionBarShowing() {
1224 return mActionBarController.isActionBarShowing();
1225 }
1226
Yorke Leec98a5bb2014-10-28 16:12:05 -07001227 @Override
1228 public ActionBarController getActionBarController() {
1229 return mActionBarController;
1230 }
1231
Andrew Lee9da8fb42014-06-03 14:03:09 -07001232 public boolean isDialpadShown() {
1233 return mIsDialpadShown;
1234 }
1235
Yorke Lee5253be02014-05-21 18:50:03 -07001236 @Override
1237 public int getActionBarHideOffset() {
1238 return getActionBar().getHideOffset();
1239 }
1240
1241 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001242 public void setActionBarHideOffset(int offset) {
1243 getActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001244 }
1245
1246 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001247 public int getActionBarHeight() {
1248 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001249 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001250
1251 /**
1252 * Updates controller based on currently known information.
1253 *
1254 * @param animate Whether or not to animate the transition.
1255 */
1256 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Leefdfeaaf2015-05-05 14:10:35 -07001257 int align = (!mIsLandscape &&
1258 mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
Andrew Lee405a6e62014-08-20 15:02:16 -07001259 FloatingActionButtonController.ALIGN_MIDDLE :
1260 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001261 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001262 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001263}