blob: 6991be6f9158d0175f35b3a57b096eda89512c44 [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;
Chiao Cheng94b10b52012-08-17 16:59:12 -070034import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070035import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070036import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070037import android.support.v4.view.ViewPager;
Yorke Lee6eec2282014-07-18 12:40:27 -070038import android.telecomm.TelecommManager;
Yorke Leec3766332013-07-31 11:13:16 -070039import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070040import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070041import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070042import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070043import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070044import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070045import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070046import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070047import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070049import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070050import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070051import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070052import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070053import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070054import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070055import android.view.animation.AnimationUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070056import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070057import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070058import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070059import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070060import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070061import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080062import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070063
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070064import com.android.contacts.common.CallUtil;
Yorke Leec3766332013-07-31 11:13:16 -070065import com.android.contacts.common.dialog.ClearFrequentsDialog;
66import com.android.contacts.common.interactions.ImportExportDialogFragment;
Nancy Chen0d3a7392014-08-12 14:44:53 -070067import com.android.contacts.common.interactions.TouchPointManager;
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;
Nancy Chen0d3a7392014-08-12 14:44:53 -070092import com.android.incallui.CallCardFragment;
Yorke Lee2fec47b2014-08-05 18:16:27 -070093import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070094import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070095
Yorke Leec3766332013-07-31 11:13:16 -070096import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080097import java.util.List;
Yorke Lee69c247f2014-07-22 11:49:49 -070098import java.util.Locale;
Yorke Leec3766332013-07-31 11:13:16 -070099
Chiao Cheng94b10b52012-08-17 16:59:12 -0700100/**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700101 * The dialer tab's title is 'phone', a more common name (see strings.xml).
102 */
Yorke Leec3766332013-07-31 11:13:16 -0700103public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700104 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700105 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800106 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700107 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700108 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700109 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700110 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700111 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700112 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700113 ViewPager.OnPageChangeListener,
114 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700115 private static final String TAG = "DialtactsActivity";
116
Ihab Awad526c0b82014-02-27 12:55:36 -0800117 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700118
Yorke Leef74011e2013-08-02 11:30:30 -0700119 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
120
Chiao Cheng94b10b52012-08-17 16:59:12 -0700121 /** @see #getCallOrigin() */
122 private static final String CALL_ORIGIN_DIALTACTS =
123 "com.android.dialer.DialtactsActivity";
124
Yorke Leeb207f8a2013-08-29 18:51:06 -0700125 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
126 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700127 private static final String KEY_SEARCH_QUERY = "search_query";
128 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700129 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700130
Yorke Leec3766332013-07-31 11:13:16 -0700131 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
132 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
133 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
134 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700135
Chiao Cheng94b10b52012-08-17 16:59:12 -0700136 /**
137 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
138 */
139 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
140
Yorke Leec3766332013-07-31 11:13:16 -0700141 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700142
Yorke Lee28aab272014-06-11 10:24:19 -0700143 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700144
Yorke Leec3766332013-07-31 11:13:16 -0700145 /**
Yorke Leec3766332013-07-31 11:13:16 -0700146 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700147 */
Yorke Leef74011e2013-08-02 11:30:30 -0700148 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700149
150 /**
151 * Fragment for searching phone numbers using the alphanumeric keyboard.
152 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700153 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700154
155 /**
156 * Fragment for searching phone numbers using the dialpad.
157 */
158 private SmartDialSearchFragment mSmartDialSearchFragment;
159
Yorke Leee00c9fe2014-04-12 12:42:06 -0700160 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700161 * Animation that slides in.
162 */
163 private Animation mSlideIn;
164
165 /**
166 * Animation that slides out.
167 */
168 private Animation mSlideOut;
169
170 /**
171 * Listener for after slide out animation completes on dialer fragment.
172 */
173 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
174 @Override
175 public void onAnimationEnd(Animation animation) {
176 commitDialpadFragmentHide();
177 }
178 };
179
180 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700181 * Fragment containing the speed dial list, recents list, and all contacts list.
182 */
183 private ListsFragment mListsFragment;
184
Yorke Leeb207f8a2013-08-29 18:51:06 -0700185 private boolean mInDialpadSearch;
186 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700187 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700188 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700189 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700190
Yorke Leeef2b7382013-08-09 17:39:25 -0700191 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700192 * Whether or not the device is in landscape orientation.
193 */
194 private boolean mIsLandscape;
195
196 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700197 * The position of the currently selected tab in the attached {@link ListsFragment}.
198 */
199 private int mCurrentTabPosition = 0;
200
201 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700202 * True if the dialpad is only temporarily showing due to being in call
203 */
204 private boolean mInCallDialpadUp;
205
206 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700207 * True when this activity has been launched for the first time.
208 */
Yorke Lee98702de2013-08-06 12:03:32 -0700209 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700210
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700211 /**
212 * Search query to be applied to the SearchView in the ActionBar once
213 * onCreateOptionsMenu has been called.
214 */
215 private String mPendingSearchViewQuery;
216
Yorke Lee74edcdc2014-07-11 16:15:08 -0700217 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700218 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700219 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700220
Yorke Leeef2b7382013-08-09 17:39:25 -0700221 private String mSearchQuery;
222
Yorke Leefce269a2013-08-12 11:56:04 -0700223 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700224 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700225 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700226
227 private String mDescriptionDialButtonStr;
228 private String mActionMenuDialpadButtonStr;
229 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700230 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700231
Andrew Lee2423a2f2014-05-29 14:14:45 -0700232 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700233
Andrew Leee74a10e2014-05-16 14:31:40 -0700234 private class OptionsPopupMenu extends PopupMenu {
235 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700236 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700237 }
238
239 @Override
240 public void show() {
241 final Menu menu = getMenu();
242 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700243 clearFrequents.setVisible(mListsFragment != null &&
244 mListsFragment.getSpeedDialFragment() != null &&
245 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700246 super.show();
247 }
248 }
249
Chiao Cheng94b10b52012-08-17 16:59:12 -0700250 /**
Yorke Lee28266192014-05-01 10:05:52 -0700251 * Listener that listens to drag events and sends their x and y coordinates to a
252 * {@link DragDropController}.
253 */
254 private class LayoutOnDragListener implements OnDragListener {
255 @Override
256 public boolean onDrag(View v, DragEvent event) {
257 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700258 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700259 }
260 return true;
261 }
262 }
263
264 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700265 * Listener used to send search queries to the phone search fragment.
266 */
Yorke Lee53a22302014-04-29 18:13:46 -0700267 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700268 @Override
269 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
270 }
Yorke Leec3766332013-07-31 11:13:16 -0700271
Andrew Lee99a570c2014-05-15 14:18:50 -0700272 @Override
273 public void onTextChanged(CharSequence s, int start, int before, int count) {
274 final String newText = s.toString();
275 if (newText.equals(mSearchQuery)) {
276 // If the query hasn't changed (perhaps due to activity being destroyed
277 // and restored, or user launching the same DIAL intent twice), then there is
278 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700279 return;
280 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700281 if (DEBUG) {
282 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700283 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700284 }
Yorke Lee710709d2014-05-29 07:18:42 -0700285 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700286
Andrew Lee90374a72014-05-16 15:01:09 -0700287 // Show search fragment only when the query string is changed to non-empty text.
288 if (!TextUtils.isEmpty(newText)) {
289 // Call enterSearchUi only if we are switching search modes, or showing a search
290 // fragment for the first time.
291 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
292 (!mIsDialpadShown && mInRegularSearch);
293 if (!sameSearchMode) {
294 enterSearchUi(mIsDialpadShown, mSearchQuery);
295 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700296 }
297
Andrew Leea8515422014-06-13 16:53:54 -0700298 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700299 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700300 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700301 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700302 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700303 }
304
305 @Override
306 public void afterTextChanged(Editable s) {
307 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700308 };
309
Andrew Leeb1903842014-05-15 16:11:24 -0700310
311 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700312 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700313 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700314 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700315 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700316 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700317 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700318 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700319 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
320 }
Andrew Leeb1903842014-05-15 16:11:24 -0700321 }
322 };
323
324 /**
325 * If the search term is empty and the user closes the soft keyboard, close the search UI.
326 */
327 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
328 @Override
329 public boolean onKey(View v, int keyCode, KeyEvent event) {
330 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
331 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700332 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700333 }
334 return false;
335 }
336 };
337
Chiao Cheng94b10b52012-08-17 16:59:12 -0700338 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700339 public boolean dispatchTouchEvent(MotionEvent ev) {
340 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
341 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
342 }
343 return super.dispatchTouchEvent(ev);
344
345 }
346
347 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700348 protected void onCreate(Bundle savedInstanceState) {
349 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700350 mFirstLaunch = true;
351
Andrew Lee2423a2f2014-05-29 14:14:45 -0700352 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700353 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700354 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
355 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700356
Yorke Lee8898cd02013-08-08 10:24:27 -0700357 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800358 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700359
Yorke Lee53a22302014-04-29 18:13:46 -0700360 final ActionBar actionBar = getActionBar();
361 actionBar.setCustomView(R.layout.search_edittext);
362 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700363 actionBar.setBackgroundDrawable(null);
Yorke Lee8fd67242014-08-05 18:43:45 -0700364 actionBar.setElevation(resources.getDimensionPixelSize(R.dimen.action_bar_elevation));
Yorke Lee53a22302014-04-29 18:13:46 -0700365
Yorke Lee5253be02014-05-21 18:50:03 -0700366 mActionBarController = new ActionBarController(this,
367 (SearchEditTextLayout) actionBar.getCustomView());
368
Andrew Lee04675a52014-06-05 18:36:20 -0700369 SearchEditTextLayout searchEditTextLayout =
370 (SearchEditTextLayout) actionBar.getCustomView();
371 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
372
373 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700374 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700375 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
376 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
377 .setOnClickListener(mSearchViewOnClickListener);
378 searchEditTextLayout.findViewById(R.id.search_box_start_search)
379 .setOnClickListener(mSearchViewOnClickListener);
380 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700381 @Override
382 public void onBackButtonClicked() {
383 onBackPressed();
384 }
385 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700386
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700387 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700388 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700389
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700390 final View floatingActionButtonContainer = findViewById(
391 R.id.floating_action_button_container);
392 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
393 int floatingActionButtonWidth = resources.getDimensionPixelSize(
394 R.dimen.floating_action_button_width);
395 mFloatingActionButton.setOnClickListener(this);
396 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Leebd7a0562014-08-19 11:38:32 -0700397 floatingActionButtonContainer, mFloatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700398
Andrew Lee04675a52014-06-05 18:36:20 -0700399 ImageButton optionsMenuButton =
400 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700401 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700402 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
403 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700404
Yorke Leeef2b7382013-08-09 17:39:25 -0700405 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
406 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700407 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800408 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700409 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800410 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
411 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700412 } else {
413 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700414 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
415 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700416 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700417 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700418 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700419 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700420
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700421 final boolean isLayoutRtl = DialerUtils.isRtl();
422 if (mIsLandscape) {
423 mSlideIn = AnimationUtils.loadAnimation(this,
424 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
425 mSlideOut = AnimationUtils.loadAnimation(this,
426 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
427 } else {
428 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
429 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
430 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700431
Yorke Lee2fec47b2014-08-05 18:16:27 -0700432 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
433 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
434
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700435 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700436
Yorke Lee28aab272014-06-11 10:24:19 -0700437 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700438 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
439 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700440 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700441 new ViewTreeObserver.OnGlobalLayoutListener() {
442 @Override
443 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700444 final ViewTreeObserver observer = floatingActionButtonContainer
445 .getViewTreeObserver();
446 if (!observer.isAlive()) {
447 return;
448 }
449 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700450 int screenWidth = parentLayout.getWidth();
451 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700452 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700453 }
454 });
Andrew Lee0c667702014-05-12 14:31:45 -0700455
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700456 setupActivityOverlay();
457
Yorke Lee0baa98b2013-08-22 10:55:16 -0700458 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700459 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700460 }
461
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700462 private void setupActivityOverlay() {
463 final View activityOverlay = findViewById(R.id.activity_overlay);
464 activityOverlay.setOnTouchListener(new OnTouchListener() {
465 @Override
466 public boolean onTouch(View v, MotionEvent event) {
467 if (!mIsDialpadShown) {
468 maybeExitSearchUi();
469 }
470 return false;
471 }
472 });
473 }
474
Chiao Cheng94b10b52012-08-17 16:59:12 -0700475 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700476 protected void onResume() {
477 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700478 if (mFirstLaunch) {
479 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700480 } else if (!phoneIsInUse() && mInCallDialpadUp) {
481 hideDialpadFragment(false, true);
482 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700483 } else if (mShowDialpadOnResume) {
484 showDialpadFragment(false);
485 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700486 }
487 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700488 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700489 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700490 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700491 }
492
493 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700494 protected void onPause() {
495 if (mClearSearchOnPause) {
496 hideDialpadAndSearchUi();
497 mClearSearchOnPause = false;
498 }
499 super.onPause();
500 }
501
502 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700503 protected void onSaveInstanceState(Bundle outState) {
504 super.onSaveInstanceState(outState);
505 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700506 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
507 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700508 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700509 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700510 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700511 }
512
513 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700514 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700515 if (fragment instanceof DialpadFragment) {
516 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700517 if (!mShowDialpadOnResume) {
518 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
519 transaction.hide(mDialpadFragment);
520 transaction.commit();
521 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700522 } else if (fragment instanceof SmartDialSearchFragment) {
523 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700524 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700525 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700526 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700527 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700528 } else if (fragment instanceof ListsFragment) {
529 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700530 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700531 }
Yorke Leec3766332013-07-31 11:13:16 -0700532 }
533
Alon Albertb453e5b2013-09-10 15:54:23 -0700534 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700535 final Intent intent = new Intent(this, DialerSettingsActivity.class);
536 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700537 }
538
Chiao Cheng94b10b52012-08-17 16:59:12 -0700539 @Override
540 public void onClick(View view) {
541 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700542 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700543 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700544 mInCallDialpadUp = false;
545 showDialpadFragment(true);
546 } else {
547 // Dial button was pressed; tell the Dialpad fragment
548 mDialpadFragment.dialButtonPressed();
549 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700550 break;
Yorke Leec3766332013-07-31 11:13:16 -0700551 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800552 try {
553 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
554 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
555 } catch (ActivityNotFoundException e) {
556 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
557 Toast.LENGTH_SHORT).show();
558 }
Yorke Leec3766332013-07-31 11:13:16 -0700559 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700560 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700561 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700562 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700563 default: {
564 Log.wtf(TAG, "Unexpected onClick event from " + view);
565 break;
566 }
567 }
568 }
569
Yorke Leec3766332013-07-31 11:13:16 -0700570 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700571 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700572 switch (item.getItemId()) {
573 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700574 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700575 break;
576 case R.id.menu_add_contact:
577 try {
578 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
579 } catch (ActivityNotFoundException e) {
580 Toast toast = Toast.makeText(this,
581 R.string.add_contact_not_available,
582 Toast.LENGTH_SHORT);
583 toast.show();
584 }
585 break;
586 case R.id.menu_import_export:
587 // We hard-code the "contactsAreAvailable" argument because doing it properly would
588 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
589 // now in Dialtacts for (potential) performance reasons. Compare with how it is
590 // done in {@link PeopleActivity}.
591 ImportExportDialogFragment.show(getFragmentManager(), true,
592 DialtactsActivity.class);
593 return true;
594 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700595 ClearFrequentsDialog.show(getFragmentManager());
596 return true;
597 case R.id.menu_call_settings:
598 handleMenuSettings();
599 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700600 }
601 return false;
602 }
603
604 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700605 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
606 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
607 if (resultCode == RESULT_OK) {
608 final ArrayList<String> matches = data.getStringArrayListExtra(
609 RecognizerIntent.EXTRA_RESULTS);
610 if (matches.size() > 0) {
611 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700612 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700613 } else {
614 Log.e(TAG, "Voice search - nothing heard");
615 }
616 } else {
617 Log.e(TAG, "Voice search failed");
618 }
619 }
620 super.onActivityResult(requestCode, resultCode, data);
621 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700622
Andrew Lee2a58ab82014-05-15 02:16:04 -0700623 /**
624 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
625 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
626 * @see #onDialpadShown
627 */
Yorke Leec3766332013-07-31 11:13:16 -0700628 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700629 if (mIsDialpadShown) {
630 return;
631 }
632 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700633 mDialpadFragment.setAnimate(animate);
Sai Cheemalapati2d7faf62014-08-04 11:48:50 -0700634 mDialpadFragment.sendScreenView();
Andrew Leecdfa6c62014-05-06 15:33:35 -0700635
Chiao Cheng94b10b52012-08-17 16:59:12 -0700636 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700637 ft.show(mDialpadFragment);
638 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700639
Yorke Lee5253be02014-05-21 18:50:03 -0700640 mActionBarController.onDialpadUp();
641
Andrew Leeb1903842014-05-15 16:11:24 -0700642 if (!isInSearchUi()) {
643 enterSearchUi(true /* isSmartDial */, mSearchQuery);
644 }
Yorke Leec3766332013-07-31 11:13:16 -0700645 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700646
Andrew Lee2a58ab82014-05-15 02:16:04 -0700647 /**
648 * Callback from child DialpadFragment when the dialpad is shown.
649 */
650 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700651 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
652 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
653 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700654 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700655 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700656 } else {
657 mDialpadFragment.setYFraction(0);
658 }
659
Andrew Lee2a58ab82014-05-15 02:16:04 -0700660 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700661 }
662
663 /**
664 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
665 * a callback after the hide animation ends.
666 * @see #commitDialpadFragmentHide
667 */
Yorke Leeca195042013-09-25 16:29:38 -0700668 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700669 if (mDialpadFragment == null) {
670 return;
671 }
Yorke Leef6673d32013-08-23 15:34:17 -0700672 if (clearDialpad) {
673 mDialpadFragment.clearDialpad();
674 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700675 if (!mIsDialpadShown) {
676 return;
Yorke Leec3766332013-07-31 11:13:16 -0700677 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700678 mIsDialpadShown = false;
679 mDialpadFragment.setAnimate(animate);
680
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700681 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700682 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
683 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
684
685 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700686 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700687 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700688 } else {
689 commitDialpadFragmentHide();
690 }
691
Yorke Lee5253be02014-05-21 18:50:03 -0700692 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700693
Andrew Leed4cde832014-05-16 15:56:48 -0700694 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700695 if (TextUtils.isEmpty(mSearchQuery)) {
696 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700697 }
Andrew Leed4cde832014-05-16 15:56:48 -0700698 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700699 }
700
701 /**
702 * Finishes hiding the dialpad fragment after any animations are completed.
703 */
704 private void commitDialpadFragmentHide() {
705 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700706 ft.hide(mDialpadFragment);
707 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700708 }
709
Andrew Lee2a58ab82014-05-15 02:16:04 -0700710 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700711 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700712 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700713 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700714 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700715 fragment = mRegularSearchFragment;
716 }
717 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700718 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700719 }
720 }
721
Yorke Lee5253be02014-05-21 18:50:03 -0700722 @Override
723 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700724 return mInDialpadSearch || mInRegularSearch;
725 }
726
Yorke Lee5253be02014-05-21 18:50:03 -0700727 @Override
728 public boolean hasSearchQuery() {
729 return !TextUtils.isEmpty(mSearchQuery);
730 }
731
732 @Override
733 public boolean shouldShowActionBar() {
734 return mListsFragment.shouldShowActionBar();
735 }
736
Yorke Leeb207f8a2013-08-29 18:51:06 -0700737 private void setNotInSearchUi() {
738 mInDialpadSearch = false;
739 mInRegularSearch = false;
740 }
741
Yorke Lee311969c2013-08-26 06:31:11 -0700742 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700743 if (mIsDialpadShown) {
744 hideDialpadFragment(false, true);
745 } else {
746 exitSearchUi();
747 }
Yorke Lee311969c2013-08-26 06:31:11 -0700748 }
749
Yorke Lee53a22302014-04-29 18:13:46 -0700750 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700751 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
752 if (canIntentBeHandled(voiceIntent)) {
753 mVoiceSearchButton.setVisibility(View.VISIBLE);
754 mVoiceSearchButton.setOnClickListener(this);
755 } else {
756 mVoiceSearchButton.setVisibility(View.GONE);
757 }
758 }
759
Andrew Leee74a10e2014-05-16 14:31:40 -0700760 private OptionsPopupMenu buildOptionsMenu(View invoker) {
761 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
762 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700763 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700764 popupMenu.setOnMenuItemClickListener(this);
765 return popupMenu;
766 }
767
Yorke Lee86e21f72014-04-02 16:49:38 -0700768 @Override
769 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700770 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700771 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700772 mPendingSearchViewQuery = null;
773 }
Yorke Leea524ae52014-08-05 18:01:05 -0700774 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700775 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700776 }
777
Chiao Cheng94b10b52012-08-17 16:59:12 -0700778 /**
779 * Returns true if the intent is due to hitting the green send key (hardware call button:
780 * KEYCODE_CALL) while in a call.
781 *
782 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700783 * @return true if the intent is due to hitting the green send key while in a call
784 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700785 private boolean isSendKeyWhileInCall(Intent intent) {
786 // If there is a call in progress and the user launched the dialer by hitting the call
787 // button, go straight to the in-call screen.
788 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700789
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700790 if (callKey) {
Nancy Chen105015e2014-08-21 22:50:11 -0700791 getTelecommManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700792 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700793 }
794
795 return false;
796 }
797
798 /**
799 * Sets the current tab based on the intent's request type
800 *
801 * @param intent Intent that contains information about which tab should be selected
802 */
Yorke Leec3766332013-07-31 11:13:16 -0700803 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700804 // 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 -0700805 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700806 finish();
807 return;
808 }
809
Yorke Lee669b6082013-09-17 15:43:38 -0700810 if (mDialpadFragment != null) {
811 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700812 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700813 mDialpadFragment.setStartedFromNewIntent(true);
814 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
815 mInCallDialpadUp = true;
816 }
817 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700818 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700819 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700820 }
821
822 @Override
823 public void onNewIntent(Intent newIntent) {
824 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700825 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700826
Chiao Cheng94b10b52012-08-17 16:59:12 -0700827 invalidateOptionsMenu();
828 }
829
830 /** Returns true if the given intent contains a phone number to populate the dialer with */
831 private boolean isDialIntent(Intent intent) {
832 final String action = intent.getAction();
833 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
834 return true;
835 }
836 if (Intent.ACTION_VIEW.equals(action)) {
837 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700838 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700839 return true;
840 }
841 }
842 return false;
843 }
844
845 /**
846 * Returns an appropriate call origin for this Activity. May return null when no call origin
847 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
848 * for remembering the tab in which the user made a phone call, so the external app's DIAL
849 * request should not be counted.)
850 */
851 public String getCallOrigin() {
852 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
853 }
854
Chiao Cheng94b10b52012-08-17 16:59:12 -0700855 /**
Yorke Leec3766332013-07-31 11:13:16 -0700856 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700857 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700858 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700859 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700860 // Weird race condition where fragment is doing work after the activity is destroyed
861 // due to talkback being on (b/10209937). Just return since we can't do any
862 // constructive here.
863 return;
864 }
865
Yorke Leeef2b7382013-08-09 17:39:25 -0700866 if (DEBUG) {
867 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
868 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700869
Yorke Leec3766332013-07-31 11:13:16 -0700870 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700871 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700872 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700873 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700874 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700875 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700876
Yorke Leeb207f8a2013-08-29 18:51:06 -0700877 final String tag;
878 if (smartDialSearch) {
879 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
880 } else {
881 tag = TAG_REGULAR_SEARCH_FRAGMENT;
882 }
883 mInDialpadSearch = smartDialSearch;
884 mInRegularSearch = !smartDialSearch;
885
Andrew Lee752956e2014-05-15 11:43:38 -0700886 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700887 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700888 if (fragment == null) {
889 if (smartDialSearch) {
890 fragment = new SmartDialSearchFragment();
891 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700892 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700893 }
Andrew Leeb1903842014-05-15 16:11:24 -0700894 transaction.add(R.id.dialtacts_frame, fragment, tag);
895 } else {
896 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700897 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700898 // DialtactsActivity will provide the options menu
899 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700900 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700901 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700902 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700903
904 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700905 }
906
907 /**
Yorke Leec3766332013-07-31 11:13:16 -0700908 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700909 */
Yorke Leec3766332013-07-31 11:13:16 -0700910 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700911 // See related bug in enterSearchUI();
912 if (getFragmentManager().isDestroyed()) {
913 return;
914 }
Andrew Leeb1903842014-05-15 16:11:24 -0700915
Andrew Leeb1903842014-05-15 16:11:24 -0700916 mSearchView.setText(null);
917 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700918 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700919
Andrew Leeb1903842014-05-15 16:11:24 -0700920 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700921 if (mSmartDialSearchFragment != null) {
922 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700923 }
Andrew Leeb1903842014-05-15 16:11:24 -0700924 if (mRegularSearchFragment != null) {
925 transaction.remove(mRegularSearchFragment);
926 }
927 transaction.commit();
928
929 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700930 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700931 }
932
933 /** Returns an Intent to launch Call Settings screen */
934 public static Intent getCallSettingsIntent() {
Yorke Lee6eec2282014-07-18 12:40:27 -0700935 final Intent intent = new Intent(TelecommManager.ACTION_SHOW_CALL_SETTINGS);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700936 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
937 return intent;
938 }
939
940 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700941 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700942 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700943 if (TextUtils.isEmpty(mSearchQuery) ||
944 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
945 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700946 exitSearchUi();
947 }
Yorke Leef6673d32013-08-23 15:34:17 -0700948 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700949 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700950 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700951 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700952 } else {
953 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700954 }
Yorke Leec3766332013-07-31 11:13:16 -0700955 }
956
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700957 /**
958 * @return True if the search UI was exited, false otherwise
959 */
960 private boolean maybeExitSearchUi() {
961 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
962 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700963 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700964 return true;
965 }
966 return false;
967 }
968
Yorke Leec3766332013-07-31 11:13:16 -0700969 @Override
970 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700971 if (mSmartDialSearchFragment != null) {
972 mSmartDialSearchFragment.setAddToContactNumber(query);
973 }
Yorke Leec3766332013-07-31 11:13:16 -0700974 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
975 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700976
977 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700978 if (DEBUG) {
979 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
980 }
981 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
982 // This callback can happen if the dialpad fragment is recreated because of
983 // activity destruction. In that case, don't update the search view because
984 // that would bring the user back to the search fragment regardless of the
985 // previous state of the application. Instead, just return here and let the
986 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700987 if (!TextUtils.isEmpty(normalizedQuery)) {
988 mPendingSearchViewQuery = normalizedQuery;
989 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700990 return;
991 }
Yorke Lee53a22302014-04-29 18:13:46 -0700992 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700993 }
994 }
Yorke Leec3766332013-07-31 11:13:16 -0700995
996 @Override
997 public void onListFragmentScrollStateChange(int scrollState) {
998 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700999 hideDialpadFragment(true, false);
Yorke Leef543baa2014-07-24 11:31:13 -07001000 DialerUtils.hideInputMethod(getCurrentFocus());
Yorke Leec3766332013-07-31 11:13:16 -07001001 }
1002 }
1003
1004 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001005 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001006 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001007 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1008 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001009 }
1010
Yorke Lee86e21f72014-04-02 16:49:38 -07001011 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001012 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001013 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001014 }
1015
1016 private boolean phoneIsInUse() {
Nancy Chen105015e2014-08-21 22:50:11 -07001017 return getTelecommManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001018 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001019
Yorke Leee1424812013-09-04 18:24:48 -07001020 public static Intent getAddNumberToContactIntent(CharSequence text) {
1021 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1022 intent.putExtra(Intents.Insert.PHONE, text);
1023 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1024 return intent;
1025 }
1026
Yorke Leeda0f9042013-12-05 14:25:51 -08001027 private boolean canIntentBeHandled(Intent intent) {
1028 final PackageManager packageManager = getPackageManager();
1029 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1030 PackageManager.MATCH_DEFAULT_ONLY);
1031 return resolveInfo != null && resolveInfo.size() > 0;
1032 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001033
Yorke Lee6a1461a2014-04-21 16:27:14 -07001034 @Override
1035 public void showCallHistory() {
1036 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1037 // CONTENT_TYPE, so that we always open our call log from our dialer
1038 final Intent intent = new Intent(this, CallLogActivity.class);
1039 startActivity(intent);
1040 }
1041
Yorke Lee86e21f72014-04-02 16:49:38 -07001042 /**
1043 * Called when the user has long-pressed a contact tile to start a drag operation.
1044 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001045 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001046 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001047 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001048 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001049 }
Andrew Lee18963442014-06-06 17:20:13 -07001050 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001051 }
1052
1053 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001054 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1055 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001056
Yorke Lee86e21f72014-04-02 16:49:38 -07001057 /**
1058 * Called when the user has released a contact tile after long-pressing it.
1059 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001060 @Override
1061 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001062 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001063 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001064 }
Andrew Lee18963442014-06-06 17:20:13 -07001065 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001066 }
1067
1068 @Override
1069 public void onDroppedOnRemove() {}
1070
1071 /**
Yorke Leed999b712014-04-23 15:10:58 -07001072 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001073 * once it has been attached to the activity.
1074 */
1075 @Override
1076 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001077 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001078 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001079 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001080
1081 @Override
1082 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001083 // Specify call-origin so that users will see the previous tab instead of
1084 // CallLog screen (search UI will be automatically exited).
1085 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001086 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001087 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001088 }
1089
1090 @Override
1091 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001092 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1093 }
1094
1095 @Override
1096 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001097 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001098 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1099 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001100 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001101 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001102 }
1103
1104 @Override
1105 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001106 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001107 }
1108
1109 @Override
1110 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001111 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001112 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001113
Yorke Leecc4660d2014-04-24 11:22:57 -07001114 @Override
1115 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001116 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001117 // Only scroll the button when the first tab is selected. The button should scroll from
1118 // the middle to right position only on the transition from the first tab to the second
1119 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001120 // If the app is in RTL mode, we need to check against the second tab, rather than the
1121 // first. This is because if we are scrolling between the first and second tabs, the
1122 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1123 // reversal of the order of the tabs.
1124 final boolean isLayoutRtl = DialerUtils.isRtl();
1125 final boolean shouldScrollButton = position == (isLayoutRtl
1126 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1127 if (shouldScrollButton && !mIsLandscape) {
1128 mFloatingActionButtonController.onPageScrolled(
1129 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001130 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1131 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001132 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001133 }
1134
1135 @Override
1136 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001137 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001138 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001139 }
1140
1141 @Override
1142 public void onPageScrollStateChanged(int state) {
1143 }
1144
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001145 private TelephonyManager getTelephonyManager() {
1146 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1147 }
1148
Nancy Chen105015e2014-08-21 22:50:11 -07001149 private TelecommManager getTelecommManager() {
1150 return (TelecommManager) getSystemService(Context.TELECOMM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001151 }
1152
Yorke Lee5253be02014-05-21 18:50:03 -07001153 @Override
1154 public boolean isActionBarShowing() {
1155 return mActionBarController.isActionBarShowing();
1156 }
1157
Andrew Lee9da8fb42014-06-03 14:03:09 -07001158 public boolean isDialpadShown() {
1159 return mIsDialpadShown;
1160 }
1161
Yorke Lee5253be02014-05-21 18:50:03 -07001162 @Override
1163 public int getActionBarHideOffset() {
1164 return getActionBar().getHideOffset();
1165 }
1166
1167 @Override
1168 public int getActionBarHeight() {
1169 return mActionBarHeight;
1170 }
1171
1172 @Override
1173 public void setActionBarHideOffset(int hideOffset) {
Yorke Leea524ae52014-08-05 18:01:05 -07001174 mActionBarController.setHideOffset(hideOffset);
Yorke Lee5253be02014-05-21 18:50:03 -07001175 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001176
1177 /**
1178 * Updates controller based on currently known information.
1179 *
1180 * @param animate Whether or not to animate the transition.
1181 */
1182 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1183 int align;
1184 if (mIsDialpadShown) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001185 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_END
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001186 : FloatingActionButtonController.ALIGN_MIDDLE;
1187 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001188 if (!mIsLandscape) {
1189 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1190 ? FloatingActionButtonController.ALIGN_MIDDLE
Yorke Lee69c247f2014-07-22 11:49:49 -07001191 : FloatingActionButtonController.ALIGN_END;
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001192 } else {
Yorke Lee69c247f2014-07-22 11:49:49 -07001193 align = FloatingActionButtonController.ALIGN_END;
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001194 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001195 }
Andrew Leef43b32f2014-08-14 17:43:04 -07001196 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001197 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001198}