blob: d48b28e72e84766491f22451c50f0079ed7b31ac [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;
Yorke Leec3766332013-07-31 11:13:16 -070040import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070041import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070043import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070044import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070045import android.view.DragEvent;
Andrew Leeb1903842014-05-15 16:11:24 -070046import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070047import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070049import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070050import android.view.View;
Sai Cheemalapati41460652014-06-02 21:05:39 -070051import android.view.ViewTreeObserver;
Yorke Lee28266192014-05-01 10:05:52 -070052import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070053import android.view.View.OnTouchListener;
Andrew Lee2a58ab82014-05-15 02:16:04 -070054import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070055import android.view.animation.AnimationUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070056import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070057import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070058import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070059import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070060import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070061import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080062import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070063
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070064import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070065import com.android.contacts.common.activity.TransactionSafeActivity;
Andrew Lee3c14bc32014-05-28 15:43:03 -070066import com.android.contacts.common.animation.AnimationListenerAdapter;
Yorke Leec3766332013-07-31 11:13:16 -070067import com.android.contacts.common.dialog.ClearFrequentsDialog;
Nancy Chenbeededb2014-06-10 18:30:28 -070068import com.android.contacts.common.dialog.SelectSIMDialogFragment;
Yorke Leec3766332013-07-31 11:13:16 -070069import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080070import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070071import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070072import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070073import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070074import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070075import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070076import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070077import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080078import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070079import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080080import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070081import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leed999b712014-04-23 15:10:58 -070082import com.android.dialer.list.SpeedDialFragment;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070083import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070084import com.android.dialer.list.RegularSearchFragment;
85import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070086import com.android.dialer.list.SmartDialSearchFragment;
Yorke Lee5253be02014-05-21 18:50:03 -070087import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070088import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070089import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070090import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070091
Yorke Leec3766332013-07-31 11:13:16 -070092import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080093import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070094
Chiao Cheng94b10b52012-08-17 16:59:12 -070095/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070096 * The dialer tab's title is 'phone', a more common name (see strings.xml).
97 */
Yorke Leec3766332013-07-31 11:13:16 -070098public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -070099 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700100 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800101 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700102 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700103 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700104 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700105 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700106 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700107 PopupMenu.OnMenuItemClickListener,
Nancy Chenbeededb2014-06-10 18:30:28 -0700108 SelectSIMDialogFragment.OnClickOkListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700109 ViewPager.OnPageChangeListener,
110 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700111 private static final String TAG = "DialtactsActivity";
112
Ihab Awad526c0b82014-02-27 12:55:36 -0800113 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700114
Yorke Leef74011e2013-08-02 11:30:30 -0700115 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
116
Chiao Cheng94b10b52012-08-17 16:59:12 -0700117 /** Used to open Call Setting */
118 private static final String PHONE_PACKAGE = "com.android.phone";
119 private static final String CALL_SETTINGS_CLASS_NAME =
120 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700121 /** @see #getCallOrigin() */
122 private static final String CALL_ORIGIN_DIALTACTS =
123 "com.android.dialer.DialtactsActivity";
124
Yorke Leeb207f8a2013-08-29 18:51:06 -0700125 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
126 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700127 private static final String KEY_SEARCH_QUERY = "search_query";
128 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700129 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700130
Yorke Leec3766332013-07-31 11:13:16 -0700131 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
132 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
133 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
134 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700135
Chiao Cheng94b10b52012-08-17 16:59:12 -0700136 /**
137 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
138 */
139 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
140
Yorke Leec3766332013-07-31 11:13:16 -0700141 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700142
Nancy Chenbeededb2014-06-10 18:30:28 -0700143 /**
144 * Constant to indicate there is only one service provider available.
145 */
146 private static final int NO_MULTI_SIM = -1;
147
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 Chenbeededb2014-06-10 18:30:28 -0700202 * Information about the currently selected SIM card.
203 */
204 private int mCurrentSimCard = NO_MULTI_SIM;
205
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
Yorke Lee53a22302014-04-29 18:13:46 -0700372
Andrew Lee04675a52014-06-05 18:36:20 -0700373 SearchEditTextLayout searchEditTextLayout =
374 (SearchEditTextLayout) actionBar.getCustomView();
375 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
376
377 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700378 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700379 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
380 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
381 .setOnClickListener(mSearchViewOnClickListener);
382 searchEditTextLayout.findViewById(R.id.search_box_start_search)
383 .setOnClickListener(mSearchViewOnClickListener);
384 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700385 @Override
386 public void onBackButtonClicked() {
387 onBackPressed();
388 }
389 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700390
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700391 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700392 == Configuration.ORIENTATION_LANDSCAPE;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700393 final View floatingActionButtonContainer = findViewById(
394 R.id.floating_action_button_container);
395 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
396 int floatingActionButtonWidth = resources.getDimensionPixelSize(
397 R.dimen.floating_action_button_width);
398 mFloatingActionButton.setOnClickListener(this);
399 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700400 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700401 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
402 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700403
Andrew Lee04675a52014-06-05 18:36:20 -0700404 ImageButton optionsMenuButton =
405 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700406 optionsMenuButton.setOnClickListener(this);
407 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
408 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
409
Yorke Leeef2b7382013-08-09 17:39:25 -0700410 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
411 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700412 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800413 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700414 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800415 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
416 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700417 } else {
418 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700419 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
420 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700421 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700422 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700423 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700424 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700425
426 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700427 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700428 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700429 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700430
431 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700432
Yorke Lee28aab272014-06-11 10:24:19 -0700433 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700434 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
435 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700436 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700437 new ViewTreeObserver.OnGlobalLayoutListener() {
438 @Override
439 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700440 final ViewTreeObserver observer = floatingActionButtonContainer
441 .getViewTreeObserver();
442 if (!observer.isAlive()) {
443 return;
444 }
445 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700446 int screenWidth = parentLayout.getWidth();
447 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700448 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700449 }
450 });
Andrew Lee0c667702014-05-12 14:31:45 -0700451
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700452 setupActivityOverlay();
453
Yorke Lee0baa98b2013-08-22 10:55:16 -0700454 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700455 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700456 }
457
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700458 private void setupActivityOverlay() {
459 final View activityOverlay = findViewById(R.id.activity_overlay);
460 activityOverlay.setOnTouchListener(new OnTouchListener() {
461 @Override
462 public boolean onTouch(View v, MotionEvent event) {
463 if (!mIsDialpadShown) {
464 maybeExitSearchUi();
465 }
466 return false;
467 }
468 });
469 }
470
Chiao Cheng94b10b52012-08-17 16:59:12 -0700471 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700472 protected void onResume() {
473 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700474 if (mFirstLaunch) {
475 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700476 } else if (!phoneIsInUse() && mInCallDialpadUp) {
477 hideDialpadFragment(false, true);
478 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700479 } else if (mShowDialpadOnResume) {
480 showDialpadFragment(false);
481 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700482 }
483 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700484 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700485 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700486 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700487 }
488
489 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700490 protected void onPause() {
491 if (mClearSearchOnPause) {
492 hideDialpadAndSearchUi();
493 mClearSearchOnPause = false;
494 }
495 super.onPause();
496 }
497
498 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700499 protected void onSaveInstanceState(Bundle outState) {
500 super.onSaveInstanceState(outState);
501 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700502 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
503 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700504 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700505 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700506 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700507 }
508
509 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700510 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700511 if (fragment instanceof DialpadFragment) {
512 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700513 if (!mShowDialpadOnResume) {
514 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
515 transaction.hide(mDialpadFragment);
516 transaction.commit();
517 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700518 } else if (fragment instanceof SmartDialSearchFragment) {
519 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700520 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700521 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700522 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700523 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700524 } else if (fragment instanceof ListsFragment) {
525 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700526 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700527 }
Yorke Leec3766332013-07-31 11:13:16 -0700528 }
529
Alon Albertb453e5b2013-09-10 15:54:23 -0700530 protected void handleMenuSettings() {
531 openTelephonySetting(this);
532 }
533
534 public static void openTelephonySetting(Activity activity) {
535 final Intent settingsIntent = getCallSettingsIntent();
536 activity.startActivity(settingsIntent);
537 }
538
Chiao Cheng94b10b52012-08-17 16:59:12 -0700539 @Override
540 public void onClick(View view) {
541 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700542 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700543 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700544 mInCallDialpadUp = false;
545 showDialpadFragment(true);
546 } else {
547 // Dial button was pressed; tell the Dialpad fragment
548 mDialpadFragment.dialButtonPressed();
549 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700550 break;
Yorke Leec3766332013-07-31 11:13:16 -0700551 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800552 try {
553 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
554 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
555 } catch (ActivityNotFoundException e) {
556 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
557 Toast.LENGTH_SHORT).show();
558 }
Yorke Leec3766332013-07-31 11:13:16 -0700559 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700560 case R.id.dialtacts_options_menu_button:
561 buildOptionsMenu(view).show();
562 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700563 default: {
564 Log.wtf(TAG, "Unexpected onClick event from " + view);
565 break;
566 }
567 }
568 }
569
Yorke Leec3766332013-07-31 11:13:16 -0700570 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700571 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700572 switch (item.getItemId()) {
573 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700574 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700575 break;
576 case R.id.menu_add_contact:
577 try {
578 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
579 } catch (ActivityNotFoundException e) {
580 Toast toast = Toast.makeText(this,
581 R.string.add_contact_not_available,
582 Toast.LENGTH_SHORT);
583 toast.show();
584 }
585 break;
586 case R.id.menu_import_export:
587 // We hard-code the "contactsAreAvailable" argument because doing it properly would
588 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
589 // now in Dialtacts for (potential) performance reasons. Compare with how it is
590 // done in {@link PeopleActivity}.
591 ImportExportDialogFragment.show(getFragmentManager(), true,
592 DialtactsActivity.class);
593 return true;
594 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700595 ClearFrequentsDialog.show(getFragmentManager());
596 return true;
597 case R.id.menu_call_settings:
598 handleMenuSettings();
599 return true;
Nancy Chenbeededb2014-06-10 18:30:28 -0700600 case R.id.menu_select_sim:
601 SelectSIMDialogFragment.show(getFragmentManager(), mCurrentSimCard);
602 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700603 }
604 return false;
605 }
606
607 @Override
Nancy Chenbeededb2014-06-10 18:30:28 -0700608 public void passSimUpdate(int simId) {
609 mCurrentSimCard = simId;
Nancy Chen4c924562014-06-11 15:31:16 -0700610 if (mIsDialpadShown) {
611 mDialpadFragment.setSimCard(simId);
612 }
Nancy Chenbeededb2014-06-10 18:30:28 -0700613 }
614
615 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700616 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
617 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
618 if (resultCode == RESULT_OK) {
619 final ArrayList<String> matches = data.getStringArrayListExtra(
620 RecognizerIntent.EXTRA_RESULTS);
621 if (matches.size() > 0) {
622 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700623 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700624 } else {
625 Log.e(TAG, "Voice search - nothing heard");
626 }
627 } else {
628 Log.e(TAG, "Voice search failed");
629 }
630 }
631 super.onActivityResult(requestCode, resultCode, data);
632 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700633
Andrew Lee2a58ab82014-05-15 02:16:04 -0700634 /**
635 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
636 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
637 * @see #onDialpadShown
638 */
Yorke Leec3766332013-07-31 11:13:16 -0700639 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700640 if (mIsDialpadShown) {
641 return;
642 }
643 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700644 mDialpadFragment.setAnimate(animate);
Nancy Chen4c924562014-06-11 15:31:16 -0700645 mDialpadFragment.setSimCard(mCurrentSimCard);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700646
Chiao Cheng94b10b52012-08-17 16:59:12 -0700647 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700648 ft.show(mDialpadFragment);
649 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700650
Yorke Lee5253be02014-05-21 18:50:03 -0700651 mActionBarController.onDialpadUp();
652
Andrew Leeb1903842014-05-15 16:11:24 -0700653 if (!isInSearchUi()) {
654 enterSearchUi(true /* isSmartDial */, mSearchQuery);
655 }
Yorke Leec3766332013-07-31 11:13:16 -0700656 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700657
Andrew Lee2a58ab82014-05-15 02:16:04 -0700658 /**
659 * Callback from child DialpadFragment when the dialpad is shown.
660 */
661 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700662 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
663 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
664 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700665 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700666 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700667 } else {
668 mDialpadFragment.setYFraction(0);
669 }
670
Andrew Lee2a58ab82014-05-15 02:16:04 -0700671 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700672 }
673
674 /**
675 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
676 * a callback after the hide animation ends.
677 * @see #commitDialpadFragmentHide
678 */
Yorke Leeca195042013-09-25 16:29:38 -0700679 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700680 if (mDialpadFragment == null) {
681 return;
682 }
Yorke Leef6673d32013-08-23 15:34:17 -0700683 if (clearDialpad) {
684 mDialpadFragment.clearDialpad();
685 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700686 if (!mIsDialpadShown) {
687 return;
Yorke Leec3766332013-07-31 11:13:16 -0700688 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700689 mIsDialpadShown = false;
690 mDialpadFragment.setAnimate(animate);
691
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700692 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700693 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
694 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
695
696 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700697 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700698 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700699 } else {
700 commitDialpadFragmentHide();
701 }
702
Yorke Lee5253be02014-05-21 18:50:03 -0700703 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700704
Andrew Leed4cde832014-05-16 15:56:48 -0700705 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700706 if (TextUtils.isEmpty(mSearchQuery)) {
707 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700708 }
Andrew Leed4cde832014-05-16 15:56:48 -0700709 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700710 }
711
712 /**
713 * Finishes hiding the dialpad fragment after any animations are completed.
714 */
715 private void commitDialpadFragmentHide() {
716 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700717 ft.hide(mDialpadFragment);
718 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700719 }
720
Andrew Lee2a58ab82014-05-15 02:16:04 -0700721 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700722 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700723 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700724 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700725 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700726 fragment = mRegularSearchFragment;
727 }
728 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700729 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700730 }
731 }
732
Yorke Lee5253be02014-05-21 18:50:03 -0700733 @Override
734 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700735 return mInDialpadSearch || mInRegularSearch;
736 }
737
Yorke Lee5253be02014-05-21 18:50:03 -0700738 @Override
739 public boolean hasSearchQuery() {
740 return !TextUtils.isEmpty(mSearchQuery);
741 }
742
743 @Override
744 public boolean shouldShowActionBar() {
745 return mListsFragment.shouldShowActionBar();
746 }
747
Yorke Leeb207f8a2013-08-29 18:51:06 -0700748 private void setNotInSearchUi() {
749 mInDialpadSearch = false;
750 mInRegularSearch = false;
751 }
752
Yorke Lee311969c2013-08-26 06:31:11 -0700753 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700754 if (mIsDialpadShown) {
755 hideDialpadFragment(false, true);
756 } else {
757 exitSearchUi();
758 }
Yorke Lee311969c2013-08-26 06:31:11 -0700759 }
760
Yorke Leee00c9fe2014-04-12 12:42:06 -0700761 private void hideInputMethod(View view) {
762 final InputMethodManager imm = (InputMethodManager) getSystemService(
763 Context.INPUT_METHOD_SERVICE);
764 if (imm != null && view != null) {
765 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
766 }
767 }
768
Yorke Lee53a22302014-04-29 18:13:46 -0700769 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700770 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
771 if (canIntentBeHandled(voiceIntent)) {
772 mVoiceSearchButton.setVisibility(View.VISIBLE);
773 mVoiceSearchButton.setOnClickListener(this);
774 } else {
775 mVoiceSearchButton.setVisibility(View.GONE);
776 }
777 }
778
Andrew Leee74a10e2014-05-16 14:31:40 -0700779 private OptionsPopupMenu buildOptionsMenu(View invoker) {
780 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
781 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700782 final Menu menu = popupMenu.getMenu();
783 final MenuItem selectSim = menu.findItem(R.id.menu_select_sim);
784 selectSim.setVisible(mCurrentSimCard != NO_MULTI_SIM);
Andrew Leee74a10e2014-05-16 14:31:40 -0700785 popupMenu.setOnMenuItemClickListener(this);
786 return popupMenu;
787 }
788
Yorke Lee86e21f72014-04-02 16:49:38 -0700789 @Override
790 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700791 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700792 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700793 mPendingSearchViewQuery = null;
794 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700795 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700796 }
797
Chiao Cheng94b10b52012-08-17 16:59:12 -0700798 /**
799 * Returns true if the intent is due to hitting the green send key (hardware call button:
800 * KEYCODE_CALL) while in a call.
801 *
802 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700803 * @return true if the intent is due to hitting the green send key while in a call
804 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700805 private boolean isSendKeyWhileInCall(Intent intent) {
806 // If there is a call in progress and the user launched the dialer by hitting the call
807 // button, go straight to the in-call screen.
808 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700809
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700810 if (callKey) {
811 getTelephonyManager().showCallScreen();
812 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700813 }
814
815 return false;
816 }
817
818 /**
819 * Sets the current tab based on the intent's request type
820 *
821 * @param intent Intent that contains information about which tab should be selected
822 */
Yorke Leec3766332013-07-31 11:13:16 -0700823 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700824 // 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 -0700825 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700826 finish();
827 return;
828 }
829
Yorke Lee669b6082013-09-17 15:43:38 -0700830 if (mDialpadFragment != null) {
831 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700832 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700833 mDialpadFragment.setStartedFromNewIntent(true);
834 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
835 mInCallDialpadUp = true;
836 }
837 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700838 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700839 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700840 }
841
842 @Override
843 public void onNewIntent(Intent newIntent) {
844 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700845 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700846
Chiao Cheng94b10b52012-08-17 16:59:12 -0700847 invalidateOptionsMenu();
848 }
849
850 /** Returns true if the given intent contains a phone number to populate the dialer with */
851 private boolean isDialIntent(Intent intent) {
852 final String action = intent.getAction();
853 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
854 return true;
855 }
856 if (Intent.ACTION_VIEW.equals(action)) {
857 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700858 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700859 return true;
860 }
861 }
862 return false;
863 }
864
865 /**
866 * Returns an appropriate call origin for this Activity. May return null when no call origin
867 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
868 * for remembering the tab in which the user made a phone call, so the external app's DIAL
869 * request should not be counted.)
870 */
871 public String getCallOrigin() {
872 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
873 }
874
Chiao Cheng94b10b52012-08-17 16:59:12 -0700875 /**
Yorke Leec3766332013-07-31 11:13:16 -0700876 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700877 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700878 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700879 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700880 // Weird race condition where fragment is doing work after the activity is destroyed
881 // due to talkback being on (b/10209937). Just return since we can't do any
882 // constructive here.
883 return;
884 }
885
Yorke Leeef2b7382013-08-09 17:39:25 -0700886 if (DEBUG) {
887 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
888 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700889
Yorke Leec3766332013-07-31 11:13:16 -0700890 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700891 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700892 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700893 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700894 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700895 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700896
Yorke Leeb207f8a2013-08-29 18:51:06 -0700897 final String tag;
898 if (smartDialSearch) {
899 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
900 } else {
901 tag = TAG_REGULAR_SEARCH_FRAGMENT;
902 }
903 mInDialpadSearch = smartDialSearch;
904 mInRegularSearch = !smartDialSearch;
905
Andrew Lee752956e2014-05-15 11:43:38 -0700906 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700907 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700908 if (fragment == null) {
909 if (smartDialSearch) {
910 fragment = new SmartDialSearchFragment();
911 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700912 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700913 }
Andrew Leeb1903842014-05-15 16:11:24 -0700914 transaction.add(R.id.dialtacts_frame, fragment, tag);
915 } else {
916 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700917 }
Andrew Leeb1903842014-05-15 16:11:24 -0700918
Yorke Lee86e21f72014-04-02 16:49:38 -0700919 // DialtactsActivity will provide the options menu
920 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700921 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700922 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700923 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700924
925 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700926 }
927
928 /**
Yorke Leec3766332013-07-31 11:13:16 -0700929 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700930 */
Yorke Leec3766332013-07-31 11:13:16 -0700931 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700932 // See related bug in enterSearchUI();
933 if (getFragmentManager().isDestroyed()) {
934 return;
935 }
Andrew Leeb1903842014-05-15 16:11:24 -0700936
Andrew Leeb1903842014-05-15 16:11:24 -0700937 mSearchView.setText(null);
938 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700939 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700940
Andrew Leeb1903842014-05-15 16:11:24 -0700941 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700942 if (mSmartDialSearchFragment != null) {
943 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700944 }
Andrew Leeb1903842014-05-15 16:11:24 -0700945 if (mRegularSearchFragment != null) {
946 transaction.remove(mRegularSearchFragment);
947 }
948 transaction.commit();
949
950 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700951 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700952 }
953
954 /** Returns an Intent to launch Call Settings screen */
955 public static Intent getCallSettingsIntent() {
956 final Intent intent = new Intent(Intent.ACTION_MAIN);
957 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
958 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
959 return intent;
960 }
961
962 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700963 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700964 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700965 if (TextUtils.isEmpty(mSearchQuery) ||
966 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
967 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700968 exitSearchUi();
969 }
Yorke Leef6673d32013-08-23 15:34:17 -0700970 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700971 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700972 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700973 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700974 } else {
975 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700976 }
Yorke Leec3766332013-07-31 11:13:16 -0700977 }
978
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700979 /**
980 * @return True if the search UI was exited, false otherwise
981 */
982 private boolean maybeExitSearchUi() {
983 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
984 exitSearchUi();
985 hideInputMethod(parentLayout);
986 return true;
987 }
988 return false;
989 }
990
Yorke Leec3766332013-07-31 11:13:16 -0700991 @Override
992 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700993 if (mSmartDialSearchFragment != null) {
994 mSmartDialSearchFragment.setAddToContactNumber(query);
995 }
Yorke Leec3766332013-07-31 11:13:16 -0700996 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
997 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700998
999 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001000 if (DEBUG) {
1001 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1002 }
1003 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1004 // This callback can happen if the dialpad fragment is recreated because of
1005 // activity destruction. In that case, don't update the search view because
1006 // that would bring the user back to the search fragment regardless of the
1007 // previous state of the application. Instead, just return here and let the
1008 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001009 if (!TextUtils.isEmpty(normalizedQuery)) {
1010 mPendingSearchViewQuery = normalizedQuery;
1011 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001012 return;
1013 }
Yorke Lee53a22302014-04-29 18:13:46 -07001014 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001015 }
1016 }
Yorke Leec3766332013-07-31 11:13:16 -07001017
1018 @Override
1019 public void onListFragmentScrollStateChange(int scrollState) {
1020 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001021 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001022 hideInputMethod(getCurrentFocus());
1023 }
1024 }
1025
1026 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001027 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001028 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001029 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1030 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001031 }
1032
Yorke Lee86e21f72014-04-02 16:49:38 -07001033 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001034 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001035 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001036 }
1037
1038 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001039 // TODO(santoscordon): Replace with a TelecommService method call.
1040 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001041 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001042
Yorke Leee1424812013-09-04 18:24:48 -07001043 public static Intent getAddNumberToContactIntent(CharSequence text) {
1044 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1045 intent.putExtra(Intents.Insert.PHONE, text);
1046 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1047 return intent;
1048 }
1049
Yorke Leeda0f9042013-12-05 14:25:51 -08001050 private boolean canIntentBeHandled(Intent intent) {
1051 final PackageManager packageManager = getPackageManager();
1052 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1053 PackageManager.MATCH_DEFAULT_ONLY);
1054 return resolveInfo != null && resolveInfo.size() > 0;
1055 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001056
Yorke Lee6a1461a2014-04-21 16:27:14 -07001057 @Override
1058 public void showCallHistory() {
1059 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1060 // CONTENT_TYPE, so that we always open our call log from our dialer
1061 final Intent intent = new Intent(this, CallLogActivity.class);
1062 startActivity(intent);
1063 }
1064
Yorke Lee86e21f72014-04-02 16:49:38 -07001065 /**
1066 * Called when the user has long-pressed a contact tile to start a drag operation.
1067 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001068 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001069 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001070 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001071 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001072 }
Andrew Lee18963442014-06-06 17:20:13 -07001073 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001074 }
1075
1076 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001077 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1078 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001079
Yorke Lee86e21f72014-04-02 16:49:38 -07001080 /**
1081 * Called when the user has released a contact tile after long-pressing it.
1082 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001083 @Override
1084 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001085 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001086 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001087 }
Andrew Lee18963442014-06-06 17:20:13 -07001088 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001089 }
1090
1091 @Override
1092 public void onDroppedOnRemove() {}
1093
1094 /**
Yorke Leed999b712014-04-23 15:10:58 -07001095 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001096 * once it has been attached to the activity.
1097 */
1098 @Override
1099 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001100 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001101 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001102 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001103
1104 @Override
1105 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001106 // Specify call-origin so that users will see the previous tab instead of
1107 // CallLog screen (search UI will be automatically exited).
1108 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001109 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001110 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001111 }
1112
1113 @Override
1114 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001115 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
1116 startActivity(intent);
1117 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001118 }
1119
1120 @Override
1121 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001122 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001123 }
1124
1125 @Override
1126 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001127 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001128 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001129
Yorke Leecc4660d2014-04-24 11:22:57 -07001130 @Override
1131 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001132 // Only scroll the button when the first tab is selected. The button should scroll from
1133 // the middle to right position only on the transition from the first tab to the second
1134 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001135 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001136 mFloatingActionButtonController.onPageScrolled(positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001137 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1138 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001139 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001140 }
1141
1142 @Override
1143 public void onPageSelected(int position) {
1144 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001145 }
1146
1147 @Override
1148 public void onPageScrollStateChanged(int state) {
1149 }
1150
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001151 private TelephonyManager getTelephonyManager() {
1152 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1153 }
1154
Yorke Lee5253be02014-05-21 18:50:03 -07001155 @Override
1156 public boolean isActionBarShowing() {
1157 return mActionBarController.isActionBarShowing();
1158 }
1159
Andrew Lee9da8fb42014-06-03 14:03:09 -07001160 public boolean isDialpadShown() {
1161 return mIsDialpadShown;
1162 }
1163
Yorke Lee5253be02014-05-21 18:50:03 -07001164 @Override
1165 public int getActionBarHideOffset() {
1166 return getActionBar().getHideOffset();
1167 }
1168
1169 @Override
1170 public int getActionBarHeight() {
1171 return mActionBarHeight;
1172 }
1173
1174 @Override
1175 public void setActionBarHideOffset(int hideOffset) {
1176 getActionBar().setHideOffset(hideOffset);
1177 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001178
1179 /**
1180 * Updates controller based on currently known information.
1181 *
1182 * @param animate Whether or not to animate the transition.
1183 */
1184 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1185 int align;
1186 if (mIsDialpadShown) {
1187 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1188 : FloatingActionButtonController.ALIGN_MIDDLE;
1189 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001190 if (!mIsLandscape) {
1191 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1192 ? FloatingActionButtonController.ALIGN_MIDDLE
1193 : FloatingActionButtonController.ALIGN_RIGHT;
1194 } else {
1195 align = FloatingActionButtonController.ALIGN_RIGHT;
1196 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001197 }
1198 mFloatingActionButtonController.align(align,
1199 0 /* offsetX */,
1200 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1201 animate);
1202 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001203}