blob: 4145690311dcc6131932aa51c7c7f2a02340c790 [file] [log] [blame]
Chiao Cheng94b10b52012-08-17 16:59:12 -07001/*
Yorke Leec3766332013-07-31 11:13:16 -07002 * Copyright (C) 2013 The Android Open Source Project
Chiao Cheng94b10b52012-08-17 16:59:12 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.dialer;
18
Yorke Leecc4660d2014-04-24 11:22:57 -070019import android.animation.LayoutTransition;
Yorke Lee53a22302014-04-29 18:13:46 -070020import android.app.ActionBar;
Chiao Cheng94b10b52012-08-17 16:59:12 -070021import android.app.Activity;
22import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080024import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070025import android.content.Context;
26import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080027import android.content.pm.PackageManager;
28import android.content.pm.ResolveInfo;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070029import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070030import android.content.res.Resources;
Yorke Lee33932ff2014-04-16 13:34:32 -070031import android.content.res.TypedArray;
Chiao Cheng94b10b52012-08-17 16:59:12 -070032import android.net.Uri;
33import android.os.Bundle;
34import android.os.RemoteException;
35import android.os.ServiceManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070036import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070037import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070038import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070039import android.support.v4.view.ViewPager;
Yorke Leec3766332013-07-31 11:13:16 -070040import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070041import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070043import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070044import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070045import android.view.DragEvent;
Andrew Leeb1903842014-05-15 16:11:24 -070046import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070047import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070049import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070050import android.view.View;
Sai Cheemalapati41460652014-06-02 21:05:39 -070051import android.view.ViewTreeObserver;
Yorke Lee28266192014-05-01 10:05:52 -070052import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070053import android.view.View.OnTouchListener;
Andrew Lee2a58ab82014-05-15 02:16:04 -070054import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070055import android.view.animation.AnimationUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070056import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070057import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070058import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070059import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070060import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070061import android.widget.PopupMenu;
Yorke Leecc4660d2014-04-24 11:22:57 -070062import android.widget.RelativeLayout;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080063import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070064
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070065import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070066import com.android.contacts.common.activity.TransactionSafeActivity;
Andrew Lee3c14bc32014-05-28 15:43:03 -070067import com.android.contacts.common.animation.AnimationListenerAdapter;
Yorke Leec3766332013-07-31 11:13:16 -070068import com.android.contacts.common.dialog.ClearFrequentsDialog;
69import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080070import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Andrew Lee4cbc9732014-04-24 14:38:58 -070071import com.android.contacts.common.util.ViewUtil;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070072import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070073import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070074import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070075import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070076import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070077import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070078import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080079import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070080import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080081import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070082import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070083import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070084import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070085import com.android.dialer.list.RegularSearchFragment;
86import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070087import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee5253be02014-05-21 18:50:03 -070088import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070089import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070090import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070091import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070092
Yorke Leec3766332013-07-31 11:13:16 -070093import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080094import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070095
Chiao Cheng94b10b52012-08-17 16:59:12 -070096/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070097 * The dialer tab's title is 'phone', a more common name (see strings.xml).
98 */
Yorke Leec3766332013-07-31 11:13:16 -070099public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700100 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700101 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800102 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700103 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700104 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700105 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700106 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700107 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700108 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700109 ViewPager.OnPageChangeListener,
110 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700111 private static final String TAG = "DialtactsActivity";
112
Ihab Awad526c0b82014-02-27 12:55:36 -0800113 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700114
Yorke Leef74011e2013-08-02 11:30:30 -0700115 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
116
Chiao Cheng94b10b52012-08-17 16:59:12 -0700117 /** Used to open Call Setting */
118 private static final String PHONE_PACKAGE = "com.android.phone";
119 private static final String CALL_SETTINGS_CLASS_NAME =
120 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700121 /** @see #getCallOrigin() */
122 private static final String CALL_ORIGIN_DIALTACTS =
123 "com.android.dialer.DialtactsActivity";
124
Yorke Leeb207f8a2013-08-29 18:51:06 -0700125 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
126 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700127 private static final String KEY_SEARCH_QUERY = "search_query";
128 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700129 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700130
Yorke Leec3766332013-07-31 11:13:16 -0700131 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
132 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
133 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
134 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700135
Chiao Cheng94b10b52012-08-17 16:59:12 -0700136 /**
137 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
138 */
139 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
140
Yorke Leec3766332013-07-31 11:13:16 -0700141 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700142
Yorke Lee28aab272014-06-11 10:24:19 -0700143 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700144
Yorke Leec3766332013-07-31 11:13:16 -0700145 /**
Yorke Leec3766332013-07-31 11:13:16 -0700146 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700147 */
Yorke Leef74011e2013-08-02 11:30:30 -0700148 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700149
150 /**
151 * Fragment for searching phone numbers using the alphanumeric keyboard.
152 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700153 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700154
155 /**
156 * Fragment for searching phone numbers using the dialpad.
157 */
158 private SmartDialSearchFragment mSmartDialSearchFragment;
159
Yorke Leee00c9fe2014-04-12 12:42:06 -0700160 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700161 * Animation that slides in.
162 */
163 private Animation mSlideIn;
164
165 /**
166 * Animation that slides out.
167 */
168 private Animation mSlideOut;
169
170 /**
171 * Listener for after slide out animation completes on dialer fragment.
172 */
173 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
174 @Override
175 public void onAnimationEnd(Animation animation) {
176 commitDialpadFragmentHide();
177 }
178 };
179
180 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700181 * Fragment containing the speed dial list, recents list, and all contacts list.
182 */
183 private ListsFragment mListsFragment;
184
Yorke Leeb207f8a2013-08-29 18:51:06 -0700185 private boolean mInDialpadSearch;
186 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700187 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700188 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700189 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700190
Yorke Leeef2b7382013-08-09 17:39:25 -0700191 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700192 * Whether or not the device is in landscape orientation.
193 */
194 private boolean mIsLandscape;
195
196 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700197 * The position of the currently selected tab in the attached {@link ListsFragment}.
198 */
199 private int mCurrentTabPosition = 0;
200
201 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700202 * True if the dialpad is only temporarily showing due to being in call
203 */
204 private boolean mInCallDialpadUp;
205
206 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700207 * True when this activity has been launched for the first time.
208 */
Yorke Lee98702de2013-08-06 12:03:32 -0700209 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700210
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700211 /**
212 * Search query to be applied to the SearchView in the ActionBar once
213 * onCreateOptionsMenu has been called.
214 */
215 private String mPendingSearchViewQuery;
216
Yorke Lee53a22302014-04-29 18:13:46 -0700217 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700218 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700219
Yorke Leeef2b7382013-08-09 17:39:25 -0700220 private String mSearchQuery;
221
Yorke Leefce269a2013-08-12 11:56:04 -0700222 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700223 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700224 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700225
226 private String mDescriptionDialButtonStr;
227 private String mActionMenuDialpadButtonStr;
228 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700229 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700230 /**
231 * Additional offset for FAB to be lowered when dialpad is open.
232 */
233 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700234
Andrew Lee2423a2f2014-05-29 14:14:45 -0700235 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700236
Andrew Leee74a10e2014-05-16 14:31:40 -0700237 private class OptionsPopupMenu extends PopupMenu {
238 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700239 super(context, anchor);
240 }
241
242 @Override
243 public void show() {
244 final Menu menu = getMenu();
245 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700246 clearFrequents.setVisible(mListsFragment != null &&
247 mListsFragment.getSpeedDialFragment() != null &&
248 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700249 super.show();
250 }
251 }
252
Chiao Cheng94b10b52012-08-17 16:59:12 -0700253 /**
Yorke Lee28266192014-05-01 10:05:52 -0700254 * Listener that listens to drag events and sends their x and y coordinates to a
255 * {@link DragDropController}.
256 */
257 private class LayoutOnDragListener implements OnDragListener {
258 @Override
259 public boolean onDrag(View v, DragEvent event) {
260 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700261 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700262 }
263 return true;
264 }
265 }
266
267 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700268 * Listener used to send search queries to the phone search fragment.
269 */
Yorke Lee53a22302014-04-29 18:13:46 -0700270 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700271 @Override
272 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
273 }
Yorke Leec3766332013-07-31 11:13:16 -0700274
Andrew Lee99a570c2014-05-15 14:18:50 -0700275 @Override
276 public void onTextChanged(CharSequence s, int start, int before, int count) {
277 final String newText = s.toString();
278 if (newText.equals(mSearchQuery)) {
279 // If the query hasn't changed (perhaps due to activity being destroyed
280 // and restored, or user launching the same DIAL intent twice), then there is
281 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700282 return;
283 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700284 if (DEBUG) {
285 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700286 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700287 }
Yorke Lee710709d2014-05-29 07:18:42 -0700288 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700289
Andrew Lee90374a72014-05-16 15:01:09 -0700290 // Show search fragment only when the query string is changed to non-empty text.
291 if (!TextUtils.isEmpty(newText)) {
292 // Call enterSearchUi only if we are switching search modes, or showing a search
293 // fragment for the first time.
294 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
295 (!mIsDialpadShown && mInRegularSearch);
296 if (!sameSearchMode) {
297 enterSearchUi(mIsDialpadShown, mSearchQuery);
298 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700299 }
300
301 if (mIsDialpadShown && mSmartDialSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700302 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700303 } else if (mRegularSearchFragment != null) {
Andrew Leeb1903842014-05-15 16:11:24 -0700304 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700305 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700306 }
307
308 @Override
309 public void afterTextChanged(Editable s) {
310 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700311 };
312
Andrew Leeb1903842014-05-15 16:11:24 -0700313
314 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700315 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700316 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700317 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700318 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700319 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700320 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700321 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700322 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
323 }
Andrew Leeb1903842014-05-15 16:11:24 -0700324 }
325 };
326
327 /**
328 * If the search term is empty and the user closes the soft keyboard, close the search UI.
329 */
330 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
331 @Override
332 public boolean onKey(View v, int keyCode, KeyEvent event) {
333 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
334 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700335 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700336 }
337 return false;
338 }
339 };
340
Chiao Cheng94b10b52012-08-17 16:59:12 -0700341 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700342 protected void onCreate(Bundle savedInstanceState) {
343 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700344 mFirstLaunch = true;
345
Andrew Lee2423a2f2014-05-29 14:14:45 -0700346 final Resources resources = getResources();
347 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700348 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
349 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700350
Yorke Lee8898cd02013-08-08 10:24:27 -0700351 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800352 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700353
Yorke Lee53a22302014-04-29 18:13:46 -0700354 final ActionBar actionBar = getActionBar();
355 actionBar.setCustomView(R.layout.search_edittext);
356 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700357 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700358
Yorke Lee5253be02014-05-21 18:50:03 -0700359 mActionBarController = new ActionBarController(this,
360 (SearchEditTextLayout) actionBar.getCustomView());
361
Yorke Lee53a22302014-04-29 18:13:46 -0700362
Andrew Lee04675a52014-06-05 18:36:20 -0700363 SearchEditTextLayout searchEditTextLayout =
364 (SearchEditTextLayout) actionBar.getCustomView();
365 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
366
367 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700368 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700369 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
370 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
371 .setOnClickListener(mSearchViewOnClickListener);
372 searchEditTextLayout.findViewById(R.id.search_box_start_search)
373 .setOnClickListener(mSearchViewOnClickListener);
374 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700375 @Override
376 public void onBackButtonClicked() {
377 onBackPressed();
378 }
379 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700380
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700381 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700382 == Configuration.ORIENTATION_LANDSCAPE;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700383 final View floatingActionButtonContainer = findViewById(
384 R.id.floating_action_button_container);
385 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
386 int floatingActionButtonWidth = resources.getDimensionPixelSize(
387 R.dimen.floating_action_button_width);
388 mFloatingActionButton.setOnClickListener(this);
389 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700390 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700391 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
392 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700393
Andrew Lee04675a52014-06-05 18:36:20 -0700394 ImageButton optionsMenuButton =
395 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700396 optionsMenuButton.setOnClickListener(this);
397 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
398 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
399
Yorke Leeef2b7382013-08-09 17:39:25 -0700400 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
401 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700402 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800403 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700404 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800405 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
406 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700407 } else {
408 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700409 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
410 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700411 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700412 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700413 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700414 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700415
416 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700417 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700418 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700419 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700420
421 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700422
Yorke Lee28aab272014-06-11 10:24:19 -0700423 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700424 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
425 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700426 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700427 new ViewTreeObserver.OnGlobalLayoutListener() {
428 @Override
429 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700430 final ViewTreeObserver observer = floatingActionButtonContainer
431 .getViewTreeObserver();
432 if (!observer.isAlive()) {
433 return;
434 }
435 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700436 int screenWidth = parentLayout.getWidth();
437 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700438 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700439 }
440 });
Andrew Lee0c667702014-05-12 14:31:45 -0700441
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700442 setupActivityOverlay();
443
Yorke Lee0baa98b2013-08-22 10:55:16 -0700444 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700445 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700446 }
447
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700448 private void setupActivityOverlay() {
449 final View activityOverlay = findViewById(R.id.activity_overlay);
450 activityOverlay.setOnTouchListener(new OnTouchListener() {
451 @Override
452 public boolean onTouch(View v, MotionEvent event) {
453 if (!mIsDialpadShown) {
454 maybeExitSearchUi();
455 }
456 return false;
457 }
458 });
459 }
460
Chiao Cheng94b10b52012-08-17 16:59:12 -0700461 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700462 protected void onResume() {
463 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700464 if (mFirstLaunch) {
465 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700466 } else if (!phoneIsInUse() && mInCallDialpadUp) {
467 hideDialpadFragment(false, true);
468 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700469 } else if (mShowDialpadOnResume) {
470 showDialpadFragment(false);
471 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700472 }
473 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700474 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700475 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700476 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700477 }
478
479 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700480 protected void onPause() {
481 if (mClearSearchOnPause) {
482 hideDialpadAndSearchUi();
483 mClearSearchOnPause = false;
484 }
485 super.onPause();
486 }
487
488 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700489 protected void onSaveInstanceState(Bundle outState) {
490 super.onSaveInstanceState(outState);
491 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700492 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
493 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700494 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700495 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700496 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700497 }
498
499 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700500 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700501 if (fragment instanceof DialpadFragment) {
502 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700503 if (!mShowDialpadOnResume) {
504 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
505 transaction.hide(mDialpadFragment);
506 transaction.commit();
507 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700508 } else if (fragment instanceof SmartDialSearchFragment) {
509 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700510 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700511 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700512 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700513 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700514 } else if (fragment instanceof ListsFragment) {
515 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700516 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700517 }
Yorke Leec3766332013-07-31 11:13:16 -0700518 }
519
Alon Albertb453e5b2013-09-10 15:54:23 -0700520 protected void handleMenuSettings() {
521 openTelephonySetting(this);
522 }
523
524 public static void openTelephonySetting(Activity activity) {
525 final Intent settingsIntent = getCallSettingsIntent();
526 activity.startActivity(settingsIntent);
527 }
528
Chiao Cheng94b10b52012-08-17 16:59:12 -0700529 @Override
530 public void onClick(View view) {
531 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700532 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700533 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700534 mInCallDialpadUp = false;
535 showDialpadFragment(true);
536 } else {
537 // Dial button was pressed; tell the Dialpad fragment
538 mDialpadFragment.dialButtonPressed();
539 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700540 break;
Yorke Leec3766332013-07-31 11:13:16 -0700541 case R.id.search_close_button:
542 // Clear the search field
Yorke Lee53a22302014-04-29 18:13:46 -0700543 if (!TextUtils.isEmpty(mSearchView.getText())) {
Yorke Lee2eafb7a2013-09-10 14:34:01 -0700544 mDialpadFragment.clearDialpad();
Yorke Lee53a22302014-04-29 18:13:46 -0700545 mSearchView.setText(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700546 }
547 break;
Yorke Leec3766332013-07-31 11:13:16 -0700548 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800549 try {
550 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
551 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
552 } catch (ActivityNotFoundException e) {
553 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
554 Toast.LENGTH_SHORT).show();
555 }
Yorke Leec3766332013-07-31 11:13:16 -0700556 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700557 case R.id.dialtacts_options_menu_button:
558 buildOptionsMenu(view).show();
559 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700560 default: {
561 Log.wtf(TAG, "Unexpected onClick event from " + view);
562 break;
563 }
564 }
565 }
566
Yorke Leec3766332013-07-31 11:13:16 -0700567 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700568 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700569 switch (item.getItemId()) {
570 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700571 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700572 break;
573 case R.id.menu_add_contact:
574 try {
575 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
576 } catch (ActivityNotFoundException e) {
577 Toast toast = Toast.makeText(this,
578 R.string.add_contact_not_available,
579 Toast.LENGTH_SHORT);
580 toast.show();
581 }
582 break;
583 case R.id.menu_import_export:
584 // We hard-code the "contactsAreAvailable" argument because doing it properly would
585 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
586 // now in Dialtacts for (potential) performance reasons. Compare with how it is
587 // done in {@link PeopleActivity}.
588 ImportExportDialogFragment.show(getFragmentManager(), true,
589 DialtactsActivity.class);
590 return true;
591 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700592 ClearFrequentsDialog.show(getFragmentManager());
593 return true;
594 case R.id.menu_call_settings:
595 handleMenuSettings();
596 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700597 }
598 return false;
599 }
600
601 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700602 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
603 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
604 if (resultCode == RESULT_OK) {
605 final ArrayList<String> matches = data.getStringArrayListExtra(
606 RecognizerIntent.EXTRA_RESULTS);
607 if (matches.size() > 0) {
608 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700609 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700610 } else {
611 Log.e(TAG, "Voice search - nothing heard");
612 }
613 } else {
614 Log.e(TAG, "Voice search failed");
615 }
616 }
617 super.onActivityResult(requestCode, resultCode, data);
618 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700619
Andrew Lee2a58ab82014-05-15 02:16:04 -0700620 /**
621 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
622 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
623 * @see #onDialpadShown
624 */
Yorke Leec3766332013-07-31 11:13:16 -0700625 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700626 if (mIsDialpadShown) {
627 return;
628 }
629 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700630 mDialpadFragment.setAnimate(animate);
631
Chiao Cheng94b10b52012-08-17 16:59:12 -0700632 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700633 ft.show(mDialpadFragment);
634 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700635
Yorke Lee5253be02014-05-21 18:50:03 -0700636 mActionBarController.onDialpadUp();
637
Andrew Leeb1903842014-05-15 16:11:24 -0700638 if (!isInSearchUi()) {
639 enterSearchUi(true /* isSmartDial */, mSearchQuery);
640 }
Yorke Leec3766332013-07-31 11:13:16 -0700641 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700642
Andrew Lee2a58ab82014-05-15 02:16:04 -0700643 /**
644 * Callback from child DialpadFragment when the dialpad is shown.
645 */
646 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700647 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
648 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
649 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700650 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700651 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700652 } else {
653 mDialpadFragment.setYFraction(0);
654 }
655
Andrew Lee2a58ab82014-05-15 02:16:04 -0700656 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700657 }
658
659 /**
660 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
661 * a callback after the hide animation ends.
662 * @see #commitDialpadFragmentHide
663 */
Yorke Leeca195042013-09-25 16:29:38 -0700664 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700665 if (mDialpadFragment == null) {
666 return;
667 }
Yorke Leef6673d32013-08-23 15:34:17 -0700668 if (clearDialpad) {
669 mDialpadFragment.clearDialpad();
670 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700671 if (!mIsDialpadShown) {
672 return;
Yorke Leec3766332013-07-31 11:13:16 -0700673 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700674 mIsDialpadShown = false;
675 mDialpadFragment.setAnimate(animate);
676
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700677 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700678 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
679 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
680
681 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700682 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700683 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700684 } else {
685 commitDialpadFragmentHide();
686 }
687
Yorke Lee5253be02014-05-21 18:50:03 -0700688 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700689
Andrew Leed4cde832014-05-16 15:56:48 -0700690 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700691 if (TextUtils.isEmpty(mSearchQuery)) {
692 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700693 }
Andrew Leed4cde832014-05-16 15:56:48 -0700694 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700695 }
696
697 /**
698 * Finishes hiding the dialpad fragment after any animations are completed.
699 */
700 private void commitDialpadFragmentHide() {
701 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700702 ft.hide(mDialpadFragment);
703 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700704 }
705
Andrew Lee2a58ab82014-05-15 02:16:04 -0700706 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700707 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700708 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700709 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700710 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700711 fragment = mRegularSearchFragment;
712 }
713 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700714 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700715 }
716 }
717
Yorke Lee5253be02014-05-21 18:50:03 -0700718 @Override
719 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700720 return mInDialpadSearch || mInRegularSearch;
721 }
722
Yorke Lee5253be02014-05-21 18:50:03 -0700723 @Override
724 public boolean hasSearchQuery() {
725 return !TextUtils.isEmpty(mSearchQuery);
726 }
727
728 @Override
729 public boolean shouldShowActionBar() {
730 return mListsFragment.shouldShowActionBar();
731 }
732
Yorke Leeb207f8a2013-08-29 18:51:06 -0700733 private void setNotInSearchUi() {
734 mInDialpadSearch = false;
735 mInRegularSearch = false;
736 }
737
Yorke Lee311969c2013-08-26 06:31:11 -0700738 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700739 if (mIsDialpadShown) {
740 hideDialpadFragment(false, true);
741 } else {
742 exitSearchUi();
743 }
Yorke Lee311969c2013-08-26 06:31:11 -0700744 }
745
Yorke Leee00c9fe2014-04-12 12:42:06 -0700746 private void hideInputMethod(View view) {
747 final InputMethodManager imm = (InputMethodManager) getSystemService(
748 Context.INPUT_METHOD_SERVICE);
749 if (imm != null && view != null) {
750 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
751 }
752 }
753
Yorke Lee53a22302014-04-29 18:13:46 -0700754 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700755 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
756 if (canIntentBeHandled(voiceIntent)) {
757 mVoiceSearchButton.setVisibility(View.VISIBLE);
758 mVoiceSearchButton.setOnClickListener(this);
759 } else {
760 mVoiceSearchButton.setVisibility(View.GONE);
761 }
762 }
763
Andrew Leee74a10e2014-05-16 14:31:40 -0700764 private OptionsPopupMenu buildOptionsMenu(View invoker) {
765 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
766 popupMenu.inflate(R.menu.dialtacts_options);
767 popupMenu.setOnMenuItemClickListener(this);
768 return popupMenu;
769 }
770
Yorke Lee86e21f72014-04-02 16:49:38 -0700771 @Override
772 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700773 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700774 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700775 mPendingSearchViewQuery = null;
776 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700777 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700778 }
779
Chiao Cheng94b10b52012-08-17 16:59:12 -0700780 /**
781 * Returns true if the intent is due to hitting the green send key (hardware call button:
782 * KEYCODE_CALL) while in a call.
783 *
784 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700785 * @return true if the intent is due to hitting the green send key while in a call
786 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700787 private boolean isSendKeyWhileInCall(Intent intent) {
788 // If there is a call in progress and the user launched the dialer by hitting the call
789 // button, go straight to the in-call screen.
790 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700791
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700792 if (callKey) {
793 getTelephonyManager().showCallScreen();
794 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700795 }
796
797 return false;
798 }
799
800 /**
801 * Sets the current tab based on the intent's request type
802 *
803 * @param intent Intent that contains information about which tab should be selected
804 */
Yorke Leec3766332013-07-31 11:13:16 -0700805 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700806 // 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 -0700807 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700808 finish();
809 return;
810 }
811
Yorke Lee669b6082013-09-17 15:43:38 -0700812 if (mDialpadFragment != null) {
813 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700814 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700815 mDialpadFragment.setStartedFromNewIntent(true);
816 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
817 mInCallDialpadUp = true;
818 }
819 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700820 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700821 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700822 }
823
824 @Override
825 public void onNewIntent(Intent newIntent) {
826 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700827 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700828
Chiao Cheng94b10b52012-08-17 16:59:12 -0700829 invalidateOptionsMenu();
830 }
831
832 /** Returns true if the given intent contains a phone number to populate the dialer with */
833 private boolean isDialIntent(Intent intent) {
834 final String action = intent.getAction();
835 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
836 return true;
837 }
838 if (Intent.ACTION_VIEW.equals(action)) {
839 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700840 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700841 return true;
842 }
843 }
844 return false;
845 }
846
847 /**
848 * Returns an appropriate call origin for this Activity. May return null when no call origin
849 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
850 * for remembering the tab in which the user made a phone call, so the external app's DIAL
851 * request should not be counted.)
852 */
853 public String getCallOrigin() {
854 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
855 }
856
Chiao Cheng94b10b52012-08-17 16:59:12 -0700857 /**
Yorke Leec3766332013-07-31 11:13:16 -0700858 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700859 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700860 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700861 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700862 // Weird race condition where fragment is doing work after the activity is destroyed
863 // due to talkback being on (b/10209937). Just return since we can't do any
864 // constructive here.
865 return;
866 }
867
Yorke Leeef2b7382013-08-09 17:39:25 -0700868 if (DEBUG) {
869 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
870 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700871
Yorke Leec3766332013-07-31 11:13:16 -0700872 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700873 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700874 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700875 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700876 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700877 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700878
Yorke Leeb207f8a2013-08-29 18:51:06 -0700879 final String tag;
880 if (smartDialSearch) {
881 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
882 } else {
883 tag = TAG_REGULAR_SEARCH_FRAGMENT;
884 }
885 mInDialpadSearch = smartDialSearch;
886 mInRegularSearch = !smartDialSearch;
887
Andrew Lee752956e2014-05-15 11:43:38 -0700888 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700889 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700890 if (fragment == null) {
891 if (smartDialSearch) {
892 fragment = new SmartDialSearchFragment();
893 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700894 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700895 }
Andrew Leeb1903842014-05-15 16:11:24 -0700896 transaction.add(R.id.dialtacts_frame, fragment, tag);
897 } else {
898 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700899 }
Andrew Leeb1903842014-05-15 16:11:24 -0700900
Yorke Lee86e21f72014-04-02 16:49:38 -0700901 // DialtactsActivity will provide the options menu
902 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700903 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700904 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700905 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700906
907 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700908 }
909
910 /**
Yorke Leec3766332013-07-31 11:13:16 -0700911 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700912 */
Yorke Leec3766332013-07-31 11:13:16 -0700913 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700914 // See related bug in enterSearchUI();
915 if (getFragmentManager().isDestroyed()) {
916 return;
917 }
Andrew Leeb1903842014-05-15 16:11:24 -0700918
Andrew Leeb1903842014-05-15 16:11:24 -0700919 mSearchView.setText(null);
920 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700921 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700922
Andrew Leeb1903842014-05-15 16:11:24 -0700923 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700924 if (mSmartDialSearchFragment != null) {
925 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700926 }
Andrew Leeb1903842014-05-15 16:11:24 -0700927 if (mRegularSearchFragment != null) {
928 transaction.remove(mRegularSearchFragment);
929 }
930 transaction.commit();
931
932 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700933 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700934 }
935
936 /** Returns an Intent to launch Call Settings screen */
937 public static Intent getCallSettingsIntent() {
938 final Intent intent = new Intent(Intent.ACTION_MAIN);
939 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
940 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
941 return intent;
942 }
943
944 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700945 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700946 if (mIsDialpadShown) {
Andrew Leeb1903842014-05-15 16:11:24 -0700947 if (TextUtils.isEmpty(mSearchQuery)) {
948 exitSearchUi();
949 }
Yorke Leef6673d32013-08-23 15:34:17 -0700950 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700951 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700952 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700953 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700954 } else {
955 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700956 }
Yorke Leec3766332013-07-31 11:13:16 -0700957 }
958
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700959 /**
960 * @return True if the search UI was exited, false otherwise
961 */
962 private boolean maybeExitSearchUi() {
963 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
964 exitSearchUi();
965 hideInputMethod(parentLayout);
966 return true;
967 }
968 return false;
969 }
970
Yorke Leec3766332013-07-31 11:13:16 -0700971 @Override
972 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700973 if (mSmartDialSearchFragment != null) {
974 mSmartDialSearchFragment.setAddToContactNumber(query);
975 }
Yorke Leec3766332013-07-31 11:13:16 -0700976 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
977 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700978
979 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700980 if (DEBUG) {
981 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
982 }
983 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
984 // This callback can happen if the dialpad fragment is recreated because of
985 // activity destruction. In that case, don't update the search view because
986 // that would bring the user back to the search fragment regardless of the
987 // previous state of the application. Instead, just return here and let the
988 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700989 if (!TextUtils.isEmpty(normalizedQuery)) {
990 mPendingSearchViewQuery = normalizedQuery;
991 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700992 return;
993 }
Yorke Lee53a22302014-04-29 18:13:46 -0700994 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700995 }
996 }
Yorke Leec3766332013-07-31 11:13:16 -0700997
998 @Override
999 public void onListFragmentScrollStateChange(int scrollState) {
1000 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001001 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001002 hideInputMethod(getCurrentFocus());
1003 }
1004 }
1005
1006 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001007 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001008 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001009 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1010 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001011 }
1012
Yorke Lee86e21f72014-04-02 16:49:38 -07001013 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001014 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001015 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001016 }
1017
1018 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001019 // TODO(santoscordon): Replace with a TelecommService method call.
1020 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001021 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001022
Yorke Leee1424812013-09-04 18:24:48 -07001023 public static Intent getAddNumberToContactIntent(CharSequence text) {
1024 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1025 intent.putExtra(Intents.Insert.PHONE, text);
1026 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1027 return intent;
1028 }
1029
Yorke Leeda0f9042013-12-05 14:25:51 -08001030 private boolean canIntentBeHandled(Intent intent) {
1031 final PackageManager packageManager = getPackageManager();
1032 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1033 PackageManager.MATCH_DEFAULT_ONLY);
1034 return resolveInfo != null && resolveInfo.size() > 0;
1035 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001036
Yorke Lee6a1461a2014-04-21 16:27:14 -07001037 @Override
1038 public void showCallHistory() {
1039 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1040 // CONTENT_TYPE, so that we always open our call log from our dialer
1041 final Intent intent = new Intent(this, CallLogActivity.class);
1042 startActivity(intent);
1043 }
1044
Yorke Lee86e21f72014-04-02 16:49:38 -07001045 /**
1046 * Called when the user has long-pressed a contact tile to start a drag operation.
1047 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001048 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001049 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001050 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001051 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001052 }
Andrew Lee18963442014-06-06 17:20:13 -07001053 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001054 }
1055
1056 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001057 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1058 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001059
Yorke Lee86e21f72014-04-02 16:49:38 -07001060 /**
1061 * Called when the user has released a contact tile after long-pressing it.
1062 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001063 @Override
1064 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001065 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001066 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001067 }
Andrew Lee18963442014-06-06 17:20:13 -07001068 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001069 }
1070
1071 @Override
1072 public void onDroppedOnRemove() {}
1073
1074 /**
Yorke Leed999b712014-04-23 15:10:58 -07001075 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001076 * once it has been attached to the activity.
1077 */
1078 @Override
1079 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001080 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001081 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001082 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001083
1084 @Override
1085 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001086 // Specify call-origin so that users will see the previous tab instead of
1087 // CallLog screen (search UI will be automatically exited).
1088 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001089 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001090 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001091 }
1092
1093 @Override
1094 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001095 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1096 startActivity(intent);
1097 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001098 }
1099
1100 @Override
1101 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001102 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001103 }
1104
1105 @Override
1106 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001107 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001108 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001109
Yorke Leecc4660d2014-04-24 11:22:57 -07001110 @Override
1111 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001112 // Only scroll the button when the first tab is selected. The button should scroll from
1113 // the middle to right position only on the transition from the first tab to the second
1114 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001115 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001116 mFloatingActionButtonController.onPageScrolled(positionOffset);
1117 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001118 }
1119
1120 @Override
1121 public void onPageSelected(int position) {
1122 mCurrentTabPosition = position;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001123 // Prevents jittery movement when clicking on tabs.
1124 if (mCurrentTabPosition != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1125 mFloatingActionButtonController.manuallyTranslate(
1126 mFloatingActionButtonController.getTranslationXForAlignment(
1127 FloatingActionButtonController.ALIGN_RIGHT), 0);
1128 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001129 }
1130
1131 @Override
1132 public void onPageScrollStateChanged(int state) {
1133 }
1134
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001135 private TelephonyManager getTelephonyManager() {
1136 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1137 }
1138
Yorke Lee5253be02014-05-21 18:50:03 -07001139 @Override
1140 public boolean isActionBarShowing() {
1141 return mActionBarController.isActionBarShowing();
1142 }
1143
Andrew Lee9da8fb42014-06-03 14:03:09 -07001144 public boolean isDialpadShown() {
1145 return mIsDialpadShown;
1146 }
1147
Yorke Lee5253be02014-05-21 18:50:03 -07001148 @Override
1149 public int getActionBarHideOffset() {
1150 return getActionBar().getHideOffset();
1151 }
1152
1153 @Override
1154 public int getActionBarHeight() {
1155 return mActionBarHeight;
1156 }
1157
1158 @Override
1159 public void setActionBarHideOffset(int hideOffset) {
1160 getActionBar().setHideOffset(hideOffset);
1161 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001162
1163 /**
1164 * Updates controller based on currently known information.
1165 *
1166 * @param animate Whether or not to animate the transition.
1167 */
1168 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1169 int align;
1170 if (mIsDialpadShown) {
1171 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1172 : FloatingActionButtonController.ALIGN_MIDDLE;
1173 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001174 if (!mIsLandscape) {
1175 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1176 ? FloatingActionButtonController.ALIGN_MIDDLE
1177 : FloatingActionButtonController.ALIGN_RIGHT;
1178 } else {
1179 align = FloatingActionButtonController.ALIGN_RIGHT;
1180 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001181 }
1182 mFloatingActionButtonController.align(align,
1183 0 /* offsetX */,
1184 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1185 animate);
1186 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001187}