blob: a9eb217792386a576033735ea2e71c0bf1330f9b [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
313 if (mIsDialpadShown && mSmartDialSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700314 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700315 } else if (mRegularSearchFragment != null) {
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.search_close_button:
554 // Clear the search field
Yorke Lee53a22302014-04-29 18:13:46 -0700555 if (!TextUtils.isEmpty(mSearchView.getText())) {
Yorke Lee2eafb7a2013-09-10 14:34:01 -0700556 mDialpadFragment.clearDialpad();
Yorke Lee53a22302014-04-29 18:13:46 -0700557 mSearchView.setText(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700558 }
559 break;
Yorke Leec3766332013-07-31 11:13:16 -0700560 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800561 try {
562 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
563 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
564 } catch (ActivityNotFoundException e) {
565 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
566 Toast.LENGTH_SHORT).show();
567 }
Yorke Leec3766332013-07-31 11:13:16 -0700568 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700569 case R.id.dialtacts_options_menu_button:
570 buildOptionsMenu(view).show();
571 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700572 default: {
573 Log.wtf(TAG, "Unexpected onClick event from " + view);
574 break;
575 }
576 }
577 }
578
Yorke Leec3766332013-07-31 11:13:16 -0700579 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700580 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700581 switch (item.getItemId()) {
582 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700583 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700584 break;
585 case R.id.menu_add_contact:
586 try {
587 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
588 } catch (ActivityNotFoundException e) {
589 Toast toast = Toast.makeText(this,
590 R.string.add_contact_not_available,
591 Toast.LENGTH_SHORT);
592 toast.show();
593 }
594 break;
595 case R.id.menu_import_export:
596 // We hard-code the "contactsAreAvailable" argument because doing it properly would
597 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
598 // now in Dialtacts for (potential) performance reasons. Compare with how it is
599 // done in {@link PeopleActivity}.
600 ImportExportDialogFragment.show(getFragmentManager(), true,
601 DialtactsActivity.class);
602 return true;
603 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700604 ClearFrequentsDialog.show(getFragmentManager());
605 return true;
606 case R.id.menu_call_settings:
607 handleMenuSettings();
608 return true;
Nancy Chenbeededb2014-06-10 18:30:28 -0700609 case R.id.menu_select_sim:
610 SelectSIMDialogFragment.show(getFragmentManager(), mCurrentSimCard);
611 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700612 }
613 return false;
614 }
615
616 @Override
Nancy Chenbeededb2014-06-10 18:30:28 -0700617 public void passSimUpdate(int simId) {
618 mCurrentSimCard = simId;
619 }
620
621 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700622 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
623 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
624 if (resultCode == RESULT_OK) {
625 final ArrayList<String> matches = data.getStringArrayListExtra(
626 RecognizerIntent.EXTRA_RESULTS);
627 if (matches.size() > 0) {
628 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700629 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700630 } else {
631 Log.e(TAG, "Voice search - nothing heard");
632 }
633 } else {
634 Log.e(TAG, "Voice search failed");
635 }
636 }
637 super.onActivityResult(requestCode, resultCode, data);
638 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700639
Andrew Lee2a58ab82014-05-15 02:16:04 -0700640 /**
641 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
642 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
643 * @see #onDialpadShown
644 */
Yorke Leec3766332013-07-31 11:13:16 -0700645 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700646 if (mIsDialpadShown) {
647 return;
648 }
649 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700650 mDialpadFragment.setAnimate(animate);
651
Chiao Cheng94b10b52012-08-17 16:59:12 -0700652 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700653 ft.show(mDialpadFragment);
654 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700655
Yorke Lee5253be02014-05-21 18:50:03 -0700656 mActionBarController.onDialpadUp();
657
Andrew Leeb1903842014-05-15 16:11:24 -0700658 if (!isInSearchUi()) {
659 enterSearchUi(true /* isSmartDial */, mSearchQuery);
660 }
Yorke Leec3766332013-07-31 11:13:16 -0700661 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700662
Andrew Lee2a58ab82014-05-15 02:16:04 -0700663 /**
664 * Callback from child DialpadFragment when the dialpad is shown.
665 */
666 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700667 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
668 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
669 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700670 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700671 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700672 } else {
673 mDialpadFragment.setYFraction(0);
674 }
675
Andrew Lee2a58ab82014-05-15 02:16:04 -0700676 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700677 }
678
679 /**
680 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
681 * a callback after the hide animation ends.
682 * @see #commitDialpadFragmentHide
683 */
Yorke Leeca195042013-09-25 16:29:38 -0700684 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700685 if (mDialpadFragment == null) {
686 return;
687 }
Yorke Leef6673d32013-08-23 15:34:17 -0700688 if (clearDialpad) {
689 mDialpadFragment.clearDialpad();
690 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700691 if (!mIsDialpadShown) {
692 return;
Yorke Leec3766332013-07-31 11:13:16 -0700693 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700694 mIsDialpadShown = false;
695 mDialpadFragment.setAnimate(animate);
696
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700697 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700698 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
699 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
700
701 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700702 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700703 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700704 } else {
705 commitDialpadFragmentHide();
706 }
707
Yorke Lee5253be02014-05-21 18:50:03 -0700708 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700709
Andrew Leed4cde832014-05-16 15:56:48 -0700710 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700711 if (TextUtils.isEmpty(mSearchQuery)) {
712 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700713 }
Andrew Leed4cde832014-05-16 15:56:48 -0700714 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700715 }
716
717 /**
718 * Finishes hiding the dialpad fragment after any animations are completed.
719 */
720 private void commitDialpadFragmentHide() {
721 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700722 ft.hide(mDialpadFragment);
723 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700724 }
725
Andrew Lee2a58ab82014-05-15 02:16:04 -0700726 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700727 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700728 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700729 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700730 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700731 fragment = mRegularSearchFragment;
732 }
733 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700734 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700735 }
736 }
737
Yorke Lee5253be02014-05-21 18:50:03 -0700738 @Override
739 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700740 return mInDialpadSearch || mInRegularSearch;
741 }
742
Yorke Lee5253be02014-05-21 18:50:03 -0700743 @Override
744 public boolean hasSearchQuery() {
745 return !TextUtils.isEmpty(mSearchQuery);
746 }
747
748 @Override
749 public boolean shouldShowActionBar() {
750 return mListsFragment.shouldShowActionBar();
751 }
752
Yorke Leeb207f8a2013-08-29 18:51:06 -0700753 private void setNotInSearchUi() {
754 mInDialpadSearch = false;
755 mInRegularSearch = false;
756 }
757
Yorke Lee311969c2013-08-26 06:31:11 -0700758 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700759 if (mIsDialpadShown) {
760 hideDialpadFragment(false, true);
761 } else {
762 exitSearchUi();
763 }
Yorke Lee311969c2013-08-26 06:31:11 -0700764 }
765
Yorke Leee00c9fe2014-04-12 12:42:06 -0700766 private void hideInputMethod(View view) {
767 final InputMethodManager imm = (InputMethodManager) getSystemService(
768 Context.INPUT_METHOD_SERVICE);
769 if (imm != null && view != null) {
770 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
771 }
772 }
773
Yorke Lee53a22302014-04-29 18:13:46 -0700774 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700775 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
776 if (canIntentBeHandled(voiceIntent)) {
777 mVoiceSearchButton.setVisibility(View.VISIBLE);
778 mVoiceSearchButton.setOnClickListener(this);
779 } else {
780 mVoiceSearchButton.setVisibility(View.GONE);
781 }
782 }
783
Andrew Leee74a10e2014-05-16 14:31:40 -0700784 private OptionsPopupMenu buildOptionsMenu(View invoker) {
785 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
786 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700787 final Menu menu = popupMenu.getMenu();
788 final MenuItem selectSim = menu.findItem(R.id.menu_select_sim);
789 selectSim.setVisible(mCurrentSimCard != NO_MULTI_SIM);
Andrew Leee74a10e2014-05-16 14:31:40 -0700790 popupMenu.setOnMenuItemClickListener(this);
791 return popupMenu;
792 }
793
Yorke Lee86e21f72014-04-02 16:49:38 -0700794 @Override
795 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700796 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700797 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700798 mPendingSearchViewQuery = null;
799 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700800 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700801 }
802
Chiao Cheng94b10b52012-08-17 16:59:12 -0700803 /**
804 * Returns true if the intent is due to hitting the green send key (hardware call button:
805 * KEYCODE_CALL) while in a call.
806 *
807 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700808 * @return true if the intent is due to hitting the green send key while in a call
809 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700810 private boolean isSendKeyWhileInCall(Intent intent) {
811 // If there is a call in progress and the user launched the dialer by hitting the call
812 // button, go straight to the in-call screen.
813 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700814
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700815 if (callKey) {
816 getTelephonyManager().showCallScreen();
817 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700818 }
819
820 return false;
821 }
822
823 /**
824 * Sets the current tab based on the intent's request type
825 *
826 * @param intent Intent that contains information about which tab should be selected
827 */
Yorke Leec3766332013-07-31 11:13:16 -0700828 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700829 // 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 -0700830 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700831 finish();
832 return;
833 }
834
Yorke Lee669b6082013-09-17 15:43:38 -0700835 if (mDialpadFragment != null) {
836 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700837 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700838 mDialpadFragment.setStartedFromNewIntent(true);
839 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
840 mInCallDialpadUp = true;
841 }
842 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700843 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700844 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700845 }
846
847 @Override
848 public void onNewIntent(Intent newIntent) {
849 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700850 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700851
Chiao Cheng94b10b52012-08-17 16:59:12 -0700852 invalidateOptionsMenu();
853 }
854
855 /** Returns true if the given intent contains a phone number to populate the dialer with */
856 private boolean isDialIntent(Intent intent) {
857 final String action = intent.getAction();
858 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
859 return true;
860 }
861 if (Intent.ACTION_VIEW.equals(action)) {
862 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700863 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700864 return true;
865 }
866 }
867 return false;
868 }
869
870 /**
871 * Returns an appropriate call origin for this Activity. May return null when no call origin
872 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
873 * for remembering the tab in which the user made a phone call, so the external app's DIAL
874 * request should not be counted.)
875 */
876 public String getCallOrigin() {
877 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
878 }
879
Chiao Cheng94b10b52012-08-17 16:59:12 -0700880 /**
Yorke Leec3766332013-07-31 11:13:16 -0700881 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700882 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700883 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700884 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700885 // Weird race condition where fragment is doing work after the activity is destroyed
886 // due to talkback being on (b/10209937). Just return since we can't do any
887 // constructive here.
888 return;
889 }
890
Yorke Leeef2b7382013-08-09 17:39:25 -0700891 if (DEBUG) {
892 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
893 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700894
Yorke Leec3766332013-07-31 11:13:16 -0700895 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700896 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700897 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700898 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700899 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700900 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700901
Yorke Leeb207f8a2013-08-29 18:51:06 -0700902 final String tag;
903 if (smartDialSearch) {
904 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
905 } else {
906 tag = TAG_REGULAR_SEARCH_FRAGMENT;
907 }
908 mInDialpadSearch = smartDialSearch;
909 mInRegularSearch = !smartDialSearch;
910
Andrew Lee752956e2014-05-15 11:43:38 -0700911 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700912 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700913 if (fragment == null) {
914 if (smartDialSearch) {
915 fragment = new SmartDialSearchFragment();
916 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700917 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700918 }
Andrew Leeb1903842014-05-15 16:11:24 -0700919 transaction.add(R.id.dialtacts_frame, fragment, tag);
920 } else {
921 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700922 }
Andrew Leeb1903842014-05-15 16:11:24 -0700923
Yorke Lee86e21f72014-04-02 16:49:38 -0700924 // DialtactsActivity will provide the options menu
925 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700926 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700927 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700928 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700929
930 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700931 }
932
933 /**
Yorke Leec3766332013-07-31 11:13:16 -0700934 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700935 */
Yorke Leec3766332013-07-31 11:13:16 -0700936 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700937 // See related bug in enterSearchUI();
938 if (getFragmentManager().isDestroyed()) {
939 return;
940 }
Andrew Leeb1903842014-05-15 16:11:24 -0700941
Andrew Leeb1903842014-05-15 16:11:24 -0700942 mSearchView.setText(null);
943 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700944 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700945
Andrew Leeb1903842014-05-15 16:11:24 -0700946 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700947 if (mSmartDialSearchFragment != null) {
948 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700949 }
Andrew Leeb1903842014-05-15 16:11:24 -0700950 if (mRegularSearchFragment != null) {
951 transaction.remove(mRegularSearchFragment);
952 }
953 transaction.commit();
954
955 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700956 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700957 }
958
959 /** Returns an Intent to launch Call Settings screen */
960 public static Intent getCallSettingsIntent() {
961 final Intent intent = new Intent(Intent.ACTION_MAIN);
962 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
963 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
964 return intent;
965 }
966
967 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700968 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700969 if (mIsDialpadShown) {
Andrew Leeb1903842014-05-15 16:11:24 -0700970 if (TextUtils.isEmpty(mSearchQuery)) {
971 exitSearchUi();
972 }
Yorke Leef6673d32013-08-23 15:34:17 -0700973 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700974 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700975 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700976 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700977 } else {
978 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700979 }
Yorke Leec3766332013-07-31 11:13:16 -0700980 }
981
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700982 /**
983 * @return True if the search UI was exited, false otherwise
984 */
985 private boolean maybeExitSearchUi() {
986 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
987 exitSearchUi();
988 hideInputMethod(parentLayout);
989 return true;
990 }
991 return false;
992 }
993
Yorke Leec3766332013-07-31 11:13:16 -0700994 @Override
995 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700996 if (mSmartDialSearchFragment != null) {
997 mSmartDialSearchFragment.setAddToContactNumber(query);
998 }
Yorke Leec3766332013-07-31 11:13:16 -0700999 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
1000 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -07001001
1002 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001003 if (DEBUG) {
1004 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1005 }
1006 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1007 // This callback can happen if the dialpad fragment is recreated because of
1008 // activity destruction. In that case, don't update the search view because
1009 // that would bring the user back to the search fragment regardless of the
1010 // previous state of the application. Instead, just return here and let the
1011 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001012 if (!TextUtils.isEmpty(normalizedQuery)) {
1013 mPendingSearchViewQuery = normalizedQuery;
1014 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001015 return;
1016 }
Yorke Lee53a22302014-04-29 18:13:46 -07001017 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001018 }
1019 }
Yorke Leec3766332013-07-31 11:13:16 -07001020
1021 @Override
1022 public void onListFragmentScrollStateChange(int scrollState) {
1023 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001024 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001025 hideInputMethod(getCurrentFocus());
1026 }
1027 }
1028
1029 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001030 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001031 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001032 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1033 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001034 }
1035
Yorke Lee86e21f72014-04-02 16:49:38 -07001036 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001037 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001038 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001039 }
1040
1041 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001042 // TODO(santoscordon): Replace with a TelecommService method call.
1043 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001044 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001045
Yorke Leee1424812013-09-04 18:24:48 -07001046 public static Intent getAddNumberToContactIntent(CharSequence text) {
1047 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1048 intent.putExtra(Intents.Insert.PHONE, text);
1049 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1050 return intent;
1051 }
1052
Yorke Leeda0f9042013-12-05 14:25:51 -08001053 private boolean canIntentBeHandled(Intent intent) {
1054 final PackageManager packageManager = getPackageManager();
1055 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1056 PackageManager.MATCH_DEFAULT_ONLY);
1057 return resolveInfo != null && resolveInfo.size() > 0;
1058 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001059
Yorke Lee6a1461a2014-04-21 16:27:14 -07001060 @Override
1061 public void showCallHistory() {
1062 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1063 // CONTENT_TYPE, so that we always open our call log from our dialer
1064 final Intent intent = new Intent(this, CallLogActivity.class);
1065 startActivity(intent);
1066 }
1067
Yorke Lee86e21f72014-04-02 16:49:38 -07001068 /**
1069 * Called when the user has long-pressed a contact tile to start a drag operation.
1070 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001071 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001072 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001073 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001074 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001075 }
Andrew Lee18963442014-06-06 17:20:13 -07001076 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001077 }
1078
1079 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001080 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1081 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001082
Yorke Lee86e21f72014-04-02 16:49:38 -07001083 /**
1084 * Called when the user has released a contact tile after long-pressing it.
1085 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001086 @Override
1087 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001088 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001089 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001090 }
Andrew Lee18963442014-06-06 17:20:13 -07001091 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001092 }
1093
1094 @Override
1095 public void onDroppedOnRemove() {}
1096
1097 /**
Yorke Leed999b712014-04-23 15:10:58 -07001098 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001099 * once it has been attached to the activity.
1100 */
1101 @Override
1102 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001103 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001104 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001105 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001106
1107 @Override
1108 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001109 // Specify call-origin so that users will see the previous tab instead of
1110 // CallLog screen (search UI will be automatically exited).
1111 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001112 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001113 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001114 }
1115
1116 @Override
1117 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001118 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1119 startActivity(intent);
1120 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001121 }
1122
1123 @Override
1124 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001125 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001126 }
1127
1128 @Override
1129 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001130 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001131 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001132
Yorke Leecc4660d2014-04-24 11:22:57 -07001133 @Override
1134 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001135 // Only scroll the button when the first tab is selected. The button should scroll from
1136 // the middle to right position only on the transition from the first tab to the second
1137 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001138 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001139 mFloatingActionButtonController.onPageScrolled(positionOffset);
1140 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001141 }
1142
1143 @Override
1144 public void onPageSelected(int position) {
1145 mCurrentTabPosition = position;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001146 // Prevents jittery movement when clicking on tabs.
1147 if (mCurrentTabPosition != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1148 mFloatingActionButtonController.manuallyTranslate(
1149 mFloatingActionButtonController.getTranslationXForAlignment(
1150 FloatingActionButtonController.ALIGN_RIGHT), 0);
1151 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001152 }
1153
1154 @Override
1155 public void onPageScrollStateChanged(int state) {
1156 }
1157
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001158 private TelephonyManager getTelephonyManager() {
1159 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1160 }
1161
Yorke Lee5253be02014-05-21 18:50:03 -07001162 @Override
1163 public boolean isActionBarShowing() {
1164 return mActionBarController.isActionBarShowing();
1165 }
1166
Andrew Lee9da8fb42014-06-03 14:03:09 -07001167 public boolean isDialpadShown() {
1168 return mIsDialpadShown;
1169 }
1170
Yorke Lee5253be02014-05-21 18:50:03 -07001171 @Override
1172 public int getActionBarHideOffset() {
1173 return getActionBar().getHideOffset();
1174 }
1175
1176 @Override
1177 public int getActionBarHeight() {
1178 return mActionBarHeight;
1179 }
1180
1181 @Override
1182 public void setActionBarHideOffset(int hideOffset) {
1183 getActionBar().setHideOffset(hideOffset);
1184 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001185
1186 /**
1187 * Updates controller based on currently known information.
1188 *
1189 * @param animate Whether or not to animate the transition.
1190 */
1191 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1192 int align;
1193 if (mIsDialpadShown) {
1194 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1195 : FloatingActionButtonController.ALIGN_MIDDLE;
1196 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001197 if (!mIsLandscape) {
1198 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1199 ? FloatingActionButtonController.ALIGN_MIDDLE
1200 : FloatingActionButtonController.ALIGN_RIGHT;
1201 } else {
1202 align = FloatingActionButtonController.ALIGN_RIGHT;
1203 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001204 }
1205 mFloatingActionButtonController.align(align,
1206 0 /* offsetX */,
1207 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1208 animate);
1209 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001210}