blob: f9a2f5b2b45a6bf21d24347eaf503dfe15ccbdc6 [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;
Chiao Cheng94b10b52012-08-17 16:59:12 -070033import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070034import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070035import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070036import android.support.v4.view.ViewPager;
Ihab Awad1d1bd0d2014-06-30 21:24:01 -070037import android.telecomm.PhoneAccount;
Yorke Leec3766332013-07-31 11:13:16 -070038import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070039import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070040import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070041import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070043import android.view.DragEvent;
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;
Sai Cheemalapati41460652014-06-02 21:05:39 -070049import android.view.ViewTreeObserver;
Yorke Lee28266192014-05-01 10:05:52 -070050import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070051import android.view.View.OnTouchListener;
Andrew Lee2a58ab82014-05-15 02:16:04 -070052import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070053import android.view.animation.AnimationUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070054import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070055import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070056import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070057import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070058import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070059import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080060import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070061
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070062import com.android.contacts.common.CallUtil;
Ihab Awad1d1bd0d2014-06-30 21:24:01 -070063import com.android.contacts.common.PhoneAccountManager;
Chiao Cheng603ff682012-10-24 15:18:40 -070064import com.android.contacts.common.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070065import com.android.contacts.common.dialog.ClearFrequentsDialog;
Ihab Awad1d1bd0d2014-06-30 21:24:01 -070066import com.android.contacts.common.dialog.SelectAccountDialogFragment;
Yorke Leec3766332013-07-31 11:13:16 -070067import 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 /**
Ihab Awad1d1bd0d2014-06-30 21:24:01 -0700199 * Information about the currently selected account.
Nancy Chenbeededb2014-06-10 18:30:28 -0700200 */
Ihab Awad1d1bd0d2014-06-30 21:24:01 -0700201 private PhoneAccountManager mAccountManager = null;
Nancy Chenbeededb2014-06-10 18:30:28 -0700202
203 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700204 * The position of the currently selected tab in the attached {@link ListsFragment}.
205 */
206 private int mCurrentTabPosition = 0;
207
208 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700209 * True if the dialpad is only temporarily showing due to being in call
210 */
211 private boolean mInCallDialpadUp;
212
213 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700214 * True when this activity has been launched for the first time.
215 */
Yorke Lee98702de2013-08-06 12:03:32 -0700216 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700217
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700218 /**
219 * Search query to be applied to the SearchView in the ActionBar once
220 * onCreateOptionsMenu has been called.
221 */
222 private String mPendingSearchViewQuery;
223
Yorke Lee53a22302014-04-29 18:13:46 -0700224 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700225 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700226
Yorke Leeef2b7382013-08-09 17:39:25 -0700227 private String mSearchQuery;
228
Yorke Leefce269a2013-08-12 11:56:04 -0700229 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700230 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700231 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700232
233 private String mDescriptionDialButtonStr;
234 private String mActionMenuDialpadButtonStr;
235 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700236 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700237 /**
238 * Additional offset for FAB to be lowered when dialpad is open.
239 */
240 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700241
Andrew Lee2423a2f2014-05-29 14:14:45 -0700242 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700243
Andrew Leee74a10e2014-05-16 14:31:40 -0700244 private class OptionsPopupMenu extends PopupMenu {
245 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700246 super(context, anchor);
247 }
248
249 @Override
250 public void show() {
251 final Menu menu = getMenu();
252 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700253 clearFrequents.setVisible(mListsFragment != null &&
254 mListsFragment.getSpeedDialFragment() != null &&
255 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700256 super.show();
257 }
258 }
259
Chiao Cheng94b10b52012-08-17 16:59:12 -0700260 /**
Yorke Lee28266192014-05-01 10:05:52 -0700261 * Listener that listens to drag events and sends their x and y coordinates to a
262 * {@link DragDropController}.
263 */
264 private class LayoutOnDragListener implements OnDragListener {
265 @Override
266 public boolean onDrag(View v, DragEvent event) {
267 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700268 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700269 }
270 return true;
271 }
272 }
273
274 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700275 * Listener used to send search queries to the phone search fragment.
276 */
Yorke Lee53a22302014-04-29 18:13:46 -0700277 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700278 @Override
279 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
280 }
Yorke Leec3766332013-07-31 11:13:16 -0700281
Andrew Lee99a570c2014-05-15 14:18:50 -0700282 @Override
283 public void onTextChanged(CharSequence s, int start, int before, int count) {
284 final String newText = s.toString();
285 if (newText.equals(mSearchQuery)) {
286 // If the query hasn't changed (perhaps due to activity being destroyed
287 // and restored, or user launching the same DIAL intent twice), then there is
288 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700289 return;
290 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700291 if (DEBUG) {
292 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700293 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700294 }
Yorke Lee710709d2014-05-29 07:18:42 -0700295 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700296
Andrew Lee90374a72014-05-16 15:01:09 -0700297 // Show search fragment only when the query string is changed to non-empty text.
298 if (!TextUtils.isEmpty(newText)) {
299 // Call enterSearchUi only if we are switching search modes, or showing a search
300 // fragment for the first time.
301 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
302 (!mIsDialpadShown && mInRegularSearch);
303 if (!sameSearchMode) {
304 enterSearchUi(mIsDialpadShown, mSearchQuery);
305 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700306 }
307
Andrew Leea8515422014-06-13 16:53:54 -0700308 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700309 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700310 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700311 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700312 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700313 }
314
315 @Override
316 public void afterTextChanged(Editable s) {
317 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700318 };
319
Andrew Leeb1903842014-05-15 16:11:24 -0700320
321 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700322 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700323 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700324 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700325 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700326 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700327 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700328 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700329 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
330 }
Andrew Leeb1903842014-05-15 16:11:24 -0700331 }
332 };
333
334 /**
335 * If the search term is empty and the user closes the soft keyboard, close the search UI.
336 */
337 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
338 @Override
339 public boolean onKey(View v, int keyCode, KeyEvent event) {
340 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
341 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700342 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700343 }
344 return false;
345 }
346 };
347
Chiao Cheng94b10b52012-08-17 16:59:12 -0700348 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700349 protected void onCreate(Bundle savedInstanceState) {
350 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700351 mFirstLaunch = true;
352
Andrew Lee2423a2f2014-05-29 14:14:45 -0700353 final Resources resources = getResources();
354 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700355 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
356 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700357
Yorke Lee8898cd02013-08-08 10:24:27 -0700358 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800359 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700360
Yorke Lee53a22302014-04-29 18:13:46 -0700361 final ActionBar actionBar = getActionBar();
362 actionBar.setCustomView(R.layout.search_edittext);
363 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700364 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700365
Yorke Lee5253be02014-05-21 18:50:03 -0700366 mActionBarController = new ActionBarController(this,
367 (SearchEditTextLayout) actionBar.getCustomView());
368
Andrew Lee04675a52014-06-05 18:36:20 -0700369 SearchEditTextLayout searchEditTextLayout =
370 (SearchEditTextLayout) actionBar.getCustomView();
371 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
372
373 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700374 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700375 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
376 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
377 .setOnClickListener(mSearchViewOnClickListener);
378 searchEditTextLayout.findViewById(R.id.search_box_start_search)
379 .setOnClickListener(mSearchViewOnClickListener);
380 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700381 @Override
382 public void onBackButtonClicked() {
383 onBackPressed();
384 }
385 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700386
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700387 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700388 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700389
Ihab Awad1d1bd0d2014-06-30 21:24:01 -0700390 if (getTelephonyManager().getAccounts().size() > 1 && ENABLE_ACCOUNT_SELECT) {
391 mAccountManager = new PhoneAccountManager(getTelephonyManager());
Nancy Chen8e066292014-06-18 17:16:10 -0700392 }
393
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700394 final View floatingActionButtonContainer = findViewById(
395 R.id.floating_action_button_container);
396 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
397 int floatingActionButtonWidth = resources.getDimensionPixelSize(
398 R.dimen.floating_action_button_width);
399 mFloatingActionButton.setOnClickListener(this);
400 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700401 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700402 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
403 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700404
Andrew Lee04675a52014-06-05 18:36:20 -0700405 ImageButton optionsMenuButton =
406 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700407 optionsMenuButton.setOnClickListener(this);
408 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
409 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
410
Yorke Leeef2b7382013-08-09 17:39:25 -0700411 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
412 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700413 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800414 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700415 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800416 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
417 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700418 } else {
419 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700420 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
421 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700422 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700423 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700424 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700425 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700426
427 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700428 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700429 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700430 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700431
432 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700433
Yorke Lee28aab272014-06-11 10:24:19 -0700434 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700435 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
436 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700437 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700438 new ViewTreeObserver.OnGlobalLayoutListener() {
439 @Override
440 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700441 final ViewTreeObserver observer = floatingActionButtonContainer
442 .getViewTreeObserver();
443 if (!observer.isAlive()) {
444 return;
445 }
446 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700447 int screenWidth = parentLayout.getWidth();
448 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700449 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700450 }
451 });
Andrew Lee0c667702014-05-12 14:31:45 -0700452
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700453 setupActivityOverlay();
454
Yorke Lee0baa98b2013-08-22 10:55:16 -0700455 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700456 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700457 }
458
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700459 private void setupActivityOverlay() {
460 final View activityOverlay = findViewById(R.id.activity_overlay);
461 activityOverlay.setOnTouchListener(new OnTouchListener() {
462 @Override
463 public boolean onTouch(View v, MotionEvent event) {
464 if (!mIsDialpadShown) {
465 maybeExitSearchUi();
466 }
467 return false;
468 }
469 });
470 }
471
Chiao Cheng94b10b52012-08-17 16:59:12 -0700472 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700473 protected void onResume() {
474 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700475 if (mFirstLaunch) {
476 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700477 } else if (!phoneIsInUse() && mInCallDialpadUp) {
478 hideDialpadFragment(false, true);
479 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700480 } else if (mShowDialpadOnResume) {
481 showDialpadFragment(false);
482 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700483 }
484 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700485 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700486 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700487 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700488 }
489
490 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700491 protected void onPause() {
492 if (mClearSearchOnPause) {
493 hideDialpadAndSearchUi();
494 mClearSearchOnPause = false;
495 }
496 super.onPause();
497 }
498
499 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700500 protected void onSaveInstanceState(Bundle outState) {
501 super.onSaveInstanceState(outState);
502 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700503 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
504 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700505 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700506 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700507 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700508 }
509
510 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700511 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700512 if (fragment instanceof DialpadFragment) {
513 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700514 if (!mShowDialpadOnResume) {
515 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
516 transaction.hide(mDialpadFragment);
517 transaction.commit();
518 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700519 } else if (fragment instanceof SmartDialSearchFragment) {
520 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700521 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700522 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700523 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700524 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700525 } else if (fragment instanceof ListsFragment) {
526 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700527 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700528 }
Yorke Leec3766332013-07-31 11:13:16 -0700529 }
530
Alon Albertb453e5b2013-09-10 15:54:23 -0700531 protected void handleMenuSettings() {
532 openTelephonySetting(this);
533 }
534
535 public static void openTelephonySetting(Activity activity) {
536 final Intent settingsIntent = getCallSettingsIntent();
537 activity.startActivity(settingsIntent);
538 }
539
Chiao Cheng94b10b52012-08-17 16:59:12 -0700540 @Override
541 public void onClick(View view) {
542 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700543 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700544 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700545 mInCallDialpadUp = false;
546 showDialpadFragment(true);
547 } else {
548 // Dial button was pressed; tell the Dialpad fragment
549 mDialpadFragment.dialButtonPressed();
550 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700551 break;
Yorke Leec3766332013-07-31 11:13:16 -0700552 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800553 try {
554 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
555 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
556 } catch (ActivityNotFoundException e) {
557 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
558 Toast.LENGTH_SHORT).show();
559 }
Yorke Leec3766332013-07-31 11:13:16 -0700560 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700561 case R.id.dialtacts_options_menu_button:
562 buildOptionsMenu(view).show();
563 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700564 default: {
565 Log.wtf(TAG, "Unexpected onClick event from " + view);
566 break;
567 }
568 }
569 }
570
Yorke Leec3766332013-07-31 11:13:16 -0700571 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700572 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700573 switch (item.getItemId()) {
574 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700575 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700576 break;
577 case R.id.menu_add_contact:
578 try {
579 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
580 } catch (ActivityNotFoundException e) {
581 Toast toast = Toast.makeText(this,
582 R.string.add_contact_not_available,
583 Toast.LENGTH_SHORT);
584 toast.show();
585 }
586 break;
587 case R.id.menu_import_export:
588 // We hard-code the "contactsAreAvailable" argument because doing it properly would
589 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
590 // now in Dialtacts for (potential) performance reasons. Compare with how it is
591 // done in {@link PeopleActivity}.
592 ImportExportDialogFragment.show(getFragmentManager(), true,
593 DialtactsActivity.class);
594 return true;
595 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700596 ClearFrequentsDialog.show(getFragmentManager());
597 return true;
598 case R.id.menu_call_settings:
599 handleMenuSettings();
600 return true;
Ihab Awad1d1bd0d2014-06-30 21:24:01 -0700601 case R.id.menu_select_account:
602 SelectAccountDialogFragment.show(getFragmentManager(), mAccountManager);
Nancy Chenbeededb2014-06-10 18:30:28 -0700603 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700604 }
605 return false;
606 }
607
608 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700609 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
610 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
611 if (resultCode == RESULT_OK) {
612 final ArrayList<String> matches = data.getStringArrayListExtra(
613 RecognizerIntent.EXTRA_RESULTS);
614 if (matches.size() > 0) {
615 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700616 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700617 } else {
618 Log.e(TAG, "Voice search - nothing heard");
619 }
620 } else {
621 Log.e(TAG, "Voice search failed");
622 }
623 }
624 super.onActivityResult(requestCode, resultCode, data);
625 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700626
Andrew Lee2a58ab82014-05-15 02:16:04 -0700627 /**
628 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
629 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
630 * @see #onDialpadShown
631 */
Yorke Leec3766332013-07-31 11:13:16 -0700632 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700633 if (mIsDialpadShown) {
634 return;
635 }
636 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700637 mDialpadFragment.setAnimate(animate);
Ihab Awad1d1bd0d2014-06-30 21:24:01 -0700638 mDialpadFragment.setAccountManager(mAccountManager);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700639
Chiao Cheng94b10b52012-08-17 16:59:12 -0700640 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700641 ft.show(mDialpadFragment);
642 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700643
Yorke Lee5253be02014-05-21 18:50:03 -0700644 mActionBarController.onDialpadUp();
645
Andrew Leeb1903842014-05-15 16:11:24 -0700646 if (!isInSearchUi()) {
647 enterSearchUi(true /* isSmartDial */, mSearchQuery);
648 }
Yorke Leec3766332013-07-31 11:13:16 -0700649 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700650
Andrew Lee2a58ab82014-05-15 02:16:04 -0700651 /**
652 * Callback from child DialpadFragment when the dialpad is shown.
653 */
654 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700655 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
656 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
657 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700658 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700659 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700660 } else {
661 mDialpadFragment.setYFraction(0);
662 }
663
Andrew Lee2a58ab82014-05-15 02:16:04 -0700664 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700665 }
666
667 /**
668 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
669 * a callback after the hide animation ends.
670 * @see #commitDialpadFragmentHide
671 */
Yorke Leeca195042013-09-25 16:29:38 -0700672 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700673 if (mDialpadFragment == null) {
674 return;
675 }
Yorke Leef6673d32013-08-23 15:34:17 -0700676 if (clearDialpad) {
677 mDialpadFragment.clearDialpad();
678 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700679 if (!mIsDialpadShown) {
680 return;
Yorke Leec3766332013-07-31 11:13:16 -0700681 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700682 mIsDialpadShown = false;
683 mDialpadFragment.setAnimate(animate);
684
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700685 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700686 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
687 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
688
689 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700690 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700691 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700692 } else {
693 commitDialpadFragmentHide();
694 }
695
Yorke Lee5253be02014-05-21 18:50:03 -0700696 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700697
Andrew Leed4cde832014-05-16 15:56:48 -0700698 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700699 if (TextUtils.isEmpty(mSearchQuery)) {
700 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700701 }
Andrew Leed4cde832014-05-16 15:56:48 -0700702 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700703 }
704
705 /**
706 * Finishes hiding the dialpad fragment after any animations are completed.
707 */
708 private void commitDialpadFragmentHide() {
709 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700710 ft.hide(mDialpadFragment);
711 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700712 }
713
Andrew Lee2a58ab82014-05-15 02:16:04 -0700714 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700715 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700716 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700717 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700718 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700719 fragment = mRegularSearchFragment;
720 }
721 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700722 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700723 }
724 }
725
Yorke Lee5253be02014-05-21 18:50:03 -0700726 @Override
727 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700728 return mInDialpadSearch || mInRegularSearch;
729 }
730
Yorke Lee5253be02014-05-21 18:50:03 -0700731 @Override
732 public boolean hasSearchQuery() {
733 return !TextUtils.isEmpty(mSearchQuery);
734 }
735
736 @Override
737 public boolean shouldShowActionBar() {
738 return mListsFragment.shouldShowActionBar();
739 }
740
Yorke Leeb207f8a2013-08-29 18:51:06 -0700741 private void setNotInSearchUi() {
742 mInDialpadSearch = false;
743 mInRegularSearch = false;
744 }
745
Yorke Lee311969c2013-08-26 06:31:11 -0700746 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700747 if (mIsDialpadShown) {
748 hideDialpadFragment(false, true);
749 } else {
750 exitSearchUi();
751 }
Yorke Lee311969c2013-08-26 06:31:11 -0700752 }
753
Yorke Leee00c9fe2014-04-12 12:42:06 -0700754 private void hideInputMethod(View view) {
755 final InputMethodManager imm = (InputMethodManager) getSystemService(
756 Context.INPUT_METHOD_SERVICE);
757 if (imm != null && view != null) {
758 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
759 }
760 }
761
Yorke Lee53a22302014-04-29 18:13:46 -0700762 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700763 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
764 if (canIntentBeHandled(voiceIntent)) {
765 mVoiceSearchButton.setVisibility(View.VISIBLE);
766 mVoiceSearchButton.setOnClickListener(this);
767 } else {
768 mVoiceSearchButton.setVisibility(View.GONE);
769 }
770 }
771
Andrew Leee74a10e2014-05-16 14:31:40 -0700772 private OptionsPopupMenu buildOptionsMenu(View invoker) {
773 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
774 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700775 final Menu menu = popupMenu.getMenu();
Ihab Awad1d1bd0d2014-06-30 21:24:01 -0700776 final MenuItem selectAccount = menu.findItem(R.id.menu_select_account);
777 selectAccount.setVisible(mAccountManager != null);
Andrew Leee74a10e2014-05-16 14:31:40 -0700778 popupMenu.setOnMenuItemClickListener(this);
779 return popupMenu;
780 }
781
Yorke Lee86e21f72014-04-02 16:49:38 -0700782 @Override
783 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700784 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700785 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700786 mPendingSearchViewQuery = null;
787 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700788 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700789 }
790
Chiao Cheng94b10b52012-08-17 16:59:12 -0700791 /**
792 * Returns true if the intent is due to hitting the green send key (hardware call button:
793 * KEYCODE_CALL) while in a call.
794 *
795 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700796 * @return true if the intent is due to hitting the green send key while in a call
797 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700798 private boolean isSendKeyWhileInCall(Intent intent) {
799 // If there is a call in progress and the user launched the dialer by hitting the call
800 // button, go straight to the in-call screen.
801 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700802
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700803 if (callKey) {
804 getTelephonyManager().showCallScreen();
805 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700806 }
807
808 return false;
809 }
810
811 /**
812 * Sets the current tab based on the intent's request type
813 *
814 * @param intent Intent that contains information about which tab should be selected
815 */
Yorke Leec3766332013-07-31 11:13:16 -0700816 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700817 // If we got here by hitting send and we're in call forward along to the in-call activity
Yorke Lee62e995c2014-03-28 10:02:56 -0700818 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700819 finish();
820 return;
821 }
822
Yorke Lee669b6082013-09-17 15:43:38 -0700823 if (mDialpadFragment != null) {
824 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700825 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700826 mDialpadFragment.setStartedFromNewIntent(true);
827 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
828 mInCallDialpadUp = true;
829 }
830 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700831 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700832 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700833 }
834
835 @Override
836 public void onNewIntent(Intent newIntent) {
837 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700838 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700839
Chiao Cheng94b10b52012-08-17 16:59:12 -0700840 invalidateOptionsMenu();
841 }
842
843 /** Returns true if the given intent contains a phone number to populate the dialer with */
844 private boolean isDialIntent(Intent intent) {
845 final String action = intent.getAction();
846 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
847 return true;
848 }
849 if (Intent.ACTION_VIEW.equals(action)) {
850 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700851 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700852 return true;
853 }
854 }
855 return false;
856 }
857
858 /**
859 * Returns an appropriate call origin for this Activity. May return null when no call origin
860 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
861 * for remembering the tab in which the user made a phone call, so the external app's DIAL
862 * request should not be counted.)
863 */
864 public String getCallOrigin() {
865 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
866 }
867
Chiao Cheng94b10b52012-08-17 16:59:12 -0700868 /**
Yorke Leec3766332013-07-31 11:13:16 -0700869 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700870 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700871 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700872 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700873 // Weird race condition where fragment is doing work after the activity is destroyed
874 // due to talkback being on (b/10209937). Just return since we can't do any
875 // constructive here.
876 return;
877 }
878
Yorke Leeef2b7382013-08-09 17:39:25 -0700879 if (DEBUG) {
880 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
881 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700882
Yorke Leec3766332013-07-31 11:13:16 -0700883 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700884 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700885 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700886 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700887 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700888 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700889
Yorke Leeb207f8a2013-08-29 18:51:06 -0700890 final String tag;
891 if (smartDialSearch) {
892 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
893 } else {
894 tag = TAG_REGULAR_SEARCH_FRAGMENT;
895 }
896 mInDialpadSearch = smartDialSearch;
897 mInRegularSearch = !smartDialSearch;
898
Andrew Lee752956e2014-05-15 11:43:38 -0700899 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700900 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700901 if (fragment == null) {
902 if (smartDialSearch) {
903 fragment = new SmartDialSearchFragment();
904 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700905 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700906 }
Andrew Leeb1903842014-05-15 16:11:24 -0700907 transaction.add(R.id.dialtacts_frame, fragment, tag);
908 } else {
909 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700910 }
Andrew Leeb1903842014-05-15 16:11:24 -0700911
Yorke Lee86e21f72014-04-02 16:49:38 -0700912 // DialtactsActivity will provide the options menu
913 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700914 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700915 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700916 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700917
918 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700919 }
920
921 /**
Yorke Leec3766332013-07-31 11:13:16 -0700922 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700923 */
Yorke Leec3766332013-07-31 11:13:16 -0700924 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700925 // See related bug in enterSearchUI();
926 if (getFragmentManager().isDestroyed()) {
927 return;
928 }
Andrew Leeb1903842014-05-15 16:11:24 -0700929
Andrew Leeb1903842014-05-15 16:11:24 -0700930 mSearchView.setText(null);
931 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700932 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700933
Andrew Leeb1903842014-05-15 16:11:24 -0700934 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700935 if (mSmartDialSearchFragment != null) {
936 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700937 }
Andrew Leeb1903842014-05-15 16:11:24 -0700938 if (mRegularSearchFragment != null) {
939 transaction.remove(mRegularSearchFragment);
940 }
941 transaction.commit();
942
943 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700944 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700945 }
946
947 /** Returns an Intent to launch Call Settings screen */
948 public static Intent getCallSettingsIntent() {
949 final Intent intent = new Intent(Intent.ACTION_MAIN);
950 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
951 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
952 return intent;
953 }
954
955 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700956 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700957 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700958 if (TextUtils.isEmpty(mSearchQuery) ||
959 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
960 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700961 exitSearchUi();
962 }
Yorke Leef6673d32013-08-23 15:34:17 -0700963 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700964 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700965 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700966 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700967 } else {
968 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700969 }
Yorke Leec3766332013-07-31 11:13:16 -0700970 }
971
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700972 /**
973 * @return True if the search UI was exited, false otherwise
974 */
975 private boolean maybeExitSearchUi() {
976 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
977 exitSearchUi();
978 hideInputMethod(parentLayout);
979 return true;
980 }
981 return false;
982 }
983
Yorke Leec3766332013-07-31 11:13:16 -0700984 @Override
985 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700986 if (mSmartDialSearchFragment != null) {
987 mSmartDialSearchFragment.setAddToContactNumber(query);
988 }
Yorke Leec3766332013-07-31 11:13:16 -0700989 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
990 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700991
992 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700993 if (DEBUG) {
994 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
995 }
996 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
997 // This callback can happen if the dialpad fragment is recreated because of
998 // activity destruction. In that case, don't update the search view because
999 // that would bring the user back to the search fragment regardless of the
1000 // previous state of the application. Instead, just return here and let the
1001 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001002 if (!TextUtils.isEmpty(normalizedQuery)) {
1003 mPendingSearchViewQuery = normalizedQuery;
1004 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001005 return;
1006 }
Yorke Lee53a22302014-04-29 18:13:46 -07001007 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001008 }
1009 }
Yorke Leec3766332013-07-31 11:13:16 -07001010
1011 @Override
1012 public void onListFragmentScrollStateChange(int scrollState) {
1013 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001014 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001015 hideInputMethod(getCurrentFocus());
1016 }
1017 }
1018
1019 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001020 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001021 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001022 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1023 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001024 }
1025
Yorke Lee86e21f72014-04-02 16:49:38 -07001026 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001027 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001028 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001029 }
1030
1031 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001032 // TODO(santoscordon): Replace with a TelecommService method call.
1033 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001034 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001035
Yorke Leee1424812013-09-04 18:24:48 -07001036 public static Intent getAddNumberToContactIntent(CharSequence text) {
1037 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1038 intent.putExtra(Intents.Insert.PHONE, text);
1039 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1040 return intent;
1041 }
1042
Yorke Leeda0f9042013-12-05 14:25:51 -08001043 private boolean canIntentBeHandled(Intent intent) {
1044 final PackageManager packageManager = getPackageManager();
1045 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1046 PackageManager.MATCH_DEFAULT_ONLY);
1047 return resolveInfo != null && resolveInfo.size() > 0;
1048 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001049
Yorke Lee6a1461a2014-04-21 16:27:14 -07001050 @Override
1051 public void showCallHistory() {
1052 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1053 // CONTENT_TYPE, so that we always open our call log from our dialer
1054 final Intent intent = new Intent(this, CallLogActivity.class);
1055 startActivity(intent);
1056 }
1057
Yorke Lee86e21f72014-04-02 16:49:38 -07001058 /**
1059 * Called when the user has long-pressed a contact tile to start a drag operation.
1060 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001061 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001062 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001063 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001064 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001065 }
Andrew Lee18963442014-06-06 17:20:13 -07001066 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001067 }
1068
1069 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001070 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1071 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001072
Yorke Lee86e21f72014-04-02 16:49:38 -07001073 /**
1074 * Called when the user has released a contact tile after long-pressing it.
1075 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001076 @Override
1077 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001078 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001079 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001080 }
Andrew Lee18963442014-06-06 17:20:13 -07001081 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001082 }
1083
1084 @Override
1085 public void onDroppedOnRemove() {}
1086
1087 /**
Yorke Leed999b712014-04-23 15:10:58 -07001088 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001089 * once it has been attached to the activity.
1090 */
1091 @Override
1092 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001093 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001094 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001095 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001096
1097 @Override
1098 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001099 // Specify call-origin so that users will see the previous tab instead of
1100 // CallLog screen (search UI will be automatically exited).
1101 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001102 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001103 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001104 }
1105
1106 @Override
1107 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001108 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1109 }
1110
1111 @Override
1112 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001113 final PhoneAccount account = mAccountManager != null ?
1114 mAccountManager.getCurrentAccount() : null;
Andrew Leed2a683f2014-07-08 15:54:50 -07001115 Intent intent = isVideoCall ?
1116 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin(), account) :
1117 CallUtil.getCallIntent(phoneNumber, getCallOrigin(), account);
Yorke Lee7d20f822014-06-19 17:09:33 -07001118 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001119 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001120 }
1121
1122 @Override
1123 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001124 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001125 }
1126
1127 @Override
1128 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001129 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001130 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001131
Yorke Leecc4660d2014-04-24 11:22:57 -07001132 @Override
1133 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001134 // Only scroll the button when the first tab is selected. The button should scroll from
1135 // the middle to right position only on the transition from the first tab to the second
1136 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001137 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001138 mFloatingActionButtonController.onPageScrolled(positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001139 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1140 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001141 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001142 }
1143
1144 @Override
1145 public void onPageSelected(int position) {
1146 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001147 }
1148
1149 @Override
1150 public void onPageScrollStateChanged(int state) {
1151 }
1152
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001153 private TelephonyManager getTelephonyManager() {
1154 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1155 }
1156
Yorke Lee5253be02014-05-21 18:50:03 -07001157 @Override
1158 public boolean isActionBarShowing() {
1159 return mActionBarController.isActionBarShowing();
1160 }
1161
Andrew Lee9da8fb42014-06-03 14:03:09 -07001162 public boolean isDialpadShown() {
1163 return mIsDialpadShown;
1164 }
1165
Yorke Lee5253be02014-05-21 18:50:03 -07001166 @Override
1167 public int getActionBarHideOffset() {
1168 return getActionBar().getHideOffset();
1169 }
1170
1171 @Override
1172 public int getActionBarHeight() {
1173 return mActionBarHeight;
1174 }
1175
1176 @Override
1177 public void setActionBarHideOffset(int hideOffset) {
1178 getActionBar().setHideOffset(hideOffset);
1179 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001180
1181 /**
1182 * Updates controller based on currently known information.
1183 *
1184 * @param animate Whether or not to animate the transition.
1185 */
1186 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1187 int align;
1188 if (mIsDialpadShown) {
1189 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1190 : FloatingActionButtonController.ALIGN_MIDDLE;
1191 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001192 if (!mIsLandscape) {
1193 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1194 ? FloatingActionButtonController.ALIGN_MIDDLE
1195 : FloatingActionButtonController.ALIGN_RIGHT;
1196 } else {
1197 align = FloatingActionButtonController.ALIGN_RIGHT;
1198 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001199 }
1200 mFloatingActionButtonController.align(align,
1201 0 /* offsetX */,
1202 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1203 animate);
1204 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001205}