blob: bb03ed1377ef8b79444cd7eab6d3984622d92311 [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 Lee53a22302014-04-29 18:13:46 -070019import android.app.ActionBar;
Chiao Cheng94b10b52012-08-17 16:59:12 -070020import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070021import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080022import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.content.Context;
24import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080025import android.content.pm.PackageManager;
26import android.content.pm.ResolveInfo;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070027import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070028import android.content.res.Resources;
Chiao Cheng94b10b52012-08-17 16:59:12 -070029import android.net.Uri;
30import android.os.Bundle;
Yorke Leef5554ce2015-01-27 14:46:02 -080031import android.os.Trace;
Chiao Cheng94b10b52012-08-17 16:59:12 -070032import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070033import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070034import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070035import android.support.v4.view.ViewPager;
Tyler Gunn9dc924c2014-09-12 09:33:50 -070036import android.telecom.PhoneAccount;
37import android.telecom.TelecomManager;
Yorke Leec3766332013-07-31 11:13:16 -070038import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070039import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070040import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070041import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070043import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070044import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070045import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070046import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070047import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070048import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070049import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070050import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070051import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070052import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070053import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070054import android.view.animation.AnimationUtils;
Yorke Leec3766332013-07-31 11:13:16 -070055import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070056import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070057import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070058import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070059import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080060import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070061
Brian Attwellc311af12014-10-22 18:28:58 -070062import com.android.contacts.common.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070063import com.android.contacts.common.dialog.ClearFrequentsDialog;
64import com.android.contacts.common.interactions.ImportExportDialogFragment;
Nancy Chen0d3a7392014-08-12 14:44:53 -070065import com.android.contacts.common.interactions.TouchPointManager;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080066import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070067import com.android.contacts.common.widget.FloatingActionButtonController;
Brian Attwellbeab3bb2014-10-27 12:24:49 -070068import com.android.contacts.commonbind.analytics.AnalyticsUtil;
Yorke Leec3766332013-07-31 11:13:16 -070069import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070070import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070071import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070072import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070073import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070074import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080075import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070076import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080077import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070078import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070079import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070080import com.android.dialer.list.RegularSearchFragment;
81import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070082import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070083import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070084import com.android.dialer.settings.DialerSettingsActivity;
Yorke Leeb82e8da2015-04-18 14:37:50 -070085import com.android.dialer.util.CallIntentUtil;
Yorke Lee7d20f822014-06-19 17:09:33 -070086import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070087import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070088import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070089import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070090import com.android.dialerbind.DatabaseHelperManager;
Yorke Lee2fec47b2014-08-05 18:16:27 -070091import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070092import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070093
Yorke Leed5c512a2015-01-30 14:42:53 -080094import junit.framework.Assert;
95
Yorke Leec3766332013-07-31 11:13:16 -070096import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080097import java.util.List;
Yorke Leec3766332013-07-31 11:13:16 -070098
Chiao Cheng94b10b52012-08-17 16:59:12 -070099/**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700100 * The dialer tab's title is 'phone', a more common name (see strings.xml).
101 */
Yorke Leec3766332013-07-31 11:13:16 -0700102public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700103 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700104 OnListFragmentScrolledListener,
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 Leef614f6f2014-10-03 10:44:19 -0700141 private FrameLayout mParentLayout;
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 */
Evan Charlton72d66252014-11-07 16:23:47 -0800146 protected 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
Yorke Lee6c450eb2015-05-08 09:45:47 -0700168 AnimationListenerAdapter mSlideInListener = new AnimationListenerAdapter() {
169 @Override
170 public void onAnimationEnd(Animation animation) {
171 if (!isInSearchUi()) {
172 enterSearchUi(true /* isSmartDial */, mSearchQuery, false);
173 }
174 }
175 };
176
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700177 /**
178 * Listener for after slide out animation completes on dialer fragment.
179 */
180 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
181 @Override
182 public void onAnimationEnd(Animation animation) {
183 commitDialpadFragmentHide();
184 }
185 };
186
187 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700188 * Fragment containing the speed dial list, recents list, and all contacts list.
189 */
190 private ListsFragment mListsFragment;
191
Yorke Lee19e68ca2014-10-28 11:51:40 -0700192 /**
193 * Tracks whether onSaveInstanceState has been called. If true, no fragment transactions can
194 * be commited.
195 */
196 private boolean mStateSaved;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800197 private boolean mIsRestarting;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700198 private boolean mInDialpadSearch;
199 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700200 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700201 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700202 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700203
Yorke Leeef2b7382013-08-09 17:39:25 -0700204 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700205 * Whether or not the device is in landscape orientation.
206 */
207 private boolean mIsLandscape;
208
209 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700210 * The position of the currently selected tab in the attached {@link ListsFragment}.
211 */
212 private int mCurrentTabPosition = 0;
213
214 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700215 * True if the dialpad is only temporarily showing due to being in call
216 */
217 private boolean mInCallDialpadUp;
218
219 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700220 * True when this activity has been launched for the first time.
221 */
Yorke Lee98702de2013-08-06 12:03:32 -0700222 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700223
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700224 /**
225 * Search query to be applied to the SearchView in the ActionBar once
226 * onCreateOptionsMenu has been called.
227 */
228 private String mPendingSearchViewQuery;
229
Yorke Lee74edcdc2014-07-11 16:15:08 -0700230 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700231 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700232 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700233
Yorke Leeef2b7382013-08-09 17:39:25 -0700234 private String mSearchQuery;
235
Yorke Leefce269a2013-08-12 11:56:04 -0700236 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700237 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700238 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700239
Sai Cheemalapati41460652014-06-02 21:05:39 -0700240 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700241
Andrew Lee2423a2f2014-05-29 14:14:45 -0700242 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700243
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800244 /**
245 * The text returned from a voice search query. Set in {@link #onActivityResult} and used in
246 * {@link #onResume()} to populate the search box.
247 */
248 private String mVoiceSearchQuery;
249
Andrew Lee467de3d2015-03-17 15:47:24 -0700250 protected class OptionsPopupMenu extends PopupMenu {
Andrew Leee74a10e2014-05-16 14:31:40 -0700251 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700252 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700253 }
254
255 @Override
256 public void show() {
257 final Menu menu = getMenu();
258 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700259 clearFrequents.setVisible(mListsFragment != null &&
260 mListsFragment.getSpeedDialFragment() != null &&
261 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700262 super.show();
263 }
264 }
265
Chiao Cheng94b10b52012-08-17 16:59:12 -0700266 /**
Yorke Lee28266192014-05-01 10:05:52 -0700267 * Listener that listens to drag events and sends their x and y coordinates to a
268 * {@link DragDropController}.
269 */
270 private class LayoutOnDragListener implements OnDragListener {
271 @Override
272 public boolean onDrag(View v, DragEvent event) {
273 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700274 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700275 }
276 return true;
277 }
278 }
279
280 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700281 * Listener used to send search queries to the phone search fragment.
282 */
Yorke Lee53a22302014-04-29 18:13:46 -0700283 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700284 @Override
285 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
286 }
Yorke Leec3766332013-07-31 11:13:16 -0700287
Andrew Lee99a570c2014-05-15 14:18:50 -0700288 @Override
289 public void onTextChanged(CharSequence s, int start, int before, int count) {
290 final String newText = s.toString();
291 if (newText.equals(mSearchQuery)) {
292 // If the query hasn't changed (perhaps due to activity being destroyed
293 // and restored, or user launching the same DIAL intent twice), then there is
294 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700295 return;
296 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700297 if (DEBUG) {
298 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700299 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700300 }
Yorke Lee710709d2014-05-29 07:18:42 -0700301 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700302
Andrew Lee90374a72014-05-16 15:01:09 -0700303 // Show search fragment only when the query string is changed to non-empty text.
304 if (!TextUtils.isEmpty(newText)) {
305 // Call enterSearchUi only if we are switching search modes, or showing a search
306 // fragment for the first time.
307 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
308 (!mIsDialpadShown && mInRegularSearch);
309 if (!sameSearchMode) {
Yorke Lee6c450eb2015-05-08 09:45:47 -0700310 enterSearchUi(mIsDialpadShown, mSearchQuery, true /* animate */);
Andrew Lee90374a72014-05-16 15:01:09 -0700311 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700312 }
313
Andrew Leea8515422014-06-13 16:53:54 -0700314 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700315 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700316 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700317 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700318 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700319 }
320
321 @Override
322 public void afterTextChanged(Editable s) {
323 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700324 };
325
Andrew Leeb1903842014-05-15 16:11:24 -0700326
327 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700328 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700329 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700330 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700331 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700332 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700333 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700334 mActionBarController.onSearchBoxTapped();
Yorke Lee6c450eb2015-05-08 09:45:47 -0700335 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString(),
336 true /* animate */);
Andrew Leeb1903842014-05-15 16:11:24 -0700337 }
Andrew Leeb1903842014-05-15 16:11:24 -0700338 }
339 };
340
341 /**
342 * If the search term is empty and the user closes the soft keyboard, close the search UI.
343 */
344 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
345 @Override
346 public boolean onKey(View v, int keyCode, KeyEvent event) {
347 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
348 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700349 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700350 }
351 return false;
352 }
353 };
354
Chiao Cheng94b10b52012-08-17 16:59:12 -0700355 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700356 public boolean dispatchTouchEvent(MotionEvent ev) {
357 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
358 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
359 }
360 return super.dispatchTouchEvent(ev);
361
362 }
363
364 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700365 protected void onCreate(Bundle savedInstanceState) {
Yorke Leef5554ce2015-01-27 14:46:02 -0800366 Trace.beginSection(TAG + " onCreate");
Yorke Leec3766332013-07-31 11:13:16 -0700367 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700368 mFirstLaunch = true;
369
Andrew Lee2423a2f2014-05-29 14:14:45 -0700370 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700371 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700372
Yorke Leef5554ce2015-01-27 14:46:02 -0800373 Trace.beginSection(TAG + " setContentView");
Yorke Lee8898cd02013-08-08 10:24:27 -0700374 setContentView(R.layout.dialtacts_activity);
Yorke Leef5554ce2015-01-27 14:46:02 -0800375 Trace.endSection();
Yorke Lee9e91bb02014-03-05 17:50:50 -0800376 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700377
Yorke Leef5554ce2015-01-27 14:46:02 -0800378 Trace.beginSection(TAG + " setup Views");
Yorke Lee53a22302014-04-29 18:13:46 -0700379 final ActionBar actionBar = getActionBar();
380 actionBar.setCustomView(R.layout.search_edittext);
381 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700382 actionBar.setBackgroundDrawable(null);
Yorke Lee53a22302014-04-29 18:13:46 -0700383
Andrew Lee04675a52014-06-05 18:36:20 -0700384 SearchEditTextLayout searchEditTextLayout =
Andrew Leee3f59a82015-02-26 12:06:35 -0800385 (SearchEditTextLayout) actionBar.getCustomView().findViewById(R.id.search_view_container);
Andrew Lee04675a52014-06-05 18:36:20 -0700386 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
387
Andrew Leee3f59a82015-02-26 12:06:35 -0800388 mActionBarController = new ActionBarController(this, searchEditTextLayout);
389
Andrew Lee04675a52014-06-05 18:36:20 -0700390 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700391 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700392 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
393 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
394 .setOnClickListener(mSearchViewOnClickListener);
395 searchEditTextLayout.findViewById(R.id.search_box_start_search)
396 .setOnClickListener(mSearchViewOnClickListener);
397 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700398 @Override
399 public void onBackButtonClicked() {
400 onBackPressed();
401 }
402 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700403
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700404 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700405 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700406
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700407 final View floatingActionButtonContainer = findViewById(
408 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700409 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
410 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700411 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700412 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700413
Andrew Lee04675a52014-06-05 18:36:20 -0700414 ImageButton optionsMenuButton =
415 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700416 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700417 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
418 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700419
Yorke Leed5c512a2015-01-30 14:42:53 -0800420 // Add the favorites fragment but only if savedInstanceState is null. Otherwise the
421 // fragment manager is responsible for recreating it.
Yorke Leec3766332013-07-31 11:13:16 -0700422 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800423 getFragmentManager().beginTransaction()
Andrew Lee6a866242015-05-05 18:21:45 +0000424 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800425 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700426 } else {
427 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700428 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
429 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700430 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700431 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700432 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700433 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700434
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700435 final boolean isLayoutRtl = DialerUtils.isRtl();
436 if (mIsLandscape) {
437 mSlideIn = AnimationUtils.loadAnimation(this,
438 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
439 mSlideOut = AnimationUtils.loadAnimation(this,
440 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
441 } else {
442 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
443 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
444 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700445
Yorke Lee2fec47b2014-08-05 18:16:27 -0700446 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
447 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
448
Yorke Lee6c450eb2015-05-08 09:45:47 -0700449 mSlideIn.setAnimationListener(mSlideInListener);
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700450 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700451
Yorke Leef614f6f2014-10-03 10:44:19 -0700452 mParentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
453 mParentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700454 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700455 new ViewTreeObserver.OnGlobalLayoutListener() {
456 @Override
457 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700458 final ViewTreeObserver observer =
459 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700460 if (!observer.isAlive()) {
461 return;
462 }
463 observer.removeOnGlobalLayoutListener(this);
Yorke Leef614f6f2014-10-03 10:44:19 -0700464 int screenWidth = mParentLayout.getWidth();
Sai Cheemalapati41460652014-06-02 21:05:39 -0700465 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700466 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700467 }
468 });
Andrew Lee0c667702014-05-12 14:31:45 -0700469
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700470 setupActivityOverlay();
471
Yorke Leef5554ce2015-01-27 14:46:02 -0800472 Trace.endSection();
473
474 Trace.beginSection(TAG + " initialize smart dialing");
Yorke Lee0baa98b2013-08-22 10:55:16 -0700475 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700476 SmartDialPrefix.initializeNanpSettings(this);
Yorke Leef5554ce2015-01-27 14:46:02 -0800477 Trace.endSection();
478 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700479 }
480
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700481 private void setupActivityOverlay() {
482 final View activityOverlay = findViewById(R.id.activity_overlay);
483 activityOverlay.setOnTouchListener(new OnTouchListener() {
484 @Override
485 public boolean onTouch(View v, MotionEvent event) {
486 if (!mIsDialpadShown) {
487 maybeExitSearchUi();
488 }
489 return false;
490 }
491 });
492 }
493
Chiao Cheng94b10b52012-08-17 16:59:12 -0700494 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700495 protected void onResume() {
Yorke Leef5554ce2015-01-27 14:46:02 -0800496 Trace.beginSection(TAG + " onResume");
Yorke Leec3766332013-07-31 11:13:16 -0700497 super.onResume();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700498 mStateSaved = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700499 if (mFirstLaunch) {
500 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700501 } else if (!phoneIsInUse() && mInCallDialpadUp) {
502 hideDialpadFragment(false, true);
503 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700504 } else if (mShowDialpadOnResume) {
505 showDialpadFragment(false);
506 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700507 }
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800508
509 // If there was a voice query result returned in the {@link #onActivityResult} callback, it
510 // will have been stashed in mVoiceSearchQuery since the search results fragment cannot be
511 // shown until onResume has completed. Active the search UI and set the search term now.
512 if (!TextUtils.isEmpty(mVoiceSearchQuery)) {
513 mActionBarController.onSearchBoxTapped();
514 mSearchView.setText(mVoiceSearchQuery);
515 mVoiceSearchQuery = null;
516 }
517
Yorke Lee98702de2013-08-06 12:03:32 -0700518 mFirstLaunch = false;
Yorke Lee7ee5c422014-11-04 10:29:32 -0800519
520 if (mIsRestarting) {
521 // This is only called when the activity goes from resumed -> paused -> resumed, so it
522 // will not cause an extra view to be sent out on rotation
523 if (mIsDialpadShown) {
524 AnalyticsUtil.sendScreenView(mDialpadFragment, this);
525 }
526 mIsRestarting = false;
527 }
Yorke Lee53a22302014-04-29 18:13:46 -0700528 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700529 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700530 updateFloatingActionButtonControllerAlignment(false /* animate */);
Yorke Leef5554ce2015-01-27 14:46:02 -0800531 Trace.endSection();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700532 }
533
534 @Override
Yorke Lee7ee5c422014-11-04 10:29:32 -0800535 protected void onRestart() {
536 super.onRestart();
537 mIsRestarting = true;
538 }
539
540 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700541 protected void onPause() {
542 if (mClearSearchOnPause) {
543 hideDialpadAndSearchUi();
544 mClearSearchOnPause = false;
545 }
Yorke Lee19e68ca2014-10-28 11:51:40 -0700546 if (mSlideOut.hasStarted() && !mSlideOut.hasEnded()) {
547 commitDialpadFragmentHide();
548 }
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700549 super.onPause();
550 }
551
552 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700553 protected void onSaveInstanceState(Bundle outState) {
554 super.onSaveInstanceState(outState);
555 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700556 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
557 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700558 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700559 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700560 mActionBarController.saveInstanceState(outState);
Yorke Lee19e68ca2014-10-28 11:51:40 -0700561 mStateSaved = true;
Yorke Leeef2b7382013-08-09 17:39:25 -0700562 }
563
564 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700565 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700566 if (fragment instanceof DialpadFragment) {
567 mDialpadFragment = (DialpadFragment) fragment;
Yorke Leed5c512a2015-01-30 14:42:53 -0800568 if (!mIsDialpadShown && !mShowDialpadOnResume) {
Yorke Lee50aba882014-05-28 20:04:31 -0700569 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
570 transaction.hide(mDialpadFragment);
571 transaction.commit();
572 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700573 } else if (fragment instanceof SmartDialSearchFragment) {
574 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700575 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700576 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700577 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700578 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700579 } else if (fragment instanceof ListsFragment) {
580 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700581 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700582 }
Yorke Leec3766332013-07-31 11:13:16 -0700583 }
584
Alon Albertb453e5b2013-09-10 15:54:23 -0700585 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700586 final Intent intent = new Intent(this, DialerSettingsActivity.class);
587 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700588 }
589
Chiao Cheng94b10b52012-08-17 16:59:12 -0700590 @Override
591 public void onClick(View view) {
592 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700593 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700594 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700595 mInCallDialpadUp = false;
596 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700597 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700598 break;
Yorke Leec3766332013-07-31 11:13:16 -0700599 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800600 try {
601 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
602 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
603 } catch (ActivityNotFoundException e) {
604 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
605 Toast.LENGTH_SHORT).show();
606 }
Yorke Leec3766332013-07-31 11:13:16 -0700607 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700608 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700609 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700610 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700611 default: {
612 Log.wtf(TAG, "Unexpected onClick event from " + view);
613 break;
614 }
615 }
616 }
617
Yorke Leec3766332013-07-31 11:13:16 -0700618 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700619 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700620 switch (item.getItemId()) {
621 case R.id.menu_history:
Andrew Lee69705be2015-05-04 17:24:01 -0700622 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
623 // CONTENT_TYPE, so that we always open our call log from our dialer
624 final Intent intent = new Intent(this, CallLogActivity.class);
625 startActivity(intent);
Yorke Lee86e21f72014-04-02 16:49:38 -0700626 break;
627 case R.id.menu_add_contact:
628 try {
629 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
630 } catch (ActivityNotFoundException e) {
631 Toast toast = Toast.makeText(this,
632 R.string.add_contact_not_available,
633 Toast.LENGTH_SHORT);
634 toast.show();
635 }
636 break;
637 case R.id.menu_import_export:
638 // We hard-code the "contactsAreAvailable" argument because doing it properly would
639 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
640 // now in Dialtacts for (potential) performance reasons. Compare with how it is
641 // done in {@link PeopleActivity}.
642 ImportExportDialogFragment.show(getFragmentManager(), true,
643 DialtactsActivity.class);
644 return true;
645 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700646 ClearFrequentsDialog.show(getFragmentManager());
647 return true;
648 case R.id.menu_call_settings:
649 handleMenuSettings();
650 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700651 }
652 return false;
653 }
654
655 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700656 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
657 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
658 if (resultCode == RESULT_OK) {
659 final ArrayList<String> matches = data.getStringArrayListExtra(
660 RecognizerIntent.EXTRA_RESULTS);
661 if (matches.size() > 0) {
662 final String match = matches.get(0);
Tyler Gunnc1cfae52014-11-20 13:22:54 -0800663 mVoiceSearchQuery = match;
Yorke Leec3766332013-07-31 11:13:16 -0700664 } else {
665 Log.e(TAG, "Voice search - nothing heard");
666 }
667 } else {
668 Log.e(TAG, "Voice search failed");
669 }
670 }
671 super.onActivityResult(requestCode, resultCode, data);
672 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700673
Andrew Lee2a58ab82014-05-15 02:16:04 -0700674 /**
675 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
676 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
677 * @see #onDialpadShown
678 */
Yorke Leec3766332013-07-31 11:13:16 -0700679 private void showDialpadFragment(boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700680 if (mIsDialpadShown || mStateSaved) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700681 return;
682 }
683 mIsDialpadShown = true;
Yorke Leed5c512a2015-01-30 14:42:53 -0800684
Yorke Lee7ee5c422014-11-04 10:29:32 -0800685 mListsFragment.setUserVisibleHint(false);
Andrew Leecdfa6c62014-05-06 15:33:35 -0700686
Chiao Cheng94b10b52012-08-17 16:59:12 -0700687 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leed5c512a2015-01-30 14:42:53 -0800688 if (mDialpadFragment == null) {
689 mDialpadFragment = new DialpadFragment();
690 ft.add(R.id.dialtacts_container, mDialpadFragment, TAG_DIALPAD_FRAGMENT);
691 } else {
692 ft.show(mDialpadFragment);
693 }
694
695 mDialpadFragment.setAnimate(animate);
696 AnalyticsUtil.sendScreenView(mDialpadFragment);
Yorke Leec3766332013-07-31 11:13:16 -0700697 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700698
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700699 if (animate) {
700 mFloatingActionButtonController.scaleOut();
701 } else {
702 mFloatingActionButtonController.setVisible(false);
703 }
Yorke Lee5253be02014-05-21 18:50:03 -0700704 mActionBarController.onDialpadUp();
705
Yorke Lee6c450eb2015-05-08 09:45:47 -0700706 mListsFragment.getView().animate().alpha(0).withLayer();
Yorke Leec3766332013-07-31 11:13:16 -0700707 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700708
Andrew Lee2a58ab82014-05-15 02:16:04 -0700709 /**
710 * Callback from child DialpadFragment when the dialpad is shown.
711 */
712 public void onDialpadShown() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800713 Assert.assertNotNull(mDialpadFragment);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700714 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700715 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700716 } else {
717 mDialpadFragment.setYFraction(0);
718 }
719
Andrew Lee2a58ab82014-05-15 02:16:04 -0700720 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700721 }
722
723 /**
724 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
725 * a callback after the hide animation ends.
726 * @see #commitDialpadFragmentHide
727 */
Yorke Leeca195042013-09-25 16:29:38 -0700728 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700729 if (mDialpadFragment == null) {
730 return;
731 }
Yorke Leef6673d32013-08-23 15:34:17 -0700732 if (clearDialpad) {
733 mDialpadFragment.clearDialpad();
734 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700735 if (!mIsDialpadShown) {
736 return;
Yorke Leec3766332013-07-31 11:13:16 -0700737 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700738 mIsDialpadShown = false;
739 mDialpadFragment.setAnimate(animate);
Yorke Lee7ee5c422014-11-04 10:29:32 -0800740 mListsFragment.setUserVisibleHint(true);
741 mListsFragment.sendScreenViewForCurrentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700742
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700743 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700744
745 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700746 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700747 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700748 } else {
749 commitDialpadFragmentHide();
750 }
751
Yorke Lee5253be02014-05-21 18:50:03 -0700752 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700753
Andrew Leed4cde832014-05-16 15:56:48 -0700754 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700755 if (TextUtils.isEmpty(mSearchQuery)) {
756 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700757 }
Andrew Leed4cde832014-05-16 15:56:48 -0700758 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700759 }
760
761 /**
762 * Finishes hiding the dialpad fragment after any animations are completed.
763 */
764 private void commitDialpadFragmentHide() {
Yorke Leed5c512a2015-01-30 14:42:53 -0800765 if (!mStateSaved && mDialpadFragment != null && !mDialpadFragment.isHidden()) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700766 final FragmentTransaction ft = getFragmentManager().beginTransaction();
767 ft.hide(mDialpadFragment);
768 ft.commit();
769 }
Andrew Lee405a6e62014-08-20 15:02:16 -0700770 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700771 }
772
Andrew Lee2a58ab82014-05-15 02:16:04 -0700773 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700774 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700775 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700776 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700777 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700778 fragment = mRegularSearchFragment;
779 }
780 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700781 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700782 }
783 }
784
Yorke Lee5253be02014-05-21 18:50:03 -0700785 @Override
786 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700787 return mInDialpadSearch || mInRegularSearch;
788 }
789
Yorke Lee5253be02014-05-21 18:50:03 -0700790 @Override
791 public boolean hasSearchQuery() {
792 return !TextUtils.isEmpty(mSearchQuery);
793 }
794
795 @Override
796 public boolean shouldShowActionBar() {
797 return mListsFragment.shouldShowActionBar();
798 }
799
Yorke Leeb207f8a2013-08-29 18:51:06 -0700800 private void setNotInSearchUi() {
801 mInDialpadSearch = false;
802 mInRegularSearch = false;
803 }
804
Yorke Lee311969c2013-08-26 06:31:11 -0700805 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700806 if (mIsDialpadShown) {
807 hideDialpadFragment(false, true);
808 } else {
809 exitSearchUi();
810 }
Yorke Lee311969c2013-08-26 06:31:11 -0700811 }
812
Yorke Lee53a22302014-04-29 18:13:46 -0700813 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700814 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
815 if (canIntentBeHandled(voiceIntent)) {
816 mVoiceSearchButton.setVisibility(View.VISIBLE);
817 mVoiceSearchButton.setOnClickListener(this);
818 } else {
819 mVoiceSearchButton.setVisibility(View.GONE);
820 }
821 }
822
Andrew Lee467de3d2015-03-17 15:47:24 -0700823 protected OptionsPopupMenu buildOptionsMenu(View invoker) {
Andrew Leee74a10e2014-05-16 14:31:40 -0700824 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
825 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700826 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700827 popupMenu.setOnMenuItemClickListener(this);
828 return popupMenu;
829 }
830
Yorke Lee86e21f72014-04-02 16:49:38 -0700831 @Override
832 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700833 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700834 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700835 mPendingSearchViewQuery = null;
836 }
Yorke Leea524ae52014-08-05 18:01:05 -0700837 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700838 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700839 }
840
Chiao Cheng94b10b52012-08-17 16:59:12 -0700841 /**
842 * Returns true if the intent is due to hitting the green send key (hardware call button:
843 * KEYCODE_CALL) while in a call.
844 *
845 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700846 * @return true if the intent is due to hitting the green send key while in a call
847 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700848 private boolean isSendKeyWhileInCall(Intent intent) {
849 // If there is a call in progress and the user launched the dialer by hitting the call
850 // button, go straight to the in-call screen.
851 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700852
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700853 if (callKey) {
Tyler Gunn9dc924c2014-09-12 09:33:50 -0700854 getTelecomManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700855 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700856 }
857
858 return false;
859 }
860
861 /**
862 * Sets the current tab based on the intent's request type
863 *
864 * @param intent Intent that contains information about which tab should be selected
865 */
Yorke Leec3766332013-07-31 11:13:16 -0700866 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700867 // 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 -0700868 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700869 finish();
870 return;
871 }
872
Yorke Leed5c512a2015-01-30 14:42:53 -0800873 final boolean phoneIsInUse = phoneIsInUse();
874 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
875 showDialpadFragment(false);
876 mDialpadFragment.setStartedFromNewIntent(true);
877 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
878 mInCallDialpadUp = true;
Yorke Lee35127cd2013-09-10 14:09:29 -0700879 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700880 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700881 }
882
883 @Override
884 public void onNewIntent(Intent newIntent) {
885 setIntent(newIntent);
Nancy Chen199b7f02014-11-05 15:03:00 -0800886 mStateSaved = false;
Yorke Leec3766332013-07-31 11:13:16 -0700887 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700888
Chiao Cheng94b10b52012-08-17 16:59:12 -0700889 invalidateOptionsMenu();
890 }
891
892 /** Returns true if the given intent contains a phone number to populate the dialer with */
893 private boolean isDialIntent(Intent intent) {
894 final String action = intent.getAction();
895 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
896 return true;
897 }
898 if (Intent.ACTION_VIEW.equals(action)) {
899 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700900 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700901 return true;
902 }
903 }
904 return false;
905 }
906
907 /**
908 * Returns an appropriate call origin for this Activity. May return null when no call origin
909 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
910 * for remembering the tab in which the user made a phone call, so the external app's DIAL
911 * request should not be counted.)
912 */
913 public String getCallOrigin() {
914 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
915 }
916
Chiao Cheng94b10b52012-08-17 16:59:12 -0700917 /**
Yorke Leec3766332013-07-31 11:13:16 -0700918 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700919 */
Yorke Lee6c450eb2015-05-08 09:45:47 -0700920 private void enterSearchUi(boolean smartDialSearch, String query, boolean animate) {
Yorke Lee19e68ca2014-10-28 11:51:40 -0700921 if (mStateSaved || getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700922 // Weird race condition where fragment is doing work after the activity is destroyed
923 // due to talkback being on (b/10209937). Just return since we can't do any
924 // constructive here.
925 return;
926 }
927
Yorke Leeef2b7382013-08-09 17:39:25 -0700928 if (DEBUG) {
929 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
930 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700931
Yorke Leec3766332013-07-31 11:13:16 -0700932 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700933 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700934 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700935 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700936 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700937 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700938
Yorke Leeb207f8a2013-08-29 18:51:06 -0700939 final String tag;
940 if (smartDialSearch) {
941 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
942 } else {
943 tag = TAG_REGULAR_SEARCH_FRAGMENT;
944 }
945 mInDialpadSearch = smartDialSearch;
946 mInRegularSearch = !smartDialSearch;
947
Andrew Lee752956e2014-05-15 11:43:38 -0700948 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Yorke Lee6c450eb2015-05-08 09:45:47 -0700949 if (animate) {
950 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
951 } else {
952 transaction.setTransition(FragmentTransaction.TRANSIT_NONE);
953 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700954 if (fragment == null) {
955 if (smartDialSearch) {
956 fragment = new SmartDialSearchFragment();
957 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700958 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700959 }
Andrew Leeb1903842014-05-15 16:11:24 -0700960 transaction.add(R.id.dialtacts_frame, fragment, tag);
961 } else {
962 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700963 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700964 // DialtactsActivity will provide the options menu
965 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700966 fragment.setShowEmptyListForNullQuery(true);
Yorke Lee6c450eb2015-05-08 09:45:47 -0700967 if (!smartDialSearch) {
968 fragment.setQueryString(query, false /* delaySelection */);
969 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700970 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700971
Yorke Lee6c450eb2015-05-08 09:45:47 -0700972 if (animate) {
973 mListsFragment.getView().animate().alpha(0).withLayer();
974 }
Yorke Lee7ee5c422014-11-04 10:29:32 -0800975 mListsFragment.setUserVisibleHint(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700976 }
977
978 /**
Yorke Leec3766332013-07-31 11:13:16 -0700979 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700980 */
Yorke Leec3766332013-07-31 11:13:16 -0700981 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700982 // See related bug in enterSearchUI();
Yorke Lee19e68ca2014-10-28 11:51:40 -0700983 if (getFragmentManager().isDestroyed() || mStateSaved) {
Yorke Lee3487db72013-09-26 17:12:06 -0700984 return;
985 }
Andrew Leeb1903842014-05-15 16:11:24 -0700986
Andrew Leeb1903842014-05-15 16:11:24 -0700987 mSearchView.setText(null);
Yorke Leed5c512a2015-01-30 14:42:53 -0800988
989 if (mDialpadFragment != null) {
990 mDialpadFragment.clearDialpad();
991 }
992
Yorke Leeb207f8a2013-08-29 18:51:06 -0700993 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700994
Andrew Leeb1903842014-05-15 16:11:24 -0700995 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700996 if (mSmartDialSearchFragment != null) {
997 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700998 }
Andrew Leeb1903842014-05-15 16:11:24 -0700999 if (mRegularSearchFragment != null) {
1000 transaction.remove(mRegularSearchFragment);
1001 }
1002 transaction.commit();
1003
1004 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Leed5c512a2015-01-30 14:42:53 -08001005
1006 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
Yorke Lee7ee5c422014-11-04 10:29:32 -08001007 // If the dialpad fragment wasn't previously visible, then send a screen view because
1008 // we are exiting regular search. Otherwise, the screen view will be sent by
1009 // {@link #hideDialpadFragment}.
1010 mListsFragment.sendScreenViewForCurrentPosition();
1011 mListsFragment.setUserVisibleHint(true);
1012 }
1013
Yorke Lee5253be02014-05-21 18:50:03 -07001014 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001015 }
1016
Chiao Cheng94b10b52012-08-17 16:59:12 -07001017 @Override
Yorke Leec3766332013-07-31 11:13:16 -07001018 public void onBackPressed() {
Yorke Lee19e68ca2014-10-28 11:51:40 -07001019 if (mStateSaved) {
1020 return;
1021 }
Andrew Lee2a58ab82014-05-15 02:16:04 -07001022 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -07001023 if (TextUtils.isEmpty(mSearchQuery) ||
1024 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
1025 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -07001026 exitSearchUi();
1027 }
Yorke Leef6673d32013-08-23 15:34:17 -07001028 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -07001029 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -07001030 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001031 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001032 } else {
1033 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -07001034 }
Yorke Leec3766332013-07-31 11:13:16 -07001035 }
1036
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001037 /**
1038 * @return True if the search UI was exited, false otherwise
1039 */
1040 private boolean maybeExitSearchUi() {
1041 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
1042 exitSearchUi();
Yorke Leef614f6f2014-10-03 10:44:19 -07001043 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -07001044 return true;
1045 }
1046 return false;
1047 }
1048
Yorke Leec3766332013-07-31 11:13:16 -07001049 @Override
1050 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -07001051 if (mSmartDialSearchFragment != null) {
1052 mSmartDialSearchFragment.setAddToContactNumber(query);
1053 }
Yorke Leec3766332013-07-31 11:13:16 -07001054 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
1055 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -07001056
1057 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -07001058 if (DEBUG) {
1059 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
1060 }
1061 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
1062 // This callback can happen if the dialpad fragment is recreated because of
1063 // activity destruction. In that case, don't update the search view because
1064 // that would bring the user back to the search fragment regardless of the
1065 // previous state of the application. Instead, just return here and let the
1066 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -07001067 if (!TextUtils.isEmpty(normalizedQuery)) {
1068 mPendingSearchViewQuery = normalizedQuery;
1069 }
Yorke Leeef2b7382013-08-09 17:39:25 -07001070 return;
1071 }
Yorke Lee53a22302014-04-29 18:13:46 -07001072 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -07001073 }
1074 }
Yorke Leec3766332013-07-31 11:13:16 -07001075
1076 @Override
1077 public void onListFragmentScrollStateChange(int scrollState) {
1078 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001079 hideDialpadFragment(true, false);
Yorke Leef614f6f2014-10-03 10:44:19 -07001080 DialerUtils.hideInputMethod(mParentLayout);
Yorke Leec3766332013-07-31 11:13:16 -07001081 }
1082 }
1083
1084 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001085 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001086 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001087 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1088 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001089 }
1090
Yorke Leec3766332013-07-31 11:13:16 -07001091 private boolean phoneIsInUse() {
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001092 return getTelecomManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001093 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001094
Yorke Leee1424812013-09-04 18:24:48 -07001095 public static Intent getAddNumberToContactIntent(CharSequence text) {
Tyler Gunn1513fec2014-12-05 14:19:00 -08001096 return getAddToContactIntent(null /* name */, text /* phoneNumber */,
1097 -1 /* phoneNumberType */);
1098 }
1099
1100 public static Intent getAddToContactIntent(CharSequence name, CharSequence phoneNumber,
1101 int phoneNumberType) {
1102 Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1103 intent.putExtra(Intents.Insert.PHONE, phoneNumber);
1104 // Only include the name and phone type extras if they are specified (the method
1105 // getAddNumberToContactIntent does not use them).
1106 if (name != null) {
1107 intent.putExtra(Intents.Insert.NAME, name);
1108 }
1109 if (phoneNumberType != -1) {
1110 intent.putExtra(Intents.Insert.PHONE_TYPE, phoneNumberType);
1111 }
Yorke Leee1424812013-09-04 18:24:48 -07001112 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1113 return intent;
1114 }
1115
Yorke Leeda0f9042013-12-05 14:25:51 -08001116 private boolean canIntentBeHandled(Intent intent) {
1117 final PackageManager packageManager = getPackageManager();
1118 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1119 PackageManager.MATCH_DEFAULT_ONLY);
1120 return resolveInfo != null && resolveInfo.size() > 0;
1121 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001122
Yorke Lee86e21f72014-04-02 16:49:38 -07001123 /**
1124 * Called when the user has long-pressed a contact tile to start a drag operation.
1125 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001126 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001127 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Lee18963442014-06-06 17:20:13 -07001128 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001129 }
1130
1131 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001132 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1133 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001134
Yorke Lee86e21f72014-04-02 16:49:38 -07001135 /**
1136 * Called when the user has released a contact tile after long-pressing it.
1137 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001138 @Override
1139 public void onDragFinished(int x, int y) {
Andrew Lee18963442014-06-06 17:20:13 -07001140 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001141 }
1142
1143 @Override
1144 public void onDroppedOnRemove() {}
1145
1146 /**
Yorke Leed999b712014-04-23 15:10:58 -07001147 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001148 * once it has been attached to the activity.
1149 */
1150 @Override
1151 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001152 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001153 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001154 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001155
1156 @Override
1157 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001158 // Specify call-origin so that users will see the previous tab instead of
1159 // CallLog screen (search UI will be automatically exited).
1160 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001161 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001162 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001163 }
1164
1165 @Override
1166 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001167 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1168 }
1169
1170 @Override
1171 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001172 Intent intent = isVideoCall ?
Yorke Leeb82e8da2015-04-18 14:37:50 -07001173 CallIntentUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1174 CallIntentUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001175 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001176 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001177 }
1178
1179 @Override
1180 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001181 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001182 }
1183
1184 @Override
1185 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001186 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001187 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001188
Yorke Leecc4660d2014-04-24 11:22:57 -07001189 @Override
1190 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001191 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001192 // Only scroll the button when the first tab is selected. The button should scroll from
1193 // the middle to right position only on the transition from the first tab to the second
1194 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001195 // If the app is in RTL mode, we need to check against the second tab, rather than the
1196 // first. This is because if we are scrolling between the first and second tabs, the
1197 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1198 // reversal of the order of the tabs.
1199 final boolean isLayoutRtl = DialerUtils.isRtl();
1200 final boolean shouldScrollButton = position == (isLayoutRtl
1201 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1202 if (shouldScrollButton && !mIsLandscape) {
1203 mFloatingActionButtonController.onPageScrolled(
1204 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001205 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1206 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001207 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001208 }
1209
1210 @Override
1211 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001212 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001213 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001214 }
1215
1216 @Override
1217 public void onPageScrollStateChanged(int state) {
1218 }
1219
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001220 private TelephonyManager getTelephonyManager() {
1221 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1222 }
1223
Tyler Gunn9dc924c2014-09-12 09:33:50 -07001224 private TelecomManager getTelecomManager() {
1225 return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001226 }
1227
Yorke Lee5253be02014-05-21 18:50:03 -07001228 @Override
1229 public boolean isActionBarShowing() {
1230 return mActionBarController.isActionBarShowing();
1231 }
1232
Yorke Leec98a5bb2014-10-28 16:12:05 -07001233 @Override
1234 public ActionBarController getActionBarController() {
1235 return mActionBarController;
1236 }
1237
Andrew Lee9da8fb42014-06-03 14:03:09 -07001238 public boolean isDialpadShown() {
1239 return mIsDialpadShown;
1240 }
1241
Yorke Lee5253be02014-05-21 18:50:03 -07001242 @Override
1243 public int getActionBarHideOffset() {
1244 return getActionBar().getHideOffset();
1245 }
1246
1247 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001248 public void setActionBarHideOffset(int offset) {
1249 getActionBar().setHideOffset(offset);
Yorke Lee5253be02014-05-21 18:50:03 -07001250 }
1251
1252 @Override
Yorke Leec98a5bb2014-10-28 16:12:05 -07001253 public int getActionBarHeight() {
1254 return mActionBarHeight;
Yorke Lee5253be02014-05-21 18:50:03 -07001255 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001256
1257 /**
1258 * Updates controller based on currently known information.
1259 *
1260 * @param animate Whether or not to animate the transition.
1261 */
1262 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Lee405a6e62014-08-20 15:02:16 -07001263 int align = (!mIsLandscape && mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
1264 FloatingActionButtonController.ALIGN_MIDDLE :
1265 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001266 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001267 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001268}