blob: 5e6f035979ec22676c0a08ba4c50d0eb706a8fad [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;
Chiao Cheng94b10b52012-08-17 16:59:12 -070031import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070032import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070033import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070034import android.support.v4.view.ViewPager;
Tyler Gunn9dc924c2014-09-12 09:33:50 -070035import android.telecom.PhoneAccount;
36import android.telecom.TelecomManager;
Yorke Leec3766332013-07-31 11:13:16 -070037import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070038import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070039import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070040import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070041import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070042import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070043import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070044import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070045import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070046import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070047import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070049import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070050import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070051import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070052import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070053import android.view.animation.AnimationUtils;
Yorke Leec3766332013-07-31 11:13:16 -070054import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070055import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070056import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070057import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070058import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080059import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070060
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070061import com.android.contacts.common.CallUtil;
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 Lee7d20f822014-06-19 17:09:33 -070085import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070086import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070087import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070088import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070089import com.android.dialerbind.DatabaseHelperManager;
Yorke Lee2fec47b2014-08-05 18:16:27 -070090import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070091import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070092
Yorke Leec3766332013-07-31 11:13:16 -070093import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080094import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070095
Chiao Cheng94b10b52012-08-17 16:59:12 -070096/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070097 * The dialer tab's title is 'phone', a more common name (see strings.xml).
98 */
Yorke Leec3766332013-07-31 11:13:16 -070099public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700100 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700101 OnListFragmentScrolledListener,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700102 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700103 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700104 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700105 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700106 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700107 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700108 ViewPager.OnPageChangeListener,
109 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700110 private static final String TAG = "DialtactsActivity";
111
Ihab Awad526c0b82014-02-27 12:55:36 -0800112 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700113
Yorke Leef74011e2013-08-02 11:30:30 -0700114 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
115
Chiao Cheng94b10b52012-08-17 16:59:12 -0700116 /** @see #getCallOrigin() */
117 private static final String CALL_ORIGIN_DIALTACTS =
118 "com.android.dialer.DialtactsActivity";
119
Yorke Leeb207f8a2013-08-29 18:51:06 -0700120 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
121 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700122 private static final String KEY_SEARCH_QUERY = "search_query";
123 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700124 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700125
Yorke Leec3766332013-07-31 11:13:16 -0700126 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
127 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
128 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
129 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700130
Chiao Cheng94b10b52012-08-17 16:59:12 -0700131 /**
132 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
133 */
134 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
135
Yorke Leec3766332013-07-31 11:13:16 -0700136 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700137
Yorke Leef614f6f2014-10-03 10:44:19 -0700138 private FrameLayout mParentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700139
Yorke Leec3766332013-07-31 11:13:16 -0700140 /**
Yorke Leec3766332013-07-31 11:13:16 -0700141 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700142 */
Evan Charlton72d66252014-11-07 16:23:47 -0800143 protected DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700144
145 /**
146 * Fragment for searching phone numbers using the alphanumeric keyboard.
147 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700148 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700149
150 /**
151 * Fragment for searching phone numbers using the dialpad.
152 */
153 private SmartDialSearchFragment mSmartDialSearchFragment;
154
Yorke Leee00c9fe2014-04-12 12:42:06 -0700155 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700156 * Animation that slides in.
157 */
158 private Animation mSlideIn;
159
160 /**
161 * Animation that slides out.
162 */
163 private Animation mSlideOut;
164
165 /**
166 * Listener for after slide out animation completes on dialer fragment.
167 */
168 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
169 @Override
170 public void onAnimationEnd(Animation animation) {
171 commitDialpadFragmentHide();
172 }
173 };
174
175 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700176 * Fragment containing the speed dial list, recents list, and all contacts list.
177 */
178 private ListsFragment mListsFragment;
179
Yorke Lee19e68ca2014-10-28 11:51:40 -0700180 /**
181 * Tracks whether onSaveInstanceState has been called. If true, no fragment transactions can
182 * be commited.
183 */
184 private boolean mStateSaved;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800185 private boolean mIsRestarting;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700186 private boolean mInDialpadSearch;
187 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700188 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700189 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700190 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700191
Yorke Leeef2b7382013-08-09 17:39:25 -0700192 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700193 * Whether or not the device is in landscape orientation.
194 */
195 private boolean mIsLandscape;
196
197 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700198 * The position of the currently selected tab in the attached {@link ListsFragment}.
199 */
200 private int mCurrentTabPosition = 0;
201
202 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700203 * True if the dialpad is only temporarily showing due to being in call
204 */
205 private boolean mInCallDialpadUp;
206
207 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700208 * True when this activity has been launched for the first time.
209 */
Yorke Lee98702de2013-08-06 12:03:32 -0700210 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700211
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700212 /**
213 * Search query to be applied to the SearchView in the ActionBar once
214 * onCreateOptionsMenu has been called.
215 */
216 private String mPendingSearchViewQuery;
217
Yorke Lee74edcdc2014-07-11 16:15:08 -0700218 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700219 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700220 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700221
Yorke Leeef2b7382013-08-09 17:39:25 -0700222 private String mSearchQuery;
223
Yorke Leefce269a2013-08-12 11:56:04 -0700224 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700225 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700226 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700227
Sai Cheemalapati41460652014-06-02 21:05:39 -0700228 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700229
Andrew Lee2423a2f2014-05-29 14:14:45 -0700230 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700231
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800232 /**
233 * The text returned from a voice search query. Set in {@link #onActivityResult} and used in
234 * {@link #onResume()} to populate the search box.
235 */
236 private String mVoiceSearchQuery;
237
Andrew Leee74a10e2014-05-16 14:31:40 -0700238 private class OptionsPopupMenu extends PopupMenu {
239 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700240 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700241 }
242
243 @Override
244 public void show() {
245 final Menu menu = getMenu();
246 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700247 clearFrequents.setVisible(mListsFragment != null &&
248 mListsFragment.getSpeedDialFragment() != null &&
249 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700250 super.show();
251 }
252 }
253
Chiao Cheng94b10b52012-08-17 16:59:12 -0700254 /**
Yorke Lee28266192014-05-01 10:05:52 -0700255 * Listener that listens to drag events and sends their x and y coordinates to a
256 * {@link DragDropController}.
257 */
258 private class LayoutOnDragListener implements OnDragListener {
259 @Override
260 public boolean onDrag(View v, DragEvent event) {
261 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700262 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700263 }
264 return true;
265 }
266 }
267
268 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700269 * Listener used to send search queries to the phone search fragment.
270 */
Yorke Lee53a22302014-04-29 18:13:46 -0700271 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700272 @Override
273 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
274 }
Yorke Leec3766332013-07-31 11:13:16 -0700275
Andrew Lee99a570c2014-05-15 14:18:50 -0700276 @Override
277 public void onTextChanged(CharSequence s, int start, int before, int count) {
278 final String newText = s.toString();
279 if (newText.equals(mSearchQuery)) {
280 // If the query hasn't changed (perhaps due to activity being destroyed
281 // and restored, or user launching the same DIAL intent twice), then there is
282 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700283 return;
284 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700285 if (DEBUG) {
286 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700287 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700288 }
Yorke Lee710709d2014-05-29 07:18:42 -0700289 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700290
Andrew Lee90374a72014-05-16 15:01:09 -0700291 // Show search fragment only when the query string is changed to non-empty text.
292 if (!TextUtils.isEmpty(newText)) {
293 // Call enterSearchUi only if we are switching search modes, or showing a search
294 // fragment for the first time.
295 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
296 (!mIsDialpadShown && mInRegularSearch);
297 if (!sameSearchMode) {
298 enterSearchUi(mIsDialpadShown, mSearchQuery);
299 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700300 }
301
Andrew Leea8515422014-06-13 16:53:54 -0700302 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700303 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700304 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700305 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700306 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700307 }
308
309 @Override
310 public void afterTextChanged(Editable s) {
311 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700312 };
313
Andrew Leeb1903842014-05-15 16:11:24 -0700314
315 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700316 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700317 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700318 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700319 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700320 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700321 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700322 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700323 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
324 }
Andrew Leeb1903842014-05-15 16:11:24 -0700325 }
326 };
327
328 /**
329 * If the search term is empty and the user closes the soft keyboard, close the search UI.
330 */
331 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
332 @Override
333 public boolean onKey(View v, int keyCode, KeyEvent event) {
334 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
335 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700336 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700337 }
338 return false;
339 }
340 };
341
Chiao Cheng94b10b52012-08-17 16:59:12 -0700342 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700343 public boolean dispatchTouchEvent(MotionEvent ev) {
344 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
345 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
346 }
347 return super.dispatchTouchEvent(ev);
348
349 }
350
351 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700352 protected void onCreate(Bundle savedInstanceState) {
353 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700354 mFirstLaunch = true;
355
Andrew Lee2423a2f2014-05-29 14:14:45 -0700356 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700357 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700358
Yorke Lee8898cd02013-08-08 10:24:27 -0700359 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800360 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700361
Yorke Lee53a22302014-04-29 18:13:46 -0700362 final ActionBar actionBar = getActionBar();
363 actionBar.setCustomView(R.layout.search_edittext);
364 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700365 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700366
Yorke Lee5253be02014-05-21 18:50:03 -0700367 mActionBarController = new ActionBarController(this,
368 (SearchEditTextLayout) actionBar.getCustomView());
369
Andrew Lee04675a52014-06-05 18:36:20 -0700370 SearchEditTextLayout searchEditTextLayout =
371 (SearchEditTextLayout) actionBar.getCustomView();
372 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
373
374 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700375 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700376 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
377 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
378 .setOnClickListener(mSearchViewOnClickListener);
379 searchEditTextLayout.findViewById(R.id.search_box_start_search)
380 .setOnClickListener(mSearchViewOnClickListener);
381 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700382 @Override
383 public void onBackButtonClicked() {
384 onBackPressed();
385 }
386 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700387
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700388 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700389 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700390
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700391 final View floatingActionButtonContainer = findViewById(
392 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700393 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
394 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700395 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700396 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700397
Andrew Lee04675a52014-06-05 18:36:20 -0700398 ImageButton optionsMenuButton =
399 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700400 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700401 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
402 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700403
Yorke Leeef2b7382013-08-09 17:39:25 -0700404 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
405 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700406 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800407 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700408 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800409 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
410 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700411 } else {
412 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700413 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
414 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700415 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700416 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700417 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700418 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700419
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700420 final boolean isLayoutRtl = DialerUtils.isRtl();
421 if (mIsLandscape) {
422 mSlideIn = AnimationUtils.loadAnimation(this,
423 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
424 mSlideOut = AnimationUtils.loadAnimation(this,
425 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
426 } else {
427 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
428 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
429 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700430
Yorke Lee2fec47b2014-08-05 18:16:27 -0700431 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
432 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
433
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700434 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700435
Yorke Leef614f6f2014-10-03 10:44:19 -0700436 mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
437 mParentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700438 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700439 new ViewTreeObserver.OnGlobalLayoutListener() {
440 @Override
441 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700442 final ViewTreeObserver observer =
443 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700444 if (!observer.isAlive()) {
445 return;
446 }
447 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700448 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700449 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700450 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700451 }
452 });
Andrew Lee0c667702014-05-12 14:31:45 -0700453
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700454 setupActivityOverlay();
455
Yorke Lee0baa98b2013-08-22 10:55:16 -0700456 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700457 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700458 }
459
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700460 private void setupActivityOverlay() {
461 final View activityOverlay = findViewById(R.id.activity_overlay);
462 activityOverlay.setOnTouchListener(new OnTouchListener() {
463 @Override
464 public boolean onTouch(View v, MotionEvent event) {
465 if (!mIsDialpadShown) {
466 maybeExitSearchUi();
467 }
468 return false;
469 }
470 });
471 }
472
Chiao Cheng94b10b52012-08-17 16:59:12 -0700473 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700474 protected void onResume() {
475 super.onResume();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700476 mStateSaved = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700477 if (mFirstLaunch) {
478 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700479 } else if (!phoneIsInUse() && mInCallDialpadUp) {
480 hideDialpadFragment(false, true);
481 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700482 } else if (mShowDialpadOnResume) {
483 showDialpadFragment(false);
484 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700485 }
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800486
487 // If there was a voice query result returned in the {@link #onActivityResult} callback, it
488 // will have been stashed in mVoiceSearchQuery since the search results fragment cannot be
489 // shown until onResume has completed. Active the search UI and set the search term now.
490 if (!TextUtils.isEmpty(mVoiceSearchQuery)) {
491 mActionBarController.onSearchBoxTapped();
492 mSearchView.setText(mVoiceSearchQuery);
493 mVoiceSearchQuery = null;
494 }
495
Yorke Lee98702de2013-08-06 12:03:32 -0700496 mFirstLaunch = false;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800497
498 if (mIsRestarting) {
499 // This is only called when the activity goes from resumed -> paused -> resumed, so it
500 // will not cause an extra view to be sent out on rotation
501 if (mIsDialpadShown) {
502 AnalyticsUtil.sendScreenView(mDialpadFragment, this);
503 }
504 mIsRestarting = false;
505 }
Yorke Lee53a22302014-04-29 18:13:46 -0700506 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700507 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700508 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700509 }
510
511 @Override
Yorke Lee7ee5c422014-11-04 10:29:32 -0800512 protected void onRestart() {
513 super.onRestart();
514 mIsRestarting = true;
515 }
516
517 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700518 protected void onPause() {
519 if (mClearSearchOnPause) {
520 hideDialpadAndSearchUi();
521 mClearSearchOnPause = false;
522 }
Yorke Lee19e68ca2014-10-28 11:51:40 -0700523 if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) {
524 commitDialpadFragmentHide();
525 }
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700526 super.onPause();
527 }
528
529 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700530 protected void onSaveInstanceState(Bundle outState) {
531 super.onSaveInstanceState(outState);
532 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700533 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
534 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700535 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700536 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700537 mActionBarController.saveInstanceState(outState);
Yorke Lee19e68ca2014-10-28 11:51:40 -0700538 mStateSaved = true;
Yorke Leeef2b7382013-08-09 17:39:25 -0700539 }
540
541 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700542 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700543 if (fragment instanceof DialpadFragment) {
544 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700545 if (!mShowDialpadOnResume) {
546 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
547 transaction.hide(mDialpadFragment);
548 transaction.commit();
549 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700550 } else if (fragment instanceof SmartDialSearchFragment) {
551 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700552 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700553 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700554 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700555 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700556 } else if (fragment instanceof ListsFragment) {
557 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700558 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700559 }
Yorke Leec3766332013-07-31 11:13:16 -0700560 }
561
Alon Albertb453e5b2013-09-10 15:54:23 -0700562 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700563 final Intent intent = new Intent(this, DialerSettingsActivity.class);
564 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700565 }
566
Chiao Cheng94b10b52012-08-17 16:59:12 -0700567 @Override
568 public void onClick(View view) {
569 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700570 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700571 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700572 mInCallDialpadUp = false;
573 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700574 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700575 break;
Yorke Leec3766332013-07-31 11:13:16 -0700576 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800577 try {
578 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
579 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
580 } catch (ActivityNotFoundException e) {
581 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
582 Toast.LENGTH_SHORT).show();
583 }
Yorke Leec3766332013-07-31 11:13:16 -0700584 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700585 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700586 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700587 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700588 default: {
589 Log.wtf(TAG, "Unexpected onClick event from " + view);
590 break;
591 }
592 }
593 }
594
Yorke Leec3766332013-07-31 11:13:16 -0700595 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700596 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700597 switch (item.getItemId()) {
598 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700599 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700600 break;
601 case R.id.menu_add_contact:
602 try {
603 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
604 } catch (ActivityNotFoundException e) {
605 Toast toast = Toast.makeText(this,
606 R.string.add_contact_not_available,
607 Toast.LENGTH_SHORT);
608 toast.show();
609 }
610 break;
611 case R.id.menu_import_export:
612 // We hard-code the "contactsAreAvailable" argument because doing it properly would
613 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
614 // now in Dialtacts for (potential) performance reasons. Compare with how it is
615 // done in {@link PeopleActivity}.
616 ImportExportDialogFragment.show(getFragmentManager(), true,
617 DialtactsActivity.class);
618 return true;
619 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700620 ClearFrequentsDialog.show(getFragmentManager());
621 return true;
622 case R.id.menu_call_settings:
623 handleMenuSettings();
624 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700625 }
626 return false;
627 }
628
629 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700630 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
631 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
632 if (resultCode == RESULT_OK) {
633 final ArrayList<String> matches = data.getStringArrayListExtra(
634 RecognizerIntent.EXTRA_RESULTS);
635 if (matches.size() > 0) {
636 final String match = matches.get(0);
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800637 mVoiceSearchQuery = match;
Yorke Leec3766332013-07-31 11:13:16 -0700638 } else {
639 Log.e(TAG, "Voice search - nothing heard");
640 }
641 } else {
642 Log.e(TAG, "Voice search failed");
643 }
644 }
645 super.onActivityResult(requestCode, resultCode, data);
646 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700647
Andrew Lee2a58ab82014-05-15 02:16:04 -0700648 /**
649 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
650 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
651 * @see #onDialpadShown
652 */
Yorke Leec3766332013-07-31 11:13:16 -0700653 private void showDialpadFragment(boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700654 if (mIsDialpadShown || mStateSaved) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700655 return;
656 }
657 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700658 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800659 mListsFragment.setUserVisibleHint(false);
Brian Attwellbeab3bb2014-10-27 12:24:49 -0700660 AnalyticsUtil.sendScreenView(mDialpadFragment);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700661
Chiao Cheng94b10b52012-08-17 16:59:12 -0700662 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700663 ft.show(mDialpadFragment);
664 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700665
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700666 if (animate) {
667 mFloatingActionButtonController.scaleOut();
668 } else {
669 mFloatingActionButtonController.setVisible(false);
670 }
Yorke Lee5253be02014-05-21 18:50:03 -0700671 mActionBarController.onDialpadUp();
672
Andrew Leeb1903842014-05-15 16:11:24 -0700673 if (!isInSearchUi()) {
674 enterSearchUi(true /* isSmartDial */, mSearchQuery);
675 }
Yorke Leec3766332013-07-31 11:13:16 -0700676 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700677
Andrew Lee2a58ab82014-05-15 02:16:04 -0700678 /**
679 * Callback from child DialpadFragment when the dialpad is shown.
680 */
681 public void onDialpadShown() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700682 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700683 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700684 } else {
685 mDialpadFragment.setYFraction(0);
686 }
687
Andrew Lee2a58ab82014-05-15 02:16:04 -0700688 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700689 }
690
691 /**
692 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
693 * a callback after the hide animation ends.
694 * @see #commitDialpadFragmentHide
695 */
Yorke Leeca195042013-09-25 16:29:38 -0700696 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700697 if (mDialpadFragment == null) {
698 return;
699 }
Yorke Leef6673d32013-08-23 15:34:17 -0700700 if (clearDialpad) {
701 mDialpadFragment.clearDialpad();
702 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700703 if (!mIsDialpadShown) {
704 return;
Yorke Leec3766332013-07-31 11:13:16 -0700705 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700706 mIsDialpadShown = false;
707 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800708 mListsFragment.setUserVisibleHint(true);
709 mListsFragment.sendScreenViewForCurrentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700710
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700711 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700712
713 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700714 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700715 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700716 } else {
717 commitDialpadFragmentHide();
718 }
719
Yorke Lee5253be02014-05-21 18:50:03 -0700720 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700721
Andrew Leed4cde832014-05-16 15:56:48 -0700722 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700723 if (TextUtils.isEmpty(mSearchQuery)) {
724 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700725 }
Andrew Leed4cde832014-05-16 15:56:48 -0700726 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700727 }
728
729 /**
730 * Finishes hiding the dialpad fragment after any animations are completed.
731 */
732 private void commitDialpadFragmentHide() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700733 if (!mStateSaved && !mDialpadFragment.isHidden()) {
734 final FragmentTransaction ft = getFragmentManager().beginTransaction();
735 ft.hide(mDialpadFragment);
736 ft.commit();
737 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700738 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700739 }
740
Andrew Lee2a58ab82014-05-15 02:16:04 -0700741 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700742 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700743 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700744 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700745 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700746 fragment = mRegularSearchFragment;
747 }
748 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700749 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700750 }
751 }
752
Yorke Lee5253be02014-05-21 18:50:03 -0700753 @Override
754 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700755 return mInDialpadSearch || mInRegularSearch;
756 }
757
Yorke Lee5253be02014-05-21 18:50:03 -0700758 @Override
759 public boolean hasSearchQuery() {
760 return !TextUtils.isEmpty(mSearchQuery);
761 }
762
763 @Override
764 public boolean shouldShowActionBar() {
765 return mListsFragment.shouldShowActionBar();
766 }
767
Yorke Leeb207f8a2013-08-29 18:51:06 -0700768 private void setNotInSearchUi() {
769 mInDialpadSearch = false;
770 mInRegularSearch = false;
771 }
772
Yorke Lee311969c2013-08-26 06:31:11 -0700773 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700774 if (mIsDialpadShown) {
775 hideDialpadFragment(false, true);
776 } else {
777 exitSearchUi();
778 }
Yorke Lee311969c2013-08-26 06:31:11 -0700779 }
780
Yorke Lee53a22302014-04-29 18:13:46 -0700781 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700782 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
783 if (canIntentBeHandled(voiceIntent)) {
784 mVoiceSearchButton.setVisibility(View.VISIBLE);
785 mVoiceSearchButton.setOnClickListener(this);
786 } else {
787 mVoiceSearchButton.setVisibility(View.GONE);
788 }
789 }
790
Andrew Leee74a10e2014-05-16 14:31:40 -0700791 private OptionsPopupMenu buildOptionsMenu(View invoker) {
792 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
793 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700794 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700795 popupMenu.setOnMenuItemClickListener(this);
796 return popupMenu;
797 }
798
Yorke Lee86e21f72014-04-02 16:49:38 -0700799 @Override
800 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700801 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700802 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700803 mPendingSearchViewQuery = null;
804 }
Yorke Leea524ae52014-08-05 18:01:05 -0700805 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700806 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700807 }
808
Chiao Cheng94b10b52012-08-17 16:59:12 -0700809 /**
810 * Returns true if the intent is due to hitting the green send key (hardware call button:
811 * KEYCODE_CALL) while in a call.
812 *
813 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700814 * @return true if the intent is due to hitting the green send key while in a call
815 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700816 private boolean isSendKeyWhileInCall(Intent intent) {
817 // If there is a call in progress and the user launched the dialer by hitting the call
818 // button, go straight to the in-call screen.
819 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700820
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700821 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700822 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700823 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700824 }
825
826 return false;
827 }
828
829 /**
830 * Sets the current tab based on the intent's request type
831 *
832 * @param intent Intent that contains information about which tab should be selected
833 */
Yorke Leec3766332013-07-31 11:13:16 -0700834 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700835 // 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 -0700836 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700837 finish();
838 return;
839 }
840
Yorke Lee669b6082013-09-17 15:43:38 -0700841 if (mDialpadFragment != null) {
842 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700843 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700844 mDialpadFragment.setStartedFromNewIntent(true);
845 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
846 mInCallDialpadUp = true;
847 }
848 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700849 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700850 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700851 }
852
853 @Override
854 public void onNewIntent(Intent newIntent) {
855 setIntent(newIntent);
Nancy Chen199b7f02014-11-05 15:03:00 -0800856 mStateSaved = false;
Yorke Leec3766332013-07-31 11:13:16 -0700857 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700858
Chiao Cheng94b10b52012-08-17 16:59:12 -0700859 invalidateOptionsMenu();
860 }
861
862 /** Returns true if the given intent contains a phone number to populate the dialer with */
863 private boolean isDialIntent(Intent intent) {
864 final String action = intent.getAction();
865 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
866 return true;
867 }
868 if (Intent.ACTION_VIEW.equals(action)) {
869 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700870 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700871 return true;
872 }
873 }
874 return false;
875 }
876
877 /**
878 * Returns an appropriate call origin for this Activity. May return null when no call origin
879 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
880 * for remembering the tab in which the user made a phone call, so the external app's DIAL
881 * request should not be counted.)
882 */
883 public String getCallOrigin() {
884 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
885 }
886
Chiao Cheng94b10b52012-08-17 16:59:12 -0700887 /**
Yorke Leec3766332013-07-31 11:13:16 -0700888 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700889 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700890 private void enterSearchUi(boolean smartDialSearch, String query) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700891 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700892 // Weird race condition where fragment is doing work after the activity is destroyed
893 // due to talkback being on (b/10209937). Just return since we can't do any
894 // constructive here.
895 return;
896 }
897
Yorke Leeef2b7382013-08-09 17:39:25 -0700898 if (DEBUG) {
899 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
900 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700901
Yorke Leec3766332013-07-31 11:13:16 -0700902 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700903 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700904 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700905 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700906 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700907 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700908
Yorke Leeb207f8a2013-08-29 18:51:06 -0700909 final String tag;
910 if (smartDialSearch) {
911 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
912 } else {
913 tag = TAG_REGULAR_SEARCH_FRAGMENT;
914 }
915 mInDialpadSearch = smartDialSearch;
916 mInRegularSearch = !smartDialSearch;
917
Andrew Lee752956e2014-05-15 11:43:38 -0700918 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700919 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700920 if (fragment == null) {
921 if (smartDialSearch) {
922 fragment = new SmartDialSearchFragment();
923 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700924 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700925 }
Andrew Leeb1903842014-05-15 16:11:24 -0700926 transaction.add(R.id.dialtacts_frame, fragment, tag);
927 } else {
928 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700929 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700930 // DialtactsActivity will provide the options menu
931 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700932 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700933 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700934 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700935
936 mListsFragment.getView().animate().alpha(0).withLayer();
Yorke Lee7ee5c422014-11-04 10:29:32 -0800937 mListsFragment.setUserVisibleHint(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700938 }
939
940 /**
Yorke Leec3766332013-07-31 11:13:16 -0700941 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700942 */
Yorke Leec3766332013-07-31 11:13:16 -0700943 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700944 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700945 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -0700946 return;
947 }
Andrew Leeb1903842014-05-15 16:11:24 -0700948
Andrew Leeb1903842014-05-15 16:11:24 -0700949 mSearchView.setText(null);
950 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700951 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700952
Andrew Leeb1903842014-05-15 16:11:24 -0700953 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700954 if (mSmartDialSearchFragment != null) {
955 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700956 }
Andrew Leeb1903842014-05-15 16:11:24 -0700957 if (mRegularSearchFragment != null) {
958 transaction.remove(mRegularSearchFragment);
959 }
960 transaction.commit();
961
962 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee7ee5c422014-11-04 10:29:32 -0800963 if (!mDialpadFragment.isVisible()) {
964 // If the dialpad fragment wasn't previously visible, then send a screen view because
965 // we are exiting regular search. Otherwise, the screen view will be sent by
966 // {@link #hideDialpadFragment}.
967 mListsFragment.sendScreenViewForCurrentPosition();
968 mListsFragment.setUserVisibleHint(true);
969 }
970
Yorke Lee5253be02014-05-21 18:50:03 -0700971 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700972 }
973
Chiao Cheng94b10b52012-08-17 16:59:12 -0700974 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700975 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700976 if (mStateSaved) {
977 return;
978 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700979 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700980 if (TextUtils.isEmpty(mSearchQuery) ||
981 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
982 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700983 exitSearchUi();
984 }
Yorke Leef6673d32013-08-23 15:34:17 -0700985 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700986 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700987 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -0700988 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700989 } else {
990 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700991 }
Yorke Leec3766332013-07-31 11:13:16 -0700992 }
993
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700994 /**
995 * @return True if the search UI was exited, false otherwise
996 */
997 private boolean maybeExitSearchUi() {
998 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
999 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001000 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001001 return true;
1002 }
1003 return false;
1004 }
1005
Yorke Leec3766332013-07-31 11:13:16 -07001006 @Override
1007 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -07001008 if (mSmartDialSearchFragment != null) {
1009 mSmartDialSearchFragment.setAddToContactNumber(query);
1010 }
Yorke Leec3766332013-07-31 11:13:16 -07001011 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
1012 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -07001013
1014 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001015 if (DEBUG) {
1016 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1017 }
1018 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1019 // This callback can happen if the dialpad fragment is recreated because of
1020 // activity destruction. In that case, don't update the search view because
1021 // that would bring the user back to the search fragment regardless of the
1022 // previous state of the application. Instead, just return here and let the
1023 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001024 if (!TextUtils.isEmpty(normalizedQuery)) {
1025 mPendingSearchViewQuery = normalizedQuery;
1026 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001027 return;
1028 }
Yorke Lee53a22302014-04-29 18:13:46 -07001029 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001030 }
1031 }
Yorke Leec3766332013-07-31 11:13:16 -07001032
1033 @Override
1034 public void onListFragmentScrollStateChange(int scrollState) {
1035 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001036 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -07001037 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001038 }
1039 }
1040
1041 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001042 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001043 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001044 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1045 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001046 }
1047
Yorke Leec3766332013-07-31 11:13:16 -07001048 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001049 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001050 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001051
Yorke Leee1424812013-09-04 18:24:48 -07001052 public static Intent getAddNumberToContactIntent(CharSequence text) {
1053 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1054 intent.putExtra(Intents.Insert.PHONE, text);
1055 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1056 return intent;
1057 }
1058
Yorke Leeda0f9042013-12-05 14:25:51 -08001059 private boolean canIntentBeHandled(Intent intent) {
1060 final PackageManager packageManager = getPackageManager();
1061 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1062 PackageManager.MATCH_DEFAULT_ONLY);
1063 return resolveInfo != null && resolveInfo.size() > 0;
1064 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001065
Yorke Lee6a1461a2014-04-21 16:27:14 -07001066 @Override
1067 public void showCallHistory() {
1068 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1069 // CONTENT_TYPE, so that we always open our call log from our dialer
1070 final Intent intent = new Intent(this, CallLogActivity.class);
1071 startActivity(intent);
1072 }
1073
Yorke Lee86e21f72014-04-02 16:49:38 -07001074 /**
1075 * Called when the user has long-pressed a contact tile to start a drag operation.
1076 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001077 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001078 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001079 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001080 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001081 }
Andrew Lee18963442014-06-06 17:20:13 -07001082 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001083 }
1084
1085 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001086 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1087 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001088
Yorke Lee86e21f72014-04-02 16:49:38 -07001089 /**
1090 * Called when the user has released a contact tile after long-pressing it.
1091 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001092 @Override
1093 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001094 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001095 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001096 }
Andrew Lee18963442014-06-06 17:20:13 -07001097 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001098 }
1099
1100 @Override
1101 public void onDroppedOnRemove() {}
1102
1103 /**
Yorke Leed999b712014-04-23 15:10:58 -07001104 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001105 * once it has been attached to the activity.
1106 */
1107 @Override
1108 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001109 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001110 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001111 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001112
1113 @Override
1114 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001115 // Specify call-origin so that users will see the previous tab instead of
1116 // CallLog screen (search UI will be automatically exited).
1117 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001118 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001119 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001120 }
1121
1122 @Override
1123 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001124 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1125 }
1126
1127 @Override
1128 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001129 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001130 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1131 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001132 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001133 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001134 }
1135
1136 @Override
1137 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001138 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001139 }
1140
1141 @Override
1142 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001143 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001144 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001145
Yorke Leecc4660d2014-04-24 11:22:57 -07001146 @Override
1147 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001148 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001149 // Only scroll the button when the first tab is selected. The button should scroll from
1150 // the middle to right position only on the transition from the first tab to the second
1151 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001152 // If the app is in RTL mode, we need to check against the second tab, rather than the
1153 // first. This is because if we are scrolling between the first and second tabs, the
1154 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1155 // reversal of the order of the tabs.
1156 final boolean isLayoutRtl = DialerUtils.isRtl();
1157 final boolean shouldScrollButton = position == (isLayoutRtl
1158 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1159 if (shouldScrollButton && !mIsLandscape) {
1160 mFloatingActionButtonController.onPageScrolled(
1161 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001162 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1163 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001164 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001165 }
1166
1167 @Override
1168 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001169 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001170 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001171 }
1172
1173 @Override
1174 public void onPageScrollStateChanged(int state) {
1175 }
1176
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001177 private TelephonyManager getTelephonyManager() {
1178 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1179 }
1180
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001181 private TelecomManager getTelecomManager() {
1182 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001183 }
1184
Yorke Lee5253be02014-05-21 18:50:03 -07001185 @Override
1186 public boolean isActionBarShowing() {
1187 return mActionBarController.isActionBarShowing();
1188 }
1189
Yorke Leec98a5bb2014-10-28 16:12:05 -07001190 @Override
1191 public ActionBarController getActionBarController() {
1192 return mActionBarController;
1193 }
1194
Andrew Lee9da8fb42014-06-03 14:03:09 -07001195 public boolean isDialpadShown() {
1196 return mIsDialpadShown;
1197 }
1198
Yorke Lee5253be02014-05-21 18:50:03 -07001199 @Override
1200 public int getActionBarHideOffset() {
1201 return getActionBar().getHideOffset();
1202 }
1203
1204 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001205 public void setActionBarHideOffset(int offset) {
1206 getActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001207 }
1208
1209 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001210 public int getActionBarHeight() {
1211 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001212 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001213
1214 /**
1215 * Updates controller based on currently known information.
1216 *
1217 * @param animate Whether or not to animate the transition.
1218 */
1219 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Lee405a6e62014-08-20 15:02:16 -07001220 int align = (!mIsLandscape && mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
1221 FloatingActionButtonController.ALIGN_MIDDLE :
1222 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001223 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001224 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001225}