blob: 12c52da9c0ff0b289974e1d09644912bb3b0d7c4 [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 Leecc4660d2014-04-24 11:22:57 -070019import android.animation.LayoutTransition;
Yorke Lee53a22302014-04-29 18:13:46 -070020import android.app.ActionBar;
Chiao Cheng94b10b52012-08-17 16:59:12 -070021import android.app.Activity;
22import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080024import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070025import android.content.Context;
26import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080027import android.content.pm.PackageManager;
28import android.content.pm.ResolveInfo;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070029import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070030import android.content.res.Resources;
Chiao Cheng94b10b52012-08-17 16:59:12 -070031import android.net.Uri;
32import android.os.Bundle;
Santos Cordond15629d2014-07-07 15:15:29 -070033import android.os.RemoteException;
Santos Cordond15629d2014-07-07 15:15:29 -070034import android.phone.PhoneManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070035import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070036import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070037import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070038import android.support.v4.view.ViewPager;
Yorke Lee6eec2282014-07-18 12:40:27 -070039import android.telecomm.TelecommManager;
Yorke Leec3766332013-07-31 11:13:16 -070040import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070041import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070043import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070044import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070045import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070046import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070047import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070049import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070050import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070051import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070052import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070053import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070054import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070055import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070056import android.view.animation.AnimationUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070057import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070058import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070059import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070060import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070061import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070062import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080063import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070064
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070065import com.android.contacts.common.CallUtil;
Yorke Leec3766332013-07-31 11:13:16 -070066import com.android.contacts.common.dialog.ClearFrequentsDialog;
67import com.android.contacts.common.interactions.ImportExportDialogFragment;
Nancy Chen0d3a7392014-08-12 14:44:53 -070068import com.android.contacts.common.interactions.TouchPointManager;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080069import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070070import com.android.contacts.common.widget.FloatingActionButtonController;
Sai Cheemalapati7fa029f2014-07-29 15:03:55 -070071import com.android.dialer.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070072import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070073import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070074import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070075import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070076import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070077import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080078import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070079import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080080import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070081import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070082import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070083import com.android.dialer.list.RegularSearchFragment;
84import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070085import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070086import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070087import com.android.dialer.settings.DialerSettingsActivity;
Yorke Lee7d20f822014-06-19 17:09:33 -070088import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070089import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070090import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070091import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070092import com.android.dialerbind.DatabaseHelperManager;
Nancy Chen0d3a7392014-08-12 14:44:53 -070093import com.android.incallui.CallCardFragment;
Yorke Lee2fec47b2014-08-05 18:16:27 -070094import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070095import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070096
Yorke Leec3766332013-07-31 11:13:16 -070097import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080098import java.util.List;
Yorke Lee69c247f2014-07-22 11:49:49 -070099import java.util.Locale;
Yorke Leec3766332013-07-31 11:13:16 -0700100
Chiao Cheng94b10b52012-08-17 16:59:12 -0700101/**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700102 * The dialer tab's title is 'phone', a more common name (see strings.xml).
103 */
Yorke Leec3766332013-07-31 11:13:16 -0700104public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Nancy Chen0d3a7392014-08-12 14:44:53 -0700105 View.OnTouchListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700106 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700107 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800108 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700109 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700110 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700111 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700112 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700113 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700114 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700115 ViewPager.OnPageChangeListener,
116 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700117 private static final String TAG = "DialtactsActivity";
118
Ihab Awad526c0b82014-02-27 12:55:36 -0800119 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700120
Yorke Leef74011e2013-08-02 11:30:30 -0700121 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
122
Chiao Cheng94b10b52012-08-17 16:59:12 -0700123 /** @see #getCallOrigin() */
124 private static final String CALL_ORIGIN_DIALTACTS =
125 "com.android.dialer.DialtactsActivity";
126
Yorke Leeb207f8a2013-08-29 18:51:06 -0700127 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
128 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700129 private static final String KEY_SEARCH_QUERY = "search_query";
130 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700131 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700132
Yorke Leec3766332013-07-31 11:13:16 -0700133 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
134 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
135 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
136 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700137
Chiao Cheng94b10b52012-08-17 16:59:12 -0700138 /**
139 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
140 */
141 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
142
Yorke Leec3766332013-07-31 11:13:16 -0700143 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700144
Yorke Lee28aab272014-06-11 10:24:19 -0700145 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700146
Yorke Leec3766332013-07-31 11:13:16 -0700147 /**
Yorke Leec3766332013-07-31 11:13:16 -0700148 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700149 */
Yorke Leef74011e2013-08-02 11:30:30 -0700150 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700151
152 /**
153 * Fragment for searching phone numbers using the alphanumeric keyboard.
154 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700155 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700156
157 /**
158 * Fragment for searching phone numbers using the dialpad.
159 */
160 private SmartDialSearchFragment mSmartDialSearchFragment;
161
Yorke Leee00c9fe2014-04-12 12:42:06 -0700162 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700163 * Animation that slides in.
164 */
165 private Animation mSlideIn;
166
167 /**
168 * Animation that slides out.
169 */
170 private Animation mSlideOut;
171
172 /**
173 * Listener for after slide out animation completes on dialer fragment.
174 */
175 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
176 @Override
177 public void onAnimationEnd(Animation animation) {
178 commitDialpadFragmentHide();
179 }
180 };
181
182 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700183 * Fragment containing the speed dial list, recents list, and all contacts list.
184 */
185 private ListsFragment mListsFragment;
186
Yorke Leeb207f8a2013-08-29 18:51:06 -0700187 private boolean mInDialpadSearch;
188 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700189 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700190 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700191 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700192
Yorke Leeef2b7382013-08-09 17:39:25 -0700193 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700194 * Whether or not the device is in landscape orientation.
195 */
196 private boolean mIsLandscape;
197
198 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700199 * The position of the currently selected tab in the attached {@link ListsFragment}.
200 */
201 private int mCurrentTabPosition = 0;
202
203 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700204 * True if the dialpad is only temporarily showing due to being in call
205 */
206 private boolean mInCallDialpadUp;
207
208 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700209 * True when this activity has been launched for the first time.
210 */
Yorke Lee98702de2013-08-06 12:03:32 -0700211 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700212
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700213 /**
214 * Search query to be applied to the SearchView in the ActionBar once
215 * onCreateOptionsMenu has been called.
216 */
217 private String mPendingSearchViewQuery;
218
Yorke Lee74edcdc2014-07-11 16:15:08 -0700219 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700220 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700221 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700222
Yorke Leeef2b7382013-08-09 17:39:25 -0700223 private String mSearchQuery;
224
Yorke Leefce269a2013-08-12 11:56:04 -0700225 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700226 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700227 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700228
229 private String mDescriptionDialButtonStr;
230 private String mActionMenuDialpadButtonStr;
231 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700232 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700233 /**
234 * Additional offset for FAB to be lowered when dialpad is open.
235 */
236 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700237
Andrew Lee2423a2f2014-05-29 14:14:45 -0700238 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700239
Andrew Leee74a10e2014-05-16 14:31:40 -0700240 private class OptionsPopupMenu extends PopupMenu {
241 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700242 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700243 }
244
245 @Override
246 public void show() {
247 final Menu menu = getMenu();
248 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700249 clearFrequents.setVisible(mListsFragment != null &&
250 mListsFragment.getSpeedDialFragment() != null &&
251 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700252 super.show();
253 }
254 }
255
Chiao Cheng94b10b52012-08-17 16:59:12 -0700256 /**
Yorke Lee28266192014-05-01 10:05:52 -0700257 * Listener that listens to drag events and sends their x and y coordinates to a
258 * {@link DragDropController}.
259 */
260 private class LayoutOnDragListener implements OnDragListener {
261 @Override
262 public boolean onDrag(View v, DragEvent event) {
263 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700264 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700265 }
266 return true;
267 }
268 }
269
270 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700271 * Listener used to send search queries to the phone search fragment.
272 */
Yorke Lee53a22302014-04-29 18:13:46 -0700273 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700274 @Override
275 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
276 }
Yorke Leec3766332013-07-31 11:13:16 -0700277
Andrew Lee99a570c2014-05-15 14:18:50 -0700278 @Override
279 public void onTextChanged(CharSequence s, int start, int before, int count) {
280 final String newText = s.toString();
281 if (newText.equals(mSearchQuery)) {
282 // If the query hasn't changed (perhaps due to activity being destroyed
283 // and restored, or user launching the same DIAL intent twice), then there is
284 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700285 return;
286 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700287 if (DEBUG) {
288 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700289 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700290 }
Yorke Lee710709d2014-05-29 07:18:42 -0700291 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700292
Andrew Lee90374a72014-05-16 15:01:09 -0700293 // Show search fragment only when the query string is changed to non-empty text.
294 if (!TextUtils.isEmpty(newText)) {
295 // Call enterSearchUi only if we are switching search modes, or showing a search
296 // fragment for the first time.
297 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
298 (!mIsDialpadShown && mInRegularSearch);
299 if (!sameSearchMode) {
300 enterSearchUi(mIsDialpadShown, mSearchQuery);
301 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700302 }
303
Andrew Leea8515422014-06-13 16:53:54 -0700304 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700305 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700306 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700307 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700308 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700309 }
310
311 @Override
312 public void afterTextChanged(Editable s) {
313 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700314 };
315
Andrew Leeb1903842014-05-15 16:11:24 -0700316
317 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700318 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700319 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700320 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700321 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700322 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700323 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700324 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700325 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
326 }
Andrew Leeb1903842014-05-15 16:11:24 -0700327 }
328 };
329
330 /**
331 * If the search term is empty and the user closes the soft keyboard, close the search UI.
332 */
333 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
334 @Override
335 public boolean onKey(View v, int keyCode, KeyEvent event) {
336 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
337 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700338 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700339 }
340 return false;
341 }
342 };
343
Chiao Cheng94b10b52012-08-17 16:59:12 -0700344 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700345 protected void onCreate(Bundle savedInstanceState) {
346 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700347 mFirstLaunch = true;
348
Andrew Lee2423a2f2014-05-29 14:14:45 -0700349 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700350 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700351 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
352 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700353
Yorke Lee8898cd02013-08-08 10:24:27 -0700354 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800355 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700356
Yorke Lee53a22302014-04-29 18:13:46 -0700357 final ActionBar actionBar = getActionBar();
358 actionBar.setCustomView(R.layout.search_edittext);
359 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700360 actionBar.setBackgroundDrawable(null);
Yorke Lee8fd67242014-08-05 18:43:45 -0700361 actionBar.setElevation(resources.getDimensionPixelSize(R.dimen.action_bar_elevation));
Yorke Lee53a22302014-04-29 18:13:46 -0700362
Yorke Lee5253be02014-05-21 18:50:03 -0700363 mActionBarController = new ActionBarController(this,
364 (SearchEditTextLayout) actionBar.getCustomView());
365
Andrew Lee04675a52014-06-05 18:36:20 -0700366 SearchEditTextLayout searchEditTextLayout =
367 (SearchEditTextLayout) actionBar.getCustomView();
368 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
369
370 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700371 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700372 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
373 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
374 .setOnClickListener(mSearchViewOnClickListener);
375 searchEditTextLayout.findViewById(R.id.search_box_start_search)
376 .setOnClickListener(mSearchViewOnClickListener);
377 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700378 @Override
379 public void onBackButtonClicked() {
380 onBackPressed();
381 }
382 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700383
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700384 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700385 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700386
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700387 final View floatingActionButtonContainer = findViewById(
388 R.id.floating_action_button_container);
389 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
390 int floatingActionButtonWidth = resources.getDimensionPixelSize(
391 R.dimen.floating_action_button_width);
392 mFloatingActionButton.setOnClickListener(this);
Nancy Chen0d3a7392014-08-12 14:44:53 -0700393 mFloatingActionButton.setOnTouchListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700394 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700395 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700396 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
397 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
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 Leeef2b7382013-08-09 17:39:25 -0700405 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
406 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700407 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800408 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700409 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800410 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
411 .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 Lee28aab272014-06-11 10:24:19 -0700437 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700438 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
439 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700440 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700441 new ViewTreeObserver.OnGlobalLayoutListener() {
442 @Override
443 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700444 final ViewTreeObserver observer = floatingActionButtonContainer
445 .getViewTreeObserver();
446 if (!observer.isAlive()) {
447 return;
448 }
449 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700450 int screenWidth = parentLayout.getWidth();
451 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700452 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700453 }
454 });
Andrew Lee0c667702014-05-12 14:31:45 -0700455
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700456 setupActivityOverlay();
457
Yorke Lee0baa98b2013-08-22 10:55:16 -0700458 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700459 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700460 }
461
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700462 private void setupActivityOverlay() {
463 final View activityOverlay = findViewById(R.id.activity_overlay);
464 activityOverlay.setOnTouchListener(new OnTouchListener() {
465 @Override
466 public boolean onTouch(View v, MotionEvent event) {
467 if (!mIsDialpadShown) {
468 maybeExitSearchUi();
469 }
Nancy Chen0d3a7392014-08-12 14:44:53 -0700470
471 recordTouchEvent(v, event);
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700472 return false;
473 }
474 });
475 }
476
Chiao Cheng94b10b52012-08-17 16:59:12 -0700477 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700478 protected void onResume() {
479 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700480 if (mFirstLaunch) {
481 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700482 } else if (!phoneIsInUse() && mInCallDialpadUp) {
483 hideDialpadFragment(false, true);
484 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700485 } else if (mShowDialpadOnResume) {
486 showDialpadFragment(false);
487 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700488 }
489 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700490 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700491 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700492 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700493 }
494
495 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700496 protected void onPause() {
497 if (mClearSearchOnPause) {
498 hideDialpadAndSearchUi();
499 mClearSearchOnPause = false;
500 }
501 super.onPause();
502 }
503
504 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700505 protected void onSaveInstanceState(Bundle outState) {
506 super.onSaveInstanceState(outState);
507 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700508 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
509 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700510 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700511 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700512 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700513 }
514
515 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700516 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700517 if (fragment instanceof DialpadFragment) {
518 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700519 if (!mShowDialpadOnResume) {
520 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
521 transaction.hide(mDialpadFragment);
522 transaction.commit();
523 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700524 } else if (fragment instanceof SmartDialSearchFragment) {
525 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700526 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700527 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700528 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700529 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700530 } else if (fragment instanceof ListsFragment) {
531 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700532 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700533 }
Yorke Leec3766332013-07-31 11:13:16 -0700534 }
535
Alon Albertb453e5b2013-09-10 15:54:23 -0700536 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700537 final Intent intent = new Intent(this, DialerSettingsActivity.class);
538 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700539 }
540
Chiao Cheng94b10b52012-08-17 16:59:12 -0700541 @Override
542 public void onClick(View view) {
543 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700544 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700545 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700546 mInCallDialpadUp = false;
547 showDialpadFragment(true);
548 } else {
549 // Dial button was pressed; tell the Dialpad fragment
550 mDialpadFragment.dialButtonPressed();
551 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700552 break;
Yorke Leec3766332013-07-31 11:13:16 -0700553 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800554 try {
555 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
556 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
557 } catch (ActivityNotFoundException e) {
558 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
559 Toast.LENGTH_SHORT).show();
560 }
Yorke Leec3766332013-07-31 11:13:16 -0700561 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700562 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700563 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700564 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700565 default: {
566 Log.wtf(TAG, "Unexpected onClick event from " + view);
567 break;
568 }
569 }
570 }
571
Yorke Leec3766332013-07-31 11:13:16 -0700572 @Override
Nancy Chen0d3a7392014-08-12 14:44:53 -0700573 public boolean onTouch(View view, MotionEvent event) {
574 recordTouchEvent(view, event);
575 return false;
576 }
577
578 private void recordTouchEvent(View view, MotionEvent event) {
579 if (event.getAction() == MotionEvent.ACTION_DOWN) {
580 TouchPointManager.getInstance().setPoint((int) event.getRawX(), (int) event.getRawY());
581 }
582 }
583
584 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700585 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700586 switch (item.getItemId()) {
587 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700588 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700589 break;
590 case R.id.menu_add_contact:
591 try {
592 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
593 } catch (ActivityNotFoundException e) {
594 Toast toast = Toast.makeText(this,
595 R.string.add_contact_not_available,
596 Toast.LENGTH_SHORT);
597 toast.show();
598 }
599 break;
600 case R.id.menu_import_export:
601 // We hard-code the "contactsAreAvailable" argument because doing it properly would
602 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
603 // now in Dialtacts for (potential) performance reasons. Compare with how it is
604 // done in {@link PeopleActivity}.
605 ImportExportDialogFragment.show(getFragmentManager(), true,
606 DialtactsActivity.class);
607 return true;
608 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700609 ClearFrequentsDialog.show(getFragmentManager());
610 return true;
611 case R.id.menu_call_settings:
612 handleMenuSettings();
613 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700614 }
615 return false;
616 }
617
618 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700619 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
620 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
621 if (resultCode == RESULT_OK) {
622 final ArrayList<String> matches = data.getStringArrayListExtra(
623 RecognizerIntent.EXTRA_RESULTS);
624 if (matches.size() > 0) {
625 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700626 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700627 } else {
628 Log.e(TAG, "Voice search - nothing heard");
629 }
630 } else {
631 Log.e(TAG, "Voice search failed");
632 }
633 }
634 super.onActivityResult(requestCode, resultCode, data);
635 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700636
Andrew Lee2a58ab82014-05-15 02:16:04 -0700637 /**
638 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
639 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
640 * @see #onDialpadShown
641 */
Yorke Leec3766332013-07-31 11:13:16 -0700642 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700643 if (mIsDialpadShown) {
644 return;
645 }
646 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700647 mDialpadFragment.setAnimate(animate);
Sai Cheemalapati2d7faf62014-08-04 11:48:50 -0700648 mDialpadFragment.sendScreenView();
Andrew Leecdfa6c62014-05-06 15:33:35 -0700649
Chiao Cheng94b10b52012-08-17 16:59:12 -0700650 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700651 ft.show(mDialpadFragment);
652 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700653
Yorke Lee5253be02014-05-21 18:50:03 -0700654 mActionBarController.onDialpadUp();
655
Andrew Leeb1903842014-05-15 16:11:24 -0700656 if (!isInSearchUi()) {
657 enterSearchUi(true /* isSmartDial */, mSearchQuery);
658 }
Yorke Leec3766332013-07-31 11:13:16 -0700659 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700660
Andrew Lee2a58ab82014-05-15 02:16:04 -0700661 /**
662 * Callback from child DialpadFragment when the dialpad is shown.
663 */
664 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700665 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
666 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
667 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700668 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700669 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700670 } else {
671 mDialpadFragment.setYFraction(0);
672 }
673
Andrew Lee2a58ab82014-05-15 02:16:04 -0700674 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700675 }
676
677 /**
678 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
679 * a callback after the hide animation ends.
680 * @see #commitDialpadFragmentHide
681 */
Yorke Leeca195042013-09-25 16:29:38 -0700682 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700683 if (mDialpadFragment == null) {
684 return;
685 }
Yorke Leef6673d32013-08-23 15:34:17 -0700686 if (clearDialpad) {
687 mDialpadFragment.clearDialpad();
688 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700689 if (!mIsDialpadShown) {
690 return;
Yorke Leec3766332013-07-31 11:13:16 -0700691 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700692 mIsDialpadShown = false;
693 mDialpadFragment.setAnimate(animate);
694
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700695 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700696 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
697 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
698
699 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700700 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700701 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700702 } else {
703 commitDialpadFragmentHide();
704 }
705
Yorke Lee5253be02014-05-21 18:50:03 -0700706 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700707
Andrew Leed4cde832014-05-16 15:56:48 -0700708 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700709 if (TextUtils.isEmpty(mSearchQuery)) {
710 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700711 }
Andrew Leed4cde832014-05-16 15:56:48 -0700712 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700713 }
714
715 /**
716 * Finishes hiding the dialpad fragment after any animations are completed.
717 */
718 private void commitDialpadFragmentHide() {
719 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700720 ft.hide(mDialpadFragment);
721 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700722 }
723
Andrew Lee2a58ab82014-05-15 02:16:04 -0700724 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700725 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700726 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700727 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700728 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700729 fragment = mRegularSearchFragment;
730 }
731 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700732 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700733 }
734 }
735
Yorke Lee5253be02014-05-21 18:50:03 -0700736 @Override
737 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700738 return mInDialpadSearch || mInRegularSearch;
739 }
740
Yorke Lee5253be02014-05-21 18:50:03 -0700741 @Override
742 public boolean hasSearchQuery() {
743 return !TextUtils.isEmpty(mSearchQuery);
744 }
745
746 @Override
747 public boolean shouldShowActionBar() {
748 return mListsFragment.shouldShowActionBar();
749 }
750
Yorke Leeb207f8a2013-08-29 18:51:06 -0700751 private void setNotInSearchUi() {
752 mInDialpadSearch = false;
753 mInRegularSearch = false;
754 }
755
Yorke Lee311969c2013-08-26 06:31:11 -0700756 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700757 if (mIsDialpadShown) {
758 hideDialpadFragment(false, true);
759 } else {
760 exitSearchUi();
761 }
Yorke Lee311969c2013-08-26 06:31:11 -0700762 }
763
Yorke Lee53a22302014-04-29 18:13:46 -0700764 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700765 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
766 if (canIntentBeHandled(voiceIntent)) {
767 mVoiceSearchButton.setVisibility(View.VISIBLE);
768 mVoiceSearchButton.setOnClickListener(this);
769 } else {
770 mVoiceSearchButton.setVisibility(View.GONE);
771 }
772 }
773
Andrew Leee74a10e2014-05-16 14:31:40 -0700774 private OptionsPopupMenu buildOptionsMenu(View invoker) {
775 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
776 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700777 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700778 popupMenu.setOnMenuItemClickListener(this);
779 return popupMenu;
780 }
781
Yorke Lee86e21f72014-04-02 16:49:38 -0700782 @Override
783 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700784 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700785 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700786 mPendingSearchViewQuery = null;
787 }
Yorke Leea524ae52014-08-05 18:01:05 -0700788 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700789 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700790 }
791
Chiao Cheng94b10b52012-08-17 16:59:12 -0700792 /**
793 * Returns true if the intent is due to hitting the green send key (hardware call button:
794 * KEYCODE_CALL) while in a call.
795 *
796 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700797 * @return true if the intent is due to hitting the green send key while in a call
798 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700799 private boolean isSendKeyWhileInCall(Intent intent) {
800 // If there is a call in progress and the user launched the dialer by hitting the call
801 // button, go straight to the in-call screen.
802 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700803
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700804 if (callKey) {
Santos Cordond15629d2014-07-07 15:15:29 -0700805 getPhoneManager().showCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700806 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700807 }
808
809 return false;
810 }
811
812 /**
813 * Sets the current tab based on the intent's request type
814 *
815 * @param intent Intent that contains information about which tab should be selected
816 */
Yorke Leec3766332013-07-31 11:13:16 -0700817 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700818 // 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 -0700819 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700820 finish();
821 return;
822 }
823
Yorke Lee669b6082013-09-17 15:43:38 -0700824 if (mDialpadFragment != null) {
825 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700826 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700827 mDialpadFragment.setStartedFromNewIntent(true);
828 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
829 mInCallDialpadUp = true;
830 }
831 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700832 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700833 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700834 }
835
836 @Override
837 public void onNewIntent(Intent newIntent) {
838 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700839 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700840
Chiao Cheng94b10b52012-08-17 16:59:12 -0700841 invalidateOptionsMenu();
842 }
843
844 /** Returns true if the given intent contains a phone number to populate the dialer with */
845 private boolean isDialIntent(Intent intent) {
846 final String action = intent.getAction();
847 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
848 return true;
849 }
850 if (Intent.ACTION_VIEW.equals(action)) {
851 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700852 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700853 return true;
854 }
855 }
856 return false;
857 }
858
859 /**
860 * Returns an appropriate call origin for this Activity. May return null when no call origin
861 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
862 * for remembering the tab in which the user made a phone call, so the external app's DIAL
863 * request should not be counted.)
864 */
865 public String getCallOrigin() {
866 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
867 }
868
Chiao Cheng94b10b52012-08-17 16:59:12 -0700869 /**
Yorke Leec3766332013-07-31 11:13:16 -0700870 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700871 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700872 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700873 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700874 // Weird race condition where fragment is doing work after the activity is destroyed
875 // due to talkback being on (b/10209937). Just return since we can't do any
876 // constructive here.
877 return;
878 }
879
Yorke Leeef2b7382013-08-09 17:39:25 -0700880 if (DEBUG) {
881 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
882 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700883
Yorke Leec3766332013-07-31 11:13:16 -0700884 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700885 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700886 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700887 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700888 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700889 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700890
Yorke Leeb207f8a2013-08-29 18:51:06 -0700891 final String tag;
892 if (smartDialSearch) {
893 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
894 } else {
895 tag = TAG_REGULAR_SEARCH_FRAGMENT;
896 }
897 mInDialpadSearch = smartDialSearch;
898 mInRegularSearch = !smartDialSearch;
899
Andrew Lee752956e2014-05-15 11:43:38 -0700900 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700901 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700902 if (fragment == null) {
903 if (smartDialSearch) {
904 fragment = new SmartDialSearchFragment();
905 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700906 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700907 }
Andrew Leeb1903842014-05-15 16:11:24 -0700908 transaction.add(R.id.dialtacts_frame, fragment, tag);
909 } else {
910 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700911 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700912 // DialtactsActivity will provide the options menu
913 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700914 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700915 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700916 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700917
918 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700919 }
920
921 /**
Yorke Leec3766332013-07-31 11:13:16 -0700922 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700923 */
Yorke Leec3766332013-07-31 11:13:16 -0700924 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700925 // See related bug in enterSearchUI();
926 if (getFragmentManager().isDestroyed()) {
927 return;
928 }
Andrew Leeb1903842014-05-15 16:11:24 -0700929
Andrew Leeb1903842014-05-15 16:11:24 -0700930 mSearchView.setText(null);
931 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700932 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700933
Andrew Leeb1903842014-05-15 16:11:24 -0700934 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700935 if (mSmartDialSearchFragment != null) {
936 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700937 }
Andrew Leeb1903842014-05-15 16:11:24 -0700938 if (mRegularSearchFragment != null) {
939 transaction.remove(mRegularSearchFragment);
940 }
941 transaction.commit();
942
943 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700944 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700945 }
946
947 /** Returns an Intent to launch Call Settings screen */
948 public static Intent getCallSettingsIntent() {
Yorke Lee6eec2282014-07-18 12:40:27 -0700949 final Intent intent = new Intent(TelecommManager.ACTION_SHOW_CALL_SETTINGS);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700950 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
951 return intent;
952 }
953
954 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700955 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700956 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700957 if (TextUtils.isEmpty(mSearchQuery) ||
958 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
959 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700960 exitSearchUi();
961 }
Yorke Leef6673d32013-08-23 15:34:17 -0700962 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700963 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700964 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700965 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700966 } else {
967 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700968 }
Yorke Leec3766332013-07-31 11:13:16 -0700969 }
970
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700971 /**
972 * @return True if the search UI was exited, false otherwise
973 */
974 private boolean maybeExitSearchUi() {
975 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
976 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700977 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700978 return true;
979 }
980 return false;
981 }
982
Yorke Leec3766332013-07-31 11:13:16 -0700983 @Override
984 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700985 if (mSmartDialSearchFragment != null) {
986 mSmartDialSearchFragment.setAddToContactNumber(query);
987 }
Yorke Leec3766332013-07-31 11:13:16 -0700988 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
989 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700990
991 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700992 if (DEBUG) {
993 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
994 }
995 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
996 // This callback can happen if the dialpad fragment is recreated because of
997 // activity destruction. In that case, don't update the search view because
998 // that would bring the user back to the search fragment regardless of the
999 // previous state of the application. Instead, just return here and let the
1000 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001001 if (!TextUtils.isEmpty(normalizedQuery)) {
1002 mPendingSearchViewQuery = normalizedQuery;
1003 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001004 return;
1005 }
Yorke Lee53a22302014-04-29 18:13:46 -07001006 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001007 }
1008 }
Yorke Leec3766332013-07-31 11:13:16 -07001009
1010 @Override
1011 public void onListFragmentScrollStateChange(int scrollState) {
1012 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001013 hideDialpadFragment(true, false);
Yorke Leef543baa2014-07-24 11:31:13 -07001014 DialerUtils.hideInputMethod(getCurrentFocus());
Yorke Leec3766332013-07-31 11:13:16 -07001015 }
1016 }
1017
1018 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001019 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001020 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001021 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1022 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001023 }
1024
Yorke Lee86e21f72014-04-02 16:49:38 -07001025 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001026 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001027 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001028 }
1029
1030 private boolean phoneIsInUse() {
Santos Cordond15629d2014-07-07 15:15:29 -07001031 return getPhoneManager().isInAPhoneCall();
Yorke Leec3766332013-07-31 11:13:16 -07001032 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001033
Yorke Leee1424812013-09-04 18:24:48 -07001034 public static Intent getAddNumberToContactIntent(CharSequence text) {
1035 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1036 intent.putExtra(Intents.Insert.PHONE, text);
1037 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1038 return intent;
1039 }
1040
Yorke Leeda0f9042013-12-05 14:25:51 -08001041 private boolean canIntentBeHandled(Intent intent) {
1042 final PackageManager packageManager = getPackageManager();
1043 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1044 PackageManager.MATCH_DEFAULT_ONLY);
1045 return resolveInfo != null && resolveInfo.size() > 0;
1046 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001047
Yorke Lee6a1461a2014-04-21 16:27:14 -07001048 @Override
1049 public void showCallHistory() {
1050 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1051 // CONTENT_TYPE, so that we always open our call log from our dialer
1052 final Intent intent = new Intent(this, CallLogActivity.class);
1053 startActivity(intent);
1054 }
1055
Yorke Lee86e21f72014-04-02 16:49:38 -07001056 /**
1057 * Called when the user has long-pressed a contact tile to start a drag operation.
1058 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001059 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001060 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001061 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001062 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001063 }
Andrew Lee18963442014-06-06 17:20:13 -07001064 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001065 }
1066
1067 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001068 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1069 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001070
Yorke Lee86e21f72014-04-02 16:49:38 -07001071 /**
1072 * Called when the user has released a contact tile after long-pressing it.
1073 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001074 @Override
1075 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001076 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001077 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001078 }
Andrew Lee18963442014-06-06 17:20:13 -07001079 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001080 }
1081
1082 @Override
1083 public void onDroppedOnRemove() {}
1084
1085 /**
Yorke Leed999b712014-04-23 15:10:58 -07001086 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001087 * once it has been attached to the activity.
1088 */
1089 @Override
1090 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001091 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001092 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001093 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001094
1095 @Override
1096 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001097 // Specify call-origin so that users will see the previous tab instead of
1098 // CallLog screen (search UI will be automatically exited).
1099 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001100 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001101 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001102 }
1103
1104 @Override
1105 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001106 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1107 }
1108
1109 @Override
1110 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001111 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001112 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1113 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001114 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001115 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001116 }
1117
1118 @Override
1119 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001120 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001121 }
1122
1123 @Override
1124 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001125 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001126 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001127
Yorke Leecc4660d2014-04-24 11:22:57 -07001128 @Override
1129 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001130 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001131 // Only scroll the button when the first tab is selected. The button should scroll from
1132 // the middle to right position only on the transition from the first tab to the second
1133 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001134 // If the app is in RTL mode, we need to check against the second tab, rather than the
1135 // first. This is because if we are scrolling between the first and second tabs, the
1136 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1137 // reversal of the order of the tabs.
1138 final boolean isLayoutRtl = DialerUtils.isRtl();
1139 final boolean shouldScrollButton = position == (isLayoutRtl
1140 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1141 if (shouldScrollButton && !mIsLandscape) {
1142 mFloatingActionButtonController.onPageScrolled(
1143 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001144 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1145 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001146 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001147 }
1148
1149 @Override
1150 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001151 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001152 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001153 }
1154
1155 @Override
1156 public void onPageScrollStateChanged(int state) {
1157 }
1158
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001159 private TelephonyManager getTelephonyManager() {
1160 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1161 }
1162
Santos Cordond15629d2014-07-07 15:15:29 -07001163 private PhoneManager getPhoneManager() {
1164 return (PhoneManager) getSystemService(Context.PHONE_SERVICE);
1165 }
1166
Yorke Lee5253be02014-05-21 18:50:03 -07001167 @Override
1168 public boolean isActionBarShowing() {
1169 return mActionBarController.isActionBarShowing();
1170 }
1171
Andrew Lee9da8fb42014-06-03 14:03:09 -07001172 public boolean isDialpadShown() {
1173 return mIsDialpadShown;
1174 }
1175
Yorke Lee5253be02014-05-21 18:50:03 -07001176 @Override
1177 public int getActionBarHideOffset() {
1178 return getActionBar().getHideOffset();
1179 }
1180
1181 @Override
1182 public int getActionBarHeight() {
1183 return mActionBarHeight;
1184 }
1185
1186 @Override
1187 public void setActionBarHideOffset(int hideOffset) {
Yorke Leea524ae52014-08-05 18:01:05 -07001188 mActionBarController.setHideOffset(hideOffset);
Yorke Lee5253be02014-05-21 18:50:03 -07001189 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001190
1191 /**
1192 * Updates controller based on currently known information.
1193 *
1194 * @param animate Whether or not to animate the transition.
1195 */
1196 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1197 int align;
1198 if (mIsDialpadShown) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001199 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_END
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001200 : FloatingActionButtonController.ALIGN_MIDDLE;
1201 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001202 if (!mIsLandscape) {
1203 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1204 ? FloatingActionButtonController.ALIGN_MIDDLE
Yorke Lee69c247f2014-07-22 11:49:49 -07001205 : FloatingActionButtonController.ALIGN_END;
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001206 } else {
Yorke Lee69c247f2014-07-22 11:49:49 -07001207 align = FloatingActionButtonController.ALIGN_END;
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001208 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001209 }
1210 mFloatingActionButtonController.align(align,
1211 0 /* offsetX */,
1212 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1213 animate);
1214 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001215}