blob: 7e14e228cec3fee71cb924fd692c9807d56b9cf4 [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;
Chiao Cheng94b10b52012-08-17 16:59:12 -070031import android.net.Uri;
32import android.os.Bundle;
Santos Cordond15629d2014-07-07 15:15:29 -070033import android.os.RemoteException;
34import android.os.ServiceManager;
35import android.phone.PhoneManager;
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;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080062import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070063
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070064import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070065import com.android.contacts.common.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070066import com.android.contacts.common.dialog.ClearFrequentsDialog;
67import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080068import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070069import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070070import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070071import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070072import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070073import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070074import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070075import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080076import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070077import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080078import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070079import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070080import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070081import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070082import com.android.dialer.list.RegularSearchFragment;
83import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070084import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee7d20f822014-06-19 17:09:33 -070085import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070086import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070087import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070088import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070089import com.android.dialerbind.DatabaseHelperManager;
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,
Ihab Awad526c0b82014-02-27 12:55:36 -0800101 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700102 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700103 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700104 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700105 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700106 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700107 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700108 ViewPager.OnPageChangeListener,
109 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700110 private static final String TAG = "DialtactsActivity";
111
Ihab Awad526c0b82014-02-27 12:55:36 -0800112 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700113
Ihab Awad1d1bd0d2014-06-30 21:24:01 -0700114 /** Temporary flag for disabling account selection menu */
115 public static final boolean ENABLE_ACCOUNT_SELECT = false;
Nancy Chen8e066292014-06-18 17:16:10 -0700116
Yorke Leef74011e2013-08-02 11:30:30 -0700117 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
118
Chiao Cheng94b10b52012-08-17 16:59:12 -0700119 /** Used to open Call Setting */
120 private static final String PHONE_PACKAGE = "com.android.phone";
121 private static final String CALL_SETTINGS_CLASS_NAME =
122 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700123 /** @see #getCallOrigin() */
124 private static final String CALL_ORIGIN_DIALTACTS =
125 "com.android.dialer.DialtactsActivity";
126
Yorke Leeb207f8a2013-08-29 18:51:06 -0700127 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
128 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700129 private static final String KEY_SEARCH_QUERY = "search_query";
130 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700131 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700132
Yorke Leec3766332013-07-31 11:13:16 -0700133 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
134 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
135 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
136 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700137
Chiao Cheng94b10b52012-08-17 16:59:12 -0700138 /**
139 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
140 */
141 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
142
Yorke Leec3766332013-07-31 11:13:16 -0700143 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700144
Yorke Lee28aab272014-06-11 10:24:19 -0700145 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700146
Yorke Leec3766332013-07-31 11:13:16 -0700147 /**
Yorke Leec3766332013-07-31 11:13:16 -0700148 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700149 */
Yorke Leef74011e2013-08-02 11:30:30 -0700150 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700151
152 /**
153 * Fragment for searching phone numbers using the alphanumeric keyboard.
154 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700155 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700156
157 /**
158 * Fragment for searching phone numbers using the dialpad.
159 */
160 private SmartDialSearchFragment mSmartDialSearchFragment;
161
Yorke Leee00c9fe2014-04-12 12:42:06 -0700162 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700163 * Animation that slides in.
164 */
165 private Animation mSlideIn;
166
167 /**
168 * Animation that slides out.
169 */
170 private Animation mSlideOut;
171
172 /**
173 * Listener for after slide out animation completes on dialer fragment.
174 */
175 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
176 @Override
177 public void onAnimationEnd(Animation animation) {
178 commitDialpadFragmentHide();
179 }
180 };
181
182 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700183 * Fragment containing the speed dial list, recents list, and all contacts list.
184 */
185 private ListsFragment mListsFragment;
186
Yorke Leeb207f8a2013-08-29 18:51:06 -0700187 private boolean mInDialpadSearch;
188 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700189 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700190 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700191 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700192
Yorke Leeef2b7382013-08-09 17:39:25 -0700193 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700194 * Whether or not the device is in landscape orientation.
195 */
196 private boolean mIsLandscape;
197
198 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700199 * The position of the currently selected tab in the attached {@link ListsFragment}.
200 */
201 private int mCurrentTabPosition = 0;
202
203 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700204 * True if the dialpad is only temporarily showing due to being in call
205 */
206 private boolean mInCallDialpadUp;
207
208 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700209 * True when this activity has been launched for the first time.
210 */
Yorke Lee98702de2013-08-06 12:03:32 -0700211 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700212
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700213 /**
214 * Search query to be applied to the SearchView in the ActionBar once
215 * onCreateOptionsMenu has been called.
216 */
217 private String mPendingSearchViewQuery;
218
Yorke Lee53a22302014-04-29 18:13:46 -0700219 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700220 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700221
Yorke Leeef2b7382013-08-09 17:39:25 -0700222 private String mSearchQuery;
223
Yorke Leefce269a2013-08-12 11:56:04 -0700224 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700225 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700226 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700227
228 private String mDescriptionDialButtonStr;
229 private String mActionMenuDialpadButtonStr;
230 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700231 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700232 /**
233 * Additional offset for FAB to be lowered when dialpad is open.
234 */
235 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700236
Andrew Lee2423a2f2014-05-29 14:14:45 -0700237 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700238
Andrew Leee74a10e2014-05-16 14:31:40 -0700239 private class OptionsPopupMenu extends PopupMenu {
240 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700241 super(context, anchor);
242 }
243
244 @Override
245 public void show() {
246 final Menu menu = getMenu();
247 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700248 clearFrequents.setVisible(mListsFragment != null &&
249 mListsFragment.getSpeedDialFragment() != null &&
250 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700251 super.show();
252 }
253 }
254
Chiao Cheng94b10b52012-08-17 16:59:12 -0700255 /**
Yorke Lee28266192014-05-01 10:05:52 -0700256 * Listener that listens to drag events and sends their x and y coordinates to a
257 * {@link DragDropController}.
258 */
259 private class LayoutOnDragListener implements OnDragListener {
260 @Override
261 public boolean onDrag(View v, DragEvent event) {
262 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700263 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700264 }
265 return true;
266 }
267 }
268
269 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700270 * Listener used to send search queries to the phone search fragment.
271 */
Yorke Lee53a22302014-04-29 18:13:46 -0700272 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700273 @Override
274 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
275 }
Yorke Leec3766332013-07-31 11:13:16 -0700276
Andrew Lee99a570c2014-05-15 14:18:50 -0700277 @Override
278 public void onTextChanged(CharSequence s, int start, int before, int count) {
279 final String newText = s.toString();
280 if (newText.equals(mSearchQuery)) {
281 // If the query hasn't changed (perhaps due to activity being destroyed
282 // and restored, or user launching the same DIAL intent twice), then there is
283 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700284 return;
285 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700286 if (DEBUG) {
287 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700288 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700289 }
Yorke Lee710709d2014-05-29 07:18:42 -0700290 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700291
Andrew Lee90374a72014-05-16 15:01:09 -0700292 // Show search fragment only when the query string is changed to non-empty text.
293 if (!TextUtils.isEmpty(newText)) {
294 // Call enterSearchUi only if we are switching search modes, or showing a search
295 // fragment for the first time.
296 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
297 (!mIsDialpadShown && mInRegularSearch);
298 if (!sameSearchMode) {
299 enterSearchUi(mIsDialpadShown, mSearchQuery);
300 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700301 }
302
Andrew Leea8515422014-06-13 16:53:54 -0700303 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700304 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700305 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700306 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700307 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700308 }
309
310 @Override
311 public void afterTextChanged(Editable s) {
312 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700313 };
314
Andrew Leeb1903842014-05-15 16:11:24 -0700315
316 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700317 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700318 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700319 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700320 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700321 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700322 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700323 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700324 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
325 }
Andrew Leeb1903842014-05-15 16:11:24 -0700326 }
327 };
328
329 /**
330 * If the search term is empty and the user closes the soft keyboard, close the search UI.
331 */
332 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
333 @Override
334 public boolean onKey(View v, int keyCode, KeyEvent event) {
335 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
336 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700337 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700338 }
339 return false;
340 }
341 };
342
Chiao Cheng94b10b52012-08-17 16:59:12 -0700343 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700344 protected void onCreate(Bundle savedInstanceState) {
345 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700346 mFirstLaunch = true;
347
Andrew Lee2423a2f2014-05-29 14:14:45 -0700348 final Resources resources = getResources();
349 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700350 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
351 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700352
Yorke Lee8898cd02013-08-08 10:24:27 -0700353 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800354 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700355
Yorke Lee53a22302014-04-29 18:13:46 -0700356 final ActionBar actionBar = getActionBar();
357 actionBar.setCustomView(R.layout.search_edittext);
358 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700359 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700360
Yorke Lee5253be02014-05-21 18:50:03 -0700361 mActionBarController = new ActionBarController(this,
362 (SearchEditTextLayout) actionBar.getCustomView());
363
Andrew Lee04675a52014-06-05 18:36:20 -0700364 SearchEditTextLayout searchEditTextLayout =
365 (SearchEditTextLayout) actionBar.getCustomView();
366 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
367
368 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700369 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700370 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
371 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
372 .setOnClickListener(mSearchViewOnClickListener);
373 searchEditTextLayout.findViewById(R.id.search_box_start_search)
374 .setOnClickListener(mSearchViewOnClickListener);
375 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700376 @Override
377 public void onBackButtonClicked() {
378 onBackPressed();
379 }
380 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700381
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700382 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700383 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700384
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700385 final View floatingActionButtonContainer = findViewById(
386 R.id.floating_action_button_container);
387 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
388 int floatingActionButtonWidth = resources.getDimensionPixelSize(
389 R.dimen.floating_action_button_width);
390 mFloatingActionButton.setOnClickListener(this);
391 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700392 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700393 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
394 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700395
Andrew Lee04675a52014-06-05 18:36:20 -0700396 ImageButton optionsMenuButton =
397 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700398 optionsMenuButton.setOnClickListener(this);
399 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
400 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
401
Yorke Leeef2b7382013-08-09 17:39:25 -0700402 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
403 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700404 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800405 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700406 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800407 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
408 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700409 } else {
410 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700411 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
412 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700413 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700414 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700415 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700416 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700417
418 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700419 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700420 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700421 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700422
423 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700424
Yorke Lee28aab272014-06-11 10:24:19 -0700425 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700426 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
427 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700428 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700429 new ViewTreeObserver.OnGlobalLayoutListener() {
430 @Override
431 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700432 final ViewTreeObserver observer = floatingActionButtonContainer
433 .getViewTreeObserver();
434 if (!observer.isAlive()) {
435 return;
436 }
437 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700438 int screenWidth = parentLayout.getWidth();
439 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700440 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700441 }
442 });
Andrew Lee0c667702014-05-12 14:31:45 -0700443
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700444 setupActivityOverlay();
445
Yorke Lee0baa98b2013-08-22 10:55:16 -0700446 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700447 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700448 }
449
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700450 private void setupActivityOverlay() {
451 final View activityOverlay = findViewById(R.id.activity_overlay);
452 activityOverlay.setOnTouchListener(new OnTouchListener() {
453 @Override
454 public boolean onTouch(View v, MotionEvent event) {
455 if (!mIsDialpadShown) {
456 maybeExitSearchUi();
457 }
458 return false;
459 }
460 });
461 }
462
Chiao Cheng94b10b52012-08-17 16:59:12 -0700463 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700464 protected void onResume() {
465 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700466 if (mFirstLaunch) {
467 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700468 } else if (!phoneIsInUse() && mInCallDialpadUp) {
469 hideDialpadFragment(false, true);
470 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700471 } else if (mShowDialpadOnResume) {
472 showDialpadFragment(false);
473 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700474 }
475 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700476 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700477 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700478 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700479 }
480
481 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700482 protected void onPause() {
483 if (mClearSearchOnPause) {
484 hideDialpadAndSearchUi();
485 mClearSearchOnPause = false;
486 }
487 super.onPause();
488 }
489
490 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700491 protected void onSaveInstanceState(Bundle outState) {
492 super.onSaveInstanceState(outState);
493 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700494 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
495 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700496 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700497 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700498 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700499 }
500
501 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700502 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700503 if (fragment instanceof DialpadFragment) {
504 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700505 if (!mShowDialpadOnResume) {
506 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
507 transaction.hide(mDialpadFragment);
508 transaction.commit();
509 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700510 } else if (fragment instanceof SmartDialSearchFragment) {
511 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700512 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700513 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700514 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700515 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700516 } else if (fragment instanceof ListsFragment) {
517 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700518 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700519 }
Yorke Leec3766332013-07-31 11:13:16 -0700520 }
521
Alon Albertb453e5b2013-09-10 15:54:23 -0700522 protected void handleMenuSettings() {
523 openTelephonySetting(this);
524 }
525
526 public static void openTelephonySetting(Activity activity) {
527 final Intent settingsIntent = getCallSettingsIntent();
528 activity.startActivity(settingsIntent);
529 }
530
Chiao Cheng94b10b52012-08-17 16:59:12 -0700531 @Override
532 public void onClick(View view) {
533 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700534 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700535 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700536 mInCallDialpadUp = false;
537 showDialpadFragment(true);
538 } else {
539 // Dial button was pressed; tell the Dialpad fragment
540 mDialpadFragment.dialButtonPressed();
541 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700542 break;
Yorke Leec3766332013-07-31 11:13:16 -0700543 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800544 try {
545 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
546 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
547 } catch (ActivityNotFoundException e) {
548 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
549 Toast.LENGTH_SHORT).show();
550 }
Yorke Leec3766332013-07-31 11:13:16 -0700551 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700552 case R.id.dialtacts_options_menu_button:
553 buildOptionsMenu(view).show();
554 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700555 default: {
556 Log.wtf(TAG, "Unexpected onClick event from " + view);
557 break;
558 }
559 }
560 }
561
Yorke Leec3766332013-07-31 11:13:16 -0700562 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700563 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700564 switch (item.getItemId()) {
565 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700566 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700567 break;
568 case R.id.menu_add_contact:
569 try {
570 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
571 } catch (ActivityNotFoundException e) {
572 Toast toast = Toast.makeText(this,
573 R.string.add_contact_not_available,
574 Toast.LENGTH_SHORT);
575 toast.show();
576 }
577 break;
578 case R.id.menu_import_export:
579 // We hard-code the "contactsAreAvailable" argument because doing it properly would
580 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
581 // now in Dialtacts for (potential) performance reasons. Compare with how it is
582 // done in {@link PeopleActivity}.
583 ImportExportDialogFragment.show(getFragmentManager(), true,
584 DialtactsActivity.class);
585 return true;
586 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700587 ClearFrequentsDialog.show(getFragmentManager());
588 return true;
589 case R.id.menu_call_settings:
590 handleMenuSettings();
591 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700592 }
593 return false;
594 }
595
596 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700597 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
598 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
599 if (resultCode == RESULT_OK) {
600 final ArrayList<String> matches = data.getStringArrayListExtra(
601 RecognizerIntent.EXTRA_RESULTS);
602 if (matches.size() > 0) {
603 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700604 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700605 } else {
606 Log.e(TAG, "Voice search - nothing heard");
607 }
608 } else {
609 Log.e(TAG, "Voice search failed");
610 }
611 }
612 super.onActivityResult(requestCode, resultCode, data);
613 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700614
Andrew Lee2a58ab82014-05-15 02:16:04 -0700615 /**
616 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
617 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
618 * @see #onDialpadShown
619 */
Yorke Leec3766332013-07-31 11:13:16 -0700620 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700621 if (mIsDialpadShown) {
622 return;
623 }
624 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700625 mDialpadFragment.setAnimate(animate);
626
Chiao Cheng94b10b52012-08-17 16:59:12 -0700627 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700628 ft.show(mDialpadFragment);
629 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700630
Yorke Lee5253be02014-05-21 18:50:03 -0700631 mActionBarController.onDialpadUp();
632
Andrew Leeb1903842014-05-15 16:11:24 -0700633 if (!isInSearchUi()) {
634 enterSearchUi(true /* isSmartDial */, mSearchQuery);
635 }
Yorke Leec3766332013-07-31 11:13:16 -0700636 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700637
Andrew Lee2a58ab82014-05-15 02:16:04 -0700638 /**
639 * Callback from child DialpadFragment when the dialpad is shown.
640 */
641 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700642 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
643 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
644 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700645 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700646 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700647 } else {
648 mDialpadFragment.setYFraction(0);
649 }
650
Andrew Lee2a58ab82014-05-15 02:16:04 -0700651 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700652 }
653
654 /**
655 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
656 * a callback after the hide animation ends.
657 * @see #commitDialpadFragmentHide
658 */
Yorke Leeca195042013-09-25 16:29:38 -0700659 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700660 if (mDialpadFragment == null) {
661 return;
662 }
Yorke Leef6673d32013-08-23 15:34:17 -0700663 if (clearDialpad) {
664 mDialpadFragment.clearDialpad();
665 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700666 if (!mIsDialpadShown) {
667 return;
Yorke Leec3766332013-07-31 11:13:16 -0700668 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700669 mIsDialpadShown = false;
670 mDialpadFragment.setAnimate(animate);
671
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700672 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700673 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
674 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
675
676 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700677 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700678 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700679 } else {
680 commitDialpadFragmentHide();
681 }
682
Yorke Lee5253be02014-05-21 18:50:03 -0700683 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700684
Andrew Leed4cde832014-05-16 15:56:48 -0700685 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700686 if (TextUtils.isEmpty(mSearchQuery)) {
687 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700688 }
Andrew Leed4cde832014-05-16 15:56:48 -0700689 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700690 }
691
692 /**
693 * Finishes hiding the dialpad fragment after any animations are completed.
694 */
695 private void commitDialpadFragmentHide() {
696 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700697 ft.hide(mDialpadFragment);
698 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700699 }
700
Andrew Lee2a58ab82014-05-15 02:16:04 -0700701 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700702 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700703 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700704 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700705 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700706 fragment = mRegularSearchFragment;
707 }
708 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700709 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700710 }
711 }
712
Yorke Lee5253be02014-05-21 18:50:03 -0700713 @Override
714 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700715 return mInDialpadSearch || mInRegularSearch;
716 }
717
Yorke Lee5253be02014-05-21 18:50:03 -0700718 @Override
719 public boolean hasSearchQuery() {
720 return !TextUtils.isEmpty(mSearchQuery);
721 }
722
723 @Override
724 public boolean shouldShowActionBar() {
725 return mListsFragment.shouldShowActionBar();
726 }
727
Yorke Leeb207f8a2013-08-29 18:51:06 -0700728 private void setNotInSearchUi() {
729 mInDialpadSearch = false;
730 mInRegularSearch = false;
731 }
732
Yorke Lee311969c2013-08-26 06:31:11 -0700733 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700734 if (mIsDialpadShown) {
735 hideDialpadFragment(false, true);
736 } else {
737 exitSearchUi();
738 }
Yorke Lee311969c2013-08-26 06:31:11 -0700739 }
740
Yorke Leee00c9fe2014-04-12 12:42:06 -0700741 private void hideInputMethod(View view) {
742 final InputMethodManager imm = (InputMethodManager) getSystemService(
743 Context.INPUT_METHOD_SERVICE);
744 if (imm != null && view != null) {
745 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
746 }
747 }
748
Yorke Lee53a22302014-04-29 18:13:46 -0700749 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700750 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
751 if (canIntentBeHandled(voiceIntent)) {
752 mVoiceSearchButton.setVisibility(View.VISIBLE);
753 mVoiceSearchButton.setOnClickListener(this);
754 } else {
755 mVoiceSearchButton.setVisibility(View.GONE);
756 }
757 }
758
Andrew Leee74a10e2014-05-16 14:31:40 -0700759 private OptionsPopupMenu buildOptionsMenu(View invoker) {
760 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
761 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700762 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700763 popupMenu.setOnMenuItemClickListener(this);
764 return popupMenu;
765 }
766
Yorke Lee86e21f72014-04-02 16:49:38 -0700767 @Override
768 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700769 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700770 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700771 mPendingSearchViewQuery = null;
772 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700773 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700774 }
775
Chiao Cheng94b10b52012-08-17 16:59:12 -0700776 /**
777 * Returns true if the intent is due to hitting the green send key (hardware call button:
778 * KEYCODE_CALL) while in a call.
779 *
780 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700781 * @return true if the intent is due to hitting the green send key while in a call
782 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700783 private boolean isSendKeyWhileInCall(Intent intent) {
784 // If there is a call in progress and the user launched the dialer by hitting the call
785 // button, go straight to the in-call screen.
786 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700787
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700788 if (callKey) {
Santos Cordond15629d2014-07-07 15:15:29 -0700789 getPhoneManager().showCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700790 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700791 }
792
793 return false;
794 }
795
796 /**
797 * Sets the current tab based on the intent's request type
798 *
799 * @param intent Intent that contains information about which tab should be selected
800 */
Yorke Leec3766332013-07-31 11:13:16 -0700801 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700802 // 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 -0700803 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700804 finish();
805 return;
806 }
807
Yorke Lee669b6082013-09-17 15:43:38 -0700808 if (mDialpadFragment != null) {
809 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700810 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700811 mDialpadFragment.setStartedFromNewIntent(true);
812 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
813 mInCallDialpadUp = true;
814 }
815 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700816 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700817 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700818 }
819
820 @Override
821 public void onNewIntent(Intent newIntent) {
822 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700823 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700824
Chiao Cheng94b10b52012-08-17 16:59:12 -0700825 invalidateOptionsMenu();
826 }
827
828 /** Returns true if the given intent contains a phone number to populate the dialer with */
829 private boolean isDialIntent(Intent intent) {
830 final String action = intent.getAction();
831 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
832 return true;
833 }
834 if (Intent.ACTION_VIEW.equals(action)) {
835 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700836 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700837 return true;
838 }
839 }
840 return false;
841 }
842
843 /**
844 * Returns an appropriate call origin for this Activity. May return null when no call origin
845 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
846 * for remembering the tab in which the user made a phone call, so the external app's DIAL
847 * request should not be counted.)
848 */
849 public String getCallOrigin() {
850 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
851 }
852
Chiao Cheng94b10b52012-08-17 16:59:12 -0700853 /**
Yorke Leec3766332013-07-31 11:13:16 -0700854 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700855 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700856 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700857 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700858 // Weird race condition where fragment is doing work after the activity is destroyed
859 // due to talkback being on (b/10209937). Just return since we can't do any
860 // constructive here.
861 return;
862 }
863
Yorke Leeef2b7382013-08-09 17:39:25 -0700864 if (DEBUG) {
865 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
866 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700867
Yorke Leec3766332013-07-31 11:13:16 -0700868 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700869 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700870 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700871 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700872 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700873 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700874
Yorke Leeb207f8a2013-08-29 18:51:06 -0700875 final String tag;
876 if (smartDialSearch) {
877 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
878 } else {
879 tag = TAG_REGULAR_SEARCH_FRAGMENT;
880 }
881 mInDialpadSearch = smartDialSearch;
882 mInRegularSearch = !smartDialSearch;
883
Andrew Lee752956e2014-05-15 11:43:38 -0700884 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700885 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700886 if (fragment == null) {
887 if (smartDialSearch) {
888 fragment = new SmartDialSearchFragment();
889 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700890 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700891 }
Andrew Leeb1903842014-05-15 16:11:24 -0700892 transaction.add(R.id.dialtacts_frame, fragment, tag);
893 } else {
894 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700895 }
Andrew Leeb1903842014-05-15 16:11:24 -0700896
Yorke Lee86e21f72014-04-02 16:49:38 -0700897 // DialtactsActivity will provide the options menu
898 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700899 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700900 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700901 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700902
903 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700904 }
905
906 /**
Yorke Leec3766332013-07-31 11:13:16 -0700907 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700908 */
Yorke Leec3766332013-07-31 11:13:16 -0700909 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700910 // See related bug in enterSearchUI();
911 if (getFragmentManager().isDestroyed()) {
912 return;
913 }
Andrew Leeb1903842014-05-15 16:11:24 -0700914
Andrew Leeb1903842014-05-15 16:11:24 -0700915 mSearchView.setText(null);
916 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700917 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700918
Andrew Leeb1903842014-05-15 16:11:24 -0700919 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700920 if (mSmartDialSearchFragment != null) {
921 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700922 }
Andrew Leeb1903842014-05-15 16:11:24 -0700923 if (mRegularSearchFragment != null) {
924 transaction.remove(mRegularSearchFragment);
925 }
926 transaction.commit();
927
928 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700929 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700930 }
931
932 /** Returns an Intent to launch Call Settings screen */
933 public static Intent getCallSettingsIntent() {
934 final Intent intent = new Intent(Intent.ACTION_MAIN);
935 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
936 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
937 return intent;
938 }
939
940 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700941 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700942 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700943 if (TextUtils.isEmpty(mSearchQuery) ||
944 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
945 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700946 exitSearchUi();
947 }
Yorke Leef6673d32013-08-23 15:34:17 -0700948 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700949 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700950 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700951 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700952 } else {
953 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700954 }
Yorke Leec3766332013-07-31 11:13:16 -0700955 }
956
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700957 /**
958 * @return True if the search UI was exited, false otherwise
959 */
960 private boolean maybeExitSearchUi() {
961 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
962 exitSearchUi();
963 hideInputMethod(parentLayout);
964 return true;
965 }
966 return false;
967 }
968
Yorke Leec3766332013-07-31 11:13:16 -0700969 @Override
970 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700971 if (mSmartDialSearchFragment != null) {
972 mSmartDialSearchFragment.setAddToContactNumber(query);
973 }
Yorke Leec3766332013-07-31 11:13:16 -0700974 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
975 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700976
977 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700978 if (DEBUG) {
979 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
980 }
981 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
982 // This callback can happen if the dialpad fragment is recreated because of
983 // activity destruction. In that case, don't update the search view because
984 // that would bring the user back to the search fragment regardless of the
985 // previous state of the application. Instead, just return here and let the
986 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700987 if (!TextUtils.isEmpty(normalizedQuery)) {
988 mPendingSearchViewQuery = normalizedQuery;
989 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700990 return;
991 }
Yorke Lee53a22302014-04-29 18:13:46 -0700992 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700993 }
994 }
Yorke Leec3766332013-07-31 11:13:16 -0700995
996 @Override
997 public void onListFragmentScrollStateChange(int scrollState) {
998 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700999 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001000 hideInputMethod(getCurrentFocus());
1001 }
1002 }
1003
1004 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001005 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001006 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001007 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1008 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001009 }
1010
Yorke Lee86e21f72014-04-02 16:49:38 -07001011 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001012 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001013 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001014 }
1015
1016 private boolean phoneIsInUse() {
Santos Cordond15629d2014-07-07 15:15:29 -07001017 return getPhoneManager().isInAPhoneCall();
Yorke Leec3766332013-07-31 11:13:16 -07001018 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001019
Yorke Leee1424812013-09-04 18:24:48 -07001020 public static Intent getAddNumberToContactIntent(CharSequence text) {
1021 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1022 intent.putExtra(Intents.Insert.PHONE, text);
1023 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1024 return intent;
1025 }
1026
Yorke Leeda0f9042013-12-05 14:25:51 -08001027 private boolean canIntentBeHandled(Intent intent) {
1028 final PackageManager packageManager = getPackageManager();
1029 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1030 PackageManager.MATCH_DEFAULT_ONLY);
1031 return resolveInfo != null && resolveInfo.size() > 0;
1032 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001033
Yorke Lee6a1461a2014-04-21 16:27:14 -07001034 @Override
1035 public void showCallHistory() {
1036 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1037 // CONTENT_TYPE, so that we always open our call log from our dialer
1038 final Intent intent = new Intent(this, CallLogActivity.class);
1039 startActivity(intent);
1040 }
1041
Yorke Lee86e21f72014-04-02 16:49:38 -07001042 /**
1043 * Called when the user has long-pressed a contact tile to start a drag operation.
1044 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001045 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001046 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001047 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001048 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001049 }
Andrew Lee18963442014-06-06 17:20:13 -07001050 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001051 }
1052
1053 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001054 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1055 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001056
Yorke Lee86e21f72014-04-02 16:49:38 -07001057 /**
1058 * Called when the user has released a contact tile after long-pressing it.
1059 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001060 @Override
1061 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001062 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001063 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001064 }
Andrew Lee18963442014-06-06 17:20:13 -07001065 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001066 }
1067
1068 @Override
1069 public void onDroppedOnRemove() {}
1070
1071 /**
Yorke Leed999b712014-04-23 15:10:58 -07001072 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001073 * once it has been attached to the activity.
1074 */
1075 @Override
1076 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001077 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001078 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001079 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001080
1081 @Override
1082 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001083 // Specify call-origin so that users will see the previous tab instead of
1084 // CallLog screen (search UI will be automatically exited).
1085 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001086 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001087 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001088 }
1089
1090 @Override
1091 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001092 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1093 }
1094
1095 @Override
1096 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001097 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001098 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1099 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001100 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001101 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001102 }
1103
1104 @Override
1105 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001106 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001107 }
1108
1109 @Override
1110 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001111 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001112 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001113
Yorke Leecc4660d2014-04-24 11:22:57 -07001114 @Override
1115 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001116 // Only scroll the button when the first tab is selected. The button should scroll from
1117 // the middle to right position only on the transition from the first tab to the second
1118 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001119 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001120 mFloatingActionButtonController.onPageScrolled(positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001121 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1122 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001123 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001124 }
1125
1126 @Override
1127 public void onPageSelected(int position) {
1128 mCurrentTabPosition = position;
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
Santos Cordond15629d2014-07-07 15:15:29 -07001139 private PhoneManager getPhoneManager() {
1140 return (PhoneManager) getSystemService(Context.PHONE_SERVICE);
1141 }
1142
Yorke Lee5253be02014-05-21 18:50:03 -07001143 @Override
1144 public boolean isActionBarShowing() {
1145 return mActionBarController.isActionBarShowing();
1146 }
1147
Andrew Lee9da8fb42014-06-03 14:03:09 -07001148 public boolean isDialpadShown() {
1149 return mIsDialpadShown;
1150 }
1151
Yorke Lee5253be02014-05-21 18:50:03 -07001152 @Override
1153 public int getActionBarHideOffset() {
1154 return getActionBar().getHideOffset();
1155 }
1156
1157 @Override
1158 public int getActionBarHeight() {
1159 return mActionBarHeight;
1160 }
1161
1162 @Override
1163 public void setActionBarHideOffset(int hideOffset) {
1164 getActionBar().setHideOffset(hideOffset);
1165 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001166
1167 /**
1168 * Updates controller based on currently known information.
1169 *
1170 * @param animate Whether or not to animate the transition.
1171 */
1172 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1173 int align;
1174 if (mIsDialpadShown) {
1175 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1176 : FloatingActionButtonController.ALIGN_MIDDLE;
1177 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001178 if (!mIsLandscape) {
1179 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1180 ? FloatingActionButtonController.ALIGN_MIDDLE
1181 : FloatingActionButtonController.ALIGN_RIGHT;
1182 } else {
1183 align = FloatingActionButtonController.ALIGN_RIGHT;
1184 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001185 }
1186 mFloatingActionButtonController.align(align,
1187 0 /* offsetX */,
1188 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1189 animate);
1190 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001191}