blob: 309f12ac6682c306be6bf3eeaf4274e0c4422608 [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;
Chiao Cheng94b10b52012-08-17 16:59:12 -070064import android.widget.PopupMenu;
Yorke Leecc4660d2014-04-24 11:22:57 -070065import android.widget.RelativeLayout;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080066import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070067
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070068import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070069import com.android.contacts.common.activity.TransactionSafeActivity;
Andrew Lee3c14bc32014-05-28 15:43:03 -070070import com.android.contacts.common.animation.AnimationListenerAdapter;
Yorke Leec3766332013-07-31 11:13:16 -070071import com.android.contacts.common.dialog.ClearFrequentsDialog;
72import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080073import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Andrew Lee4cbc9732014-04-24 14:38:58 -070074import com.android.contacts.common.util.ViewUtil;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070075import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070076import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070077import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070078import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070079import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070080import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070081import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080082import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070083import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080084import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070085import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070086import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070087import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070088import com.android.dialer.list.RegularSearchFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080089import com.android.dialer.list.RemoveView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070090import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070091import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee5253be02014-05-21 18:50:03 -070092import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070093import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070094import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070095import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070096
Yorke Leec3766332013-07-31 11:13:16 -070097import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080098import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070099
Chiao Cheng94b10b52012-08-17 16:59:12 -0700100/**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700101 * The dialer tab's title is 'phone', a more common name (see strings.xml).
102 */
Yorke Leec3766332013-07-31 11:13:16 -0700103public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700104 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700105 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800106 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700107 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700108 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700109 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700110 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700111 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700112 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700113 ViewPager.OnPageChangeListener,
114 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700115 private static final String TAG = "DialtactsActivity";
116
Ihab Awad526c0b82014-02-27 12:55:36 -0800117 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700118
Yorke Leef74011e2013-08-02 11:30:30 -0700119 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
120
Chiao Cheng94b10b52012-08-17 16:59:12 -0700121 /** Used to open Call Setting */
122 private static final String PHONE_PACKAGE = "com.android.phone";
123 private static final String CALL_SETTINGS_CLASS_NAME =
124 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700125 /** @see #getCallOrigin() */
126 private static final String CALL_ORIGIN_DIALTACTS =
127 "com.android.dialer.DialtactsActivity";
128
Yorke Leeb207f8a2013-08-29 18:51:06 -0700129 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
130 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700131 private static final String KEY_SEARCH_QUERY = "search_query";
132 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700133 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700134
Yorke Leec3766332013-07-31 11:13:16 -0700135 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
136 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
137 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
138 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700139
Chiao Cheng94b10b52012-08-17 16:59:12 -0700140 /**
141 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
142 */
143 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
144
Yorke Leec3766332013-07-31 11:13:16 -0700145 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700146
Andrew Lee0c667702014-05-12 14:31:45 -0700147 private RelativeLayout parentLayout;
148
Yorke Leec3766332013-07-31 11:13:16 -0700149 /**
Yorke Leec3766332013-07-31 11:13:16 -0700150 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700151 */
Yorke Leef74011e2013-08-02 11:30:30 -0700152 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700153
154 /**
155 * Fragment for searching phone numbers using the alphanumeric keyboard.
156 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700157 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700158
159 /**
160 * Fragment for searching phone numbers using the dialpad.
161 */
162 private SmartDialSearchFragment mSmartDialSearchFragment;
163
Yorke Leee00c9fe2014-04-12 12:42:06 -0700164 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700165 * Animation that slides in.
166 */
167 private Animation mSlideIn;
168
169 /**
170 * Animation that slides out.
171 */
172 private Animation mSlideOut;
173
174 /**
175 * Listener for after slide out animation completes on dialer fragment.
176 */
177 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
178 @Override
179 public void onAnimationEnd(Animation animation) {
180 commitDialpadFragmentHide();
181 }
182 };
183
184 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700185 * Fragment containing the speed dial list, recents list, and all contacts list.
186 */
187 private ListsFragment mListsFragment;
188
Yorke Leeb207f8a2013-08-29 18:51:06 -0700189 private boolean mInDialpadSearch;
190 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700191 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700192 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700193 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700194
Yorke Leeef2b7382013-08-09 17:39:25 -0700195 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700196 * Whether or not the device is in landscape orientation.
197 */
198 private boolean mIsLandscape;
199
200 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700201 * The position of the currently selected tab in the attached {@link ListsFragment}.
202 */
203 private int mCurrentTabPosition = 0;
204
205 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700206 * True if the dialpad is only temporarily showing due to being in call
207 */
208 private boolean mInCallDialpadUp;
209
210 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700211 * True when this activity has been launched for the first time.
212 */
Yorke Lee98702de2013-08-06 12:03:32 -0700213 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700214
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700215 /**
216 * Search query to be applied to the SearchView in the ActionBar once
217 * onCreateOptionsMenu has been called.
218 */
219 private String mPendingSearchViewQuery;
220
Yorke Lee53a22302014-04-29 18:13:46 -0700221 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700222 private View mVoiceSearchButton;
Yorke Leeec489fb2014-05-19 15:39:27 -0700223 private SearchEditTextLayout mSearchEditTextLayout;
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 Leeec489fb2014-05-19 15:39:27 -0700375 mSearchEditTextLayout = (SearchEditTextLayout) actionBar.getCustomView();
376 mSearchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
Yorke Lee53a22302014-04-29 18:13:46 -0700377
Yorke Leeec489fb2014-05-19 15:39:27 -0700378 mSearchView = (EditText) mSearchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700379 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Yorke Lee11ca39e2014-05-19 20:31:37 -0700380 mVoiceSearchButton = mSearchEditTextLayout.findViewById(R.id.voice_search_button);
381 mSearchEditTextLayout.findViewById(R.id.search_box_start_search).setOnClickListener(
382 mSearchViewOnClickListener);
383 mSearchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
384 @Override
385 public void onBackButtonClicked() {
386 onBackPressed();
387 }
388 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700389
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700390 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700391 == Configuration.ORIENTATION_LANDSCAPE;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700392 final View floatingActionButtonContainer = findViewById(
393 R.id.floating_action_button_container);
394 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
395 int floatingActionButtonWidth = resources.getDimensionPixelSize(
396 R.dimen.floating_action_button_width);
397 mFloatingActionButton.setOnClickListener(this);
398 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700399 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700400 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
401 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700402
Yorke Leeec489fb2014-05-19 15:39:27 -0700403 ImageButton optionsMenuButton = (ImageButton) mSearchEditTextLayout.findViewById(
404 R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700405 optionsMenuButton.setOnClickListener(this);
406 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
407 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
408
Yorke Leeef2b7382013-08-09 17:39:25 -0700409 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
410 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700411 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800412 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700413 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800414 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
415 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700416 } else {
417 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700418 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
419 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700420 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700421 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700422 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700423 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700424
425 mSlideIn = AnimationUtils.loadAnimation(this,
426 mIsLandscape ? R.anim.slide_in_right : R.anim.slide_in);
427 mSlideOut = AnimationUtils.loadAnimation(this,
428 mIsLandscape ? R.anim.slide_out_right : R.anim.slide_out);
429
430 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700431
Andrew Lee0c667702014-05-12 14:31:45 -0700432 parentLayout = (RelativeLayout) findViewById(R.id.dialtacts_mainlayout);
433 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
434 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700435 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700436 new ViewTreeObserver.OnGlobalLayoutListener() {
437 @Override
438 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700439 final ViewTreeObserver observer = floatingActionButtonContainer
440 .getViewTreeObserver();
441 if (!observer.isAlive()) {
442 return;
443 }
444 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700445 int screenWidth = parentLayout.getWidth();
446 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700447 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700448 }
449 });
Andrew Lee0c667702014-05-12 14:31:45 -0700450
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700451 setupActivityOverlay();
452
Yorke Lee28266192014-05-01 10:05:52 -0700453 mRemoveViewContainer = findViewById(R.id.remove_view_container);
Yorke Leeb0d19762014-03-05 14:43:28 -0800454
Yorke Lee0baa98b2013-08-22 10:55:16 -0700455 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700456 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700457 }
458
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700459 private void setupActivityOverlay() {
460 final View activityOverlay = findViewById(R.id.activity_overlay);
461 activityOverlay.setOnTouchListener(new OnTouchListener() {
462 @Override
463 public boolean onTouch(View v, MotionEvent event) {
464 if (!mIsDialpadShown) {
465 maybeExitSearchUi();
466 }
467 return false;
468 }
469 });
470 }
471
Chiao Cheng94b10b52012-08-17 16:59:12 -0700472 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700473 protected void onResume() {
474 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700475 if (mFirstLaunch) {
476 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700477 } else if (!phoneIsInUse() && mInCallDialpadUp) {
478 hideDialpadFragment(false, true);
479 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700480 } else if (mShowDialpadOnResume) {
481 showDialpadFragment(false);
482 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700483 }
484 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700485 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700486 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700487 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700488 }
489
490 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700491 protected void onPause() {
492 if (mClearSearchOnPause) {
493 hideDialpadAndSearchUi();
494 mClearSearchOnPause = false;
495 }
496 super.onPause();
497 }
498
499 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700500 protected void onSaveInstanceState(Bundle outState) {
501 super.onSaveInstanceState(outState);
502 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700503 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
504 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700505 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700506 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700507 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700508 }
509
510 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700511 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700512 if (fragment instanceof DialpadFragment) {
513 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700514 if (!mShowDialpadOnResume) {
515 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
516 transaction.hide(mDialpadFragment);
517 transaction.commit();
518 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700519 } else if (fragment instanceof SmartDialSearchFragment) {
520 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700521 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700522 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700523 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700524 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700525 } else if (fragment instanceof ListsFragment) {
526 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700527 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700528 }
Yorke Leec3766332013-07-31 11:13:16 -0700529 }
530
Alon Albertb453e5b2013-09-10 15:54:23 -0700531 protected void handleMenuSettings() {
532 openTelephonySetting(this);
533 }
534
535 public static void openTelephonySetting(Activity activity) {
536 final Intent settingsIntent = getCallSettingsIntent();
537 activity.startActivity(settingsIntent);
538 }
539
Chiao Cheng94b10b52012-08-17 16:59:12 -0700540 @Override
541 public void onClick(View view) {
542 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700543 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700544 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700545 mInCallDialpadUp = false;
546 showDialpadFragment(true);
547 } else {
548 // Dial button was pressed; tell the Dialpad fragment
549 mDialpadFragment.dialButtonPressed();
550 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700551 break;
Yorke Leec3766332013-07-31 11:13:16 -0700552 case R.id.search_close_button:
553 // Clear the search field
Yorke Lee53a22302014-04-29 18:13:46 -0700554 if (!TextUtils.isEmpty(mSearchView.getText())) {
Yorke Lee2eafb7a2013-09-10 14:34:01 -0700555 mDialpadFragment.clearDialpad();
Yorke Lee53a22302014-04-29 18:13:46 -0700556 mSearchView.setText(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700557 }
558 break;
Yorke Leec3766332013-07-31 11:13:16 -0700559 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800560 try {
561 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
562 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
563 } catch (ActivityNotFoundException e) {
564 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
565 Toast.LENGTH_SHORT).show();
566 }
Yorke Leec3766332013-07-31 11:13:16 -0700567 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700568 case R.id.dialtacts_options_menu_button:
569 buildOptionsMenu(view).show();
570 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700571 default: {
572 Log.wtf(TAG, "Unexpected onClick event from " + view);
573 break;
574 }
575 }
576 }
577
Yorke Leec3766332013-07-31 11:13:16 -0700578 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700579 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700580 switch (item.getItemId()) {
581 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700582 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700583 break;
584 case R.id.menu_add_contact:
585 try {
586 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
587 } catch (ActivityNotFoundException e) {
588 Toast toast = Toast.makeText(this,
589 R.string.add_contact_not_available,
590 Toast.LENGTH_SHORT);
591 toast.show();
592 }
593 break;
594 case R.id.menu_import_export:
595 // We hard-code the "contactsAreAvailable" argument because doing it properly would
596 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
597 // now in Dialtacts for (potential) performance reasons. Compare with how it is
598 // done in {@link PeopleActivity}.
599 ImportExportDialogFragment.show(getFragmentManager(), true,
600 DialtactsActivity.class);
601 return true;
602 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700603 ClearFrequentsDialog.show(getFragmentManager());
604 return true;
605 case R.id.menu_call_settings:
606 handleMenuSettings();
607 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700608 }
609 return false;
610 }
611
612 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700613 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
614 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
615 if (resultCode == RESULT_OK) {
616 final ArrayList<String> matches = data.getStringArrayListExtra(
617 RecognizerIntent.EXTRA_RESULTS);
618 if (matches.size() > 0) {
619 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700620 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700621 } else {
622 Log.e(TAG, "Voice search - nothing heard");
623 }
624 } else {
625 Log.e(TAG, "Voice search failed");
626 }
627 }
628 super.onActivityResult(requestCode, resultCode, data);
629 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700630
Andrew Lee2a58ab82014-05-15 02:16:04 -0700631 /**
632 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
633 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
634 * @see #onDialpadShown
635 */
Yorke Leec3766332013-07-31 11:13:16 -0700636 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700637 if (mIsDialpadShown) {
638 return;
639 }
640 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700641 mDialpadFragment.setAnimate(animate);
642
Chiao Cheng94b10b52012-08-17 16:59:12 -0700643 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700644 ft.show(mDialpadFragment);
645 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700646
Yorke Lee5253be02014-05-21 18:50:03 -0700647 mActionBarController.onDialpadUp();
648
Andrew Leeb1903842014-05-15 16:11:24 -0700649 if (!isInSearchUi()) {
650 enterSearchUi(true /* isSmartDial */, mSearchQuery);
651 }
Yorke Leec3766332013-07-31 11:13:16 -0700652 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700653
Andrew Lee2a58ab82014-05-15 02:16:04 -0700654 /**
655 * Callback from child DialpadFragment when the dialpad is shown.
656 */
657 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700658 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
659 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
660 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700661 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700662 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700663 } else {
664 mDialpadFragment.setYFraction(0);
665 }
666
Andrew Lee2a58ab82014-05-15 02:16:04 -0700667 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700668 }
669
670 /**
671 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
672 * a callback after the hide animation ends.
673 * @see #commitDialpadFragmentHide
674 */
Yorke Leeca195042013-09-25 16:29:38 -0700675 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700676 if (mDialpadFragment == null) {
677 return;
678 }
Yorke Leef6673d32013-08-23 15:34:17 -0700679 if (clearDialpad) {
680 mDialpadFragment.clearDialpad();
681 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700682 if (!mIsDialpadShown) {
683 return;
Yorke Leec3766332013-07-31 11:13:16 -0700684 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700685 mIsDialpadShown = false;
686 mDialpadFragment.setAnimate(animate);
687
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700688 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700689 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
690 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
691
692 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700693 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700694 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700695 } else {
696 commitDialpadFragmentHide();
697 }
698
Yorke Lee5253be02014-05-21 18:50:03 -0700699 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700700
Andrew Leed4cde832014-05-16 15:56:48 -0700701 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700702 if (TextUtils.isEmpty(mSearchQuery)) {
703 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700704 }
Andrew Leed4cde832014-05-16 15:56:48 -0700705 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700706 }
707
708 /**
709 * Finishes hiding the dialpad fragment after any animations are completed.
710 */
711 private void commitDialpadFragmentHide() {
712 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700713 ft.hide(mDialpadFragment);
714 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700715 }
716
Andrew Lee2a58ab82014-05-15 02:16:04 -0700717 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700718 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700719 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700720 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700721 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700722 fragment = mRegularSearchFragment;
723 }
724 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700725 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700726 }
727 }
728
Yorke Lee5253be02014-05-21 18:50:03 -0700729 @Override
730 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700731 return mInDialpadSearch || mInRegularSearch;
732 }
733
Yorke Lee5253be02014-05-21 18:50:03 -0700734 @Override
735 public boolean hasSearchQuery() {
736 return !TextUtils.isEmpty(mSearchQuery);
737 }
738
739 @Override
740 public boolean shouldShowActionBar() {
741 return mListsFragment.shouldShowActionBar();
742 }
743
Yorke Leeb207f8a2013-08-29 18:51:06 -0700744 private void setNotInSearchUi() {
745 mInDialpadSearch = false;
746 mInRegularSearch = false;
747 }
748
Yorke Lee311969c2013-08-26 06:31:11 -0700749 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700750 if (mIsDialpadShown) {
751 hideDialpadFragment(false, true);
752 } else {
753 exitSearchUi();
754 }
Yorke Lee311969c2013-08-26 06:31:11 -0700755 }
756
Yorke Leee00c9fe2014-04-12 12:42:06 -0700757 private void hideInputMethod(View view) {
758 final InputMethodManager imm = (InputMethodManager) getSystemService(
759 Context.INPUT_METHOD_SERVICE);
760 if (imm != null && view != null) {
761 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
762 }
763 }
764
Yorke Lee53a22302014-04-29 18:13:46 -0700765 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700766 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
767 if (canIntentBeHandled(voiceIntent)) {
768 mVoiceSearchButton.setVisibility(View.VISIBLE);
769 mVoiceSearchButton.setOnClickListener(this);
770 } else {
771 mVoiceSearchButton.setVisibility(View.GONE);
772 }
773 }
774
Andrew Leee74a10e2014-05-16 14:31:40 -0700775 private OptionsPopupMenu buildOptionsMenu(View invoker) {
776 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
777 popupMenu.inflate(R.menu.dialtacts_options);
778 popupMenu.setOnMenuItemClickListener(this);
779 return popupMenu;
780 }
781
Yorke Lee86e21f72014-04-02 16:49:38 -0700782 @Override
783 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700784 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700785 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700786 mPendingSearchViewQuery = null;
787 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700788 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700789 }
790
Chiao Cheng94b10b52012-08-17 16:59:12 -0700791 /**
792 * Returns true if the intent is due to hitting the green send key (hardware call button:
793 * KEYCODE_CALL) while in a call.
794 *
795 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700796 * @return true if the intent is due to hitting the green send key while in a call
797 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700798 private boolean isSendKeyWhileInCall(Intent intent) {
799 // If there is a call in progress and the user launched the dialer by hitting the call
800 // button, go straight to the in-call screen.
801 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700802
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700803 if (callKey) {
804 getTelephonyManager().showCallScreen();
805 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700806 }
807
808 return false;
809 }
810
811 /**
812 * Sets the current tab based on the intent's request type
813 *
814 * @param intent Intent that contains information about which tab should be selected
815 */
Yorke Leec3766332013-07-31 11:13:16 -0700816 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700817 // 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 -0700818 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700819 finish();
820 return;
821 }
822
Yorke Lee669b6082013-09-17 15:43:38 -0700823 if (mDialpadFragment != null) {
824 final boolean phoneIsInUse = phoneIsInUse();
825 if (phoneIsInUse || isDialIntent(intent)) {
826 mDialpadFragment.setStartedFromNewIntent(true);
827 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
828 mInCallDialpadUp = true;
829 }
830 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700831 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700832 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700833 }
834
835 @Override
836 public void onNewIntent(Intent newIntent) {
837 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700838 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700839
Chiao Cheng94b10b52012-08-17 16:59:12 -0700840 invalidateOptionsMenu();
841 }
842
843 /** Returns true if the given intent contains a phone number to populate the dialer with */
844 private boolean isDialIntent(Intent intent) {
845 final String action = intent.getAction();
846 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
847 return true;
848 }
849 if (Intent.ACTION_VIEW.equals(action)) {
850 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700851 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700852 return true;
853 }
854 }
855 return false;
856 }
857
858 /**
859 * Returns an appropriate call origin for this Activity. May return null when no call origin
860 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
861 * for remembering the tab in which the user made a phone call, so the external app's DIAL
862 * request should not be counted.)
863 */
864 public String getCallOrigin() {
865 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
866 }
867
Chiao Cheng94b10b52012-08-17 16:59:12 -0700868 /**
Yorke Leec3766332013-07-31 11:13:16 -0700869 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700870 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700871 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700872 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700873 // Weird race condition where fragment is doing work after the activity is destroyed
874 // due to talkback being on (b/10209937). Just return since we can't do any
875 // constructive here.
876 return;
877 }
878
Yorke Leeef2b7382013-08-09 17:39:25 -0700879 if (DEBUG) {
880 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
881 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700882
Yorke Leec3766332013-07-31 11:13:16 -0700883 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700884 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700885 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700886 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700887 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700888 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700889
Yorke Leeb207f8a2013-08-29 18:51:06 -0700890 final String tag;
891 if (smartDialSearch) {
892 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
893 } else {
894 tag = TAG_REGULAR_SEARCH_FRAGMENT;
895 }
896 mInDialpadSearch = smartDialSearch;
897 mInRegularSearch = !smartDialSearch;
898
Andrew Lee752956e2014-05-15 11:43:38 -0700899 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700900 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700901 if (fragment == null) {
902 if (smartDialSearch) {
903 fragment = new SmartDialSearchFragment();
904 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700905 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700906 }
Andrew Leeb1903842014-05-15 16:11:24 -0700907 transaction.add(R.id.dialtacts_frame, fragment, tag);
908 } else {
909 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700910 }
Andrew Leeb1903842014-05-15 16:11:24 -0700911
Yorke Lee86e21f72014-04-02 16:49:38 -0700912 // DialtactsActivity will provide the options menu
913 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700914 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700915 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700916 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700917
918 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700919 }
920
921 /**
Yorke Leec3766332013-07-31 11:13:16 -0700922 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700923 */
Yorke Leec3766332013-07-31 11:13:16 -0700924 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700925 // See related bug in enterSearchUI();
926 if (getFragmentManager().isDestroyed()) {
927 return;
928 }
Andrew Leeb1903842014-05-15 16:11:24 -0700929
Andrew Leeb1903842014-05-15 16:11:24 -0700930 mSearchView.setText(null);
931 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700932 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700933
Andrew Leeb1903842014-05-15 16:11:24 -0700934 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700935 if (mSmartDialSearchFragment != null) {
936 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700937 }
Andrew Leeb1903842014-05-15 16:11:24 -0700938 if (mRegularSearchFragment != null) {
939 transaction.remove(mRegularSearchFragment);
940 }
941 transaction.commit();
942
943 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700944 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700945 }
946
947 /** Returns an Intent to launch Call Settings screen */
948 public static Intent getCallSettingsIntent() {
949 final Intent intent = new Intent(Intent.ACTION_MAIN);
950 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
951 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
952 return intent;
953 }
954
955 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700956 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700957 if (mIsDialpadShown) {
Andrew Leeb1903842014-05-15 16:11:24 -0700958 if (TextUtils.isEmpty(mSearchQuery)) {
959 exitSearchUi();
960 }
Yorke Leef6673d32013-08-23 15:34:17 -0700961 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700962 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700963 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700964 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700965 } else {
966 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700967 }
Yorke Leec3766332013-07-31 11:13:16 -0700968 }
969
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700970 /**
971 * @return True if the search UI was exited, false otherwise
972 */
973 private boolean maybeExitSearchUi() {
974 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
975 exitSearchUi();
976 hideInputMethod(parentLayout);
977 return true;
978 }
979 return false;
980 }
981
Yorke Leec3766332013-07-31 11:13:16 -0700982 @Override
983 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700984 if (mSmartDialSearchFragment != null) {
985 mSmartDialSearchFragment.setAddToContactNumber(query);
986 }
Yorke Leec3766332013-07-31 11:13:16 -0700987 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
988 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700989
990 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700991 if (DEBUG) {
992 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
993 }
994 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
995 // This callback can happen if the dialpad fragment is recreated because of
996 // activity destruction. In that case, don't update the search view because
997 // that would bring the user back to the search fragment regardless of the
998 // previous state of the application. Instead, just return here and let the
999 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001000 if (!TextUtils.isEmpty(normalizedQuery)) {
1001 mPendingSearchViewQuery = normalizedQuery;
1002 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001003 return;
1004 }
Yorke Lee53a22302014-04-29 18:13:46 -07001005 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001006 }
1007 }
Yorke Leec3766332013-07-31 11:13:16 -07001008
1009 @Override
1010 public void onListFragmentScrollStateChange(int scrollState) {
1011 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001012 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001013 hideInputMethod(getCurrentFocus());
1014 }
1015 }
1016
1017 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001018 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001019 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001020 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1021 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001022 }
1023
Yorke Lee86e21f72014-04-02 16:49:38 -07001024 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001025 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001026 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001027 }
1028
1029 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001030 // TODO(santoscordon): Replace with a TelecommService method call.
1031 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001032 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001033
Yorke Leee1424812013-09-04 18:24:48 -07001034 public static Intent getAddNumberToContactIntent(CharSequence text) {
1035 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1036 intent.putExtra(Intents.Insert.PHONE, text);
1037 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1038 return intent;
1039 }
1040
Yorke Leeda0f9042013-12-05 14:25:51 -08001041 private boolean canIntentBeHandled(Intent intent) {
1042 final PackageManager packageManager = getPackageManager();
1043 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1044 PackageManager.MATCH_DEFAULT_ONLY);
1045 return resolveInfo != null && resolveInfo.size() > 0;
1046 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001047
Yorke Lee6a1461a2014-04-21 16:27:14 -07001048 @Override
1049 public void showCallHistory() {
1050 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1051 // CONTENT_TYPE, so that we always open our call log from our dialer
1052 final Intent intent = new Intent(this, CallLogActivity.class);
1053 startActivity(intent);
1054 }
1055
Yorke Lee86e21f72014-04-02 16:49:38 -07001056 /**
1057 * Called when the user has long-pressed a contact tile to start a drag operation.
1058 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001059 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001060 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001061 if (mListsFragment.isPaneOpen()) {
1062 mActionBarController.slideActionBarUp(true);
1063 }
Yorke Lee28266192014-05-01 10:05:52 -07001064 mRemoveViewContainer.setVisibility(View.VISIBLE);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001065 }
1066
1067 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001068 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1069 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001070
Yorke Lee86e21f72014-04-02 16:49:38 -07001071 /**
1072 * Called when the user has released a contact tile after long-pressing it.
1073 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001074 @Override
1075 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001076 if (mListsFragment.isPaneOpen()) {
1077 mActionBarController.slideActionBarDown(true);
1078 }
Yorke Lee28266192014-05-01 10:05:52 -07001079 mRemoveViewContainer.setVisibility(View.GONE);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001080 }
1081
1082 @Override
1083 public void onDroppedOnRemove() {}
1084
1085 /**
Yorke Leed999b712014-04-23 15:10:58 -07001086 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001087 * once it has been attached to the activity.
1088 */
1089 @Override
1090 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001091 mDragDropController = dragController;
1092 ((RemoveView) findViewById(R.id.remove_view))
1093 .setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001094 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001095
1096 @Override
1097 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001098 // Specify call-origin so that users will see the previous tab instead of
1099 // CallLog screen (search UI will be automatically exited).
1100 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001101 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001102 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001103 }
1104
1105 @Override
1106 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001107 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1108 startActivity(intent);
1109 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001110 }
1111
1112 @Override
1113 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001114 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001115 }
1116
1117 @Override
1118 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001119 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001120 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001121
Yorke Leecc4660d2014-04-24 11:22:57 -07001122 @Override
1123 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001124 // Only scroll the button when the first tab is selected. The button should scroll from
1125 // the middle to right position only on the transition from the first tab to the second
1126 // tab.
1127 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL) {
1128 mFloatingActionButtonController.onPageScrolled(positionOffset);
1129 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001130 }
1131
1132 @Override
1133 public void onPageSelected(int position) {
1134 mCurrentTabPosition = position;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001135 // Prevents jittery movement when clicking on tabs.
1136 if (mCurrentTabPosition != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1137 mFloatingActionButtonController.manuallyTranslate(
1138 mFloatingActionButtonController.getTranslationXForAlignment(
1139 FloatingActionButtonController.ALIGN_RIGHT), 0);
1140 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001141 }
1142
1143 @Override
1144 public void onPageScrollStateChanged(int state) {
1145 }
1146
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001147 private TelephonyManager getTelephonyManager() {
1148 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1149 }
1150
Yorke Lee5253be02014-05-21 18:50:03 -07001151 @Override
1152 public boolean isActionBarShowing() {
1153 return mActionBarController.isActionBarShowing();
1154 }
1155
Andrew Lee9da8fb42014-06-03 14:03:09 -07001156 public boolean isDialpadShown() {
1157 return mIsDialpadShown;
1158 }
1159
Yorke Lee5253be02014-05-21 18:50:03 -07001160 @Override
1161 public int getActionBarHideOffset() {
1162 return getActionBar().getHideOffset();
1163 }
1164
1165 @Override
1166 public int getActionBarHeight() {
1167 return mActionBarHeight;
1168 }
1169
1170 @Override
1171 public void setActionBarHideOffset(int hideOffset) {
1172 getActionBar().setHideOffset(hideOffset);
1173 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001174
1175 /**
1176 * Updates controller based on currently known information.
1177 *
1178 * @param animate Whether or not to animate the transition.
1179 */
1180 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1181 int align;
1182 if (mIsDialpadShown) {
1183 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1184 : FloatingActionButtonController.ALIGN_MIDDLE;
1185 } else {
1186 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1187 ? FloatingActionButtonController.ALIGN_MIDDLE
1188 : FloatingActionButtonController.ALIGN_RIGHT;
1189 }
1190 mFloatingActionButtonController.align(align,
1191 0 /* offsetX */,
1192 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1193 animate);
1194 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001195}