blob: 4cc11eba02ca96bfd2f4d41c7c38a39118b79634 [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;
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 Lee69c247f2014-07-22 11:49:49 -070096import java.util.Locale;
Yorke Leec3766332013-07-31 11:13:16 -070097
Chiao Cheng94b10b52012-08-17 16:59:12 -070098/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070099 * The dialer tab's title is 'phone', a more common name (see strings.xml).
100 */
Yorke Leec3766332013-07-31 11:13:16 -0700101public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700102 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700103 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800104 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700105 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700106 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700107 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700108 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700109 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700110 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700111 ViewPager.OnPageChangeListener,
112 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700113 private static final String TAG = "DialtactsActivity";
114
Ihab Awad526c0b82014-02-27 12:55:36 -0800115 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700116
Yorke Leef74011e2013-08-02 11:30:30 -0700117 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
118
Chiao Cheng94b10b52012-08-17 16:59:12 -0700119 /** @see #getCallOrigin() */
120 private static final String CALL_ORIGIN_DIALTACTS =
121 "com.android.dialer.DialtactsActivity";
122
Yorke Leeb207f8a2013-08-29 18:51:06 -0700123 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
124 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700125 private static final String KEY_SEARCH_QUERY = "search_query";
126 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700127 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700128
Yorke Leec3766332013-07-31 11:13:16 -0700129 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
130 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
131 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
132 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700133
Chiao Cheng94b10b52012-08-17 16:59:12 -0700134 /**
135 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
136 */
137 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
138
Yorke Leec3766332013-07-31 11:13:16 -0700139 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700140
Yorke Lee28aab272014-06-11 10:24:19 -0700141 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700142
Yorke Leec3766332013-07-31 11:13:16 -0700143 /**
Yorke Leec3766332013-07-31 11:13:16 -0700144 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700145 */
Yorke Leef74011e2013-08-02 11:30:30 -0700146 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700147
148 /**
149 * Fragment for searching phone numbers using the alphanumeric keyboard.
150 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700151 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700152
153 /**
154 * Fragment for searching phone numbers using the dialpad.
155 */
156 private SmartDialSearchFragment mSmartDialSearchFragment;
157
Yorke Leee00c9fe2014-04-12 12:42:06 -0700158 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700159 * Animation that slides in.
160 */
161 private Animation mSlideIn;
162
163 /**
164 * Animation that slides out.
165 */
166 private Animation mSlideOut;
167
168 /**
169 * Listener for after slide out animation completes on dialer fragment.
170 */
171 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
172 @Override
173 public void onAnimationEnd(Animation animation) {
174 commitDialpadFragmentHide();
175 }
176 };
177
178 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700179 * Fragment containing the speed dial list, recents list, and all contacts list.
180 */
181 private ListsFragment mListsFragment;
182
Yorke Leeb207f8a2013-08-29 18:51:06 -0700183 private boolean mInDialpadSearch;
184 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700185 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700186 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700187 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700188
Yorke Leeef2b7382013-08-09 17:39:25 -0700189 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700190 * Whether or not the device is in landscape orientation.
191 */
192 private boolean mIsLandscape;
193
194 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700195 * The position of the currently selected tab in the attached {@link ListsFragment}.
196 */
197 private int mCurrentTabPosition = 0;
198
199 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700200 * True if the dialpad is only temporarily showing due to being in call
201 */
202 private boolean mInCallDialpadUp;
203
204 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700205 * True when this activity has been launched for the first time.
206 */
Yorke Lee98702de2013-08-06 12:03:32 -0700207 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700208
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700209 /**
210 * Search query to be applied to the SearchView in the ActionBar once
211 * onCreateOptionsMenu has been called.
212 */
213 private String mPendingSearchViewQuery;
214
Yorke Lee74edcdc2014-07-11 16:15:08 -0700215 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700216 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700217 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700218
Yorke Leeef2b7382013-08-09 17:39:25 -0700219 private String mSearchQuery;
220
Yorke Leefce269a2013-08-12 11:56:04 -0700221 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700222 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700223 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700224
225 private String mDescriptionDialButtonStr;
226 private String mActionMenuDialpadButtonStr;
227 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700228 private FloatingActionButtonController mFloatingActionButtonController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700229 /**
230 * Additional offset for FAB to be lowered when dialpad is open.
231 */
232 private int mFloatingActionButtonDialpadMarginBottomOffset;
Yorke Leefce269a2013-08-12 11:56:04 -0700233
Andrew Lee2423a2f2014-05-29 14:14:45 -0700234 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700235
Andrew Leee74a10e2014-05-16 14:31:40 -0700236 private class OptionsPopupMenu extends PopupMenu {
237 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700238 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700239 }
240
241 @Override
242 public void show() {
243 final Menu menu = getMenu();
244 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700245 clearFrequents.setVisible(mListsFragment != null &&
246 mListsFragment.getSpeedDialFragment() != null &&
247 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700248 super.show();
249 }
250 }
251
Chiao Cheng94b10b52012-08-17 16:59:12 -0700252 /**
Yorke Lee28266192014-05-01 10:05:52 -0700253 * Listener that listens to drag events and sends their x and y coordinates to a
254 * {@link DragDropController}.
255 */
256 private class LayoutOnDragListener implements OnDragListener {
257 @Override
258 public boolean onDrag(View v, DragEvent event) {
259 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700260 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700261 }
262 return true;
263 }
264 }
265
266 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700267 * Listener used to send search queries to the phone search fragment.
268 */
Yorke Lee53a22302014-04-29 18:13:46 -0700269 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700270 @Override
271 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
272 }
Yorke Leec3766332013-07-31 11:13:16 -0700273
Andrew Lee99a570c2014-05-15 14:18:50 -0700274 @Override
275 public void onTextChanged(CharSequence s, int start, int before, int count) {
276 final String newText = s.toString();
277 if (newText.equals(mSearchQuery)) {
278 // If the query hasn't changed (perhaps due to activity being destroyed
279 // and restored, or user launching the same DIAL intent twice), then there is
280 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700281 return;
282 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700283 if (DEBUG) {
284 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700285 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700286 }
Yorke Lee710709d2014-05-29 07:18:42 -0700287 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700288
Andrew Lee90374a72014-05-16 15:01:09 -0700289 // Show search fragment only when the query string is changed to non-empty text.
290 if (!TextUtils.isEmpty(newText)) {
291 // Call enterSearchUi only if we are switching search modes, or showing a search
292 // fragment for the first time.
293 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
294 (!mIsDialpadShown && mInRegularSearch);
295 if (!sameSearchMode) {
296 enterSearchUi(mIsDialpadShown, mSearchQuery);
297 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700298 }
299
Andrew Leea8515422014-06-13 16:53:54 -0700300 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700301 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700302 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700303 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700304 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700305 }
306
307 @Override
308 public void afterTextChanged(Editable s) {
309 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700310 };
311
Andrew Leeb1903842014-05-15 16:11:24 -0700312
313 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700314 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700315 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700316 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700317 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700318 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700319 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700320 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700321 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
322 }
Andrew Leeb1903842014-05-15 16:11:24 -0700323 }
324 };
325
326 /**
327 * If the search term is empty and the user closes the soft keyboard, close the search UI.
328 */
329 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
330 @Override
331 public boolean onKey(View v, int keyCode, KeyEvent event) {
332 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
333 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700334 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700335 }
336 return false;
337 }
338 };
339
Chiao Cheng94b10b52012-08-17 16:59:12 -0700340 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700341 protected void onCreate(Bundle savedInstanceState) {
342 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700343 mFirstLaunch = true;
344
Andrew Lee2423a2f2014-05-29 14:14:45 -0700345 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700346 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700347 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
348 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700349
Yorke Lee8898cd02013-08-08 10:24:27 -0700350 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800351 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700352
Yorke Lee53a22302014-04-29 18:13:46 -0700353 final ActionBar actionBar = getActionBar();
354 actionBar.setCustomView(R.layout.search_edittext);
355 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700356 actionBar.setBackgroundDrawable(null);
Yorke Lee8fd67242014-08-05 18:43:45 -0700357 actionBar.setElevation(resources.getDimensionPixelSize(R.dimen.action_bar_elevation));
Yorke Lee53a22302014-04-29 18:13:46 -0700358
Yorke Lee5253be02014-05-21 18:50:03 -0700359 mActionBarController = new ActionBarController(this,
360 (SearchEditTextLayout) actionBar.getCustomView());
361
Andrew Lee04675a52014-06-05 18:36:20 -0700362 SearchEditTextLayout searchEditTextLayout =
363 (SearchEditTextLayout) actionBar.getCustomView();
364 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
365
366 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700367 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700368 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
369 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
370 .setOnClickListener(mSearchViewOnClickListener);
371 searchEditTextLayout.findViewById(R.id.search_box_start_search)
372 .setOnClickListener(mSearchViewOnClickListener);
373 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700374 @Override
375 public void onBackButtonClicked() {
376 onBackPressed();
377 }
378 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700379
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700380 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700381 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700382
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700383 final View floatingActionButtonContainer = findViewById(
384 R.id.floating_action_button_container);
385 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
386 int floatingActionButtonWidth = resources.getDimensionPixelSize(
387 R.dimen.floating_action_button_width);
388 mFloatingActionButton.setOnClickListener(this);
389 mFloatingActionButtonController = new FloatingActionButtonController(this,
Sai Cheemalapati41460652014-06-02 21:05:39 -0700390 floatingActionButtonContainer);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700391 mFloatingActionButtonDialpadMarginBottomOffset = resources.getDimensionPixelOffset(
392 R.dimen.floating_action_button_dialpad_margin_bottom_offset);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700393
Andrew Lee04675a52014-06-05 18:36:20 -0700394 ImageButton optionsMenuButton =
395 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700396 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700397 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
398 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700399
Yorke Leeef2b7382013-08-09 17:39:25 -0700400 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
401 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700402 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800403 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700404 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800405 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
406 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700407 } else {
408 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700409 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
410 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700411 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700412 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700413 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700414 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700415
416 mSlideIn = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700417 mIsLandscape ? R.anim.dialpad_slide_in_right : R.anim.dialpad_slide_in_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700418 mSlideOut = AnimationUtils.loadAnimation(this,
Sai Cheemalapatica0d53b2014-06-09 09:58:09 -0700419 mIsLandscape ? R.anim.dialpad_slide_out_right : R.anim.dialpad_slide_out_bottom);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700420
421 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700422
Yorke Lee28aab272014-06-11 10:24:19 -0700423 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700424 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
425 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700426 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700427 new ViewTreeObserver.OnGlobalLayoutListener() {
428 @Override
429 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700430 final ViewTreeObserver observer = floatingActionButtonContainer
431 .getViewTreeObserver();
432 if (!observer.isAlive()) {
433 return;
434 }
435 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700436 int screenWidth = parentLayout.getWidth();
437 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700438 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700439 }
440 });
Andrew Lee0c667702014-05-12 14:31:45 -0700441
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700442 setupActivityOverlay();
443
Yorke Lee0baa98b2013-08-22 10:55:16 -0700444 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700445 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700446 }
447
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700448 private void setupActivityOverlay() {
449 final View activityOverlay = findViewById(R.id.activity_overlay);
450 activityOverlay.setOnTouchListener(new OnTouchListener() {
451 @Override
452 public boolean onTouch(View v, MotionEvent event) {
453 if (!mIsDialpadShown) {
454 maybeExitSearchUi();
455 }
456 return false;
457 }
458 });
459 }
460
Chiao Cheng94b10b52012-08-17 16:59:12 -0700461 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700462 protected void onResume() {
463 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700464 if (mFirstLaunch) {
465 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700466 } else if (!phoneIsInUse() && mInCallDialpadUp) {
467 hideDialpadFragment(false, true);
468 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700469 } else if (mShowDialpadOnResume) {
470 showDialpadFragment(false);
471 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700472 }
473 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700474 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700475 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700476 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700477 }
478
479 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700480 protected void onPause() {
481 if (mClearSearchOnPause) {
482 hideDialpadAndSearchUi();
483 mClearSearchOnPause = false;
484 }
485 super.onPause();
486 }
487
488 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700489 protected void onSaveInstanceState(Bundle outState) {
490 super.onSaveInstanceState(outState);
491 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700492 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
493 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700494 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700495 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700496 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700497 }
498
499 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700500 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700501 if (fragment instanceof DialpadFragment) {
502 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700503 if (!mShowDialpadOnResume) {
504 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
505 transaction.hide(mDialpadFragment);
506 transaction.commit();
507 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700508 } else if (fragment instanceof SmartDialSearchFragment) {
509 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700510 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700511 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700512 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700513 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700514 } else if (fragment instanceof ListsFragment) {
515 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700516 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700517 }
Yorke Leec3766332013-07-31 11:13:16 -0700518 }
519
Alon Albertb453e5b2013-09-10 15:54:23 -0700520 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700521 final Intent intent = new Intent(this, DialerSettingsActivity.class);
522 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700523 }
524
Chiao Cheng94b10b52012-08-17 16:59:12 -0700525 @Override
526 public void onClick(View view) {
527 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700528 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700529 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700530 mInCallDialpadUp = false;
531 showDialpadFragment(true);
532 } else {
533 // Dial button was pressed; tell the Dialpad fragment
534 mDialpadFragment.dialButtonPressed();
535 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700536 break;
Yorke Leec3766332013-07-31 11:13:16 -0700537 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800538 try {
539 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
540 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
541 } catch (ActivityNotFoundException e) {
542 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
543 Toast.LENGTH_SHORT).show();
544 }
Yorke Leec3766332013-07-31 11:13:16 -0700545 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700546 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700547 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700548 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700549 default: {
550 Log.wtf(TAG, "Unexpected onClick event from " + view);
551 break;
552 }
553 }
554 }
555
Yorke Leec3766332013-07-31 11:13:16 -0700556 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700557 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700558 switch (item.getItemId()) {
559 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700560 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700561 break;
562 case R.id.menu_add_contact:
563 try {
564 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
565 } catch (ActivityNotFoundException e) {
566 Toast toast = Toast.makeText(this,
567 R.string.add_contact_not_available,
568 Toast.LENGTH_SHORT);
569 toast.show();
570 }
571 break;
572 case R.id.menu_import_export:
573 // We hard-code the "contactsAreAvailable" argument because doing it properly would
574 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
575 // now in Dialtacts for (potential) performance reasons. Compare with how it is
576 // done in {@link PeopleActivity}.
577 ImportExportDialogFragment.show(getFragmentManager(), true,
578 DialtactsActivity.class);
579 return true;
580 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700581 ClearFrequentsDialog.show(getFragmentManager());
582 return true;
583 case R.id.menu_call_settings:
584 handleMenuSettings();
585 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700586 }
587 return false;
588 }
589
590 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700591 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
592 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
593 if (resultCode == RESULT_OK) {
594 final ArrayList<String> matches = data.getStringArrayListExtra(
595 RecognizerIntent.EXTRA_RESULTS);
596 if (matches.size() > 0) {
597 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700598 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700599 } else {
600 Log.e(TAG, "Voice search - nothing heard");
601 }
602 } else {
603 Log.e(TAG, "Voice search failed");
604 }
605 }
606 super.onActivityResult(requestCode, resultCode, data);
607 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700608
Andrew Lee2a58ab82014-05-15 02:16:04 -0700609 /**
610 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
611 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
612 * @see #onDialpadShown
613 */
Yorke Leec3766332013-07-31 11:13:16 -0700614 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700615 if (mIsDialpadShown) {
616 return;
617 }
618 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700619 mDialpadFragment.setAnimate(animate);
Sai Cheemalapati2d7faf62014-08-04 11:48:50 -0700620 mDialpadFragment.sendScreenView();
Andrew Leecdfa6c62014-05-06 15:33:35 -0700621
Chiao Cheng94b10b52012-08-17 16:59:12 -0700622 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700623 ft.show(mDialpadFragment);
624 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700625
Yorke Lee5253be02014-05-21 18:50:03 -0700626 mActionBarController.onDialpadUp();
627
Andrew Leeb1903842014-05-15 16:11:24 -0700628 if (!isInSearchUi()) {
629 enterSearchUi(true /* isSmartDial */, mSearchQuery);
630 }
Yorke Leec3766332013-07-31 11:13:16 -0700631 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700632
Andrew Lee2a58ab82014-05-15 02:16:04 -0700633 /**
634 * Callback from child DialpadFragment when the dialpad is shown.
635 */
636 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700637 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
638 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
639 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700640 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700641 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700642 } else {
643 mDialpadFragment.setYFraction(0);
644 }
645
Andrew Lee2a58ab82014-05-15 02:16:04 -0700646 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700647 }
648
649 /**
650 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
651 * a callback after the hide animation ends.
652 * @see #commitDialpadFragmentHide
653 */
Yorke Leeca195042013-09-25 16:29:38 -0700654 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700655 if (mDialpadFragment == null) {
656 return;
657 }
Yorke Leef6673d32013-08-23 15:34:17 -0700658 if (clearDialpad) {
659 mDialpadFragment.clearDialpad();
660 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700661 if (!mIsDialpadShown) {
662 return;
Yorke Leec3766332013-07-31 11:13:16 -0700663 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700664 mIsDialpadShown = false;
665 mDialpadFragment.setAnimate(animate);
666
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700667 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700668 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
669 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
670
671 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700672 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700673 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700674 } else {
675 commitDialpadFragmentHide();
676 }
677
Yorke Lee5253be02014-05-21 18:50:03 -0700678 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700679
Andrew Leed4cde832014-05-16 15:56:48 -0700680 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700681 if (TextUtils.isEmpty(mSearchQuery)) {
682 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700683 }
Andrew Leed4cde832014-05-16 15:56:48 -0700684 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700685 }
686
687 /**
688 * Finishes hiding the dialpad fragment after any animations are completed.
689 */
690 private void commitDialpadFragmentHide() {
691 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700692 ft.hide(mDialpadFragment);
693 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700694 }
695
Andrew Lee2a58ab82014-05-15 02:16:04 -0700696 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700697 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700698 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700699 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700700 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700701 fragment = mRegularSearchFragment;
702 }
703 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700704 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700705 }
706 }
707
Yorke Lee5253be02014-05-21 18:50:03 -0700708 @Override
709 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700710 return mInDialpadSearch || mInRegularSearch;
711 }
712
Yorke Lee5253be02014-05-21 18:50:03 -0700713 @Override
714 public boolean hasSearchQuery() {
715 return !TextUtils.isEmpty(mSearchQuery);
716 }
717
718 @Override
719 public boolean shouldShowActionBar() {
720 return mListsFragment.shouldShowActionBar();
721 }
722
Yorke Leeb207f8a2013-08-29 18:51:06 -0700723 private void setNotInSearchUi() {
724 mInDialpadSearch = false;
725 mInRegularSearch = false;
726 }
727
Yorke Lee311969c2013-08-26 06:31:11 -0700728 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700729 if (mIsDialpadShown) {
730 hideDialpadFragment(false, true);
731 } else {
732 exitSearchUi();
733 }
Yorke Lee311969c2013-08-26 06:31:11 -0700734 }
735
Yorke Lee53a22302014-04-29 18:13:46 -0700736 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700737 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
738 if (canIntentBeHandled(voiceIntent)) {
739 mVoiceSearchButton.setVisibility(View.VISIBLE);
740 mVoiceSearchButton.setOnClickListener(this);
741 } else {
742 mVoiceSearchButton.setVisibility(View.GONE);
743 }
744 }
745
Andrew Leee74a10e2014-05-16 14:31:40 -0700746 private OptionsPopupMenu buildOptionsMenu(View invoker) {
747 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
748 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700749 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700750 popupMenu.setOnMenuItemClickListener(this);
751 return popupMenu;
752 }
753
Yorke Lee86e21f72014-04-02 16:49:38 -0700754 @Override
755 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700756 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700757 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700758 mPendingSearchViewQuery = null;
759 }
Andrew Leee74a10e2014-05-16 14:31:40 -0700760 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700761 }
762
Chiao Cheng94b10b52012-08-17 16:59:12 -0700763 /**
764 * Returns true if the intent is due to hitting the green send key (hardware call button:
765 * KEYCODE_CALL) while in a call.
766 *
767 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700768 * @return true if the intent is due to hitting the green send key while in a call
769 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700770 private boolean isSendKeyWhileInCall(Intent intent) {
771 // If there is a call in progress and the user launched the dialer by hitting the call
772 // button, go straight to the in-call screen.
773 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700774
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700775 if (callKey) {
Santos Cordond15629d2014-07-07 15:15:29 -0700776 getPhoneManager().showCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700777 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700778 }
779
780 return false;
781 }
782
783 /**
784 * Sets the current tab based on the intent's request type
785 *
786 * @param intent Intent that contains information about which tab should be selected
787 */
Yorke Leec3766332013-07-31 11:13:16 -0700788 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700789 // 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 -0700790 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700791 finish();
792 return;
793 }
794
Yorke Lee669b6082013-09-17 15:43:38 -0700795 if (mDialpadFragment != null) {
796 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700797 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700798 mDialpadFragment.setStartedFromNewIntent(true);
799 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
800 mInCallDialpadUp = true;
801 }
802 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700803 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700804 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700805 }
806
807 @Override
808 public void onNewIntent(Intent newIntent) {
809 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700810 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700811
Chiao Cheng94b10b52012-08-17 16:59:12 -0700812 invalidateOptionsMenu();
813 }
814
815 /** Returns true if the given intent contains a phone number to populate the dialer with */
816 private boolean isDialIntent(Intent intent) {
817 final String action = intent.getAction();
818 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
819 return true;
820 }
821 if (Intent.ACTION_VIEW.equals(action)) {
822 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700823 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700824 return true;
825 }
826 }
827 return false;
828 }
829
830 /**
831 * Returns an appropriate call origin for this Activity. May return null when no call origin
832 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
833 * for remembering the tab in which the user made a phone call, so the external app's DIAL
834 * request should not be counted.)
835 */
836 public String getCallOrigin() {
837 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
838 }
839
Chiao Cheng94b10b52012-08-17 16:59:12 -0700840 /**
Yorke Leec3766332013-07-31 11:13:16 -0700841 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700842 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700843 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700844 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700845 // Weird race condition where fragment is doing work after the activity is destroyed
846 // due to talkback being on (b/10209937). Just return since we can't do any
847 // constructive here.
848 return;
849 }
850
Yorke Leeef2b7382013-08-09 17:39:25 -0700851 if (DEBUG) {
852 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
853 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700854
Yorke Leec3766332013-07-31 11:13:16 -0700855 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700856 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700857 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700858 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700859 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700860 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700861
Yorke Leeb207f8a2013-08-29 18:51:06 -0700862 final String tag;
863 if (smartDialSearch) {
864 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
865 } else {
866 tag = TAG_REGULAR_SEARCH_FRAGMENT;
867 }
868 mInDialpadSearch = smartDialSearch;
869 mInRegularSearch = !smartDialSearch;
870
Andrew Lee752956e2014-05-15 11:43:38 -0700871 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700872 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700873 if (fragment == null) {
874 if (smartDialSearch) {
875 fragment = new SmartDialSearchFragment();
876 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700877 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700878 }
Andrew Leeb1903842014-05-15 16:11:24 -0700879 transaction.add(R.id.dialtacts_frame, fragment, tag);
880 } else {
881 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700882 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700883 // DialtactsActivity will provide the options menu
884 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700885 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700886 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700887 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700888
889 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700890 }
891
892 /**
Yorke Leec3766332013-07-31 11:13:16 -0700893 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700894 */
Yorke Leec3766332013-07-31 11:13:16 -0700895 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700896 // See related bug in enterSearchUI();
897 if (getFragmentManager().isDestroyed()) {
898 return;
899 }
Andrew Leeb1903842014-05-15 16:11:24 -0700900
Andrew Leeb1903842014-05-15 16:11:24 -0700901 mSearchView.setText(null);
902 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700903 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700904
Andrew Leeb1903842014-05-15 16:11:24 -0700905 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700906 if (mSmartDialSearchFragment != null) {
907 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700908 }
Andrew Leeb1903842014-05-15 16:11:24 -0700909 if (mRegularSearchFragment != null) {
910 transaction.remove(mRegularSearchFragment);
911 }
912 transaction.commit();
913
914 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700915 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700916 }
917
918 /** Returns an Intent to launch Call Settings screen */
919 public static Intent getCallSettingsIntent() {
Yorke Lee6eec2282014-07-18 12:40:27 -0700920 final Intent intent = new Intent(TelecommManager.ACTION_SHOW_CALL_SETTINGS);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700921 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
922 return intent;
923 }
924
925 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700926 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700927 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700928 if (TextUtils.isEmpty(mSearchQuery) ||
929 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
930 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700931 exitSearchUi();
932 }
Yorke Leef6673d32013-08-23 15:34:17 -0700933 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700934 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700935 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700936 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700937 } else {
938 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700939 }
Yorke Leec3766332013-07-31 11:13:16 -0700940 }
941
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700942 /**
943 * @return True if the search UI was exited, false otherwise
944 */
945 private boolean maybeExitSearchUi() {
946 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
947 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700948 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700949 return true;
950 }
951 return false;
952 }
953
Yorke Leec3766332013-07-31 11:13:16 -0700954 @Override
955 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700956 if (mSmartDialSearchFragment != null) {
957 mSmartDialSearchFragment.setAddToContactNumber(query);
958 }
Yorke Leec3766332013-07-31 11:13:16 -0700959 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
960 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700961
962 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700963 if (DEBUG) {
964 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
965 }
966 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
967 // This callback can happen if the dialpad fragment is recreated because of
968 // activity destruction. In that case, don't update the search view because
969 // that would bring the user back to the search fragment regardless of the
970 // previous state of the application. Instead, just return here and let the
971 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700972 if (!TextUtils.isEmpty(normalizedQuery)) {
973 mPendingSearchViewQuery = normalizedQuery;
974 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700975 return;
976 }
Yorke Lee53a22302014-04-29 18:13:46 -0700977 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700978 }
979 }
Yorke Leec3766332013-07-31 11:13:16 -0700980
981 @Override
982 public void onListFragmentScrollStateChange(int scrollState) {
983 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700984 hideDialpadFragment(true, false);
Yorke Leef543baa2014-07-24 11:31:13 -0700985 DialerUtils.hideInputMethod(getCurrentFocus());
Yorke Leec3766332013-07-31 11:13:16 -0700986 }
987 }
988
989 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -0700990 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -0700991 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700992 // TODO: No-op for now. This should eventually show/hide the actionBar based on
993 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -0700994 }
995
Yorke Lee86e21f72014-04-02 16:49:38 -0700996 @Override
Andrew Leea73e1892014-05-13 13:21:16 -0700997 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -0700998 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -0700999 }
1000
1001 private boolean phoneIsInUse() {
Santos Cordond15629d2014-07-07 15:15:29 -07001002 return getPhoneManager().isInAPhoneCall();
Yorke Leec3766332013-07-31 11:13:16 -07001003 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001004
Yorke Leee1424812013-09-04 18:24:48 -07001005 public static Intent getAddNumberToContactIntent(CharSequence text) {
1006 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1007 intent.putExtra(Intents.Insert.PHONE, text);
1008 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1009 return intent;
1010 }
1011
Yorke Leeda0f9042013-12-05 14:25:51 -08001012 private boolean canIntentBeHandled(Intent intent) {
1013 final PackageManager packageManager = getPackageManager();
1014 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1015 PackageManager.MATCH_DEFAULT_ONLY);
1016 return resolveInfo != null && resolveInfo.size() > 0;
1017 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001018
Yorke Lee6a1461a2014-04-21 16:27:14 -07001019 @Override
1020 public void showCallHistory() {
1021 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1022 // CONTENT_TYPE, so that we always open our call log from our dialer
1023 final Intent intent = new Intent(this, CallLogActivity.class);
1024 startActivity(intent);
1025 }
1026
Yorke Lee86e21f72014-04-02 16:49:38 -07001027 /**
1028 * Called when the user has long-pressed a contact tile to start a drag operation.
1029 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001030 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001031 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001032 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001033 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001034 }
Andrew Lee18963442014-06-06 17:20:13 -07001035 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001036 }
1037
1038 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001039 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1040 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001041
Yorke Lee86e21f72014-04-02 16:49:38 -07001042 /**
1043 * Called when the user has released a contact tile after long-pressing it.
1044 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001045 @Override
1046 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001047 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001048 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001049 }
Andrew Lee18963442014-06-06 17:20:13 -07001050 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001051 }
1052
1053 @Override
1054 public void onDroppedOnRemove() {}
1055
1056 /**
Yorke Leed999b712014-04-23 15:10:58 -07001057 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001058 * once it has been attached to the activity.
1059 */
1060 @Override
1061 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001062 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001063 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001064 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001065
1066 @Override
1067 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001068 // Specify call-origin so that users will see the previous tab instead of
1069 // CallLog screen (search UI will be automatically exited).
1070 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001071 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001072 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001073 }
1074
1075 @Override
1076 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001077 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1078 }
1079
1080 @Override
1081 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001082 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001083 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1084 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001085 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001086 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001087 }
1088
1089 @Override
1090 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001091 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001092 }
1093
1094 @Override
1095 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001096 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001097 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001098
Yorke Leecc4660d2014-04-24 11:22:57 -07001099 @Override
1100 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001101 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001102 // Only scroll the button when the first tab is selected. The button should scroll from
1103 // the middle to right position only on the transition from the first tab to the second
1104 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001105 // If the app is in RTL mode, we need to check against the second tab, rather than the
1106 // first. This is because if we are scrolling between the first and second tabs, the
1107 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1108 // reversal of the order of the tabs.
1109 final boolean isLayoutRtl = DialerUtils.isRtl();
1110 final boolean shouldScrollButton = position == (isLayoutRtl
1111 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1112 if (shouldScrollButton && !mIsLandscape) {
1113 mFloatingActionButtonController.onPageScrolled(
1114 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001115 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1116 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001117 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001118 }
1119
1120 @Override
1121 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001122 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001123 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001124 }
1125
1126 @Override
1127 public void onPageScrollStateChanged(int state) {
1128 }
1129
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001130 private TelephonyManager getTelephonyManager() {
1131 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1132 }
1133
Santos Cordond15629d2014-07-07 15:15:29 -07001134 private PhoneManager getPhoneManager() {
1135 return (PhoneManager) getSystemService(Context.PHONE_SERVICE);
1136 }
1137
Yorke Lee5253be02014-05-21 18:50:03 -07001138 @Override
1139 public boolean isActionBarShowing() {
1140 return mActionBarController.isActionBarShowing();
1141 }
1142
Andrew Lee9da8fb42014-06-03 14:03:09 -07001143 public boolean isDialpadShown() {
1144 return mIsDialpadShown;
1145 }
1146
Yorke Lee5253be02014-05-21 18:50:03 -07001147 @Override
1148 public int getActionBarHideOffset() {
1149 return getActionBar().getHideOffset();
1150 }
1151
1152 @Override
1153 public int getActionBarHeight() {
1154 return mActionBarHeight;
1155 }
1156
1157 @Override
1158 public void setActionBarHideOffset(int hideOffset) {
1159 getActionBar().setHideOffset(hideOffset);
1160 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001161
1162 /**
1163 * Updates controller based on currently known information.
1164 *
1165 * @param animate Whether or not to animate the transition.
1166 */
1167 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1168 int align;
1169 if (mIsDialpadShown) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001170 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_END
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001171 : FloatingActionButtonController.ALIGN_MIDDLE;
1172 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001173 if (!mIsLandscape) {
1174 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1175 ? FloatingActionButtonController.ALIGN_MIDDLE
Yorke Lee69c247f2014-07-22 11:49:49 -07001176 : FloatingActionButtonController.ALIGN_END;
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001177 } else {
Yorke Lee69c247f2014-07-22 11:49:49 -07001178 align = FloatingActionButtonController.ALIGN_END;
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001179 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001180 }
1181 mFloatingActionButtonController.align(align,
1182 0 /* offsetX */,
1183 mIsDialpadShown ? mFloatingActionButtonDialpadMarginBottomOffset : 0 /* offsetY */,
1184 animate);
1185 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001186}