blob: f5a2d3ed54610a7d345b95e717efa14726c998c9 [file] [log] [blame]
Chiao Cheng94b10b52012-08-17 16:59:12 -07001/*
Yorke Leec3766332013-07-31 11:13:16 -07002 * Copyright (C) 2013 The Android Open Source Project
Chiao Cheng94b10b52012-08-17 16:59:12 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.dialer;
18
Yorke Leecc4660d2014-04-24 11:22:57 -070019import android.animation.LayoutTransition;
Yorke Lee53a22302014-04-29 18:13:46 -070020import android.app.ActionBar;
Chiao Cheng94b10b52012-08-17 16:59:12 -070021import android.app.Activity;
22import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080024import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070025import android.content.Context;
26import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080027import android.content.pm.PackageManager;
28import android.content.pm.ResolveInfo;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070029import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070030import android.content.res.Resources;
Yorke Lee33932ff2014-04-16 13:34:32 -070031import android.content.res.TypedArray;
Chiao Cheng94b10b52012-08-17 16:59:12 -070032import android.net.Uri;
33import android.os.Bundle;
34import android.os.RemoteException;
35import android.os.ServiceManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070036import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070037import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070038import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070039import android.support.v4.view.ViewPager;
Yorke Leec3766332013-07-31 11:13:16 -070040import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070041import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070043import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070044import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070045import android.view.DragEvent;
Andrew Leeb1903842014-05-15 16:11:24 -070046import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070047import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070049import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070050import android.view.View;
Sai Cheemalapati41460652014-06-02 21:05:39 -070051import android.view.ViewTreeObserver;
Yorke Lee28266192014-05-01 10:05:52 -070052import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070053import android.view.View.OnTouchListener;
Andrew Lee2a58ab82014-05-15 02:16:04 -070054import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070055import android.view.animation.AnimationUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070056import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070057import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070058import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070059import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070060import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070061import android.widget.PopupMenu;
Yorke Leecc4660d2014-04-24 11:22:57 -070062import android.widget.RelativeLayout;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080063import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070064
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070065import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070066import com.android.contacts.common.activity.TransactionSafeActivity;
Andrew Lee3c14bc32014-05-28 15:43:03 -070067import com.android.contacts.common.animation.AnimationListenerAdapter;
Yorke Leec3766332013-07-31 11:13:16 -070068import com.android.contacts.common.dialog.ClearFrequentsDialog;
Nancy Chenbeededb2014-06-10 18:30:28 -070069import com.android.contacts.common.dialog.SelectSIMDialogFragment;
Yorke Leec3766332013-07-31 11:13:16 -070070import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080071import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Andrew Lee4cbc9732014-04-24 14:38:58 -070072import com.android.contacts.common.util.ViewUtil;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070073import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070074import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070075import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070076import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070077import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070078import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070079import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080080import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070081import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080082import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070083import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070084import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070085import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070086import com.android.dialer.list.RegularSearchFragment;
87import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070088import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee5253be02014-05-21 18:50:03 -070089import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070090import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070091import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070092import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070093
Yorke Leec3766332013-07-31 11:13:16 -070094import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080095import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070096
Chiao Cheng94b10b52012-08-17 16:59:12 -070097/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070098 * The dialer tab's title is 'phone', a more common name (see strings.xml).
99 */
Yorke Leec3766332013-07-31 11:13:16 -0700100public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700101 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700102 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800103 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700104 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700105 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700106 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700107 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700108 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700109 PopupMenu.OnMenuItemClickListener,
Nancy Chenbeededb2014-06-10 18:30:28 -0700110 SelectSIMDialogFragment.OnClickOkListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700111 ViewPager.OnPageChangeListener,
112 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700113 private static final String TAG = "DialtactsActivity";
114
Ihab Awad526c0b82014-02-27 12:55:36 -0800115 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700116
Yorke Leef74011e2013-08-02 11:30:30 -0700117 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
118
Chiao Cheng94b10b52012-08-17 16:59:12 -0700119 /** Used to open Call Setting */
120 private static final String PHONE_PACKAGE = "com.android.phone";
121 private static final String CALL_SETTINGS_CLASS_NAME =
122 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700123 /** @see #getCallOrigin() */
124 private static final String CALL_ORIGIN_DIALTACTS =
125 "com.android.dialer.DialtactsActivity";
126
Yorke Leeb207f8a2013-08-29 18:51:06 -0700127 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
128 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700129 private static final String KEY_SEARCH_QUERY = "search_query";
130 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700131 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700132
Yorke Leec3766332013-07-31 11:13:16 -0700133 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
134 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
135 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
136 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700137
Chiao Cheng94b10b52012-08-17 16:59:12 -0700138 /**
139 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
140 */
141 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
142
Yorke Leec3766332013-07-31 11:13:16 -0700143 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700144
Nancy Chenbeededb2014-06-10 18:30:28 -0700145 /**
146 * Constant to indicate there is only one service provider available.
147 */
148 private static final int NO_MULTI_SIM = -1;
149
Yorke Lee28aab272014-06-11 10:24:19 -0700150 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700151
Yorke Leec3766332013-07-31 11:13:16 -0700152 /**
Yorke Leec3766332013-07-31 11:13:16 -0700153 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700154 */
Yorke Leef74011e2013-08-02 11:30:30 -0700155 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700156
157 /**
158 * Fragment for searching phone numbers using the alphanumeric keyboard.
159 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700160 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700161
162 /**
163 * Fragment for searching phone numbers using the dialpad.
164 */
165 private SmartDialSearchFragment mSmartDialSearchFragment;
166
Yorke Leee00c9fe2014-04-12 12:42:06 -0700167 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700168 * Animation that slides in.
169 */
170 private Animation mSlideIn;
171
172 /**
173 * Animation that slides out.
174 */
175 private Animation mSlideOut;
176
177 /**
178 * Listener for after slide out animation completes on dialer fragment.
179 */
180 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
181 @Override
182 public void onAnimationEnd(Animation animation) {
183 commitDialpadFragmentHide();
184 }
185 };
186
187 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700188 * Fragment containing the speed dial list, recents list, and all contacts list.
189 */
190 private ListsFragment mListsFragment;
191
Yorke Leeb207f8a2013-08-29 18:51:06 -0700192 private boolean mInDialpadSearch;
193 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700194 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700195 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700196 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700197
Yorke Leeef2b7382013-08-09 17:39:25 -0700198 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700199 * Whether or not the device is in landscape orientation.
200 */
201 private boolean mIsLandscape;
202
203 /**
Nancy Chenbeededb2014-06-10 18:30:28 -0700204 * Information about the currently selected SIM card.
205 */
206 private int mCurrentSimCard = NO_MULTI_SIM;
207
208 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700209 * The position of the currently selected tab in the attached {@link ListsFragment}.
210 */
211 private int mCurrentTabPosition = 0;
212
213 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700214 * True if the dialpad is only temporarily showing due to being in call
215 */
216 private boolean mInCallDialpadUp;
217
218 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700219 * True when this activity has been launched for the first time.
220 */
Yorke Lee98702de2013-08-06 12:03:32 -0700221 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700222
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700223 /**
224 * Search query to be applied to the SearchView in the ActionBar once
225 * onCreateOptionsMenu has been called.
226 */
227 private String mPendingSearchViewQuery;
228
Yorke Lee53a22302014-04-29 18:13:46 -0700229 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700230 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700231
Yorke Leeef2b7382013-08-09 17:39:25 -0700232 private String mSearchQuery;
233
Yorke Leefce269a2013-08-12 11:56:04 -0700234 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700235 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700236 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700237
238 private String mDescriptionDialButtonStr;
239 private String mActionMenuDialpadButtonStr;
240 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700241 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700242 /**
243 * Additional offset for FAB to be lowered when dialpad is open.
244 */
245 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700246
Andrew Lee2423a2f2014-05-29 14:14:45 -0700247 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700248
Andrew Leee74a10e2014-05-16 14:31:40 -0700249 private class OptionsPopupMenu extends PopupMenu {
250 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700251 super(context, anchor);
252 }
253
254 @Override
255 public void show() {
256 final Menu menu = getMenu();
257 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700258 clearFrequents.setVisible(mListsFragment != null &&
259 mListsFragment.getSpeedDialFragment() != null &&
260 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700261 super.show();
262 }
263 }
264
Chiao Cheng94b10b52012-08-17 16:59:12 -0700265 /**
Yorke Lee28266192014-05-01 10:05:52 -0700266 * Listener that listens to drag events and sends their x and y coordinates to a
267 * {@link DragDropController}.
268 */
269 private class LayoutOnDragListener implements OnDragListener {
270 @Override
271 public boolean onDrag(View v, DragEvent event) {
272 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700273 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700274 }
275 return true;
276 }
277 }
278
279 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700280 * Listener used to send search queries to the phone search fragment.
281 */
Yorke Lee53a22302014-04-29 18:13:46 -0700282 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700283 @Override
284 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
285 }
Yorke Leec3766332013-07-31 11:13:16 -0700286
Andrew Lee99a570c2014-05-15 14:18:50 -0700287 @Override
288 public void onTextChanged(CharSequence s, int start, int before, int count) {
289 final String newText = s.toString();
290 if (newText.equals(mSearchQuery)) {
291 // If the query hasn't changed (perhaps due to activity being destroyed
292 // and restored, or user launching the same DIAL intent twice), then there is
293 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700294 return;
295 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700296 if (DEBUG) {
297 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700298 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700299 }
Yorke Lee710709d2014-05-29 07:18:42 -0700300 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700301
Andrew Lee90374a72014-05-16 15:01:09 -0700302 // Show search fragment only when the query string is changed to non-empty text.
303 if (!TextUtils.isEmpty(newText)) {
304 // Call enterSearchUi only if we are switching search modes, or showing a search
305 // fragment for the first time.
306 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
307 (!mIsDialpadShown && mInRegularSearch);
308 if (!sameSearchMode) {
309 enterSearchUi(mIsDialpadShown, mSearchQuery);
310 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700311 }
312
Andrew Leea8515422014-06-13 16:53:54 -0700313 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700314 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700315 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700316 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700317 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700318 }
319
320 @Override
321 public void afterTextChanged(Editable s) {
322 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700323 };
324
Andrew Leeb1903842014-05-15 16:11:24 -0700325
326 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700327 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700328 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700329 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700330 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700331 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700332 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700333 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700334 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
335 }
Andrew Leeb1903842014-05-15 16:11:24 -0700336 }
337 };
338
339 /**
340 * If the search term is empty and the user closes the soft keyboard, close the search UI.
341 */
342 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
343 @Override
344 public boolean onKey(View v, int keyCode, KeyEvent event) {
345 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
346 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700347 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700348 }
349 return false;
350 }
351 };
352
Chiao Cheng94b10b52012-08-17 16:59:12 -0700353 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700354 protected void onCreate(Bundle savedInstanceState) {
355 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700356 mFirstLaunch = true;
357
Andrew Lee2423a2f2014-05-29 14:14:45 -0700358 final Resources resources = getResources();
359 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700360 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
361 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700362
Yorke Lee8898cd02013-08-08 10:24:27 -0700363 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800364 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700365
Yorke Lee53a22302014-04-29 18:13:46 -0700366 final ActionBar actionBar = getActionBar();
367 actionBar.setCustomView(R.layout.search_edittext);
368 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700369 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700370
Yorke Lee5253be02014-05-21 18:50:03 -0700371 mActionBarController = new ActionBarController(this,
372 (SearchEditTextLayout) actionBar.getCustomView());
373
Yorke Lee53a22302014-04-29 18:13:46 -0700374
Andrew Lee04675a52014-06-05 18:36:20 -0700375 SearchEditTextLayout searchEditTextLayout =
376 (SearchEditTextLayout) actionBar.getCustomView();
377 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
378
379 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700380 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700381 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
382 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
383 .setOnClickListener(mSearchViewOnClickListener);
384 searchEditTextLayout.findViewById(R.id.search_box_start_search)
385 .setOnClickListener(mSearchViewOnClickListener);
386 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700387 @Override
388 public void onBackButtonClicked() {
389 onBackPressed();
390 }
391 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700392
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700393 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700394 == Configuration.ORIENTATION_LANDSCAPE;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700395 final View floatingActionButtonContainer = findViewById(
396 R.id.floating_action_button_container);
397 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
398 int floatingActionButtonWidth = resources.getDimensionPixelSize(
399 R.dimen.floating_action_button_width);
400 mFloatingActionButton.setOnClickListener(this);
401 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700402 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700403 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
404 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700405
Andrew Lee04675a52014-06-05 18:36:20 -0700406 ImageButton optionsMenuButton =
407 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700408 optionsMenuButton.setOnClickListener(this);
409 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
410 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
411
Yorke Leeef2b7382013-08-09 17:39:25 -0700412 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
413 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700414 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800415 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700416 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800417 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
418 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700419 } else {
420 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700421 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
422 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700423 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700424 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700425 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700426 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700427
428 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700429 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700430 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700431 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700432
433 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700434
Yorke Lee28aab272014-06-11 10:24:19 -0700435 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700436 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
437 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700438 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700439 new ViewTreeObserver.OnGlobalLayoutListener() {
440 @Override
441 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700442 final ViewTreeObserver observer = floatingActionButtonContainer
443 .getViewTreeObserver();
444 if (!observer.isAlive()) {
445 return;
446 }
447 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700448 int screenWidth = parentLayout.getWidth();
449 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700450 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700451 }
452 });
Andrew Lee0c667702014-05-12 14:31:45 -0700453
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700454 setupActivityOverlay();
455
Yorke Lee0baa98b2013-08-22 10:55:16 -0700456 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700457 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700458 }
459
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700460 private void setupActivityOverlay() {
461 final View activityOverlay = findViewById(R.id.activity_overlay);
462 activityOverlay.setOnTouchListener(new OnTouchListener() {
463 @Override
464 public boolean onTouch(View v, MotionEvent event) {
465 if (!mIsDialpadShown) {
466 maybeExitSearchUi();
467 }
468 return false;
469 }
470 });
471 }
472
Chiao Cheng94b10b52012-08-17 16:59:12 -0700473 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700474 protected void onResume() {
475 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700476 if (mFirstLaunch) {
477 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700478 } else if (!phoneIsInUse() && mInCallDialpadUp) {
479 hideDialpadFragment(false, true);
480 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700481 } else if (mShowDialpadOnResume) {
482 showDialpadFragment(false);
483 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700484 }
485 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700486 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700487 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700488 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700489 }
490
491 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700492 protected void onPause() {
493 if (mClearSearchOnPause) {
494 hideDialpadAndSearchUi();
495 mClearSearchOnPause = false;
496 }
497 super.onPause();
498 }
499
500 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700501 protected void onSaveInstanceState(Bundle outState) {
502 super.onSaveInstanceState(outState);
503 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700504 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
505 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700506 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700507 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700508 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700509 }
510
511 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700512 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700513 if (fragment instanceof DialpadFragment) {
514 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700515 if (!mShowDialpadOnResume) {
516 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
517 transaction.hide(mDialpadFragment);
518 transaction.commit();
519 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700520 } else if (fragment instanceof SmartDialSearchFragment) {
521 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700522 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700523 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700524 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700525 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700526 } else if (fragment instanceof ListsFragment) {
527 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700528 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700529 }
Yorke Leec3766332013-07-31 11:13:16 -0700530 }
531
Alon Albertb453e5b2013-09-10 15:54:23 -0700532 protected void handleMenuSettings() {
533 openTelephonySetting(this);
534 }
535
536 public static void openTelephonySetting(Activity activity) {
537 final Intent settingsIntent = getCallSettingsIntent();
538 activity.startActivity(settingsIntent);
539 }
540
Chiao Cheng94b10b52012-08-17 16:59:12 -0700541 @Override
542 public void onClick(View view) {
543 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700544 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700545 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700546 mInCallDialpadUp = false;
547 showDialpadFragment(true);
548 } else {
549 // Dial button was pressed; tell the Dialpad fragment
550 mDialpadFragment.dialButtonPressed();
551 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700552 break;
Yorke Leec3766332013-07-31 11:13:16 -0700553 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800554 try {
555 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
556 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
557 } catch (ActivityNotFoundException e) {
558 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
559 Toast.LENGTH_SHORT).show();
560 }
Yorke Leec3766332013-07-31 11:13:16 -0700561 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700562 case R.id.dialtacts_options_menu_button:
563 buildOptionsMenu(view).show();
564 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700565 default: {
566 Log.wtf(TAG, "Unexpected onClick event from " + view);
567 break;
568 }
569 }
570 }
571
Yorke Leec3766332013-07-31 11:13:16 -0700572 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700573 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700574 switch (item.getItemId()) {
575 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700576 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700577 break;
578 case R.id.menu_add_contact:
579 try {
580 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
581 } catch (ActivityNotFoundException e) {
582 Toast toast = Toast.makeText(this,
583 R.string.add_contact_not_available,
584 Toast.LENGTH_SHORT);
585 toast.show();
586 }
587 break;
588 case R.id.menu_import_export:
589 // We hard-code the "contactsAreAvailable" argument because doing it properly would
590 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
591 // now in Dialtacts for (potential) performance reasons. Compare with how it is
592 // done in {@link PeopleActivity}.
593 ImportExportDialogFragment.show(getFragmentManager(), true,
594 DialtactsActivity.class);
595 return true;
596 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700597 ClearFrequentsDialog.show(getFragmentManager());
598 return true;
599 case R.id.menu_call_settings:
600 handleMenuSettings();
601 return true;
Nancy Chenbeededb2014-06-10 18:30:28 -0700602 case R.id.menu_select_sim:
603 SelectSIMDialogFragment.show(getFragmentManager(), mCurrentSimCard);
604 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700605 }
606 return false;
607 }
608
609 @Override
Nancy Chenbeededb2014-06-10 18:30:28 -0700610 public void passSimUpdate(int simId) {
611 mCurrentSimCard = simId;
612 }
613
614 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700615 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
616 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
617 if (resultCode == RESULT_OK) {
618 final ArrayList<String> matches = data.getStringArrayListExtra(
619 RecognizerIntent.EXTRA_RESULTS);
620 if (matches.size() > 0) {
621 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700622 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700623 } else {
624 Log.e(TAG, "Voice search - nothing heard");
625 }
626 } else {
627 Log.e(TAG, "Voice search failed");
628 }
629 }
630 super.onActivityResult(requestCode, resultCode, data);
631 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700632
Andrew Lee2a58ab82014-05-15 02:16:04 -0700633 /**
634 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
635 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
636 * @see #onDialpadShown
637 */
Yorke Leec3766332013-07-31 11:13:16 -0700638 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700639 if (mIsDialpadShown) {
640 return;
641 }
642 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700643 mDialpadFragment.setAnimate(animate);
644
Chiao Cheng94b10b52012-08-17 16:59:12 -0700645 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700646 ft.show(mDialpadFragment);
647 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700648
Yorke Lee5253be02014-05-21 18:50:03 -0700649 mActionBarController.onDialpadUp();
650
Andrew Leeb1903842014-05-15 16:11:24 -0700651 if (!isInSearchUi()) {
652 enterSearchUi(true /* isSmartDial */, mSearchQuery);
653 }
Yorke Leec3766332013-07-31 11:13:16 -0700654 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700655
Andrew Lee2a58ab82014-05-15 02:16:04 -0700656 /**
657 * Callback from child DialpadFragment when the dialpad is shown.
658 */
659 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700660 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
661 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
662 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700663 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700664 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700665 } else {
666 mDialpadFragment.setYFraction(0);
667 }
668
Andrew Lee2a58ab82014-05-15 02:16:04 -0700669 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700670 }
671
672 /**
673 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
674 * a callback after the hide animation ends.
675 * @see #commitDialpadFragmentHide
676 */
Yorke Leeca195042013-09-25 16:29:38 -0700677 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700678 if (mDialpadFragment == null) {
679 return;
680 }
Yorke Leef6673d32013-08-23 15:34:17 -0700681 if (clearDialpad) {
682 mDialpadFragment.clearDialpad();
683 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700684 if (!mIsDialpadShown) {
685 return;
Yorke Leec3766332013-07-31 11:13:16 -0700686 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700687 mIsDialpadShown = false;
688 mDialpadFragment.setAnimate(animate);
689
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700690 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700691 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
692 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
693
694 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700695 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700696 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700697 } else {
698 commitDialpadFragmentHide();
699 }
700
Yorke Lee5253be02014-05-21 18:50:03 -0700701 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700702
Andrew Leed4cde832014-05-16 15:56:48 -0700703 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700704 if (TextUtils.isEmpty(mSearchQuery)) {
705 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700706 }
Andrew Leed4cde832014-05-16 15:56:48 -0700707 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700708 }
709
710 /**
711 * Finishes hiding the dialpad fragment after any animations are completed.
712 */
713 private void commitDialpadFragmentHide() {
714 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700715 ft.hide(mDialpadFragment);
716 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700717 }
718
Andrew Lee2a58ab82014-05-15 02:16:04 -0700719 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700720 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700721 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700722 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700723 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700724 fragment = mRegularSearchFragment;
725 }
726 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700727 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700728 }
729 }
730
Yorke Lee5253be02014-05-21 18:50:03 -0700731 @Override
732 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700733 return mInDialpadSearch || mInRegularSearch;
734 }
735
Yorke Lee5253be02014-05-21 18:50:03 -0700736 @Override
737 public boolean hasSearchQuery() {
738 return !TextUtils.isEmpty(mSearchQuery);
739 }
740
741 @Override
742 public boolean shouldShowActionBar() {
743 return mListsFragment.shouldShowActionBar();
744 }
745
Yorke Leeb207f8a2013-08-29 18:51:06 -0700746 private void setNotInSearchUi() {
747 mInDialpadSearch = false;
748 mInRegularSearch = false;
749 }
750
Yorke Lee311969c2013-08-26 06:31:11 -0700751 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700752 if (mIsDialpadShown) {
753 hideDialpadFragment(false, true);
754 } else {
755 exitSearchUi();
756 }
Yorke Lee311969c2013-08-26 06:31:11 -0700757 }
758
Yorke Leee00c9fe2014-04-12 12:42:06 -0700759 private void hideInputMethod(View view) {
760 final InputMethodManager imm = (InputMethodManager) getSystemService(
761 Context.INPUT_METHOD_SERVICE);
762 if (imm != null && view != null) {
763 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
764 }
765 }
766
Yorke Lee53a22302014-04-29 18:13:46 -0700767 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700768 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
769 if (canIntentBeHandled(voiceIntent)) {
770 mVoiceSearchButton.setVisibility(View.VISIBLE);
771 mVoiceSearchButton.setOnClickListener(this);
772 } else {
773 mVoiceSearchButton.setVisibility(View.GONE);
774 }
775 }
776
Andrew Leee74a10e2014-05-16 14:31:40 -0700777 private OptionsPopupMenu buildOptionsMenu(View invoker) {
778 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
779 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700780 final Menu menu = popupMenu.getMenu();
781 final MenuItem selectSim = menu.findItem(R.id.menu_select_sim);
782 selectSim.setVisible(mCurrentSimCard != NO_MULTI_SIM);
Andrew Leee74a10e2014-05-16 14:31:40 -0700783 popupMenu.setOnMenuItemClickListener(this);
784 return popupMenu;
785 }
786
Yorke Lee86e21f72014-04-02 16:49:38 -0700787 @Override
788 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700789 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700790 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700791 mPendingSearchViewQuery = null;
792 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700793 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700794 }
795
Chiao Cheng94b10b52012-08-17 16:59:12 -0700796 /**
797 * Returns true if the intent is due to hitting the green send key (hardware call button:
798 * KEYCODE_CALL) while in a call.
799 *
800 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700801 * @return true if the intent is due to hitting the green send key while in a call
802 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700803 private boolean isSendKeyWhileInCall(Intent intent) {
804 // If there is a call in progress and the user launched the dialer by hitting the call
805 // button, go straight to the in-call screen.
806 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700807
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700808 if (callKey) {
809 getTelephonyManager().showCallScreen();
810 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700811 }
812
813 return false;
814 }
815
816 /**
817 * Sets the current tab based on the intent's request type
818 *
819 * @param intent Intent that contains information about which tab should be selected
820 */
Yorke Leec3766332013-07-31 11:13:16 -0700821 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700822 // 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 -0700823 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700824 finish();
825 return;
826 }
827
Yorke Lee669b6082013-09-17 15:43:38 -0700828 if (mDialpadFragment != null) {
829 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700830 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700831 mDialpadFragment.setStartedFromNewIntent(true);
832 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
833 mInCallDialpadUp = true;
834 }
835 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700836 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700837 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700838 }
839
840 @Override
841 public void onNewIntent(Intent newIntent) {
842 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700843 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700844
Chiao Cheng94b10b52012-08-17 16:59:12 -0700845 invalidateOptionsMenu();
846 }
847
848 /** Returns true if the given intent contains a phone number to populate the dialer with */
849 private boolean isDialIntent(Intent intent) {
850 final String action = intent.getAction();
851 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
852 return true;
853 }
854 if (Intent.ACTION_VIEW.equals(action)) {
855 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700856 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700857 return true;
858 }
859 }
860 return false;
861 }
862
863 /**
864 * Returns an appropriate call origin for this Activity. May return null when no call origin
865 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
866 * for remembering the tab in which the user made a phone call, so the external app's DIAL
867 * request should not be counted.)
868 */
869 public String getCallOrigin() {
870 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
871 }
872
Chiao Cheng94b10b52012-08-17 16:59:12 -0700873 /**
Yorke Leec3766332013-07-31 11:13:16 -0700874 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700875 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700876 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700877 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700878 // Weird race condition where fragment is doing work after the activity is destroyed
879 // due to talkback being on (b/10209937). Just return since we can't do any
880 // constructive here.
881 return;
882 }
883
Yorke Leeef2b7382013-08-09 17:39:25 -0700884 if (DEBUG) {
885 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
886 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700887
Yorke Leec3766332013-07-31 11:13:16 -0700888 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700889 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700890 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700891 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700892 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700893 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700894
Yorke Leeb207f8a2013-08-29 18:51:06 -0700895 final String tag;
896 if (smartDialSearch) {
897 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
898 } else {
899 tag = TAG_REGULAR_SEARCH_FRAGMENT;
900 }
901 mInDialpadSearch = smartDialSearch;
902 mInRegularSearch = !smartDialSearch;
903
Andrew Lee752956e2014-05-15 11:43:38 -0700904 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700905 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700906 if (fragment == null) {
907 if (smartDialSearch) {
908 fragment = new SmartDialSearchFragment();
909 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700910 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700911 }
Andrew Leeb1903842014-05-15 16:11:24 -0700912 transaction.add(R.id.dialtacts_frame, fragment, tag);
913 } else {
914 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700915 }
Andrew Leeb1903842014-05-15 16:11:24 -0700916
Yorke Lee86e21f72014-04-02 16:49:38 -0700917 // DialtactsActivity will provide the options menu
918 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700919 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700920 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700921 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700922
923 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700924 }
925
926 /**
Yorke Leec3766332013-07-31 11:13:16 -0700927 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700928 */
Yorke Leec3766332013-07-31 11:13:16 -0700929 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700930 // See related bug in enterSearchUI();
931 if (getFragmentManager().isDestroyed()) {
932 return;
933 }
Andrew Leeb1903842014-05-15 16:11:24 -0700934
Andrew Leeb1903842014-05-15 16:11:24 -0700935 mSearchView.setText(null);
936 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700937 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700938
Andrew Leeb1903842014-05-15 16:11:24 -0700939 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700940 if (mSmartDialSearchFragment != null) {
941 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700942 }
Andrew Leeb1903842014-05-15 16:11:24 -0700943 if (mRegularSearchFragment != null) {
944 transaction.remove(mRegularSearchFragment);
945 }
946 transaction.commit();
947
948 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700949 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700950 }
951
952 /** Returns an Intent to launch Call Settings screen */
953 public static Intent getCallSettingsIntent() {
954 final Intent intent = new Intent(Intent.ACTION_MAIN);
955 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
956 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
957 return intent;
958 }
959
960 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700961 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700962 if (mIsDialpadShown) {
Andrew Leeb1903842014-05-15 16:11:24 -0700963 if (TextUtils.isEmpty(mSearchQuery)) {
964 exitSearchUi();
965 }
Yorke Leef6673d32013-08-23 15:34:17 -0700966 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700967 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700968 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700969 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700970 } else {
971 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700972 }
Yorke Leec3766332013-07-31 11:13:16 -0700973 }
974
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700975 /**
976 * @return True if the search UI was exited, false otherwise
977 */
978 private boolean maybeExitSearchUi() {
979 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
980 exitSearchUi();
981 hideInputMethod(parentLayout);
982 return true;
983 }
984 return false;
985 }
986
Yorke Leec3766332013-07-31 11:13:16 -0700987 @Override
988 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700989 if (mSmartDialSearchFragment != null) {
990 mSmartDialSearchFragment.setAddToContactNumber(query);
991 }
Yorke Leec3766332013-07-31 11:13:16 -0700992 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
993 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700994
995 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700996 if (DEBUG) {
997 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
998 }
999 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1000 // This callback can happen if the dialpad fragment is recreated because of
1001 // activity destruction. In that case, don't update the search view because
1002 // that would bring the user back to the search fragment regardless of the
1003 // previous state of the application. Instead, just return here and let the
1004 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001005 if (!TextUtils.isEmpty(normalizedQuery)) {
1006 mPendingSearchViewQuery = normalizedQuery;
1007 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001008 return;
1009 }
Yorke Lee53a22302014-04-29 18:13:46 -07001010 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001011 }
1012 }
Yorke Leec3766332013-07-31 11:13:16 -07001013
1014 @Override
1015 public void onListFragmentScrollStateChange(int scrollState) {
1016 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001017 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001018 hideInputMethod(getCurrentFocus());
1019 }
1020 }
1021
1022 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001023 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001024 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001025 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1026 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001027 }
1028
Yorke Lee86e21f72014-04-02 16:49:38 -07001029 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001030 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001031 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001032 }
1033
1034 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001035 // TODO(santoscordon): Replace with a TelecommService method call.
1036 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001037 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001038
Yorke Leee1424812013-09-04 18:24:48 -07001039 public static Intent getAddNumberToContactIntent(CharSequence text) {
1040 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1041 intent.putExtra(Intents.Insert.PHONE, text);
1042 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1043 return intent;
1044 }
1045
Yorke Leeda0f9042013-12-05 14:25:51 -08001046 private boolean canIntentBeHandled(Intent intent) {
1047 final PackageManager packageManager = getPackageManager();
1048 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1049 PackageManager.MATCH_DEFAULT_ONLY);
1050 return resolveInfo != null && resolveInfo.size() > 0;
1051 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001052
Yorke Lee6a1461a2014-04-21 16:27:14 -07001053 @Override
1054 public void showCallHistory() {
1055 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1056 // CONTENT_TYPE, so that we always open our call log from our dialer
1057 final Intent intent = new Intent(this, CallLogActivity.class);
1058 startActivity(intent);
1059 }
1060
Yorke Lee86e21f72014-04-02 16:49:38 -07001061 /**
1062 * Called when the user has long-pressed a contact tile to start a drag operation.
1063 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001064 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001065 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001066 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001067 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001068 }
Andrew Lee18963442014-06-06 17:20:13 -07001069 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001070 }
1071
1072 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001073 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1074 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001075
Yorke Lee86e21f72014-04-02 16:49:38 -07001076 /**
1077 * Called when the user has released a contact tile after long-pressing it.
1078 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001079 @Override
1080 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001081 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001082 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001083 }
Andrew Lee18963442014-06-06 17:20:13 -07001084 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001085 }
1086
1087 @Override
1088 public void onDroppedOnRemove() {}
1089
1090 /**
Yorke Leed999b712014-04-23 15:10:58 -07001091 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001092 * once it has been attached to the activity.
1093 */
1094 @Override
1095 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001096 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001097 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001098 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001099
1100 @Override
1101 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001102 // Specify call-origin so that users will see the previous tab instead of
1103 // CallLog screen (search UI will be automatically exited).
1104 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001105 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001106 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001107 }
1108
1109 @Override
1110 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001111 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1112 startActivity(intent);
1113 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001114 }
1115
1116 @Override
1117 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001118 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001119 }
1120
1121 @Override
1122 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001123 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001124 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001125
Yorke Leecc4660d2014-04-24 11:22:57 -07001126 @Override
1127 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001128 // Only scroll the button when the first tab is selected. The button should scroll from
1129 // the middle to right position only on the transition from the first tab to the second
1130 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001131 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001132 mFloatingActionButtonController.onPageScrolled(positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001133 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1134 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001135 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001136 }
1137
1138 @Override
1139 public void onPageSelected(int position) {
1140 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001141 }
1142
1143 @Override
1144 public void onPageScrollStateChanged(int state) {
1145 }
1146
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001147 private TelephonyManager getTelephonyManager() {
1148 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1149 }
1150
Yorke Lee5253be02014-05-21 18:50:03 -07001151 @Override
1152 public boolean isActionBarShowing() {
1153 return mActionBarController.isActionBarShowing();
1154 }
1155
Andrew Lee9da8fb42014-06-03 14:03:09 -07001156 public boolean isDialpadShown() {
1157 return mIsDialpadShown;
1158 }
1159
Yorke Lee5253be02014-05-21 18:50:03 -07001160 @Override
1161 public int getActionBarHideOffset() {
1162 return getActionBar().getHideOffset();
1163 }
1164
1165 @Override
1166 public int getActionBarHeight() {
1167 return mActionBarHeight;
1168 }
1169
1170 @Override
1171 public void setActionBarHideOffset(int hideOffset) {
1172 getActionBar().setHideOffset(hideOffset);
1173 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001174
1175 /**
1176 * Updates controller based on currently known information.
1177 *
1178 * @param animate Whether or not to animate the transition.
1179 */
1180 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1181 int align;
1182 if (mIsDialpadShown) {
1183 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1184 : FloatingActionButtonController.ALIGN_MIDDLE;
1185 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001186 if (!mIsLandscape) {
1187 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1188 ? FloatingActionButtonController.ALIGN_MIDDLE
1189 : FloatingActionButtonController.ALIGN_RIGHT;
1190 } else {
1191 align = FloatingActionButtonController.ALIGN_RIGHT;
1192 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001193 }
1194 mFloatingActionButtonController.align(align,
1195 0 /* offsetX */,
1196 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1197 animate);
1198 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001199}