blob: cb01e8ef0cfc88ace6bde9fa6b02f029b208517a [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;
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;
Sai Cheemalapati7fa029f2014-07-29 15:03:55 -070070import com.android.dialer.activity.TransactionSafeActivity;
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;
Yorke Lee2fec47b2014-08-05 18:16:27 -070092import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070093import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070094
Yorke Leec3766332013-07-31 11:13:16 -070095import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080096import java.util.List;
Yorke Lee69c247f2014-07-22 11:49:49 -070097import java.util.Locale;
Yorke Leec3766332013-07-31 11:13:16 -070098
Chiao Cheng94b10b52012-08-17 16:59:12 -070099/**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700100 * The dialer tab's title is 'phone', a more common name (see strings.xml).
101 */
Yorke Leec3766332013-07-31 11:13:16 -0700102public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700103 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700104 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800105 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700106 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700107 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700108 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700109 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700110 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700111 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700112 ViewPager.OnPageChangeListener,
113 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700114 private static final String TAG = "DialtactsActivity";
115
Ihab Awad526c0b82014-02-27 12:55:36 -0800116 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700117
Yorke Leef74011e2013-08-02 11:30:30 -0700118 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
119
Chiao Cheng94b10b52012-08-17 16:59:12 -0700120 /** @see #getCallOrigin() */
121 private static final String CALL_ORIGIN_DIALTACTS =
122 "com.android.dialer.DialtactsActivity";
123
Yorke Leeb207f8a2013-08-29 18:51:06 -0700124 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
125 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700126 private static final String KEY_SEARCH_QUERY = "search_query";
127 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700128 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700129
Yorke Leec3766332013-07-31 11:13:16 -0700130 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
131 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
132 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
133 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700134
Chiao Cheng94b10b52012-08-17 16:59:12 -0700135 /**
136 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
137 */
138 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
139
Yorke Leec3766332013-07-31 11:13:16 -0700140 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700141
Yorke Lee28aab272014-06-11 10:24:19 -0700142 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700143
Yorke Leec3766332013-07-31 11:13:16 -0700144 /**
Yorke Leec3766332013-07-31 11:13:16 -0700145 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700146 */
Yorke Leef74011e2013-08-02 11:30:30 -0700147 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700148
149 /**
150 * Fragment for searching phone numbers using the alphanumeric keyboard.
151 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700152 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700153
154 /**
155 * Fragment for searching phone numbers using the dialpad.
156 */
157 private SmartDialSearchFragment mSmartDialSearchFragment;
158
Yorke Leee00c9fe2014-04-12 12:42:06 -0700159 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700160 * Animation that slides in.
161 */
162 private Animation mSlideIn;
163
164 /**
165 * Animation that slides out.
166 */
167 private Animation mSlideOut;
168
169 /**
170 * Listener for after slide out animation completes on dialer fragment.
171 */
172 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
173 @Override
174 public void onAnimationEnd(Animation animation) {
175 commitDialpadFragmentHide();
176 }
177 };
178
179 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700180 * Fragment containing the speed dial list, recents list, and all contacts list.
181 */
182 private ListsFragment mListsFragment;
183
Yorke Leeb207f8a2013-08-29 18:51:06 -0700184 private boolean mInDialpadSearch;
185 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700186 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700187 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700188 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700189
Yorke Leeef2b7382013-08-09 17:39:25 -0700190 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700191 * Whether or not the device is in landscape orientation.
192 */
193 private boolean mIsLandscape;
194
195 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700196 * The position of the currently selected tab in the attached {@link ListsFragment}.
197 */
198 private int mCurrentTabPosition = 0;
199
200 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700201 * True if the dialpad is only temporarily showing due to being in call
202 */
203 private boolean mInCallDialpadUp;
204
205 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700206 * True when this activity has been launched for the first time.
207 */
Yorke Lee98702de2013-08-06 12:03:32 -0700208 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700209
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700210 /**
211 * Search query to be applied to the SearchView in the ActionBar once
212 * onCreateOptionsMenu has been called.
213 */
214 private String mPendingSearchViewQuery;
215
Yorke Lee74edcdc2014-07-11 16:15:08 -0700216 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700217 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700218 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700219
Yorke Leeef2b7382013-08-09 17:39:25 -0700220 private String mSearchQuery;
221
Yorke Leefce269a2013-08-12 11:56:04 -0700222 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700223 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700224 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700225
226 private String mDescriptionDialButtonStr;
227 private String mActionMenuDialpadButtonStr;
228 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700229 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700230 /**
231 * Additional offset for FAB to be lowered when dialpad is open.
232 */
233 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700234
Andrew Lee2423a2f2014-05-29 14:14:45 -0700235 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700236
Andrew Leee74a10e2014-05-16 14:31:40 -0700237 private class OptionsPopupMenu extends PopupMenu {
238 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700239 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700240 }
241
242 @Override
243 public void show() {
244 final Menu menu = getMenu();
245 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700246 clearFrequents.setVisible(mListsFragment != null &&
247 mListsFragment.getSpeedDialFragment() != null &&
248 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700249 super.show();
250 }
251 }
252
Chiao Cheng94b10b52012-08-17 16:59:12 -0700253 /**
Yorke Lee28266192014-05-01 10:05:52 -0700254 * Listener that listens to drag events and sends their x and y coordinates to a
255 * {@link DragDropController}.
256 */
257 private class LayoutOnDragListener implements OnDragListener {
258 @Override
259 public boolean onDrag(View v, DragEvent event) {
260 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700261 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700262 }
263 return true;
264 }
265 }
266
267 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700268 * Listener used to send search queries to the phone search fragment.
269 */
Yorke Lee53a22302014-04-29 18:13:46 -0700270 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700271 @Override
272 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
273 }
Yorke Leec3766332013-07-31 11:13:16 -0700274
Andrew Lee99a570c2014-05-15 14:18:50 -0700275 @Override
276 public void onTextChanged(CharSequence s, int start, int before, int count) {
277 final String newText = s.toString();
278 if (newText.equals(mSearchQuery)) {
279 // If the query hasn't changed (perhaps due to activity being destroyed
280 // and restored, or user launching the same DIAL intent twice), then there is
281 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700282 return;
283 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700284 if (DEBUG) {
285 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700286 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700287 }
Yorke Lee710709d2014-05-29 07:18:42 -0700288 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700289
Andrew Lee90374a72014-05-16 15:01:09 -0700290 // Show search fragment only when the query string is changed to non-empty text.
291 if (!TextUtils.isEmpty(newText)) {
292 // Call enterSearchUi only if we are switching search modes, or showing a search
293 // fragment for the first time.
294 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
295 (!mIsDialpadShown && mInRegularSearch);
296 if (!sameSearchMode) {
297 enterSearchUi(mIsDialpadShown, mSearchQuery);
298 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700299 }
300
Andrew Leea8515422014-06-13 16:53:54 -0700301 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700302 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700303 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700304 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700305 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700306 }
307
308 @Override
309 public void afterTextChanged(Editable s) {
310 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700311 };
312
Andrew Leeb1903842014-05-15 16:11:24 -0700313
314 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700315 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700316 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700317 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700318 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700319 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700320 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700321 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700322 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
323 }
Andrew Leeb1903842014-05-15 16:11:24 -0700324 }
325 };
326
327 /**
328 * If the search term is empty and the user closes the soft keyboard, close the search UI.
329 */
330 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
331 @Override
332 public boolean onKey(View v, int keyCode, KeyEvent event) {
333 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
334 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700335 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700336 }
337 return false;
338 }
339 };
340
Chiao Cheng94b10b52012-08-17 16:59:12 -0700341 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700342 protected void onCreate(Bundle savedInstanceState) {
343 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700344 mFirstLaunch = true;
345
Andrew Lee2423a2f2014-05-29 14:14:45 -0700346 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700347 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700348 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
349 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700350
Yorke Lee8898cd02013-08-08 10:24:27 -0700351 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800352 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700353
Yorke Lee53a22302014-04-29 18:13:46 -0700354 final ActionBar actionBar = getActionBar();
355 actionBar.setCustomView(R.layout.search_edittext);
356 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700357 actionBar.setBackgroundDrawable(null);
Yorke Lee8fd67242014-08-05 18:43:45 -0700358 actionBar.setElevation(resources.getDimensionPixelSize(R.dimen.action_bar_elevation));
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
Yorke Lee2fec47b2014-08-05 18:16:27 -0700422 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
423 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
424
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700425 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700426
Yorke Lee28aab272014-06-11 10:24:19 -0700427 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700428 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
429 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700430 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700431 new ViewTreeObserver.OnGlobalLayoutListener() {
432 @Override
433 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700434 final ViewTreeObserver observer = floatingActionButtonContainer
435 .getViewTreeObserver();
436 if (!observer.isAlive()) {
437 return;
438 }
439 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700440 int screenWidth = parentLayout.getWidth();
441 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700442 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700443 }
444 });
Andrew Lee0c667702014-05-12 14:31:45 -0700445
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700446 setupActivityOverlay();
447
Yorke Lee0baa98b2013-08-22 10:55:16 -0700448 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700449 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700450 }
451
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700452 private void setupActivityOverlay() {
453 final View activityOverlay = findViewById(R.id.activity_overlay);
454 activityOverlay.setOnTouchListener(new OnTouchListener() {
455 @Override
456 public boolean onTouch(View v, MotionEvent event) {
457 if (!mIsDialpadShown) {
458 maybeExitSearchUi();
459 }
460 return false;
461 }
462 });
463 }
464
Chiao Cheng94b10b52012-08-17 16:59:12 -0700465 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700466 protected void onResume() {
467 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700468 if (mFirstLaunch) {
469 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700470 } else if (!phoneIsInUse() && mInCallDialpadUp) {
471 hideDialpadFragment(false, true);
472 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700473 } else if (mShowDialpadOnResume) {
474 showDialpadFragment(false);
475 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700476 }
477 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700478 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700479 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700480 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700481 }
482
483 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700484 protected void onPause() {
485 if (mClearSearchOnPause) {
486 hideDialpadAndSearchUi();
487 mClearSearchOnPause = false;
488 }
489 super.onPause();
490 }
491
492 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700493 protected void onSaveInstanceState(Bundle outState) {
494 super.onSaveInstanceState(outState);
495 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700496 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
497 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700498 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700499 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700500 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700501 }
502
503 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700504 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700505 if (fragment instanceof DialpadFragment) {
506 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700507 if (!mShowDialpadOnResume) {
508 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
509 transaction.hide(mDialpadFragment);
510 transaction.commit();
511 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700512 } else if (fragment instanceof SmartDialSearchFragment) {
513 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700514 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700515 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700516 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700517 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700518 } else if (fragment instanceof ListsFragment) {
519 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700520 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700521 }
Yorke Leec3766332013-07-31 11:13:16 -0700522 }
523
Alon Albertb453e5b2013-09-10 15:54:23 -0700524 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700525 final Intent intent = new Intent(this, DialerSettingsActivity.class);
526 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700527 }
528
Chiao Cheng94b10b52012-08-17 16:59:12 -0700529 @Override
530 public void onClick(View view) {
531 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700532 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700533 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700534 mInCallDialpadUp = false;
535 showDialpadFragment(true);
536 } else {
537 // Dial button was pressed; tell the Dialpad fragment
538 mDialpadFragment.dialButtonPressed();
539 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700540 break;
Yorke Leec3766332013-07-31 11:13:16 -0700541 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800542 try {
543 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
544 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
545 } catch (ActivityNotFoundException e) {
546 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
547 Toast.LENGTH_SHORT).show();
548 }
Yorke Leec3766332013-07-31 11:13:16 -0700549 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700550 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700551 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700552 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700553 default: {
554 Log.wtf(TAG, "Unexpected onClick event from " + view);
555 break;
556 }
557 }
558 }
559
Yorke Leec3766332013-07-31 11:13:16 -0700560 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700561 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700562 switch (item.getItemId()) {
563 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700564 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700565 break;
566 case R.id.menu_add_contact:
567 try {
568 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
569 } catch (ActivityNotFoundException e) {
570 Toast toast = Toast.makeText(this,
571 R.string.add_contact_not_available,
572 Toast.LENGTH_SHORT);
573 toast.show();
574 }
575 break;
576 case R.id.menu_import_export:
577 // We hard-code the "contactsAreAvailable" argument because doing it properly would
578 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
579 // now in Dialtacts for (potential) performance reasons. Compare with how it is
580 // done in {@link PeopleActivity}.
581 ImportExportDialogFragment.show(getFragmentManager(), true,
582 DialtactsActivity.class);
583 return true;
584 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700585 ClearFrequentsDialog.show(getFragmentManager());
586 return true;
587 case R.id.menu_call_settings:
588 handleMenuSettings();
589 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700590 }
591 return false;
592 }
593
594 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700595 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
596 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
597 if (resultCode == RESULT_OK) {
598 final ArrayList<String> matches = data.getStringArrayListExtra(
599 RecognizerIntent.EXTRA_RESULTS);
600 if (matches.size() > 0) {
601 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700602 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700603 } else {
604 Log.e(TAG, "Voice search - nothing heard");
605 }
606 } else {
607 Log.e(TAG, "Voice search failed");
608 }
609 }
610 super.onActivityResult(requestCode, resultCode, data);
611 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700612
Andrew Lee2a58ab82014-05-15 02:16:04 -0700613 /**
614 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
615 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
616 * @see #onDialpadShown
617 */
Yorke Leec3766332013-07-31 11:13:16 -0700618 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700619 if (mIsDialpadShown) {
620 return;
621 }
622 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700623 mDialpadFragment.setAnimate(animate);
Sai Cheemalapati2d7faf62014-08-04 11:48:50 -0700624 mDialpadFragment.sendScreenView();
Andrew Leecdfa6c62014-05-06 15:33:35 -0700625
Chiao Cheng94b10b52012-08-17 16:59:12 -0700626 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700627 ft.show(mDialpadFragment);
628 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700629
Yorke Lee5253be02014-05-21 18:50:03 -0700630 mActionBarController.onDialpadUp();
631
Andrew Leeb1903842014-05-15 16:11:24 -0700632 if (!isInSearchUi()) {
633 enterSearchUi(true /* isSmartDial */, mSearchQuery);
634 }
Yorke Leec3766332013-07-31 11:13:16 -0700635 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700636
Andrew Lee2a58ab82014-05-15 02:16:04 -0700637 /**
638 * Callback from child DialpadFragment when the dialpad is shown.
639 */
640 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700641 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
642 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
643 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700644 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700645 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700646 } else {
647 mDialpadFragment.setYFraction(0);
648 }
649
Andrew Lee2a58ab82014-05-15 02:16:04 -0700650 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700651 }
652
653 /**
654 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
655 * a callback after the hide animation ends.
656 * @see #commitDialpadFragmentHide
657 */
Yorke Leeca195042013-09-25 16:29:38 -0700658 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700659 if (mDialpadFragment == null) {
660 return;
661 }
Yorke Leef6673d32013-08-23 15:34:17 -0700662 if (clearDialpad) {
663 mDialpadFragment.clearDialpad();
664 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700665 if (!mIsDialpadShown) {
666 return;
Yorke Leec3766332013-07-31 11:13:16 -0700667 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700668 mIsDialpadShown = false;
669 mDialpadFragment.setAnimate(animate);
670
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700671 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700672 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
673 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
674
675 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700676 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700677 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700678 } else {
679 commitDialpadFragmentHide();
680 }
681
Yorke Lee5253be02014-05-21 18:50:03 -0700682 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700683
Andrew Leed4cde832014-05-16 15:56:48 -0700684 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700685 if (TextUtils.isEmpty(mSearchQuery)) {
686 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700687 }
Andrew Leed4cde832014-05-16 15:56:48 -0700688 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700689 }
690
691 /**
692 * Finishes hiding the dialpad fragment after any animations are completed.
693 */
694 private void commitDialpadFragmentHide() {
695 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700696 ft.hide(mDialpadFragment);
697 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700698 }
699
Andrew Lee2a58ab82014-05-15 02:16:04 -0700700 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700701 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700702 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700703 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700704 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700705 fragment = mRegularSearchFragment;
706 }
707 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700708 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700709 }
710 }
711
Yorke Lee5253be02014-05-21 18:50:03 -0700712 @Override
713 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700714 return mInDialpadSearch || mInRegularSearch;
715 }
716
Yorke Lee5253be02014-05-21 18:50:03 -0700717 @Override
718 public boolean hasSearchQuery() {
719 return !TextUtils.isEmpty(mSearchQuery);
720 }
721
722 @Override
723 public boolean shouldShowActionBar() {
724 return mListsFragment.shouldShowActionBar();
725 }
726
Yorke Leeb207f8a2013-08-29 18:51:06 -0700727 private void setNotInSearchUi() {
728 mInDialpadSearch = false;
729 mInRegularSearch = false;
730 }
731
Yorke Lee311969c2013-08-26 06:31:11 -0700732 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700733 if (mIsDialpadShown) {
734 hideDialpadFragment(false, true);
735 } else {
736 exitSearchUi();
737 }
Yorke Lee311969c2013-08-26 06:31:11 -0700738 }
739
Yorke Lee53a22302014-04-29 18:13:46 -0700740 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700741 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
742 if (canIntentBeHandled(voiceIntent)) {
743 mVoiceSearchButton.setVisibility(View.VISIBLE);
744 mVoiceSearchButton.setOnClickListener(this);
745 } else {
746 mVoiceSearchButton.setVisibility(View.GONE);
747 }
748 }
749
Andrew Leee74a10e2014-05-16 14:31:40 -0700750 private OptionsPopupMenu buildOptionsMenu(View invoker) {
751 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
752 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700753 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700754 popupMenu.setOnMenuItemClickListener(this);
755 return popupMenu;
756 }
757
Yorke Lee86e21f72014-04-02 16:49:38 -0700758 @Override
759 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700760 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700761 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700762 mPendingSearchViewQuery = null;
763 }
Yorke Leea524ae52014-08-05 18:01:05 -0700764 mActionBarController.restoreActionBarOffset();
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 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700888 // DialtactsActivity will provide the options menu
889 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700890 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700891 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700892 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700893
894 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700895 }
896
897 /**
Yorke Leec3766332013-07-31 11:13:16 -0700898 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700899 */
Yorke Leec3766332013-07-31 11:13:16 -0700900 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700901 // See related bug in enterSearchUI();
902 if (getFragmentManager().isDestroyed()) {
903 return;
904 }
Andrew Leeb1903842014-05-15 16:11:24 -0700905
Andrew Leeb1903842014-05-15 16:11:24 -0700906 mSearchView.setText(null);
907 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700908 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700909
Andrew Leeb1903842014-05-15 16:11:24 -0700910 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700911 if (mSmartDialSearchFragment != null) {
912 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700913 }
Andrew Leeb1903842014-05-15 16:11:24 -0700914 if (mRegularSearchFragment != null) {
915 transaction.remove(mRegularSearchFragment);
916 }
917 transaction.commit();
918
919 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700920 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700921 }
922
923 /** Returns an Intent to launch Call Settings screen */
924 public static Intent getCallSettingsIntent() {
Yorke Lee6eec2282014-07-18 12:40:27 -0700925 final Intent intent = new Intent(TelecommManager.ACTION_SHOW_CALL_SETTINGS);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700926 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
927 return intent;
928 }
929
930 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700931 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700932 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700933 if (TextUtils.isEmpty(mSearchQuery) ||
934 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
935 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700936 exitSearchUi();
937 }
Yorke Leef6673d32013-08-23 15:34:17 -0700938 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700939 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700940 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700941 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700942 } else {
943 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700944 }
Yorke Leec3766332013-07-31 11:13:16 -0700945 }
946
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700947 /**
948 * @return True if the search UI was exited, false otherwise
949 */
950 private boolean maybeExitSearchUi() {
951 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
952 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700953 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700954 return true;
955 }
956 return false;
957 }
958
Yorke Leec3766332013-07-31 11:13:16 -0700959 @Override
960 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700961 if (mSmartDialSearchFragment != null) {
962 mSmartDialSearchFragment.setAddToContactNumber(query);
963 }
Yorke Leec3766332013-07-31 11:13:16 -0700964 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
965 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700966
967 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700968 if (DEBUG) {
969 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
970 }
971 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
972 // This callback can happen if the dialpad fragment is recreated because of
973 // activity destruction. In that case, don't update the search view because
974 // that would bring the user back to the search fragment regardless of the
975 // previous state of the application. Instead, just return here and let the
976 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700977 if (!TextUtils.isEmpty(normalizedQuery)) {
978 mPendingSearchViewQuery = normalizedQuery;
979 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700980 return;
981 }
Yorke Lee53a22302014-04-29 18:13:46 -0700982 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700983 }
984 }
Yorke Leec3766332013-07-31 11:13:16 -0700985
986 @Override
987 public void onListFragmentScrollStateChange(int scrollState) {
988 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700989 hideDialpadFragment(true, false);
Yorke Leef543baa2014-07-24 11:31:13 -0700990 DialerUtils.hideInputMethod(getCurrentFocus());
Yorke Leec3766332013-07-31 11:13:16 -0700991 }
992 }
993
994 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -0700995 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -0700996 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700997 // TODO: No-op for now. This should eventually show/hide the actionBar based on
998 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -0700999 }
1000
Yorke Lee86e21f72014-04-02 16:49:38 -07001001 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001002 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001003 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001004 }
1005
1006 private boolean phoneIsInUse() {
Santos Cordond15629d2014-07-07 15:15:29 -07001007 return getPhoneManager().isInAPhoneCall();
Yorke Leec3766332013-07-31 11:13:16 -07001008 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001009
Yorke Leee1424812013-09-04 18:24:48 -07001010 public static Intent getAddNumberToContactIntent(CharSequence text) {
1011 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1012 intent.putExtra(Intents.Insert.PHONE, text);
1013 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1014 return intent;
1015 }
1016
Yorke Leeda0f9042013-12-05 14:25:51 -08001017 private boolean canIntentBeHandled(Intent intent) {
1018 final PackageManager packageManager = getPackageManager();
1019 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1020 PackageManager.MATCH_DEFAULT_ONLY);
1021 return resolveInfo != null && resolveInfo.size() > 0;
1022 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001023
Yorke Lee6a1461a2014-04-21 16:27:14 -07001024 @Override
1025 public void showCallHistory() {
1026 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1027 // CONTENT_TYPE, so that we always open our call log from our dialer
1028 final Intent intent = new Intent(this, CallLogActivity.class);
1029 startActivity(intent);
1030 }
1031
Yorke Lee86e21f72014-04-02 16:49:38 -07001032 /**
1033 * Called when the user has long-pressed a contact tile to start a drag operation.
1034 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001035 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001036 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001037 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001038 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001039 }
Andrew Lee18963442014-06-06 17:20:13 -07001040 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001041 }
1042
1043 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001044 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1045 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001046
Yorke Lee86e21f72014-04-02 16:49:38 -07001047 /**
1048 * Called when the user has released a contact tile after long-pressing it.
1049 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001050 @Override
1051 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001052 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001053 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001054 }
Andrew Lee18963442014-06-06 17:20:13 -07001055 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001056 }
1057
1058 @Override
1059 public void onDroppedOnRemove() {}
1060
1061 /**
Yorke Leed999b712014-04-23 15:10:58 -07001062 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001063 * once it has been attached to the activity.
1064 */
1065 @Override
1066 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001067 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001068 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001069 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001070
1071 @Override
1072 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001073 // Specify call-origin so that users will see the previous tab instead of
1074 // CallLog screen (search UI will be automatically exited).
1075 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001076 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001077 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001078 }
1079
1080 @Override
1081 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001082 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1083 }
1084
1085 @Override
1086 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001087 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001088 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1089 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001090 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001091 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001092 }
1093
1094 @Override
1095 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001096 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001097 }
1098
1099 @Override
1100 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001101 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001102 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001103
Yorke Leecc4660d2014-04-24 11:22:57 -07001104 @Override
1105 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001106 position = mListsFragment.getRtlPosition(position);
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.
Yorke Lee69c247f2014-07-22 11:49:49 -07001110 // If the app is in RTL mode, we need to check against the second tab, rather than the
1111 // first. This is because if we are scrolling between the first and second tabs, the
1112 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1113 // reversal of the order of the tabs.
1114 final boolean isLayoutRtl = DialerUtils.isRtl();
1115 final boolean shouldScrollButton = position == (isLayoutRtl
1116 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1117 if (shouldScrollButton && !mIsLandscape) {
1118 mFloatingActionButtonController.onPageScrolled(
1119 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001120 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1121 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001122 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001123 }
1124
1125 @Override
1126 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001127 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001128 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001129 }
1130
1131 @Override
1132 public void onPageScrollStateChanged(int state) {
1133 }
1134
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001135 private TelephonyManager getTelephonyManager() {
1136 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1137 }
1138
Santos Cordond15629d2014-07-07 15:15:29 -07001139 private PhoneManager getPhoneManager() {
1140 return (PhoneManager) getSystemService(Context.PHONE_SERVICE);
1141 }
1142
Yorke Lee5253be02014-05-21 18:50:03 -07001143 @Override
1144 public boolean isActionBarShowing() {
1145 return mActionBarController.isActionBarShowing();
1146 }
1147
Andrew Lee9da8fb42014-06-03 14:03:09 -07001148 public boolean isDialpadShown() {
1149 return mIsDialpadShown;
1150 }
1151
Yorke Lee5253be02014-05-21 18:50:03 -07001152 @Override
1153 public int getActionBarHideOffset() {
1154 return getActionBar().getHideOffset();
1155 }
1156
1157 @Override
1158 public int getActionBarHeight() {
1159 return mActionBarHeight;
1160 }
1161
1162 @Override
1163 public void setActionBarHideOffset(int hideOffset) {
Yorke Leea524ae52014-08-05 18:01:05 -07001164 mActionBarController.setHideOffset(hideOffset);
Yorke Lee5253be02014-05-21 18:50:03 -07001165 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001166
1167 /**
1168 * Updates controller based on currently known information.
1169 *
1170 * @param animate Whether or not to animate the transition.
1171 */
1172 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1173 int align;
1174 if (mIsDialpadShown) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001175 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_END
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001176 : FloatingActionButtonController.ALIGN_MIDDLE;
1177 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001178 if (!mIsLandscape) {
1179 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1180 ? FloatingActionButtonController.ALIGN_MIDDLE
Yorke Lee69c247f2014-07-22 11:49:49 -07001181 : FloatingActionButtonController.ALIGN_END;
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001182 } else {
Yorke Lee69c247f2014-07-22 11:49:49 -07001183 align = FloatingActionButtonController.ALIGN_END;
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001184 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001185 }
1186 mFloatingActionButtonController.align(align,
1187 0 /* offsetX */,
1188 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1189 animate);
1190 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001191}