blob: 1c933504d4243f3666510f4436a1751ea38c216f [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 Lee53a22302014-04-29 18:13:46 -070019import android.app.ActionBar;
Chiao Cheng94b10b52012-08-17 16:59:12 -070020import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070021import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080022import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.content.Context;
24import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080025import android.content.pm.PackageManager;
26import android.content.pm.ResolveInfo;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070027import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070028import android.content.res.Resources;
Chiao Cheng94b10b52012-08-17 16:59:12 -070029import android.net.Uri;
30import android.os.Bundle;
Chiao Cheng94b10b52012-08-17 16:59:12 -070031import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070032import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070033import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070034import android.support.v4.view.ViewPager;
Tyler Gunn9dc924c2014-09-12 09:33:50 -070035import android.telecom.PhoneAccount;
36import android.telecom.TelecomManager;
Yorke Leec3766332013-07-31 11:13:16 -070037import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070038import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070039import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070040import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070041import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070042import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070043import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070044import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070045import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070046import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070047import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070049import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070050import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070051import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070052import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070053import android.view.animation.AnimationUtils;
Yorke Leec3766332013-07-31 11:13:16 -070054import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070055import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070056import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070057import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070058import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080059import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070060
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070061import com.android.contacts.common.CallUtil;
Brian Attwellc311af12014-10-22 18:28:58 -070062import com.android.contacts.common.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070063import com.android.contacts.common.dialog.ClearFrequentsDialog;
64import com.android.contacts.common.interactions.ImportExportDialogFragment;
Nancy Chen0d3a7392014-08-12 14:44:53 -070065import com.android.contacts.common.interactions.TouchPointManager;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080066import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070067import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070068import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070069import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070070import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070071import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070072import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070073import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080074import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070075import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080076import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070077import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070078import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070079import com.android.dialer.list.RegularSearchFragment;
80import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070081import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070082import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070083import com.android.dialer.settings.DialerSettingsActivity;
Yorke Lee7d20f822014-06-19 17:09:33 -070084import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070085import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070086import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070087import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070088import com.android.dialerbind.DatabaseHelperManager;
Yorke Lee2fec47b2014-08-05 18:16:27 -070089import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070090import com.android.phone.common.animation.AnimationListenerAdapter;
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,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700101 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700102 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700103 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700104 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700105 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700106 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700107 ViewPager.OnPageChangeListener,
108 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700109 private static final String TAG = "DialtactsActivity";
110
Ihab Awad526c0b82014-02-27 12:55:36 -0800111 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700112
Yorke Leef74011e2013-08-02 11:30:30 -0700113 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
114
Chiao Cheng94b10b52012-08-17 16:59:12 -0700115 /** @see #getCallOrigin() */
116 private static final String CALL_ORIGIN_DIALTACTS =
117 "com.android.dialer.DialtactsActivity";
118
Yorke Leeb207f8a2013-08-29 18:51:06 -0700119 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
120 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700121 private static final String KEY_SEARCH_QUERY = "search_query";
122 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700123 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700124
Yorke Leec3766332013-07-31 11:13:16 -0700125 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
126 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
127 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
128 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700129
Chiao Cheng94b10b52012-08-17 16:59:12 -0700130 /**
131 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
132 */
133 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
134
Yorke Leec3766332013-07-31 11:13:16 -0700135 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700136
Yorke Leef614f6f2014-10-03 10:44:19 -0700137 private FrameLayout mParentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700138
Yorke Leec3766332013-07-31 11:13:16 -0700139 /**
Yorke Leec3766332013-07-31 11:13:16 -0700140 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700141 */
Yorke Leef74011e2013-08-02 11:30:30 -0700142 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700143
144 /**
145 * Fragment for searching phone numbers using the alphanumeric keyboard.
146 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700147 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700148
149 /**
150 * Fragment for searching phone numbers using the dialpad.
151 */
152 private SmartDialSearchFragment mSmartDialSearchFragment;
153
Yorke Leee00c9fe2014-04-12 12:42:06 -0700154 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700155 * Animation that slides in.
156 */
157 private Animation mSlideIn;
158
159 /**
160 * Animation that slides out.
161 */
162 private Animation mSlideOut;
163
164 /**
165 * Listener for after slide out animation completes on dialer fragment.
166 */
167 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
168 @Override
169 public void onAnimationEnd(Animation animation) {
170 commitDialpadFragmentHide();
171 }
172 };
173
174 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700175 * Fragment containing the speed dial list, recents list, and all contacts list.
176 */
177 private ListsFragment mListsFragment;
178
Yorke Leeb207f8a2013-08-29 18:51:06 -0700179 private boolean mInDialpadSearch;
180 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700181 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700182 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700183 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700184
Yorke Leeef2b7382013-08-09 17:39:25 -0700185 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700186 * Whether or not the device is in landscape orientation.
187 */
188 private boolean mIsLandscape;
189
190 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700191 * The position of the currently selected tab in the attached {@link ListsFragment}.
192 */
193 private int mCurrentTabPosition = 0;
194
195 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700196 * True if the dialpad is only temporarily showing due to being in call
197 */
198 private boolean mInCallDialpadUp;
199
200 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700201 * True when this activity has been launched for the first time.
202 */
Yorke Lee98702de2013-08-06 12:03:32 -0700203 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700204
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700205 /**
206 * Search query to be applied to the SearchView in the ActionBar once
207 * onCreateOptionsMenu has been called.
208 */
209 private String mPendingSearchViewQuery;
210
Yorke Lee74edcdc2014-07-11 16:15:08 -0700211 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700212 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700213 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700214
Yorke Leeef2b7382013-08-09 17:39:25 -0700215 private String mSearchQuery;
216
Yorke Leefce269a2013-08-12 11:56:04 -0700217 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700218 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700219 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700220
Sai Cheemalapati41460652014-06-02 21:05:39 -0700221 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700222
Andrew Lee2423a2f2014-05-29 14:14:45 -0700223 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700224
Andrew Leee74a10e2014-05-16 14:31:40 -0700225 private class OptionsPopupMenu extends PopupMenu {
226 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700227 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700228 }
229
230 @Override
231 public void show() {
232 final Menu menu = getMenu();
233 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700234 clearFrequents.setVisible(mListsFragment != null &&
235 mListsFragment.getSpeedDialFragment() != null &&
236 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700237 super.show();
238 }
239 }
240
Chiao Cheng94b10b52012-08-17 16:59:12 -0700241 /**
Yorke Lee28266192014-05-01 10:05:52 -0700242 * Listener that listens to drag events and sends their x and y coordinates to a
243 * {@link DragDropController}.
244 */
245 private class LayoutOnDragListener implements OnDragListener {
246 @Override
247 public boolean onDrag(View v, DragEvent event) {
248 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700249 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700250 }
251 return true;
252 }
253 }
254
255 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700256 * Listener used to send search queries to the phone search fragment.
257 */
Yorke Lee53a22302014-04-29 18:13:46 -0700258 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700259 @Override
260 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
261 }
Yorke Leec3766332013-07-31 11:13:16 -0700262
Andrew Lee99a570c2014-05-15 14:18:50 -0700263 @Override
264 public void onTextChanged(CharSequence s, int start, int before, int count) {
265 final String newText = s.toString();
266 if (newText.equals(mSearchQuery)) {
267 // If the query hasn't changed (perhaps due to activity being destroyed
268 // and restored, or user launching the same DIAL intent twice), then there is
269 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700270 return;
271 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700272 if (DEBUG) {
273 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700274 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700275 }
Yorke Lee710709d2014-05-29 07:18:42 -0700276 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700277
Andrew Lee90374a72014-05-16 15:01:09 -0700278 // Show search fragment only when the query string is changed to non-empty text.
279 if (!TextUtils.isEmpty(newText)) {
280 // Call enterSearchUi only if we are switching search modes, or showing a search
281 // fragment for the first time.
282 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
283 (!mIsDialpadShown && mInRegularSearch);
284 if (!sameSearchMode) {
285 enterSearchUi(mIsDialpadShown, mSearchQuery);
286 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700287 }
288
Andrew Leea8515422014-06-13 16:53:54 -0700289 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700290 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700291 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700292 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700293 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700294 }
295
296 @Override
297 public void afterTextChanged(Editable s) {
298 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700299 };
300
Andrew Leeb1903842014-05-15 16:11:24 -0700301
302 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700303 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700304 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700305 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700306 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700307 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700308 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700309 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700310 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
311 }
Andrew Leeb1903842014-05-15 16:11:24 -0700312 }
313 };
314
315 /**
316 * If the search term is empty and the user closes the soft keyboard, close the search UI.
317 */
318 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
319 @Override
320 public boolean onKey(View v, int keyCode, KeyEvent event) {
321 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
322 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700323 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700324 }
325 return false;
326 }
327 };
328
Chiao Cheng94b10b52012-08-17 16:59:12 -0700329 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700330 public boolean dispatchTouchEvent(MotionEvent ev) {
331 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
332 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
333 }
334 return super.dispatchTouchEvent(ev);
335
336 }
337
338 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700339 protected void onCreate(Bundle savedInstanceState) {
340 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700341 mFirstLaunch = true;
342
Andrew Lee2423a2f2014-05-29 14:14:45 -0700343 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700344 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700345
Yorke Lee8898cd02013-08-08 10:24:27 -0700346 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800347 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700348
Yorke Lee53a22302014-04-29 18:13:46 -0700349 final ActionBar actionBar = getActionBar();
350 actionBar.setCustomView(R.layout.search_edittext);
351 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700352 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700353
Yorke Lee5253be02014-05-21 18:50:03 -0700354 mActionBarController = new ActionBarController(this,
355 (SearchEditTextLayout) actionBar.getCustomView());
356
Andrew Lee04675a52014-06-05 18:36:20 -0700357 SearchEditTextLayout searchEditTextLayout =
358 (SearchEditTextLayout) actionBar.getCustomView();
359 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
360
361 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700362 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700363 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
364 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
365 .setOnClickListener(mSearchViewOnClickListener);
366 searchEditTextLayout.findViewById(R.id.search_box_start_search)
367 .setOnClickListener(mSearchViewOnClickListener);
368 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700369 @Override
370 public void onBackButtonClicked() {
371 onBackPressed();
372 }
373 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700374
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700375 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700376 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700377
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700378 final View floatingActionButtonContainer = findViewById(
379 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700380 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
381 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700382 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700383 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700384
Andrew Lee04675a52014-06-05 18:36:20 -0700385 ImageButton optionsMenuButton =
386 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700387 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700388 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
389 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700390
Yorke Leeef2b7382013-08-09 17:39:25 -0700391 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
392 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700393 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800394 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700395 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800396 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
397 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700398 } else {
399 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700400 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
401 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700402 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700403 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700404 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700405 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700406
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700407 final boolean isLayoutRtl = DialerUtils.isRtl();
408 if (mIsLandscape) {
409 mSlideIn = AnimationUtils.loadAnimation(this,
410 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
411 mSlideOut = AnimationUtils.loadAnimation(this,
412 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
413 } else {
414 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
415 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
416 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700417
Yorke Lee2fec47b2014-08-05 18:16:27 -0700418 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
419 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
420
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700421 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700422
Yorke Leef614f6f2014-10-03 10:44:19 -0700423 mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
424 mParentLayout.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() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700429 final ViewTreeObserver observer =
430 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700431 if (!observer.isAlive()) {
432 return;
433 }
434 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700435 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700436 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() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700520 final Intent intent = new Intent(this, DialerSettingsActivity.class);
521 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700522 }
523
Chiao Cheng94b10b52012-08-17 16:59:12 -0700524 @Override
525 public void onClick(View view) {
526 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700527 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700528 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700529 mInCallDialpadUp = false;
530 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700531 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700532 break;
Yorke Leec3766332013-07-31 11:13:16 -0700533 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800534 try {
535 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
536 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
537 } catch (ActivityNotFoundException e) {
538 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
539 Toast.LENGTH_SHORT).show();
540 }
Yorke Leec3766332013-07-31 11:13:16 -0700541 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700542 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700543 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700544 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700545 default: {
546 Log.wtf(TAG, "Unexpected onClick event from " + view);
547 break;
548 }
549 }
550 }
551
Yorke Leec3766332013-07-31 11:13:16 -0700552 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700553 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700554 switch (item.getItemId()) {
555 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700556 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700557 break;
558 case R.id.menu_add_contact:
559 try {
560 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
561 } catch (ActivityNotFoundException e) {
562 Toast toast = Toast.makeText(this,
563 R.string.add_contact_not_available,
564 Toast.LENGTH_SHORT);
565 toast.show();
566 }
567 break;
568 case R.id.menu_import_export:
569 // We hard-code the "contactsAreAvailable" argument because doing it properly would
570 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
571 // now in Dialtacts for (potential) performance reasons. Compare with how it is
572 // done in {@link PeopleActivity}.
573 ImportExportDialogFragment.show(getFragmentManager(), true,
574 DialtactsActivity.class);
575 return true;
576 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700577 ClearFrequentsDialog.show(getFragmentManager());
578 return true;
579 case R.id.menu_call_settings:
580 handleMenuSettings();
581 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700582 }
583 return false;
584 }
585
586 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700587 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
588 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
589 if (resultCode == RESULT_OK) {
590 final ArrayList<String> matches = data.getStringArrayListExtra(
591 RecognizerIntent.EXTRA_RESULTS);
592 if (matches.size() > 0) {
593 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700594 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700595 } else {
596 Log.e(TAG, "Voice search - nothing heard");
597 }
598 } else {
599 Log.e(TAG, "Voice search failed");
600 }
601 }
602 super.onActivityResult(requestCode, resultCode, data);
603 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700604
Andrew Lee2a58ab82014-05-15 02:16:04 -0700605 /**
606 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
607 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
608 * @see #onDialpadShown
609 */
Yorke Leec3766332013-07-31 11:13:16 -0700610 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700611 if (mIsDialpadShown) {
612 return;
613 }
614 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700615 mDialpadFragment.setAnimate(animate);
Sai Cheemalapati2d7faf62014-08-04 11:48:50 -0700616 mDialpadFragment.sendScreenView();
Andrew Leecdfa6c62014-05-06 15:33:35 -0700617
Chiao Cheng94b10b52012-08-17 16:59:12 -0700618 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700619 ft.show(mDialpadFragment);
620 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700621
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700622 if (animate) {
623 mFloatingActionButtonController.scaleOut();
624 } else {
625 mFloatingActionButtonController.setVisible(false);
626 }
Yorke Lee5253be02014-05-21 18:50:03 -0700627 mActionBarController.onDialpadUp();
628
Andrew Leeb1903842014-05-15 16:11:24 -0700629 if (!isInSearchUi()) {
630 enterSearchUi(true /* isSmartDial */, mSearchQuery);
631 }
Yorke Leec3766332013-07-31 11:13:16 -0700632 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700633
Andrew Lee2a58ab82014-05-15 02:16:04 -0700634 /**
635 * Callback from child DialpadFragment when the dialpad is shown.
636 */
637 public void onDialpadShown() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700638 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700639 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700640 } else {
641 mDialpadFragment.setYFraction(0);
642 }
643
Andrew Lee2a58ab82014-05-15 02:16:04 -0700644 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700645 }
646
647 /**
648 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
649 * a callback after the hide animation ends.
650 * @see #commitDialpadFragmentHide
651 */
Yorke Leeca195042013-09-25 16:29:38 -0700652 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700653 if (mDialpadFragment == null) {
654 return;
655 }
Yorke Leef6673d32013-08-23 15:34:17 -0700656 if (clearDialpad) {
657 mDialpadFragment.clearDialpad();
658 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700659 if (!mIsDialpadShown) {
660 return;
Yorke Leec3766332013-07-31 11:13:16 -0700661 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700662 mIsDialpadShown = false;
663 mDialpadFragment.setAnimate(animate);
664
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700665 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700666
667 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700668 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700669 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700670 } else {
671 commitDialpadFragmentHide();
672 }
673
Yorke Lee5253be02014-05-21 18:50:03 -0700674 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700675
Andrew Leed4cde832014-05-16 15:56:48 -0700676 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700677 if (TextUtils.isEmpty(mSearchQuery)) {
678 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700679 }
Andrew Leed4cde832014-05-16 15:56:48 -0700680 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700681 }
682
683 /**
684 * Finishes hiding the dialpad fragment after any animations are completed.
685 */
686 private void commitDialpadFragmentHide() {
687 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700688 ft.hide(mDialpadFragment);
689 ft.commit();
Andrew Lee405a6e62014-08-20 15:02:16 -0700690
691 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700692 }
693
Andrew Lee2a58ab82014-05-15 02:16:04 -0700694 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700695 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700696 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700697 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700698 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700699 fragment = mRegularSearchFragment;
700 }
701 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700702 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700703 }
704 }
705
Yorke Lee5253be02014-05-21 18:50:03 -0700706 @Override
707 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700708 return mInDialpadSearch || mInRegularSearch;
709 }
710
Yorke Lee5253be02014-05-21 18:50:03 -0700711 @Override
712 public boolean hasSearchQuery() {
713 return !TextUtils.isEmpty(mSearchQuery);
714 }
715
716 @Override
717 public boolean shouldShowActionBar() {
718 return mListsFragment.shouldShowActionBar();
719 }
720
Yorke Leeb207f8a2013-08-29 18:51:06 -0700721 private void setNotInSearchUi() {
722 mInDialpadSearch = false;
723 mInRegularSearch = false;
724 }
725
Yorke Lee311969c2013-08-26 06:31:11 -0700726 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700727 if (mIsDialpadShown) {
728 hideDialpadFragment(false, true);
729 } else {
730 exitSearchUi();
731 }
Yorke Lee311969c2013-08-26 06:31:11 -0700732 }
733
Yorke Lee53a22302014-04-29 18:13:46 -0700734 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700735 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
736 if (canIntentBeHandled(voiceIntent)) {
737 mVoiceSearchButton.setVisibility(View.VISIBLE);
738 mVoiceSearchButton.setOnClickListener(this);
739 } else {
740 mVoiceSearchButton.setVisibility(View.GONE);
741 }
742 }
743
Andrew Leee74a10e2014-05-16 14:31:40 -0700744 private OptionsPopupMenu buildOptionsMenu(View invoker) {
745 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
746 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700747 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700748 popupMenu.setOnMenuItemClickListener(this);
749 return popupMenu;
750 }
751
Yorke Lee86e21f72014-04-02 16:49:38 -0700752 @Override
753 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700754 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700755 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700756 mPendingSearchViewQuery = null;
757 }
Yorke Leea524ae52014-08-05 18:01:05 -0700758 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700759 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700760 }
761
Chiao Cheng94b10b52012-08-17 16:59:12 -0700762 /**
763 * Returns true if the intent is due to hitting the green send key (hardware call button:
764 * KEYCODE_CALL) while in a call.
765 *
766 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700767 * @return true if the intent is due to hitting the green send key while in a call
768 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700769 private boolean isSendKeyWhileInCall(Intent intent) {
770 // If there is a call in progress and the user launched the dialer by hitting the call
771 // button, go straight to the in-call screen.
772 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700773
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700774 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700775 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700776 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700777 }
778
779 return false;
780 }
781
782 /**
783 * Sets the current tab based on the intent's request type
784 *
785 * @param intent Intent that contains information about which tab should be selected
786 */
Yorke Leec3766332013-07-31 11:13:16 -0700787 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700788 // 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 -0700789 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700790 finish();
791 return;
792 }
793
Yorke Lee669b6082013-09-17 15:43:38 -0700794 if (mDialpadFragment != null) {
795 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700796 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700797 mDialpadFragment.setStartedFromNewIntent(true);
798 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
799 mInCallDialpadUp = true;
800 }
801 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700802 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700803 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700804 }
805
806 @Override
807 public void onNewIntent(Intent newIntent) {
808 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700809 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700810
Chiao Cheng94b10b52012-08-17 16:59:12 -0700811 invalidateOptionsMenu();
812 }
813
814 /** Returns true if the given intent contains a phone number to populate the dialer with */
815 private boolean isDialIntent(Intent intent) {
816 final String action = intent.getAction();
817 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
818 return true;
819 }
820 if (Intent.ACTION_VIEW.equals(action)) {
821 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700822 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700823 return true;
824 }
825 }
826 return false;
827 }
828
829 /**
830 * Returns an appropriate call origin for this Activity. May return null when no call origin
831 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
832 * for remembering the tab in which the user made a phone call, so the external app's DIAL
833 * request should not be counted.)
834 */
835 public String getCallOrigin() {
836 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
837 }
838
Chiao Cheng94b10b52012-08-17 16:59:12 -0700839 /**
Yorke Leec3766332013-07-31 11:13:16 -0700840 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700841 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700842 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700843 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700844 // Weird race condition where fragment is doing work after the activity is destroyed
845 // due to talkback being on (b/10209937). Just return since we can't do any
846 // constructive here.
847 return;
848 }
849
Yorke Leeef2b7382013-08-09 17:39:25 -0700850 if (DEBUG) {
851 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
852 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700853
Yorke Leec3766332013-07-31 11:13:16 -0700854 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700855 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700856 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700857 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700858 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700859 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700860
Yorke Leeb207f8a2013-08-29 18:51:06 -0700861 final String tag;
862 if (smartDialSearch) {
863 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
864 } else {
865 tag = TAG_REGULAR_SEARCH_FRAGMENT;
866 }
867 mInDialpadSearch = smartDialSearch;
868 mInRegularSearch = !smartDialSearch;
869
Andrew Lee752956e2014-05-15 11:43:38 -0700870 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700871 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700872 if (fragment == null) {
873 if (smartDialSearch) {
874 fragment = new SmartDialSearchFragment();
875 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700876 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700877 }
Andrew Leeb1903842014-05-15 16:11:24 -0700878 transaction.add(R.id.dialtacts_frame, fragment, tag);
879 } else {
880 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700881 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700882 // DialtactsActivity will provide the options menu
883 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700884 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700885 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700886 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700887
888 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700889 }
890
891 /**
Yorke Leec3766332013-07-31 11:13:16 -0700892 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700893 */
Yorke Leec3766332013-07-31 11:13:16 -0700894 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700895 // See related bug in enterSearchUI();
896 if (getFragmentManager().isDestroyed()) {
897 return;
898 }
Andrew Leeb1903842014-05-15 16:11:24 -0700899
Andrew Leeb1903842014-05-15 16:11:24 -0700900 mSearchView.setText(null);
901 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700902 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700903
Andrew Leeb1903842014-05-15 16:11:24 -0700904 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700905 if (mSmartDialSearchFragment != null) {
906 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700907 }
Andrew Leeb1903842014-05-15 16:11:24 -0700908 if (mRegularSearchFragment != null) {
909 transaction.remove(mRegularSearchFragment);
910 }
911 transaction.commit();
912
913 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700914 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700915 }
916
917 /** Returns an Intent to launch Call Settings screen */
918 public static Intent getCallSettingsIntent() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700919 final Intent intent = new Intent(TelecomManager.ACTION_SHOW_CALL_SETTINGS);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700920 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
921 return intent;
922 }
923
924 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700925 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700926 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700927 if (TextUtils.isEmpty(mSearchQuery) ||
928 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
929 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700930 exitSearchUi();
931 }
Yorke Leef6673d32013-08-23 15:34:17 -0700932 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700933 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700934 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -0700935 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700936 } else {
937 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700938 }
Yorke Leec3766332013-07-31 11:13:16 -0700939 }
940
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700941 /**
942 * @return True if the search UI was exited, false otherwise
943 */
944 private boolean maybeExitSearchUi() {
945 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
946 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -0700947 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700948 return true;
949 }
950 return false;
951 }
952
Yorke Leec3766332013-07-31 11:13:16 -0700953 @Override
954 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700955 if (mSmartDialSearchFragment != null) {
956 mSmartDialSearchFragment.setAddToContactNumber(query);
957 }
Yorke Leec3766332013-07-31 11:13:16 -0700958 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
959 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700960
961 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700962 if (DEBUG) {
963 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
964 }
965 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
966 // This callback can happen if the dialpad fragment is recreated because of
967 // activity destruction. In that case, don't update the search view because
968 // that would bring the user back to the search fragment regardless of the
969 // previous state of the application. Instead, just return here and let the
970 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700971 if (!TextUtils.isEmpty(normalizedQuery)) {
972 mPendingSearchViewQuery = normalizedQuery;
973 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700974 return;
975 }
Yorke Lee53a22302014-04-29 18:13:46 -0700976 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700977 }
978 }
Yorke Leec3766332013-07-31 11:13:16 -0700979
980 @Override
981 public void onListFragmentScrollStateChange(int scrollState) {
982 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700983 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -0700984 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700985 }
986 }
987
988 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -0700989 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -0700990 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700991 // TODO: No-op for now. This should eventually show/hide the actionBar based on
992 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -0700993 }
994
Yorke Leec3766332013-07-31 11:13:16 -0700995 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700996 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -0700997 }
Yorke Lee8dd62002013-08-08 15:57:20 -0700998
Yorke Leee1424812013-09-04 18:24:48 -0700999 public static Intent getAddNumberToContactIntent(CharSequence text) {
1000 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1001 intent.putExtra(Intents.Insert.PHONE, text);
1002 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1003 return intent;
1004 }
1005
Yorke Leeda0f9042013-12-05 14:25:51 -08001006 private boolean canIntentBeHandled(Intent intent) {
1007 final PackageManager packageManager = getPackageManager();
1008 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1009 PackageManager.MATCH_DEFAULT_ONLY);
1010 return resolveInfo != null && resolveInfo.size() > 0;
1011 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001012
Yorke Lee6a1461a2014-04-21 16:27:14 -07001013 @Override
1014 public void showCallHistory() {
1015 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1016 // CONTENT_TYPE, so that we always open our call log from our dialer
1017 final Intent intent = new Intent(this, CallLogActivity.class);
1018 startActivity(intent);
1019 }
1020
Yorke Lee86e21f72014-04-02 16:49:38 -07001021 /**
1022 * Called when the user has long-pressed a contact tile to start a drag operation.
1023 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001024 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001025 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001026 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001027 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001028 }
Andrew Lee18963442014-06-06 17:20:13 -07001029 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001030 }
1031
1032 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001033 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1034 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001035
Yorke Lee86e21f72014-04-02 16:49:38 -07001036 /**
1037 * Called when the user has released a contact tile after long-pressing it.
1038 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001039 @Override
1040 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001041 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001042 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001043 }
Andrew Lee18963442014-06-06 17:20:13 -07001044 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001045 }
1046
1047 @Override
1048 public void onDroppedOnRemove() {}
1049
1050 /**
Yorke Leed999b712014-04-23 15:10:58 -07001051 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001052 * once it has been attached to the activity.
1053 */
1054 @Override
1055 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001056 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001057 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001058 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001059
1060 @Override
1061 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001062 // Specify call-origin so that users will see the previous tab instead of
1063 // CallLog screen (search UI will be automatically exited).
1064 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001065 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001066 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001067 }
1068
1069 @Override
1070 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001071 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1072 }
1073
1074 @Override
1075 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001076 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001077 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1078 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001079 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001080 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001081 }
1082
1083 @Override
1084 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001085 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001086 }
1087
1088 @Override
1089 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001090 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001091 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001092
Yorke Leecc4660d2014-04-24 11:22:57 -07001093 @Override
1094 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001095 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001096 // Only scroll the button when the first tab is selected. The button should scroll from
1097 // the middle to right position only on the transition from the first tab to the second
1098 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001099 // If the app is in RTL mode, we need to check against the second tab, rather than the
1100 // first. This is because if we are scrolling between the first and second tabs, the
1101 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1102 // reversal of the order of the tabs.
1103 final boolean isLayoutRtl = DialerUtils.isRtl();
1104 final boolean shouldScrollButton = position == (isLayoutRtl
1105 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1106 if (shouldScrollButton && !mIsLandscape) {
1107 mFloatingActionButtonController.onPageScrolled(
1108 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001109 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1110 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001111 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001112 }
1113
1114 @Override
1115 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001116 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001117 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001118 }
1119
1120 @Override
1121 public void onPageScrollStateChanged(int state) {
1122 }
1123
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001124 private TelephonyManager getTelephonyManager() {
1125 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1126 }
1127
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001128 private TelecomManager getTelecomManager() {
1129 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001130 }
1131
Yorke Lee5253be02014-05-21 18:50:03 -07001132 @Override
1133 public boolean isActionBarShowing() {
1134 return mActionBarController.isActionBarShowing();
1135 }
1136
Yorke Leec98a5bb2014-10-28 16:12:05 -07001137 @Override
1138 public ActionBarController getActionBarController() {
1139 return mActionBarController;
1140 }
1141
Andrew Lee9da8fb42014-06-03 14:03:09 -07001142 public boolean isDialpadShown() {
1143 return mIsDialpadShown;
1144 }
1145
Yorke Lee5253be02014-05-21 18:50:03 -07001146 @Override
1147 public int getActionBarHideOffset() {
1148 return getActionBar().getHideOffset();
1149 }
1150
1151 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001152 public void setActionBarHideOffset(int offset) {
1153 getActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001154 }
1155
1156 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001157 public int getActionBarHeight() {
1158 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001159 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001160
1161 /**
1162 * Updates controller based on currently known information.
1163 *
1164 * @param animate Whether or not to animate the transition.
1165 */
1166 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Lee405a6e62014-08-20 15:02:16 -07001167 int align = (!mIsLandscape && mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
1168 FloatingActionButtonController.ALIGN_MIDDLE :
1169 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001170 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001171 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001172}