blob: bf2af138a3a3817ff9218390501df5ba5ffbdbae [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 Lee6eec2282014-07-18 12:40:27 -070039import android.telecomm.TelecommManager;
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;
Yorke Lee74edcdc2014-07-11 16:15:08 -070046import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070047import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070049import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070050import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070051import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070052import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070053import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070054import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070055import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070056import android.view.animation.AnimationUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070057import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070058import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070059import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070060import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070061import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070062import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080063import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070064
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070065import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070066import com.android.contacts.common.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070067import com.android.contacts.common.dialog.ClearFrequentsDialog;
68import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080069import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070070import com.android.contacts.common.widget.FloatingActionButtonController;
Yorke Leec3766332013-07-31 11:13:16 -070071import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070072import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070073import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070074import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070075import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070076import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080077import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070078import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080079import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070080import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070081import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070082import com.android.dialer.list.RegularSearchFragment;
83import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070084import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070085import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070086import com.android.dialer.settings.DialerSettingsActivity;
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;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070092import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070093
Yorke Leec3766332013-07-31 11:13:16 -070094import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080095import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070096
Chiao Cheng94b10b52012-08-17 16:59:12 -070097/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070098 * The dialer tab's title is 'phone', a more common name (see strings.xml).
99 */
Yorke Leec3766332013-07-31 11:13:16 -0700100public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700101 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700102 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800103 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700104 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700105 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700106 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700107 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700108 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700109 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700110 ViewPager.OnPageChangeListener,
111 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700112 private static final String TAG = "DialtactsActivity";
113
Ihab Awad526c0b82014-02-27 12:55:36 -0800114 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700115
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 /** @see #getCallOrigin() */
119 private static final String CALL_ORIGIN_DIALTACTS =
120 "com.android.dialer.DialtactsActivity";
121
Yorke Leeb207f8a2013-08-29 18:51:06 -0700122 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
123 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700124 private static final String KEY_SEARCH_QUERY = "search_query";
125 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700126 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700127
Yorke Leec3766332013-07-31 11:13:16 -0700128 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
129 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
130 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
131 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700132
Chiao Cheng94b10b52012-08-17 16:59:12 -0700133 /**
134 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
135 */
136 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
137
Yorke Leec3766332013-07-31 11:13:16 -0700138 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700139
Yorke Lee28aab272014-06-11 10:24:19 -0700140 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700141
Yorke Leec3766332013-07-31 11:13:16 -0700142 /**
Yorke Leec3766332013-07-31 11:13:16 -0700143 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700144 */
Yorke Leef74011e2013-08-02 11:30:30 -0700145 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700146
147 /**
148 * Fragment for searching phone numbers using the alphanumeric keyboard.
149 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700150 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700151
152 /**
153 * Fragment for searching phone numbers using the dialpad.
154 */
155 private SmartDialSearchFragment mSmartDialSearchFragment;
156
Yorke Leee00c9fe2014-04-12 12:42:06 -0700157 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700158 * Animation that slides in.
159 */
160 private Animation mSlideIn;
161
162 /**
163 * Animation that slides out.
164 */
165 private Animation mSlideOut;
166
167 /**
168 * Listener for after slide out animation completes on dialer fragment.
169 */
170 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
171 @Override
172 public void onAnimationEnd(Animation animation) {
173 commitDialpadFragmentHide();
174 }
175 };
176
177 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700178 * Fragment containing the speed dial list, recents list, and all contacts list.
179 */
180 private ListsFragment mListsFragment;
181
Yorke Leeb207f8a2013-08-29 18:51:06 -0700182 private boolean mInDialpadSearch;
183 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700184 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700185 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700186 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700187
Yorke Leeef2b7382013-08-09 17:39:25 -0700188 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700189 * Whether or not the device is in landscape orientation.
190 */
191 private boolean mIsLandscape;
192
193 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700194 * The position of the currently selected tab in the attached {@link ListsFragment}.
195 */
196 private int mCurrentTabPosition = 0;
197
198 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700199 * True if the dialpad is only temporarily showing due to being in call
200 */
201 private boolean mInCallDialpadUp;
202
203 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700204 * True when this activity has been launched for the first time.
205 */
Yorke Lee98702de2013-08-06 12:03:32 -0700206 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700207
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700208 /**
209 * Search query to be applied to the SearchView in the ActionBar once
210 * onCreateOptionsMenu has been called.
211 */
212 private String mPendingSearchViewQuery;
213
Yorke Lee74edcdc2014-07-11 16:15:08 -0700214 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700215 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700216 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700217
Yorke Leeef2b7382013-08-09 17:39:25 -0700218 private String mSearchQuery;
219
Yorke Leefce269a2013-08-12 11:56:04 -0700220 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700221 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700222 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700223
224 private String mDescriptionDialButtonStr;
225 private String mActionMenuDialpadButtonStr;
226 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700227 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700228 /**
229 * Additional offset for FAB to be lowered when dialpad is open.
230 */
231 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700232
Andrew Lee2423a2f2014-05-29 14:14:45 -0700233 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700234
Andrew Leee74a10e2014-05-16 14:31:40 -0700235 private class OptionsPopupMenu extends PopupMenu {
236 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700237 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700238 }
239
240 @Override
241 public void show() {
242 final Menu menu = getMenu();
243 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700244 clearFrequents.setVisible(mListsFragment != null &&
245 mListsFragment.getSpeedDialFragment() != null &&
246 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700247 super.show();
248 }
249 }
250
Chiao Cheng94b10b52012-08-17 16:59:12 -0700251 /**
Yorke Lee28266192014-05-01 10:05:52 -0700252 * Listener that listens to drag events and sends their x and y coordinates to a
253 * {@link DragDropController}.
254 */
255 private class LayoutOnDragListener implements OnDragListener {
256 @Override
257 public boolean onDrag(View v, DragEvent event) {
258 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700259 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700260 }
261 return true;
262 }
263 }
264
265 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700266 * Listener used to send search queries to the phone search fragment.
267 */
Yorke Lee53a22302014-04-29 18:13:46 -0700268 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700269 @Override
270 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
271 }
Yorke Leec3766332013-07-31 11:13:16 -0700272
Andrew Lee99a570c2014-05-15 14:18:50 -0700273 @Override
274 public void onTextChanged(CharSequence s, int start, int before, int count) {
275 final String newText = s.toString();
276 if (newText.equals(mSearchQuery)) {
277 // If the query hasn't changed (perhaps due to activity being destroyed
278 // and restored, or user launching the same DIAL intent twice), then there is
279 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700280 return;
281 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700282 if (DEBUG) {
283 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700284 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700285 }
Yorke Lee710709d2014-05-29 07:18:42 -0700286 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700287
Andrew Lee90374a72014-05-16 15:01:09 -0700288 // Show search fragment only when the query string is changed to non-empty text.
289 if (!TextUtils.isEmpty(newText)) {
290 // Call enterSearchUi only if we are switching search modes, or showing a search
291 // fragment for the first time.
292 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
293 (!mIsDialpadShown && mInRegularSearch);
294 if (!sameSearchMode) {
295 enterSearchUi(mIsDialpadShown, mSearchQuery);
296 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700297 }
298
Andrew Leea8515422014-06-13 16:53:54 -0700299 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700300 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700301 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700302 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700303 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700304 }
305
306 @Override
307 public void afterTextChanged(Editable s) {
308 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700309 };
310
Andrew Leeb1903842014-05-15 16:11:24 -0700311
312 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700313 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700314 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700315 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700316 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700317 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700318 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700319 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700320 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
321 }
Andrew Leeb1903842014-05-15 16:11:24 -0700322 }
323 };
324
325 /**
326 * If the search term is empty and the user closes the soft keyboard, close the search UI.
327 */
328 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
329 @Override
330 public boolean onKey(View v, int keyCode, KeyEvent event) {
331 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
332 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700333 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700334 }
335 return false;
336 }
337 };
338
Chiao Cheng94b10b52012-08-17 16:59:12 -0700339 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700340 protected void onCreate(Bundle savedInstanceState) {
341 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700342 mFirstLaunch = true;
343
Andrew Lee2423a2f2014-05-29 14:14:45 -0700344 final Resources resources = getResources();
345 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700346 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
347 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700348
Yorke Lee8898cd02013-08-08 10:24:27 -0700349 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800350 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700351
Yorke Lee53a22302014-04-29 18:13:46 -0700352 final ActionBar actionBar = getActionBar();
353 actionBar.setCustomView(R.layout.search_edittext);
354 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700355 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700356
Yorke Lee5253be02014-05-21 18:50:03 -0700357 mActionBarController = new ActionBarController(this,
358 (SearchEditTextLayout) actionBar.getCustomView());
359
Andrew Lee04675a52014-06-05 18:36:20 -0700360 SearchEditTextLayout searchEditTextLayout =
361 (SearchEditTextLayout) actionBar.getCustomView();
362 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
363
364 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700365 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700366 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
367 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
368 .setOnClickListener(mSearchViewOnClickListener);
369 searchEditTextLayout.findViewById(R.id.search_box_start_search)
370 .setOnClickListener(mSearchViewOnClickListener);
371 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700372 @Override
373 public void onBackButtonClicked() {
374 onBackPressed();
375 }
376 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700377
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700378 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700379 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700380
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700381 final View floatingActionButtonContainer = findViewById(
382 R.id.floating_action_button_container);
383 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
384 int floatingActionButtonWidth = resources.getDimensionPixelSize(
385 R.dimen.floating_action_button_width);
386 mFloatingActionButton.setOnClickListener(this);
387 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700388 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700389 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
390 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700391
Andrew Lee04675a52014-06-05 18:36:20 -0700392 ImageButton optionsMenuButton =
393 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700394 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700395 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
396 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700397
Yorke Leeef2b7382013-08-09 17:39:25 -0700398 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
399 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700400 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800401 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700402 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800403 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
404 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700405 } else {
406 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700407 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
408 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700409 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700410 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700411 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700412 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700413
414 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700415 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700416 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700417 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700418
419 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700420
Yorke Lee28aab272014-06-11 10:24:19 -0700421 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700422 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
423 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700424 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700425 new ViewTreeObserver.OnGlobalLayoutListener() {
426 @Override
427 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700428 final ViewTreeObserver observer = floatingActionButtonContainer
429 .getViewTreeObserver();
430 if (!observer.isAlive()) {
431 return;
432 }
433 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700434 int screenWidth = parentLayout.getWidth();
435 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700436 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700437 }
438 });
Andrew Lee0c667702014-05-12 14:31:45 -0700439
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700440 setupActivityOverlay();
441
Yorke Lee0baa98b2013-08-22 10:55:16 -0700442 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700443 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700444 }
445
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700446 private void setupActivityOverlay() {
447 final View activityOverlay = findViewById(R.id.activity_overlay);
448 activityOverlay.setOnTouchListener(new OnTouchListener() {
449 @Override
450 public boolean onTouch(View v, MotionEvent event) {
451 if (!mIsDialpadShown) {
452 maybeExitSearchUi();
453 }
454 return false;
455 }
456 });
457 }
458
Chiao Cheng94b10b52012-08-17 16:59:12 -0700459 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700460 protected void onResume() {
461 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700462 if (mFirstLaunch) {
463 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700464 } else if (!phoneIsInUse() && mInCallDialpadUp) {
465 hideDialpadFragment(false, true);
466 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700467 } else if (mShowDialpadOnResume) {
468 showDialpadFragment(false);
469 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700470 }
471 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700472 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700473 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700474 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700475 }
476
477 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700478 protected void onPause() {
479 if (mClearSearchOnPause) {
480 hideDialpadAndSearchUi();
481 mClearSearchOnPause = false;
482 }
483 super.onPause();
484 }
485
486 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700487 protected void onSaveInstanceState(Bundle outState) {
488 super.onSaveInstanceState(outState);
489 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700490 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
491 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700492 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700493 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700494 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700495 }
496
497 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700498 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700499 if (fragment instanceof DialpadFragment) {
500 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700501 if (!mShowDialpadOnResume) {
502 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
503 transaction.hide(mDialpadFragment);
504 transaction.commit();
505 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700506 } else if (fragment instanceof SmartDialSearchFragment) {
507 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700508 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700509 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700510 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700511 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700512 } else if (fragment instanceof ListsFragment) {
513 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700514 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700515 }
Yorke Leec3766332013-07-31 11:13:16 -0700516 }
517
Alon Albertb453e5b2013-09-10 15:54:23 -0700518 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700519 final Intent intent = new Intent(this, DialerSettingsActivity.class);
520 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700521 }
522
Chiao Cheng94b10b52012-08-17 16:59:12 -0700523 @Override
524 public void onClick(View view) {
525 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700526 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700527 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700528 mInCallDialpadUp = false;
529 showDialpadFragment(true);
530 } else {
531 // Dial button was pressed; tell the Dialpad fragment
532 mDialpadFragment.dialButtonPressed();
533 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700534 break;
Yorke Leec3766332013-07-31 11:13:16 -0700535 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800536 try {
537 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
538 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
539 } catch (ActivityNotFoundException e) {
540 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
541 Toast.LENGTH_SHORT).show();
542 }
Yorke Leec3766332013-07-31 11:13:16 -0700543 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700544 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700545 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700546 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700547 default: {
548 Log.wtf(TAG, "Unexpected onClick event from " + view);
549 break;
550 }
551 }
552 }
553
Yorke Leec3766332013-07-31 11:13:16 -0700554 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700555 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700556 switch (item.getItemId()) {
557 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700558 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700559 break;
560 case R.id.menu_add_contact:
561 try {
562 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
563 } catch (ActivityNotFoundException e) {
564 Toast toast = Toast.makeText(this,
565 R.string.add_contact_not_available,
566 Toast.LENGTH_SHORT);
567 toast.show();
568 }
569 break;
570 case R.id.menu_import_export:
571 // We hard-code the "contactsAreAvailable" argument because doing it properly would
572 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
573 // now in Dialtacts for (potential) performance reasons. Compare with how it is
574 // done in {@link PeopleActivity}.
575 ImportExportDialogFragment.show(getFragmentManager(), true,
576 DialtactsActivity.class);
577 return true;
578 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700579 ClearFrequentsDialog.show(getFragmentManager());
580 return true;
581 case R.id.menu_call_settings:
582 handleMenuSettings();
583 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700584 }
585 return false;
586 }
587
588 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700589 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
590 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
591 if (resultCode == RESULT_OK) {
592 final ArrayList<String> matches = data.getStringArrayListExtra(
593 RecognizerIntent.EXTRA_RESULTS);
594 if (matches.size() > 0) {
595 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700596 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700597 } else {
598 Log.e(TAG, "Voice search - nothing heard");
599 }
600 } else {
601 Log.e(TAG, "Voice search failed");
602 }
603 }
604 super.onActivityResult(requestCode, resultCode, data);
605 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700606
Andrew Lee2a58ab82014-05-15 02:16:04 -0700607 /**
608 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
609 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
610 * @see #onDialpadShown
611 */
Yorke Leec3766332013-07-31 11:13:16 -0700612 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700613 if (mIsDialpadShown) {
614 return;
615 }
616 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700617 mDialpadFragment.setAnimate(animate);
618
Chiao Cheng94b10b52012-08-17 16:59:12 -0700619 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700620 ft.show(mDialpadFragment);
621 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700622
Yorke Lee5253be02014-05-21 18:50:03 -0700623 mActionBarController.onDialpadUp();
624
Andrew Leeb1903842014-05-15 16:11:24 -0700625 if (!isInSearchUi()) {
626 enterSearchUi(true /* isSmartDial */, mSearchQuery);
627 }
Yorke Leec3766332013-07-31 11:13:16 -0700628 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700629
Andrew Lee2a58ab82014-05-15 02:16:04 -0700630 /**
631 * Callback from child DialpadFragment when the dialpad is shown.
632 */
633 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700634 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
635 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
636 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700637 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700638 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700639 } else {
640 mDialpadFragment.setYFraction(0);
641 }
642
Andrew Lee2a58ab82014-05-15 02:16:04 -0700643 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700644 }
645
646 /**
647 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
648 * a callback after the hide animation ends.
649 * @see #commitDialpadFragmentHide
650 */
Yorke Leeca195042013-09-25 16:29:38 -0700651 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700652 if (mDialpadFragment == null) {
653 return;
654 }
Yorke Leef6673d32013-08-23 15:34:17 -0700655 if (clearDialpad) {
656 mDialpadFragment.clearDialpad();
657 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700658 if (!mIsDialpadShown) {
659 return;
Yorke Leec3766332013-07-31 11:13:16 -0700660 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700661 mIsDialpadShown = false;
662 mDialpadFragment.setAnimate(animate);
663
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700664 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700665 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
666 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
667
668 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700669 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700670 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700671 } else {
672 commitDialpadFragmentHide();
673 }
674
Yorke Lee5253be02014-05-21 18:50:03 -0700675 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700676
Andrew Leed4cde832014-05-16 15:56:48 -0700677 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700678 if (TextUtils.isEmpty(mSearchQuery)) {
679 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700680 }
Andrew Leed4cde832014-05-16 15:56:48 -0700681 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700682 }
683
684 /**
685 * Finishes hiding the dialpad fragment after any animations are completed.
686 */
687 private void commitDialpadFragmentHide() {
688 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700689 ft.hide(mDialpadFragment);
690 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700691 }
692
Andrew Lee2a58ab82014-05-15 02:16:04 -0700693 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700694 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700695 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700696 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700697 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700698 fragment = mRegularSearchFragment;
699 }
700 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700701 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700702 }
703 }
704
Yorke Lee5253be02014-05-21 18:50:03 -0700705 @Override
706 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700707 return mInDialpadSearch || mInRegularSearch;
708 }
709
Yorke Lee5253be02014-05-21 18:50:03 -0700710 @Override
711 public boolean hasSearchQuery() {
712 return !TextUtils.isEmpty(mSearchQuery);
713 }
714
715 @Override
716 public boolean shouldShowActionBar() {
717 return mListsFragment.shouldShowActionBar();
718 }
719
Yorke Leeb207f8a2013-08-29 18:51:06 -0700720 private void setNotInSearchUi() {
721 mInDialpadSearch = false;
722 mInRegularSearch = false;
723 }
724
Yorke Lee311969c2013-08-26 06:31:11 -0700725 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700726 if (mIsDialpadShown) {
727 hideDialpadFragment(false, true);
728 } else {
729 exitSearchUi();
730 }
Yorke Lee311969c2013-08-26 06:31:11 -0700731 }
732
Yorke Leee00c9fe2014-04-12 12:42:06 -0700733 private void hideInputMethod(View view) {
734 final InputMethodManager imm = (InputMethodManager) getSystemService(
735 Context.INPUT_METHOD_SERVICE);
736 if (imm != null && view != null) {
737 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
738 }
739 }
740
Yorke Lee53a22302014-04-29 18:13:46 -0700741 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700742 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
743 if (canIntentBeHandled(voiceIntent)) {
744 mVoiceSearchButton.setVisibility(View.VISIBLE);
745 mVoiceSearchButton.setOnClickListener(this);
746 } else {
747 mVoiceSearchButton.setVisibility(View.GONE);
748 }
749 }
750
Andrew Leee74a10e2014-05-16 14:31:40 -0700751 private OptionsPopupMenu buildOptionsMenu(View invoker) {
752 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
753 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700754 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700755 popupMenu.setOnMenuItemClickListener(this);
756 return popupMenu;
757 }
758
Yorke Lee86e21f72014-04-02 16:49:38 -0700759 @Override
760 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700761 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700762 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700763 mPendingSearchViewQuery = null;
764 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700765 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700766 }
767
Chiao Cheng94b10b52012-08-17 16:59:12 -0700768 /**
769 * Returns true if the intent is due to hitting the green send key (hardware call button:
770 * KEYCODE_CALL) while in a call.
771 *
772 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700773 * @return true if the intent is due to hitting the green send key while in a call
774 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700775 private boolean isSendKeyWhileInCall(Intent intent) {
776 // If there is a call in progress and the user launched the dialer by hitting the call
777 // button, go straight to the in-call screen.
778 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700779
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700780 if (callKey) {
Santos Cordond15629d2014-07-07 15:15:29 -0700781 getPhoneManager().showCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700782 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700783 }
784
785 return false;
786 }
787
788 /**
789 * Sets the current tab based on the intent's request type
790 *
791 * @param intent Intent that contains information about which tab should be selected
792 */
Yorke Leec3766332013-07-31 11:13:16 -0700793 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700794 // 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 -0700795 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700796 finish();
797 return;
798 }
799
Yorke Lee669b6082013-09-17 15:43:38 -0700800 if (mDialpadFragment != null) {
801 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700802 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700803 mDialpadFragment.setStartedFromNewIntent(true);
804 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
805 mInCallDialpadUp = true;
806 }
807 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700808 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700809 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700810 }
811
812 @Override
813 public void onNewIntent(Intent newIntent) {
814 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700815 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700816
Chiao Cheng94b10b52012-08-17 16:59:12 -0700817 invalidateOptionsMenu();
818 }
819
820 /** Returns true if the given intent contains a phone number to populate the dialer with */
821 private boolean isDialIntent(Intent intent) {
822 final String action = intent.getAction();
823 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
824 return true;
825 }
826 if (Intent.ACTION_VIEW.equals(action)) {
827 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700828 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700829 return true;
830 }
831 }
832 return false;
833 }
834
835 /**
836 * Returns an appropriate call origin for this Activity. May return null when no call origin
837 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
838 * for remembering the tab in which the user made a phone call, so the external app's DIAL
839 * request should not be counted.)
840 */
841 public String getCallOrigin() {
842 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
843 }
844
Chiao Cheng94b10b52012-08-17 16:59:12 -0700845 /**
Yorke Leec3766332013-07-31 11:13:16 -0700846 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700847 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700848 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700849 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700850 // Weird race condition where fragment is doing work after the activity is destroyed
851 // due to talkback being on (b/10209937). Just return since we can't do any
852 // constructive here.
853 return;
854 }
855
Yorke Leeef2b7382013-08-09 17:39:25 -0700856 if (DEBUG) {
857 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
858 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700859
Yorke Leec3766332013-07-31 11:13:16 -0700860 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700861 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700862 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700863 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700864 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700865 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700866
Yorke Leeb207f8a2013-08-29 18:51:06 -0700867 final String tag;
868 if (smartDialSearch) {
869 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
870 } else {
871 tag = TAG_REGULAR_SEARCH_FRAGMENT;
872 }
873 mInDialpadSearch = smartDialSearch;
874 mInRegularSearch = !smartDialSearch;
875
Andrew Lee752956e2014-05-15 11:43:38 -0700876 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700877 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700878 if (fragment == null) {
879 if (smartDialSearch) {
880 fragment = new SmartDialSearchFragment();
881 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700882 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700883 }
Andrew Leeb1903842014-05-15 16:11:24 -0700884 transaction.add(R.id.dialtacts_frame, fragment, tag);
885 } else {
886 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700887 }
Andrew Leeb1903842014-05-15 16:11:24 -0700888
Yorke Lee86e21f72014-04-02 16:49:38 -0700889 // DialtactsActivity will provide the options menu
890 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700891 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700892 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700893 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700894
895 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700896 }
897
898 /**
Yorke Leec3766332013-07-31 11:13:16 -0700899 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700900 */
Yorke Leec3766332013-07-31 11:13:16 -0700901 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700902 // See related bug in enterSearchUI();
903 if (getFragmentManager().isDestroyed()) {
904 return;
905 }
Andrew Leeb1903842014-05-15 16:11:24 -0700906
Andrew Leeb1903842014-05-15 16:11:24 -0700907 mSearchView.setText(null);
908 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700909 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700910
Andrew Leeb1903842014-05-15 16:11:24 -0700911 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700912 if (mSmartDialSearchFragment != null) {
913 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700914 }
Andrew Leeb1903842014-05-15 16:11:24 -0700915 if (mRegularSearchFragment != null) {
916 transaction.remove(mRegularSearchFragment);
917 }
918 transaction.commit();
919
920 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700921 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700922 }
923
924 /** Returns an Intent to launch Call Settings screen */
925 public static Intent getCallSettingsIntent() {
Yorke Lee6eec2282014-07-18 12:40:27 -0700926 final Intent intent = new Intent(TelecommManager.ACTION_SHOW_CALL_SETTINGS);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700927 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
928 return intent;
929 }
930
931 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700932 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700933 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700934 if (TextUtils.isEmpty(mSearchQuery) ||
935 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
936 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700937 exitSearchUi();
938 }
Yorke Leef6673d32013-08-23 15:34:17 -0700939 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700940 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700941 exitSearchUi();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700942 hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700943 } else {
944 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700945 }
Yorke Leec3766332013-07-31 11:13:16 -0700946 }
947
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700948 /**
949 * @return True if the search UI was exited, false otherwise
950 */
951 private boolean maybeExitSearchUi() {
952 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
953 exitSearchUi();
954 hideInputMethod(parentLayout);
955 return true;
956 }
957 return false;
958 }
959
Yorke Leec3766332013-07-31 11:13:16 -0700960 @Override
961 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700962 if (mSmartDialSearchFragment != null) {
963 mSmartDialSearchFragment.setAddToContactNumber(query);
964 }
Yorke Leec3766332013-07-31 11:13:16 -0700965 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
966 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700967
968 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700969 if (DEBUG) {
970 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
971 }
972 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
973 // This callback can happen if the dialpad fragment is recreated because of
974 // activity destruction. In that case, don't update the search view because
975 // that would bring the user back to the search fragment regardless of the
976 // previous state of the application. Instead, just return here and let the
977 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700978 if (!TextUtils.isEmpty(normalizedQuery)) {
979 mPendingSearchViewQuery = normalizedQuery;
980 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700981 return;
982 }
Yorke Lee53a22302014-04-29 18:13:46 -0700983 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700984 }
985 }
Yorke Leec3766332013-07-31 11:13:16 -0700986
987 @Override
988 public void onListFragmentScrollStateChange(int scrollState) {
989 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700990 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -0700991 hideInputMethod(getCurrentFocus());
992 }
993 }
994
995 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -0700996 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -0700997 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700998 // TODO: No-op for now. This should eventually show/hide the actionBar based on
999 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001000 }
1001
Yorke Lee86e21f72014-04-02 16:49:38 -07001002 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001003 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001004 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001005 }
1006
1007 private boolean phoneIsInUse() {
Santos Cordond15629d2014-07-07 15:15:29 -07001008 return getPhoneManager().isInAPhoneCall();
Yorke Leec3766332013-07-31 11:13:16 -07001009 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001010
Yorke Leee1424812013-09-04 18:24:48 -07001011 public static Intent getAddNumberToContactIntent(CharSequence text) {
1012 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1013 intent.putExtra(Intents.Insert.PHONE, text);
1014 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1015 return intent;
1016 }
1017
Yorke Leeda0f9042013-12-05 14:25:51 -08001018 private boolean canIntentBeHandled(Intent intent) {
1019 final PackageManager packageManager = getPackageManager();
1020 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1021 PackageManager.MATCH_DEFAULT_ONLY);
1022 return resolveInfo != null && resolveInfo.size() > 0;
1023 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001024
Yorke Lee6a1461a2014-04-21 16:27:14 -07001025 @Override
1026 public void showCallHistory() {
1027 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1028 // CONTENT_TYPE, so that we always open our call log from our dialer
1029 final Intent intent = new Intent(this, CallLogActivity.class);
1030 startActivity(intent);
1031 }
1032
Yorke Lee86e21f72014-04-02 16:49:38 -07001033 /**
1034 * Called when the user has long-pressed a contact tile to start a drag operation.
1035 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001036 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001037 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001038 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001039 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001040 }
Andrew Lee18963442014-06-06 17:20:13 -07001041 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001042 }
1043
1044 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001045 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1046 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001047
Yorke Lee86e21f72014-04-02 16:49:38 -07001048 /**
1049 * Called when the user has released a contact tile after long-pressing it.
1050 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001051 @Override
1052 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001053 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001054 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001055 }
Andrew Lee18963442014-06-06 17:20:13 -07001056 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001057 }
1058
1059 @Override
1060 public void onDroppedOnRemove() {}
1061
1062 /**
Yorke Leed999b712014-04-23 15:10:58 -07001063 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001064 * once it has been attached to the activity.
1065 */
1066 @Override
1067 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001068 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001069 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001070 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001071
1072 @Override
1073 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001074 // Specify call-origin so that users will see the previous tab instead of
1075 // CallLog screen (search UI will be automatically exited).
1076 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001077 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001078 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001079 }
1080
1081 @Override
1082 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001083 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1084 }
1085
1086 @Override
1087 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001088 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001089 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1090 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001091 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001092 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001093 }
1094
1095 @Override
1096 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001097 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001098 }
1099
1100 @Override
1101 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001102 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001103 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001104
Yorke Leecc4660d2014-04-24 11:22:57 -07001105 @Override
1106 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001107 // Only scroll the button when the first tab is selected. The button should scroll from
1108 // the middle to right position only on the transition from the first tab to the second
1109 // tab.
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001110 if (position == ListsFragment.TAB_INDEX_SPEED_DIAL && !mIsLandscape) {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001111 mFloatingActionButtonController.onPageScrolled(positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001112 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1113 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001114 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001115 }
1116
1117 @Override
1118 public void onPageSelected(int position) {
1119 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001120 }
1121
1122 @Override
1123 public void onPageScrollStateChanged(int state) {
1124 }
1125
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001126 private TelephonyManager getTelephonyManager() {
1127 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1128 }
1129
Santos Cordond15629d2014-07-07 15:15:29 -07001130 private PhoneManager getPhoneManager() {
1131 return (PhoneManager) getSystemService(Context.PHONE_SERVICE);
1132 }
1133
Yorke Lee5253be02014-05-21 18:50:03 -07001134 @Override
1135 public boolean isActionBarShowing() {
1136 return mActionBarController.isActionBarShowing();
1137 }
1138
Andrew Lee9da8fb42014-06-03 14:03:09 -07001139 public boolean isDialpadShown() {
1140 return mIsDialpadShown;
1141 }
1142
Yorke Lee5253be02014-05-21 18:50:03 -07001143 @Override
1144 public int getActionBarHideOffset() {
1145 return getActionBar().getHideOffset();
1146 }
1147
1148 @Override
1149 public int getActionBarHeight() {
1150 return mActionBarHeight;
1151 }
1152
1153 @Override
1154 public void setActionBarHideOffset(int hideOffset) {
1155 getActionBar().setHideOffset(hideOffset);
1156 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001157
1158 /**
1159 * Updates controller based on currently known information.
1160 *
1161 * @param animate Whether or not to animate the transition.
1162 */
1163 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1164 int align;
1165 if (mIsDialpadShown) {
1166 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_RIGHT
1167 : FloatingActionButtonController.ALIGN_MIDDLE;
1168 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001169 if (!mIsLandscape) {
1170 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1171 ? FloatingActionButtonController.ALIGN_MIDDLE
1172 : FloatingActionButtonController.ALIGN_RIGHT;
1173 } else {
1174 align = FloatingActionButtonController.ALIGN_RIGHT;
1175 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001176 }
1177 mFloatingActionButtonController.align(align,
1178 0 /* offsetX */,
1179 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1180 animate);
1181 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001182}