blob: 5c2e17e2985dcd9d300153d25510b58d78f73b7c [file] [log] [blame]
Chiao Cheng94b10b52012-08-17 16:59:12 -07001/*
Yorke Leec3766332013-07-31 11:13:16 -07002 * Copyright (C) 2013 The Android Open Source Project
Chiao Cheng94b10b52012-08-17 16:59:12 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.dialer;
18
Yorke Leecc4660d2014-04-24 11:22:57 -070019import android.animation.LayoutTransition;
Yorke Lee53a22302014-04-29 18:13:46 -070020import android.app.ActionBar;
Chiao Cheng94b10b52012-08-17 16:59:12 -070021import android.app.Activity;
22import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080024import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070025import android.content.Context;
26import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080027import android.content.pm.PackageManager;
28import android.content.pm.ResolveInfo;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070029import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070030import android.content.res.Resources;
Yorke Lee33932ff2014-04-16 13:34:32 -070031import android.content.res.TypedArray;
Chiao Cheng94b10b52012-08-17 16:59:12 -070032import android.net.Uri;
33import android.os.Bundle;
34import android.os.RemoteException;
35import android.os.ServiceManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070036import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070037import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070038import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070039import android.support.v4.view.ViewPager;
Nancy Chen8e066292014-06-18 17:16:10 -070040import android.telecomm.Subscription;
Yorke Leec3766332013-07-31 11:13:16 -070041import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070042import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070043import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070044import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070045import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070046import android.view.DragEvent;
Andrew Leeb1903842014-05-15 16:11:24 -070047import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070049import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070050import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070051import android.view.View;
Sai Cheemalapati41460652014-06-02 21:05:39 -070052import android.view.ViewTreeObserver;
Yorke Lee28266192014-05-01 10:05:52 -070053import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070054import android.view.View.OnTouchListener;
Andrew Lee2a58ab82014-05-15 02:16:04 -070055import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070056import android.view.animation.AnimationUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070057import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070058import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070059import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070060import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070061import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070062import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080063import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070064
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070065import com.android.contacts.common.CallUtil;
Nancy Chen8e066292014-06-18 17:16:10 -070066import com.android.contacts.common.SubscriptionManager;
Chiao Cheng603ff682012-10-24 15:18:40 -070067import com.android.contacts.common.activity.TransactionSafeActivity;
Andrew Lee3c14bc32014-05-28 15:43:03 -070068import com.android.contacts.common.animation.AnimationListenerAdapter;
Yorke Leec3766332013-07-31 11:13:16 -070069import com.android.contacts.common.dialog.ClearFrequentsDialog;
Nancy Chen8e066292014-06-18 17:16:10 -070070import com.android.contacts.common.dialog.SelectSubscriptionDialogFragment;
Yorke Leec3766332013-07-31 11:13:16 -070071import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080072import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070073import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070074import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070075import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070076import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070077import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070078import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070079import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080080import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070081import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080082import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070083import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070084import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070085import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070086import com.android.dialer.list.RegularSearchFragment;
87import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070088import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee5253be02014-05-21 18:50:03 -070089import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070090import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070091import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070092import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070093
Yorke Leec3766332013-07-31 11:13:16 -070094import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080095import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070096
Chiao Cheng94b10b52012-08-17 16:59:12 -070097/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070098 * The dialer tab's title is 'phone', a more common name (see strings.xml).
99 */
Yorke Leec3766332013-07-31 11:13:16 -0700100public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700101 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700102 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800103 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700104 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700105 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700106 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700107 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700108 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700109 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700110 ViewPager.OnPageChangeListener,
111 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700112 private static final String TAG = "DialtactsActivity";
113
Ihab Awad526c0b82014-02-27 12:55:36 -0800114 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700115
Nancy Chen8e066292014-06-18 17:16:10 -0700116 /** Temporary flag for disabling subscription selection menu */
117 public static final boolean ENABLE_SUBSCRIPTION_SELECT = false;
118
Yorke Leef74011e2013-08-02 11:30:30 -0700119 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
120
Chiao Cheng94b10b52012-08-17 16:59:12 -0700121 /** Used to open Call Setting */
122 private static final String PHONE_PACKAGE = "com.android.phone";
123 private static final String CALL_SETTINGS_CLASS_NAME =
124 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700125 /** @see #getCallOrigin() */
126 private static final String CALL_ORIGIN_DIALTACTS =
127 "com.android.dialer.DialtactsActivity";
128
Yorke Leeb207f8a2013-08-29 18:51:06 -0700129 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
130 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700131 private static final String KEY_SEARCH_QUERY = "search_query";
132 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700133 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700134
Yorke Leec3766332013-07-31 11:13:16 -0700135 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
136 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
137 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
138 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700139
Chiao Cheng94b10b52012-08-17 16:59:12 -0700140 /**
141 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
142 */
143 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
144
Yorke Leec3766332013-07-31 11:13:16 -0700145 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700146
Yorke Lee28aab272014-06-11 10:24:19 -0700147 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700148
Yorke Leec3766332013-07-31 11:13:16 -0700149 /**
Yorke Leec3766332013-07-31 11:13:16 -0700150 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700151 */
Yorke Leef74011e2013-08-02 11:30:30 -0700152 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700153
154 /**
155 * Fragment for searching phone numbers using the alphanumeric keyboard.
156 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700157 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700158
159 /**
160 * Fragment for searching phone numbers using the dialpad.
161 */
162 private SmartDialSearchFragment mSmartDialSearchFragment;
163
Yorke Leee00c9fe2014-04-12 12:42:06 -0700164 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700165 * Animation that slides in.
166 */
167 private Animation mSlideIn;
168
169 /**
170 * Animation that slides out.
171 */
172 private Animation mSlideOut;
173
174 /**
175 * Listener for after slide out animation completes on dialer fragment.
176 */
177 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
178 @Override
179 public void onAnimationEnd(Animation animation) {
180 commitDialpadFragmentHide();
181 }
182 };
183
184 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700185 * Fragment containing the speed dial list, recents list, and all contacts list.
186 */
187 private ListsFragment mListsFragment;
188
Yorke Leeb207f8a2013-08-29 18:51:06 -0700189 private boolean mInDialpadSearch;
190 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700191 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700192 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700193 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700194
Yorke Leeef2b7382013-08-09 17:39:25 -0700195 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700196 * Whether or not the device is in landscape orientation.
197 */
198 private boolean mIsLandscape;
199
200 /**
Nancy Chen8e066292014-06-18 17:16:10 -0700201 * Information about the currently selected subscription.
Nancy Chenbeededb2014-06-10 18:30:28 -0700202 */
Nancy Chen8e066292014-06-18 17:16:10 -0700203 private SubscriptionManager mSubscriptionManager = null;
Nancy Chenbeededb2014-06-10 18:30:28 -0700204
205 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700206 * The position of the currently selected tab in the attached {@link ListsFragment}.
207 */
208 private int mCurrentTabPosition = 0;
209
210 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700211 * True if the dialpad is only temporarily showing due to being in call
212 */
213 private boolean mInCallDialpadUp;
214
215 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700216 * True when this activity has been launched for the first time.
217 */
Yorke Lee98702de2013-08-06 12:03:32 -0700218 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700219
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700220 /**
221 * Search query to be applied to the SearchView in the ActionBar once
222 * onCreateOptionsMenu has been called.
223 */
224 private String mPendingSearchViewQuery;
225
Yorke Lee53a22302014-04-29 18:13:46 -0700226 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700227 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700228
Yorke Leeef2b7382013-08-09 17:39:25 -0700229 private String mSearchQuery;
230
Yorke Leefce269a2013-08-12 11:56:04 -0700231 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700232 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700233 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700234
235 private String mDescriptionDialButtonStr;
236 private String mActionMenuDialpadButtonStr;
237 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700238 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700239 /**
240 * Additional offset for FAB to be lowered when dialpad is open.
241 */
242 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700243
Andrew Lee2423a2f2014-05-29 14:14:45 -0700244 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700245
Andrew Leee74a10e2014-05-16 14:31:40 -0700246 private class OptionsPopupMenu extends PopupMenu {
247 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700248 super(context, anchor);
249 }
250
251 @Override
252 public void show() {
253 final Menu menu = getMenu();
254 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700255 clearFrequents.setVisible(mListsFragment != null &&
256 mListsFragment.getSpeedDialFragment() != null &&
257 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700258 super.show();
259 }
260 }
261
Chiao Cheng94b10b52012-08-17 16:59:12 -0700262 /**
Yorke Lee28266192014-05-01 10:05:52 -0700263 * Listener that listens to drag events and sends their x and y coordinates to a
264 * {@link DragDropController}.
265 */
266 private class LayoutOnDragListener implements OnDragListener {
267 @Override
268 public boolean onDrag(View v, DragEvent event) {
269 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700270 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700271 }
272 return true;
273 }
274 }
275
276 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700277 * Listener used to send search queries to the phone search fragment.
278 */
Yorke Lee53a22302014-04-29 18:13:46 -0700279 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700280 @Override
281 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
282 }
Yorke Leec3766332013-07-31 11:13:16 -0700283
Andrew Lee99a570c2014-05-15 14:18:50 -0700284 @Override
285 public void onTextChanged(CharSequence s, int start, int before, int count) {
286 final String newText = s.toString();
287 if (newText.equals(mSearchQuery)) {
288 // If the query hasn't changed (perhaps due to activity being destroyed
289 // and restored, or user launching the same DIAL intent twice), then there is
290 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700291 return;
292 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700293 if (DEBUG) {
294 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700295 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700296 }
Yorke Lee710709d2014-05-29 07:18:42 -0700297 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700298
Andrew Lee90374a72014-05-16 15:01:09 -0700299 // Show search fragment only when the query string is changed to non-empty text.
300 if (!TextUtils.isEmpty(newText)) {
301 // Call enterSearchUi only if we are switching search modes, or showing a search
302 // fragment for the first time.
303 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
304 (!mIsDialpadShown && mInRegularSearch);
305 if (!sameSearchMode) {
306 enterSearchUi(mIsDialpadShown, mSearchQuery);
307 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700308 }
309
Andrew Leea8515422014-06-13 16:53:54 -0700310 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700311 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700312 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700313 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700314 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700315 }
316
317 @Override
318 public void afterTextChanged(Editable s) {
319 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700320 };
321
Andrew Leeb1903842014-05-15 16:11:24 -0700322
323 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700324 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700325 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700326 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700327 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700328 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700329 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700330 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700331 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
332 }
Andrew Leeb1903842014-05-15 16:11:24 -0700333 }
334 };
335
336 /**
337 * If the search term is empty and the user closes the soft keyboard, close the search UI.
338 */
339 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
340 @Override
341 public boolean onKey(View v, int keyCode, KeyEvent event) {
342 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
343 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700344 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700345 }
346 return false;
347 }
348 };
349
Chiao Cheng94b10b52012-08-17 16:59:12 -0700350 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700351 protected void onCreate(Bundle savedInstanceState) {
352 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700353 mFirstLaunch = true;
354
Andrew Lee2423a2f2014-05-29 14:14:45 -0700355 final Resources resources = getResources();
356 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700357 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
358 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700359
Yorke Lee8898cd02013-08-08 10:24:27 -0700360 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800361 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700362
Yorke Lee53a22302014-04-29 18:13:46 -0700363 final ActionBar actionBar = getActionBar();
364 actionBar.setCustomView(R.layout.search_edittext);
365 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700366 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700367
Yorke Lee5253be02014-05-21 18:50:03 -0700368 mActionBarController = new ActionBarController(this,
369 (SearchEditTextLayout) actionBar.getCustomView());
370
Andrew Lee04675a52014-06-05 18:36:20 -0700371 SearchEditTextLayout searchEditTextLayout =
372 (SearchEditTextLayout) actionBar.getCustomView();
373 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
374
375 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700376 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700377 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
378 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
379 .setOnClickListener(mSearchViewOnClickListener);
380 searchEditTextLayout.findViewById(R.id.search_box_start_search)
381 .setOnClickListener(mSearchViewOnClickListener);
382 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700383 @Override
384 public void onBackButtonClicked() {
385 onBackPressed();
386 }
387 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700388
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700389 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700390 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700391
392 if (getTelephonyManager().getSubscriptions().size() > 1 && ENABLE_SUBSCRIPTION_SELECT) {
393 mSubscriptionManager = new SubscriptionManager(getTelephonyManager());
394 }
395
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700396 final View floatingActionButtonContainer = findViewById(
397 R.id.floating_action_button_container);
398 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
399 int floatingActionButtonWidth = resources.getDimensionPixelSize(
400 R.dimen.floating_action_button_width);
401 mFloatingActionButton.setOnClickListener(this);
402 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700403 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700404 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
405 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700406
Andrew Lee04675a52014-06-05 18:36:20 -0700407 ImageButton optionsMenuButton =
408 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700409 optionsMenuButton.setOnClickListener(this);
410 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
411 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
412
Yorke Leeef2b7382013-08-09 17:39:25 -0700413 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
414 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700415 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800416 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700417 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800418 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
419 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700420 } else {
421 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700422 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
423 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700424 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700425 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700426 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700427 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700428
429 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700430 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700431 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700432 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700433
434 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700435
Yorke Lee28aab272014-06-11 10:24:19 -0700436 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700437 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
438 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700439 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700440 new ViewTreeObserver.OnGlobalLayoutListener() {
441 @Override
442 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700443 final ViewTreeObserver observer = floatingActionButtonContainer
444 .getViewTreeObserver();
445 if (!observer.isAlive()) {
446 return;
447 }
448 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700449 int screenWidth = parentLayout.getWidth();
450 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700451 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700452 }
453 });
Andrew Lee0c667702014-05-12 14:31:45 -0700454
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700455 setupActivityOverlay();
456
Yorke Lee0baa98b2013-08-22 10:55:16 -0700457 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700458 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700459 }
460
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700461 private void setupActivityOverlay() {
462 final View activityOverlay = findViewById(R.id.activity_overlay);
463 activityOverlay.setOnTouchListener(new OnTouchListener() {
464 @Override
465 public boolean onTouch(View v, MotionEvent event) {
466 if (!mIsDialpadShown) {
467 maybeExitSearchUi();
468 }
469 return false;
470 }
471 });
472 }
473
Chiao Cheng94b10b52012-08-17 16:59:12 -0700474 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700475 protected void onResume() {
476 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700477 if (mFirstLaunch) {
478 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700479 } else if (!phoneIsInUse() && mInCallDialpadUp) {
480 hideDialpadFragment(false, true);
481 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700482 } else if (mShowDialpadOnResume) {
483 showDialpadFragment(false);
484 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700485 }
486 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700487 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700488 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700489 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700490 }
491
492 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700493 protected void onPause() {
494 if (mClearSearchOnPause) {
495 hideDialpadAndSearchUi();
496 mClearSearchOnPause = false;
497 }
498 super.onPause();
499 }
500
501 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700502 protected void onSaveInstanceState(Bundle outState) {
503 super.onSaveInstanceState(outState);
504 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700505 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
506 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700507 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700508 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700509 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700510 }
511
512 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700513 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700514 if (fragment instanceof DialpadFragment) {
515 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700516 if (!mShowDialpadOnResume) {
517 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
518 transaction.hide(mDialpadFragment);
519 transaction.commit();
520 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700521 } else if (fragment instanceof SmartDialSearchFragment) {
522 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700523 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700524 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700525 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700526 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700527 } else if (fragment instanceof ListsFragment) {
528 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700529 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700530 }
Yorke Leec3766332013-07-31 11:13:16 -0700531 }
532
Alon Albertb453e5b2013-09-10 15:54:23 -0700533 protected void handleMenuSettings() {
534 openTelephonySetting(this);
535 }
536
537 public static void openTelephonySetting(Activity activity) {
538 final Intent settingsIntent = getCallSettingsIntent();
539 activity.startActivity(settingsIntent);
540 }
541
Chiao Cheng94b10b52012-08-17 16:59:12 -0700542 @Override
543 public void onClick(View view) {
544 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700545 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700546 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700547 mInCallDialpadUp = false;
548 showDialpadFragment(true);
549 } else {
550 // Dial button was pressed; tell the Dialpad fragment
551 mDialpadFragment.dialButtonPressed();
552 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700553 break;
Yorke Leec3766332013-07-31 11:13:16 -0700554 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800555 try {
556 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
557 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
558 } catch (ActivityNotFoundException e) {
559 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
560 Toast.LENGTH_SHORT).show();
561 }
Yorke Leec3766332013-07-31 11:13:16 -0700562 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700563 case R.id.dialtacts_options_menu_button:
564 buildOptionsMenu(view).show();
565 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700566 default: {
567 Log.wtf(TAG, "Unexpected onClick event from " + view);
568 break;
569 }
570 }
571 }
572
Yorke Leec3766332013-07-31 11:13:16 -0700573 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700574 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700575 switch (item.getItemId()) {
576 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700577 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700578 break;
579 case R.id.menu_add_contact:
580 try {
581 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
582 } catch (ActivityNotFoundException e) {
583 Toast toast = Toast.makeText(this,
584 R.string.add_contact_not_available,
585 Toast.LENGTH_SHORT);
586 toast.show();
587 }
588 break;
589 case R.id.menu_import_export:
590 // We hard-code the "contactsAreAvailable" argument because doing it properly would
591 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
592 // now in Dialtacts for (potential) performance reasons. Compare with how it is
593 // done in {@link PeopleActivity}.
594 ImportExportDialogFragment.show(getFragmentManager(), true,
595 DialtactsActivity.class);
596 return true;
597 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700598 ClearFrequentsDialog.show(getFragmentManager());
599 return true;
600 case R.id.menu_call_settings:
601 handleMenuSettings();
602 return true;
Nancy Chen8e066292014-06-18 17:16:10 -0700603 case R.id.menu_select_subscription:
604 SelectSubscriptionDialogFragment.show(getFragmentManager(), mSubscriptionManager);
Nancy Chenbeededb2014-06-10 18:30:28 -0700605 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700606 }
607 return false;
608 }
609
610 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700611 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
612 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
613 if (resultCode == RESULT_OK) {
614 final ArrayList<String> matches = data.getStringArrayListExtra(
615 RecognizerIntent.EXTRA_RESULTS);
616 if (matches.size() > 0) {
617 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700618 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700619 } else {
620 Log.e(TAG, "Voice search - nothing heard");
621 }
622 } else {
623 Log.e(TAG, "Voice search failed");
624 }
625 }
626 super.onActivityResult(requestCode, resultCode, data);
627 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700628
Andrew Lee2a58ab82014-05-15 02:16:04 -0700629 /**
630 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
631 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
632 * @see #onDialpadShown
633 */
Yorke Leec3766332013-07-31 11:13:16 -0700634 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700635 if (mIsDialpadShown) {
636 return;
637 }
638 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700639 mDialpadFragment.setAnimate(animate);
Nancy Chen8e066292014-06-18 17:16:10 -0700640 mDialpadFragment.setSubscriptionManager(mSubscriptionManager);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700641
Chiao Cheng94b10b52012-08-17 16:59:12 -0700642 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700643 ft.show(mDialpadFragment);
644 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700645
Yorke Lee5253be02014-05-21 18:50:03 -0700646 mActionBarController.onDialpadUp();
647
Andrew Leeb1903842014-05-15 16:11:24 -0700648 if (!isInSearchUi()) {
649 enterSearchUi(true /* isSmartDial */, mSearchQuery);
650 }
Yorke Leec3766332013-07-31 11:13:16 -0700651 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700652
Andrew Lee2a58ab82014-05-15 02:16:04 -0700653 /**
654 * Callback from child DialpadFragment when the dialpad is shown.
655 */
656 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700657 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
658 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
659 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700660 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700661 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700662 } else {
663 mDialpadFragment.setYFraction(0);
664 }
665
Andrew Lee2a58ab82014-05-15 02:16:04 -0700666 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700667 }
668
669 /**
670 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
671 * a callback after the hide animation ends.
672 * @see #commitDialpadFragmentHide
673 */
Yorke Leeca195042013-09-25 16:29:38 -0700674 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700675 if (mDialpadFragment == null) {
676 return;
677 }
Yorke Leef6673d32013-08-23 15:34:17 -0700678 if (clearDialpad) {
679 mDialpadFragment.clearDialpad();
680 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700681 if (!mIsDialpadShown) {
682 return;
Yorke Leec3766332013-07-31 11:13:16 -0700683 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700684 mIsDialpadShown = false;
685 mDialpadFragment.setAnimate(animate);
686
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700687 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700688 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
689 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
690
691 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700692 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700693 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700694 } else {
695 commitDialpadFragmentHide();
696 }
697
Yorke Lee5253be02014-05-21 18:50:03 -0700698 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700699
Andrew Leed4cde832014-05-16 15:56:48 -0700700 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700701 if (TextUtils.isEmpty(mSearchQuery)) {
702 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700703 }
Andrew Leed4cde832014-05-16 15:56:48 -0700704 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700705 }
706
707 /**
708 * Finishes hiding the dialpad fragment after any animations are completed.
709 */
710 private void commitDialpadFragmentHide() {
711 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700712 ft.hide(mDialpadFragment);
713 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700714 }
715
Andrew Lee2a58ab82014-05-15 02:16:04 -0700716 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700717 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700718 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700719 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700720 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700721 fragment = mRegularSearchFragment;
722 }
723 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700724 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700725 }
726 }
727
Yorke Lee5253be02014-05-21 18:50:03 -0700728 @Override
729 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700730 return mInDialpadSearch || mInRegularSearch;
731 }
732
Yorke Lee5253be02014-05-21 18:50:03 -0700733 @Override
734 public boolean hasSearchQuery() {
735 return !TextUtils.isEmpty(mSearchQuery);
736 }
737
738 @Override
739 public boolean shouldShowActionBar() {
740 return mListsFragment.shouldShowActionBar();
741 }
742
Yorke Leeb207f8a2013-08-29 18:51:06 -0700743 private void setNotInSearchUi() {
744 mInDialpadSearch = false;
745 mInRegularSearch = false;
746 }
747
Yorke Lee311969c2013-08-26 06:31:11 -0700748 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700749 if (mIsDialpadShown) {
750 hideDialpadFragment(false, true);
751 } else {
752 exitSearchUi();
753 }
Yorke Lee311969c2013-08-26 06:31:11 -0700754 }
755
Yorke Leee00c9fe2014-04-12 12:42:06 -0700756 private void hideInputMethod(View view) {
757 final InputMethodManager imm = (InputMethodManager) getSystemService(
758 Context.INPUT_METHOD_SERVICE);
759 if (imm != null && view != null) {
760 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
761 }
762 }
763
Yorke Lee53a22302014-04-29 18:13:46 -0700764 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700765 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
766 if (canIntentBeHandled(voiceIntent)) {
767 mVoiceSearchButton.setVisibility(View.VISIBLE);
768 mVoiceSearchButton.setOnClickListener(this);
769 } else {
770 mVoiceSearchButton.setVisibility(View.GONE);
771 }
772 }
773
Andrew Leee74a10e2014-05-16 14:31:40 -0700774 private OptionsPopupMenu buildOptionsMenu(View invoker) {
775 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
776 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700777 final Menu menu = popupMenu.getMenu();
Nancy Chen8e066292014-06-18 17:16:10 -0700778 final MenuItem selectSubscription = menu.findItem(R.id.menu_select_subscription);
779 selectSubscription.setVisible(mSubscriptionManager != null);
Andrew Leee74a10e2014-05-16 14:31:40 -0700780 popupMenu.setOnMenuItemClickListener(this);
781 return popupMenu;
782 }
783
Yorke Lee86e21f72014-04-02 16:49:38 -0700784 @Override
785 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700786 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700787 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700788 mPendingSearchViewQuery = null;
789 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700790 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700791 }
792
Chiao Cheng94b10b52012-08-17 16:59:12 -0700793 /**
794 * Returns true if the intent is due to hitting the green send key (hardware call button:
795 * KEYCODE_CALL) while in a call.
796 *
797 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700798 * @return true if the intent is due to hitting the green send key while in a call
799 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700800 private boolean isSendKeyWhileInCall(Intent intent) {
801 // If there is a call in progress and the user launched the dialer by hitting the call
802 // button, go straight to the in-call screen.
803 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700804
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700805 if (callKey) {
806 getTelephonyManager().showCallScreen();
807 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700808 }
809
810 return false;
811 }
812
813 /**
814 * Sets the current tab based on the intent's request type
815 *
816 * @param intent Intent that contains information about which tab should be selected
817 */
Yorke Leec3766332013-07-31 11:13:16 -0700818 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700819 // 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 -0700820 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700821 finish();
822 return;
823 }
824
Yorke Lee669b6082013-09-17 15:43:38 -0700825 if (mDialpadFragment != null) {
826 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700827 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700828 mDialpadFragment.setStartedFromNewIntent(true);
829 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
830 mInCallDialpadUp = true;
831 }
832 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700833 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700834 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700835 }
836
837 @Override
838 public void onNewIntent(Intent newIntent) {
839 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700840 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700841
Chiao Cheng94b10b52012-08-17 16:59:12 -0700842 invalidateOptionsMenu();
843 }
844
845 /** Returns true if the given intent contains a phone number to populate the dialer with */
846 private boolean isDialIntent(Intent intent) {
847 final String action = intent.getAction();
848 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
849 return true;
850 }
851 if (Intent.ACTION_VIEW.equals(action)) {
852 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700853 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700854 return true;
855 }
856 }
857 return false;
858 }
859
860 /**
861 * Returns an appropriate call origin for this Activity. May return null when no call origin
862 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
863 * for remembering the tab in which the user made a phone call, so the external app's DIAL
864 * request should not be counted.)
865 */
866 public String getCallOrigin() {
867 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
868 }
869
Chiao Cheng94b10b52012-08-17 16:59:12 -0700870 /**
Yorke Leec3766332013-07-31 11:13:16 -0700871 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700872 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700873 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700874 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700875 // Weird race condition where fragment is doing work after the activity is destroyed
876 // due to talkback being on (b/10209937). Just return since we can't do any
877 // constructive here.
878 return;
879 }
880
Yorke Leeef2b7382013-08-09 17:39:25 -0700881 if (DEBUG) {
882 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
883 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700884
Yorke Leec3766332013-07-31 11:13:16 -0700885 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700886 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700887 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700888 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700889 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700890 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700891
Yorke Leeb207f8a2013-08-29 18:51:06 -0700892 final String tag;
893 if (smartDialSearch) {
894 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
895 } else {
896 tag = TAG_REGULAR_SEARCH_FRAGMENT;
897 }
898 mInDialpadSearch = smartDialSearch;
899 mInRegularSearch = !smartDialSearch;
900
Andrew Lee752956e2014-05-15 11:43:38 -0700901 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700902 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700903 if (fragment == null) {
904 if (smartDialSearch) {
905 fragment = new SmartDialSearchFragment();
906 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700907 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700908 }
Andrew Leeb1903842014-05-15 16:11:24 -0700909 transaction.add(R.id.dialtacts_frame, fragment, tag);
910 } else {
911 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700912 }
Andrew Leeb1903842014-05-15 16:11:24 -0700913
Yorke Lee86e21f72014-04-02 16:49:38 -0700914 // DialtactsActivity will provide the options menu
915 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700916 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700917 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700918 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700919
920 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700921 }
922
923 /**
Yorke Leec3766332013-07-31 11:13:16 -0700924 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700925 */
Yorke Leec3766332013-07-31 11:13:16 -0700926 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700927 // See related bug in enterSearchUI();
928 if (getFragmentManager().isDestroyed()) {
929 return;
930 }
Andrew Leeb1903842014-05-15 16:11:24 -0700931
Andrew Leeb1903842014-05-15 16:11:24 -0700932 mSearchView.setText(null);
933 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700934 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700935
Andrew Leeb1903842014-05-15 16:11:24 -0700936 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700937 if (mSmartDialSearchFragment != null) {
938 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700939 }
Andrew Leeb1903842014-05-15 16:11:24 -0700940 if (mRegularSearchFragment != null) {
941 transaction.remove(mRegularSearchFragment);
942 }
943 transaction.commit();
944
945 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700946 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700947 }
948
949 /** Returns an Intent to launch Call Settings screen */
950 public static Intent getCallSettingsIntent() {
951 final Intent intent = new Intent(Intent.ACTION_MAIN);
952 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
953 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
954 return intent;
955 }
956
957 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700958 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700959 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700960 if (TextUtils.isEmpty(mSearchQuery) ||
961 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
962 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700963 exitSearchUi();
964 }
Yorke Leef6673d32013-08-23 15:34:17 -0700965 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700966 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700967 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700968 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700969 } else {
970 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700971 }
Yorke Leec3766332013-07-31 11:13:16 -0700972 }
973
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700974 /**
975 * @return True if the search UI was exited, false otherwise
976 */
977 private boolean maybeExitSearchUi() {
978 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
979 exitSearchUi();
980 hideInputMethod(parentLayout);
981 return true;
982 }
983 return false;
984 }
985
Yorke Leec3766332013-07-31 11:13:16 -0700986 @Override
987 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700988 if (mSmartDialSearchFragment != null) {
989 mSmartDialSearchFragment.setAddToContactNumber(query);
990 }
Yorke Leec3766332013-07-31 11:13:16 -0700991 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
992 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700993
994 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700995 if (DEBUG) {
996 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
997 }
998 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
999 // This callback can happen if the dialpad fragment is recreated because of
1000 // activity destruction. In that case, don't update the search view because
1001 // that would bring the user back to the search fragment regardless of the
1002 // previous state of the application. Instead, just return here and let the
1003 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001004 if (!TextUtils.isEmpty(normalizedQuery)) {
1005 mPendingSearchViewQuery = normalizedQuery;
1006 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001007 return;
1008 }
Yorke Lee53a22302014-04-29 18:13:46 -07001009 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001010 }
1011 }
Yorke Leec3766332013-07-31 11:13:16 -07001012
1013 @Override
1014 public void onListFragmentScrollStateChange(int scrollState) {
1015 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001016 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001017 hideInputMethod(getCurrentFocus());
1018 }
1019 }
1020
1021 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001022 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001023 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001024 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1025 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001026 }
1027
Yorke Lee86e21f72014-04-02 16:49:38 -07001028 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001029 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001030 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001031 }
1032
1033 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001034 // TODO(santoscordon): Replace with a TelecommService method call.
1035 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001036 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001037
Yorke Leee1424812013-09-04 18:24:48 -07001038 public static Intent getAddNumberToContactIntent(CharSequence text) {
1039 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1040 intent.putExtra(Intents.Insert.PHONE, text);
1041 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1042 return intent;
1043 }
1044
Yorke Leeda0f9042013-12-05 14:25:51 -08001045 private boolean canIntentBeHandled(Intent intent) {
1046 final PackageManager packageManager = getPackageManager();
1047 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1048 PackageManager.MATCH_DEFAULT_ONLY);
1049 return resolveInfo != null && resolveInfo.size() > 0;
1050 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001051
Yorke Lee6a1461a2014-04-21 16:27:14 -07001052 @Override
1053 public void showCallHistory() {
1054 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1055 // CONTENT_TYPE, so that we always open our call log from our dialer
1056 final Intent intent = new Intent(this, CallLogActivity.class);
1057 startActivity(intent);
1058 }
1059
Yorke Lee86e21f72014-04-02 16:49:38 -07001060 /**
1061 * Called when the user has long-pressed a contact tile to start a drag operation.
1062 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001063 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001064 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001065 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001066 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001067 }
Andrew Lee18963442014-06-06 17:20:13 -07001068 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001069 }
1070
1071 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001072 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1073 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001074
Yorke Lee86e21f72014-04-02 16:49:38 -07001075 /**
1076 * Called when the user has released a contact tile after long-pressing it.
1077 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001078 @Override
1079 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001080 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001081 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001082 }
Andrew Lee18963442014-06-06 17:20:13 -07001083 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001084 }
1085
1086 @Override
1087 public void onDroppedOnRemove() {}
1088
1089 /**
Yorke Leed999b712014-04-23 15:10:58 -07001090 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001091 * once it has been attached to the activity.
1092 */
1093 @Override
1094 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001095 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001096 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001097 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001098
1099 @Override
1100 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001101 // Specify call-origin so that users will see the previous tab instead of
1102 // CallLog screen (search UI will be automatically exited).
1103 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001104 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001105 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001106 }
1107
1108 @Override
1109 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001110 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1111 startActivity(intent);
1112 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001113 }
1114
1115 @Override
1116 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001117 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001118 }
1119
1120 @Override
1121 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001122 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001123 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001124
Yorke Leecc4660d2014-04-24 11:22:57 -07001125 @Override
1126 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001127 // Only scroll the button when the first tab is selected. The button should scroll from
1128 // the middle to right position only on the transition from the first tab to the second
1129 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001130 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001131 mFloatingActionButtonController.onPageScrolled(positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001132 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1133 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001134 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001135 }
1136
1137 @Override
1138 public void onPageSelected(int position) {
1139 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001140 }
1141
1142 @Override
1143 public void onPageScrollStateChanged(int state) {
1144 }
1145
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001146 private TelephonyManager getTelephonyManager() {
1147 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1148 }
1149
Yorke Lee5253be02014-05-21 18:50:03 -07001150 @Override
1151 public boolean isActionBarShowing() {
1152 return mActionBarController.isActionBarShowing();
1153 }
1154
Andrew Lee9da8fb42014-06-03 14:03:09 -07001155 public boolean isDialpadShown() {
1156 return mIsDialpadShown;
1157 }
1158
Yorke Lee5253be02014-05-21 18:50:03 -07001159 @Override
1160 public int getActionBarHideOffset() {
1161 return getActionBar().getHideOffset();
1162 }
1163
1164 @Override
1165 public int getActionBarHeight() {
1166 return mActionBarHeight;
1167 }
1168
1169 @Override
1170 public void setActionBarHideOffset(int hideOffset) {
1171 getActionBar().setHideOffset(hideOffset);
1172 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001173
1174 /**
1175 * Updates controller based on currently known information.
1176 *
1177 * @param animate Whether or not to animate the transition.
1178 */
1179 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1180 int align;
1181 if (mIsDialpadShown) {
1182 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1183 : FloatingActionButtonController.ALIGN_MIDDLE;
1184 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001185 if (!mIsLandscape) {
1186 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1187 ? FloatingActionButtonController.ALIGN_MIDDLE
1188 : FloatingActionButtonController.ALIGN_RIGHT;
1189 } else {
1190 align = FloatingActionButtonController.ALIGN_RIGHT;
1191 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001192 }
1193 mFloatingActionButtonController.align(align,
1194 0 /* offsetX */,
1195 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1196 animate);
1197 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001198}