blob: 241080fa555966030277b19ec4e1e1598f5805ef [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 Leeb207f8a2013-08-29 18:51:06 -0700185 private boolean mInDialpadSearch;
186 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700187 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700188 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700189 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700190
Yorke Leeef2b7382013-08-09 17:39:25 -0700191 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700192 * Whether or not the device is in landscape orientation.
193 */
194 private boolean mIsLandscape;
195
196 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700197 * The position of the currently selected tab in the attached {@link ListsFragment}.
198 */
199 private int mCurrentTabPosition = 0;
200
201 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700202 * True if the dialpad is only temporarily showing due to being in call
203 */
204 private boolean mInCallDialpadUp;
205
206 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700207 * True when this activity has been launched for the first time.
208 */
Yorke Lee98702de2013-08-06 12:03:32 -0700209 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700210
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700211 /**
212 * Search query to be applied to the SearchView in the ActionBar once
213 * onCreateOptionsMenu has been called.
214 */
215 private String mPendingSearchViewQuery;
216
Yorke Lee74edcdc2014-07-11 16:15:08 -0700217 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700218 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700219 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700220
Yorke Leeef2b7382013-08-09 17:39:25 -0700221 private String mSearchQuery;
222
Yorke Leefce269a2013-08-12 11:56:04 -0700223 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700224 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700225 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700226
Sai Cheemalapati41460652014-06-02 21:05:39 -0700227 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700228
Andrew Lee2423a2f2014-05-29 14:14:45 -0700229 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700230
Andrew Leee74a10e2014-05-16 14:31:40 -0700231 private class OptionsPopupMenu extends PopupMenu {
232 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700233 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700234 }
235
236 @Override
237 public void show() {
238 final Menu menu = getMenu();
239 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700240 clearFrequents.setVisible(mListsFragment != null &&
241 mListsFragment.getSpeedDialFragment() != null &&
242 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700243 super.show();
244 }
245 }
246
Chiao Cheng94b10b52012-08-17 16:59:12 -0700247 /**
Yorke Lee28266192014-05-01 10:05:52 -0700248 * Listener that listens to drag events and sends their x and y coordinates to a
249 * {@link DragDropController}.
250 */
251 private class LayoutOnDragListener implements OnDragListener {
252 @Override
253 public boolean onDrag(View v, DragEvent event) {
254 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700255 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700256 }
257 return true;
258 }
259 }
260
261 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700262 * Listener used to send search queries to the phone search fragment.
263 */
Yorke Lee53a22302014-04-29 18:13:46 -0700264 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700265 @Override
266 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
267 }
Yorke Leec3766332013-07-31 11:13:16 -0700268
Andrew Lee99a570c2014-05-15 14:18:50 -0700269 @Override
270 public void onTextChanged(CharSequence s, int start, int before, int count) {
271 final String newText = s.toString();
272 if (newText.equals(mSearchQuery)) {
273 // If the query hasn't changed (perhaps due to activity being destroyed
274 // and restored, or user launching the same DIAL intent twice), then there is
275 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700276 return;
277 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700278 if (DEBUG) {
279 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700280 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700281 }
Yorke Lee710709d2014-05-29 07:18:42 -0700282 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700283
Andrew Lee90374a72014-05-16 15:01:09 -0700284 // Show search fragment only when the query string is changed to non-empty text.
285 if (!TextUtils.isEmpty(newText)) {
286 // Call enterSearchUi only if we are switching search modes, or showing a search
287 // fragment for the first time.
288 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
289 (!mIsDialpadShown && mInRegularSearch);
290 if (!sameSearchMode) {
291 enterSearchUi(mIsDialpadShown, mSearchQuery);
292 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700293 }
294
Andrew Leea8515422014-06-13 16:53:54 -0700295 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700296 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700297 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700298 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700299 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700300 }
301
302 @Override
303 public void afterTextChanged(Editable s) {
304 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700305 };
306
Andrew Leeb1903842014-05-15 16:11:24 -0700307
308 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700309 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700310 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700311 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700312 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700313 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700314 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700315 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700316 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
317 }
Andrew Leeb1903842014-05-15 16:11:24 -0700318 }
319 };
320
321 /**
322 * If the search term is empty and the user closes the soft keyboard, close the search UI.
323 */
324 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
325 @Override
326 public boolean onKey(View v, int keyCode, KeyEvent event) {
327 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
328 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700329 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700330 }
331 return false;
332 }
333 };
334
Chiao Cheng94b10b52012-08-17 16:59:12 -0700335 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700336 public boolean dispatchTouchEvent(MotionEvent ev) {
337 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
338 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
339 }
340 return super.dispatchTouchEvent(ev);
341
342 }
343
344 @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);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700351
Yorke Lee8898cd02013-08-08 10:24:27 -0700352 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800353 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700354
Yorke Lee53a22302014-04-29 18:13:46 -0700355 final ActionBar actionBar = getActionBar();
356 actionBar.setCustomView(R.layout.search_edittext);
357 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700358 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700359
Yorke Lee5253be02014-05-21 18:50:03 -0700360 mActionBarController = new ActionBarController(this,
361 (SearchEditTextLayout) actionBar.getCustomView());
362
Andrew Lee04675a52014-06-05 18:36:20 -0700363 SearchEditTextLayout searchEditTextLayout =
364 (SearchEditTextLayout) actionBar.getCustomView();
365 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
366
367 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700368 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700369 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
370 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
371 .setOnClickListener(mSearchViewOnClickListener);
372 searchEditTextLayout.findViewById(R.id.search_box_start_search)
373 .setOnClickListener(mSearchViewOnClickListener);
374 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700375 @Override
376 public void onBackButtonClicked() {
377 onBackPressed();
378 }
379 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700380
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700381 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700382 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700383
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700384 final View floatingActionButtonContainer = findViewById(
385 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700386 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
387 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700388 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700389 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700390
Andrew Lee04675a52014-06-05 18:36:20 -0700391 ImageButton optionsMenuButton =
392 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700393 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700394 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
395 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700396
Yorke Leeef2b7382013-08-09 17:39:25 -0700397 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
398 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700399 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800400 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700401 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800402 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
403 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700404 } else {
405 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700406 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
407 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700408 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700409 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700410 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700411 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700412
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700413 final boolean isLayoutRtl = DialerUtils.isRtl();
414 if (mIsLandscape) {
415 mSlideIn = AnimationUtils.loadAnimation(this,
416 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
417 mSlideOut = AnimationUtils.loadAnimation(this,
418 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
419 } else {
420 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
421 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
422 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700423
Yorke Lee2fec47b2014-08-05 18:16:27 -0700424 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
425 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
426
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700427 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700428
Yorke Leef614f6f2014-10-03 10:44:19 -0700429 mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
430 mParentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700431 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700432 new ViewTreeObserver.OnGlobalLayoutListener() {
433 @Override
434 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700435 final ViewTreeObserver observer =
436 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700437 if (!observer.isAlive()) {
438 return;
439 }
440 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700441 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700442 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700443 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700444 }
445 });
Andrew Lee0c667702014-05-12 14:31:45 -0700446
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700447 setupActivityOverlay();
448
Yorke Lee0baa98b2013-08-22 10:55:16 -0700449 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700450 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700451 }
452
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700453 private void setupActivityOverlay() {
454 final View activityOverlay = findViewById(R.id.activity_overlay);
455 activityOverlay.setOnTouchListener(new OnTouchListener() {
456 @Override
457 public boolean onTouch(View v, MotionEvent event) {
458 if (!mIsDialpadShown) {
459 maybeExitSearchUi();
460 }
461 return false;
462 }
463 });
464 }
465
Chiao Cheng94b10b52012-08-17 16:59:12 -0700466 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700467 protected void onResume() {
468 super.onResume();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700469 mStateSaved = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700470 if (mFirstLaunch) {
471 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700472 } else if (!phoneIsInUse() && mInCallDialpadUp) {
473 hideDialpadFragment(false, true);
474 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700475 } else if (mShowDialpadOnResume) {
476 showDialpadFragment(false);
477 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700478 }
479 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700480 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700481 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700482 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700483 }
484
485 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700486 protected void onPause() {
487 if (mClearSearchOnPause) {
488 hideDialpadAndSearchUi();
489 mClearSearchOnPause = false;
490 }
Yorke Lee19e68ca2014-10-28 11:51:40 -0700491 if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) {
492 commitDialpadFragmentHide();
493 }
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700494 super.onPause();
495 }
496
497 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700498 protected void onSaveInstanceState(Bundle outState) {
499 super.onSaveInstanceState(outState);
500 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700501 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
502 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700503 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700504 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700505 mActionBarController.saveInstanceState(outState);
Yorke Lee19e68ca2014-10-28 11:51:40 -0700506 mStateSaved = true;
Yorke Leeef2b7382013-08-09 17:39:25 -0700507 }
508
509 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700510 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700511 if (fragment instanceof DialpadFragment) {
512 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700513 if (!mShowDialpadOnResume) {
514 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
515 transaction.hide(mDialpadFragment);
516 transaction.commit();
517 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700518 } else if (fragment instanceof SmartDialSearchFragment) {
519 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700520 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700521 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700522 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700523 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700524 } else if (fragment instanceof ListsFragment) {
525 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700526 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700527 }
Yorke Leec3766332013-07-31 11:13:16 -0700528 }
529
Alon Albertb453e5b2013-09-10 15:54:23 -0700530 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700531 final Intent intent = new Intent(this, DialerSettingsActivity.class);
532 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700533 }
534
Chiao Cheng94b10b52012-08-17 16:59:12 -0700535 @Override
536 public void onClick(View view) {
537 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700538 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700539 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700540 mInCallDialpadUp = false;
541 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700542 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700543 break;
Yorke Leec3766332013-07-31 11:13:16 -0700544 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800545 try {
546 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
547 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
548 } catch (ActivityNotFoundException e) {
549 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
550 Toast.LENGTH_SHORT).show();
551 }
Yorke Leec3766332013-07-31 11:13:16 -0700552 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700553 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700554 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700555 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700556 default: {
557 Log.wtf(TAG, "Unexpected onClick event from " + view);
558 break;
559 }
560 }
561 }
562
Yorke Leec3766332013-07-31 11:13:16 -0700563 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700564 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700565 switch (item.getItemId()) {
566 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700567 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700568 break;
569 case R.id.menu_add_contact:
570 try {
571 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
572 } catch (ActivityNotFoundException e) {
573 Toast toast = Toast.makeText(this,
574 R.string.add_contact_not_available,
575 Toast.LENGTH_SHORT);
576 toast.show();
577 }
578 break;
579 case R.id.menu_import_export:
580 // We hard-code the "contactsAreAvailable" argument because doing it properly would
581 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
582 // now in Dialtacts for (potential) performance reasons. Compare with how it is
583 // done in {@link PeopleActivity}.
584 ImportExportDialogFragment.show(getFragmentManager(), true,
585 DialtactsActivity.class);
586 return true;
587 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700588 ClearFrequentsDialog.show(getFragmentManager());
589 return true;
590 case R.id.menu_call_settings:
591 handleMenuSettings();
592 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700593 }
594 return false;
595 }
596
597 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700598 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
599 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
600 if (resultCode == RESULT_OK) {
601 final ArrayList<String> matches = data.getStringArrayListExtra(
602 RecognizerIntent.EXTRA_RESULTS);
603 if (matches.size() > 0) {
604 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700605 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700606 } else {
607 Log.e(TAG, "Voice search - nothing heard");
608 }
609 } else {
610 Log.e(TAG, "Voice search failed");
611 }
612 }
613 super.onActivityResult(requestCode, resultCode, data);
614 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700615
Andrew Lee2a58ab82014-05-15 02:16:04 -0700616 /**
617 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
618 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
619 * @see #onDialpadShown
620 */
Yorke Leec3766332013-07-31 11:13:16 -0700621 private void showDialpadFragment(boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700622 if (mIsDialpadShown || mStateSaved) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700623 return;
624 }
625 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700626 mDialpadFragment.setAnimate(animate);
Brian Attwellbeab3bb2014-10-27 12:24:49 -0700627 AnalyticsUtil.sendScreenView(mDialpadFragment);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700628
Chiao Cheng94b10b52012-08-17 16:59:12 -0700629 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700630 ft.show(mDialpadFragment);
631 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700632
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700633 if (animate) {
634 mFloatingActionButtonController.scaleOut();
635 } else {
636 mFloatingActionButtonController.setVisible(false);
637 }
Yorke Lee5253be02014-05-21 18:50:03 -0700638 mActionBarController.onDialpadUp();
639
Andrew Leeb1903842014-05-15 16:11:24 -0700640 if (!isInSearchUi()) {
641 enterSearchUi(true /* isSmartDial */, mSearchQuery);
642 }
Yorke Leec3766332013-07-31 11:13:16 -0700643 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700644
Andrew Lee2a58ab82014-05-15 02:16:04 -0700645 /**
646 * Callback from child DialpadFragment when the dialpad is shown.
647 */
648 public void onDialpadShown() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700649 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700650 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700651 } else {
652 mDialpadFragment.setYFraction(0);
653 }
654
Andrew Lee2a58ab82014-05-15 02:16:04 -0700655 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700656 }
657
658 /**
659 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
660 * a callback after the hide animation ends.
661 * @see #commitDialpadFragmentHide
662 */
Yorke Leeca195042013-09-25 16:29:38 -0700663 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700664 if (mDialpadFragment == null) {
665 return;
666 }
Yorke Leef6673d32013-08-23 15:34:17 -0700667 if (clearDialpad) {
668 mDialpadFragment.clearDialpad();
669 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700670 if (!mIsDialpadShown) {
671 return;
Yorke Leec3766332013-07-31 11:13:16 -0700672 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700673 mIsDialpadShown = false;
674 mDialpadFragment.setAnimate(animate);
675
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700676 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700677
678 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700679 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700680 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700681 } else {
682 commitDialpadFragmentHide();
683 }
684
Yorke Lee5253be02014-05-21 18:50:03 -0700685 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700686
Andrew Leed4cde832014-05-16 15:56:48 -0700687 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700688 if (TextUtils.isEmpty(mSearchQuery)) {
689 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700690 }
Andrew Leed4cde832014-05-16 15:56:48 -0700691 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700692 }
693
694 /**
695 * Finishes hiding the dialpad fragment after any animations are completed.
696 */
697 private void commitDialpadFragmentHide() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700698 if (!mStateSaved && !mDialpadFragment.isHidden()) {
699 final FragmentTransaction ft = getFragmentManager().beginTransaction();
700 ft.hide(mDialpadFragment);
701 ft.commit();
702 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700703 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700704 }
705
Andrew Lee2a58ab82014-05-15 02:16:04 -0700706 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700707 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700708 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700709 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700710 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700711 fragment = mRegularSearchFragment;
712 }
713 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700714 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700715 }
716 }
717
Yorke Lee5253be02014-05-21 18:50:03 -0700718 @Override
719 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700720 return mInDialpadSearch || mInRegularSearch;
721 }
722
Yorke Lee5253be02014-05-21 18:50:03 -0700723 @Override
724 public boolean hasSearchQuery() {
725 return !TextUtils.isEmpty(mSearchQuery);
726 }
727
728 @Override
729 public boolean shouldShowActionBar() {
730 return mListsFragment.shouldShowActionBar();
731 }
732
Yorke Leeb207f8a2013-08-29 18:51:06 -0700733 private void setNotInSearchUi() {
734 mInDialpadSearch = false;
735 mInRegularSearch = false;
736 }
737
Yorke Lee311969c2013-08-26 06:31:11 -0700738 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700739 if (mIsDialpadShown) {
740 hideDialpadFragment(false, true);
741 } else {
742 exitSearchUi();
743 }
Yorke Lee311969c2013-08-26 06:31:11 -0700744 }
745
Yorke Lee53a22302014-04-29 18:13:46 -0700746 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700747 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
748 if (canIntentBeHandled(voiceIntent)) {
749 mVoiceSearchButton.setVisibility(View.VISIBLE);
750 mVoiceSearchButton.setOnClickListener(this);
751 } else {
752 mVoiceSearchButton.setVisibility(View.GONE);
753 }
754 }
755
Andrew Leee74a10e2014-05-16 14:31:40 -0700756 private OptionsPopupMenu buildOptionsMenu(View invoker) {
757 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
758 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700759 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700760 popupMenu.setOnMenuItemClickListener(this);
761 return popupMenu;
762 }
763
Yorke Lee86e21f72014-04-02 16:49:38 -0700764 @Override
765 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700766 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700767 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700768 mPendingSearchViewQuery = null;
769 }
Yorke Leea524ae52014-08-05 18:01:05 -0700770 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700771 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700772 }
773
Chiao Cheng94b10b52012-08-17 16:59:12 -0700774 /**
775 * Returns true if the intent is due to hitting the green send key (hardware call button:
776 * KEYCODE_CALL) while in a call.
777 *
778 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700779 * @return true if the intent is due to hitting the green send key while in a call
780 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700781 private boolean isSendKeyWhileInCall(Intent intent) {
782 // If there is a call in progress and the user launched the dialer by hitting the call
783 // button, go straight to the in-call screen.
784 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700785
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700786 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700787 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700788 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700789 }
790
791 return false;
792 }
793
794 /**
795 * Sets the current tab based on the intent's request type
796 *
797 * @param intent Intent that contains information about which tab should be selected
798 */
Yorke Leec3766332013-07-31 11:13:16 -0700799 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700800 // 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 -0700801 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700802 finish();
803 return;
804 }
805
Yorke Lee669b6082013-09-17 15:43:38 -0700806 if (mDialpadFragment != null) {
807 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700808 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700809 mDialpadFragment.setStartedFromNewIntent(true);
810 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
811 mInCallDialpadUp = true;
812 }
813 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700814 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700815 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700816 }
817
818 @Override
819 public void onNewIntent(Intent newIntent) {
820 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700821 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700822
Chiao Cheng94b10b52012-08-17 16:59:12 -0700823 invalidateOptionsMenu();
824 }
825
826 /** Returns true if the given intent contains a phone number to populate the dialer with */
827 private boolean isDialIntent(Intent intent) {
828 final String action = intent.getAction();
829 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
830 return true;
831 }
832 if (Intent.ACTION_VIEW.equals(action)) {
833 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700834 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700835 return true;
836 }
837 }
838 return false;
839 }
840
841 /**
842 * Returns an appropriate call origin for this Activity. May return null when no call origin
843 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
844 * for remembering the tab in which the user made a phone call, so the external app's DIAL
845 * request should not be counted.)
846 */
847 public String getCallOrigin() {
848 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
849 }
850
Chiao Cheng94b10b52012-08-17 16:59:12 -0700851 /**
Yorke Leec3766332013-07-31 11:13:16 -0700852 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700853 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700854 private void enterSearchUi(boolean smartDialSearch, String query) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700855 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700856 // Weird race condition where fragment is doing work after the activity is destroyed
857 // due to talkback being on (b/10209937). Just return since we can't do any
858 // constructive here.
859 return;
860 }
861
Yorke Leeef2b7382013-08-09 17:39:25 -0700862 if (DEBUG) {
863 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
864 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700865
Yorke Leec3766332013-07-31 11:13:16 -0700866 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700867 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700868 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700869 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700870 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700871 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700872
Yorke Leeb207f8a2013-08-29 18:51:06 -0700873 final String tag;
874 if (smartDialSearch) {
875 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
876 } else {
877 tag = TAG_REGULAR_SEARCH_FRAGMENT;
878 }
879 mInDialpadSearch = smartDialSearch;
880 mInRegularSearch = !smartDialSearch;
881
Andrew Lee752956e2014-05-15 11:43:38 -0700882 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700883 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700884 if (fragment == null) {
885 if (smartDialSearch) {
886 fragment = new SmartDialSearchFragment();
887 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700888 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700889 }
Andrew Leeb1903842014-05-15 16:11:24 -0700890 transaction.add(R.id.dialtacts_frame, fragment, tag);
891 } else {
892 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700893 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700894 // DialtactsActivity will provide the options menu
895 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700896 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700897 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700898 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700899
900 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700901 }
902
903 /**
Yorke Leec3766332013-07-31 11:13:16 -0700904 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700905 */
Yorke Leec3766332013-07-31 11:13:16 -0700906 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700907 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700908 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -0700909 return;
910 }
Andrew Leeb1903842014-05-15 16:11:24 -0700911
Andrew Leeb1903842014-05-15 16:11:24 -0700912 mSearchView.setText(null);
913 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700914 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700915
Andrew Leeb1903842014-05-15 16:11:24 -0700916 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700917 if (mSmartDialSearchFragment != null) {
918 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700919 }
Andrew Leeb1903842014-05-15 16:11:24 -0700920 if (mRegularSearchFragment != null) {
921 transaction.remove(mRegularSearchFragment);
922 }
923 transaction.commit();
924
925 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700926 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700927 }
928
Chiao Cheng94b10b52012-08-17 16:59:12 -0700929 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700930 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700931 if (mStateSaved) {
932 return;
933 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700934 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700935 if (TextUtils.isEmpty(mSearchQuery) ||
936 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
937 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700938 exitSearchUi();
939 }
Yorke Leef6673d32013-08-23 15:34:17 -0700940 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700941 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700942 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -0700943 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700944 } else {
945 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700946 }
Yorke Leec3766332013-07-31 11:13:16 -0700947 }
948
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700949 /**
950 * @return True if the search UI was exited, false otherwise
951 */
952 private boolean maybeExitSearchUi() {
953 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
954 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -0700955 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700956 return true;
957 }
958 return false;
959 }
960
Yorke Leec3766332013-07-31 11:13:16 -0700961 @Override
962 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700963 if (mSmartDialSearchFragment != null) {
964 mSmartDialSearchFragment.setAddToContactNumber(query);
965 }
Yorke Leec3766332013-07-31 11:13:16 -0700966 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
967 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700968
969 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700970 if (DEBUG) {
971 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
972 }
973 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
974 // This callback can happen if the dialpad fragment is recreated because of
975 // activity destruction. In that case, don't update the search view because
976 // that would bring the user back to the search fragment regardless of the
977 // previous state of the application. Instead, just return here and let the
978 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700979 if (!TextUtils.isEmpty(normalizedQuery)) {
980 mPendingSearchViewQuery = normalizedQuery;
981 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700982 return;
983 }
Yorke Lee53a22302014-04-29 18:13:46 -0700984 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700985 }
986 }
Yorke Leec3766332013-07-31 11:13:16 -0700987
988 @Override
989 public void onListFragmentScrollStateChange(int scrollState) {
990 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700991 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -0700992 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700993 }
994 }
995
996 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -0700997 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -0700998 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700999 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1000 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001001 }
1002
Yorke Leec3766332013-07-31 11:13:16 -07001003 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001004 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001005 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001006
Yorke Leee1424812013-09-04 18:24:48 -07001007 public static Intent getAddNumberToContactIntent(CharSequence text) {
1008 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1009 intent.putExtra(Intents.Insert.PHONE, text);
1010 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1011 return intent;
1012 }
1013
Yorke Leeda0f9042013-12-05 14:25:51 -08001014 private boolean canIntentBeHandled(Intent intent) {
1015 final PackageManager packageManager = getPackageManager();
1016 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1017 PackageManager.MATCH_DEFAULT_ONLY);
1018 return resolveInfo != null && resolveInfo.size() > 0;
1019 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001020
Yorke Lee6a1461a2014-04-21 16:27:14 -07001021 @Override
1022 public void showCallHistory() {
1023 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1024 // CONTENT_TYPE, so that we always open our call log from our dialer
1025 final Intent intent = new Intent(this, CallLogActivity.class);
1026 startActivity(intent);
1027 }
1028
Yorke Lee86e21f72014-04-02 16:49:38 -07001029 /**
1030 * Called when the user has long-pressed a contact tile to start a drag operation.
1031 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001032 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001033 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001034 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001035 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001036 }
Andrew Lee18963442014-06-06 17:20:13 -07001037 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001038 }
1039
1040 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001041 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1042 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001043
Yorke Lee86e21f72014-04-02 16:49:38 -07001044 /**
1045 * Called when the user has released a contact tile after long-pressing it.
1046 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001047 @Override
1048 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001049 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001050 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001051 }
Andrew Lee18963442014-06-06 17:20:13 -07001052 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001053 }
1054
1055 @Override
1056 public void onDroppedOnRemove() {}
1057
1058 /**
Yorke Leed999b712014-04-23 15:10:58 -07001059 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001060 * once it has been attached to the activity.
1061 */
1062 @Override
1063 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001064 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001065 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001066 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001067
1068 @Override
1069 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001070 // Specify call-origin so that users will see the previous tab instead of
1071 // CallLog screen (search UI will be automatically exited).
1072 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001073 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001074 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001075 }
1076
1077 @Override
1078 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001079 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1080 }
1081
1082 @Override
1083 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001084 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001085 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1086 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001087 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001088 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001089 }
1090
1091 @Override
1092 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001093 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001094 }
1095
1096 @Override
1097 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001098 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001099 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001100
Yorke Leecc4660d2014-04-24 11:22:57 -07001101 @Override
1102 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001103 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001104 // Only scroll the button when the first tab is selected. The button should scroll from
1105 // the middle to right position only on the transition from the first tab to the second
1106 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001107 // If the app is in RTL mode, we need to check against the second tab, rather than the
1108 // first. This is because if we are scrolling between the first and second tabs, the
1109 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1110 // reversal of the order of the tabs.
1111 final boolean isLayoutRtl = DialerUtils.isRtl();
1112 final boolean shouldScrollButton = position == (isLayoutRtl
1113 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1114 if (shouldScrollButton && !mIsLandscape) {
1115 mFloatingActionButtonController.onPageScrolled(
1116 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001117 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1118 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001119 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001120 }
1121
1122 @Override
1123 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001124 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001125 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001126 }
1127
1128 @Override
1129 public void onPageScrollStateChanged(int state) {
1130 }
1131
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001132 private TelephonyManager getTelephonyManager() {
1133 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1134 }
1135
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001136 private TelecomManager getTelecomManager() {
1137 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001138 }
1139
Yorke Lee5253be02014-05-21 18:50:03 -07001140 @Override
1141 public boolean isActionBarShowing() {
1142 return mActionBarController.isActionBarShowing();
1143 }
1144
Yorke Leec98a5bb2014-10-28 16:12:05 -07001145 @Override
1146 public ActionBarController getActionBarController() {
1147 return mActionBarController;
1148 }
1149
Andrew Lee9da8fb42014-06-03 14:03:09 -07001150 public boolean isDialpadShown() {
1151 return mIsDialpadShown;
1152 }
1153
Yorke Lee5253be02014-05-21 18:50:03 -07001154 @Override
1155 public int getActionBarHideOffset() {
1156 return getActionBar().getHideOffset();
1157 }
1158
1159 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001160 public void setActionBarHideOffset(int offset) {
1161 getActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001162 }
1163
1164 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001165 public int getActionBarHeight() {
1166 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001167 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001168
1169 /**
1170 * Updates controller based on currently known information.
1171 *
1172 * @param animate Whether or not to animate the transition.
1173 */
1174 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Lee405a6e62014-08-20 15:02:16 -07001175 int align = (!mIsLandscape && mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
1176 FloatingActionButtonController.ALIGN_MIDDLE :
1177 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001178 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001179 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001180}