blob: 9c8137e1ce1cd5dbef2c39b45789b0f998219e43 [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 */
Yorke Leef74011e2013-08-02 11:30:30 -0700143 private 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
Andrew Leee74a10e2014-05-16 14:31:40 -0700232 private class OptionsPopupMenu extends PopupMenu {
233 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700234 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700235 }
236
237 @Override
238 public void show() {
239 final Menu menu = getMenu();
240 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700241 clearFrequents.setVisible(mListsFragment != null &&
242 mListsFragment.getSpeedDialFragment() != null &&
243 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700244 super.show();
245 }
246 }
247
Chiao Cheng94b10b52012-08-17 16:59:12 -0700248 /**
Yorke Lee28266192014-05-01 10:05:52 -0700249 * Listener that listens to drag events and sends their x and y coordinates to a
250 * {@link DragDropController}.
251 */
252 private class LayoutOnDragListener implements OnDragListener {
253 @Override
254 public boolean onDrag(View v, DragEvent event) {
255 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700256 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700257 }
258 return true;
259 }
260 }
261
262 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700263 * Listener used to send search queries to the phone search fragment.
264 */
Yorke Lee53a22302014-04-29 18:13:46 -0700265 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700266 @Override
267 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
268 }
Yorke Leec3766332013-07-31 11:13:16 -0700269
Andrew Lee99a570c2014-05-15 14:18:50 -0700270 @Override
271 public void onTextChanged(CharSequence s, int start, int before, int count) {
272 final String newText = s.toString();
273 if (newText.equals(mSearchQuery)) {
274 // If the query hasn't changed (perhaps due to activity being destroyed
275 // and restored, or user launching the same DIAL intent twice), then there is
276 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700277 return;
278 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700279 if (DEBUG) {
280 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700281 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700282 }
Yorke Lee710709d2014-05-29 07:18:42 -0700283 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700284
Andrew Lee90374a72014-05-16 15:01:09 -0700285 // Show search fragment only when the query string is changed to non-empty text.
286 if (!TextUtils.isEmpty(newText)) {
287 // Call enterSearchUi only if we are switching search modes, or showing a search
288 // fragment for the first time.
289 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
290 (!mIsDialpadShown && mInRegularSearch);
291 if (!sameSearchMode) {
292 enterSearchUi(mIsDialpadShown, mSearchQuery);
293 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700294 }
295
Andrew Leea8515422014-06-13 16:53:54 -0700296 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700297 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700298 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700299 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700300 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700301 }
302
303 @Override
304 public void afterTextChanged(Editable s) {
305 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700306 };
307
Andrew Leeb1903842014-05-15 16:11:24 -0700308
309 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700310 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700311 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700312 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700313 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700314 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700315 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700316 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700317 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
318 }
Andrew Leeb1903842014-05-15 16:11:24 -0700319 }
320 };
321
322 /**
323 * If the search term is empty and the user closes the soft keyboard, close the search UI.
324 */
325 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
326 @Override
327 public boolean onKey(View v, int keyCode, KeyEvent event) {
328 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
329 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700330 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700331 }
332 return false;
333 }
334 };
335
Chiao Cheng94b10b52012-08-17 16:59:12 -0700336 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700337 public boolean dispatchTouchEvent(MotionEvent ev) {
338 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
339 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
340 }
341 return super.dispatchTouchEvent(ev);
342
343 }
344
345 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700346 protected void onCreate(Bundle savedInstanceState) {
347 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700348 mFirstLaunch = true;
349
Andrew Lee2423a2f2014-05-29 14:14:45 -0700350 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700351 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700352
Yorke Lee8898cd02013-08-08 10:24:27 -0700353 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800354 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700355
Yorke Lee53a22302014-04-29 18:13:46 -0700356 final ActionBar actionBar = getActionBar();
357 actionBar.setCustomView(R.layout.search_edittext);
358 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700359 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700360
Yorke Lee5253be02014-05-21 18:50:03 -0700361 mActionBarController = new ActionBarController(this,
362 (SearchEditTextLayout) actionBar.getCustomView());
363
Andrew Lee04675a52014-06-05 18:36:20 -0700364 SearchEditTextLayout searchEditTextLayout =
365 (SearchEditTextLayout) actionBar.getCustomView();
366 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
367
368 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700369 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700370 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
371 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
372 .setOnClickListener(mSearchViewOnClickListener);
373 searchEditTextLayout.findViewById(R.id.search_box_start_search)
374 .setOnClickListener(mSearchViewOnClickListener);
375 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700376 @Override
377 public void onBackButtonClicked() {
378 onBackPressed();
379 }
380 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700381
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700382 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700383 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700384
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700385 final View floatingActionButtonContainer = findViewById(
386 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700387 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
388 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700389 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700390 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700391
Andrew Lee04675a52014-06-05 18:36:20 -0700392 ImageButton optionsMenuButton =
393 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700394 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700395 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
396 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700397
Yorke Leeef2b7382013-08-09 17:39:25 -0700398 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
399 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700400 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800401 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700402 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800403 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
404 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700405 } else {
406 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700407 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
408 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700409 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700410 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700411 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700412 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700413
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700414 final boolean isLayoutRtl = DialerUtils.isRtl();
415 if (mIsLandscape) {
416 mSlideIn = AnimationUtils.loadAnimation(this,
417 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
418 mSlideOut = AnimationUtils.loadAnimation(this,
419 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
420 } else {
421 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
422 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
423 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700424
Yorke Lee2fec47b2014-08-05 18:16:27 -0700425 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
426 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
427
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700428 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700429
Yorke Leef614f6f2014-10-03 10:44:19 -0700430 mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
431 mParentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700432 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700433 new ViewTreeObserver.OnGlobalLayoutListener() {
434 @Override
435 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700436 final ViewTreeObserver observer =
437 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700438 if (!observer.isAlive()) {
439 return;
440 }
441 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700442 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700443 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700444 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700445 }
446 });
Andrew Lee0c667702014-05-12 14:31:45 -0700447
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700448 setupActivityOverlay();
449
Yorke Lee0baa98b2013-08-22 10:55:16 -0700450 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700451 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700452 }
453
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700454 private void setupActivityOverlay() {
455 final View activityOverlay = findViewById(R.id.activity_overlay);
456 activityOverlay.setOnTouchListener(new OnTouchListener() {
457 @Override
458 public boolean onTouch(View v, MotionEvent event) {
459 if (!mIsDialpadShown) {
460 maybeExitSearchUi();
461 }
462 return false;
463 }
464 });
465 }
466
Chiao Cheng94b10b52012-08-17 16:59:12 -0700467 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700468 protected void onResume() {
469 super.onResume();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700470 mStateSaved = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700471 if (mFirstLaunch) {
472 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700473 } else if (!phoneIsInUse() && mInCallDialpadUp) {
474 hideDialpadFragment(false, true);
475 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700476 } else if (mShowDialpadOnResume) {
477 showDialpadFragment(false);
478 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700479 }
480 mFirstLaunch = false;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800481
482 if (mIsRestarting) {
483 // This is only called when the activity goes from resumed -> paused -> resumed, so it
484 // will not cause an extra view to be sent out on rotation
485 if (mIsDialpadShown) {
486 AnalyticsUtil.sendScreenView(mDialpadFragment, this);
487 }
488 mIsRestarting = false;
489 }
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 Lee7ee5c422014-11-04 10:29:32 -0800496 protected void onRestart() {
497 super.onRestart();
498 mIsRestarting = true;
499 }
500
501 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700502 protected void onPause() {
503 if (mClearSearchOnPause) {
504 hideDialpadAndSearchUi();
505 mClearSearchOnPause = false;
506 }
Yorke Lee19e68ca2014-10-28 11:51:40 -0700507 if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) {
508 commitDialpadFragmentHide();
509 }
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700510 super.onPause();
511 }
512
513 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700514 protected void onSaveInstanceState(Bundle outState) {
515 super.onSaveInstanceState(outState);
516 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700517 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
518 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700519 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700520 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700521 mActionBarController.saveInstanceState(outState);
Yorke Lee19e68ca2014-10-28 11:51:40 -0700522 mStateSaved = true;
Yorke Leeef2b7382013-08-09 17:39:25 -0700523 }
524
525 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700526 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700527 if (fragment instanceof DialpadFragment) {
528 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700529 if (!mShowDialpadOnResume) {
530 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
531 transaction.hide(mDialpadFragment);
532 transaction.commit();
533 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700534 } else if (fragment instanceof SmartDialSearchFragment) {
535 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700536 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700537 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700538 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700539 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700540 } else if (fragment instanceof ListsFragment) {
541 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700542 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700543 }
Yorke Leec3766332013-07-31 11:13:16 -0700544 }
545
Alon Albertb453e5b2013-09-10 15:54:23 -0700546 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700547 final Intent intent = new Intent(this, DialerSettingsActivity.class);
548 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700549 }
550
Chiao Cheng94b10b52012-08-17 16:59:12 -0700551 @Override
552 public void onClick(View view) {
553 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700554 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700555 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700556 mInCallDialpadUp = false;
557 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700558 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700559 break;
Yorke Leec3766332013-07-31 11:13:16 -0700560 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800561 try {
562 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
563 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
564 } catch (ActivityNotFoundException e) {
565 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
566 Toast.LENGTH_SHORT).show();
567 }
Yorke Leec3766332013-07-31 11:13:16 -0700568 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700569 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700570 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700571 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700572 default: {
573 Log.wtf(TAG, "Unexpected onClick event from " + view);
574 break;
575 }
576 }
577 }
578
Yorke Leec3766332013-07-31 11:13:16 -0700579 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700580 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700581 switch (item.getItemId()) {
582 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700583 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700584 break;
585 case R.id.menu_add_contact:
586 try {
587 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
588 } catch (ActivityNotFoundException e) {
589 Toast toast = Toast.makeText(this,
590 R.string.add_contact_not_available,
591 Toast.LENGTH_SHORT);
592 toast.show();
593 }
594 break;
595 case R.id.menu_import_export:
596 // We hard-code the "contactsAreAvailable" argument because doing it properly would
597 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
598 // now in Dialtacts for (potential) performance reasons. Compare with how it is
599 // done in {@link PeopleActivity}.
600 ImportExportDialogFragment.show(getFragmentManager(), true,
601 DialtactsActivity.class);
602 return true;
603 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700604 ClearFrequentsDialog.show(getFragmentManager());
605 return true;
606 case R.id.menu_call_settings:
607 handleMenuSettings();
608 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700609 }
610 return false;
611 }
612
613 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700614 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
615 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
616 if (resultCode == RESULT_OK) {
617 final ArrayList<String> matches = data.getStringArrayListExtra(
618 RecognizerIntent.EXTRA_RESULTS);
619 if (matches.size() > 0) {
620 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700621 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700622 } else {
623 Log.e(TAG, "Voice search - nothing heard");
624 }
625 } else {
626 Log.e(TAG, "Voice search failed");
627 }
628 }
629 super.onActivityResult(requestCode, resultCode, data);
630 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700631
Andrew Lee2a58ab82014-05-15 02:16:04 -0700632 /**
633 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
634 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
635 * @see #onDialpadShown
636 */
Yorke Leec3766332013-07-31 11:13:16 -0700637 private void showDialpadFragment(boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700638 if (mIsDialpadShown || mStateSaved) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700639 return;
640 }
641 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700642 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800643 mListsFragment.setUserVisibleHint(false);
Brian Attwellbeab3bb2014-10-27 12:24:49 -0700644 AnalyticsUtil.sendScreenView(mDialpadFragment);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700645
Chiao Cheng94b10b52012-08-17 16:59:12 -0700646 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700647 ft.show(mDialpadFragment);
648 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700649
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700650 if (animate) {
651 mFloatingActionButtonController.scaleOut();
652 } else {
653 mFloatingActionButtonController.setVisible(false);
654 }
Yorke Lee5253be02014-05-21 18:50:03 -0700655 mActionBarController.onDialpadUp();
656
Andrew Leeb1903842014-05-15 16:11:24 -0700657 if (!isInSearchUi()) {
658 enterSearchUi(true /* isSmartDial */, mSearchQuery);
659 }
Yorke Leec3766332013-07-31 11:13:16 -0700660 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700661
Andrew Lee2a58ab82014-05-15 02:16:04 -0700662 /**
663 * Callback from child DialpadFragment when the dialpad is shown.
664 */
665 public void onDialpadShown() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700666 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700667 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700668 } else {
669 mDialpadFragment.setYFraction(0);
670 }
671
Andrew Lee2a58ab82014-05-15 02:16:04 -0700672 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700673 }
674
675 /**
676 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
677 * a callback after the hide animation ends.
678 * @see #commitDialpadFragmentHide
679 */
Yorke Leeca195042013-09-25 16:29:38 -0700680 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700681 if (mDialpadFragment == null) {
682 return;
683 }
Yorke Leef6673d32013-08-23 15:34:17 -0700684 if (clearDialpad) {
685 mDialpadFragment.clearDialpad();
686 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700687 if (!mIsDialpadShown) {
688 return;
Yorke Leec3766332013-07-31 11:13:16 -0700689 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700690 mIsDialpadShown = false;
691 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800692 mListsFragment.setUserVisibleHint(true);
693 mListsFragment.sendScreenViewForCurrentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700694
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700695 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700696
697 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700698 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700699 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700700 } else {
701 commitDialpadFragmentHide();
702 }
703
Yorke Lee5253be02014-05-21 18:50:03 -0700704 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700705
Andrew Leed4cde832014-05-16 15:56:48 -0700706 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700707 if (TextUtils.isEmpty(mSearchQuery)) {
708 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700709 }
Andrew Leed4cde832014-05-16 15:56:48 -0700710 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700711 }
712
713 /**
714 * Finishes hiding the dialpad fragment after any animations are completed.
715 */
716 private void commitDialpadFragmentHide() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700717 if (!mStateSaved && !mDialpadFragment.isHidden()) {
718 final FragmentTransaction ft = getFragmentManager().beginTransaction();
719 ft.hide(mDialpadFragment);
720 ft.commit();
721 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700722 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700723 }
724
Andrew Lee2a58ab82014-05-15 02:16:04 -0700725 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700726 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700727 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700728 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700729 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700730 fragment = mRegularSearchFragment;
731 }
732 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700733 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700734 }
735 }
736
Yorke Lee5253be02014-05-21 18:50:03 -0700737 @Override
738 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700739 return mInDialpadSearch || mInRegularSearch;
740 }
741
Yorke Lee5253be02014-05-21 18:50:03 -0700742 @Override
743 public boolean hasSearchQuery() {
744 return !TextUtils.isEmpty(mSearchQuery);
745 }
746
747 @Override
748 public boolean shouldShowActionBar() {
749 return mListsFragment.shouldShowActionBar();
750 }
751
Yorke Leeb207f8a2013-08-29 18:51:06 -0700752 private void setNotInSearchUi() {
753 mInDialpadSearch = false;
754 mInRegularSearch = false;
755 }
756
Yorke Lee311969c2013-08-26 06:31:11 -0700757 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700758 if (mIsDialpadShown) {
759 hideDialpadFragment(false, true);
760 } else {
761 exitSearchUi();
762 }
Yorke Lee311969c2013-08-26 06:31:11 -0700763 }
764
Yorke Lee53a22302014-04-29 18:13:46 -0700765 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700766 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
767 if (canIntentBeHandled(voiceIntent)) {
768 mVoiceSearchButton.setVisibility(View.VISIBLE);
769 mVoiceSearchButton.setOnClickListener(this);
770 } else {
771 mVoiceSearchButton.setVisibility(View.GONE);
772 }
773 }
774
Andrew Leee74a10e2014-05-16 14:31:40 -0700775 private OptionsPopupMenu buildOptionsMenu(View invoker) {
776 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
777 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700778 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700779 popupMenu.setOnMenuItemClickListener(this);
780 return popupMenu;
781 }
782
Yorke Lee86e21f72014-04-02 16:49:38 -0700783 @Override
784 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700785 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700786 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700787 mPendingSearchViewQuery = null;
788 }
Yorke Leea524ae52014-08-05 18:01:05 -0700789 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700790 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700791 }
792
Chiao Cheng94b10b52012-08-17 16:59:12 -0700793 /**
794 * Returns true if the intent is due to hitting the green send key (hardware call button:
795 * KEYCODE_CALL) while in a call.
796 *
797 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700798 * @return true if the intent is due to hitting the green send key while in a call
799 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700800 private boolean isSendKeyWhileInCall(Intent intent) {
801 // If there is a call in progress and the user launched the dialer by hitting the call
802 // button, go straight to the in-call screen.
803 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700804
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700805 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700806 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700807 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700808 }
809
810 return false;
811 }
812
813 /**
814 * Sets the current tab based on the intent's request type
815 *
816 * @param intent Intent that contains information about which tab should be selected
817 */
Yorke Leec3766332013-07-31 11:13:16 -0700818 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700819 // 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 -0700820 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700821 finish();
822 return;
823 }
824
Yorke Lee669b6082013-09-17 15:43:38 -0700825 if (mDialpadFragment != null) {
826 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700827 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700828 mDialpadFragment.setStartedFromNewIntent(true);
829 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
830 mInCallDialpadUp = true;
831 }
832 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700833 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700834 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700835 }
836
837 @Override
838 public void onNewIntent(Intent newIntent) {
839 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700840 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700841
Chiao Cheng94b10b52012-08-17 16:59:12 -0700842 invalidateOptionsMenu();
843 }
844
845 /** Returns true if the given intent contains a phone number to populate the dialer with */
846 private boolean isDialIntent(Intent intent) {
847 final String action = intent.getAction();
848 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
849 return true;
850 }
851 if (Intent.ACTION_VIEW.equals(action)) {
852 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700853 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700854 return true;
855 }
856 }
857 return false;
858 }
859
860 /**
861 * Returns an appropriate call origin for this Activity. May return null when no call origin
862 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
863 * for remembering the tab in which the user made a phone call, so the external app's DIAL
864 * request should not be counted.)
865 */
866 public String getCallOrigin() {
867 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
868 }
869
Chiao Cheng94b10b52012-08-17 16:59:12 -0700870 /**
Yorke Leec3766332013-07-31 11:13:16 -0700871 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700872 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700873 private void enterSearchUi(boolean smartDialSearch, String query) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700874 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700875 // Weird race condition where fragment is doing work after the activity is destroyed
876 // due to talkback being on (b/10209937). Just return since we can't do any
877 // constructive here.
878 return;
879 }
880
Yorke Leeef2b7382013-08-09 17:39:25 -0700881 if (DEBUG) {
882 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
883 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700884
Yorke Leec3766332013-07-31 11:13:16 -0700885 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700886 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700887 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700888 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700889 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700890 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700891
Yorke Leeb207f8a2013-08-29 18:51:06 -0700892 final String tag;
893 if (smartDialSearch) {
894 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
895 } else {
896 tag = TAG_REGULAR_SEARCH_FRAGMENT;
897 }
898 mInDialpadSearch = smartDialSearch;
899 mInRegularSearch = !smartDialSearch;
900
Andrew Lee752956e2014-05-15 11:43:38 -0700901 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700902 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700903 if (fragment == null) {
904 if (smartDialSearch) {
905 fragment = new SmartDialSearchFragment();
906 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700907 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700908 }
Andrew Leeb1903842014-05-15 16:11:24 -0700909 transaction.add(R.id.dialtacts_frame, fragment, tag);
910 } else {
911 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700912 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700913 // DialtactsActivity will provide the options menu
914 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700915 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700916 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700917 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700918
919 mListsFragment.getView().animate().alpha(0).withLayer();
Yorke Lee7ee5c422014-11-04 10:29:32 -0800920 mListsFragment.setUserVisibleHint(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700921 }
922
923 /**
Yorke Leec3766332013-07-31 11:13:16 -0700924 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700925 */
Yorke Leec3766332013-07-31 11:13:16 -0700926 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700927 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700928 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -0700929 return;
930 }
Andrew Leeb1903842014-05-15 16:11:24 -0700931
Andrew Leeb1903842014-05-15 16:11:24 -0700932 mSearchView.setText(null);
933 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700934 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700935
Andrew Leeb1903842014-05-15 16:11:24 -0700936 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700937 if (mSmartDialSearchFragment != null) {
938 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700939 }
Andrew Leeb1903842014-05-15 16:11:24 -0700940 if (mRegularSearchFragment != null) {
941 transaction.remove(mRegularSearchFragment);
942 }
943 transaction.commit();
944
945 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee7ee5c422014-11-04 10:29:32 -0800946 if (!mDialpadFragment.isVisible()) {
947 // If the dialpad fragment wasn't previously visible, then send a screen view because
948 // we are exiting regular search. Otherwise, the screen view will be sent by
949 // {@link #hideDialpadFragment}.
950 mListsFragment.sendScreenViewForCurrentPosition();
951 mListsFragment.setUserVisibleHint(true);
952 }
953
Yorke Lee5253be02014-05-21 18:50:03 -0700954 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700955 }
956
Chiao Cheng94b10b52012-08-17 16:59:12 -0700957 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700958 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700959 if (mStateSaved) {
960 return;
961 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700962 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700963 if (TextUtils.isEmpty(mSearchQuery) ||
964 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
965 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700966 exitSearchUi();
967 }
Yorke Leef6673d32013-08-23 15:34:17 -0700968 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700969 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700970 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -0700971 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700972 } else {
973 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700974 }
Yorke Leec3766332013-07-31 11:13:16 -0700975 }
976
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700977 /**
978 * @return True if the search UI was exited, false otherwise
979 */
980 private boolean maybeExitSearchUi() {
981 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
982 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -0700983 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700984 return true;
985 }
986 return false;
987 }
988
Yorke Leec3766332013-07-31 11:13:16 -0700989 @Override
990 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700991 if (mSmartDialSearchFragment != null) {
992 mSmartDialSearchFragment.setAddToContactNumber(query);
993 }
Yorke Leec3766332013-07-31 11:13:16 -0700994 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
995 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700996
997 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700998 if (DEBUG) {
999 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1000 }
1001 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1002 // This callback can happen if the dialpad fragment is recreated because of
1003 // activity destruction. In that case, don't update the search view because
1004 // that would bring the user back to the search fragment regardless of the
1005 // previous state of the application. Instead, just return here and let the
1006 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001007 if (!TextUtils.isEmpty(normalizedQuery)) {
1008 mPendingSearchViewQuery = normalizedQuery;
1009 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001010 return;
1011 }
Yorke Lee53a22302014-04-29 18:13:46 -07001012 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001013 }
1014 }
Yorke Leec3766332013-07-31 11:13:16 -07001015
1016 @Override
1017 public void onListFragmentScrollStateChange(int scrollState) {
1018 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001019 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -07001020 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001021 }
1022 }
1023
1024 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001025 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001026 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001027 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1028 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001029 }
1030
Yorke Leec3766332013-07-31 11:13:16 -07001031 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001032 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001033 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001034
Yorke Leee1424812013-09-04 18:24:48 -07001035 public static Intent getAddNumberToContactIntent(CharSequence text) {
1036 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1037 intent.putExtra(Intents.Insert.PHONE, text);
1038 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1039 return intent;
1040 }
1041
Yorke Leeda0f9042013-12-05 14:25:51 -08001042 private boolean canIntentBeHandled(Intent intent) {
1043 final PackageManager packageManager = getPackageManager();
1044 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1045 PackageManager.MATCH_DEFAULT_ONLY);
1046 return resolveInfo != null && resolveInfo.size() > 0;
1047 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001048
Yorke Lee6a1461a2014-04-21 16:27:14 -07001049 @Override
1050 public void showCallHistory() {
1051 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1052 // CONTENT_TYPE, so that we always open our call log from our dialer
1053 final Intent intent = new Intent(this, CallLogActivity.class);
1054 startActivity(intent);
1055 }
1056
Yorke Lee86e21f72014-04-02 16:49:38 -07001057 /**
1058 * Called when the user has long-pressed a contact tile to start a drag operation.
1059 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001060 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001061 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001062 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001063 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001064 }
Andrew Lee18963442014-06-06 17:20:13 -07001065 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001066 }
1067
1068 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001069 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1070 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001071
Yorke Lee86e21f72014-04-02 16:49:38 -07001072 /**
1073 * Called when the user has released a contact tile after long-pressing it.
1074 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001075 @Override
1076 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001077 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001078 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001079 }
Andrew Lee18963442014-06-06 17:20:13 -07001080 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001081 }
1082
1083 @Override
1084 public void onDroppedOnRemove() {}
1085
1086 /**
Yorke Leed999b712014-04-23 15:10:58 -07001087 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001088 * once it has been attached to the activity.
1089 */
1090 @Override
1091 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001092 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001093 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001094 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001095
1096 @Override
1097 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001098 // Specify call-origin so that users will see the previous tab instead of
1099 // CallLog screen (search UI will be automatically exited).
1100 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001101 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001102 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001103 }
1104
1105 @Override
1106 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001107 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1108 }
1109
1110 @Override
1111 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001112 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001113 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1114 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001115 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001116 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001117 }
1118
1119 @Override
1120 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001121 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001122 }
1123
1124 @Override
1125 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001126 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001127 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001128
Yorke Leecc4660d2014-04-24 11:22:57 -07001129 @Override
1130 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001131 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001132 // Only scroll the button when the first tab is selected. The button should scroll from
1133 // the middle to right position only on the transition from the first tab to the second
1134 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001135 // If the app is in RTL mode, we need to check against the second tab, rather than the
1136 // first. This is because if we are scrolling between the first and second tabs, the
1137 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1138 // reversal of the order of the tabs.
1139 final boolean isLayoutRtl = DialerUtils.isRtl();
1140 final boolean shouldScrollButton = position == (isLayoutRtl
1141 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1142 if (shouldScrollButton && !mIsLandscape) {
1143 mFloatingActionButtonController.onPageScrolled(
1144 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001145 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1146 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001147 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001148 }
1149
1150 @Override
1151 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001152 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001153 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001154 }
1155
1156 @Override
1157 public void onPageScrollStateChanged(int state) {
1158 }
1159
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001160 private TelephonyManager getTelephonyManager() {
1161 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1162 }
1163
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001164 private TelecomManager getTelecomManager() {
1165 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001166 }
1167
Yorke Lee5253be02014-05-21 18:50:03 -07001168 @Override
1169 public boolean isActionBarShowing() {
1170 return mActionBarController.isActionBarShowing();
1171 }
1172
Yorke Leec98a5bb2014-10-28 16:12:05 -07001173 @Override
1174 public ActionBarController getActionBarController() {
1175 return mActionBarController;
1176 }
1177
Andrew Lee9da8fb42014-06-03 14:03:09 -07001178 public boolean isDialpadShown() {
1179 return mIsDialpadShown;
1180 }
1181
Yorke Lee5253be02014-05-21 18:50:03 -07001182 @Override
1183 public int getActionBarHideOffset() {
1184 return getActionBar().getHideOffset();
1185 }
1186
1187 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001188 public void setActionBarHideOffset(int offset) {
1189 getActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001190 }
1191
1192 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001193 public int getActionBarHeight() {
1194 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001195 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001196
1197 /**
1198 * Updates controller based on currently known information.
1199 *
1200 * @param animate Whether or not to animate the transition.
1201 */
1202 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Lee405a6e62014-08-20 15:02:16 -07001203 int align = (!mIsLandscape && mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
1204 FloatingActionButtonController.ALIGN_MIDDLE :
1205 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001206 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001207 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001208}