blob: 8e873c876c834f45c7aa3e1114cffeb8b101067f [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;
Yorke Leec3766332013-07-31 11:13:16 -070068import com.android.contacts.common.dialog.ClearFrequentsDialog;
Nancy Chen8e066292014-06-18 17:16:10 -070069import com.android.contacts.common.dialog.SelectSubscriptionDialogFragment;
Yorke Leec3766332013-07-31 11:13:16 -070070import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080071import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070072import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070073import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070074import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070075import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070076import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070077import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070078import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080079import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070080import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080081import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070082import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070083import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070084import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070085import com.android.dialer.list.RegularSearchFragment;
86import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070087import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee7d20f822014-06-19 17:09:33 -070088import com.android.dialer.util.DialerUtils;
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;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070093import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070094
Yorke Leec3766332013-07-31 11:13:16 -070095import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080096import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070097
Chiao Cheng94b10b52012-08-17 16:59:12 -070098/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070099 * The dialer tab's title is 'phone', a more common name (see strings.xml).
100 */
Yorke Leec3766332013-07-31 11:13:16 -0700101public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700102 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700103 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800104 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700105 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700106 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700107 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700108 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700109 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700110 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700111 ViewPager.OnPageChangeListener,
112 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700113 private static final String TAG = "DialtactsActivity";
114
Ihab Awad526c0b82014-02-27 12:55:36 -0800115 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700116
Nancy Chen8e066292014-06-18 17:16:10 -0700117 /** Temporary flag for disabling subscription selection menu */
118 public static final boolean ENABLE_SUBSCRIPTION_SELECT = false;
119
Yorke Leef74011e2013-08-02 11:30:30 -0700120 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
121
Chiao Cheng94b10b52012-08-17 16:59:12 -0700122 /** Used to open Call Setting */
123 private static final String PHONE_PACKAGE = "com.android.phone";
124 private static final String CALL_SETTINGS_CLASS_NAME =
125 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700126 /** @see #getCallOrigin() */
127 private static final String CALL_ORIGIN_DIALTACTS =
128 "com.android.dialer.DialtactsActivity";
129
Yorke Leeb207f8a2013-08-29 18:51:06 -0700130 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
131 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700132 private static final String KEY_SEARCH_QUERY = "search_query";
133 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700134 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700135
Yorke Leec3766332013-07-31 11:13:16 -0700136 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
137 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
138 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
139 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700140
Chiao Cheng94b10b52012-08-17 16:59:12 -0700141 /**
142 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
143 */
144 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
145
Yorke Leec3766332013-07-31 11:13:16 -0700146 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700147
Yorke Lee28aab272014-06-11 10:24:19 -0700148 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700149
Yorke Leec3766332013-07-31 11:13:16 -0700150 /**
Yorke Leec3766332013-07-31 11:13:16 -0700151 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700152 */
Yorke Leef74011e2013-08-02 11:30:30 -0700153 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700154
155 /**
156 * Fragment for searching phone numbers using the alphanumeric keyboard.
157 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700158 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700159
160 /**
161 * Fragment for searching phone numbers using the dialpad.
162 */
163 private SmartDialSearchFragment mSmartDialSearchFragment;
164
Yorke Leee00c9fe2014-04-12 12:42:06 -0700165 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700166 * Animation that slides in.
167 */
168 private Animation mSlideIn;
169
170 /**
171 * Animation that slides out.
172 */
173 private Animation mSlideOut;
174
175 /**
176 * Listener for after slide out animation completes on dialer fragment.
177 */
178 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
179 @Override
180 public void onAnimationEnd(Animation animation) {
181 commitDialpadFragmentHide();
182 }
183 };
184
185 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700186 * Fragment containing the speed dial list, recents list, and all contacts list.
187 */
188 private ListsFragment mListsFragment;
189
Yorke Leeb207f8a2013-08-29 18:51:06 -0700190 private boolean mInDialpadSearch;
191 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700192 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700193 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700194 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700195
Yorke Leeef2b7382013-08-09 17:39:25 -0700196 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700197 * Whether or not the device is in landscape orientation.
198 */
199 private boolean mIsLandscape;
200
201 /**
Nancy Chen8e066292014-06-18 17:16:10 -0700202 * Information about the currently selected subscription.
Nancy Chenbeededb2014-06-10 18:30:28 -0700203 */
Nancy Chen8e066292014-06-18 17:16:10 -0700204 private SubscriptionManager mSubscriptionManager = null;
Nancy Chenbeededb2014-06-10 18:30:28 -0700205
206 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700207 * The position of the currently selected tab in the attached {@link ListsFragment}.
208 */
209 private int mCurrentTabPosition = 0;
210
211 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700212 * True if the dialpad is only temporarily showing due to being in call
213 */
214 private boolean mInCallDialpadUp;
215
216 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700217 * True when this activity has been launched for the first time.
218 */
Yorke Lee98702de2013-08-06 12:03:32 -0700219 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700220
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700221 /**
222 * Search query to be applied to the SearchView in the ActionBar once
223 * onCreateOptionsMenu has been called.
224 */
225 private String mPendingSearchViewQuery;
226
Yorke Lee53a22302014-04-29 18:13:46 -0700227 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700228 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700229
Yorke Leeef2b7382013-08-09 17:39:25 -0700230 private String mSearchQuery;
231
Yorke Leefce269a2013-08-12 11:56:04 -0700232 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700233 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700234 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700235
236 private String mDescriptionDialButtonStr;
237 private String mActionMenuDialpadButtonStr;
238 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700239 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700240 /**
241 * Additional offset for FAB to be lowered when dialpad is open.
242 */
243 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700244
Andrew Lee2423a2f2014-05-29 14:14:45 -0700245 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700246
Andrew Leee74a10e2014-05-16 14:31:40 -0700247 private class OptionsPopupMenu extends PopupMenu {
248 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700249 super(context, anchor);
250 }
251
252 @Override
253 public void show() {
254 final Menu menu = getMenu();
255 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700256 clearFrequents.setVisible(mListsFragment != null &&
257 mListsFragment.getSpeedDialFragment() != null &&
258 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700259 super.show();
260 }
261 }
262
Chiao Cheng94b10b52012-08-17 16:59:12 -0700263 /**
Yorke Lee28266192014-05-01 10:05:52 -0700264 * Listener that listens to drag events and sends their x and y coordinates to a
265 * {@link DragDropController}.
266 */
267 private class LayoutOnDragListener implements OnDragListener {
268 @Override
269 public boolean onDrag(View v, DragEvent event) {
270 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700271 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700272 }
273 return true;
274 }
275 }
276
277 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700278 * Listener used to send search queries to the phone search fragment.
279 */
Yorke Lee53a22302014-04-29 18:13:46 -0700280 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700281 @Override
282 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
283 }
Yorke Leec3766332013-07-31 11:13:16 -0700284
Andrew Lee99a570c2014-05-15 14:18:50 -0700285 @Override
286 public void onTextChanged(CharSequence s, int start, int before, int count) {
287 final String newText = s.toString();
288 if (newText.equals(mSearchQuery)) {
289 // If the query hasn't changed (perhaps due to activity being destroyed
290 // and restored, or user launching the same DIAL intent twice), then there is
291 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700292 return;
293 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700294 if (DEBUG) {
295 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700296 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700297 }
Yorke Lee710709d2014-05-29 07:18:42 -0700298 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700299
Andrew Lee90374a72014-05-16 15:01:09 -0700300 // Show search fragment only when the query string is changed to non-empty text.
301 if (!TextUtils.isEmpty(newText)) {
302 // Call enterSearchUi only if we are switching search modes, or showing a search
303 // fragment for the first time.
304 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
305 (!mIsDialpadShown && mInRegularSearch);
306 if (!sameSearchMode) {
307 enterSearchUi(mIsDialpadShown, mSearchQuery);
308 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700309 }
310
Andrew Leea8515422014-06-13 16:53:54 -0700311 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700312 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700313 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700314 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700315 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700316 }
317
318 @Override
319 public void afterTextChanged(Editable s) {
320 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700321 };
322
Andrew Leeb1903842014-05-15 16:11:24 -0700323
324 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700325 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700326 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700327 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700328 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700329 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700330 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700331 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700332 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
333 }
Andrew Leeb1903842014-05-15 16:11:24 -0700334 }
335 };
336
337 /**
338 * If the search term is empty and the user closes the soft keyboard, close the search UI.
339 */
340 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
341 @Override
342 public boolean onKey(View v, int keyCode, KeyEvent event) {
343 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
344 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700345 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700346 }
347 return false;
348 }
349 };
350
Chiao Cheng94b10b52012-08-17 16:59:12 -0700351 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700352 protected void onCreate(Bundle savedInstanceState) {
353 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700354 mFirstLaunch = true;
355
Andrew Lee2423a2f2014-05-29 14:14:45 -0700356 final Resources resources = getResources();
357 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700358 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
359 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700360
Yorke Lee8898cd02013-08-08 10:24:27 -0700361 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800362 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700363
Yorke Lee53a22302014-04-29 18:13:46 -0700364 final ActionBar actionBar = getActionBar();
365 actionBar.setCustomView(R.layout.search_edittext);
366 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700367 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700368
Yorke Lee5253be02014-05-21 18:50:03 -0700369 mActionBarController = new ActionBarController(this,
370 (SearchEditTextLayout) actionBar.getCustomView());
371
Andrew Lee04675a52014-06-05 18:36:20 -0700372 SearchEditTextLayout searchEditTextLayout =
373 (SearchEditTextLayout) actionBar.getCustomView();
374 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
375
376 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700377 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700378 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
379 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
380 .setOnClickListener(mSearchViewOnClickListener);
381 searchEditTextLayout.findViewById(R.id.search_box_start_search)
382 .setOnClickListener(mSearchViewOnClickListener);
383 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700384 @Override
385 public void onBackButtonClicked() {
386 onBackPressed();
387 }
388 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700389
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700390 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700391 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700392
393 if (getTelephonyManager().getSubscriptions().size() > 1 && ENABLE_SUBSCRIPTION_SELECT) {
394 mSubscriptionManager = new SubscriptionManager(getTelephonyManager());
395 }
396
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700397 final View floatingActionButtonContainer = findViewById(
398 R.id.floating_action_button_container);
399 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
400 int floatingActionButtonWidth = resources.getDimensionPixelSize(
401 R.dimen.floating_action_button_width);
402 mFloatingActionButton.setOnClickListener(this);
403 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700404 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700405 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
406 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700407
Andrew Lee04675a52014-06-05 18:36:20 -0700408 ImageButton optionsMenuButton =
409 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700410 optionsMenuButton.setOnClickListener(this);
411 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
412 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
413
Yorke Leeef2b7382013-08-09 17:39:25 -0700414 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
415 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700416 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800417 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700418 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800419 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
420 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700421 } else {
422 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700423 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
424 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700425 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700426 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700427 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700428 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700429
430 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700431 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700432 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700433 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700434
435 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700436
Yorke Lee28aab272014-06-11 10:24:19 -0700437 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700438 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
439 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700440 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700441 new ViewTreeObserver.OnGlobalLayoutListener() {
442 @Override
443 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700444 final ViewTreeObserver observer = floatingActionButtonContainer
445 .getViewTreeObserver();
446 if (!observer.isAlive()) {
447 return;
448 }
449 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700450 int screenWidth = parentLayout.getWidth();
451 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700452 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700453 }
454 });
Andrew Lee0c667702014-05-12 14:31:45 -0700455
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700456 setupActivityOverlay();
457
Yorke Lee0baa98b2013-08-22 10:55:16 -0700458 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700459 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700460 }
461
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700462 private void setupActivityOverlay() {
463 final View activityOverlay = findViewById(R.id.activity_overlay);
464 activityOverlay.setOnTouchListener(new OnTouchListener() {
465 @Override
466 public boolean onTouch(View v, MotionEvent event) {
467 if (!mIsDialpadShown) {
468 maybeExitSearchUi();
469 }
470 return false;
471 }
472 });
473 }
474
Chiao Cheng94b10b52012-08-17 16:59:12 -0700475 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700476 protected void onResume() {
477 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700478 if (mFirstLaunch) {
479 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700480 } else if (!phoneIsInUse() && mInCallDialpadUp) {
481 hideDialpadFragment(false, true);
482 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700483 } else if (mShowDialpadOnResume) {
484 showDialpadFragment(false);
485 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700486 }
487 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700488 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700489 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700490 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700491 }
492
493 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700494 protected void onPause() {
495 if (mClearSearchOnPause) {
496 hideDialpadAndSearchUi();
497 mClearSearchOnPause = false;
498 }
499 super.onPause();
500 }
501
502 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700503 protected void onSaveInstanceState(Bundle outState) {
504 super.onSaveInstanceState(outState);
505 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700506 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
507 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700508 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700509 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700510 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700511 }
512
513 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700514 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700515 if (fragment instanceof DialpadFragment) {
516 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700517 if (!mShowDialpadOnResume) {
518 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
519 transaction.hide(mDialpadFragment);
520 transaction.commit();
521 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700522 } else if (fragment instanceof SmartDialSearchFragment) {
523 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700524 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700525 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700526 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700527 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700528 } else if (fragment instanceof ListsFragment) {
529 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700530 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700531 }
Yorke Leec3766332013-07-31 11:13:16 -0700532 }
533
Alon Albertb453e5b2013-09-10 15:54:23 -0700534 protected void handleMenuSettings() {
535 openTelephonySetting(this);
536 }
537
538 public static void openTelephonySetting(Activity activity) {
539 final Intent settingsIntent = getCallSettingsIntent();
540 activity.startActivity(settingsIntent);
541 }
542
Chiao Cheng94b10b52012-08-17 16:59:12 -0700543 @Override
544 public void onClick(View view) {
545 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700546 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700547 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700548 mInCallDialpadUp = false;
549 showDialpadFragment(true);
550 } else {
551 // Dial button was pressed; tell the Dialpad fragment
552 mDialpadFragment.dialButtonPressed();
553 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700554 break;
Yorke Leec3766332013-07-31 11:13:16 -0700555 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800556 try {
557 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
558 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
559 } catch (ActivityNotFoundException e) {
560 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
561 Toast.LENGTH_SHORT).show();
562 }
Yorke Leec3766332013-07-31 11:13:16 -0700563 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700564 case R.id.dialtacts_options_menu_button:
565 buildOptionsMenu(view).show();
566 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700567 default: {
568 Log.wtf(TAG, "Unexpected onClick event from " + view);
569 break;
570 }
571 }
572 }
573
Yorke Leec3766332013-07-31 11:13:16 -0700574 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700575 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700576 switch (item.getItemId()) {
577 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700578 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700579 break;
580 case R.id.menu_add_contact:
581 try {
582 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
583 } catch (ActivityNotFoundException e) {
584 Toast toast = Toast.makeText(this,
585 R.string.add_contact_not_available,
586 Toast.LENGTH_SHORT);
587 toast.show();
588 }
589 break;
590 case R.id.menu_import_export:
591 // We hard-code the "contactsAreAvailable" argument because doing it properly would
592 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
593 // now in Dialtacts for (potential) performance reasons. Compare with how it is
594 // done in {@link PeopleActivity}.
595 ImportExportDialogFragment.show(getFragmentManager(), true,
596 DialtactsActivity.class);
597 return true;
598 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700599 ClearFrequentsDialog.show(getFragmentManager());
600 return true;
601 case R.id.menu_call_settings:
602 handleMenuSettings();
603 return true;
Nancy Chen8e066292014-06-18 17:16:10 -0700604 case R.id.menu_select_subscription:
605 SelectSubscriptionDialogFragment.show(getFragmentManager(), mSubscriptionManager);
Nancy Chenbeededb2014-06-10 18:30:28 -0700606 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700607 }
608 return false;
609 }
610
611 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700612 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
613 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
614 if (resultCode == RESULT_OK) {
615 final ArrayList<String> matches = data.getStringArrayListExtra(
616 RecognizerIntent.EXTRA_RESULTS);
617 if (matches.size() > 0) {
618 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700619 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700620 } else {
621 Log.e(TAG, "Voice search - nothing heard");
622 }
623 } else {
624 Log.e(TAG, "Voice search failed");
625 }
626 }
627 super.onActivityResult(requestCode, resultCode, data);
628 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700629
Andrew Lee2a58ab82014-05-15 02:16:04 -0700630 /**
631 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
632 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
633 * @see #onDialpadShown
634 */
Yorke Leec3766332013-07-31 11:13:16 -0700635 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700636 if (mIsDialpadShown) {
637 return;
638 }
639 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700640 mDialpadFragment.setAnimate(animate);
Nancy Chen8e066292014-06-18 17:16:10 -0700641 mDialpadFragment.setSubscriptionManager(mSubscriptionManager);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700642
Chiao Cheng94b10b52012-08-17 16:59:12 -0700643 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700644 ft.show(mDialpadFragment);
645 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700646
Yorke Lee5253be02014-05-21 18:50:03 -0700647 mActionBarController.onDialpadUp();
648
Andrew Leeb1903842014-05-15 16:11:24 -0700649 if (!isInSearchUi()) {
650 enterSearchUi(true /* isSmartDial */, mSearchQuery);
651 }
Yorke Leec3766332013-07-31 11:13:16 -0700652 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700653
Andrew Lee2a58ab82014-05-15 02:16:04 -0700654 /**
655 * Callback from child DialpadFragment when the dialpad is shown.
656 */
657 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700658 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
659 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
660 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700661 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700662 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700663 } else {
664 mDialpadFragment.setYFraction(0);
665 }
666
Andrew Lee2a58ab82014-05-15 02:16:04 -0700667 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700668 }
669
670 /**
671 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
672 * a callback after the hide animation ends.
673 * @see #commitDialpadFragmentHide
674 */
Yorke Leeca195042013-09-25 16:29:38 -0700675 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700676 if (mDialpadFragment == null) {
677 return;
678 }
Yorke Leef6673d32013-08-23 15:34:17 -0700679 if (clearDialpad) {
680 mDialpadFragment.clearDialpad();
681 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700682 if (!mIsDialpadShown) {
683 return;
Yorke Leec3766332013-07-31 11:13:16 -0700684 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700685 mIsDialpadShown = false;
686 mDialpadFragment.setAnimate(animate);
687
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700688 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700689 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
690 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
691
692 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700693 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700694 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700695 } else {
696 commitDialpadFragmentHide();
697 }
698
Yorke Lee5253be02014-05-21 18:50:03 -0700699 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700700
Andrew Leed4cde832014-05-16 15:56:48 -0700701 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700702 if (TextUtils.isEmpty(mSearchQuery)) {
703 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700704 }
Andrew Leed4cde832014-05-16 15:56:48 -0700705 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700706 }
707
708 /**
709 * Finishes hiding the dialpad fragment after any animations are completed.
710 */
711 private void commitDialpadFragmentHide() {
712 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700713 ft.hide(mDialpadFragment);
714 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700715 }
716
Andrew Lee2a58ab82014-05-15 02:16:04 -0700717 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700718 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700719 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700720 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700721 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700722 fragment = mRegularSearchFragment;
723 }
724 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700725 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700726 }
727 }
728
Yorke Lee5253be02014-05-21 18:50:03 -0700729 @Override
730 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700731 return mInDialpadSearch || mInRegularSearch;
732 }
733
Yorke Lee5253be02014-05-21 18:50:03 -0700734 @Override
735 public boolean hasSearchQuery() {
736 return !TextUtils.isEmpty(mSearchQuery);
737 }
738
739 @Override
740 public boolean shouldShowActionBar() {
741 return mListsFragment.shouldShowActionBar();
742 }
743
Yorke Leeb207f8a2013-08-29 18:51:06 -0700744 private void setNotInSearchUi() {
745 mInDialpadSearch = false;
746 mInRegularSearch = false;
747 }
748
Yorke Lee311969c2013-08-26 06:31:11 -0700749 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700750 if (mIsDialpadShown) {
751 hideDialpadFragment(false, true);
752 } else {
753 exitSearchUi();
754 }
Yorke Lee311969c2013-08-26 06:31:11 -0700755 }
756
Yorke Leee00c9fe2014-04-12 12:42:06 -0700757 private void hideInputMethod(View view) {
758 final InputMethodManager imm = (InputMethodManager) getSystemService(
759 Context.INPUT_METHOD_SERVICE);
760 if (imm != null && view != null) {
761 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
762 }
763 }
764
Yorke Lee53a22302014-04-29 18:13:46 -0700765 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700766 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
767 if (canIntentBeHandled(voiceIntent)) {
768 mVoiceSearchButton.setVisibility(View.VISIBLE);
769 mVoiceSearchButton.setOnClickListener(this);
770 } else {
771 mVoiceSearchButton.setVisibility(View.GONE);
772 }
773 }
774
Andrew Leee74a10e2014-05-16 14:31:40 -0700775 private OptionsPopupMenu buildOptionsMenu(View invoker) {
776 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
777 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700778 final Menu menu = popupMenu.getMenu();
Nancy Chen8e066292014-06-18 17:16:10 -0700779 final MenuItem selectSubscription = menu.findItem(R.id.menu_select_subscription);
780 selectSubscription.setVisible(mSubscriptionManager != null);
Andrew Leee74a10e2014-05-16 14:31:40 -0700781 popupMenu.setOnMenuItemClickListener(this);
782 return popupMenu;
783 }
784
Yorke Lee86e21f72014-04-02 16:49:38 -0700785 @Override
786 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700787 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700788 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700789 mPendingSearchViewQuery = null;
790 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700791 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700792 }
793
Chiao Cheng94b10b52012-08-17 16:59:12 -0700794 /**
795 * Returns true if the intent is due to hitting the green send key (hardware call button:
796 * KEYCODE_CALL) while in a call.
797 *
798 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700799 * @return true if the intent is due to hitting the green send key while in a call
800 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700801 private boolean isSendKeyWhileInCall(Intent intent) {
802 // If there is a call in progress and the user launched the dialer by hitting the call
803 // button, go straight to the in-call screen.
804 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700805
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700806 if (callKey) {
807 getTelephonyManager().showCallScreen();
808 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700809 }
810
811 return false;
812 }
813
814 /**
815 * Sets the current tab based on the intent's request type
816 *
817 * @param intent Intent that contains information about which tab should be selected
818 */
Yorke Leec3766332013-07-31 11:13:16 -0700819 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700820 // 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 -0700821 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700822 finish();
823 return;
824 }
825
Yorke Lee669b6082013-09-17 15:43:38 -0700826 if (mDialpadFragment != null) {
827 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700828 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700829 mDialpadFragment.setStartedFromNewIntent(true);
830 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
831 mInCallDialpadUp = true;
832 }
833 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700834 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700835 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700836 }
837
838 @Override
839 public void onNewIntent(Intent newIntent) {
840 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700841 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700842
Chiao Cheng94b10b52012-08-17 16:59:12 -0700843 invalidateOptionsMenu();
844 }
845
846 /** Returns true if the given intent contains a phone number to populate the dialer with */
847 private boolean isDialIntent(Intent intent) {
848 final String action = intent.getAction();
849 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
850 return true;
851 }
852 if (Intent.ACTION_VIEW.equals(action)) {
853 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700854 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700855 return true;
856 }
857 }
858 return false;
859 }
860
861 /**
862 * Returns an appropriate call origin for this Activity. May return null when no call origin
863 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
864 * for remembering the tab in which the user made a phone call, so the external app's DIAL
865 * request should not be counted.)
866 */
867 public String getCallOrigin() {
868 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
869 }
870
Chiao Cheng94b10b52012-08-17 16:59:12 -0700871 /**
Yorke Leec3766332013-07-31 11:13:16 -0700872 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700873 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700874 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700875 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700876 // Weird race condition where fragment is doing work after the activity is destroyed
877 // due to talkback being on (b/10209937). Just return since we can't do any
878 // constructive here.
879 return;
880 }
881
Yorke Leeef2b7382013-08-09 17:39:25 -0700882 if (DEBUG) {
883 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
884 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700885
Yorke Leec3766332013-07-31 11:13:16 -0700886 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700887 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700888 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700889 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700890 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700891 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700892
Yorke Leeb207f8a2013-08-29 18:51:06 -0700893 final String tag;
894 if (smartDialSearch) {
895 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
896 } else {
897 tag = TAG_REGULAR_SEARCH_FRAGMENT;
898 }
899 mInDialpadSearch = smartDialSearch;
900 mInRegularSearch = !smartDialSearch;
901
Andrew Lee752956e2014-05-15 11:43:38 -0700902 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700903 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700904 if (fragment == null) {
905 if (smartDialSearch) {
906 fragment = new SmartDialSearchFragment();
907 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700908 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700909 }
Andrew Leeb1903842014-05-15 16:11:24 -0700910 transaction.add(R.id.dialtacts_frame, fragment, tag);
911 } else {
912 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700913 }
Andrew Leeb1903842014-05-15 16:11:24 -0700914
Yorke Lee86e21f72014-04-02 16:49:38 -0700915 // DialtactsActivity will provide the options menu
916 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700917 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700918 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700919 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700920
921 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700922 }
923
924 /**
Yorke Leec3766332013-07-31 11:13:16 -0700925 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700926 */
Yorke Leec3766332013-07-31 11:13:16 -0700927 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700928 // See related bug in enterSearchUI();
929 if (getFragmentManager().isDestroyed()) {
930 return;
931 }
Andrew Leeb1903842014-05-15 16:11:24 -0700932
Andrew Leeb1903842014-05-15 16:11:24 -0700933 mSearchView.setText(null);
934 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700935 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700936
Andrew Leeb1903842014-05-15 16:11:24 -0700937 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700938 if (mSmartDialSearchFragment != null) {
939 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700940 }
Andrew Leeb1903842014-05-15 16:11:24 -0700941 if (mRegularSearchFragment != null) {
942 transaction.remove(mRegularSearchFragment);
943 }
944 transaction.commit();
945
946 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700947 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700948 }
949
950 /** Returns an Intent to launch Call Settings screen */
951 public static Intent getCallSettingsIntent() {
952 final Intent intent = new Intent(Intent.ACTION_MAIN);
953 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
954 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
955 return intent;
956 }
957
958 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700959 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700960 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700961 if (TextUtils.isEmpty(mSearchQuery) ||
962 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
963 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700964 exitSearchUi();
965 }
Yorke Leef6673d32013-08-23 15:34:17 -0700966 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700967 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700968 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700969 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700970 } else {
971 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700972 }
Yorke Leec3766332013-07-31 11:13:16 -0700973 }
974
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700975 /**
976 * @return True if the search UI was exited, false otherwise
977 */
978 private boolean maybeExitSearchUi() {
979 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
980 exitSearchUi();
981 hideInputMethod(parentLayout);
982 return true;
983 }
984 return false;
985 }
986
Yorke Leec3766332013-07-31 11:13:16 -0700987 @Override
988 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700989 if (mSmartDialSearchFragment != null) {
990 mSmartDialSearchFragment.setAddToContactNumber(query);
991 }
Yorke Leec3766332013-07-31 11:13:16 -0700992 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
993 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700994
995 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700996 if (DEBUG) {
997 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
998 }
999 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1000 // This callback can happen if the dialpad fragment is recreated because of
1001 // activity destruction. In that case, don't update the search view because
1002 // that would bring the user back to the search fragment regardless of the
1003 // previous state of the application. Instead, just return here and let the
1004 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001005 if (!TextUtils.isEmpty(normalizedQuery)) {
1006 mPendingSearchViewQuery = normalizedQuery;
1007 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001008 return;
1009 }
Yorke Lee53a22302014-04-29 18:13:46 -07001010 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001011 }
1012 }
Yorke Leec3766332013-07-31 11:13:16 -07001013
1014 @Override
1015 public void onListFragmentScrollStateChange(int scrollState) {
1016 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001017 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001018 hideInputMethod(getCurrentFocus());
1019 }
1020 }
1021
1022 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001023 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001024 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001025 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1026 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001027 }
1028
Yorke Lee86e21f72014-04-02 16:49:38 -07001029 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001030 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001031 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001032 }
1033
1034 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001035 // TODO(santoscordon): Replace with a TelecommService method call.
1036 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001037 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001038
Yorke Leee1424812013-09-04 18:24:48 -07001039 public static Intent getAddNumberToContactIntent(CharSequence text) {
1040 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1041 intent.putExtra(Intents.Insert.PHONE, text);
1042 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1043 return intent;
1044 }
1045
Yorke Leeda0f9042013-12-05 14:25:51 -08001046 private boolean canIntentBeHandled(Intent intent) {
1047 final PackageManager packageManager = getPackageManager();
1048 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1049 PackageManager.MATCH_DEFAULT_ONLY);
1050 return resolveInfo != null && resolveInfo.size() > 0;
1051 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001052
Yorke Lee6a1461a2014-04-21 16:27:14 -07001053 @Override
1054 public void showCallHistory() {
1055 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1056 // CONTENT_TYPE, so that we always open our call log from our dialer
1057 final Intent intent = new Intent(this, CallLogActivity.class);
1058 startActivity(intent);
1059 }
1060
Yorke Lee86e21f72014-04-02 16:49:38 -07001061 /**
1062 * Called when the user has long-pressed a contact tile to start a drag operation.
1063 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001064 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001065 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001066 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001067 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001068 }
Andrew Lee18963442014-06-06 17:20:13 -07001069 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001070 }
1071
1072 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001073 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1074 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001075
Yorke Lee86e21f72014-04-02 16:49:38 -07001076 /**
1077 * Called when the user has released a contact tile after long-pressing it.
1078 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001079 @Override
1080 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001081 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001082 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001083 }
Andrew Lee18963442014-06-06 17:20:13 -07001084 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001085 }
1086
1087 @Override
1088 public void onDroppedOnRemove() {}
1089
1090 /**
Yorke Leed999b712014-04-23 15:10:58 -07001091 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001092 * once it has been attached to the activity.
1093 */
1094 @Override
1095 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001096 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001097 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001098 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001099
1100 @Override
1101 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001102 // Specify call-origin so that users will see the previous tab instead of
1103 // CallLog screen (search UI will be automatically exited).
1104 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001105 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001106 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001107 }
1108
1109 @Override
1110 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001111 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001112 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001113 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001114 }
1115
1116 @Override
1117 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001118 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001119 }
1120
1121 @Override
1122 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001123 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001124 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001125
Yorke Leecc4660d2014-04-24 11:22:57 -07001126 @Override
1127 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001128 // Only scroll the button when the first tab is selected. The button should scroll from
1129 // the middle to right position only on the transition from the first tab to the second
1130 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001131 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001132 mFloatingActionButtonController.onPageScrolled(positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001133 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1134 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001135 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001136 }
1137
1138 @Override
1139 public void onPageSelected(int position) {
1140 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001141 }
1142
1143 @Override
1144 public void onPageScrollStateChanged(int state) {
1145 }
1146
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001147 private TelephonyManager getTelephonyManager() {
1148 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1149 }
1150
Yorke Lee5253be02014-05-21 18:50:03 -07001151 @Override
1152 public boolean isActionBarShowing() {
1153 return mActionBarController.isActionBarShowing();
1154 }
1155
Andrew Lee9da8fb42014-06-03 14:03:09 -07001156 public boolean isDialpadShown() {
1157 return mIsDialpadShown;
1158 }
1159
Yorke Lee5253be02014-05-21 18:50:03 -07001160 @Override
1161 public int getActionBarHideOffset() {
1162 return getActionBar().getHideOffset();
1163 }
1164
1165 @Override
1166 public int getActionBarHeight() {
1167 return mActionBarHeight;
1168 }
1169
1170 @Override
1171 public void setActionBarHideOffset(int hideOffset) {
1172 getActionBar().setHideOffset(hideOffset);
1173 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001174
1175 /**
1176 * Updates controller based on currently known information.
1177 *
1178 * @param animate Whether or not to animate the transition.
1179 */
1180 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1181 int align;
1182 if (mIsDialpadShown) {
1183 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1184 : FloatingActionButtonController.ALIGN_MIDDLE;
1185 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001186 if (!mIsLandscape) {
1187 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1188 ? FloatingActionButtonController.ALIGN_MIDDLE
1189 : FloatingActionButtonController.ALIGN_RIGHT;
1190 } else {
1191 align = FloatingActionButtonController.ALIGN_RIGHT;
1192 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001193 }
1194 mFloatingActionButtonController.align(align,
1195 0 /* offsetX */,
1196 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1197 animate);
1198 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001199}