blob: 36f7b8dfeeb97e9fbb3e0f2efeeb84ee55a35fb4 [file] [log] [blame]
Chiao Cheng94b10b52012-08-17 16:59:12 -07001/*
Yorke Leec3766332013-07-31 11:13:16 -07002 * Copyright (C) 2013 The Android Open Source Project
Chiao Cheng94b10b52012-08-17 16:59:12 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.dialer;
18
Yorke Leecc4660d2014-04-24 11:22:57 -070019import android.animation.LayoutTransition;
Yorke Lee53a22302014-04-29 18:13:46 -070020import android.app.ActionBar;
Chiao Cheng94b10b52012-08-17 16:59:12 -070021import android.app.Activity;
22import android.app.Fragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -070023import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080024import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070025import android.content.Context;
26import android.content.Intent;
Yorke Leeda0f9042013-12-05 14:25:51 -080027import android.content.pm.PackageManager;
28import android.content.pm.ResolveInfo;
Sai Cheemalapati82d6da52014-06-03 13:54:23 -070029import android.content.res.Configuration;
Andrew Lee2423a2f2014-05-29 14:14:45 -070030import android.content.res.Resources;
Chiao Cheng94b10b52012-08-17 16:59:12 -070031import android.net.Uri;
32import android.os.Bundle;
Santos Cordond15629d2014-07-07 15:15:29 -070033import android.os.RemoteException;
Santos Cordond15629d2014-07-07 15:15:29 -070034import android.phone.PhoneManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070035import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070036import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070037import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070038import android.support.v4.view.ViewPager;
Yorke Lee6eec2282014-07-18 12:40:27 -070039import android.telecomm.TelecommManager;
Yorke Leec3766332013-07-31 11:13:16 -070040import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070041import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070042import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070043import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070044import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070045import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070046import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070047import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070049import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070050import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070051import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070052import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070053import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070054import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070055import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070056import android.view.animation.AnimationUtils;
Chiao Cheng94b10b52012-08-17 16:59:12 -070057import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070058import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070059import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070060import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070061import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070062import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080063import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070064
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070065import com.android.contacts.common.CallUtil;
Yorke Leec3766332013-07-31 11:13:16 -070066import com.android.contacts.common.dialog.ClearFrequentsDialog;
67import com.android.contacts.common.interactions.ImportExportDialogFragment;
Nancy Chen0d3a7392014-08-12 14:44:53 -070068import com.android.contacts.common.interactions.TouchPointManager;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080069import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070070import com.android.contacts.common.widget.FloatingActionButtonController;
Sai Cheemalapati7fa029f2014-07-29 15:03:55 -070071import com.android.dialer.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070072import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070073import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070074import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070075import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070076import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070077import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080078import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070079import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080080import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070081import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070082import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070083import com.android.dialer.list.RegularSearchFragment;
84import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070085import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070086import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070087import com.android.dialer.settings.DialerSettingsActivity;
Yorke Lee7d20f822014-06-19 17:09:33 -070088import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070089import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070090import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070091import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070092import com.android.dialerbind.DatabaseHelperManager;
Nancy Chen0d3a7392014-08-12 14:44:53 -070093import com.android.incallui.CallCardFragment;
Yorke Lee2fec47b2014-08-05 18:16:27 -070094import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070095import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070096
Yorke Leec3766332013-07-31 11:13:16 -070097import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080098import java.util.List;
Yorke Lee69c247f2014-07-22 11:49:49 -070099import java.util.Locale;
Yorke Leec3766332013-07-31 11:13:16 -0700100
Chiao Cheng94b10b52012-08-17 16:59:12 -0700101/**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700102 * The dialer tab's title is 'phone', a more common name (see strings.xml).
103 */
Yorke Leec3766332013-07-31 11:13:16 -0700104public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700105 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700106 OnListFragmentScrolledListener,
Ihab Awad526c0b82014-02-27 12:55:36 -0800107 DialpadFragment.HostInterface,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700108 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700109 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700110 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700111 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700112 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700113 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700114 ViewPager.OnPageChangeListener,
115 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700116 private static final String TAG = "DialtactsActivity";
117
Ihab Awad526c0b82014-02-27 12:55:36 -0800118 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700119
Yorke Leef74011e2013-08-02 11:30:30 -0700120 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
121
Chiao Cheng94b10b52012-08-17 16:59:12 -0700122 /** @see #getCallOrigin() */
123 private static final String CALL_ORIGIN_DIALTACTS =
124 "com.android.dialer.DialtactsActivity";
125
Yorke Leeb207f8a2013-08-29 18:51:06 -0700126 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
127 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700128 private static final String KEY_SEARCH_QUERY = "search_query";
129 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700130 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700131
Yorke Leec3766332013-07-31 11:13:16 -0700132 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
133 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
134 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
135 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700136
Chiao Cheng94b10b52012-08-17 16:59:12 -0700137 /**
138 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
139 */
140 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
141
Yorke Leec3766332013-07-31 11:13:16 -0700142 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700143
Yorke Lee28aab272014-06-11 10:24:19 -0700144 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700145
Yorke Leec3766332013-07-31 11:13:16 -0700146 /**
Yorke Leec3766332013-07-31 11:13:16 -0700147 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700148 */
Yorke Leef74011e2013-08-02 11:30:30 -0700149 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700150
151 /**
152 * Fragment for searching phone numbers using the alphanumeric keyboard.
153 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700154 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700155
156 /**
157 * Fragment for searching phone numbers using the dialpad.
158 */
159 private SmartDialSearchFragment mSmartDialSearchFragment;
160
Yorke Leee00c9fe2014-04-12 12:42:06 -0700161 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700162 * Animation that slides in.
163 */
164 private Animation mSlideIn;
165
166 /**
167 * Animation that slides out.
168 */
169 private Animation mSlideOut;
170
171 /**
172 * Listener for after slide out animation completes on dialer fragment.
173 */
174 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
175 @Override
176 public void onAnimationEnd(Animation animation) {
177 commitDialpadFragmentHide();
178 }
179 };
180
181 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700182 * Fragment containing the speed dial list, recents list, and all contacts list.
183 */
184 private ListsFragment mListsFragment;
185
Yorke Leeb207f8a2013-08-29 18:51:06 -0700186 private boolean mInDialpadSearch;
187 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700188 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700189 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700190 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700191
Yorke Leeef2b7382013-08-09 17:39:25 -0700192 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700193 * Whether or not the device is in landscape orientation.
194 */
195 private boolean mIsLandscape;
196
197 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700198 * The position of the currently selected tab in the attached {@link ListsFragment}.
199 */
200 private int mCurrentTabPosition = 0;
201
202 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700203 * True if the dialpad is only temporarily showing due to being in call
204 */
205 private boolean mInCallDialpadUp;
206
207 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700208 * True when this activity has been launched for the first time.
209 */
Yorke Lee98702de2013-08-06 12:03:32 -0700210 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700211
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700212 /**
213 * Search query to be applied to the SearchView in the ActionBar once
214 * onCreateOptionsMenu has been called.
215 */
216 private String mPendingSearchViewQuery;
217
Yorke Lee74edcdc2014-07-11 16:15:08 -0700218 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700219 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700220 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700221
Yorke Leeef2b7382013-08-09 17:39:25 -0700222 private String mSearchQuery;
223
Yorke Leefce269a2013-08-12 11:56:04 -0700224 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700225 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700226 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700227
228 private String mDescriptionDialButtonStr;
229 private String mActionMenuDialpadButtonStr;
230 private ImageButton mFloatingActionButton;
Sai Cheemalapati41460652014-06-02 21:05:39 -0700231 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700232
Andrew Lee2423a2f2014-05-29 14:14:45 -0700233 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700234
Andrew Leee74a10e2014-05-16 14:31:40 -0700235 private class OptionsPopupMenu extends PopupMenu {
236 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700237 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700238 }
239
240 @Override
241 public void show() {
242 final Menu menu = getMenu();
243 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700244 clearFrequents.setVisible(mListsFragment != null &&
245 mListsFragment.getSpeedDialFragment() != null &&
246 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700247 super.show();
248 }
249 }
250
Chiao Cheng94b10b52012-08-17 16:59:12 -0700251 /**
Yorke Lee28266192014-05-01 10:05:52 -0700252 * Listener that listens to drag events and sends their x and y coordinates to a
253 * {@link DragDropController}.
254 */
255 private class LayoutOnDragListener implements OnDragListener {
256 @Override
257 public boolean onDrag(View v, DragEvent event) {
258 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700259 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700260 }
261 return true;
262 }
263 }
264
265 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700266 * Listener used to send search queries to the phone search fragment.
267 */
Yorke Lee53a22302014-04-29 18:13:46 -0700268 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700269 @Override
270 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
271 }
Yorke Leec3766332013-07-31 11:13:16 -0700272
Andrew Lee99a570c2014-05-15 14:18:50 -0700273 @Override
274 public void onTextChanged(CharSequence s, int start, int before, int count) {
275 final String newText = s.toString();
276 if (newText.equals(mSearchQuery)) {
277 // If the query hasn't changed (perhaps due to activity being destroyed
278 // and restored, or user launching the same DIAL intent twice), then there is
279 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700280 return;
281 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700282 if (DEBUG) {
283 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700284 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700285 }
Yorke Lee710709d2014-05-29 07:18:42 -0700286 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700287
Andrew Lee90374a72014-05-16 15:01:09 -0700288 // Show search fragment only when the query string is changed to non-empty text.
289 if (!TextUtils.isEmpty(newText)) {
290 // Call enterSearchUi only if we are switching search modes, or showing a search
291 // fragment for the first time.
292 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
293 (!mIsDialpadShown && mInRegularSearch);
294 if (!sameSearchMode) {
295 enterSearchUi(mIsDialpadShown, mSearchQuery);
296 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700297 }
298
Andrew Leea8515422014-06-13 16:53:54 -0700299 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700300 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700301 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700302 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700303 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700304 }
305
306 @Override
307 public void afterTextChanged(Editable s) {
308 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700309 };
310
Andrew Leeb1903842014-05-15 16:11:24 -0700311
312 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700313 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700314 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700315 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700316 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700317 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700318 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700319 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700320 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
321 }
Andrew Leeb1903842014-05-15 16:11:24 -0700322 }
323 };
324
325 /**
326 * If the search term is empty and the user closes the soft keyboard, close the search UI.
327 */
328 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
329 @Override
330 public boolean onKey(View v, int keyCode, KeyEvent event) {
331 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
332 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700333 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700334 }
335 return false;
336 }
337 };
338
Chiao Cheng94b10b52012-08-17 16:59:12 -0700339 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700340 public boolean dispatchTouchEvent(MotionEvent ev) {
341 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
342 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
343 }
344 return super.dispatchTouchEvent(ev);
345
346 }
347
348 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700349 protected void onCreate(Bundle savedInstanceState) {
350 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700351 mFirstLaunch = true;
352
Andrew Lee2423a2f2014-05-29 14:14:45 -0700353 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700354 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700355 mDescriptionDialButtonStr = resources.getString(R.string.description_dial_button);
356 mActionMenuDialpadButtonStr = resources.getString(R.string.action_menu_dialpad_button);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700357
Yorke Lee8898cd02013-08-08 10:24:27 -0700358 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800359 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700360
Yorke Lee53a22302014-04-29 18:13:46 -0700361 final ActionBar actionBar = getActionBar();
362 actionBar.setCustomView(R.layout.search_edittext);
363 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700364 actionBar.setBackgroundDrawable(null);
Yorke Lee8fd67242014-08-05 18:43:45 -0700365 actionBar.setElevation(resources.getDimensionPixelSize(R.dimen.action_bar_elevation));
Yorke Lee53a22302014-04-29 18:13:46 -0700366
Yorke Lee5253be02014-05-21 18:50:03 -0700367 mActionBarController = new ActionBarController(this,
368 (SearchEditTextLayout) actionBar.getCustomView());
369
Andrew Lee04675a52014-06-05 18:36:20 -0700370 SearchEditTextLayout searchEditTextLayout =
371 (SearchEditTextLayout) actionBar.getCustomView();
372 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
373
374 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700375 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700376 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
377 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
378 .setOnClickListener(mSearchViewOnClickListener);
379 searchEditTextLayout.findViewById(R.id.search_box_start_search)
380 .setOnClickListener(mSearchViewOnClickListener);
381 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700382 @Override
383 public void onBackButtonClicked() {
384 onBackPressed();
385 }
386 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700387
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700388 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700389 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700390
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700391 final View floatingActionButtonContainer = findViewById(
392 R.id.floating_action_button_container);
393 mFloatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
394 int floatingActionButtonWidth = resources.getDimensionPixelSize(
395 R.dimen.floating_action_button_width);
396 mFloatingActionButton.setOnClickListener(this);
397 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Leebd7a0562014-08-19 11:38:32 -0700398 floatingActionButtonContainer, mFloatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700399
Andrew Lee04675a52014-06-05 18:36:20 -0700400 ImageButton optionsMenuButton =
401 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700402 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700403 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
404 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700405
Yorke Leeef2b7382013-08-09 17:39:25 -0700406 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
407 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700408 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800409 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700410 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800411 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
412 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700413 } else {
414 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700415 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
416 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700417 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700418 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700419 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700420 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700421
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700422 final boolean isLayoutRtl = DialerUtils.isRtl();
423 if (mIsLandscape) {
424 mSlideIn = AnimationUtils.loadAnimation(this,
425 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
426 mSlideOut = AnimationUtils.loadAnimation(this,
427 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
428 } else {
429 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
430 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
431 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700432
Yorke Lee2fec47b2014-08-05 18:16:27 -0700433 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
434 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
435
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700436 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700437
Yorke Lee28aab272014-06-11 10:24:19 -0700438 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700439 parentLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
440 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700441 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700442 new ViewTreeObserver.OnGlobalLayoutListener() {
443 @Override
444 public void onGlobalLayout() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700445 final ViewTreeObserver observer = floatingActionButtonContainer
446 .getViewTreeObserver();
447 if (!observer.isAlive()) {
448 return;
449 }
450 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700451 int screenWidth = parentLayout.getWidth();
452 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700453 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700454 }
455 });
Andrew Lee0c667702014-05-12 14:31:45 -0700456
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700457 setupActivityOverlay();
458
Yorke Lee0baa98b2013-08-22 10:55:16 -0700459 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700460 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700461 }
462
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700463 private void setupActivityOverlay() {
464 final View activityOverlay = findViewById(R.id.activity_overlay);
465 activityOverlay.setOnTouchListener(new OnTouchListener() {
466 @Override
467 public boolean onTouch(View v, MotionEvent event) {
468 if (!mIsDialpadShown) {
469 maybeExitSearchUi();
470 }
471 return false;
472 }
473 });
474 }
475
Chiao Cheng94b10b52012-08-17 16:59:12 -0700476 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700477 protected void onResume() {
478 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700479 if (mFirstLaunch) {
480 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700481 } else if (!phoneIsInUse() && mInCallDialpadUp) {
482 hideDialpadFragment(false, true);
483 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700484 } else if (mShowDialpadOnResume) {
485 showDialpadFragment(false);
486 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700487 }
488 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700489 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700490 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700491 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700492 }
493
494 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700495 protected void onPause() {
496 if (mClearSearchOnPause) {
497 hideDialpadAndSearchUi();
498 mClearSearchOnPause = false;
499 }
500 super.onPause();
501 }
502
503 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700504 protected void onSaveInstanceState(Bundle outState) {
505 super.onSaveInstanceState(outState);
506 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700507 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
508 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700509 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700510 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700511 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700512 }
513
514 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700515 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700516 if (fragment instanceof DialpadFragment) {
517 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700518 if (!mShowDialpadOnResume) {
519 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
520 transaction.hide(mDialpadFragment);
521 transaction.commit();
522 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700523 } else if (fragment instanceof SmartDialSearchFragment) {
524 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700525 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700526 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700527 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700528 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700529 } else if (fragment instanceof ListsFragment) {
530 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700531 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700532 }
Yorke Leec3766332013-07-31 11:13:16 -0700533 }
534
Alon Albertb453e5b2013-09-10 15:54:23 -0700535 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700536 final Intent intent = new Intent(this, DialerSettingsActivity.class);
537 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700538 }
539
Chiao Cheng94b10b52012-08-17 16:59:12 -0700540 @Override
541 public void onClick(View view) {
542 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700543 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700544 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700545 mInCallDialpadUp = false;
546 showDialpadFragment(true);
547 } else {
548 // Dial button was pressed; tell the Dialpad fragment
549 mDialpadFragment.dialButtonPressed();
550 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700551 break;
Yorke Leec3766332013-07-31 11:13:16 -0700552 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800553 try {
554 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
555 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
556 } catch (ActivityNotFoundException e) {
557 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
558 Toast.LENGTH_SHORT).show();
559 }
Yorke Leec3766332013-07-31 11:13:16 -0700560 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700561 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700562 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700563 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700564 default: {
565 Log.wtf(TAG, "Unexpected onClick event from " + view);
566 break;
567 }
568 }
569 }
570
Yorke Leec3766332013-07-31 11:13:16 -0700571 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700572 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700573 switch (item.getItemId()) {
574 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700575 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700576 break;
577 case R.id.menu_add_contact:
578 try {
579 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
580 } catch (ActivityNotFoundException e) {
581 Toast toast = Toast.makeText(this,
582 R.string.add_contact_not_available,
583 Toast.LENGTH_SHORT);
584 toast.show();
585 }
586 break;
587 case R.id.menu_import_export:
588 // We hard-code the "contactsAreAvailable" argument because doing it properly would
589 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
590 // now in Dialtacts for (potential) performance reasons. Compare with how it is
591 // done in {@link PeopleActivity}.
592 ImportExportDialogFragment.show(getFragmentManager(), true,
593 DialtactsActivity.class);
594 return true;
595 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700596 ClearFrequentsDialog.show(getFragmentManager());
597 return true;
598 case R.id.menu_call_settings:
599 handleMenuSettings();
600 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700601 }
602 return false;
603 }
604
605 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700606 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
607 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
608 if (resultCode == RESULT_OK) {
609 final ArrayList<String> matches = data.getStringArrayListExtra(
610 RecognizerIntent.EXTRA_RESULTS);
611 if (matches.size() > 0) {
612 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700613 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700614 } else {
615 Log.e(TAG, "Voice search - nothing heard");
616 }
617 } else {
618 Log.e(TAG, "Voice search failed");
619 }
620 }
621 super.onActivityResult(requestCode, resultCode, data);
622 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700623
Andrew Lee2a58ab82014-05-15 02:16:04 -0700624 /**
625 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
626 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
627 * @see #onDialpadShown
628 */
Yorke Leec3766332013-07-31 11:13:16 -0700629 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700630 if (mIsDialpadShown) {
631 return;
632 }
633 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700634 mDialpadFragment.setAnimate(animate);
Sai Cheemalapati2d7faf62014-08-04 11:48:50 -0700635 mDialpadFragment.sendScreenView();
Andrew Leecdfa6c62014-05-06 15:33:35 -0700636
Chiao Cheng94b10b52012-08-17 16:59:12 -0700637 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700638 ft.show(mDialpadFragment);
639 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700640
Yorke Lee5253be02014-05-21 18:50:03 -0700641 mActionBarController.onDialpadUp();
642
Andrew Leeb1903842014-05-15 16:11:24 -0700643 if (!isInSearchUi()) {
644 enterSearchUi(true /* isSmartDial */, mSearchQuery);
645 }
Yorke Leec3766332013-07-31 11:13:16 -0700646 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700647
Andrew Lee2a58ab82014-05-15 02:16:04 -0700648 /**
649 * Callback from child DialpadFragment when the dialpad is shown.
650 */
651 public void onDialpadShown() {
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700652 mFloatingActionButton.setImageResource(R.drawable.fab_ic_call);
653 mFloatingActionButton.setContentDescription(mDescriptionDialButtonStr);
654 updateFloatingActionButtonControllerAlignment(mDialpadFragment.getAnimate());
Andrew Lee2a58ab82014-05-15 02:16:04 -0700655 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700656 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700657 } else {
658 mDialpadFragment.setYFraction(0);
659 }
660
Andrew Lee2a58ab82014-05-15 02:16:04 -0700661 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700662 }
663
664 /**
665 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
666 * a callback after the hide animation ends.
667 * @see #commitDialpadFragmentHide
668 */
Yorke Leeca195042013-09-25 16:29:38 -0700669 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700670 if (mDialpadFragment == null) {
671 return;
672 }
Yorke Leef6673d32013-08-23 15:34:17 -0700673 if (clearDialpad) {
674 mDialpadFragment.clearDialpad();
675 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700676 if (!mIsDialpadShown) {
677 return;
Yorke Leec3766332013-07-31 11:13:16 -0700678 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700679 mIsDialpadShown = false;
680 mDialpadFragment.setAnimate(animate);
681
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700682 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700683 mFloatingActionButton.setImageResource(R.drawable.fab_ic_dial);
684 mFloatingActionButton.setContentDescription(mActionMenuDialpadButtonStr);
685
686 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700687 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700688 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700689 } else {
690 commitDialpadFragmentHide();
691 }
692
Yorke Lee5253be02014-05-21 18:50:03 -0700693 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700694
Andrew Leed4cde832014-05-16 15:56:48 -0700695 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700696 if (TextUtils.isEmpty(mSearchQuery)) {
697 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700698 }
Andrew Leed4cde832014-05-16 15:56:48 -0700699 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700700 }
701
702 /**
703 * Finishes hiding the dialpad fragment after any animations are completed.
704 */
705 private void commitDialpadFragmentHide() {
706 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700707 ft.hide(mDialpadFragment);
708 ft.commit();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700709 }
710
Andrew Lee2a58ab82014-05-15 02:16:04 -0700711 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700712 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700713 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700714 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700715 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700716 fragment = mRegularSearchFragment;
717 }
718 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700719 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700720 }
721 }
722
Yorke Lee5253be02014-05-21 18:50:03 -0700723 @Override
724 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700725 return mInDialpadSearch || mInRegularSearch;
726 }
727
Yorke Lee5253be02014-05-21 18:50:03 -0700728 @Override
729 public boolean hasSearchQuery() {
730 return !TextUtils.isEmpty(mSearchQuery);
731 }
732
733 @Override
734 public boolean shouldShowActionBar() {
735 return mListsFragment.shouldShowActionBar();
736 }
737
Yorke Leeb207f8a2013-08-29 18:51:06 -0700738 private void setNotInSearchUi() {
739 mInDialpadSearch = false;
740 mInRegularSearch = false;
741 }
742
Yorke Lee311969c2013-08-26 06:31:11 -0700743 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700744 if (mIsDialpadShown) {
745 hideDialpadFragment(false, true);
746 } else {
747 exitSearchUi();
748 }
Yorke Lee311969c2013-08-26 06:31:11 -0700749 }
750
Yorke Lee53a22302014-04-29 18:13:46 -0700751 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700752 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
753 if (canIntentBeHandled(voiceIntent)) {
754 mVoiceSearchButton.setVisibility(View.VISIBLE);
755 mVoiceSearchButton.setOnClickListener(this);
756 } else {
757 mVoiceSearchButton.setVisibility(View.GONE);
758 }
759 }
760
Andrew Leee74a10e2014-05-16 14:31:40 -0700761 private OptionsPopupMenu buildOptionsMenu(View invoker) {
762 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
763 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700764 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700765 popupMenu.setOnMenuItemClickListener(this);
766 return popupMenu;
767 }
768
Yorke Lee86e21f72014-04-02 16:49:38 -0700769 @Override
770 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700771 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700772 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700773 mPendingSearchViewQuery = null;
774 }
Yorke Leea524ae52014-08-05 18:01:05 -0700775 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700776 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700777 }
778
Chiao Cheng94b10b52012-08-17 16:59:12 -0700779 /**
780 * Returns true if the intent is due to hitting the green send key (hardware call button:
781 * KEYCODE_CALL) while in a call.
782 *
783 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700784 * @return true if the intent is due to hitting the green send key while in a call
785 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700786 private boolean isSendKeyWhileInCall(Intent intent) {
787 // If there is a call in progress and the user launched the dialer by hitting the call
788 // button, go straight to the in-call screen.
789 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700790
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700791 if (callKey) {
Santos Cordond15629d2014-07-07 15:15:29 -0700792 getPhoneManager().showCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700793 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700794 }
795
796 return false;
797 }
798
799 /**
800 * Sets the current tab based on the intent's request type
801 *
802 * @param intent Intent that contains information about which tab should be selected
803 */
Yorke Leec3766332013-07-31 11:13:16 -0700804 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700805 // 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 -0700806 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700807 finish();
808 return;
809 }
810
Yorke Lee669b6082013-09-17 15:43:38 -0700811 if (mDialpadFragment != null) {
812 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700813 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700814 mDialpadFragment.setStartedFromNewIntent(true);
815 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
816 mInCallDialpadUp = true;
817 }
818 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700819 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700820 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700821 }
822
823 @Override
824 public void onNewIntent(Intent newIntent) {
825 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700826 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700827
Chiao Cheng94b10b52012-08-17 16:59:12 -0700828 invalidateOptionsMenu();
829 }
830
831 /** Returns true if the given intent contains a phone number to populate the dialer with */
832 private boolean isDialIntent(Intent intent) {
833 final String action = intent.getAction();
834 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
835 return true;
836 }
837 if (Intent.ACTION_VIEW.equals(action)) {
838 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700839 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700840 return true;
841 }
842 }
843 return false;
844 }
845
846 /**
847 * Returns an appropriate call origin for this Activity. May return null when no call origin
848 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
849 * for remembering the tab in which the user made a phone call, so the external app's DIAL
850 * request should not be counted.)
851 */
852 public String getCallOrigin() {
853 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
854 }
855
Chiao Cheng94b10b52012-08-17 16:59:12 -0700856 /**
Yorke Leec3766332013-07-31 11:13:16 -0700857 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700858 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700859 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700860 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700861 // Weird race condition where fragment is doing work after the activity is destroyed
862 // due to talkback being on (b/10209937). Just return since we can't do any
863 // constructive here.
864 return;
865 }
866
Yorke Leeef2b7382013-08-09 17:39:25 -0700867 if (DEBUG) {
868 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
869 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700870
Yorke Leec3766332013-07-31 11:13:16 -0700871 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700872 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700873 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700874 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700875 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700876 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700877
Yorke Leeb207f8a2013-08-29 18:51:06 -0700878 final String tag;
879 if (smartDialSearch) {
880 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
881 } else {
882 tag = TAG_REGULAR_SEARCH_FRAGMENT;
883 }
884 mInDialpadSearch = smartDialSearch;
885 mInRegularSearch = !smartDialSearch;
886
Andrew Lee752956e2014-05-15 11:43:38 -0700887 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700888 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700889 if (fragment == null) {
890 if (smartDialSearch) {
891 fragment = new SmartDialSearchFragment();
892 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700893 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700894 }
Andrew Leeb1903842014-05-15 16:11:24 -0700895 transaction.add(R.id.dialtacts_frame, fragment, tag);
896 } else {
897 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700898 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700899 // DialtactsActivity will provide the options menu
900 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700901 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700902 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700903 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700904
905 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700906 }
907
908 /**
Yorke Leec3766332013-07-31 11:13:16 -0700909 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700910 */
Yorke Leec3766332013-07-31 11:13:16 -0700911 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700912 // See related bug in enterSearchUI();
913 if (getFragmentManager().isDestroyed()) {
914 return;
915 }
Andrew Leeb1903842014-05-15 16:11:24 -0700916
Andrew Leeb1903842014-05-15 16:11:24 -0700917 mSearchView.setText(null);
918 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700919 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700920
Andrew Leeb1903842014-05-15 16:11:24 -0700921 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700922 if (mSmartDialSearchFragment != null) {
923 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700924 }
Andrew Leeb1903842014-05-15 16:11:24 -0700925 if (mRegularSearchFragment != null) {
926 transaction.remove(mRegularSearchFragment);
927 }
928 transaction.commit();
929
930 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700931 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700932 }
933
934 /** Returns an Intent to launch Call Settings screen */
935 public static Intent getCallSettingsIntent() {
Yorke Lee6eec2282014-07-18 12:40:27 -0700936 final Intent intent = new Intent(TelecommManager.ACTION_SHOW_CALL_SETTINGS);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700937 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
938 return intent;
939 }
940
941 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700942 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700943 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700944 if (TextUtils.isEmpty(mSearchQuery) ||
945 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
946 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700947 exitSearchUi();
948 }
Yorke Leef6673d32013-08-23 15:34:17 -0700949 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700950 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700951 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700952 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700953 } else {
954 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700955 }
Yorke Leec3766332013-07-31 11:13:16 -0700956 }
957
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700958 /**
959 * @return True if the search UI was exited, false otherwise
960 */
961 private boolean maybeExitSearchUi() {
962 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
963 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700964 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700965 return true;
966 }
967 return false;
968 }
969
Yorke Leec3766332013-07-31 11:13:16 -0700970 @Override
971 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700972 if (mSmartDialSearchFragment != null) {
973 mSmartDialSearchFragment.setAddToContactNumber(query);
974 }
Yorke Leec3766332013-07-31 11:13:16 -0700975 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
976 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700977
978 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700979 if (DEBUG) {
980 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
981 }
982 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
983 // This callback can happen if the dialpad fragment is recreated because of
984 // activity destruction. In that case, don't update the search view because
985 // that would bring the user back to the search fragment regardless of the
986 // previous state of the application. Instead, just return here and let the
987 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700988 if (!TextUtils.isEmpty(normalizedQuery)) {
989 mPendingSearchViewQuery = normalizedQuery;
990 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700991 return;
992 }
Yorke Lee53a22302014-04-29 18:13:46 -0700993 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700994 }
995 }
Yorke Leec3766332013-07-31 11:13:16 -0700996
997 @Override
998 public void onListFragmentScrollStateChange(int scrollState) {
999 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -07001000 hideDialpadFragment(true, false);
Yorke Leef543baa2014-07-24 11:31:13 -07001001 DialerUtils.hideInputMethod(getCurrentFocus());
Yorke Leec3766332013-07-31 11:13:16 -07001002 }
1003 }
1004
1005 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -07001006 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -07001007 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -07001008 // TODO: No-op for now. This should eventually show/hide the actionBar based on
1009 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -07001010 }
1011
Yorke Lee86e21f72014-04-02 16:49:38 -07001012 @Override
Andrew Leea73e1892014-05-13 13:21:16 -07001013 public void setFloatingActionButtonVisible(boolean visible) {
Sai Cheemalapati41460652014-06-02 21:05:39 -07001014 mFloatingActionButtonController.setVisible(visible);
Yorke Leec3766332013-07-31 11:13:16 -07001015 }
1016
1017 private boolean phoneIsInUse() {
Santos Cordond15629d2014-07-07 15:15:29 -07001018 return getPhoneManager().isInAPhoneCall();
Yorke Leec3766332013-07-31 11:13:16 -07001019 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001020
Yorke Leee1424812013-09-04 18:24:48 -07001021 public static Intent getAddNumberToContactIntent(CharSequence text) {
1022 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1023 intent.putExtra(Intents.Insert.PHONE, text);
1024 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1025 return intent;
1026 }
1027
Yorke Leeda0f9042013-12-05 14:25:51 -08001028 private boolean canIntentBeHandled(Intent intent) {
1029 final PackageManager packageManager = getPackageManager();
1030 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1031 PackageManager.MATCH_DEFAULT_ONLY);
1032 return resolveInfo != null && resolveInfo.size() > 0;
1033 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001034
Yorke Lee6a1461a2014-04-21 16:27:14 -07001035 @Override
1036 public void showCallHistory() {
1037 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1038 // CONTENT_TYPE, so that we always open our call log from our dialer
1039 final Intent intent = new Intent(this, CallLogActivity.class);
1040 startActivity(intent);
1041 }
1042
Yorke Lee86e21f72014-04-02 16:49:38 -07001043 /**
1044 * Called when the user has long-pressed a contact tile to start a drag operation.
1045 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001046 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001047 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001048 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001049 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001050 }
Andrew Lee18963442014-06-06 17:20:13 -07001051 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001052 }
1053
1054 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001055 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1056 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001057
Yorke Lee86e21f72014-04-02 16:49:38 -07001058 /**
1059 * Called when the user has released a contact tile after long-pressing it.
1060 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001061 @Override
1062 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001063 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001064 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001065 }
Andrew Lee18963442014-06-06 17:20:13 -07001066 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001067 }
1068
1069 @Override
1070 public void onDroppedOnRemove() {}
1071
1072 /**
Yorke Leed999b712014-04-23 15:10:58 -07001073 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001074 * once it has been attached to the activity.
1075 */
1076 @Override
1077 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001078 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001079 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001080 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001081
1082 @Override
1083 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001084 // Specify call-origin so that users will see the previous tab instead of
1085 // CallLog screen (search UI will be automatically exited).
1086 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001087 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001088 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001089 }
1090
1091 @Override
1092 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001093 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1094 }
1095
1096 @Override
1097 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001098 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001099 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1100 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001101 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001102 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001103 }
1104
1105 @Override
1106 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001107 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001108 }
1109
1110 @Override
1111 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001112 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001113 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001114
Yorke Leecc4660d2014-04-24 11:22:57 -07001115 @Override
1116 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001117 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001118 // Only scroll the button when the first tab is selected. The button should scroll from
1119 // the middle to right position only on the transition from the first tab to the second
1120 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001121 // If the app is in RTL mode, we need to check against the second tab, rather than the
1122 // first. This is because if we are scrolling between the first and second tabs, the
1123 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1124 // reversal of the order of the tabs.
1125 final boolean isLayoutRtl = DialerUtils.isRtl();
1126 final boolean shouldScrollButton = position == (isLayoutRtl
1127 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1128 if (shouldScrollButton && !mIsLandscape) {
1129 mFloatingActionButtonController.onPageScrolled(
1130 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001131 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1132 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001133 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001134 }
1135
1136 @Override
1137 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001138 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001139 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001140 }
1141
1142 @Override
1143 public void onPageScrollStateChanged(int state) {
1144 }
1145
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001146 private TelephonyManager getTelephonyManager() {
1147 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1148 }
1149
Santos Cordond15629d2014-07-07 15:15:29 -07001150 private PhoneManager getPhoneManager() {
1151 return (PhoneManager) getSystemService(Context.PHONE_SERVICE);
1152 }
1153
Yorke Lee5253be02014-05-21 18:50:03 -07001154 @Override
1155 public boolean isActionBarShowing() {
1156 return mActionBarController.isActionBarShowing();
1157 }
1158
Andrew Lee9da8fb42014-06-03 14:03:09 -07001159 public boolean isDialpadShown() {
1160 return mIsDialpadShown;
1161 }
1162
Yorke Lee5253be02014-05-21 18:50:03 -07001163 @Override
1164 public int getActionBarHideOffset() {
1165 return getActionBar().getHideOffset();
1166 }
1167
1168 @Override
1169 public int getActionBarHeight() {
1170 return mActionBarHeight;
1171 }
1172
1173 @Override
1174 public void setActionBarHideOffset(int hideOffset) {
Yorke Leea524ae52014-08-05 18:01:05 -07001175 mActionBarController.setHideOffset(hideOffset);
Yorke Lee5253be02014-05-21 18:50:03 -07001176 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001177
1178 /**
1179 * Updates controller based on currently known information.
1180 *
1181 * @param animate Whether or not to animate the transition.
1182 */
1183 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
1184 int align;
1185 if (mIsDialpadShown) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001186 align = mIsLandscape ? FloatingActionButtonController.ALIGN_QUARTER_END
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001187 : FloatingActionButtonController.ALIGN_MIDDLE;
1188 } else {
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001189 if (!mIsLandscape) {
1190 align = mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL
1191 ? FloatingActionButtonController.ALIGN_MIDDLE
Yorke Lee69c247f2014-07-22 11:49:49 -07001192 : FloatingActionButtonController.ALIGN_END;
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001193 } else {
Yorke Lee69c247f2014-07-22 11:49:49 -07001194 align = FloatingActionButtonController.ALIGN_END;
Sai Cheemalapati99085eb2014-06-09 11:36:43 -07001195 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001196 }
Andrew Leef43b32f2014-08-14 17:43:04 -07001197 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001198 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001199}