blob: 53e438d6de6cc45badd31d57f8d09d364a9a02ad [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;
Yorke Lee86e21f72014-04-02 16:49:38 -070054import android.view.animation.AccelerateInterpolator;
Andrew Lee2a58ab82014-05-15 02:16:04 -070055import android.view.animation.Animation;
56import android.view.animation.Animation.AnimationListener;
57import android.view.animation.AnimationUtils;
Yorke Lee86e21f72014-04-02 16:49:38 -070058import android.view.animation.DecelerateInterpolator;
59import android.view.animation.Interpolator;
Chiao Cheng94b10b52012-08-17 16:59:12 -070060import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070061import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070062import android.widget.EditText;
Andrew Leea73e1892014-05-13 13:21:16 -070063import android.widget.ImageButton;
Andrew Lee04675a52014-06-05 18:36:20 -070064import android.widget.ImageView;
Chiao Cheng94b10b52012-08-17 16:59:12 -070065import android.widget.PopupMenu;
Yorke Leecc4660d2014-04-24 11:22:57 -070066import android.widget.RelativeLayout;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080067import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070068
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070069import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070070import com.android.contacts.common.activity.TransactionSafeActivity;
Andrew Lee3c14bc32014-05-28 15:43:03 -070071import com.android.contacts.common.animation.AnimationListenerAdapter;
Yorke Leec3766332013-07-31 11:13:16 -070072import com.android.contacts.common.dialog.ClearFrequentsDialog;
73import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080074import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Andrew Lee4cbc9732014-04-24 14:38:58 -070075import com.android.contacts.common.util.ViewUtil;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070076import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070077import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070078import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070079import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070080import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070081import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070082import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080083import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070084import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080085import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070086import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070087import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070088import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070089import com.android.dialer.list.RegularSearchFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080090import com.android.dialer.list.RemoveView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070091import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070092import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee5253be02014-05-21 18:50:03 -070093import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070094import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070095import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070096import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070097
Yorke Leec3766332013-07-31 11:13:16 -070098import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080099import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -0700100
Chiao Cheng94b10b52012-08-17 16:59:12 -0700101/**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700102 * The dialer tab's title is 'phone', a more common name (see strings.xml).
103 */
Yorke Leec3766332013-07-31 11:13:16 -0700104public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700105 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700106 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800107 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700108 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700109 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700110 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700111 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700112 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700113 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700114 ViewPager.OnPageChangeListener,
115 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700116 private static final String TAG = "DialtactsActivity";
117
Ihab Awad526c0b82014-02-27 12:55:36 -0800118 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700119
Yorke Leef74011e2013-08-02 11:30:30 -0700120 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
121
Chiao Cheng94b10b52012-08-17 16:59:12 -0700122 /** Used to open Call Setting */
123 private static final String PHONE_PACKAGE = "com.android.phone";
124 private static final String CALL_SETTINGS_CLASS_NAME =
125 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700126 /** @see #getCallOrigin() */
127 private static final String CALL_ORIGIN_DIALTACTS =
128 "com.android.dialer.DialtactsActivity";
129
Yorke Leeb207f8a2013-08-29 18:51:06 -0700130 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
131 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700132 private static final String KEY_SEARCH_QUERY = "search_query";
133 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700134 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700135
Yorke Leec3766332013-07-31 11:13:16 -0700136 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
137 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
138 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
139 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700140
Chiao Cheng94b10b52012-08-17 16:59:12 -0700141 /**
142 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
143 */
144 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
145
Yorke Leec3766332013-07-31 11:13:16 -0700146 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700147
Andrew Lee0c667702014-05-12 14:31:45 -0700148 private RelativeLayout parentLayout;
149
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 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700202 * The position of the currently selected tab in the attached {@link ListsFragment}.
203 */
204 private int mCurrentTabPosition = 0;
205
206 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700207 * True if the dialpad is only temporarily showing due to being in call
208 */
209 private boolean mInCallDialpadUp;
210
211 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700212 * True when this activity has been launched for the first time.
213 */
Yorke Lee98702de2013-08-06 12:03:32 -0700214 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700215
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700216 /**
217 * Search query to be applied to the SearchView in the ActionBar once
218 * onCreateOptionsMenu has been called.
219 */
220 private String mPendingSearchViewQuery;
221
Yorke Lee53a22302014-04-29 18:13:46 -0700222 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700223 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700224
Yorke Lee86e21f72014-04-02 16:49:38 -0700225 /**
226 * View that contains the "Remove" dialog that shows up when the user long presses a contact.
227 * If the user releases a contact when hovering on top of this, the contact is unfavorited and
228 * removed from the speed dial list.
229 */
Yorke Lee28266192014-05-01 10:05:52 -0700230 private View mRemoveViewContainer;
Chiao Cheng94b10b52012-08-17 16:59:12 -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) {
273 mDragDropController.handleDragHovered(v, (int) event.getX(),
274 (int) event.getY());
275 }
276 return true;
277 }
278 }
279
280 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700281 * Listener used to send search queries to the phone search fragment.
282 */
Yorke Lee53a22302014-04-29 18:13:46 -0700283 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700284 @Override
285 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
286 }
Yorke Leec3766332013-07-31 11:13:16 -0700287
Andrew Lee99a570c2014-05-15 14:18:50 -0700288 @Override
289 public void onTextChanged(CharSequence s, int start, int before, int count) {
290 final String newText = s.toString();
291 if (newText.equals(mSearchQuery)) {
292 // If the query hasn't changed (perhaps due to activity being destroyed
293 // and restored, or user launching the same DIAL intent twice), then there is
294 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700295 return;
296 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700297 if (DEBUG) {
298 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700299 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700300 }
Yorke Lee710709d2014-05-29 07:18:42 -0700301 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700302
Andrew Lee90374a72014-05-16 15:01:09 -0700303 // Show search fragment only when the query string is changed to non-empty text.
304 if (!TextUtils.isEmpty(newText)) {
305 // Call enterSearchUi only if we are switching search modes, or showing a search
306 // fragment for the first time.
307 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
308 (!mIsDialpadShown && mInRegularSearch);
309 if (!sameSearchMode) {
310 enterSearchUi(mIsDialpadShown, mSearchQuery);
311 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700312 }
313
314 if (mIsDialpadShown && mSmartDialSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700315 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700316 } else if (mRegularSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700317 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700318 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700319 }
320
321 @Override
322 public void afterTextChanged(Editable s) {
323 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700324 };
325
Andrew Leeb1903842014-05-15 16:11:24 -0700326
327 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700328 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700329 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700330 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700331 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700332 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700333 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700334 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700335 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
336 }
Andrew Leeb1903842014-05-15 16:11:24 -0700337 }
338 };
339
340 /**
341 * If the search term is empty and the user closes the soft keyboard, close the search UI.
342 */
343 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
344 @Override
345 public boolean onKey(View v, int keyCode, KeyEvent event) {
346 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
347 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700348 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700349 }
350 return false;
351 }
352 };
353
Chiao Cheng94b10b52012-08-17 16:59:12 -0700354 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700355 protected void onCreate(Bundle savedInstanceState) {
356 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700357 mFirstLaunch = true;
358
Andrew Lee2423a2f2014-05-29 14:14:45 -0700359 final Resources resources = getResources();
360 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700361 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
362 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700363
Yorke Lee8898cd02013-08-08 10:24:27 -0700364 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800365 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700366
Yorke Lee53a22302014-04-29 18:13:46 -0700367 final ActionBar actionBar = getActionBar();
368 actionBar.setCustomView(R.layout.search_edittext);
369 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700370 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700371
Yorke Lee5253be02014-05-21 18:50:03 -0700372 mActionBarController = new ActionBarController(this,
373 (SearchEditTextLayout) actionBar.getCustomView());
374
Yorke Lee53a22302014-04-29 18:13:46 -0700375
Andrew Lee04675a52014-06-05 18:36:20 -0700376 SearchEditTextLayout searchEditTextLayout =
377 (SearchEditTextLayout) actionBar.getCustomView();
378 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
379
380 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700381 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700382 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
383 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
384 .setOnClickListener(mSearchViewOnClickListener);
385 searchEditTextLayout.findViewById(R.id.search_box_start_search)
386 .setOnClickListener(mSearchViewOnClickListener);
387 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700388 @Override
389 public void onBackButtonClicked() {
390 onBackPressed();
391 }
392 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700393
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700394 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700395 == Configuration.ORIENTATION_LANDSCAPE;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700396 final View floatingActionButtonContainer = findViewById(
397 R.id.floating_action_button_container);
398 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
399 int floatingActionButtonWidth = resources.getDimensionPixelSize(
400 R.dimen.floating_action_button_width);
401 mFloatingActionButton.setOnClickListener(this);
402 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700403 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700404 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
405 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700406
Andrew Lee04675a52014-06-05 18:36:20 -0700407 ImageButton optionsMenuButton =
408 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700409 optionsMenuButton.setOnClickListener(this);
410 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
411 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
412
Yorke Leeef2b7382013-08-09 17:39:25 -0700413 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
414 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700415 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800416 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700417 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800418 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
419 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700420 } else {
421 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700422 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
423 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700424 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700425 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700426 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700427 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700428
429 mSlideIn = AnimationUtils.loadAnimation(this,
430 mIsLandscape ? R.anim.slide_in_right : R.anim.slide_in);
431 mSlideOut = AnimationUtils.loadAnimation(this,
432 mIsLandscape ? R.anim.slide_out_right : R.anim.slide_out);
433
434 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700435
Andrew Lee0c667702014-05-12 14:31:45 -0700436 parentLayout = (RelativeLayout) findViewById(R.id.dialtacts_mainlayout);
437 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
438 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700439 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700440 new ViewTreeObserver.OnGlobalLayoutListener() {
441 @Override
442 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700443 final ViewTreeObserver observer = floatingActionButtonContainer
444 .getViewTreeObserver();
445 if (!observer.isAlive()) {
446 return;
447 }
448 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700449 int screenWidth = parentLayout.getWidth();
450 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700451 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700452 }
453 });
Andrew Lee0c667702014-05-12 14:31:45 -0700454
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700455 setupActivityOverlay();
456
Yorke Lee28266192014-05-01 10:05:52 -0700457 mRemoveViewContainer = findViewById(R.id.remove_view_container);
Yorke Leeb0d19762014-03-05 14:43:28 -0800458
Yorke Lee0baa98b2013-08-22 10:55:16 -0700459 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700460 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700461 }
462
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700463 private void setupActivityOverlay() {
464 final View activityOverlay = findViewById(R.id.activity_overlay);
465 activityOverlay.setOnTouchListener(new OnTouchListener() {
466 @Override
467 public boolean onTouch(View v, MotionEvent event) {
468 if (!mIsDialpadShown) {
469 maybeExitSearchUi();
470 }
471 return false;
472 }
473 });
474 }
475
Chiao Cheng94b10b52012-08-17 16:59:12 -0700476 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700477 protected void onResume() {
478 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700479 if (mFirstLaunch) {
480 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700481 } else if (!phoneIsInUse() && mInCallDialpadUp) {
482 hideDialpadFragment(false, true);
483 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700484 } else if (mShowDialpadOnResume) {
485 showDialpadFragment(false);
486 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700487 }
488 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700489 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700490 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700491 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700492 }
493
494 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700495 protected void onPause() {
496 if (mClearSearchOnPause) {
497 hideDialpadAndSearchUi();
498 mClearSearchOnPause = false;
499 }
500 super.onPause();
501 }
502
503 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700504 protected void onSaveInstanceState(Bundle outState) {
505 super.onSaveInstanceState(outState);
506 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700507 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
508 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700509 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700510 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700511 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700512 }
513
514 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700515 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700516 if (fragment instanceof DialpadFragment) {
517 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700518 if (!mShowDialpadOnResume) {
519 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
520 transaction.hide(mDialpadFragment);
521 transaction.commit();
522 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700523 } else if (fragment instanceof SmartDialSearchFragment) {
524 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700525 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700526 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700527 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700528 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700529 } else if (fragment instanceof ListsFragment) {
530 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700531 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700532 }
Yorke Leec3766332013-07-31 11:13:16 -0700533 }
534
Alon Albertb453e5b2013-09-10 15:54:23 -0700535 protected void handleMenuSettings() {
536 openTelephonySetting(this);
537 }
538
539 public static void openTelephonySetting(Activity activity) {
540 final Intent settingsIntent = getCallSettingsIntent();
541 activity.startActivity(settingsIntent);
542 }
543
Chiao Cheng94b10b52012-08-17 16:59:12 -0700544 @Override
545 public void onClick(View view) {
546 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700547 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700548 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700549 mInCallDialpadUp = false;
550 showDialpadFragment(true);
551 } else {
552 // Dial button was pressed; tell the Dialpad fragment
553 mDialpadFragment.dialButtonPressed();
554 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700555 break;
Yorke Leec3766332013-07-31 11:13:16 -0700556 case R.id.search_close_button:
557 // Clear the search field
Yorke Lee53a22302014-04-29 18:13:46 -0700558 if (!TextUtils.isEmpty(mSearchView.getText())) {
Yorke Lee2eafb7a2013-09-10 14:34:01 -0700559 mDialpadFragment.clearDialpad();
Yorke Lee53a22302014-04-29 18:13:46 -0700560 mSearchView.setText(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700561 }
562 break;
Yorke Leec3766332013-07-31 11:13:16 -0700563 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800564 try {
565 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
566 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
567 } catch (ActivityNotFoundException e) {
568 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
569 Toast.LENGTH_SHORT).show();
570 }
Yorke Leec3766332013-07-31 11:13:16 -0700571 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700572 case R.id.dialtacts_options_menu_button:
573 buildOptionsMenu(view).show();
574 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700575 default: {
576 Log.wtf(TAG, "Unexpected onClick event from " + view);
577 break;
578 }
579 }
580 }
581
Yorke Leec3766332013-07-31 11:13:16 -0700582 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700583 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700584 switch (item.getItemId()) {
585 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700586 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700587 break;
588 case R.id.menu_add_contact:
589 try {
590 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
591 } catch (ActivityNotFoundException e) {
592 Toast toast = Toast.makeText(this,
593 R.string.add_contact_not_available,
594 Toast.LENGTH_SHORT);
595 toast.show();
596 }
597 break;
598 case R.id.menu_import_export:
599 // We hard-code the "contactsAreAvailable" argument because doing it properly would
600 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
601 // now in Dialtacts for (potential) performance reasons. Compare with how it is
602 // done in {@link PeopleActivity}.
603 ImportExportDialogFragment.show(getFragmentManager(), true,
604 DialtactsActivity.class);
605 return true;
606 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700607 ClearFrequentsDialog.show(getFragmentManager());
608 return true;
609 case R.id.menu_call_settings:
610 handleMenuSettings();
611 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700612 }
613 return false;
614 }
615
616 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700617 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
618 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
619 if (resultCode == RESULT_OK) {
620 final ArrayList<String> matches = data.getStringArrayListExtra(
621 RecognizerIntent.EXTRA_RESULTS);
622 if (matches.size() > 0) {
623 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700624 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700625 } else {
626 Log.e(TAG, "Voice search - nothing heard");
627 }
628 } else {
629 Log.e(TAG, "Voice search failed");
630 }
631 }
632 super.onActivityResult(requestCode, resultCode, data);
633 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700634
Andrew Lee2a58ab82014-05-15 02:16:04 -0700635 /**
636 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
637 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
638 * @see #onDialpadShown
639 */
Yorke Leec3766332013-07-31 11:13:16 -0700640 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700641 if (mIsDialpadShown) {
642 return;
643 }
644 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700645 mDialpadFragment.setAnimate(animate);
646
Chiao Cheng94b10b52012-08-17 16:59:12 -0700647 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700648 ft.show(mDialpadFragment);
649 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700650
Yorke Lee5253be02014-05-21 18:50:03 -0700651 mActionBarController.onDialpadUp();
652
Andrew Leeb1903842014-05-15 16:11:24 -0700653 if (!isInSearchUi()) {
654 enterSearchUi(true /* isSmartDial */, mSearchQuery);
655 }
Yorke Leec3766332013-07-31 11:13:16 -0700656 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700657
Andrew Lee2a58ab82014-05-15 02:16:04 -0700658 /**
659 * Callback from child DialpadFragment when the dialpad is shown.
660 */
661 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700662 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
663 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
664 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700665 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700666 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700667 } else {
668 mDialpadFragment.setYFraction(0);
669 }
670
Andrew Lee2a58ab82014-05-15 02:16:04 -0700671 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700672 }
673
674 /**
675 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
676 * a callback after the hide animation ends.
677 * @see #commitDialpadFragmentHide
678 */
Yorke Leeca195042013-09-25 16:29:38 -0700679 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700680 if (mDialpadFragment == null) {
681 return;
682 }
Yorke Leef6673d32013-08-23 15:34:17 -0700683 if (clearDialpad) {
684 mDialpadFragment.clearDialpad();
685 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700686 if (!mIsDialpadShown) {
687 return;
Yorke Leec3766332013-07-31 11:13:16 -0700688 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700689 mIsDialpadShown = false;
690 mDialpadFragment.setAnimate(animate);
691
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700692 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700693 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
694 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
695
696 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700697 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700698 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700699 } else {
700 commitDialpadFragmentHide();
701 }
702
Yorke Lee5253be02014-05-21 18:50:03 -0700703 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700704
Andrew Leed4cde832014-05-16 15:56:48 -0700705 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700706 if (TextUtils.isEmpty(mSearchQuery)) {
707 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700708 }
Andrew Leed4cde832014-05-16 15:56:48 -0700709 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700710 }
711
712 /**
713 * Finishes hiding the dialpad fragment after any animations are completed.
714 */
715 private void commitDialpadFragmentHide() {
716 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700717 ft.hide(mDialpadFragment);
718 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700719 }
720
Andrew Lee2a58ab82014-05-15 02:16:04 -0700721 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700722 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700723 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700724 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700725 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700726 fragment = mRegularSearchFragment;
727 }
728 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700729 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700730 }
731 }
732
Yorke Lee5253be02014-05-21 18:50:03 -0700733 @Override
734 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700735 return mInDialpadSearch || mInRegularSearch;
736 }
737
Yorke Lee5253be02014-05-21 18:50:03 -0700738 @Override
739 public boolean hasSearchQuery() {
740 return !TextUtils.isEmpty(mSearchQuery);
741 }
742
743 @Override
744 public boolean shouldShowActionBar() {
745 return mListsFragment.shouldShowActionBar();
746 }
747
Yorke Leeb207f8a2013-08-29 18:51:06 -0700748 private void setNotInSearchUi() {
749 mInDialpadSearch = false;
750 mInRegularSearch = false;
751 }
752
Yorke Lee311969c2013-08-26 06:31:11 -0700753 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700754 if (mIsDialpadShown) {
755 hideDialpadFragment(false, true);
756 } else {
757 exitSearchUi();
758 }
Yorke Lee311969c2013-08-26 06:31:11 -0700759 }
760
Yorke Leee00c9fe2014-04-12 12:42:06 -0700761 private void hideInputMethod(View view) {
762 final InputMethodManager imm = (InputMethodManager) getSystemService(
763 Context.INPUT_METHOD_SERVICE);
764 if (imm != null && view != null) {
765 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
766 }
767 }
768
Yorke Lee53a22302014-04-29 18:13:46 -0700769 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700770 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
771 if (canIntentBeHandled(voiceIntent)) {
772 mVoiceSearchButton.setVisibility(View.VISIBLE);
773 mVoiceSearchButton.setOnClickListener(this);
774 } else {
775 mVoiceSearchButton.setVisibility(View.GONE);
776 }
777 }
778
Andrew Leee74a10e2014-05-16 14:31:40 -0700779 private OptionsPopupMenu buildOptionsMenu(View invoker) {
780 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
781 popupMenu.inflate(R.menu.dialtacts_options);
782 popupMenu.setOnMenuItemClickListener(this);
783 return popupMenu;
784 }
785
Yorke Lee86e21f72014-04-02 16:49:38 -0700786 @Override
787 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700788 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700789 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700790 mPendingSearchViewQuery = null;
791 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700792 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700793 }
794
Chiao Cheng94b10b52012-08-17 16:59:12 -0700795 /**
796 * Returns true if the intent is due to hitting the green send key (hardware call button:
797 * KEYCODE_CALL) while in a call.
798 *
799 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700800 * @return true if the intent is due to hitting the green send key while in a call
801 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700802 private boolean isSendKeyWhileInCall(Intent intent) {
803 // If there is a call in progress and the user launched the dialer by hitting the call
804 // button, go straight to the in-call screen.
805 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700806
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700807 if (callKey) {
808 getTelephonyManager().showCallScreen();
809 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700810 }
811
812 return false;
813 }
814
815 /**
816 * Sets the current tab based on the intent's request type
817 *
818 * @param intent Intent that contains information about which tab should be selected
819 */
Yorke Leec3766332013-07-31 11:13:16 -0700820 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700821 // 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 -0700822 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700823 finish();
824 return;
825 }
826
Yorke Lee669b6082013-09-17 15:43:38 -0700827 if (mDialpadFragment != null) {
828 final boolean phoneIsInUse = phoneIsInUse();
829 if (phoneIsInUse || isDialIntent(intent)) {
830 mDialpadFragment.setStartedFromNewIntent(true);
831 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
832 mInCallDialpadUp = true;
833 }
834 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700835 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700836 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700837 }
838
839 @Override
840 public void onNewIntent(Intent newIntent) {
841 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700842 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700843
Chiao Cheng94b10b52012-08-17 16:59:12 -0700844 invalidateOptionsMenu();
845 }
846
847 /** Returns true if the given intent contains a phone number to populate the dialer with */
848 private boolean isDialIntent(Intent intent) {
849 final String action = intent.getAction();
850 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
851 return true;
852 }
853 if (Intent.ACTION_VIEW.equals(action)) {
854 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700855 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700856 return true;
857 }
858 }
859 return false;
860 }
861
862 /**
863 * Returns an appropriate call origin for this Activity. May return null when no call origin
864 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
865 * for remembering the tab in which the user made a phone call, so the external app's DIAL
866 * request should not be counted.)
867 */
868 public String getCallOrigin() {
869 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
870 }
871
Chiao Cheng94b10b52012-08-17 16:59:12 -0700872 /**
Yorke Leec3766332013-07-31 11:13:16 -0700873 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700874 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700875 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700876 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700877 // Weird race condition where fragment is doing work after the activity is destroyed
878 // due to talkback being on (b/10209937). Just return since we can't do any
879 // constructive here.
880 return;
881 }
882
Yorke Leeef2b7382013-08-09 17:39:25 -0700883 if (DEBUG) {
884 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
885 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700886
Yorke Leec3766332013-07-31 11:13:16 -0700887 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700888 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700889 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700890 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700891 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700892 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700893
Yorke Leeb207f8a2013-08-29 18:51:06 -0700894 final String tag;
895 if (smartDialSearch) {
896 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
897 } else {
898 tag = TAG_REGULAR_SEARCH_FRAGMENT;
899 }
900 mInDialpadSearch = smartDialSearch;
901 mInRegularSearch = !smartDialSearch;
902
Andrew Lee752956e2014-05-15 11:43:38 -0700903 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700904 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700905 if (fragment == null) {
906 if (smartDialSearch) {
907 fragment = new SmartDialSearchFragment();
908 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700909 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700910 }
Andrew Leeb1903842014-05-15 16:11:24 -0700911 transaction.add(R.id.dialtacts_frame, fragment, tag);
912 } else {
913 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700914 }
Andrew Leeb1903842014-05-15 16:11:24 -0700915
Yorke Lee86e21f72014-04-02 16:49:38 -0700916 // DialtactsActivity will provide the options menu
917 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700918 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700919 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700920 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700921
922 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700923 }
924
925 /**
Yorke Leec3766332013-07-31 11:13:16 -0700926 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700927 */
Yorke Leec3766332013-07-31 11:13:16 -0700928 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700929 // See related bug in enterSearchUI();
930 if (getFragmentManager().isDestroyed()) {
931 return;
932 }
Andrew Leeb1903842014-05-15 16:11:24 -0700933
Andrew Leeb1903842014-05-15 16:11:24 -0700934 mSearchView.setText(null);
935 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700936 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700937
Andrew Leeb1903842014-05-15 16:11:24 -0700938 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700939 if (mSmartDialSearchFragment != null) {
940 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700941 }
Andrew Leeb1903842014-05-15 16:11:24 -0700942 if (mRegularSearchFragment != null) {
943 transaction.remove(mRegularSearchFragment);
944 }
945 transaction.commit();
946
947 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700948 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700949 }
950
951 /** Returns an Intent to launch Call Settings screen */
952 public static Intent getCallSettingsIntent() {
953 final Intent intent = new Intent(Intent.ACTION_MAIN);
954 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
955 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
956 return intent;
957 }
958
959 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700960 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700961 if (mIsDialpadShown) {
Andrew Leeb1903842014-05-15 16:11:24 -0700962 if (TextUtils.isEmpty(mSearchQuery)) {
963 exitSearchUi();
964 }
Yorke Leef6673d32013-08-23 15:34:17 -0700965 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700966 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700967 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700968 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700969 } else {
970 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700971 }
Yorke Leec3766332013-07-31 11:13:16 -0700972 }
973
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700974 /**
975 * @return True if the search UI was exited, false otherwise
976 */
977 private boolean maybeExitSearchUi() {
978 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
979 exitSearchUi();
980 hideInputMethod(parentLayout);
981 return true;
982 }
983 return false;
984 }
985
Yorke Leec3766332013-07-31 11:13:16 -0700986 @Override
987 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700988 if (mSmartDialSearchFragment != null) {
989 mSmartDialSearchFragment.setAddToContactNumber(query);
990 }
Yorke Leec3766332013-07-31 11:13:16 -0700991 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
992 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700993
994 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700995 if (DEBUG) {
996 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
997 }
998 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
999 // This callback can happen if the dialpad fragment is recreated because of
1000 // activity destruction. In that case, don't update the search view because
1001 // that would bring the user back to the search fragment regardless of the
1002 // previous state of the application. Instead, just return here and let the
1003 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001004 if (!TextUtils.isEmpty(normalizedQuery)) {
1005 mPendingSearchViewQuery = normalizedQuery;
1006 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001007 return;
1008 }
Yorke Lee53a22302014-04-29 18:13:46 -07001009 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001010 }
1011 }
Yorke Leec3766332013-07-31 11:13:16 -07001012
1013 @Override
1014 public void onListFragmentScrollStateChange(int scrollState) {
1015 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001016 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001017 hideInputMethod(getCurrentFocus());
1018 }
1019 }
1020
1021 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001022 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001023 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001024 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1025 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001026 }
1027
Yorke Lee86e21f72014-04-02 16:49:38 -07001028 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001029 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001030 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001031 }
1032
1033 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001034 // TODO(santoscordon): Replace with a TelecommService method call.
1035 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001036 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001037
Yorke Leee1424812013-09-04 18:24:48 -07001038 public static Intent getAddNumberToContactIntent(CharSequence text) {
1039 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1040 intent.putExtra(Intents.Insert.PHONE, text);
1041 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1042 return intent;
1043 }
1044
Yorke Leeda0f9042013-12-05 14:25:51 -08001045 private boolean canIntentBeHandled(Intent intent) {
1046 final PackageManager packageManager = getPackageManager();
1047 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1048 PackageManager.MATCH_DEFAULT_ONLY);
1049 return resolveInfo != null && resolveInfo.size() > 0;
1050 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001051
Yorke Lee6a1461a2014-04-21 16:27:14 -07001052 @Override
1053 public void showCallHistory() {
1054 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1055 // CONTENT_TYPE, so that we always open our call log from our dialer
1056 final Intent intent = new Intent(this, CallLogActivity.class);
1057 startActivity(intent);
1058 }
1059
Yorke Lee86e21f72014-04-02 16:49:38 -07001060 /**
1061 * Called when the user has long-pressed a contact tile to start a drag operation.
1062 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001063 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001064 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001065 if (mListsFragment.isPaneOpen()) {
1066 mActionBarController.slideActionBarUp(true);
1067 }
Yorke Lee28266192014-05-01 10:05:52 -07001068 mRemoveViewContainer.setVisibility(View.VISIBLE);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001069 }
1070
1071 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001072 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1073 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001074
Yorke Lee86e21f72014-04-02 16:49:38 -07001075 /**
1076 * Called when the user has released a contact tile after long-pressing it.
1077 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001078 @Override
1079 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001080 if (mListsFragment.isPaneOpen()) {
1081 mActionBarController.slideActionBarDown(true);
1082 }
Yorke Lee28266192014-05-01 10:05:52 -07001083 mRemoveViewContainer.setVisibility(View.GONE);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001084 }
1085
1086 @Override
1087 public void onDroppedOnRemove() {}
1088
1089 /**
Yorke Leed999b712014-04-23 15:10:58 -07001090 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001091 * once it has been attached to the activity.
1092 */
1093 @Override
1094 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001095 mDragDropController = dragController;
1096 ((RemoveView) findViewById(R.id.remove_view))
1097 .setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001098 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001099
1100 @Override
1101 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001102 // Specify call-origin so that users will see the previous tab instead of
1103 // CallLog screen (search UI will be automatically exited).
1104 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001105 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001106 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001107 }
1108
1109 @Override
1110 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001111 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1112 startActivity(intent);
1113 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001114 }
1115
1116 @Override
1117 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001118 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001119 }
1120
1121 @Override
1122 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001123 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001124 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001125
Yorke Leecc4660d2014-04-24 11:22:57 -07001126 @Override
1127 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001128 // Only scroll the button when the first tab is selected. The button should scroll from
1129 // the middle to right position only on the transition from the first tab to the second
1130 // tab.
1131 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL) {
1132 mFloatingActionButtonController.onPageScrolled(positionOffset);
1133 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001134 }
1135
1136 @Override
1137 public void onPageSelected(int position) {
1138 mCurrentTabPosition = position;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001139 // Prevents jittery movement when clicking on tabs.
1140 if (mCurrentTabPosition != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1141 mFloatingActionButtonController.manuallyTranslate(
1142 mFloatingActionButtonController.getTranslationXForAlignment(
1143 FloatingActionButtonController.ALIGN_RIGHT), 0);
1144 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001145 }
1146
1147 @Override
1148 public void onPageScrollStateChanged(int state) {
1149 }
1150
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001151 private TelephonyManager getTelephonyManager() {
1152 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1153 }
1154
Yorke Lee5253be02014-05-21 18:50:03 -07001155 @Override
1156 public boolean isActionBarShowing() {
1157 return mActionBarController.isActionBarShowing();
1158 }
1159
Andrew Lee9da8fb42014-06-03 14:03:09 -07001160 public boolean isDialpadShown() {
1161 return mIsDialpadShown;
1162 }
1163
Yorke Lee5253be02014-05-21 18:50:03 -07001164 @Override
1165 public int getActionBarHideOffset() {
1166 return getActionBar().getHideOffset();
1167 }
1168
1169 @Override
1170 public int getActionBarHeight() {
1171 return mActionBarHeight;
1172 }
1173
1174 @Override
1175 public void setActionBarHideOffset(int hideOffset) {
1176 getActionBar().setHideOffset(hideOffset);
1177 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001178
1179 /**
1180 * Updates controller based on currently known information.
1181 *
1182 * @param animate Whether or not to animate the transition.
1183 */
1184 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1185 int align;
1186 if (mIsDialpadShown) {
1187 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1188 : FloatingActionButtonController.ALIGN_MIDDLE;
1189 } else {
1190 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1191 ? FloatingActionButtonController.ALIGN_MIDDLE
1192 : FloatingActionButtonController.ALIGN_RIGHT;
1193 }
1194 mFloatingActionButtonController.align(align,
1195 0 /* offsetX */,
1196 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1197 animate);
1198 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001199}