blob: 6144bb5af2fe3a6a62eae4d1bba11d1e63c8e8ef [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;
Nancy Chen4c924562014-06-11 15:31:16 -0700612 if (mIsDialpadShown) {
613 mDialpadFragment.setSimCard(simId);
614 }
Nancy Chenbeededb2014-06-10 18:30:28 -0700615 }
616
617 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700618 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
619 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
620 if (resultCode == RESULT_OK) {
621 final ArrayList<String> matches = data.getStringArrayListExtra(
622 RecognizerIntent.EXTRA_RESULTS);
623 if (matches.size() > 0) {
624 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700625 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700626 } else {
627 Log.e(TAG, "Voice search - nothing heard");
628 }
629 } else {
630 Log.e(TAG, "Voice search failed");
631 }
632 }
633 super.onActivityResult(requestCode, resultCode, data);
634 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700635
Andrew Lee2a58ab82014-05-15 02:16:04 -0700636 /**
637 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
638 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
639 * @see #onDialpadShown
640 */
Yorke Leec3766332013-07-31 11:13:16 -0700641 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700642 if (mIsDialpadShown) {
643 return;
644 }
645 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700646 mDialpadFragment.setAnimate(animate);
Nancy Chen4c924562014-06-11 15:31:16 -0700647 mDialpadFragment.setSimCard(mCurrentSimCard);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700648
Chiao Cheng94b10b52012-08-17 16:59:12 -0700649 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700650 ft.show(mDialpadFragment);
651 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700652
Yorke Lee5253be02014-05-21 18:50:03 -0700653 mActionBarController.onDialpadUp();
654
Andrew Leeb1903842014-05-15 16:11:24 -0700655 if (!isInSearchUi()) {
656 enterSearchUi(true /* isSmartDial */, mSearchQuery);
657 }
Yorke Leec3766332013-07-31 11:13:16 -0700658 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700659
Andrew Lee2a58ab82014-05-15 02:16:04 -0700660 /**
661 * Callback from child DialpadFragment when the dialpad is shown.
662 */
663 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700664 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
665 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
666 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700667 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700668 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700669 } else {
670 mDialpadFragment.setYFraction(0);
671 }
672
Andrew Lee2a58ab82014-05-15 02:16:04 -0700673 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700674 }
675
676 /**
677 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
678 * a callback after the hide animation ends.
679 * @see #commitDialpadFragmentHide
680 */
Yorke Leeca195042013-09-25 16:29:38 -0700681 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700682 if (mDialpadFragment == null) {
683 return;
684 }
Yorke Leef6673d32013-08-23 15:34:17 -0700685 if (clearDialpad) {
686 mDialpadFragment.clearDialpad();
687 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700688 if (!mIsDialpadShown) {
689 return;
Yorke Leec3766332013-07-31 11:13:16 -0700690 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700691 mIsDialpadShown = false;
692 mDialpadFragment.setAnimate(animate);
693
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700694 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700695 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
696 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
697
698 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700699 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700700 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700701 } else {
702 commitDialpadFragmentHide();
703 }
704
Yorke Lee5253be02014-05-21 18:50:03 -0700705 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700706
Andrew Leed4cde832014-05-16 15:56:48 -0700707 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700708 if (TextUtils.isEmpty(mSearchQuery)) {
709 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700710 }
Andrew Leed4cde832014-05-16 15:56:48 -0700711 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700712 }
713
714 /**
715 * Finishes hiding the dialpad fragment after any animations are completed.
716 */
717 private void commitDialpadFragmentHide() {
718 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700719 ft.hide(mDialpadFragment);
720 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700721 }
722
Andrew Lee2a58ab82014-05-15 02:16:04 -0700723 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700724 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700725 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700726 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700727 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700728 fragment = mRegularSearchFragment;
729 }
730 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700731 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700732 }
733 }
734
Yorke Lee5253be02014-05-21 18:50:03 -0700735 @Override
736 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700737 return mInDialpadSearch || mInRegularSearch;
738 }
739
Yorke Lee5253be02014-05-21 18:50:03 -0700740 @Override
741 public boolean hasSearchQuery() {
742 return !TextUtils.isEmpty(mSearchQuery);
743 }
744
745 @Override
746 public boolean shouldShowActionBar() {
747 return mListsFragment.shouldShowActionBar();
748 }
749
Yorke Leeb207f8a2013-08-29 18:51:06 -0700750 private void setNotInSearchUi() {
751 mInDialpadSearch = false;
752 mInRegularSearch = false;
753 }
754
Yorke Lee311969c2013-08-26 06:31:11 -0700755 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700756 if (mIsDialpadShown) {
757 hideDialpadFragment(false, true);
758 } else {
759 exitSearchUi();
760 }
Yorke Lee311969c2013-08-26 06:31:11 -0700761 }
762
Yorke Leee00c9fe2014-04-12 12:42:06 -0700763 private void hideInputMethod(View view) {
764 final InputMethodManager imm = (InputMethodManager) getSystemService(
765 Context.INPUT_METHOD_SERVICE);
766 if (imm != null && view != null) {
767 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
768 }
769 }
770
Yorke Lee53a22302014-04-29 18:13:46 -0700771 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700772 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
773 if (canIntentBeHandled(voiceIntent)) {
774 mVoiceSearchButton.setVisibility(View.VISIBLE);
775 mVoiceSearchButton.setOnClickListener(this);
776 } else {
777 mVoiceSearchButton.setVisibility(View.GONE);
778 }
779 }
780
Andrew Leee74a10e2014-05-16 14:31:40 -0700781 private OptionsPopupMenu buildOptionsMenu(View invoker) {
782 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
783 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700784 final Menu menu = popupMenu.getMenu();
785 final MenuItem selectSim = menu.findItem(R.id.menu_select_sim);
786 selectSim.setVisible(mCurrentSimCard != NO_MULTI_SIM);
Andrew Leee74a10e2014-05-16 14:31:40 -0700787 popupMenu.setOnMenuItemClickListener(this);
788 return popupMenu;
789 }
790
Yorke Lee86e21f72014-04-02 16:49:38 -0700791 @Override
792 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700793 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700794 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700795 mPendingSearchViewQuery = null;
796 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700797 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700798 }
799
Chiao Cheng94b10b52012-08-17 16:59:12 -0700800 /**
801 * Returns true if the intent is due to hitting the green send key (hardware call button:
802 * KEYCODE_CALL) while in a call.
803 *
804 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700805 * @return true if the intent is due to hitting the green send key while in a call
806 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700807 private boolean isSendKeyWhileInCall(Intent intent) {
808 // If there is a call in progress and the user launched the dialer by hitting the call
809 // button, go straight to the in-call screen.
810 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700811
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700812 if (callKey) {
813 getTelephonyManager().showCallScreen();
814 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700815 }
816
817 return false;
818 }
819
820 /**
821 * Sets the current tab based on the intent's request type
822 *
823 * @param intent Intent that contains information about which tab should be selected
824 */
Yorke Leec3766332013-07-31 11:13:16 -0700825 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700826 // 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 -0700827 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700828 finish();
829 return;
830 }
831
Yorke Lee669b6082013-09-17 15:43:38 -0700832 if (mDialpadFragment != null) {
833 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700834 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700835 mDialpadFragment.setStartedFromNewIntent(true);
836 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
837 mInCallDialpadUp = true;
838 }
839 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700840 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700841 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700842 }
843
844 @Override
845 public void onNewIntent(Intent newIntent) {
846 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700847 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700848
Chiao Cheng94b10b52012-08-17 16:59:12 -0700849 invalidateOptionsMenu();
850 }
851
852 /** Returns true if the given intent contains a phone number to populate the dialer with */
853 private boolean isDialIntent(Intent intent) {
854 final String action = intent.getAction();
855 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
856 return true;
857 }
858 if (Intent.ACTION_VIEW.equals(action)) {
859 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700860 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700861 return true;
862 }
863 }
864 return false;
865 }
866
867 /**
868 * Returns an appropriate call origin for this Activity. May return null when no call origin
869 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
870 * for remembering the tab in which the user made a phone call, so the external app's DIAL
871 * request should not be counted.)
872 */
873 public String getCallOrigin() {
874 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
875 }
876
Chiao Cheng94b10b52012-08-17 16:59:12 -0700877 /**
Yorke Leec3766332013-07-31 11:13:16 -0700878 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700879 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700880 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700881 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700882 // Weird race condition where fragment is doing work after the activity is destroyed
883 // due to talkback being on (b/10209937). Just return since we can't do any
884 // constructive here.
885 return;
886 }
887
Yorke Leeef2b7382013-08-09 17:39:25 -0700888 if (DEBUG) {
889 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
890 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700891
Yorke Leec3766332013-07-31 11:13:16 -0700892 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700893 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700894 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700895 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700896 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700897 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700898
Yorke Leeb207f8a2013-08-29 18:51:06 -0700899 final String tag;
900 if (smartDialSearch) {
901 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
902 } else {
903 tag = TAG_REGULAR_SEARCH_FRAGMENT;
904 }
905 mInDialpadSearch = smartDialSearch;
906 mInRegularSearch = !smartDialSearch;
907
Andrew Lee752956e2014-05-15 11:43:38 -0700908 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700909 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700910 if (fragment == null) {
911 if (smartDialSearch) {
912 fragment = new SmartDialSearchFragment();
913 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700914 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700915 }
Andrew Leeb1903842014-05-15 16:11:24 -0700916 transaction.add(R.id.dialtacts_frame, fragment, tag);
917 } else {
918 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700919 }
Andrew Leeb1903842014-05-15 16:11:24 -0700920
Yorke Lee86e21f72014-04-02 16:49:38 -0700921 // DialtactsActivity will provide the options menu
922 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700923 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700924 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700925 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700926
927 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700928 }
929
930 /**
Yorke Leec3766332013-07-31 11:13:16 -0700931 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700932 */
Yorke Leec3766332013-07-31 11:13:16 -0700933 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700934 // See related bug in enterSearchUI();
935 if (getFragmentManager().isDestroyed()) {
936 return;
937 }
Andrew Leeb1903842014-05-15 16:11:24 -0700938
Andrew Leeb1903842014-05-15 16:11:24 -0700939 mSearchView.setText(null);
940 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700941 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700942
Andrew Leeb1903842014-05-15 16:11:24 -0700943 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700944 if (mSmartDialSearchFragment != null) {
945 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700946 }
Andrew Leeb1903842014-05-15 16:11:24 -0700947 if (mRegularSearchFragment != null) {
948 transaction.remove(mRegularSearchFragment);
949 }
950 transaction.commit();
951
952 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700953 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700954 }
955
956 /** Returns an Intent to launch Call Settings screen */
957 public static Intent getCallSettingsIntent() {
958 final Intent intent = new Intent(Intent.ACTION_MAIN);
959 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
960 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
961 return intent;
962 }
963
964 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700965 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700966 if (mIsDialpadShown) {
Andrew Leeb1903842014-05-15 16:11:24 -0700967 if (TextUtils.isEmpty(mSearchQuery)) {
968 exitSearchUi();
969 }
Yorke Leef6673d32013-08-23 15:34:17 -0700970 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700971 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700972 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700973 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700974 } else {
975 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700976 }
Yorke Leec3766332013-07-31 11:13:16 -0700977 }
978
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700979 /**
980 * @return True if the search UI was exited, false otherwise
981 */
982 private boolean maybeExitSearchUi() {
983 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
984 exitSearchUi();
985 hideInputMethod(parentLayout);
986 return true;
987 }
988 return false;
989 }
990
Yorke Leec3766332013-07-31 11:13:16 -0700991 @Override
992 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700993 if (mSmartDialSearchFragment != null) {
994 mSmartDialSearchFragment.setAddToContactNumber(query);
995 }
Yorke Leec3766332013-07-31 11:13:16 -0700996 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
997 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700998
999 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001000 if (DEBUG) {
1001 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1002 }
1003 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1004 // This callback can happen if the dialpad fragment is recreated because of
1005 // activity destruction. In that case, don't update the search view because
1006 // that would bring the user back to the search fragment regardless of the
1007 // previous state of the application. Instead, just return here and let the
1008 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001009 if (!TextUtils.isEmpty(normalizedQuery)) {
1010 mPendingSearchViewQuery = normalizedQuery;
1011 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001012 return;
1013 }
Yorke Lee53a22302014-04-29 18:13:46 -07001014 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001015 }
1016 }
Yorke Leec3766332013-07-31 11:13:16 -07001017
1018 @Override
1019 public void onListFragmentScrollStateChange(int scrollState) {
1020 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001021 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001022 hideInputMethod(getCurrentFocus());
1023 }
1024 }
1025
1026 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001027 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001028 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001029 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1030 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001031 }
1032
Yorke Lee86e21f72014-04-02 16:49:38 -07001033 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001034 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001035 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001036 }
1037
1038 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001039 // TODO(santoscordon): Replace with a TelecommService method call.
1040 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001041 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001042
Yorke Leee1424812013-09-04 18:24:48 -07001043 public static Intent getAddNumberToContactIntent(CharSequence text) {
1044 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1045 intent.putExtra(Intents.Insert.PHONE, text);
1046 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1047 return intent;
1048 }
1049
Yorke Leeda0f9042013-12-05 14:25:51 -08001050 private boolean canIntentBeHandled(Intent intent) {
1051 final PackageManager packageManager = getPackageManager();
1052 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1053 PackageManager.MATCH_DEFAULT_ONLY);
1054 return resolveInfo != null && resolveInfo.size() > 0;
1055 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001056
Yorke Lee6a1461a2014-04-21 16:27:14 -07001057 @Override
1058 public void showCallHistory() {
1059 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1060 // CONTENT_TYPE, so that we always open our call log from our dialer
1061 final Intent intent = new Intent(this, CallLogActivity.class);
1062 startActivity(intent);
1063 }
1064
Yorke Lee86e21f72014-04-02 16:49:38 -07001065 /**
1066 * Called when the user has long-pressed a contact tile to start a drag operation.
1067 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001068 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001069 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001070 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001071 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001072 }
Andrew Lee18963442014-06-06 17:20:13 -07001073 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001074 }
1075
1076 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001077 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1078 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001079
Yorke Lee86e21f72014-04-02 16:49:38 -07001080 /**
1081 * Called when the user has released a contact tile after long-pressing it.
1082 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001083 @Override
1084 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001085 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001086 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001087 }
Andrew Lee18963442014-06-06 17:20:13 -07001088 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001089 }
1090
1091 @Override
1092 public void onDroppedOnRemove() {}
1093
1094 /**
Yorke Leed999b712014-04-23 15:10:58 -07001095 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001096 * once it has been attached to the activity.
1097 */
1098 @Override
1099 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001100 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001101 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001102 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001103
1104 @Override
1105 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001106 // Specify call-origin so that users will see the previous tab instead of
1107 // CallLog screen (search UI will be automatically exited).
1108 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001109 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001110 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001111 }
1112
1113 @Override
1114 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001115 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1116 startActivity(intent);
1117 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001118 }
1119
1120 @Override
1121 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001122 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001123 }
1124
1125 @Override
1126 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001127 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001128 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001129
Yorke Leecc4660d2014-04-24 11:22:57 -07001130 @Override
1131 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001132 // Only scroll the button when the first tab is selected. The button should scroll from
1133 // the middle to right position only on the transition from the first tab to the second
1134 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001135 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001136 mFloatingActionButtonController.onPageScrolled(positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001137 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1138 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001139 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001140 }
1141
1142 @Override
1143 public void onPageSelected(int position) {
1144 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001145 }
1146
1147 @Override
1148 public void onPageScrollStateChanged(int state) {
1149 }
1150
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001151 private TelephonyManager getTelephonyManager() {
1152 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1153 }
1154
Yorke Lee5253be02014-05-21 18:50:03 -07001155 @Override
1156 public boolean isActionBarShowing() {
1157 return mActionBarController.isActionBarShowing();
1158 }
1159
Andrew Lee9da8fb42014-06-03 14:03:09 -07001160 public boolean isDialpadShown() {
1161 return mIsDialpadShown;
1162 }
1163
Yorke Lee5253be02014-05-21 18:50:03 -07001164 @Override
1165 public int getActionBarHideOffset() {
1166 return getActionBar().getHideOffset();
1167 }
1168
1169 @Override
1170 public int getActionBarHeight() {
1171 return mActionBarHeight;
1172 }
1173
1174 @Override
1175 public void setActionBarHideOffset(int hideOffset) {
1176 getActionBar().setHideOffset(hideOffset);
1177 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001178
1179 /**
1180 * Updates controller based on currently known information.
1181 *
1182 * @param animate Whether or not to animate the transition.
1183 */
1184 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1185 int align;
1186 if (mIsDialpadShown) {
1187 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1188 : FloatingActionButtonController.ALIGN_MIDDLE;
1189 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001190 if (!mIsLandscape) {
1191 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1192 ? FloatingActionButtonController.ALIGN_MIDDLE
1193 : FloatingActionButtonController.ALIGN_RIGHT;
1194 } else {
1195 align = FloatingActionButtonController.ALIGN_RIGHT;
1196 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001197 }
1198 mFloatingActionButtonController.align(align,
1199 0 /* offsetX */,
1200 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1201 animate);
1202 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001203}