blob: a5b69997b659ead2707ae41ec3e546ad3465cfc3 [file] [log] [blame]
Chiao Cheng94b10b52012-08-17 16:59:12 -07001/*
Yorke Leec3766332013-07-31 11:13:16 -07002 * Copyright (C) 2013 The Android Open Source Project
Chiao Cheng94b10b52012-08-17 16:59:12 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.dialer;
18
Yorke Leecc4660d2014-04-24 11:22:57 -070019import android.animation.LayoutTransition;
Yorke Lee53a22302014-04-29 18:13:46 -070020import android.app.ActionBar;
Chiao Cheng94b10b52012-08-17 16:59:12 -070021import android.app.Activity;
22import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080024import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070025import android.content.Context;
26import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080027import android.content.pm.PackageManager;
28import android.content.pm.ResolveInfo;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070029import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070030import android.content.res.Resources;
Yorke Lee33932ff2014-04-16 13:34:32 -070031import android.content.res.TypedArray;
Chiao Cheng94b10b52012-08-17 16:59:12 -070032import android.net.Uri;
33import android.os.Bundle;
34import android.os.RemoteException;
35import android.os.ServiceManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070036import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070037import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070038import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070039import android.support.v4.view.ViewPager;
Yorke Leec3766332013-07-31 11:13:16 -070040import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070041import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070043import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070044import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070045import android.view.DragEvent;
Andrew Leeb1903842014-05-15 16:11:24 -070046import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070047import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070049import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070050import android.view.View;
Sai Cheemalapati41460652014-06-02 21:05:39 -070051import android.view.ViewTreeObserver;
Yorke Lee28266192014-05-01 10:05:52 -070052import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070053import android.view.View.OnTouchListener;
Andrew Lee2a58ab82014-05-15 02:16:04 -070054import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070055import android.view.animation.AnimationUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070056import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070057import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070058import android.widget.EditText;
Andrew Leea73e1892014-05-13 13:21:16 -070059import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070060import android.widget.PopupMenu;
Yorke Leecc4660d2014-04-24 11:22:57 -070061import android.widget.RelativeLayout;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080062import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070063
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070064import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070065import com.android.contacts.common.activity.TransactionSafeActivity;
Andrew Lee3c14bc32014-05-28 15:43:03 -070066import com.android.contacts.common.animation.AnimationListenerAdapter;
Yorke Leec3766332013-07-31 11:13:16 -070067import com.android.contacts.common.dialog.ClearFrequentsDialog;
68import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080069import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Andrew Lee4cbc9732014-04-24 14:38:58 -070070import com.android.contacts.common.util.ViewUtil;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070071import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070072import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070073import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070074import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070075import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070076import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070077import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080078import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070079import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080080import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070081import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070082import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070083import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070084import com.android.dialer.list.RegularSearchFragment;
85import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070086import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee5253be02014-05-21 18:50:03 -070087import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070088import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070089import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070090import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070091
Yorke Leec3766332013-07-31 11:13:16 -070092import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080093import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070094
Chiao Cheng94b10b52012-08-17 16:59:12 -070095/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070096 * The dialer tab's title is 'phone', a more common name (see strings.xml).
97 */
Yorke Leec3766332013-07-31 11:13:16 -070098public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -070099 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700100 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800101 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700102 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700103 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700104 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700105 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700106 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700107 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700108 ViewPager.OnPageChangeListener,
109 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700110 private static final String TAG = "DialtactsActivity";
111
Ihab Awad526c0b82014-02-27 12:55:36 -0800112 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700113
Yorke Leef74011e2013-08-02 11:30:30 -0700114 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
115
Chiao Cheng94b10b52012-08-17 16:59:12 -0700116 /** Used to open Call Setting */
117 private static final String PHONE_PACKAGE = "com.android.phone";
118 private static final String CALL_SETTINGS_CLASS_NAME =
119 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700120 /** @see #getCallOrigin() */
121 private static final String CALL_ORIGIN_DIALTACTS =
122 "com.android.dialer.DialtactsActivity";
123
Yorke Leeb207f8a2013-08-29 18:51:06 -0700124 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
125 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700126 private static final String KEY_SEARCH_QUERY = "search_query";
127 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700128 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700129
Yorke Leec3766332013-07-31 11:13:16 -0700130 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
131 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
132 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
133 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700134
Chiao Cheng94b10b52012-08-17 16:59:12 -0700135 /**
136 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
137 */
138 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
139
Yorke Leec3766332013-07-31 11:13:16 -0700140 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700141
Andrew Lee0c667702014-05-12 14:31:45 -0700142 private RelativeLayout parentLayout;
143
Yorke Leec3766332013-07-31 11:13:16 -0700144 /**
Yorke Leec3766332013-07-31 11:13:16 -0700145 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700146 */
Yorke Leef74011e2013-08-02 11:30:30 -0700147 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700148
149 /**
150 * Fragment for searching phone numbers using the alphanumeric keyboard.
151 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700152 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700153
154 /**
155 * Fragment for searching phone numbers using the dialpad.
156 */
157 private SmartDialSearchFragment mSmartDialSearchFragment;
158
Yorke Leee00c9fe2014-04-12 12:42:06 -0700159 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700160 * Animation that slides in.
161 */
162 private Animation mSlideIn;
163
164 /**
165 * Animation that slides out.
166 */
167 private Animation mSlideOut;
168
169 /**
170 * Listener for after slide out animation completes on dialer fragment.
171 */
172 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
173 @Override
174 public void onAnimationEnd(Animation animation) {
175 commitDialpadFragmentHide();
176 }
177 };
178
179 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700180 * Fragment containing the speed dial list, recents list, and all contacts list.
181 */
182 private ListsFragment mListsFragment;
183
Yorke Leeb207f8a2013-08-29 18:51:06 -0700184 private boolean mInDialpadSearch;
185 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700186 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700187 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700188 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700189
Yorke Leeef2b7382013-08-09 17:39:25 -0700190 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700191 * Whether or not the device is in landscape orientation.
192 */
193 private boolean mIsLandscape;
194
195 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700196 * The position of the currently selected tab in the attached {@link ListsFragment}.
197 */
198 private int mCurrentTabPosition = 0;
199
200 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700201 * True if the dialpad is only temporarily showing due to being in call
202 */
203 private boolean mInCallDialpadUp;
204
205 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700206 * True when this activity has been launched for the first time.
207 */
Yorke Lee98702de2013-08-06 12:03:32 -0700208 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700209
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700210 /**
211 * Search query to be applied to the SearchView in the ActionBar once
212 * onCreateOptionsMenu has been called.
213 */
214 private String mPendingSearchViewQuery;
215
Yorke Lee53a22302014-04-29 18:13:46 -0700216 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700217 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700218
Yorke Leeef2b7382013-08-09 17:39:25 -0700219 private String mSearchQuery;
220
Yorke Leefce269a2013-08-12 11:56:04 -0700221 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700222 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700223 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700224
225 private String mDescriptionDialButtonStr;
226 private String mActionMenuDialpadButtonStr;
227 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700228 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700229 /**
230 * Additional offset for FAB to be lowered when dialpad is open.
231 */
232 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700233
Andrew Lee2423a2f2014-05-29 14:14:45 -0700234 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700235
Andrew Leee74a10e2014-05-16 14:31:40 -0700236 private class OptionsPopupMenu extends PopupMenu {
237 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700238 super(context, anchor);
239 }
240
241 @Override
242 public void show() {
243 final Menu menu = getMenu();
244 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700245 clearFrequents.setVisible(mListsFragment != null &&
246 mListsFragment.getSpeedDialFragment() != null &&
247 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700248 super.show();
249 }
250 }
251
Chiao Cheng94b10b52012-08-17 16:59:12 -0700252 /**
Yorke Lee28266192014-05-01 10:05:52 -0700253 * Listener that listens to drag events and sends their x and y coordinates to a
254 * {@link DragDropController}.
255 */
256 private class LayoutOnDragListener implements OnDragListener {
257 @Override
258 public boolean onDrag(View v, DragEvent event) {
259 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700260 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700261 }
262 return true;
263 }
264 }
265
266 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700267 * Listener used to send search queries to the phone search fragment.
268 */
Yorke Lee53a22302014-04-29 18:13:46 -0700269 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700270 @Override
271 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
272 }
Yorke Leec3766332013-07-31 11:13:16 -0700273
Andrew Lee99a570c2014-05-15 14:18:50 -0700274 @Override
275 public void onTextChanged(CharSequence s, int start, int before, int count) {
276 final String newText = s.toString();
277 if (newText.equals(mSearchQuery)) {
278 // If the query hasn't changed (perhaps due to activity being destroyed
279 // and restored, or user launching the same DIAL intent twice), then there is
280 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700281 return;
282 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700283 if (DEBUG) {
284 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700285 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700286 }
Yorke Lee710709d2014-05-29 07:18:42 -0700287 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700288
Andrew Lee90374a72014-05-16 15:01:09 -0700289 // Show search fragment only when the query string is changed to non-empty text.
290 if (!TextUtils.isEmpty(newText)) {
291 // Call enterSearchUi only if we are switching search modes, or showing a search
292 // fragment for the first time.
293 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
294 (!mIsDialpadShown && mInRegularSearch);
295 if (!sameSearchMode) {
296 enterSearchUi(mIsDialpadShown, mSearchQuery);
297 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700298 }
299
300 if (mIsDialpadShown && mSmartDialSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700301 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700302 } else if (mRegularSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700303 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700304 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700305 }
306
307 @Override
308 public void afterTextChanged(Editable s) {
309 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700310 };
311
Andrew Leeb1903842014-05-15 16:11:24 -0700312
313 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700314 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700315 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700316 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700317 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700318 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700319 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700320 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700321 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
322 }
Andrew Leeb1903842014-05-15 16:11:24 -0700323 }
324 };
325
326 /**
327 * If the search term is empty and the user closes the soft keyboard, close the search UI.
328 */
329 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
330 @Override
331 public boolean onKey(View v, int keyCode, KeyEvent event) {
332 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
333 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700334 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700335 }
336 return false;
337 }
338 };
339
Chiao Cheng94b10b52012-08-17 16:59:12 -0700340 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700341 protected void onCreate(Bundle savedInstanceState) {
342 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700343 mFirstLaunch = true;
344
Andrew Lee2423a2f2014-05-29 14:14:45 -0700345 final Resources resources = getResources();
346 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700347 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
348 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700349
Yorke Lee8898cd02013-08-08 10:24:27 -0700350 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800351 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700352
Yorke Lee53a22302014-04-29 18:13:46 -0700353 final ActionBar actionBar = getActionBar();
354 actionBar.setCustomView(R.layout.search_edittext);
355 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700356 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700357
Yorke Lee5253be02014-05-21 18:50:03 -0700358 mActionBarController = new ActionBarController(this,
359 (SearchEditTextLayout) actionBar.getCustomView());
360
Yorke Lee53a22302014-04-29 18:13:46 -0700361
Andrew Lee04675a52014-06-05 18:36:20 -0700362 SearchEditTextLayout searchEditTextLayout =
363 (SearchEditTextLayout) actionBar.getCustomView();
364 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
365
366 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700367 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700368 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
369 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
370 .setOnClickListener(mSearchViewOnClickListener);
371 searchEditTextLayout.findViewById(R.id.search_box_start_search)
372 .setOnClickListener(mSearchViewOnClickListener);
373 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700374 @Override
375 public void onBackButtonClicked() {
376 onBackPressed();
377 }
378 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700379
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700380 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700381 == Configuration.ORIENTATION_LANDSCAPE;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700382 final View floatingActionButtonContainer = findViewById(
383 R.id.floating_action_button_container);
384 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
385 int floatingActionButtonWidth = resources.getDimensionPixelSize(
386 R.dimen.floating_action_button_width);
387 mFloatingActionButton.setOnClickListener(this);
388 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700389 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700390 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
391 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700392
Andrew Lee04675a52014-06-05 18:36:20 -0700393 ImageButton optionsMenuButton =
394 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700395 optionsMenuButton.setOnClickListener(this);
396 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
397 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
398
Yorke Leeef2b7382013-08-09 17:39:25 -0700399 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
400 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700401 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800402 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700403 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800404 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
405 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700406 } else {
407 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700408 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
409 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700410 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700411 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700412 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700413 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700414
415 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700416 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700417 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700418 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700419
420 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700421
Andrew Lee0c667702014-05-12 14:31:45 -0700422 parentLayout = (RelativeLayout) findViewById(R.id.dialtacts_mainlayout);
423 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
424 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700425 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700426 new ViewTreeObserver.OnGlobalLayoutListener() {
427 @Override
428 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700429 final ViewTreeObserver observer = floatingActionButtonContainer
430 .getViewTreeObserver();
431 if (!observer.isAlive()) {
432 return;
433 }
434 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700435 int screenWidth = parentLayout.getWidth();
436 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700437 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700438 }
439 });
Andrew Lee0c667702014-05-12 14:31:45 -0700440
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700441 setupActivityOverlay();
442
Yorke Lee0baa98b2013-08-22 10:55:16 -0700443 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700444 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700445 }
446
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700447 private void setupActivityOverlay() {
448 final View activityOverlay = findViewById(R.id.activity_overlay);
449 activityOverlay.setOnTouchListener(new OnTouchListener() {
450 @Override
451 public boolean onTouch(View v, MotionEvent event) {
452 if (!mIsDialpadShown) {
453 maybeExitSearchUi();
454 }
455 return false;
456 }
457 });
458 }
459
Chiao Cheng94b10b52012-08-17 16:59:12 -0700460 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700461 protected void onResume() {
462 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700463 if (mFirstLaunch) {
464 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700465 } else if (!phoneIsInUse() && mInCallDialpadUp) {
466 hideDialpadFragment(false, true);
467 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700468 } else if (mShowDialpadOnResume) {
469 showDialpadFragment(false);
470 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700471 }
472 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700473 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700474 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700475 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700476 }
477
478 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700479 protected void onPause() {
480 if (mClearSearchOnPause) {
481 hideDialpadAndSearchUi();
482 mClearSearchOnPause = false;
483 }
484 super.onPause();
485 }
486
487 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700488 protected void onSaveInstanceState(Bundle outState) {
489 super.onSaveInstanceState(outState);
490 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700491 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
492 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700493 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700494 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700495 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700496 }
497
498 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700499 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700500 if (fragment instanceof DialpadFragment) {
501 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700502 if (!mShowDialpadOnResume) {
503 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
504 transaction.hide(mDialpadFragment);
505 transaction.commit();
506 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700507 } else if (fragment instanceof SmartDialSearchFragment) {
508 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700509 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700510 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700511 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700512 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700513 } else if (fragment instanceof ListsFragment) {
514 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700515 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700516 }
Yorke Leec3766332013-07-31 11:13:16 -0700517 }
518
Alon Albertb453e5b2013-09-10 15:54:23 -0700519 protected void handleMenuSettings() {
520 openTelephonySetting(this);
521 }
522
523 public static void openTelephonySetting(Activity activity) {
524 final Intent settingsIntent = getCallSettingsIntent();
525 activity.startActivity(settingsIntent);
526 }
527
Chiao Cheng94b10b52012-08-17 16:59:12 -0700528 @Override
529 public void onClick(View view) {
530 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700531 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700532 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700533 mInCallDialpadUp = false;
534 showDialpadFragment(true);
535 } else {
536 // Dial button was pressed; tell the Dialpad fragment
537 mDialpadFragment.dialButtonPressed();
538 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700539 break;
Yorke Leec3766332013-07-31 11:13:16 -0700540 case R.id.search_close_button:
541 // Clear the search field
Yorke Lee53a22302014-04-29 18:13:46 -0700542 if (!TextUtils.isEmpty(mSearchView.getText())) {
Yorke Lee2eafb7a2013-09-10 14:34:01 -0700543 mDialpadFragment.clearDialpad();
Yorke Lee53a22302014-04-29 18:13:46 -0700544 mSearchView.setText(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700545 }
546 break;
Yorke Leec3766332013-07-31 11:13:16 -0700547 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800548 try {
549 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
550 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
551 } catch (ActivityNotFoundException e) {
552 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
553 Toast.LENGTH_SHORT).show();
554 }
Yorke Leec3766332013-07-31 11:13:16 -0700555 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700556 case R.id.dialtacts_options_menu_button:
557 buildOptionsMenu(view).show();
558 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700559 default: {
560 Log.wtf(TAG, "Unexpected onClick event from " + view);
561 break;
562 }
563 }
564 }
565
Yorke Leec3766332013-07-31 11:13:16 -0700566 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700567 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700568 switch (item.getItemId()) {
569 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700570 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700571 break;
572 case R.id.menu_add_contact:
573 try {
574 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
575 } catch (ActivityNotFoundException e) {
576 Toast toast = Toast.makeText(this,
577 R.string.add_contact_not_available,
578 Toast.LENGTH_SHORT);
579 toast.show();
580 }
581 break;
582 case R.id.menu_import_export:
583 // We hard-code the "contactsAreAvailable" argument because doing it properly would
584 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
585 // now in Dialtacts for (potential) performance reasons. Compare with how it is
586 // done in {@link PeopleActivity}.
587 ImportExportDialogFragment.show(getFragmentManager(), true,
588 DialtactsActivity.class);
589 return true;
590 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700591 ClearFrequentsDialog.show(getFragmentManager());
592 return true;
593 case R.id.menu_call_settings:
594 handleMenuSettings();
595 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700596 }
597 return false;
598 }
599
600 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700601 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
602 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
603 if (resultCode == RESULT_OK) {
604 final ArrayList<String> matches = data.getStringArrayListExtra(
605 RecognizerIntent.EXTRA_RESULTS);
606 if (matches.size() > 0) {
607 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700608 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700609 } else {
610 Log.e(TAG, "Voice search - nothing heard");
611 }
612 } else {
613 Log.e(TAG, "Voice search failed");
614 }
615 }
616 super.onActivityResult(requestCode, resultCode, data);
617 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700618
Andrew Lee2a58ab82014-05-15 02:16:04 -0700619 /**
620 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
621 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
622 * @see #onDialpadShown
623 */
Yorke Leec3766332013-07-31 11:13:16 -0700624 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700625 if (mIsDialpadShown) {
626 return;
627 }
628 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700629 mDialpadFragment.setAnimate(animate);
630
Chiao Cheng94b10b52012-08-17 16:59:12 -0700631 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700632 ft.show(mDialpadFragment);
633 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700634
Yorke Lee5253be02014-05-21 18:50:03 -0700635 mActionBarController.onDialpadUp();
636
Andrew Leeb1903842014-05-15 16:11:24 -0700637 if (!isInSearchUi()) {
638 enterSearchUi(true /* isSmartDial */, mSearchQuery);
639 }
Yorke Leec3766332013-07-31 11:13:16 -0700640 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700641
Andrew Lee2a58ab82014-05-15 02:16:04 -0700642 /**
643 * Callback from child DialpadFragment when the dialpad is shown.
644 */
645 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700646 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
647 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
648 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700649 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700650 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700651 } else {
652 mDialpadFragment.setYFraction(0);
653 }
654
Andrew Lee2a58ab82014-05-15 02:16:04 -0700655 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700656 }
657
658 /**
659 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
660 * a callback after the hide animation ends.
661 * @see #commitDialpadFragmentHide
662 */
Yorke Leeca195042013-09-25 16:29:38 -0700663 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700664 if (mDialpadFragment == null) {
665 return;
666 }
Yorke Leef6673d32013-08-23 15:34:17 -0700667 if (clearDialpad) {
668 mDialpadFragment.clearDialpad();
669 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700670 if (!mIsDialpadShown) {
671 return;
Yorke Leec3766332013-07-31 11:13:16 -0700672 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700673 mIsDialpadShown = false;
674 mDialpadFragment.setAnimate(animate);
675
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700676 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700677 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
678 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
679
680 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700681 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700682 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700683 } else {
684 commitDialpadFragmentHide();
685 }
686
Yorke Lee5253be02014-05-21 18:50:03 -0700687 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700688
Andrew Leed4cde832014-05-16 15:56:48 -0700689 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700690 if (TextUtils.isEmpty(mSearchQuery)) {
691 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700692 }
Andrew Leed4cde832014-05-16 15:56:48 -0700693 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700694 }
695
696 /**
697 * Finishes hiding the dialpad fragment after any animations are completed.
698 */
699 private void commitDialpadFragmentHide() {
700 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700701 ft.hide(mDialpadFragment);
702 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700703 }
704
Andrew Lee2a58ab82014-05-15 02:16:04 -0700705 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700706 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700707 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700708 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700709 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700710 fragment = mRegularSearchFragment;
711 }
712 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700713 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700714 }
715 }
716
Yorke Lee5253be02014-05-21 18:50:03 -0700717 @Override
718 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700719 return mInDialpadSearch || mInRegularSearch;
720 }
721
Yorke Lee5253be02014-05-21 18:50:03 -0700722 @Override
723 public boolean hasSearchQuery() {
724 return !TextUtils.isEmpty(mSearchQuery);
725 }
726
727 @Override
728 public boolean shouldShowActionBar() {
729 return mListsFragment.shouldShowActionBar();
730 }
731
Yorke Leeb207f8a2013-08-29 18:51:06 -0700732 private void setNotInSearchUi() {
733 mInDialpadSearch = false;
734 mInRegularSearch = false;
735 }
736
Yorke Lee311969c2013-08-26 06:31:11 -0700737 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700738 if (mIsDialpadShown) {
739 hideDialpadFragment(false, true);
740 } else {
741 exitSearchUi();
742 }
Yorke Lee311969c2013-08-26 06:31:11 -0700743 }
744
Yorke Leee00c9fe2014-04-12 12:42:06 -0700745 private void hideInputMethod(View view) {
746 final InputMethodManager imm = (InputMethodManager) getSystemService(
747 Context.INPUT_METHOD_SERVICE);
748 if (imm != null && view != null) {
749 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
750 }
751 }
752
Yorke Lee53a22302014-04-29 18:13:46 -0700753 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700754 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
755 if (canIntentBeHandled(voiceIntent)) {
756 mVoiceSearchButton.setVisibility(View.VISIBLE);
757 mVoiceSearchButton.setOnClickListener(this);
758 } else {
759 mVoiceSearchButton.setVisibility(View.GONE);
760 }
761 }
762
Andrew Leee74a10e2014-05-16 14:31:40 -0700763 private OptionsPopupMenu buildOptionsMenu(View invoker) {
764 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
765 popupMenu.inflate(R.menu.dialtacts_options);
766 popupMenu.setOnMenuItemClickListener(this);
767 return popupMenu;
768 }
769
Yorke Lee86e21f72014-04-02 16:49:38 -0700770 @Override
771 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700772 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700773 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700774 mPendingSearchViewQuery = null;
775 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700776 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700777 }
778
Chiao Cheng94b10b52012-08-17 16:59:12 -0700779 /**
780 * Returns true if the intent is due to hitting the green send key (hardware call button:
781 * KEYCODE_CALL) while in a call.
782 *
783 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700784 * @return true if the intent is due to hitting the green send key while in a call
785 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700786 private boolean isSendKeyWhileInCall(Intent intent) {
787 // If there is a call in progress and the user launched the dialer by hitting the call
788 // button, go straight to the in-call screen.
789 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700790
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700791 if (callKey) {
792 getTelephonyManager().showCallScreen();
793 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700794 }
795
796 return false;
797 }
798
799 /**
800 * Sets the current tab based on the intent's request type
801 *
802 * @param intent Intent that contains information about which tab should be selected
803 */
Yorke Leec3766332013-07-31 11:13:16 -0700804 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700805 // 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 -0700806 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700807 finish();
808 return;
809 }
810
Yorke Lee669b6082013-09-17 15:43:38 -0700811 if (mDialpadFragment != null) {
812 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700813 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700814 mDialpadFragment.setStartedFromNewIntent(true);
815 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
816 mInCallDialpadUp = true;
817 }
818 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700819 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700820 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700821 }
822
823 @Override
824 public void onNewIntent(Intent newIntent) {
825 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700826 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700827
Chiao Cheng94b10b52012-08-17 16:59:12 -0700828 invalidateOptionsMenu();
829 }
830
831 /** Returns true if the given intent contains a phone number to populate the dialer with */
832 private boolean isDialIntent(Intent intent) {
833 final String action = intent.getAction();
834 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
835 return true;
836 }
837 if (Intent.ACTION_VIEW.equals(action)) {
838 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700839 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700840 return true;
841 }
842 }
843 return false;
844 }
845
846 /**
847 * Returns an appropriate call origin for this Activity. May return null when no call origin
848 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
849 * for remembering the tab in which the user made a phone call, so the external app's DIAL
850 * request should not be counted.)
851 */
852 public String getCallOrigin() {
853 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
854 }
855
Chiao Cheng94b10b52012-08-17 16:59:12 -0700856 /**
Yorke Leec3766332013-07-31 11:13:16 -0700857 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700858 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700859 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700860 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700861 // Weird race condition where fragment is doing work after the activity is destroyed
862 // due to talkback being on (b/10209937). Just return since we can't do any
863 // constructive here.
864 return;
865 }
866
Yorke Leeef2b7382013-08-09 17:39:25 -0700867 if (DEBUG) {
868 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
869 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700870
Yorke Leec3766332013-07-31 11:13:16 -0700871 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700872 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700873 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700874 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700875 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700876 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700877
Yorke Leeb207f8a2013-08-29 18:51:06 -0700878 final String tag;
879 if (smartDialSearch) {
880 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
881 } else {
882 tag = TAG_REGULAR_SEARCH_FRAGMENT;
883 }
884 mInDialpadSearch = smartDialSearch;
885 mInRegularSearch = !smartDialSearch;
886
Andrew Lee752956e2014-05-15 11:43:38 -0700887 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700888 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700889 if (fragment == null) {
890 if (smartDialSearch) {
891 fragment = new SmartDialSearchFragment();
892 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700893 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700894 }
Andrew Leeb1903842014-05-15 16:11:24 -0700895 transaction.add(R.id.dialtacts_frame, fragment, tag);
896 } else {
897 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700898 }
Andrew Leeb1903842014-05-15 16:11:24 -0700899
Yorke Lee86e21f72014-04-02 16:49:38 -0700900 // DialtactsActivity will provide the options menu
901 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700902 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700903 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700904 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700905
906 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700907 }
908
909 /**
Yorke Leec3766332013-07-31 11:13:16 -0700910 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700911 */
Yorke Leec3766332013-07-31 11:13:16 -0700912 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700913 // See related bug in enterSearchUI();
914 if (getFragmentManager().isDestroyed()) {
915 return;
916 }
Andrew Leeb1903842014-05-15 16:11:24 -0700917
Andrew Leeb1903842014-05-15 16:11:24 -0700918 mSearchView.setText(null);
919 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700920 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700921
Andrew Leeb1903842014-05-15 16:11:24 -0700922 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700923 if (mSmartDialSearchFragment != null) {
924 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700925 }
Andrew Leeb1903842014-05-15 16:11:24 -0700926 if (mRegularSearchFragment != null) {
927 transaction.remove(mRegularSearchFragment);
928 }
929 transaction.commit();
930
931 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700932 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700933 }
934
935 /** Returns an Intent to launch Call Settings screen */
936 public static Intent getCallSettingsIntent() {
937 final Intent intent = new Intent(Intent.ACTION_MAIN);
938 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
939 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
940 return intent;
941 }
942
943 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700944 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700945 if (mIsDialpadShown) {
Andrew Leeb1903842014-05-15 16:11:24 -0700946 if (TextUtils.isEmpty(mSearchQuery)) {
947 exitSearchUi();
948 }
Yorke Leef6673d32013-08-23 15:34:17 -0700949 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700950 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700951 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700952 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700953 } else {
954 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700955 }
Yorke Leec3766332013-07-31 11:13:16 -0700956 }
957
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700958 /**
959 * @return True if the search UI was exited, false otherwise
960 */
961 private boolean maybeExitSearchUi() {
962 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
963 exitSearchUi();
964 hideInputMethod(parentLayout);
965 return true;
966 }
967 return false;
968 }
969
Yorke Leec3766332013-07-31 11:13:16 -0700970 @Override
971 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700972 if (mSmartDialSearchFragment != null) {
973 mSmartDialSearchFragment.setAddToContactNumber(query);
974 }
Yorke Leec3766332013-07-31 11:13:16 -0700975 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
976 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700977
978 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700979 if (DEBUG) {
980 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
981 }
982 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
983 // This callback can happen if the dialpad fragment is recreated because of
984 // activity destruction. In that case, don't update the search view because
985 // that would bring the user back to the search fragment regardless of the
986 // previous state of the application. Instead, just return here and let the
987 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700988 if (!TextUtils.isEmpty(normalizedQuery)) {
989 mPendingSearchViewQuery = normalizedQuery;
990 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700991 return;
992 }
Yorke Lee53a22302014-04-29 18:13:46 -0700993 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700994 }
995 }
Yorke Leec3766332013-07-31 11:13:16 -0700996
997 @Override
998 public void onListFragmentScrollStateChange(int scrollState) {
999 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001000 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001001 hideInputMethod(getCurrentFocus());
1002 }
1003 }
1004
1005 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001006 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001007 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001008 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1009 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001010 }
1011
Yorke Lee86e21f72014-04-02 16:49:38 -07001012 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001013 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001014 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001015 }
1016
1017 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001018 // TODO(santoscordon): Replace with a TelecommService method call.
1019 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001020 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001021
Yorke Leee1424812013-09-04 18:24:48 -07001022 public static Intent getAddNumberToContactIntent(CharSequence text) {
1023 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1024 intent.putExtra(Intents.Insert.PHONE, text);
1025 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1026 return intent;
1027 }
1028
Yorke Leeda0f9042013-12-05 14:25:51 -08001029 private boolean canIntentBeHandled(Intent intent) {
1030 final PackageManager packageManager = getPackageManager();
1031 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1032 PackageManager.MATCH_DEFAULT_ONLY);
1033 return resolveInfo != null && resolveInfo.size() > 0;
1034 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001035
Yorke Lee6a1461a2014-04-21 16:27:14 -07001036 @Override
1037 public void showCallHistory() {
1038 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1039 // CONTENT_TYPE, so that we always open our call log from our dialer
1040 final Intent intent = new Intent(this, CallLogActivity.class);
1041 startActivity(intent);
1042 }
1043
Yorke Lee86e21f72014-04-02 16:49:38 -07001044 /**
1045 * Called when the user has long-pressed a contact tile to start a drag operation.
1046 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001047 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001048 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001049 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001050 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001051 }
Andrew Lee18963442014-06-06 17:20:13 -07001052 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001053 }
1054
1055 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001056 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1057 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001058
Yorke Lee86e21f72014-04-02 16:49:38 -07001059 /**
1060 * Called when the user has released a contact tile after long-pressing it.
1061 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001062 @Override
1063 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001064 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001065 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001066 }
Andrew Lee18963442014-06-06 17:20:13 -07001067 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001068 }
1069
1070 @Override
1071 public void onDroppedOnRemove() {}
1072
1073 /**
Yorke Leed999b712014-04-23 15:10:58 -07001074 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001075 * once it has been attached to the activity.
1076 */
1077 @Override
1078 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001079 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001080 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001081 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001082
1083 @Override
1084 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001085 // Specify call-origin so that users will see the previous tab instead of
1086 // CallLog screen (search UI will be automatically exited).
1087 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001088 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001089 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001090 }
1091
1092 @Override
1093 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001094 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1095 startActivity(intent);
1096 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001097 }
1098
1099 @Override
1100 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001101 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001102 }
1103
1104 @Override
1105 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001106 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001107 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001108
Yorke Leecc4660d2014-04-24 11:22:57 -07001109 @Override
1110 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001111 // Only scroll the button when the first tab is selected. The button should scroll from
1112 // the middle to right position only on the transition from the first tab to the second
1113 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001114 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001115 mFloatingActionButtonController.onPageScrolled(positionOffset);
1116 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001117 }
1118
1119 @Override
1120 public void onPageSelected(int position) {
1121 mCurrentTabPosition = position;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001122 // Prevents jittery movement when clicking on tabs.
1123 if (mCurrentTabPosition != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1124 mFloatingActionButtonController.manuallyTranslate(
1125 mFloatingActionButtonController.getTranslationXForAlignment(
1126 FloatingActionButtonController.ALIGN_RIGHT), 0);
1127 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001128 }
1129
1130 @Override
1131 public void onPageScrollStateChanged(int state) {
1132 }
1133
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001134 private TelephonyManager getTelephonyManager() {
1135 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1136 }
1137
Yorke Lee5253be02014-05-21 18:50:03 -07001138 @Override
1139 public boolean isActionBarShowing() {
1140 return mActionBarController.isActionBarShowing();
1141 }
1142
Andrew Lee9da8fb42014-06-03 14:03:09 -07001143 public boolean isDialpadShown() {
1144 return mIsDialpadShown;
1145 }
1146
Yorke Lee5253be02014-05-21 18:50:03 -07001147 @Override
1148 public int getActionBarHideOffset() {
1149 return getActionBar().getHideOffset();
1150 }
1151
1152 @Override
1153 public int getActionBarHeight() {
1154 return mActionBarHeight;
1155 }
1156
1157 @Override
1158 public void setActionBarHideOffset(int hideOffset) {
1159 getActionBar().setHideOffset(hideOffset);
1160 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001161
1162 /**
1163 * Updates controller based on currently known information.
1164 *
1165 * @param animate Whether or not to animate the transition.
1166 */
1167 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1168 int align;
1169 if (mIsDialpadShown) {
1170 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1171 : FloatingActionButtonController.ALIGN_MIDDLE;
1172 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001173 if (!mIsLandscape) {
1174 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1175 ? FloatingActionButtonController.ALIGN_MIDDLE
1176 : FloatingActionButtonController.ALIGN_RIGHT;
1177 } else {
1178 align = FloatingActionButtonController.ALIGN_RIGHT;
1179 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001180 }
1181 mFloatingActionButtonController.align(align,
1182 0 /* offsetX */,
1183 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1184 animate);
1185 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001186}