blob: de68c8e1f792e21bba0d8d610e12ba61c30f697e [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;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080062import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070063
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070064import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070065import com.android.contacts.common.activity.TransactionSafeActivity;
Andrew Lee3c14bc32014-05-28 15:43:03 -070066import com.android.contacts.common.animation.AnimationListenerAdapter;
Yorke Leec3766332013-07-31 11:13:16 -070067import com.android.contacts.common.dialog.ClearFrequentsDialog;
Nancy Chenbeededb2014-06-10 18:30:28 -070068import com.android.contacts.common.dialog.SelectSIMDialogFragment;
Yorke Leec3766332013-07-31 11:13:16 -070069import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080070import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070071import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070072import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070073import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070074import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070075import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070076import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070077import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080078import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070079import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080080import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070081import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070082import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070083import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070084import com.android.dialer.list.RegularSearchFragment;
85import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070086import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee5253be02014-05-21 18:50:03 -070087import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070088import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070089import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070090import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070091
Yorke Leec3766332013-07-31 11:13:16 -070092import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080093import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070094
Chiao Cheng94b10b52012-08-17 16:59:12 -070095/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070096 * The dialer tab's title is 'phone', a more common name (see strings.xml).
97 */
Yorke Leec3766332013-07-31 11:13:16 -070098public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -070099 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700100 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800101 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700102 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700103 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700104 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700105 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700106 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700107 PopupMenu.OnMenuItemClickListener,
Nancy Chenbeededb2014-06-10 18:30:28 -0700108 SelectSIMDialogFragment.OnClickOkListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700109 ViewPager.OnPageChangeListener,
110 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700111 private static final String TAG = "DialtactsActivity";
112
Ihab Awad526c0b82014-02-27 12:55:36 -0800113 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700114
Yorke Leef74011e2013-08-02 11:30:30 -0700115 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
116
Chiao Cheng94b10b52012-08-17 16:59:12 -0700117 /** Used to open Call Setting */
118 private static final String PHONE_PACKAGE = "com.android.phone";
119 private static final String CALL_SETTINGS_CLASS_NAME =
120 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700121 /** @see #getCallOrigin() */
122 private static final String CALL_ORIGIN_DIALTACTS =
123 "com.android.dialer.DialtactsActivity";
124
Yorke Leeb207f8a2013-08-29 18:51:06 -0700125 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
126 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700127 private static final String KEY_SEARCH_QUERY = "search_query";
128 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700129 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700130
Yorke Leec3766332013-07-31 11:13:16 -0700131 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
132 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
133 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
134 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700135
Chiao Cheng94b10b52012-08-17 16:59:12 -0700136 /**
137 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
138 */
139 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
140
Yorke Leec3766332013-07-31 11:13:16 -0700141 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700142
Nancy Chenbeededb2014-06-10 18:30:28 -0700143 /**
144 * Constant to indicate there is only one service provider available.
145 */
146 private static final int NO_MULTI_SIM = -1;
147
Yorke Lee28aab272014-06-11 10:24:19 -0700148 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700149
Yorke Leec3766332013-07-31 11:13:16 -0700150 /**
Yorke Leec3766332013-07-31 11:13:16 -0700151 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700152 */
Yorke Leef74011e2013-08-02 11:30:30 -0700153 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700154
155 /**
156 * Fragment for searching phone numbers using the alphanumeric keyboard.
157 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700158 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700159
160 /**
161 * Fragment for searching phone numbers using the dialpad.
162 */
163 private SmartDialSearchFragment mSmartDialSearchFragment;
164
Yorke Leee00c9fe2014-04-12 12:42:06 -0700165 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700166 * Animation that slides in.
167 */
168 private Animation mSlideIn;
169
170 /**
171 * Animation that slides out.
172 */
173 private Animation mSlideOut;
174
175 /**
176 * Listener for after slide out animation completes on dialer fragment.
177 */
178 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
179 @Override
180 public void onAnimationEnd(Animation animation) {
181 commitDialpadFragmentHide();
182 }
183 };
184
185 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700186 * Fragment containing the speed dial list, recents list, and all contacts list.
187 */
188 private ListsFragment mListsFragment;
189
Yorke Leeb207f8a2013-08-29 18:51:06 -0700190 private boolean mInDialpadSearch;
191 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700192 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700193 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700194 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700195
Yorke Leeef2b7382013-08-09 17:39:25 -0700196 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700197 * Whether or not the device is in landscape orientation.
198 */
199 private boolean mIsLandscape;
200
201 /**
Nancy Chenbeededb2014-06-10 18:30:28 -0700202 * Information about the currently selected SIM card.
203 */
204 private int mCurrentSimCard = NO_MULTI_SIM;
205
206 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700207 * The position of the currently selected tab in the attached {@link ListsFragment}.
208 */
209 private int mCurrentTabPosition = 0;
210
211 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700212 * True if the dialpad is only temporarily showing due to being in call
213 */
214 private boolean mInCallDialpadUp;
215
216 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700217 * True when this activity has been launched for the first time.
218 */
Yorke Lee98702de2013-08-06 12:03:32 -0700219 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700220
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700221 /**
222 * Search query to be applied to the SearchView in the ActionBar once
223 * onCreateOptionsMenu has been called.
224 */
225 private String mPendingSearchViewQuery;
226
Yorke Lee53a22302014-04-29 18:13:46 -0700227 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700228 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700229
Yorke Leeef2b7382013-08-09 17:39:25 -0700230 private String mSearchQuery;
231
Yorke Leefce269a2013-08-12 11:56:04 -0700232 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700233 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700234 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700235
236 private String mDescriptionDialButtonStr;
237 private String mActionMenuDialpadButtonStr;
238 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700239 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700240 /**
241 * Additional offset for FAB to be lowered when dialpad is open.
242 */
243 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700244
Andrew Lee2423a2f2014-05-29 14:14:45 -0700245 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700246
Andrew Leee74a10e2014-05-16 14:31:40 -0700247 private class OptionsPopupMenu extends PopupMenu {
248 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700249 super(context, anchor);
250 }
251
252 @Override
253 public void show() {
254 final Menu menu = getMenu();
255 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700256 clearFrequents.setVisible(mListsFragment != null &&
257 mListsFragment.getSpeedDialFragment() != null &&
258 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700259 super.show();
260 }
261 }
262
Chiao Cheng94b10b52012-08-17 16:59:12 -0700263 /**
Yorke Lee28266192014-05-01 10:05:52 -0700264 * Listener that listens to drag events and sends their x and y coordinates to a
265 * {@link DragDropController}.
266 */
267 private class LayoutOnDragListener implements OnDragListener {
268 @Override
269 public boolean onDrag(View v, DragEvent event) {
270 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700271 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700272 }
273 return true;
274 }
275 }
276
277 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700278 * Listener used to send search queries to the phone search fragment.
279 */
Yorke Lee53a22302014-04-29 18:13:46 -0700280 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700281 @Override
282 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
283 }
Yorke Leec3766332013-07-31 11:13:16 -0700284
Andrew Lee99a570c2014-05-15 14:18:50 -0700285 @Override
286 public void onTextChanged(CharSequence s, int start, int before, int count) {
287 final String newText = s.toString();
288 if (newText.equals(mSearchQuery)) {
289 // If the query hasn't changed (perhaps due to activity being destroyed
290 // and restored, or user launching the same DIAL intent twice), then there is
291 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700292 return;
293 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700294 if (DEBUG) {
295 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700296 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700297 }
Yorke Lee710709d2014-05-29 07:18:42 -0700298 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700299
Andrew Lee90374a72014-05-16 15:01:09 -0700300 // Show search fragment only when the query string is changed to non-empty text.
301 if (!TextUtils.isEmpty(newText)) {
302 // Call enterSearchUi only if we are switching search modes, or showing a search
303 // fragment for the first time.
304 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
305 (!mIsDialpadShown && mInRegularSearch);
306 if (!sameSearchMode) {
307 enterSearchUi(mIsDialpadShown, mSearchQuery);
308 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700309 }
310
311 if (mIsDialpadShown && mSmartDialSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700312 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700313 } else if (mRegularSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700314 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700315 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700316 }
317
318 @Override
319 public void afterTextChanged(Editable s) {
320 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700321 };
322
Andrew Leeb1903842014-05-15 16:11:24 -0700323
324 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700325 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700326 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700327 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700328 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700329 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700330 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700331 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700332 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
333 }
Andrew Leeb1903842014-05-15 16:11:24 -0700334 }
335 };
336
337 /**
338 * If the search term is empty and the user closes the soft keyboard, close the search UI.
339 */
340 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
341 @Override
342 public boolean onKey(View v, int keyCode, KeyEvent event) {
343 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
344 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700345 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700346 }
347 return false;
348 }
349 };
350
Chiao Cheng94b10b52012-08-17 16:59:12 -0700351 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700352 protected void onCreate(Bundle savedInstanceState) {
353 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700354 mFirstLaunch = true;
355
Andrew Lee2423a2f2014-05-29 14:14:45 -0700356 final Resources resources = getResources();
357 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700358 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
359 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700360
Yorke Lee8898cd02013-08-08 10:24:27 -0700361 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800362 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700363
Yorke Lee53a22302014-04-29 18:13:46 -0700364 final ActionBar actionBar = getActionBar();
365 actionBar.setCustomView(R.layout.search_edittext);
366 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700367 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700368
Yorke Lee5253be02014-05-21 18:50:03 -0700369 mActionBarController = new ActionBarController(this,
370 (SearchEditTextLayout) actionBar.getCustomView());
371
Yorke Lee53a22302014-04-29 18:13:46 -0700372
Andrew Lee04675a52014-06-05 18:36:20 -0700373 SearchEditTextLayout searchEditTextLayout =
374 (SearchEditTextLayout) actionBar.getCustomView();
375 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
376
377 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700378 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700379 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
380 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
381 .setOnClickListener(mSearchViewOnClickListener);
382 searchEditTextLayout.findViewById(R.id.search_box_start_search)
383 .setOnClickListener(mSearchViewOnClickListener);
384 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700385 @Override
386 public void onBackButtonClicked() {
387 onBackPressed();
388 }
389 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700390
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700391 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700392 == Configuration.ORIENTATION_LANDSCAPE;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700393 final View floatingActionButtonContainer = findViewById(
394 R.id.floating_action_button_container);
395 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
396 int floatingActionButtonWidth = resources.getDimensionPixelSize(
397 R.dimen.floating_action_button_width);
398 mFloatingActionButton.setOnClickListener(this);
399 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700400 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700401 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
402 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700403
Andrew Lee04675a52014-06-05 18:36:20 -0700404 ImageButton optionsMenuButton =
405 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700406 optionsMenuButton.setOnClickListener(this);
407 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
408 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
409
Yorke Leeef2b7382013-08-09 17:39:25 -0700410 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
411 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700412 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800413 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700414 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800415 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
416 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700417 } else {
418 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700419 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
420 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700421 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700422 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700423 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700424 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700425
426 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700427 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700428 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700429 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700430
431 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700432
Yorke Lee28aab272014-06-11 10:24:19 -0700433 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700434 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
435 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700436 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700437 new ViewTreeObserver.OnGlobalLayoutListener() {
438 @Override
439 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700440 final ViewTreeObserver observer = floatingActionButtonContainer
441 .getViewTreeObserver();
442 if (!observer.isAlive()) {
443 return;
444 }
445 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700446 int screenWidth = parentLayout.getWidth();
447 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700448 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700449 }
450 });
Andrew Lee0c667702014-05-12 14:31:45 -0700451
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700452 setupActivityOverlay();
453
Yorke Lee0baa98b2013-08-22 10:55:16 -0700454 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700455 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700456 }
457
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700458 private void setupActivityOverlay() {
459 final View activityOverlay = findViewById(R.id.activity_overlay);
460 activityOverlay.setOnTouchListener(new OnTouchListener() {
461 @Override
462 public boolean onTouch(View v, MotionEvent event) {
463 if (!mIsDialpadShown) {
464 maybeExitSearchUi();
465 }
466 return false;
467 }
468 });
469 }
470
Chiao Cheng94b10b52012-08-17 16:59:12 -0700471 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700472 protected void onResume() {
473 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700474 if (mFirstLaunch) {
475 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700476 } else if (!phoneIsInUse() && mInCallDialpadUp) {
477 hideDialpadFragment(false, true);
478 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700479 } else if (mShowDialpadOnResume) {
480 showDialpadFragment(false);
481 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700482 }
483 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700484 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700485 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700486 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700487 }
488
489 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700490 protected void onPause() {
491 if (mClearSearchOnPause) {
492 hideDialpadAndSearchUi();
493 mClearSearchOnPause = false;
494 }
495 super.onPause();
496 }
497
498 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700499 protected void onSaveInstanceState(Bundle outState) {
500 super.onSaveInstanceState(outState);
501 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700502 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
503 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700504 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700505 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700506 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700507 }
508
509 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700510 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700511 if (fragment instanceof DialpadFragment) {
512 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700513 if (!mShowDialpadOnResume) {
514 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
515 transaction.hide(mDialpadFragment);
516 transaction.commit();
517 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700518 } else if (fragment instanceof SmartDialSearchFragment) {
519 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700520 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700521 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700522 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700523 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700524 } else if (fragment instanceof ListsFragment) {
525 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700526 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700527 }
Yorke Leec3766332013-07-31 11:13:16 -0700528 }
529
Alon Albertb453e5b2013-09-10 15:54:23 -0700530 protected void handleMenuSettings() {
531 openTelephonySetting(this);
532 }
533
534 public static void openTelephonySetting(Activity activity) {
535 final Intent settingsIntent = getCallSettingsIntent();
536 activity.startActivity(settingsIntent);
537 }
538
Chiao Cheng94b10b52012-08-17 16:59:12 -0700539 @Override
540 public void onClick(View view) {
541 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700542 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700543 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700544 mInCallDialpadUp = false;
545 showDialpadFragment(true);
546 } else {
547 // Dial button was pressed; tell the Dialpad fragment
548 mDialpadFragment.dialButtonPressed();
549 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700550 break;
Yorke Leec3766332013-07-31 11:13:16 -0700551 case R.id.search_close_button:
552 // Clear the search field
Yorke Lee53a22302014-04-29 18:13:46 -0700553 if (!TextUtils.isEmpty(mSearchView.getText())) {
Yorke Lee2eafb7a2013-09-10 14:34:01 -0700554 mDialpadFragment.clearDialpad();
Yorke Lee53a22302014-04-29 18:13:46 -0700555 mSearchView.setText(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700556 }
557 break;
Yorke Leec3766332013-07-31 11:13:16 -0700558 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800559 try {
560 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
561 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
562 } catch (ActivityNotFoundException e) {
563 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
564 Toast.LENGTH_SHORT).show();
565 }
Yorke Leec3766332013-07-31 11:13:16 -0700566 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700567 case R.id.dialtacts_options_menu_button:
568 buildOptionsMenu(view).show();
569 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700570 default: {
571 Log.wtf(TAG, "Unexpected onClick event from " + view);
572 break;
573 }
574 }
575 }
576
Yorke Leec3766332013-07-31 11:13:16 -0700577 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700578 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700579 switch (item.getItemId()) {
580 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700581 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700582 break;
583 case R.id.menu_add_contact:
584 try {
585 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
586 } catch (ActivityNotFoundException e) {
587 Toast toast = Toast.makeText(this,
588 R.string.add_contact_not_available,
589 Toast.LENGTH_SHORT);
590 toast.show();
591 }
592 break;
593 case R.id.menu_import_export:
594 // We hard-code the "contactsAreAvailable" argument because doing it properly would
595 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
596 // now in Dialtacts for (potential) performance reasons. Compare with how it is
597 // done in {@link PeopleActivity}.
598 ImportExportDialogFragment.show(getFragmentManager(), true,
599 DialtactsActivity.class);
600 return true;
601 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700602 ClearFrequentsDialog.show(getFragmentManager());
603 return true;
604 case R.id.menu_call_settings:
605 handleMenuSettings();
606 return true;
Nancy Chenbeededb2014-06-10 18:30:28 -0700607 case R.id.menu_select_sim:
608 SelectSIMDialogFragment.show(getFragmentManager(), mCurrentSimCard);
609 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700610 }
611 return false;
612 }
613
614 @Override
Nancy Chenbeededb2014-06-10 18:30:28 -0700615 public void passSimUpdate(int simId) {
616 mCurrentSimCard = simId;
617 }
618
619 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700620 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
621 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
622 if (resultCode == RESULT_OK) {
623 final ArrayList<String> matches = data.getStringArrayListExtra(
624 RecognizerIntent.EXTRA_RESULTS);
625 if (matches.size() > 0) {
626 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700627 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700628 } else {
629 Log.e(TAG, "Voice search - nothing heard");
630 }
631 } else {
632 Log.e(TAG, "Voice search failed");
633 }
634 }
635 super.onActivityResult(requestCode, resultCode, data);
636 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700637
Andrew Lee2a58ab82014-05-15 02:16:04 -0700638 /**
639 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
640 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
641 * @see #onDialpadShown
642 */
Yorke Leec3766332013-07-31 11:13:16 -0700643 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700644 if (mIsDialpadShown) {
645 return;
646 }
647 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700648 mDialpadFragment.setAnimate(animate);
649
Chiao Cheng94b10b52012-08-17 16:59:12 -0700650 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700651 ft.show(mDialpadFragment);
652 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700653
Yorke Lee5253be02014-05-21 18:50:03 -0700654 mActionBarController.onDialpadUp();
655
Andrew Leeb1903842014-05-15 16:11:24 -0700656 if (!isInSearchUi()) {
657 enterSearchUi(true /* isSmartDial */, mSearchQuery);
658 }
Yorke Leec3766332013-07-31 11:13:16 -0700659 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700660
Andrew Lee2a58ab82014-05-15 02:16:04 -0700661 /**
662 * Callback from child DialpadFragment when the dialpad is shown.
663 */
664 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700665 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
666 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
667 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700668 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700669 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700670 } else {
671 mDialpadFragment.setYFraction(0);
672 }
673
Andrew Lee2a58ab82014-05-15 02:16:04 -0700674 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700675 }
676
677 /**
678 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
679 * a callback after the hide animation ends.
680 * @see #commitDialpadFragmentHide
681 */
Yorke Leeca195042013-09-25 16:29:38 -0700682 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700683 if (mDialpadFragment == null) {
684 return;
685 }
Yorke Leef6673d32013-08-23 15:34:17 -0700686 if (clearDialpad) {
687 mDialpadFragment.clearDialpad();
688 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700689 if (!mIsDialpadShown) {
690 return;
Yorke Leec3766332013-07-31 11:13:16 -0700691 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700692 mIsDialpadShown = false;
693 mDialpadFragment.setAnimate(animate);
694
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700695 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700696 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
697 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
698
699 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700700 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700701 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700702 } else {
703 commitDialpadFragmentHide();
704 }
705
Yorke Lee5253be02014-05-21 18:50:03 -0700706 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700707
Andrew Leed4cde832014-05-16 15:56:48 -0700708 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700709 if (TextUtils.isEmpty(mSearchQuery)) {
710 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700711 }
Andrew Leed4cde832014-05-16 15:56:48 -0700712 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700713 }
714
715 /**
716 * Finishes hiding the dialpad fragment after any animations are completed.
717 */
718 private void commitDialpadFragmentHide() {
719 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700720 ft.hide(mDialpadFragment);
721 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700722 }
723
Andrew Lee2a58ab82014-05-15 02:16:04 -0700724 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700725 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700726 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700727 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700728 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700729 fragment = mRegularSearchFragment;
730 }
731 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700732 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700733 }
734 }
735
Yorke Lee5253be02014-05-21 18:50:03 -0700736 @Override
737 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700738 return mInDialpadSearch || mInRegularSearch;
739 }
740
Yorke Lee5253be02014-05-21 18:50:03 -0700741 @Override
742 public boolean hasSearchQuery() {
743 return !TextUtils.isEmpty(mSearchQuery);
744 }
745
746 @Override
747 public boolean shouldShowActionBar() {
748 return mListsFragment.shouldShowActionBar();
749 }
750
Yorke Leeb207f8a2013-08-29 18:51:06 -0700751 private void setNotInSearchUi() {
752 mInDialpadSearch = false;
753 mInRegularSearch = false;
754 }
755
Yorke Lee311969c2013-08-26 06:31:11 -0700756 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700757 if (mIsDialpadShown) {
758 hideDialpadFragment(false, true);
759 } else {
760 exitSearchUi();
761 }
Yorke Lee311969c2013-08-26 06:31:11 -0700762 }
763
Yorke Leee00c9fe2014-04-12 12:42:06 -0700764 private void hideInputMethod(View view) {
765 final InputMethodManager imm = (InputMethodManager) getSystemService(
766 Context.INPUT_METHOD_SERVICE);
767 if (imm != null && view != null) {
768 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
769 }
770 }
771
Yorke Lee53a22302014-04-29 18:13:46 -0700772 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700773 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
774 if (canIntentBeHandled(voiceIntent)) {
775 mVoiceSearchButton.setVisibility(View.VISIBLE);
776 mVoiceSearchButton.setOnClickListener(this);
777 } else {
778 mVoiceSearchButton.setVisibility(View.GONE);
779 }
780 }
781
Andrew Leee74a10e2014-05-16 14:31:40 -0700782 private OptionsPopupMenu buildOptionsMenu(View invoker) {
783 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
784 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700785 final Menu menu = popupMenu.getMenu();
786 final MenuItem selectSim = menu.findItem(R.id.menu_select_sim);
787 selectSim.setVisible(mCurrentSimCard != NO_MULTI_SIM);
Andrew Leee74a10e2014-05-16 14:31:40 -0700788 popupMenu.setOnMenuItemClickListener(this);
789 return popupMenu;
790 }
791
Yorke Lee86e21f72014-04-02 16:49:38 -0700792 @Override
793 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700794 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700795 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700796 mPendingSearchViewQuery = null;
797 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700798 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700799 }
800
Chiao Cheng94b10b52012-08-17 16:59:12 -0700801 /**
802 * Returns true if the intent is due to hitting the green send key (hardware call button:
803 * KEYCODE_CALL) while in a call.
804 *
805 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700806 * @return true if the intent is due to hitting the green send key while in a call
807 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700808 private boolean isSendKeyWhileInCall(Intent intent) {
809 // If there is a call in progress and the user launched the dialer by hitting the call
810 // button, go straight to the in-call screen.
811 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700812
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700813 if (callKey) {
814 getTelephonyManager().showCallScreen();
815 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700816 }
817
818 return false;
819 }
820
821 /**
822 * Sets the current tab based on the intent's request type
823 *
824 * @param intent Intent that contains information about which tab should be selected
825 */
Yorke Leec3766332013-07-31 11:13:16 -0700826 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700827 // 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 -0700828 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700829 finish();
830 return;
831 }
832
Yorke Lee669b6082013-09-17 15:43:38 -0700833 if (mDialpadFragment != null) {
834 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700835 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700836 mDialpadFragment.setStartedFromNewIntent(true);
837 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
838 mInCallDialpadUp = true;
839 }
840 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700841 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700842 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700843 }
844
845 @Override
846 public void onNewIntent(Intent newIntent) {
847 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700848 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700849
Chiao Cheng94b10b52012-08-17 16:59:12 -0700850 invalidateOptionsMenu();
851 }
852
853 /** Returns true if the given intent contains a phone number to populate the dialer with */
854 private boolean isDialIntent(Intent intent) {
855 final String action = intent.getAction();
856 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
857 return true;
858 }
859 if (Intent.ACTION_VIEW.equals(action)) {
860 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700861 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700862 return true;
863 }
864 }
865 return false;
866 }
867
868 /**
869 * Returns an appropriate call origin for this Activity. May return null when no call origin
870 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
871 * for remembering the tab in which the user made a phone call, so the external app's DIAL
872 * request should not be counted.)
873 */
874 public String getCallOrigin() {
875 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
876 }
877
Chiao Cheng94b10b52012-08-17 16:59:12 -0700878 /**
Yorke Leec3766332013-07-31 11:13:16 -0700879 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700880 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700881 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700882 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700883 // Weird race condition where fragment is doing work after the activity is destroyed
884 // due to talkback being on (b/10209937). Just return since we can't do any
885 // constructive here.
886 return;
887 }
888
Yorke Leeef2b7382013-08-09 17:39:25 -0700889 if (DEBUG) {
890 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
891 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700892
Yorke Leec3766332013-07-31 11:13:16 -0700893 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700894 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700895 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700896 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700897 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700898 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700899
Yorke Leeb207f8a2013-08-29 18:51:06 -0700900 final String tag;
901 if (smartDialSearch) {
902 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
903 } else {
904 tag = TAG_REGULAR_SEARCH_FRAGMENT;
905 }
906 mInDialpadSearch = smartDialSearch;
907 mInRegularSearch = !smartDialSearch;
908
Andrew Lee752956e2014-05-15 11:43:38 -0700909 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700910 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700911 if (fragment == null) {
912 if (smartDialSearch) {
913 fragment = new SmartDialSearchFragment();
914 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700915 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700916 }
Andrew Leeb1903842014-05-15 16:11:24 -0700917 transaction.add(R.id.dialtacts_frame, fragment, tag);
918 } else {
919 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700920 }
Andrew Leeb1903842014-05-15 16:11:24 -0700921
Yorke Lee86e21f72014-04-02 16:49:38 -0700922 // DialtactsActivity will provide the options menu
923 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700924 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700925 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700926 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700927
928 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700929 }
930
931 /**
Yorke Leec3766332013-07-31 11:13:16 -0700932 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700933 */
Yorke Leec3766332013-07-31 11:13:16 -0700934 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700935 // See related bug in enterSearchUI();
936 if (getFragmentManager().isDestroyed()) {
937 return;
938 }
Andrew Leeb1903842014-05-15 16:11:24 -0700939
Andrew Leeb1903842014-05-15 16:11:24 -0700940 mSearchView.setText(null);
941 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700942 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700943
Andrew Leeb1903842014-05-15 16:11:24 -0700944 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700945 if (mSmartDialSearchFragment != null) {
946 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700947 }
Andrew Leeb1903842014-05-15 16:11:24 -0700948 if (mRegularSearchFragment != null) {
949 transaction.remove(mRegularSearchFragment);
950 }
951 transaction.commit();
952
953 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700954 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700955 }
956
957 /** Returns an Intent to launch Call Settings screen */
958 public static Intent getCallSettingsIntent() {
959 final Intent intent = new Intent(Intent.ACTION_MAIN);
960 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
961 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
962 return intent;
963 }
964
965 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700966 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700967 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700968 if (TextUtils.isEmpty(mSearchQuery) ||
969 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
970 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700971 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);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001140 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1141 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001142 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001143 }
1144
1145 @Override
1146 public void onPageSelected(int position) {
1147 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001148 }
1149
1150 @Override
1151 public void onPageScrollStateChanged(int state) {
1152 }
1153
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001154 private TelephonyManager getTelephonyManager() {
1155 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1156 }
1157
Yorke Lee5253be02014-05-21 18:50:03 -07001158 @Override
1159 public boolean isActionBarShowing() {
1160 return mActionBarController.isActionBarShowing();
1161 }
1162
Andrew Lee9da8fb42014-06-03 14:03:09 -07001163 public boolean isDialpadShown() {
1164 return mIsDialpadShown;
1165 }
1166
Yorke Lee5253be02014-05-21 18:50:03 -07001167 @Override
1168 public int getActionBarHideOffset() {
1169 return getActionBar().getHideOffset();
1170 }
1171
1172 @Override
1173 public int getActionBarHeight() {
1174 return mActionBarHeight;
1175 }
1176
1177 @Override
1178 public void setActionBarHideOffset(int hideOffset) {
1179 getActionBar().setHideOffset(hideOffset);
1180 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001181
1182 /**
1183 * Updates controller based on currently known information.
1184 *
1185 * @param animate Whether or not to animate the transition.
1186 */
1187 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1188 int align;
1189 if (mIsDialpadShown) {
1190 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1191 : FloatingActionButtonController.ALIGN_MIDDLE;
1192 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001193 if (!mIsLandscape) {
1194 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1195 ? FloatingActionButtonController.ALIGN_MIDDLE
1196 : FloatingActionButtonController.ALIGN_RIGHT;
1197 } else {
1198 align = FloatingActionButtonController.ALIGN_RIGHT;
1199 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001200 }
1201 mFloatingActionButtonController.align(align,
1202 0 /* offsetX */,
1203 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1204 animate);
1205 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001206}