blob: cbb2fe865c5bcc8aab2610cb00b6a807e491bc1f [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 Lee7d20f822014-06-19 17:09:33 -070087import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070088import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070089import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070090import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070091import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070092
Yorke Leec3766332013-07-31 11:13:16 -070093import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080094import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070095
Chiao Cheng94b10b52012-08-17 16:59:12 -070096/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070097 * The dialer tab's title is 'phone', a more common name (see strings.xml).
98 */
Yorke Leec3766332013-07-31 11:13:16 -070099public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700100 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700101 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800102 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700103 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700104 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700105 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700106 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700107 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700108 PopupMenu.OnMenuItemClickListener,
Nancy Chenbeededb2014-06-10 18:30:28 -0700109 SelectSIMDialogFragment.OnClickOkListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700110 ViewPager.OnPageChangeListener,
111 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700112 private static final String TAG = "DialtactsActivity";
113
Ihab Awad526c0b82014-02-27 12:55:36 -0800114 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700115
Yorke Leef74011e2013-08-02 11:30:30 -0700116 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
117
Chiao Cheng94b10b52012-08-17 16:59:12 -0700118 /** Used to open Call Setting */
119 private static final String PHONE_PACKAGE = "com.android.phone";
120 private static final String CALL_SETTINGS_CLASS_NAME =
121 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700122 /** @see #getCallOrigin() */
123 private static final String CALL_ORIGIN_DIALTACTS =
124 "com.android.dialer.DialtactsActivity";
125
Yorke Leeb207f8a2013-08-29 18:51:06 -0700126 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
127 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700128 private static final String KEY_SEARCH_QUERY = "search_query";
129 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700130 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700131
Yorke Leec3766332013-07-31 11:13:16 -0700132 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
133 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
134 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
135 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700136
Chiao Cheng94b10b52012-08-17 16:59:12 -0700137 /**
138 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
139 */
140 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
141
Yorke Leec3766332013-07-31 11:13:16 -0700142 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700143
Nancy Chenbeededb2014-06-10 18:30:28 -0700144 /**
145 * Constant to indicate there is only one service provider available.
146 */
147 private static final int NO_MULTI_SIM = -1;
148
Yorke Lee28aab272014-06-11 10:24:19 -0700149 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700150
Yorke Leec3766332013-07-31 11:13:16 -0700151 /**
Yorke Leec3766332013-07-31 11:13:16 -0700152 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700153 */
Yorke Leef74011e2013-08-02 11:30:30 -0700154 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700155
156 /**
157 * Fragment for searching phone numbers using the alphanumeric keyboard.
158 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700159 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700160
161 /**
162 * Fragment for searching phone numbers using the dialpad.
163 */
164 private SmartDialSearchFragment mSmartDialSearchFragment;
165
Yorke Leee00c9fe2014-04-12 12:42:06 -0700166 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700167 * Animation that slides in.
168 */
169 private Animation mSlideIn;
170
171 /**
172 * Animation that slides out.
173 */
174 private Animation mSlideOut;
175
176 /**
177 * Listener for after slide out animation completes on dialer fragment.
178 */
179 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
180 @Override
181 public void onAnimationEnd(Animation animation) {
182 commitDialpadFragmentHide();
183 }
184 };
185
186 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700187 * Fragment containing the speed dial list, recents list, and all contacts list.
188 */
189 private ListsFragment mListsFragment;
190
Yorke Leeb207f8a2013-08-29 18:51:06 -0700191 private boolean mInDialpadSearch;
192 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700193 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700194 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700195 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700196
Yorke Leeef2b7382013-08-09 17:39:25 -0700197 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700198 * Whether or not the device is in landscape orientation.
199 */
200 private boolean mIsLandscape;
201
202 /**
Nancy Chenbeededb2014-06-10 18:30:28 -0700203 * Information about the currently selected SIM card.
204 */
205 private int mCurrentSimCard = NO_MULTI_SIM;
206
207 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700208 * The position of the currently selected tab in the attached {@link ListsFragment}.
209 */
210 private int mCurrentTabPosition = 0;
211
212 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700213 * True if the dialpad is only temporarily showing due to being in call
214 */
215 private boolean mInCallDialpadUp;
216
217 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700218 * True when this activity has been launched for the first time.
219 */
Yorke Lee98702de2013-08-06 12:03:32 -0700220 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700221
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700222 /**
223 * Search query to be applied to the SearchView in the ActionBar once
224 * onCreateOptionsMenu has been called.
225 */
226 private String mPendingSearchViewQuery;
227
Yorke Lee53a22302014-04-29 18:13:46 -0700228 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700229 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700230
Yorke Leeef2b7382013-08-09 17:39:25 -0700231 private String mSearchQuery;
232
Yorke Leefce269a2013-08-12 11:56:04 -0700233 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700234 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700235 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700236
237 private String mDescriptionDialButtonStr;
238 private String mActionMenuDialpadButtonStr;
239 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700240 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700241 /**
242 * Additional offset for FAB to be lowered when dialpad is open.
243 */
244 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700245
Andrew Lee2423a2f2014-05-29 14:14:45 -0700246 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700247
Andrew Leee74a10e2014-05-16 14:31:40 -0700248 private class OptionsPopupMenu extends PopupMenu {
249 public OptionsPopupMenu(Context context, View anchor) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700250 super(context, anchor);
251 }
252
253 @Override
254 public void show() {
255 final Menu menu = getMenu();
256 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700257 clearFrequents.setVisible(mListsFragment != null &&
258 mListsFragment.getSpeedDialFragment() != null &&
259 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700260 super.show();
261 }
262 }
263
Chiao Cheng94b10b52012-08-17 16:59:12 -0700264 /**
Yorke Lee28266192014-05-01 10:05:52 -0700265 * Listener that listens to drag events and sends their x and y coordinates to a
266 * {@link DragDropController}.
267 */
268 private class LayoutOnDragListener implements OnDragListener {
269 @Override
270 public boolean onDrag(View v, DragEvent event) {
271 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700272 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700273 }
274 return true;
275 }
276 }
277
278 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700279 * Listener used to send search queries to the phone search fragment.
280 */
Yorke Lee53a22302014-04-29 18:13:46 -0700281 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700282 @Override
283 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
284 }
Yorke Leec3766332013-07-31 11:13:16 -0700285
Andrew Lee99a570c2014-05-15 14:18:50 -0700286 @Override
287 public void onTextChanged(CharSequence s, int start, int before, int count) {
288 final String newText = s.toString();
289 if (newText.equals(mSearchQuery)) {
290 // If the query hasn't changed (perhaps due to activity being destroyed
291 // and restored, or user launching the same DIAL intent twice), then there is
292 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700293 return;
294 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700295 if (DEBUG) {
296 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700297 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700298 }
Yorke Lee710709d2014-05-29 07:18:42 -0700299 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700300
Andrew Lee90374a72014-05-16 15:01:09 -0700301 // Show search fragment only when the query string is changed to non-empty text.
302 if (!TextUtils.isEmpty(newText)) {
303 // Call enterSearchUi only if we are switching search modes, or showing a search
304 // fragment for the first time.
305 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
306 (!mIsDialpadShown && mInRegularSearch);
307 if (!sameSearchMode) {
308 enterSearchUi(mIsDialpadShown, mSearchQuery);
309 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700310 }
311
Andrew Leea8515422014-06-13 16:53:54 -0700312 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700313 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700314 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700315 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700316 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700317 }
318
319 @Override
320 public void afterTextChanged(Editable s) {
321 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700322 };
323
Andrew Leeb1903842014-05-15 16:11:24 -0700324
325 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700326 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700327 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700328 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700329 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700330 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700331 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700332 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700333 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
334 }
Andrew Leeb1903842014-05-15 16:11:24 -0700335 }
336 };
337
338 /**
339 * If the search term is empty and the user closes the soft keyboard, close the search UI.
340 */
341 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
342 @Override
343 public boolean onKey(View v, int keyCode, KeyEvent event) {
344 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
345 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700346 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700347 }
348 return false;
349 }
350 };
351
Chiao Cheng94b10b52012-08-17 16:59:12 -0700352 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700353 protected void onCreate(Bundle savedInstanceState) {
354 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700355 mFirstLaunch = true;
356
Andrew Lee2423a2f2014-05-29 14:14:45 -0700357 final Resources resources = getResources();
358 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700359 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
360 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700361
Yorke Lee8898cd02013-08-08 10:24:27 -0700362 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800363 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700364
Yorke Lee53a22302014-04-29 18:13:46 -0700365 final ActionBar actionBar = getActionBar();
366 actionBar.setCustomView(R.layout.search_edittext);
367 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700368 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700369
Yorke Lee5253be02014-05-21 18:50:03 -0700370 mActionBarController = new ActionBarController(this,
371 (SearchEditTextLayout) actionBar.getCustomView());
372
Yorke Lee53a22302014-04-29 18:13:46 -0700373
Andrew Lee04675a52014-06-05 18:36:20 -0700374 SearchEditTextLayout searchEditTextLayout =
375 (SearchEditTextLayout) actionBar.getCustomView();
376 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
377
378 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700379 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700380 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
381 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
382 .setOnClickListener(mSearchViewOnClickListener);
383 searchEditTextLayout.findViewById(R.id.search_box_start_search)
384 .setOnClickListener(mSearchViewOnClickListener);
385 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700386 @Override
387 public void onBackButtonClicked() {
388 onBackPressed();
389 }
390 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700391
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700392 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700393 == Configuration.ORIENTATION_LANDSCAPE;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700394 final View floatingActionButtonContainer = findViewById(
395 R.id.floating_action_button_container);
396 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
397 int floatingActionButtonWidth = resources.getDimensionPixelSize(
398 R.dimen.floating_action_button_width);
399 mFloatingActionButton.setOnClickListener(this);
400 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700401 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700402 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
403 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700404
Andrew Lee04675a52014-06-05 18:36:20 -0700405 ImageButton optionsMenuButton =
406 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700407 optionsMenuButton.setOnClickListener(this);
408 final OptionsPopupMenu optionsMenu = buildOptionsMenu(optionsMenuButton);
409 optionsMenuButton.setOnTouchListener(optionsMenu.getDragToOpenListener());
410
Yorke Leeef2b7382013-08-09 17:39:25 -0700411 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
412 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700413 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800414 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700415 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800416 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
417 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700418 } else {
419 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700420 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
421 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700422 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700423 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700424 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700425 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700426
427 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700428 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700429 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700430 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700431
432 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700433
Yorke Lee28aab272014-06-11 10:24:19 -0700434 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700435 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
436 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700437 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700438 new ViewTreeObserver.OnGlobalLayoutListener() {
439 @Override
440 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700441 final ViewTreeObserver observer = floatingActionButtonContainer
442 .getViewTreeObserver();
443 if (!observer.isAlive()) {
444 return;
445 }
446 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700447 int screenWidth = parentLayout.getWidth();
448 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700449 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700450 }
451 });
Andrew Lee0c667702014-05-12 14:31:45 -0700452
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700453 setupActivityOverlay();
454
Yorke Lee0baa98b2013-08-22 10:55:16 -0700455 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700456 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700457 }
458
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700459 private void setupActivityOverlay() {
460 final View activityOverlay = findViewById(R.id.activity_overlay);
461 activityOverlay.setOnTouchListener(new OnTouchListener() {
462 @Override
463 public boolean onTouch(View v, MotionEvent event) {
464 if (!mIsDialpadShown) {
465 maybeExitSearchUi();
466 }
467 return false;
468 }
469 });
470 }
471
Chiao Cheng94b10b52012-08-17 16:59:12 -0700472 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700473 protected void onResume() {
474 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700475 if (mFirstLaunch) {
476 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700477 } else if (!phoneIsInUse() && mInCallDialpadUp) {
478 hideDialpadFragment(false, true);
479 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700480 } else if (mShowDialpadOnResume) {
481 showDialpadFragment(false);
482 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700483 }
484 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700485 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700486 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700487 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700488 }
489
490 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700491 protected void onPause() {
492 if (mClearSearchOnPause) {
493 hideDialpadAndSearchUi();
494 mClearSearchOnPause = false;
495 }
496 super.onPause();
497 }
498
499 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700500 protected void onSaveInstanceState(Bundle outState) {
501 super.onSaveInstanceState(outState);
502 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700503 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
504 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700505 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700506 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700507 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700508 }
509
510 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700511 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700512 if (fragment instanceof DialpadFragment) {
513 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700514 if (!mShowDialpadOnResume) {
515 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
516 transaction.hide(mDialpadFragment);
517 transaction.commit();
518 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700519 } else if (fragment instanceof SmartDialSearchFragment) {
520 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700521 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700522 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700523 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700524 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700525 } else if (fragment instanceof ListsFragment) {
526 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700527 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700528 }
Yorke Leec3766332013-07-31 11:13:16 -0700529 }
530
Alon Albertb453e5b2013-09-10 15:54:23 -0700531 protected void handleMenuSettings() {
532 openTelephonySetting(this);
533 }
534
535 public static void openTelephonySetting(Activity activity) {
536 final Intent settingsIntent = getCallSettingsIntent();
537 activity.startActivity(settingsIntent);
538 }
539
Chiao Cheng94b10b52012-08-17 16:59:12 -0700540 @Override
541 public void onClick(View view) {
542 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700543 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700544 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700545 mInCallDialpadUp = false;
546 showDialpadFragment(true);
547 } else {
548 // Dial button was pressed; tell the Dialpad fragment
549 mDialpadFragment.dialButtonPressed();
550 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700551 break;
Yorke Leec3766332013-07-31 11:13:16 -0700552 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800553 try {
554 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
555 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
556 } catch (ActivityNotFoundException e) {
557 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
558 Toast.LENGTH_SHORT).show();
559 }
Yorke Leec3766332013-07-31 11:13:16 -0700560 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700561 case R.id.dialtacts_options_menu_button:
562 buildOptionsMenu(view).show();
563 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700564 default: {
565 Log.wtf(TAG, "Unexpected onClick event from " + view);
566 break;
567 }
568 }
569 }
570
Yorke Leec3766332013-07-31 11:13:16 -0700571 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700572 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700573 switch (item.getItemId()) {
574 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700575 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700576 break;
577 case R.id.menu_add_contact:
578 try {
579 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
580 } catch (ActivityNotFoundException e) {
581 Toast toast = Toast.makeText(this,
582 R.string.add_contact_not_available,
583 Toast.LENGTH_SHORT);
584 toast.show();
585 }
586 break;
587 case R.id.menu_import_export:
588 // We hard-code the "contactsAreAvailable" argument because doing it properly would
589 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
590 // now in Dialtacts for (potential) performance reasons. Compare with how it is
591 // done in {@link PeopleActivity}.
592 ImportExportDialogFragment.show(getFragmentManager(), true,
593 DialtactsActivity.class);
594 return true;
595 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700596 ClearFrequentsDialog.show(getFragmentManager());
597 return true;
598 case R.id.menu_call_settings:
599 handleMenuSettings();
600 return true;
Nancy Chenbeededb2014-06-10 18:30:28 -0700601 case R.id.menu_select_sim:
602 SelectSIMDialogFragment.show(getFragmentManager(), mCurrentSimCard);
603 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700604 }
605 return false;
606 }
607
608 @Override
Nancy Chenbeededb2014-06-10 18:30:28 -0700609 public void passSimUpdate(int simId) {
610 mCurrentSimCard = simId;
Nancy Chen4c924562014-06-11 15:31:16 -0700611 if (mIsDialpadShown) {
612 mDialpadFragment.setSimCard(simId);
613 }
Nancy Chenbeededb2014-06-10 18:30:28 -0700614 }
615
616 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700617 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
618 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
619 if (resultCode == RESULT_OK) {
620 final ArrayList<String> matches = data.getStringArrayListExtra(
621 RecognizerIntent.EXTRA_RESULTS);
622 if (matches.size() > 0) {
623 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700624 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700625 } else {
626 Log.e(TAG, "Voice search - nothing heard");
627 }
628 } else {
629 Log.e(TAG, "Voice search failed");
630 }
631 }
632 super.onActivityResult(requestCode, resultCode, data);
633 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700634
Andrew Lee2a58ab82014-05-15 02:16:04 -0700635 /**
636 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
637 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
638 * @see #onDialpadShown
639 */
Yorke Leec3766332013-07-31 11:13:16 -0700640 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700641 if (mIsDialpadShown) {
642 return;
643 }
644 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700645 mDialpadFragment.setAnimate(animate);
Nancy Chen4c924562014-06-11 15:31:16 -0700646 mDialpadFragment.setSimCard(mCurrentSimCard);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700647
Chiao Cheng94b10b52012-08-17 16:59:12 -0700648 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700649 ft.show(mDialpadFragment);
650 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700651
Yorke Lee5253be02014-05-21 18:50:03 -0700652 mActionBarController.onDialpadUp();
653
Andrew Leeb1903842014-05-15 16:11:24 -0700654 if (!isInSearchUi()) {
655 enterSearchUi(true /* isSmartDial */, mSearchQuery);
656 }
Yorke Leec3766332013-07-31 11:13:16 -0700657 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700658
Andrew Lee2a58ab82014-05-15 02:16:04 -0700659 /**
660 * Callback from child DialpadFragment when the dialpad is shown.
661 */
662 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700663 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
664 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
665 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700666 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700667 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700668 } else {
669 mDialpadFragment.setYFraction(0);
670 }
671
Andrew Lee2a58ab82014-05-15 02:16:04 -0700672 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700673 }
674
675 /**
676 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
677 * a callback after the hide animation ends.
678 * @see #commitDialpadFragmentHide
679 */
Yorke Leeca195042013-09-25 16:29:38 -0700680 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700681 if (mDialpadFragment == null) {
682 return;
683 }
Yorke Leef6673d32013-08-23 15:34:17 -0700684 if (clearDialpad) {
685 mDialpadFragment.clearDialpad();
686 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700687 if (!mIsDialpadShown) {
688 return;
Yorke Leec3766332013-07-31 11:13:16 -0700689 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700690 mIsDialpadShown = false;
691 mDialpadFragment.setAnimate(animate);
692
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700693 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700694 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
695 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
696
697 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700698 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700699 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700700 } else {
701 commitDialpadFragmentHide();
702 }
703
Yorke Lee5253be02014-05-21 18:50:03 -0700704 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700705
Andrew Leed4cde832014-05-16 15:56:48 -0700706 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700707 if (TextUtils.isEmpty(mSearchQuery)) {
708 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700709 }
Andrew Leed4cde832014-05-16 15:56:48 -0700710 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700711 }
712
713 /**
714 * Finishes hiding the dialpad fragment after any animations are completed.
715 */
716 private void commitDialpadFragmentHide() {
717 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700718 ft.hide(mDialpadFragment);
719 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700720 }
721
Andrew Lee2a58ab82014-05-15 02:16:04 -0700722 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700723 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700724 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700725 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700726 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700727 fragment = mRegularSearchFragment;
728 }
729 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700730 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700731 }
732 }
733
Yorke Lee5253be02014-05-21 18:50:03 -0700734 @Override
735 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700736 return mInDialpadSearch || mInRegularSearch;
737 }
738
Yorke Lee5253be02014-05-21 18:50:03 -0700739 @Override
740 public boolean hasSearchQuery() {
741 return !TextUtils.isEmpty(mSearchQuery);
742 }
743
744 @Override
745 public boolean shouldShowActionBar() {
746 return mListsFragment.shouldShowActionBar();
747 }
748
Yorke Leeb207f8a2013-08-29 18:51:06 -0700749 private void setNotInSearchUi() {
750 mInDialpadSearch = false;
751 mInRegularSearch = false;
752 }
753
Yorke Lee311969c2013-08-26 06:31:11 -0700754 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700755 if (mIsDialpadShown) {
756 hideDialpadFragment(false, true);
757 } else {
758 exitSearchUi();
759 }
Yorke Lee311969c2013-08-26 06:31:11 -0700760 }
761
Yorke Leee00c9fe2014-04-12 12:42:06 -0700762 private void hideInputMethod(View view) {
763 final InputMethodManager imm = (InputMethodManager) getSystemService(
764 Context.INPUT_METHOD_SERVICE);
765 if (imm != null && view != null) {
766 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
767 }
768 }
769
Yorke Lee53a22302014-04-29 18:13:46 -0700770 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700771 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
772 if (canIntentBeHandled(voiceIntent)) {
773 mVoiceSearchButton.setVisibility(View.VISIBLE);
774 mVoiceSearchButton.setOnClickListener(this);
775 } else {
776 mVoiceSearchButton.setVisibility(View.GONE);
777 }
778 }
779
Andrew Leee74a10e2014-05-16 14:31:40 -0700780 private OptionsPopupMenu buildOptionsMenu(View invoker) {
781 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
782 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700783 final Menu menu = popupMenu.getMenu();
784 final MenuItem selectSim = menu.findItem(R.id.menu_select_sim);
785 selectSim.setVisible(mCurrentSimCard != NO_MULTI_SIM);
Andrew Leee74a10e2014-05-16 14:31:40 -0700786 popupMenu.setOnMenuItemClickListener(this);
787 return popupMenu;
788 }
789
Yorke Lee86e21f72014-04-02 16:49:38 -0700790 @Override
791 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700792 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700793 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700794 mPendingSearchViewQuery = null;
795 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700796 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700797 }
798
Chiao Cheng94b10b52012-08-17 16:59:12 -0700799 /**
800 * Returns true if the intent is due to hitting the green send key (hardware call button:
801 * KEYCODE_CALL) while in a call.
802 *
803 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700804 * @return true if the intent is due to hitting the green send key while in a call
805 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700806 private boolean isSendKeyWhileInCall(Intent intent) {
807 // If there is a call in progress and the user launched the dialer by hitting the call
808 // button, go straight to the in-call screen.
809 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700810
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700811 if (callKey) {
812 getTelephonyManager().showCallScreen();
813 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700814 }
815
816 return false;
817 }
818
819 /**
820 * Sets the current tab based on the intent's request type
821 *
822 * @param intent Intent that contains information about which tab should be selected
823 */
Yorke Leec3766332013-07-31 11:13:16 -0700824 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700825 // 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 -0700826 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700827 finish();
828 return;
829 }
830
Yorke Lee669b6082013-09-17 15:43:38 -0700831 if (mDialpadFragment != null) {
832 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700833 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700834 mDialpadFragment.setStartedFromNewIntent(true);
835 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
836 mInCallDialpadUp = true;
837 }
838 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700839 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700840 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700841 }
842
843 @Override
844 public void onNewIntent(Intent newIntent) {
845 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700846 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700847
Chiao Cheng94b10b52012-08-17 16:59:12 -0700848 invalidateOptionsMenu();
849 }
850
851 /** Returns true if the given intent contains a phone number to populate the dialer with */
852 private boolean isDialIntent(Intent intent) {
853 final String action = intent.getAction();
854 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
855 return true;
856 }
857 if (Intent.ACTION_VIEW.equals(action)) {
858 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700859 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700860 return true;
861 }
862 }
863 return false;
864 }
865
866 /**
867 * Returns an appropriate call origin for this Activity. May return null when no call origin
868 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
869 * for remembering the tab in which the user made a phone call, so the external app's DIAL
870 * request should not be counted.)
871 */
872 public String getCallOrigin() {
873 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
874 }
875
Chiao Cheng94b10b52012-08-17 16:59:12 -0700876 /**
Yorke Leec3766332013-07-31 11:13:16 -0700877 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700878 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700879 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700880 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700881 // Weird race condition where fragment is doing work after the activity is destroyed
882 // due to talkback being on (b/10209937). Just return since we can't do any
883 // constructive here.
884 return;
885 }
886
Yorke Leeef2b7382013-08-09 17:39:25 -0700887 if (DEBUG) {
888 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
889 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700890
Yorke Leec3766332013-07-31 11:13:16 -0700891 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700892 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700893 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700894 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700895 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700896 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700897
Yorke Leeb207f8a2013-08-29 18:51:06 -0700898 final String tag;
899 if (smartDialSearch) {
900 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
901 } else {
902 tag = TAG_REGULAR_SEARCH_FRAGMENT;
903 }
904 mInDialpadSearch = smartDialSearch;
905 mInRegularSearch = !smartDialSearch;
906
Andrew Lee752956e2014-05-15 11:43:38 -0700907 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700908 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700909 if (fragment == null) {
910 if (smartDialSearch) {
911 fragment = new SmartDialSearchFragment();
912 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700913 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700914 }
Andrew Leeb1903842014-05-15 16:11:24 -0700915 transaction.add(R.id.dialtacts_frame, fragment, tag);
916 } else {
917 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700918 }
Andrew Leeb1903842014-05-15 16:11:24 -0700919
Yorke Lee86e21f72014-04-02 16:49:38 -0700920 // DialtactsActivity will provide the options menu
921 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700922 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700923 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700924 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700925
926 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700927 }
928
929 /**
Yorke Leec3766332013-07-31 11:13:16 -0700930 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700931 */
Yorke Leec3766332013-07-31 11:13:16 -0700932 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700933 // See related bug in enterSearchUI();
934 if (getFragmentManager().isDestroyed()) {
935 return;
936 }
Andrew Leeb1903842014-05-15 16:11:24 -0700937
Andrew Leeb1903842014-05-15 16:11:24 -0700938 mSearchView.setText(null);
939 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700940 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700941
Andrew Leeb1903842014-05-15 16:11:24 -0700942 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700943 if (mSmartDialSearchFragment != null) {
944 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700945 }
Andrew Leeb1903842014-05-15 16:11:24 -0700946 if (mRegularSearchFragment != null) {
947 transaction.remove(mRegularSearchFragment);
948 }
949 transaction.commit();
950
951 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700952 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700953 }
954
955 /** Returns an Intent to launch Call Settings screen */
956 public static Intent getCallSettingsIntent() {
957 final Intent intent = new Intent(Intent.ACTION_MAIN);
958 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
959 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
960 return intent;
961 }
962
963 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700964 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700965 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700966 if (TextUtils.isEmpty(mSearchQuery) ||
967 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
968 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700969 exitSearchUi();
970 }
Yorke Leef6673d32013-08-23 15:34:17 -0700971 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700972 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700973 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700974 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700975 } else {
976 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700977 }
Yorke Leec3766332013-07-31 11:13:16 -0700978 }
979
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700980 /**
981 * @return True if the search UI was exited, false otherwise
982 */
983 private boolean maybeExitSearchUi() {
984 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
985 exitSearchUi();
986 hideInputMethod(parentLayout);
987 return true;
988 }
989 return false;
990 }
991
Yorke Leec3766332013-07-31 11:13:16 -0700992 @Override
993 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700994 if (mSmartDialSearchFragment != null) {
995 mSmartDialSearchFragment.setAddToContactNumber(query);
996 }
Yorke Leec3766332013-07-31 11:13:16 -0700997 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
998 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700999
1000 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001001 if (DEBUG) {
1002 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1003 }
1004 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1005 // This callback can happen if the dialpad fragment is recreated because of
1006 // activity destruction. In that case, don't update the search view because
1007 // that would bring the user back to the search fragment regardless of the
1008 // previous state of the application. Instead, just return here and let the
1009 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001010 if (!TextUtils.isEmpty(normalizedQuery)) {
1011 mPendingSearchViewQuery = normalizedQuery;
1012 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001013 return;
1014 }
Yorke Lee53a22302014-04-29 18:13:46 -07001015 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001016 }
1017 }
Yorke Leec3766332013-07-31 11:13:16 -07001018
1019 @Override
1020 public void onListFragmentScrollStateChange(int scrollState) {
1021 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001022 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -07001023 hideInputMethod(getCurrentFocus());
1024 }
1025 }
1026
1027 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001028 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001029 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001030 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1031 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001032 }
1033
Yorke Lee86e21f72014-04-02 16:49:38 -07001034 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001035 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001036 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001037 }
1038
1039 private boolean phoneIsInUse() {
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001040 // TODO(santoscordon): Replace with a TelecommService method call.
1041 return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
Yorke Leec3766332013-07-31 11:13:16 -07001042 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001043
Yorke Leee1424812013-09-04 18:24:48 -07001044 public static Intent getAddNumberToContactIntent(CharSequence text) {
1045 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1046 intent.putExtra(Intents.Insert.PHONE, text);
1047 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1048 return intent;
1049 }
1050
Yorke Leeda0f9042013-12-05 14:25:51 -08001051 private boolean canIntentBeHandled(Intent intent) {
1052 final PackageManager packageManager = getPackageManager();
1053 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1054 PackageManager.MATCH_DEFAULT_ONLY);
1055 return resolveInfo != null && resolveInfo.size() > 0;
1056 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001057
Yorke Lee6a1461a2014-04-21 16:27:14 -07001058 @Override
1059 public void showCallHistory() {
1060 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1061 // CONTENT_TYPE, so that we always open our call log from our dialer
1062 final Intent intent = new Intent(this, CallLogActivity.class);
1063 startActivity(intent);
1064 }
1065
Yorke Lee86e21f72014-04-02 16:49:38 -07001066 /**
1067 * Called when the user has long-pressed a contact tile to start a drag operation.
1068 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001069 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001070 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001071 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001072 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001073 }
Andrew Lee18963442014-06-06 17:20:13 -07001074 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001075 }
1076
1077 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001078 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1079 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001080
Yorke Lee86e21f72014-04-02 16:49:38 -07001081 /**
1082 * Called when the user has released a contact tile after long-pressing it.
1083 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001084 @Override
1085 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001086 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001087 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001088 }
Andrew Lee18963442014-06-06 17:20:13 -07001089 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001090 }
1091
1092 @Override
1093 public void onDroppedOnRemove() {}
1094
1095 /**
Yorke Leed999b712014-04-23 15:10:58 -07001096 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001097 * once it has been attached to the activity.
1098 */
1099 @Override
1100 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001101 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001102 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001103 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001104
1105 @Override
1106 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001107 // Specify call-origin so that users will see the previous tab instead of
1108 // CallLog screen (search UI will be automatically exited).
1109 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001110 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001111 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001112 }
1113
1114 @Override
1115 public void onCallNumberDirectly(String phoneNumber) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001116 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001117 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001118 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001119 }
1120
1121 @Override
1122 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001123 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001124 }
1125
1126 @Override
1127 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001128 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001129 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001130
Yorke Leecc4660d2014-04-24 11:22:57 -07001131 @Override
1132 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001133 // Only scroll the button when the first tab is selected. The button should scroll from
1134 // the middle to right position only on the transition from the first tab to the second
1135 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001136 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001137 mFloatingActionButtonController.onPageScrolled(positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001138 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1139 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001140 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001141 }
1142
1143 @Override
1144 public void onPageSelected(int position) {
1145 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001146 }
1147
1148 @Override
1149 public void onPageScrollStateChanged(int state) {
1150 }
1151
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001152 private TelephonyManager getTelephonyManager() {
1153 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1154 }
1155
Yorke Lee5253be02014-05-21 18:50:03 -07001156 @Override
1157 public boolean isActionBarShowing() {
1158 return mActionBarController.isActionBarShowing();
1159 }
1160
Andrew Lee9da8fb42014-06-03 14:03:09 -07001161 public boolean isDialpadShown() {
1162 return mIsDialpadShown;
1163 }
1164
Yorke Lee5253be02014-05-21 18:50:03 -07001165 @Override
1166 public int getActionBarHideOffset() {
1167 return getActionBar().getHideOffset();
1168 }
1169
1170 @Override
1171 public int getActionBarHeight() {
1172 return mActionBarHeight;
1173 }
1174
1175 @Override
1176 public void setActionBarHideOffset(int hideOffset) {
1177 getActionBar().setHideOffset(hideOffset);
1178 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001179
1180 /**
1181 * Updates controller based on currently known information.
1182 *
1183 * @param animate Whether or not to animate the transition.
1184 */
1185 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1186 int align;
1187 if (mIsDialpadShown) {
1188 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1189 : FloatingActionButtonController.ALIGN_MIDDLE;
1190 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001191 if (!mIsLandscape) {
1192 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1193 ? FloatingActionButtonController.ALIGN_MIDDLE
1194 : FloatingActionButtonController.ALIGN_RIGHT;
1195 } else {
1196 align = FloatingActionButtonController.ALIGN_RIGHT;
1197 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001198 }
1199 mFloatingActionButtonController.align(align,
1200 0 /* offsetX */,
1201 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1202 animate);
1203 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001204}