blob: a19964b60a3ca100eca2b1f08b8005378c0edb92 [file] [log] [blame]
Chiao Cheng94b10b52012-08-17 16:59:12 -07001/*
Yorke Leec3766332013-07-31 11:13:16 -07002 * Copyright (C) 2013 The Android Open Source Project
Chiao Cheng94b10b52012-08-17 16:59:12 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.dialer;
18
Yorke Leecc4660d2014-04-24 11:22:57 -070019import android.animation.LayoutTransition;
Yorke Lee53a22302014-04-29 18:13:46 -070020import android.app.ActionBar;
Chiao Cheng94b10b52012-08-17 16:59:12 -070021import android.app.Activity;
22import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080024import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070025import android.content.Context;
26import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080027import android.content.pm.PackageManager;
28import android.content.pm.ResolveInfo;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070029import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070030import android.content.res.Resources;
Chiao Cheng94b10b52012-08-17 16:59:12 -070031import android.net.Uri;
32import android.os.Bundle;
Santos Cordond15629d2014-07-07 15:15:29 -070033import android.os.RemoteException;
Santos Cordond15629d2014-07-07 15:15:29 -070034import android.phone.PhoneManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070035import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070036import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070037import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070038import android.support.v4.view.ViewPager;
Yorke Leec3766332013-07-31 11:13:16 -070039import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070040import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070041import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070042import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070043import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070044import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070045import android.view.Gravity;
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;
Yorke Lee28266192014-05-01 10:05:52 -070051import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070052import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070053import android.view.ViewTreeObserver;
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;
Yorke Leec3766332013-07-31 11:13:16 -070066import com.android.contacts.common.dialog.ClearFrequentsDialog;
67import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080068import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070069import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070070import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070071import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070072import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070073import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070074import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070075import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080076import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070077import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080078import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070079import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070080import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070081import com.android.dialer.list.RegularSearchFragment;
82import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070083import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070084import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070085import com.android.dialer.settings.DialerSettingsActivity;
Yorke Lee7d20f822014-06-19 17:09:33 -070086import com.android.dialer.util.DialerUtils;
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;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070091import com.android.phone.common.animation.AnimationListenerAdapter;
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,
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
Yorke Lee28aab272014-06-11 10:24:19 -0700143 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700144
Yorke Leec3766332013-07-31 11:13:16 -0700145 /**
Yorke Leec3766332013-07-31 11:13:16 -0700146 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700147 */
Yorke Leef74011e2013-08-02 11:30:30 -0700148 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700149
150 /**
151 * Fragment for searching phone numbers using the alphanumeric keyboard.
152 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700153 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700154
155 /**
156 * Fragment for searching phone numbers using the dialpad.
157 */
158 private SmartDialSearchFragment mSmartDialSearchFragment;
159
Yorke Leee00c9fe2014-04-12 12:42:06 -0700160 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700161 * Animation that slides in.
162 */
163 private Animation mSlideIn;
164
165 /**
166 * Animation that slides out.
167 */
168 private Animation mSlideOut;
169
170 /**
171 * Listener for after slide out animation completes on dialer fragment.
172 */
173 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
174 @Override
175 public void onAnimationEnd(Animation animation) {
176 commitDialpadFragmentHide();
177 }
178 };
179
180 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700181 * Fragment containing the speed dial list, recents list, and all contacts list.
182 */
183 private ListsFragment mListsFragment;
184
Yorke Leeb207f8a2013-08-29 18:51:06 -0700185 private boolean mInDialpadSearch;
186 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700187 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700188 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700189 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700190
Yorke Leeef2b7382013-08-09 17:39:25 -0700191 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700192 * Whether or not the device is in landscape orientation.
193 */
194 private boolean mIsLandscape;
195
196 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700197 * The position of the currently selected tab in the attached {@link ListsFragment}.
198 */
199 private int mCurrentTabPosition = 0;
200
201 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700202 * True if the dialpad is only temporarily showing due to being in call
203 */
204 private boolean mInCallDialpadUp;
205
206 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700207 * True when this activity has been launched for the first time.
208 */
Yorke Lee98702de2013-08-06 12:03:32 -0700209 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700210
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700211 /**
212 * Search query to be applied to the SearchView in the ActionBar once
213 * onCreateOptionsMenu has been called.
214 */
215 private String mPendingSearchViewQuery;
216
Yorke Lee74edcdc2014-07-11 16:15:08 -0700217 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700218 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700219 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700220
Yorke Leeef2b7382013-08-09 17:39:25 -0700221 private String mSearchQuery;
222
Yorke Leefce269a2013-08-12 11:56:04 -0700223 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700224 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700225 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700226
227 private String mDescriptionDialButtonStr;
228 private String mActionMenuDialpadButtonStr;
229 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700230 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700231 /**
232 * Additional offset for FAB to be lowered when dialpad is open.
233 */
234 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700235
Andrew Lee2423a2f2014-05-29 14:14:45 -0700236 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700237
Andrew Leee74a10e2014-05-16 14:31:40 -0700238 private class OptionsPopupMenu extends PopupMenu {
239 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700240 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700241 }
242
243 @Override
244 public void show() {
245 final Menu menu = getMenu();
246 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700247 clearFrequents.setVisible(mListsFragment != null &&
248 mListsFragment.getSpeedDialFragment() != null &&
249 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700250 super.show();
251 }
252 }
253
Chiao Cheng94b10b52012-08-17 16:59:12 -0700254 /**
Yorke Lee28266192014-05-01 10:05:52 -0700255 * Listener that listens to drag events and sends their x and y coordinates to a
256 * {@link DragDropController}.
257 */
258 private class LayoutOnDragListener implements OnDragListener {
259 @Override
260 public boolean onDrag(View v, DragEvent event) {
261 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700262 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700263 }
264 return true;
265 }
266 }
267
268 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700269 * Listener used to send search queries to the phone search fragment.
270 */
Yorke Lee53a22302014-04-29 18:13:46 -0700271 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700272 @Override
273 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
274 }
Yorke Leec3766332013-07-31 11:13:16 -0700275
Andrew Lee99a570c2014-05-15 14:18:50 -0700276 @Override
277 public void onTextChanged(CharSequence s, int start, int before, int count) {
278 final String newText = s.toString();
279 if (newText.equals(mSearchQuery)) {
280 // If the query hasn't changed (perhaps due to activity being destroyed
281 // and restored, or user launching the same DIAL intent twice), then there is
282 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700283 return;
284 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700285 if (DEBUG) {
286 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700287 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700288 }
Yorke Lee710709d2014-05-29 07:18:42 -0700289 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700290
Andrew Lee90374a72014-05-16 15:01:09 -0700291 // Show search fragment only when the query string is changed to non-empty text.
292 if (!TextUtils.isEmpty(newText)) {
293 // Call enterSearchUi only if we are switching search modes, or showing a search
294 // fragment for the first time.
295 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
296 (!mIsDialpadShown && mInRegularSearch);
297 if (!sameSearchMode) {
298 enterSearchUi(mIsDialpadShown, mSearchQuery);
299 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700300 }
301
Andrew Leea8515422014-06-13 16:53:54 -0700302 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700303 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700304 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700305 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700306 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700307 }
308
309 @Override
310 public void afterTextChanged(Editable s) {
311 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700312 };
313
Andrew Leeb1903842014-05-15 16:11:24 -0700314
315 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700316 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700317 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700318 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700319 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700320 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700321 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700322 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700323 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
324 }
Andrew Leeb1903842014-05-15 16:11:24 -0700325 }
326 };
327
328 /**
329 * If the search term is empty and the user closes the soft keyboard, close the search UI.
330 */
331 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
332 @Override
333 public boolean onKey(View v, int keyCode, KeyEvent event) {
334 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
335 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700336 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700337 }
338 return false;
339 }
340 };
341
Chiao Cheng94b10b52012-08-17 16:59:12 -0700342 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700343 protected void onCreate(Bundle savedInstanceState) {
344 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700345 mFirstLaunch = true;
346
Andrew Lee2423a2f2014-05-29 14:14:45 -0700347 final Resources resources = getResources();
348 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700349 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
350 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700351
Yorke Lee8898cd02013-08-08 10:24:27 -0700352 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800353 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700354
Yorke Lee53a22302014-04-29 18:13:46 -0700355 final ActionBar actionBar = getActionBar();
356 actionBar.setCustomView(R.layout.search_edittext);
357 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700358 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700359
Yorke Lee5253be02014-05-21 18:50:03 -0700360 mActionBarController = new ActionBarController(this,
361 (SearchEditTextLayout) actionBar.getCustomView());
362
Andrew Lee04675a52014-06-05 18:36:20 -0700363 SearchEditTextLayout searchEditTextLayout =
364 (SearchEditTextLayout) actionBar.getCustomView();
365 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
366
367 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700368 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700369 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
370 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
371 .setOnClickListener(mSearchViewOnClickListener);
372 searchEditTextLayout.findViewById(R.id.search_box_start_search)
373 .setOnClickListener(mSearchViewOnClickListener);
374 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700375 @Override
376 public void onBackButtonClicked() {
377 onBackPressed();
378 }
379 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700380
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700381 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700382 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700383
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700384 final View floatingActionButtonContainer = findViewById(
385 R.id.floating_action_button_container);
386 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
387 int floatingActionButtonWidth = resources.getDimensionPixelSize(
388 R.dimen.floating_action_button_width);
389 mFloatingActionButton.setOnClickListener(this);
390 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700391 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700392 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
393 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700394
Andrew Lee04675a52014-06-05 18:36:20 -0700395 ImageButton optionsMenuButton =
396 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700397 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700398 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
399 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700400
Yorke Leeef2b7382013-08-09 17:39:25 -0700401 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
402 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700403 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800404 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700405 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800406 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
407 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700408 } else {
409 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700410 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
411 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700412 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700413 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700414 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700415 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700416
417 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700418 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700419 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700420 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700421
422 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700423
Yorke Lee28aab272014-06-11 10:24:19 -0700424 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700425 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
426 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700427 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700428 new ViewTreeObserver.OnGlobalLayoutListener() {
429 @Override
430 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700431 final ViewTreeObserver observer = floatingActionButtonContainer
432 .getViewTreeObserver();
433 if (!observer.isAlive()) {
434 return;
435 }
436 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700437 int screenWidth = parentLayout.getWidth();
438 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700439 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700440 }
441 });
Andrew Lee0c667702014-05-12 14:31:45 -0700442
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700443 setupActivityOverlay();
444
Yorke Lee0baa98b2013-08-22 10:55:16 -0700445 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700446 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700447 }
448
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700449 private void setupActivityOverlay() {
450 final View activityOverlay = findViewById(R.id.activity_overlay);
451 activityOverlay.setOnTouchListener(new OnTouchListener() {
452 @Override
453 public boolean onTouch(View v, MotionEvent event) {
454 if (!mIsDialpadShown) {
455 maybeExitSearchUi();
456 }
457 return false;
458 }
459 });
460 }
461
Chiao Cheng94b10b52012-08-17 16:59:12 -0700462 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700463 protected void onResume() {
464 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700465 if (mFirstLaunch) {
466 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700467 } else if (!phoneIsInUse() && mInCallDialpadUp) {
468 hideDialpadFragment(false, true);
469 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700470 } else if (mShowDialpadOnResume) {
471 showDialpadFragment(false);
472 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700473 }
474 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700475 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700476 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700477 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700478 }
479
480 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700481 protected void onPause() {
482 if (mClearSearchOnPause) {
483 hideDialpadAndSearchUi();
484 mClearSearchOnPause = false;
485 }
486 super.onPause();
487 }
488
489 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700490 protected void onSaveInstanceState(Bundle outState) {
491 super.onSaveInstanceState(outState);
492 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700493 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
494 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700495 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700496 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700497 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700498 }
499
500 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700501 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700502 if (fragment instanceof DialpadFragment) {
503 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700504 if (!mShowDialpadOnResume) {
505 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
506 transaction.hide(mDialpadFragment);
507 transaction.commit();
508 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700509 } else if (fragment instanceof SmartDialSearchFragment) {
510 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700511 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700512 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700513 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700514 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700515 } else if (fragment instanceof ListsFragment) {
516 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700517 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700518 }
Yorke Leec3766332013-07-31 11:13:16 -0700519 }
520
Alon Albertb453e5b2013-09-10 15:54:23 -0700521 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700522 final Intent intent = new Intent(this, DialerSettingsActivity.class);
523 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700524 }
525
Chiao Cheng94b10b52012-08-17 16:59:12 -0700526 @Override
527 public void onClick(View view) {
528 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700529 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700530 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700531 mInCallDialpadUp = false;
532 showDialpadFragment(true);
533 } else {
534 // Dial button was pressed; tell the Dialpad fragment
535 mDialpadFragment.dialButtonPressed();
536 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700537 break;
Yorke Leec3766332013-07-31 11:13:16 -0700538 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800539 try {
540 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
541 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
542 } catch (ActivityNotFoundException e) {
543 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
544 Toast.LENGTH_SHORT).show();
545 }
Yorke Leec3766332013-07-31 11:13:16 -0700546 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700547 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700548 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700549 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700550 default: {
551 Log.wtf(TAG, "Unexpected onClick event from " + view);
552 break;
553 }
554 }
555 }
556
Yorke Leec3766332013-07-31 11:13:16 -0700557 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700558 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700559 switch (item.getItemId()) {
560 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700561 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700562 break;
563 case R.id.menu_add_contact:
564 try {
565 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
566 } catch (ActivityNotFoundException e) {
567 Toast toast = Toast.makeText(this,
568 R.string.add_contact_not_available,
569 Toast.LENGTH_SHORT);
570 toast.show();
571 }
572 break;
573 case R.id.menu_import_export:
574 // We hard-code the "contactsAreAvailable" argument because doing it properly would
575 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
576 // now in Dialtacts for (potential) performance reasons. Compare with how it is
577 // done in {@link PeopleActivity}.
578 ImportExportDialogFragment.show(getFragmentManager(), true,
579 DialtactsActivity.class);
580 return true;
581 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700582 ClearFrequentsDialog.show(getFragmentManager());
583 return true;
584 case R.id.menu_call_settings:
585 handleMenuSettings();
586 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700587 }
588 return false;
589 }
590
591 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700592 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
593 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
594 if (resultCode == RESULT_OK) {
595 final ArrayList<String> matches = data.getStringArrayListExtra(
596 RecognizerIntent.EXTRA_RESULTS);
597 if (matches.size() > 0) {
598 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700599 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700600 } else {
601 Log.e(TAG, "Voice search - nothing heard");
602 }
603 } else {
604 Log.e(TAG, "Voice search failed");
605 }
606 }
607 super.onActivityResult(requestCode, resultCode, data);
608 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700609
Andrew Lee2a58ab82014-05-15 02:16:04 -0700610 /**
611 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
612 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
613 * @see #onDialpadShown
614 */
Yorke Leec3766332013-07-31 11:13:16 -0700615 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700616 if (mIsDialpadShown) {
617 return;
618 }
619 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700620 mDialpadFragment.setAnimate(animate);
621
Chiao Cheng94b10b52012-08-17 16:59:12 -0700622 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700623 ft.show(mDialpadFragment);
624 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700625
Yorke Lee5253be02014-05-21 18:50:03 -0700626 mActionBarController.onDialpadUp();
627
Andrew Leeb1903842014-05-15 16:11:24 -0700628 if (!isInSearchUi()) {
629 enterSearchUi(true /* isSmartDial */, mSearchQuery);
630 }
Yorke Leec3766332013-07-31 11:13:16 -0700631 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700632
Andrew Lee2a58ab82014-05-15 02:16:04 -0700633 /**
634 * Callback from child DialpadFragment when the dialpad is shown.
635 */
636 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700637 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
638 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
639 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700640 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700641 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700642 } else {
643 mDialpadFragment.setYFraction(0);
644 }
645
Andrew Lee2a58ab82014-05-15 02:16:04 -0700646 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700647 }
648
649 /**
650 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
651 * a callback after the hide animation ends.
652 * @see #commitDialpadFragmentHide
653 */
Yorke Leeca195042013-09-25 16:29:38 -0700654 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700655 if (mDialpadFragment == null) {
656 return;
657 }
Yorke Leef6673d32013-08-23 15:34:17 -0700658 if (clearDialpad) {
659 mDialpadFragment.clearDialpad();
660 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700661 if (!mIsDialpadShown) {
662 return;
Yorke Leec3766332013-07-31 11:13:16 -0700663 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700664 mIsDialpadShown = false;
665 mDialpadFragment.setAnimate(animate);
666
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700667 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700668 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
669 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
670
671 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700672 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700673 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700674 } else {
675 commitDialpadFragmentHide();
676 }
677
Yorke Lee5253be02014-05-21 18:50:03 -0700678 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700679
Andrew Leed4cde832014-05-16 15:56:48 -0700680 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700681 if (TextUtils.isEmpty(mSearchQuery)) {
682 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700683 }
Andrew Leed4cde832014-05-16 15:56:48 -0700684 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700685 }
686
687 /**
688 * Finishes hiding the dialpad fragment after any animations are completed.
689 */
690 private void commitDialpadFragmentHide() {
691 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700692 ft.hide(mDialpadFragment);
693 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700694 }
695
Andrew Lee2a58ab82014-05-15 02:16:04 -0700696 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700697 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700698 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700699 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700700 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700701 fragment = mRegularSearchFragment;
702 }
703 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700704 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700705 }
706 }
707
Yorke Lee5253be02014-05-21 18:50:03 -0700708 @Override
709 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700710 return mInDialpadSearch || mInRegularSearch;
711 }
712
Yorke Lee5253be02014-05-21 18:50:03 -0700713 @Override
714 public boolean hasSearchQuery() {
715 return !TextUtils.isEmpty(mSearchQuery);
716 }
717
718 @Override
719 public boolean shouldShowActionBar() {
720 return mListsFragment.shouldShowActionBar();
721 }
722
Yorke Leeb207f8a2013-08-29 18:51:06 -0700723 private void setNotInSearchUi() {
724 mInDialpadSearch = false;
725 mInRegularSearch = false;
726 }
727
Yorke Lee311969c2013-08-26 06:31:11 -0700728 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700729 if (mIsDialpadShown) {
730 hideDialpadFragment(false, true);
731 } else {
732 exitSearchUi();
733 }
Yorke Lee311969c2013-08-26 06:31:11 -0700734 }
735
Yorke Leee00c9fe2014-04-12 12:42:06 -0700736 private void hideInputMethod(View view) {
737 final InputMethodManager imm = (InputMethodManager) getSystemService(
738 Context.INPUT_METHOD_SERVICE);
739 if (imm != null && view != null) {
740 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
741 }
742 }
743
Yorke Lee53a22302014-04-29 18:13:46 -0700744 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700745 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
746 if (canIntentBeHandled(voiceIntent)) {
747 mVoiceSearchButton.setVisibility(View.VISIBLE);
748 mVoiceSearchButton.setOnClickListener(this);
749 } else {
750 mVoiceSearchButton.setVisibility(View.GONE);
751 }
752 }
753
Andrew Leee74a10e2014-05-16 14:31:40 -0700754 private OptionsPopupMenu buildOptionsMenu(View invoker) {
755 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
756 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700757 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700758 popupMenu.setOnMenuItemClickListener(this);
759 return popupMenu;
760 }
761
Yorke Lee86e21f72014-04-02 16:49:38 -0700762 @Override
763 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700764 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700765 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700766 mPendingSearchViewQuery = null;
767 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700768 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700769 }
770
Chiao Cheng94b10b52012-08-17 16:59:12 -0700771 /**
772 * Returns true if the intent is due to hitting the green send key (hardware call button:
773 * KEYCODE_CALL) while in a call.
774 *
775 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700776 * @return true if the intent is due to hitting the green send key while in a call
777 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700778 private boolean isSendKeyWhileInCall(Intent intent) {
779 // If there is a call in progress and the user launched the dialer by hitting the call
780 // button, go straight to the in-call screen.
781 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700782
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700783 if (callKey) {
Santos Cordond15629d2014-07-07 15:15:29 -0700784 getPhoneManager().showCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700785 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700786 }
787
788 return false;
789 }
790
791 /**
792 * Sets the current tab based on the intent's request type
793 *
794 * @param intent Intent that contains information about which tab should be selected
795 */
Yorke Leec3766332013-07-31 11:13:16 -0700796 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700797 // 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 -0700798 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700799 finish();
800 return;
801 }
802
Yorke Lee669b6082013-09-17 15:43:38 -0700803 if (mDialpadFragment != null) {
804 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700805 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700806 mDialpadFragment.setStartedFromNewIntent(true);
807 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
808 mInCallDialpadUp = true;
809 }
810 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700811 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700812 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700813 }
814
815 @Override
816 public void onNewIntent(Intent newIntent) {
817 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700818 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700819
Chiao Cheng94b10b52012-08-17 16:59:12 -0700820 invalidateOptionsMenu();
821 }
822
823 /** Returns true if the given intent contains a phone number to populate the dialer with */
824 private boolean isDialIntent(Intent intent) {
825 final String action = intent.getAction();
826 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
827 return true;
828 }
829 if (Intent.ACTION_VIEW.equals(action)) {
830 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700831 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700832 return true;
833 }
834 }
835 return false;
836 }
837
838 /**
839 * Returns an appropriate call origin for this Activity. May return null when no call origin
840 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
841 * for remembering the tab in which the user made a phone call, so the external app's DIAL
842 * request should not be counted.)
843 */
844 public String getCallOrigin() {
845 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
846 }
847
Chiao Cheng94b10b52012-08-17 16:59:12 -0700848 /**
Yorke Leec3766332013-07-31 11:13:16 -0700849 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700850 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700851 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700852 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700853 // Weird race condition where fragment is doing work after the activity is destroyed
854 // due to talkback being on (b/10209937). Just return since we can't do any
855 // constructive here.
856 return;
857 }
858
Yorke Leeef2b7382013-08-09 17:39:25 -0700859 if (DEBUG) {
860 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
861 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700862
Yorke Leec3766332013-07-31 11:13:16 -0700863 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700864 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700865 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700866 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700867 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700868 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700869
Yorke Leeb207f8a2013-08-29 18:51:06 -0700870 final String tag;
871 if (smartDialSearch) {
872 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
873 } else {
874 tag = TAG_REGULAR_SEARCH_FRAGMENT;
875 }
876 mInDialpadSearch = smartDialSearch;
877 mInRegularSearch = !smartDialSearch;
878
Andrew Lee752956e2014-05-15 11:43:38 -0700879 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700880 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700881 if (fragment == null) {
882 if (smartDialSearch) {
883 fragment = new SmartDialSearchFragment();
884 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700885 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700886 }
Andrew Leeb1903842014-05-15 16:11:24 -0700887 transaction.add(R.id.dialtacts_frame, fragment, tag);
888 } else {
889 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700890 }
Andrew Leeb1903842014-05-15 16:11:24 -0700891
Yorke Lee86e21f72014-04-02 16:49:38 -0700892 // DialtactsActivity will provide the options menu
893 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700894 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700895 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700896 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700897
898 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700899 }
900
901 /**
Yorke Leec3766332013-07-31 11:13:16 -0700902 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700903 */
Yorke Leec3766332013-07-31 11:13:16 -0700904 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700905 // See related bug in enterSearchUI();
906 if (getFragmentManager().isDestroyed()) {
907 return;
908 }
Andrew Leeb1903842014-05-15 16:11:24 -0700909
Andrew Leeb1903842014-05-15 16:11:24 -0700910 mSearchView.setText(null);
911 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700912 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700913
Andrew Leeb1903842014-05-15 16:11:24 -0700914 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700915 if (mSmartDialSearchFragment != null) {
916 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700917 }
Andrew Leeb1903842014-05-15 16:11:24 -0700918 if (mRegularSearchFragment != null) {
919 transaction.remove(mRegularSearchFragment);
920 }
921 transaction.commit();
922
923 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700924 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700925 }
926
927 /** Returns an Intent to launch Call Settings screen */
928 public static Intent getCallSettingsIntent() {
929 final Intent intent = new Intent(Intent.ACTION_MAIN);
930 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
931 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
932 return intent;
933 }
934
935 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700936 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700937 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700938 if (TextUtils.isEmpty(mSearchQuery) ||
939 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
940 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700941 exitSearchUi();
942 }
Yorke Leef6673d32013-08-23 15:34:17 -0700943 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700944 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700945 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700946 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700947 } else {
948 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700949 }
Yorke Leec3766332013-07-31 11:13:16 -0700950 }
951
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700952 /**
953 * @return True if the search UI was exited, false otherwise
954 */
955 private boolean maybeExitSearchUi() {
956 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
957 exitSearchUi();
958 hideInputMethod(parentLayout);
959 return true;
960 }
961 return false;
962 }
963
Yorke Leec3766332013-07-31 11:13:16 -0700964 @Override
965 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700966 if (mSmartDialSearchFragment != null) {
967 mSmartDialSearchFragment.setAddToContactNumber(query);
968 }
Yorke Leec3766332013-07-31 11:13:16 -0700969 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
970 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700971
972 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700973 if (DEBUG) {
974 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
975 }
976 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
977 // This callback can happen if the dialpad fragment is recreated because of
978 // activity destruction. In that case, don't update the search view because
979 // that would bring the user back to the search fragment regardless of the
980 // previous state of the application. Instead, just return here and let the
981 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700982 if (!TextUtils.isEmpty(normalizedQuery)) {
983 mPendingSearchViewQuery = normalizedQuery;
984 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700985 return;
986 }
Yorke Lee53a22302014-04-29 18:13:46 -0700987 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700988 }
989 }
Yorke Leec3766332013-07-31 11:13:16 -0700990
991 @Override
992 public void onListFragmentScrollStateChange(int scrollState) {
993 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700994 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -0700995 hideInputMethod(getCurrentFocus());
996 }
997 }
998
999 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001000 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001001 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001002 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1003 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001004 }
1005
Yorke Lee86e21f72014-04-02 16:49:38 -07001006 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001007 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001008 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001009 }
1010
1011 private boolean phoneIsInUse() {
Santos Cordond15629d2014-07-07 15:15:29 -07001012 return getPhoneManager().isInAPhoneCall();
Yorke Leec3766332013-07-31 11:13:16 -07001013 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001014
Yorke Leee1424812013-09-04 18:24:48 -07001015 public static Intent getAddNumberToContactIntent(CharSequence text) {
1016 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1017 intent.putExtra(Intents.Insert.PHONE, text);
1018 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1019 return intent;
1020 }
1021
Yorke Leeda0f9042013-12-05 14:25:51 -08001022 private boolean canIntentBeHandled(Intent intent) {
1023 final PackageManager packageManager = getPackageManager();
1024 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1025 PackageManager.MATCH_DEFAULT_ONLY);
1026 return resolveInfo != null && resolveInfo.size() > 0;
1027 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001028
Yorke Lee6a1461a2014-04-21 16:27:14 -07001029 @Override
1030 public void showCallHistory() {
1031 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1032 // CONTENT_TYPE, so that we always open our call log from our dialer
1033 final Intent intent = new Intent(this, CallLogActivity.class);
1034 startActivity(intent);
1035 }
1036
Yorke Lee86e21f72014-04-02 16:49:38 -07001037 /**
1038 * Called when the user has long-pressed a contact tile to start a drag operation.
1039 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001040 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001041 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001042 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001043 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001044 }
Andrew Lee18963442014-06-06 17:20:13 -07001045 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001046 }
1047
1048 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001049 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1050 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001051
Yorke Lee86e21f72014-04-02 16:49:38 -07001052 /**
1053 * Called when the user has released a contact tile after long-pressing it.
1054 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001055 @Override
1056 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001057 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001058 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001059 }
Andrew Lee18963442014-06-06 17:20:13 -07001060 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001061 }
1062
1063 @Override
1064 public void onDroppedOnRemove() {}
1065
1066 /**
Yorke Leed999b712014-04-23 15:10:58 -07001067 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001068 * once it has been attached to the activity.
1069 */
1070 @Override
1071 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001072 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001073 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001074 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001075
1076 @Override
1077 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001078 // Specify call-origin so that users will see the previous tab instead of
1079 // CallLog screen (search UI will be automatically exited).
1080 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001081 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001082 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001083 }
1084
1085 @Override
1086 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001087 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1088 }
1089
1090 @Override
1091 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001092 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001093 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1094 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001095 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001096 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001097 }
1098
1099 @Override
1100 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001101 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001102 }
1103
1104 @Override
1105 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001106 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001107 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001108
Yorke Leecc4660d2014-04-24 11:22:57 -07001109 @Override
1110 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001111 // Only scroll the button when the first tab is selected. The button should scroll from
1112 // the middle to right position only on the transition from the first tab to the second
1113 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001114 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001115 mFloatingActionButtonController.onPageScrolled(positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001116 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1117 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001118 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001119 }
1120
1121 @Override
1122 public void onPageSelected(int position) {
1123 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001124 }
1125
1126 @Override
1127 public void onPageScrollStateChanged(int state) {
1128 }
1129
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001130 private TelephonyManager getTelephonyManager() {
1131 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1132 }
1133
Santos Cordond15629d2014-07-07 15:15:29 -07001134 private PhoneManager getPhoneManager() {
1135 return (PhoneManager) getSystemService(Context.PHONE_SERVICE);
1136 }
1137
Yorke Lee5253be02014-05-21 18:50:03 -07001138 @Override
1139 public boolean isActionBarShowing() {
1140 return mActionBarController.isActionBarShowing();
1141 }
1142
Andrew Lee9da8fb42014-06-03 14:03:09 -07001143 public boolean isDialpadShown() {
1144 return mIsDialpadShown;
1145 }
1146
Yorke Lee5253be02014-05-21 18:50:03 -07001147 @Override
1148 public int getActionBarHideOffset() {
1149 return getActionBar().getHideOffset();
1150 }
1151
1152 @Override
1153 public int getActionBarHeight() {
1154 return mActionBarHeight;
1155 }
1156
1157 @Override
1158 public void setActionBarHideOffset(int hideOffset) {
1159 getActionBar().setHideOffset(hideOffset);
1160 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001161
1162 /**
1163 * Updates controller based on currently known information.
1164 *
1165 * @param animate Whether or not to animate the transition.
1166 */
1167 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1168 int align;
1169 if (mIsDialpadShown) {
1170 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1171 : FloatingActionButtonController.ALIGN_MIDDLE;
1172 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001173 if (!mIsLandscape) {
1174 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1175 ? FloatingActionButtonController.ALIGN_MIDDLE
1176 : FloatingActionButtonController.ALIGN_RIGHT;
1177 } else {
1178 align = FloatingActionButtonController.ALIGN_RIGHT;
1179 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001180 }
1181 mFloatingActionButtonController.align(align,
1182 0 /* offsetX */,
1183 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1184 animate);
1185 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001186}