blob: e8cc45e245a6147679b8d34ccaf3a0ba4356cbdc [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;
Yorke Leec3766332013-07-31 11:13:16 -070068import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070069import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070070import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070071import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070072import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070073import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080074import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070075import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080076import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070077import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070078import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070079import com.android.dialer.list.RegularSearchFragment;
80import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070081import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070082import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070083import com.android.dialer.settings.DialerSettingsActivity;
Yorke Lee7d20f822014-06-19 17:09:33 -070084import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070085import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070086import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070087import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070088import com.android.dialerbind.DatabaseHelperManager;
Yorke Lee2fec47b2014-08-05 18:16:27 -070089import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070090import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070091
Yorke Leec3766332013-07-31 11:13:16 -070092import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080093import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070094
Chiao Cheng94b10b52012-08-17 16:59:12 -070095/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070096 * The dialer tab's title is 'phone', a more common name (see strings.xml).
97 */
Yorke Leec3766332013-07-31 11:13:16 -070098public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -070099 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700100 OnListFragmentScrolledListener,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700101 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700102 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700103 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700104 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700105 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700106 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700107 ViewPager.OnPageChangeListener,
108 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700109 private static final String TAG = "DialtactsActivity";
110
Ihab Awad526c0b82014-02-27 12:55:36 -0800111 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700112
Yorke Leef74011e2013-08-02 11:30:30 -0700113 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
114
Chiao Cheng94b10b52012-08-17 16:59:12 -0700115 /** @see #getCallOrigin() */
116 private static final String CALL_ORIGIN_DIALTACTS =
117 "com.android.dialer.DialtactsActivity";
118
Yorke Leeb207f8a2013-08-29 18:51:06 -0700119 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
120 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700121 private static final String KEY_SEARCH_QUERY = "search_query";
122 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700123 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700124
Yorke Leec3766332013-07-31 11:13:16 -0700125 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
126 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
127 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
128 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700129
Chiao Cheng94b10b52012-08-17 16:59:12 -0700130 /**
131 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
132 */
133 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
134
Yorke Leec3766332013-07-31 11:13:16 -0700135 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700136
Yorke Leef614f6f2014-10-03 10:44:19 -0700137 private FrameLayout mParentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700138
Yorke Leec3766332013-07-31 11:13:16 -0700139 /**
Yorke Leec3766332013-07-31 11:13:16 -0700140 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700141 */
Yorke Leef74011e2013-08-02 11:30:30 -0700142 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700143
144 /**
145 * Fragment for searching phone numbers using the alphanumeric keyboard.
146 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700147 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700148
149 /**
150 * Fragment for searching phone numbers using the dialpad.
151 */
152 private SmartDialSearchFragment mSmartDialSearchFragment;
153
Yorke Leee00c9fe2014-04-12 12:42:06 -0700154 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700155 * Animation that slides in.
156 */
157 private Animation mSlideIn;
158
159 /**
160 * Animation that slides out.
161 */
162 private Animation mSlideOut;
163
164 /**
165 * Listener for after slide out animation completes on dialer fragment.
166 */
167 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
168 @Override
169 public void onAnimationEnd(Animation animation) {
170 commitDialpadFragmentHide();
171 }
172 };
173
174 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700175 * Fragment containing the speed dial list, recents list, and all contacts list.
176 */
177 private ListsFragment mListsFragment;
178
Yorke Lee19e68ca2014-10-28 11:51:40 -0700179 /**
180 * Tracks whether onSaveInstanceState has been called. If true, no fragment transactions can
181 * be commited.
182 */
183 private boolean mStateSaved;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700184 private boolean mInDialpadSearch;
185 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700186 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700187 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700188 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700189
Yorke Leeef2b7382013-08-09 17:39:25 -0700190 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700191 * Whether or not the device is in landscape orientation.
192 */
193 private boolean mIsLandscape;
194
195 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700196 * The position of the currently selected tab in the attached {@link ListsFragment}.
197 */
198 private int mCurrentTabPosition = 0;
199
200 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700201 * True if the dialpad is only temporarily showing due to being in call
202 */
203 private boolean mInCallDialpadUp;
204
205 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700206 * True when this activity has been launched for the first time.
207 */
Yorke Lee98702de2013-08-06 12:03:32 -0700208 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700209
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700210 /**
211 * Search query to be applied to the SearchView in the ActionBar once
212 * onCreateOptionsMenu has been called.
213 */
214 private String mPendingSearchViewQuery;
215
Yorke Lee74edcdc2014-07-11 16:15:08 -0700216 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700217 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700218 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700219
Yorke Leeef2b7382013-08-09 17:39:25 -0700220 private String mSearchQuery;
221
Yorke Leefce269a2013-08-12 11:56:04 -0700222 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700223 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700224 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700225
Sai Cheemalapati41460652014-06-02 21:05:39 -0700226 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700227
Andrew Lee2423a2f2014-05-29 14:14:45 -0700228 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700229
Andrew Leee74a10e2014-05-16 14:31:40 -0700230 private class OptionsPopupMenu extends PopupMenu {
231 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700232 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700233 }
234
235 @Override
236 public void show() {
237 final Menu menu = getMenu();
238 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700239 clearFrequents.setVisible(mListsFragment != null &&
240 mListsFragment.getSpeedDialFragment() != null &&
241 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700242 super.show();
243 }
244 }
245
Chiao Cheng94b10b52012-08-17 16:59:12 -0700246 /**
Yorke Lee28266192014-05-01 10:05:52 -0700247 * Listener that listens to drag events and sends their x and y coordinates to a
248 * {@link DragDropController}.
249 */
250 private class LayoutOnDragListener implements OnDragListener {
251 @Override
252 public boolean onDrag(View v, DragEvent event) {
253 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700254 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700255 }
256 return true;
257 }
258 }
259
260 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700261 * Listener used to send search queries to the phone search fragment.
262 */
Yorke Lee53a22302014-04-29 18:13:46 -0700263 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700264 @Override
265 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
266 }
Yorke Leec3766332013-07-31 11:13:16 -0700267
Andrew Lee99a570c2014-05-15 14:18:50 -0700268 @Override
269 public void onTextChanged(CharSequence s, int start, int before, int count) {
270 final String newText = s.toString();
271 if (newText.equals(mSearchQuery)) {
272 // If the query hasn't changed (perhaps due to activity being destroyed
273 // and restored, or user launching the same DIAL intent twice), then there is
274 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700275 return;
276 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700277 if (DEBUG) {
278 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700279 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700280 }
Yorke Lee710709d2014-05-29 07:18:42 -0700281 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700282
Andrew Lee90374a72014-05-16 15:01:09 -0700283 // Show search fragment only when the query string is changed to non-empty text.
284 if (!TextUtils.isEmpty(newText)) {
285 // Call enterSearchUi only if we are switching search modes, or showing a search
286 // fragment for the first time.
287 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
288 (!mIsDialpadShown && mInRegularSearch);
289 if (!sameSearchMode) {
290 enterSearchUi(mIsDialpadShown, mSearchQuery);
291 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700292 }
293
Andrew Leea8515422014-06-13 16:53:54 -0700294 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700295 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700296 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700297 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700298 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700299 }
300
301 @Override
302 public void afterTextChanged(Editable s) {
303 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700304 };
305
Andrew Leeb1903842014-05-15 16:11:24 -0700306
307 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700308 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700309 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700310 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700311 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700312 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700313 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700314 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700315 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
316 }
Andrew Leeb1903842014-05-15 16:11:24 -0700317 }
318 };
319
320 /**
321 * If the search term is empty and the user closes the soft keyboard, close the search UI.
322 */
323 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
324 @Override
325 public boolean onKey(View v, int keyCode, KeyEvent event) {
326 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
327 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700328 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700329 }
330 return false;
331 }
332 };
333
Chiao Cheng94b10b52012-08-17 16:59:12 -0700334 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700335 public boolean dispatchTouchEvent(MotionEvent ev) {
336 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
337 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
338 }
339 return super.dispatchTouchEvent(ev);
340
341 }
342
343 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700344 protected void onCreate(Bundle savedInstanceState) {
345 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700346 mFirstLaunch = true;
347
Andrew Lee2423a2f2014-05-29 14:14:45 -0700348 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700349 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700350
Yorke Lee8898cd02013-08-08 10:24:27 -0700351 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800352 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700353
Yorke Lee53a22302014-04-29 18:13:46 -0700354 final ActionBar actionBar = getActionBar();
355 actionBar.setCustomView(R.layout.search_edittext);
356 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700357 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700358
Yorke Lee5253be02014-05-21 18:50:03 -0700359 mActionBarController = new ActionBarController(this,
360 (SearchEditTextLayout) actionBar.getCustomView());
361
Andrew Lee04675a52014-06-05 18:36:20 -0700362 SearchEditTextLayout searchEditTextLayout =
363 (SearchEditTextLayout) actionBar.getCustomView();
364 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
365
366 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700367 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700368 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
369 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
370 .setOnClickListener(mSearchViewOnClickListener);
371 searchEditTextLayout.findViewById(R.id.search_box_start_search)
372 .setOnClickListener(mSearchViewOnClickListener);
373 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700374 @Override
375 public void onBackButtonClicked() {
376 onBackPressed();
377 }
378 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700379
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700380 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700381 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700382
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700383 final View floatingActionButtonContainer = findViewById(
384 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700385 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
386 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700387 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700388 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700389
Andrew Lee04675a52014-06-05 18:36:20 -0700390 ImageButton optionsMenuButton =
391 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700392 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700393 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
394 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700395
Yorke Leeef2b7382013-08-09 17:39:25 -0700396 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
397 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700398 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800399 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700400 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800401 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
402 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700403 } else {
404 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700405 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
406 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700407 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700408 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700409 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700410 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700411
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700412 final boolean isLayoutRtl = DialerUtils.isRtl();
413 if (mIsLandscape) {
414 mSlideIn = AnimationUtils.loadAnimation(this,
415 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
416 mSlideOut = AnimationUtils.loadAnimation(this,
417 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
418 } else {
419 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
420 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
421 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700422
Yorke Lee2fec47b2014-08-05 18:16:27 -0700423 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
424 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
425
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700426 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700427
Yorke Leef614f6f2014-10-03 10:44:19 -0700428 mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
429 mParentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700430 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700431 new ViewTreeObserver.OnGlobalLayoutListener() {
432 @Override
433 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700434 final ViewTreeObserver observer =
435 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700436 if (!observer.isAlive()) {
437 return;
438 }
439 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700440 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700441 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700442 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700443 }
444 });
Andrew Lee0c667702014-05-12 14:31:45 -0700445
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700446 setupActivityOverlay();
447
Yorke Lee0baa98b2013-08-22 10:55:16 -0700448 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700449 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700450 }
451
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700452 private void setupActivityOverlay() {
453 final View activityOverlay = findViewById(R.id.activity_overlay);
454 activityOverlay.setOnTouchListener(new OnTouchListener() {
455 @Override
456 public boolean onTouch(View v, MotionEvent event) {
457 if (!mIsDialpadShown) {
458 maybeExitSearchUi();
459 }
460 return false;
461 }
462 });
463 }
464
Chiao Cheng94b10b52012-08-17 16:59:12 -0700465 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700466 protected void onResume() {
467 super.onResume();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700468 mStateSaved = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700469 if (mFirstLaunch) {
470 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700471 } else if (!phoneIsInUse() && mInCallDialpadUp) {
472 hideDialpadFragment(false, true);
473 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700474 } else if (mShowDialpadOnResume) {
475 showDialpadFragment(false);
476 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700477 }
478 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700479 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700480 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700481 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700482 }
483
484 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700485 protected void onPause() {
486 if (mClearSearchOnPause) {
487 hideDialpadAndSearchUi();
488 mClearSearchOnPause = false;
489 }
Yorke Lee19e68ca2014-10-28 11:51:40 -0700490 if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) {
491 commitDialpadFragmentHide();
492 }
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700493 super.onPause();
494 }
495
496 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700497 protected void onSaveInstanceState(Bundle outState) {
498 super.onSaveInstanceState(outState);
499 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700500 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
501 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700502 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700503 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700504 mActionBarController.saveInstanceState(outState);
Yorke Lee19e68ca2014-10-28 11:51:40 -0700505 mStateSaved = true;
Yorke Leeef2b7382013-08-09 17:39:25 -0700506 }
507
508 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700509 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700510 if (fragment instanceof DialpadFragment) {
511 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700512 if (!mShowDialpadOnResume) {
513 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
514 transaction.hide(mDialpadFragment);
515 transaction.commit();
516 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700517 } else if (fragment instanceof SmartDialSearchFragment) {
518 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700519 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700520 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700521 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700522 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700523 } else if (fragment instanceof ListsFragment) {
524 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700525 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700526 }
Yorke Leec3766332013-07-31 11:13:16 -0700527 }
528
Alon Albertb453e5b2013-09-10 15:54:23 -0700529 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700530 final Intent intent = new Intent(this, DialerSettingsActivity.class);
531 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700532 }
533
Chiao Cheng94b10b52012-08-17 16:59:12 -0700534 @Override
535 public void onClick(View view) {
536 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700537 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700538 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700539 mInCallDialpadUp = false;
540 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700541 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700542 break;
Yorke Leec3766332013-07-31 11:13:16 -0700543 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800544 try {
545 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
546 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
547 } catch (ActivityNotFoundException e) {
548 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
549 Toast.LENGTH_SHORT).show();
550 }
Yorke Leec3766332013-07-31 11:13:16 -0700551 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700552 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700553 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700554 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700555 default: {
556 Log.wtf(TAG, "Unexpected onClick event from " + view);
557 break;
558 }
559 }
560 }
561
Yorke Leec3766332013-07-31 11:13:16 -0700562 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700563 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700564 switch (item.getItemId()) {
565 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700566 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700567 break;
568 case R.id.menu_add_contact:
569 try {
570 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
571 } catch (ActivityNotFoundException e) {
572 Toast toast = Toast.makeText(this,
573 R.string.add_contact_not_available,
574 Toast.LENGTH_SHORT);
575 toast.show();
576 }
577 break;
578 case R.id.menu_import_export:
579 // We hard-code the "contactsAreAvailable" argument because doing it properly would
580 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
581 // now in Dialtacts for (potential) performance reasons. Compare with how it is
582 // done in {@link PeopleActivity}.
583 ImportExportDialogFragment.show(getFragmentManager(), true,
584 DialtactsActivity.class);
585 return true;
586 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700587 ClearFrequentsDialog.show(getFragmentManager());
588 return true;
589 case R.id.menu_call_settings:
590 handleMenuSettings();
591 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700592 }
593 return false;
594 }
595
596 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700597 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
598 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
599 if (resultCode == RESULT_OK) {
600 final ArrayList<String> matches = data.getStringArrayListExtra(
601 RecognizerIntent.EXTRA_RESULTS);
602 if (matches.size() > 0) {
603 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700604 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700605 } else {
606 Log.e(TAG, "Voice search - nothing heard");
607 }
608 } else {
609 Log.e(TAG, "Voice search failed");
610 }
611 }
612 super.onActivityResult(requestCode, resultCode, data);
613 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700614
Andrew Lee2a58ab82014-05-15 02:16:04 -0700615 /**
616 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
617 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
618 * @see #onDialpadShown
619 */
Yorke Leec3766332013-07-31 11:13:16 -0700620 private void showDialpadFragment(boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700621 if (mIsDialpadShown || mStateSaved) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700622 return;
623 }
624 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700625 mDialpadFragment.setAnimate(animate);
Sai Cheemalapati2d7faf62014-08-04 11:48:50 -0700626 mDialpadFragment.sendScreenView();
Andrew Leecdfa6c62014-05-06 15:33:35 -0700627
Chiao Cheng94b10b52012-08-17 16:59:12 -0700628 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700629 ft.show(mDialpadFragment);
630 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700631
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700632 if (animate) {
633 mFloatingActionButtonController.scaleOut();
634 } else {
635 mFloatingActionButtonController.setVisible(false);
636 }
Yorke Lee5253be02014-05-21 18:50:03 -0700637 mActionBarController.onDialpadUp();
638
Andrew Leeb1903842014-05-15 16:11:24 -0700639 if (!isInSearchUi()) {
640 enterSearchUi(true /* isSmartDial */, mSearchQuery);
641 }
Yorke Leec3766332013-07-31 11:13:16 -0700642 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700643
Andrew Lee2a58ab82014-05-15 02:16:04 -0700644 /**
645 * Callback from child DialpadFragment when the dialpad is shown.
646 */
647 public void onDialpadShown() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700648 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700649 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700650 } else {
651 mDialpadFragment.setYFraction(0);
652 }
653
Andrew Lee2a58ab82014-05-15 02:16:04 -0700654 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700655 }
656
657 /**
658 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
659 * a callback after the hide animation ends.
660 * @see #commitDialpadFragmentHide
661 */
Yorke Leeca195042013-09-25 16:29:38 -0700662 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700663 if (mDialpadFragment == null) {
664 return;
665 }
Yorke Leef6673d32013-08-23 15:34:17 -0700666 if (clearDialpad) {
667 mDialpadFragment.clearDialpad();
668 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700669 if (!mIsDialpadShown) {
670 return;
Yorke Leec3766332013-07-31 11:13:16 -0700671 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700672 mIsDialpadShown = false;
673 mDialpadFragment.setAnimate(animate);
674
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700675 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700676
677 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700678 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700679 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700680 } else {
681 commitDialpadFragmentHide();
682 }
683
Yorke Lee5253be02014-05-21 18:50:03 -0700684 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700685
Andrew Leed4cde832014-05-16 15:56:48 -0700686 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700687 if (TextUtils.isEmpty(mSearchQuery)) {
688 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700689 }
Andrew Leed4cde832014-05-16 15:56:48 -0700690 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700691 }
692
693 /**
694 * Finishes hiding the dialpad fragment after any animations are completed.
695 */
696 private void commitDialpadFragmentHide() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700697 if (!mStateSaved && !mDialpadFragment.isHidden()) {
698 final FragmentTransaction ft = getFragmentManager().beginTransaction();
699 ft.hide(mDialpadFragment);
700 ft.commit();
701 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700702 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700703 }
704
Andrew Lee2a58ab82014-05-15 02:16:04 -0700705 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700706 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700707 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700708 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700709 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700710 fragment = mRegularSearchFragment;
711 }
712 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700713 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700714 }
715 }
716
Yorke Lee5253be02014-05-21 18:50:03 -0700717 @Override
718 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700719 return mInDialpadSearch || mInRegularSearch;
720 }
721
Yorke Lee5253be02014-05-21 18:50:03 -0700722 @Override
723 public boolean hasSearchQuery() {
724 return !TextUtils.isEmpty(mSearchQuery);
725 }
726
727 @Override
728 public boolean shouldShowActionBar() {
729 return mListsFragment.shouldShowActionBar();
730 }
731
Yorke Leeb207f8a2013-08-29 18:51:06 -0700732 private void setNotInSearchUi() {
733 mInDialpadSearch = false;
734 mInRegularSearch = false;
735 }
736
Yorke Lee311969c2013-08-26 06:31:11 -0700737 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700738 if (mIsDialpadShown) {
739 hideDialpadFragment(false, true);
740 } else {
741 exitSearchUi();
742 }
Yorke Lee311969c2013-08-26 06:31:11 -0700743 }
744
Yorke Lee53a22302014-04-29 18:13:46 -0700745 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700746 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
747 if (canIntentBeHandled(voiceIntent)) {
748 mVoiceSearchButton.setVisibility(View.VISIBLE);
749 mVoiceSearchButton.setOnClickListener(this);
750 } else {
751 mVoiceSearchButton.setVisibility(View.GONE);
752 }
753 }
754
Andrew Leee74a10e2014-05-16 14:31:40 -0700755 private OptionsPopupMenu buildOptionsMenu(View invoker) {
756 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
757 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700758 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700759 popupMenu.setOnMenuItemClickListener(this);
760 return popupMenu;
761 }
762
Yorke Lee86e21f72014-04-02 16:49:38 -0700763 @Override
764 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700765 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700766 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700767 mPendingSearchViewQuery = null;
768 }
Yorke Leea524ae52014-08-05 18:01:05 -0700769 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700770 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700771 }
772
Chiao Cheng94b10b52012-08-17 16:59:12 -0700773 /**
774 * Returns true if the intent is due to hitting the green send key (hardware call button:
775 * KEYCODE_CALL) while in a call.
776 *
777 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700778 * @return true if the intent is due to hitting the green send key while in a call
779 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700780 private boolean isSendKeyWhileInCall(Intent intent) {
781 // If there is a call in progress and the user launched the dialer by hitting the call
782 // button, go straight to the in-call screen.
783 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700784
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700785 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700786 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700787 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700788 }
789
790 return false;
791 }
792
793 /**
794 * Sets the current tab based on the intent's request type
795 *
796 * @param intent Intent that contains information about which tab should be selected
797 */
Yorke Leec3766332013-07-31 11:13:16 -0700798 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700799 // 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 -0700800 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700801 finish();
802 return;
803 }
804
Yorke Lee669b6082013-09-17 15:43:38 -0700805 if (mDialpadFragment != null) {
806 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700807 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700808 mDialpadFragment.setStartedFromNewIntent(true);
809 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
810 mInCallDialpadUp = true;
811 }
812 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700813 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700814 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700815 }
816
817 @Override
818 public void onNewIntent(Intent newIntent) {
819 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700820 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700821
Chiao Cheng94b10b52012-08-17 16:59:12 -0700822 invalidateOptionsMenu();
823 }
824
825 /** Returns true if the given intent contains a phone number to populate the dialer with */
826 private boolean isDialIntent(Intent intent) {
827 final String action = intent.getAction();
828 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
829 return true;
830 }
831 if (Intent.ACTION_VIEW.equals(action)) {
832 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700833 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700834 return true;
835 }
836 }
837 return false;
838 }
839
840 /**
841 * Returns an appropriate call origin for this Activity. May return null when no call origin
842 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
843 * for remembering the tab in which the user made a phone call, so the external app's DIAL
844 * request should not be counted.)
845 */
846 public String getCallOrigin() {
847 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
848 }
849
Chiao Cheng94b10b52012-08-17 16:59:12 -0700850 /**
Yorke Leec3766332013-07-31 11:13:16 -0700851 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700852 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700853 private void enterSearchUi(boolean smartDialSearch, String query) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700854 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700855 // Weird race condition where fragment is doing work after the activity is destroyed
856 // due to talkback being on (b/10209937). Just return since we can't do any
857 // constructive here.
858 return;
859 }
860
Yorke Leeef2b7382013-08-09 17:39:25 -0700861 if (DEBUG) {
862 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
863 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700864
Yorke Leec3766332013-07-31 11:13:16 -0700865 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700866 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700867 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700868 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700869 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700870 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700871
Yorke Leeb207f8a2013-08-29 18:51:06 -0700872 final String tag;
873 if (smartDialSearch) {
874 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
875 } else {
876 tag = TAG_REGULAR_SEARCH_FRAGMENT;
877 }
878 mInDialpadSearch = smartDialSearch;
879 mInRegularSearch = !smartDialSearch;
880
Andrew Lee752956e2014-05-15 11:43:38 -0700881 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700882 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700883 if (fragment == null) {
884 if (smartDialSearch) {
885 fragment = new SmartDialSearchFragment();
886 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700887 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700888 }
Andrew Leeb1903842014-05-15 16:11:24 -0700889 transaction.add(R.id.dialtacts_frame, fragment, tag);
890 } else {
891 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700892 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700893 // DialtactsActivity will provide the options menu
894 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700895 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700896 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700897 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700898
899 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700900 }
901
902 /**
Yorke Leec3766332013-07-31 11:13:16 -0700903 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700904 */
Yorke Leec3766332013-07-31 11:13:16 -0700905 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700906 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700907 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -0700908 return;
909 }
Andrew Leeb1903842014-05-15 16:11:24 -0700910
Andrew Leeb1903842014-05-15 16:11:24 -0700911 mSearchView.setText(null);
912 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700913 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700914
Andrew Leeb1903842014-05-15 16:11:24 -0700915 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700916 if (mSmartDialSearchFragment != null) {
917 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700918 }
Andrew Leeb1903842014-05-15 16:11:24 -0700919 if (mRegularSearchFragment != null) {
920 transaction.remove(mRegularSearchFragment);
921 }
922 transaction.commit();
923
924 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700925 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700926 }
927
928 /** Returns an Intent to launch Call Settings screen */
929 public static Intent getCallSettingsIntent() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700930 final Intent intent = new Intent(TelecomManager.ACTION_SHOW_CALL_SETTINGS);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700931 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
932 return intent;
933 }
934
935 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700936 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700937 if (mStateSaved) {
938 return;
939 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700940 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700941 if (TextUtils.isEmpty(mSearchQuery) ||
942 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
943 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700944 exitSearchUi();
945 }
Yorke Leef6673d32013-08-23 15:34:17 -0700946 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700947 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700948 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -0700949 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700950 } else {
951 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700952 }
Yorke Leec3766332013-07-31 11:13:16 -0700953 }
954
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700955 /**
956 * @return True if the search UI was exited, false otherwise
957 */
958 private boolean maybeExitSearchUi() {
959 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
960 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -0700961 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700962 return true;
963 }
964 return false;
965 }
966
Yorke Leec3766332013-07-31 11:13:16 -0700967 @Override
968 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700969 if (mSmartDialSearchFragment != null) {
970 mSmartDialSearchFragment.setAddToContactNumber(query);
971 }
Yorke Leec3766332013-07-31 11:13:16 -0700972 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
973 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700974
975 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700976 if (DEBUG) {
977 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
978 }
979 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
980 // This callback can happen if the dialpad fragment is recreated because of
981 // activity destruction. In that case, don't update the search view because
982 // that would bring the user back to the search fragment regardless of the
983 // previous state of the application. Instead, just return here and let the
984 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700985 if (!TextUtils.isEmpty(normalizedQuery)) {
986 mPendingSearchViewQuery = normalizedQuery;
987 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700988 return;
989 }
Yorke Lee53a22302014-04-29 18:13:46 -0700990 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700991 }
992 }
Yorke Leec3766332013-07-31 11:13:16 -0700993
994 @Override
995 public void onListFragmentScrollStateChange(int scrollState) {
996 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700997 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -0700998 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700999 }
1000 }
1001
1002 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001003 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001004 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001005 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1006 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001007 }
1008
Yorke Leec3766332013-07-31 11:13:16 -07001009 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001010 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001011 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001012
Yorke Leee1424812013-09-04 18:24:48 -07001013 public static Intent getAddNumberToContactIntent(CharSequence text) {
1014 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1015 intent.putExtra(Intents.Insert.PHONE, text);
1016 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1017 return intent;
1018 }
1019
Yorke Leeda0f9042013-12-05 14:25:51 -08001020 private boolean canIntentBeHandled(Intent intent) {
1021 final PackageManager packageManager = getPackageManager();
1022 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1023 PackageManager.MATCH_DEFAULT_ONLY);
1024 return resolveInfo != null && resolveInfo.size() > 0;
1025 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001026
Yorke Lee6a1461a2014-04-21 16:27:14 -07001027 @Override
1028 public void showCallHistory() {
1029 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1030 // CONTENT_TYPE, so that we always open our call log from our dialer
1031 final Intent intent = new Intent(this, CallLogActivity.class);
1032 startActivity(intent);
1033 }
1034
Yorke Lee86e21f72014-04-02 16:49:38 -07001035 /**
1036 * Called when the user has long-pressed a contact tile to start a drag operation.
1037 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001038 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001039 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001040 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001041 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001042 }
Andrew Lee18963442014-06-06 17:20:13 -07001043 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001044 }
1045
1046 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001047 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1048 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001049
Yorke Lee86e21f72014-04-02 16:49:38 -07001050 /**
1051 * Called when the user has released a contact tile after long-pressing it.
1052 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001053 @Override
1054 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001055 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001056 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001057 }
Andrew Lee18963442014-06-06 17:20:13 -07001058 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001059 }
1060
1061 @Override
1062 public void onDroppedOnRemove() {}
1063
1064 /**
Yorke Leed999b712014-04-23 15:10:58 -07001065 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001066 * once it has been attached to the activity.
1067 */
1068 @Override
1069 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001070 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001071 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001072 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001073
1074 @Override
1075 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001076 // Specify call-origin so that users will see the previous tab instead of
1077 // CallLog screen (search UI will be automatically exited).
1078 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001079 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001080 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001081 }
1082
1083 @Override
1084 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001085 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1086 }
1087
1088 @Override
1089 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001090 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001091 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1092 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001093 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001094 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001095 }
1096
1097 @Override
1098 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001099 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001100 }
1101
1102 @Override
1103 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001104 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001105 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001106
Yorke Leecc4660d2014-04-24 11:22:57 -07001107 @Override
1108 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001109 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001110 // Only scroll the button when the first tab is selected. The button should scroll from
1111 // the middle to right position only on the transition from the first tab to the second
1112 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001113 // If the app is in RTL mode, we need to check against the second tab, rather than the
1114 // first. This is because if we are scrolling between the first and second tabs, the
1115 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1116 // reversal of the order of the tabs.
1117 final boolean isLayoutRtl = DialerUtils.isRtl();
1118 final boolean shouldScrollButton = position == (isLayoutRtl
1119 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1120 if (shouldScrollButton && !mIsLandscape) {
1121 mFloatingActionButtonController.onPageScrolled(
1122 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001123 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1124 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001125 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001126 }
1127
1128 @Override
1129 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001130 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001131 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001132 }
1133
1134 @Override
1135 public void onPageScrollStateChanged(int state) {
1136 }
1137
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001138 private TelephonyManager getTelephonyManager() {
1139 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1140 }
1141
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001142 private TelecomManager getTelecomManager() {
1143 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001144 }
1145
Yorke Lee5253be02014-05-21 18:50:03 -07001146 @Override
1147 public boolean isActionBarShowing() {
1148 return mActionBarController.isActionBarShowing();
1149 }
1150
Andrew Lee9da8fb42014-06-03 14:03:09 -07001151 public boolean isDialpadShown() {
1152 return mIsDialpadShown;
1153 }
1154
Yorke Lee5253be02014-05-21 18:50:03 -07001155 @Override
1156 public int getActionBarHideOffset() {
1157 return getActionBar().getHideOffset();
1158 }
1159
1160 @Override
1161 public int getActionBarHeight() {
1162 return mActionBarHeight;
1163 }
1164
1165 @Override
1166 public void setActionBarHideOffset(int hideOffset) {
Yorke Leea524ae52014-08-05 18:01:05 -07001167 mActionBarController.setHideOffset(hideOffset);
Yorke Lee5253be02014-05-21 18:50:03 -07001168 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001169
1170 /**
1171 * Updates controller based on currently known information.
1172 *
1173 * @param animate Whether or not to animate the transition.
1174 */
1175 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Lee405a6e62014-08-20 15:02:16 -07001176 int align = (!mIsLandscape && mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
1177 FloatingActionButtonController.ALIGN_MIDDLE :
1178 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001179 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001180 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001181}