blob: d7bfb00fbdc22809a2787f804e1fe7ad4d8fc340 [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;
Chiao Cheng94b10b52012-08-17 16:59:12 -070031import android.provider.ContactsContract.Contacts;
Yorke Leee1424812013-09-04 18:24:48 -070032import android.provider.ContactsContract.Intents;
Yorke Leec3766332013-07-31 11:13:16 -070033import android.speech.RecognizerIntent;
Yorke Leecc4660d2014-04-24 11:22:57 -070034import android.support.v4.view.ViewPager;
Jay Shraunerae274c02014-09-06 10:09:24 -070035import android.telecomm.PhoneAccount;
Yorke Lee6eec2282014-07-18 12:40:27 -070036import android.telecomm.TelecommManager;
Yorke Leec3766332013-07-31 11:13:16 -070037import android.telephony.TelephonyManager;
Yorke Lee53a22302014-04-29 18:13:46 -070038import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070039import android.text.TextUtils;
Yorke Lee53a22302014-04-29 18:13:46 -070040import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070041import android.util.Log;
Yorke Lee28266192014-05-01 10:05:52 -070042import android.view.DragEvent;
Yorke Lee74edcdc2014-07-11 16:15:08 -070043import android.view.Gravity;
Andrew Leeb1903842014-05-15 16:11:24 -070044import android.view.KeyEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070045import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070046import android.view.MenuItem;
Andrew Leeb1903842014-05-15 16:11:24 -070047import android.view.MotionEvent;
Chiao Cheng94b10b52012-08-17 16:59:12 -070048import android.view.View;
Yorke Lee28266192014-05-01 10:05:52 -070049import android.view.View.OnDragListener;
Yorke Leec7b2a0e2014-05-20 17:21:25 -070050import android.view.View.OnTouchListener;
Ihab Awad9134e252014-07-09 12:32:52 -070051import android.view.ViewTreeObserver;
Andrew Lee2a58ab82014-05-15 02:16:04 -070052import android.view.animation.Animation;
Andrew Lee2a58ab82014-05-15 02:16:04 -070053import android.view.animation.AnimationUtils;
Yorke Leec3766332013-07-31 11:13:16 -070054import android.widget.AbsListView.OnScrollListener;
Yorke Lee53a22302014-04-29 18:13:46 -070055import android.widget.EditText;
Yorke Lee28aab272014-06-11 10:24:19 -070056import android.widget.FrameLayout;
Andrew Leea73e1892014-05-13 13:21:16 -070057import android.widget.ImageButton;
Chiao Cheng94b10b52012-08-17 16:59:12 -070058import android.widget.PopupMenu;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080059import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070060
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070061import com.android.contacts.common.CallUtil;
Yorke Leec3766332013-07-31 11:13:16 -070062import com.android.contacts.common.dialog.ClearFrequentsDialog;
63import com.android.contacts.common.interactions.ImportExportDialogFragment;
Nancy Chen0d3a7392014-08-12 14:44:53 -070064import com.android.contacts.common.interactions.TouchPointManager;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080065import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -070066import com.android.contacts.common.widget.FloatingActionButtonController;
Sai Cheemalapati7fa029f2014-07-29 15:03:55 -070067import com.android.dialer.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070068import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070069import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070070import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070071import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070072import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070073import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee3cefcc62014-01-16 11:26:46 -080074import com.android.dialer.list.DragDropController;
Yorke Leee00c9fe2014-04-12 12:42:06 -070075import com.android.dialer.list.ListsFragment;
Yorke Lee3cefcc62014-01-16 11:26:46 -080076import com.android.dialer.list.OnDragDropListener;
Yorke Leec3766332013-07-31 11:13:16 -070077import com.android.dialer.list.OnListFragmentScrolledListener;
Yorke Leeefb2d9c2014-04-18 14:05:01 -070078import com.android.dialer.list.PhoneFavoriteSquareTileView;
Jay Shrauner2e5b34b2013-08-29 10:52:40 -070079import com.android.dialer.list.RegularSearchFragment;
80import com.android.dialer.list.SearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -070081import com.android.dialer.list.SmartDialSearchFragment;
Ihab Awad9134e252014-07-09 12:32:52 -070082import com.android.dialer.list.SpeedDialFragment;
Yorke Leeaf6f1952014-07-14 19:13:16 -070083import com.android.dialer.settings.DialerSettingsActivity;
Yorke Lee7d20f822014-06-19 17:09:33 -070084import com.android.dialer.util.DialerUtils;
Yorke Lee5253be02014-05-21 18:50:03 -070085import com.android.dialer.widget.ActionBarController;
Andrew Leeb1903842014-05-15 16:11:24 -070086import com.android.dialer.widget.SearchEditTextLayout;
Yorke Lee11ca39e2014-05-19 20:31:37 -070087import com.android.dialer.widget.SearchEditTextLayout.OnBackButtonClickedListener;
Yorke Lee0baa98b2013-08-22 10:55:16 -070088import com.android.dialerbind.DatabaseHelperManager;
Nancy Chen0d3a7392014-08-12 14:44:53 -070089import com.android.incallui.CallCardFragment;
Yorke Lee2fec47b2014-08-05 18:16:27 -070090import com.android.phone.common.animation.AnimUtils;
Sai Cheemalapatifd723ca2014-06-19 12:30:07 -070091import com.android.phone.common.animation.AnimationListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070092
Yorke Leec3766332013-07-31 11:13:16 -070093import java.util.ArrayList;
Yorke Leeda0f9042013-12-05 14:25:51 -080094import java.util.List;
Yorke Lee69c247f2014-07-22 11:49:49 -070095import java.util.Locale;
Yorke Leec3766332013-07-31 11:13:16 -070096
Chiao Cheng94b10b52012-08-17 16:59:12 -070097/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070098 * The dialer tab's title is 'phone', a more common name (see strings.xml).
99 */
Yorke Leec3766332013-07-31 11:13:16 -0700100public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Lee86e21f72014-04-02 16:49:38 -0700101 DialpadFragment.OnDialpadQueryChangedListener,
Yorke Leec3766332013-07-31 11:13:16 -0700102 OnListFragmentScrolledListener,
Yorke Lee6a1461a2014-04-21 16:27:14 -0700103 ListsFragment.HostInterface,
Yorke Leed999b712014-04-23 15:10:58 -0700104 SpeedDialFragment.HostInterface,
Yorke Lee5253be02014-05-21 18:50:03 -0700105 SearchFragment.HostInterface,
Andrew Lee752956e2014-05-15 11:43:38 -0700106 OnDragDropListener,
Yorke Leecc4660d2014-04-24 11:22:57 -0700107 OnPhoneNumberPickerActionListener,
Andrew Leee74a10e2014-05-16 14:31:40 -0700108 PopupMenu.OnMenuItemClickListener,
Yorke Lee5253be02014-05-21 18:50:03 -0700109 ViewPager.OnPageChangeListener,
110 ActionBarController.ActivityUi {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700111 private static final String TAG = "DialtactsActivity";
112
Ihab Awad526c0b82014-02-27 12:55:36 -0800113 public static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700114
Yorke Leef74011e2013-08-02 11:30:30 -0700115 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
116
Chiao Cheng94b10b52012-08-17 16:59:12 -0700117 /** @see #getCallOrigin() */
118 private static final String CALL_ORIGIN_DIALTACTS =
119 "com.android.dialer.DialtactsActivity";
120
Yorke Leeb207f8a2013-08-29 18:51:06 -0700121 private static final String KEY_IN_REGULAR_SEARCH_UI = "in_regular_search_ui";
122 private static final String KEY_IN_DIALPAD_SEARCH_UI = "in_dialpad_search_ui";
Yorke Leeef2b7382013-08-09 17:39:25 -0700123 private static final String KEY_SEARCH_QUERY = "search_query";
124 private static final String KEY_FIRST_LAUNCH = "first_launch";
Yorke Lee50aba882014-05-28 20:04:31 -0700125 private static final String KEY_IS_DIALPAD_SHOWN = "is_dialpad_shown";
Yorke Leeef2b7382013-08-09 17:39:25 -0700126
Yorke Leec3766332013-07-31 11:13:16 -0700127 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
128 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
129 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
130 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700131
Chiao Cheng94b10b52012-08-17 16:59:12 -0700132 /**
133 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
134 */
135 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
136
Yorke Leec3766332013-07-31 11:13:16 -0700137 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700138
Yorke Lee28aab272014-06-11 10:24:19 -0700139 private FrameLayout parentLayout;
Andrew Lee0c667702014-05-12 14:31:45 -0700140
Yorke Leec3766332013-07-31 11:13:16 -0700141 /**
Yorke Leec3766332013-07-31 11:13:16 -0700142 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700143 */
Yorke Leef74011e2013-08-02 11:30:30 -0700144 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700145
146 /**
147 * Fragment for searching phone numbers using the alphanumeric keyboard.
148 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700149 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700150
151 /**
152 * Fragment for searching phone numbers using the dialpad.
153 */
154 private SmartDialSearchFragment mSmartDialSearchFragment;
155
Yorke Leee00c9fe2014-04-12 12:42:06 -0700156 /**
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700157 * Animation that slides in.
158 */
159 private Animation mSlideIn;
160
161 /**
162 * Animation that slides out.
163 */
164 private Animation mSlideOut;
165
166 /**
167 * Listener for after slide out animation completes on dialer fragment.
168 */
169 AnimationListenerAdapter mSlideOutListener = new AnimationListenerAdapter() {
170 @Override
171 public void onAnimationEnd(Animation animation) {
172 commitDialpadFragmentHide();
173 }
174 };
175
176 /**
Yorke Leee00c9fe2014-04-12 12:42:06 -0700177 * Fragment containing the speed dial list, recents list, and all contacts list.
178 */
179 private ListsFragment mListsFragment;
180
Yorke Leeb207f8a2013-08-29 18:51:06 -0700181 private boolean mInDialpadSearch;
182 private boolean mInRegularSearch;
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700183 private boolean mClearSearchOnPause;
Andrew Lee2a58ab82014-05-15 02:16:04 -0700184 private boolean mIsDialpadShown;
Yorke Lee50aba882014-05-28 20:04:31 -0700185 private boolean mShowDialpadOnResume;
Yorke Leeb207f8a2013-08-29 18:51:06 -0700186
Yorke Leeef2b7382013-08-09 17:39:25 -0700187 /**
Sai Cheemalapati41460652014-06-02 21:05:39 -0700188 * Whether or not the device is in landscape orientation.
189 */
190 private boolean mIsLandscape;
191
192 /**
Yorke Leecc4660d2014-04-24 11:22:57 -0700193 * The position of the currently selected tab in the attached {@link ListsFragment}.
194 */
195 private int mCurrentTabPosition = 0;
196
197 /**
Yorke Lee35127cd2013-09-10 14:09:29 -0700198 * True if the dialpad is only temporarily showing due to being in call
199 */
200 private boolean mInCallDialpadUp;
201
202 /**
Yorke Leeef2b7382013-08-09 17:39:25 -0700203 * True when this activity has been launched for the first time.
204 */
Yorke Lee98702de2013-08-06 12:03:32 -0700205 private boolean mFirstLaunch;
Yorke Lee86e21f72014-04-02 16:49:38 -0700206
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700207 /**
208 * Search query to be applied to the SearchView in the ActionBar once
209 * onCreateOptionsMenu has been called.
210 */
211 private String mPendingSearchViewQuery;
212
Yorke Lee74edcdc2014-07-11 16:15:08 -0700213 private PopupMenu mOverflowMenu;
Yorke Lee53a22302014-04-29 18:13:46 -0700214 private EditText mSearchView;
Yorke Lee53a22302014-04-29 18:13:46 -0700215 private View mVoiceSearchButton;
Andrew Leee74a10e2014-05-16 14:31:40 -0700216
Yorke Leeef2b7382013-08-09 17:39:25 -0700217 private String mSearchQuery;
218
Yorke Leefce269a2013-08-12 11:56:04 -0700219 private DialerDatabaseHelper mDialerDatabaseHelper;
Yorke Lee28266192014-05-01 10:05:52 -0700220 private DragDropController mDragDropController;
Yorke Lee5253be02014-05-21 18:50:03 -0700221 private ActionBarController mActionBarController;
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700222
Sai Cheemalapati41460652014-06-02 21:05:39 -0700223 private FloatingActionButtonController mFloatingActionButtonController;
Yorke Leefce269a2013-08-12 11:56:04 -0700224
Andrew Lee2423a2f2014-05-29 14:14:45 -0700225 private int mActionBarHeight;
Andrew Lee2423a2f2014-05-29 14:14:45 -0700226
Andrew Leee74a10e2014-05-16 14:31:40 -0700227 private class OptionsPopupMenu extends PopupMenu {
228 public OptionsPopupMenu(Context context, View anchor) {
Yorke Lee74edcdc2014-07-11 16:15:08 -0700229 super(context, anchor, Gravity.END);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700230 }
231
232 @Override
233 public void show() {
234 final Menu menu = getMenu();
235 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Andrew Leee74a10e2014-05-16 14:31:40 -0700236 clearFrequents.setVisible(mListsFragment != null &&
237 mListsFragment.getSpeedDialFragment() != null &&
238 mListsFragment.getSpeedDialFragment().hasFrequents());
Yorke Leee00c9fe2014-04-12 12:42:06 -0700239 super.show();
240 }
241 }
242
Chiao Cheng94b10b52012-08-17 16:59:12 -0700243 /**
Yorke Lee28266192014-05-01 10:05:52 -0700244 * Listener that listens to drag events and sends their x and y coordinates to a
245 * {@link DragDropController}.
246 */
247 private class LayoutOnDragListener implements OnDragListener {
248 @Override
249 public boolean onDrag(View v, DragEvent event) {
250 if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
Andrew Lee18963442014-06-06 17:20:13 -0700251 mDragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
Yorke Lee28266192014-05-01 10:05:52 -0700252 }
253 return true;
254 }
255 }
256
257 /**
Chiao Cheng94b10b52012-08-17 16:59:12 -0700258 * Listener used to send search queries to the phone search fragment.
259 */
Yorke Lee53a22302014-04-29 18:13:46 -0700260 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
Andrew Lee99a570c2014-05-15 14:18:50 -0700261 @Override
262 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
263 }
Yorke Leec3766332013-07-31 11:13:16 -0700264
Andrew Lee99a570c2014-05-15 14:18:50 -0700265 @Override
266 public void onTextChanged(CharSequence s, int start, int before, int count) {
267 final String newText = s.toString();
268 if (newText.equals(mSearchQuery)) {
269 // If the query hasn't changed (perhaps due to activity being destroyed
270 // and restored, or user launching the same DIAL intent twice), then there is
271 // no need to do anything here.
Yorke Lee53a22302014-04-29 18:13:46 -0700272 return;
273 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700274 if (DEBUG) {
275 Log.d(TAG, "onTextChange for mSearchView called with new query: " + newText);
Yorke Lee710709d2014-05-29 07:18:42 -0700276 Log.d(TAG, "Previous Query: " + mSearchQuery);
Yorke Leec3766332013-07-31 11:13:16 -0700277 }
Yorke Lee710709d2014-05-29 07:18:42 -0700278 mSearchQuery = newText;
Andrew Lee99a570c2014-05-15 14:18:50 -0700279
Andrew Lee90374a72014-05-16 15:01:09 -0700280 // Show search fragment only when the query string is changed to non-empty text.
281 if (!TextUtils.isEmpty(newText)) {
282 // Call enterSearchUi only if we are switching search modes, or showing a search
283 // fragment for the first time.
284 final boolean sameSearchMode = (mIsDialpadShown && mInDialpadSearch) ||
285 (!mIsDialpadShown && mInRegularSearch);
286 if (!sameSearchMode) {
287 enterSearchUi(mIsDialpadShown, mSearchQuery);
288 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700289 }
290
Andrew Leea8515422014-06-13 16:53:54 -0700291 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700292 mSmartDialSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Leea8515422014-06-13 16:53:54 -0700293 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Leeb1903842014-05-15 16:11:24 -0700294 mRegularSearchFragment.setQueryString(mSearchQuery, false /* delaySelection */);
Andrew Lee99a570c2014-05-15 14:18:50 -0700295 }
Andrew Lee99a570c2014-05-15 14:18:50 -0700296 }
297
298 @Override
299 public void afterTextChanged(Editable s) {
300 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700301 };
302
Andrew Leeb1903842014-05-15 16:11:24 -0700303
304 /**
Yorke Lee11ca39e2014-05-19 20:31:37 -0700305 * Open the search UI when the user clicks on the search box.
Andrew Leeb1903842014-05-15 16:11:24 -0700306 */
Yorke Lee11ca39e2014-05-19 20:31:37 -0700307 private final View.OnClickListener mSearchViewOnClickListener = new View.OnClickListener() {
Andrew Leeb1903842014-05-15 16:11:24 -0700308 @Override
Yorke Lee11ca39e2014-05-19 20:31:37 -0700309 public void onClick(View v) {
Andrew Leeb1903842014-05-15 16:11:24 -0700310 if (!isInSearchUi()) {
Yorke Lee5253be02014-05-21 18:50:03 -0700311 mActionBarController.onSearchBoxTapped();
Andrew Leeb1903842014-05-15 16:11:24 -0700312 enterSearchUi(false /* smartDialSearch */, mSearchView.getText().toString());
313 }
Andrew Leeb1903842014-05-15 16:11:24 -0700314 }
315 };
316
317 /**
318 * If the search term is empty and the user closes the soft keyboard, close the search UI.
319 */
320 private final View.OnKeyListener mSearchEditTextLayoutListener = new View.OnKeyListener() {
321 @Override
322 public boolean onKey(View v, int keyCode, KeyEvent event) {
323 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN &&
324 TextUtils.isEmpty(mSearchView.getText().toString())) {
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700325 maybeExitSearchUi();
Andrew Leeb1903842014-05-15 16:11:24 -0700326 }
327 return false;
328 }
329 };
330
Chiao Cheng94b10b52012-08-17 16:59:12 -0700331 @Override
Nancy Chen49db1ad2014-08-18 20:10:17 -0700332 public boolean dispatchTouchEvent(MotionEvent ev) {
333 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
334 TouchPointManager.getInstance().setPoint((int) ev.getRawX(), (int) ev.getRawY());
335 }
336 return super.dispatchTouchEvent(ev);
337
338 }
339
340 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700341 protected void onCreate(Bundle savedInstanceState) {
342 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700343 mFirstLaunch = true;
344
Andrew Lee2423a2f2014-05-29 14:14:45 -0700345 final Resources resources = getResources();
Nancy Chenb8170de2014-07-28 10:41:08 -0700346 mActionBarHeight = resources.getDimensionPixelSize(R.dimen.action_bar_height_large);
Andrew Lee2423a2f2014-05-29 14:14:45 -0700347
Yorke Lee8898cd02013-08-08 10:24:27 -0700348 setContentView(R.layout.dialtacts_activity);
Yorke Lee9e91bb02014-03-05 17:50:50 -0800349 getWindow().setBackgroundDrawable(null);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700350
Yorke Lee53a22302014-04-29 18:13:46 -0700351 final ActionBar actionBar = getActionBar();
352 actionBar.setCustomView(R.layout.search_edittext);
353 actionBar.setDisplayShowCustomEnabled(true);
Yorke Leebcef9402014-05-21 15:33:00 -0700354 actionBar.setBackgroundDrawable(null);
Yorke Lee8fd67242014-08-05 18:43:45 -0700355 actionBar.setElevation(resources.getDimensionPixelSize(R.dimen.action_bar_elevation));
Yorke Lee53a22302014-04-29 18:13:46 -0700356
Yorke Lee5253be02014-05-21 18:50:03 -0700357 mActionBarController = new ActionBarController(this,
358 (SearchEditTextLayout) actionBar.getCustomView());
359
Andrew Lee04675a52014-06-05 18:36:20 -0700360 SearchEditTextLayout searchEditTextLayout =
361 (SearchEditTextLayout) actionBar.getCustomView();
362 searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener);
363
364 mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view);
Yorke Lee53a22302014-04-29 18:13:46 -0700365 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
Andrew Lee04675a52014-06-05 18:36:20 -0700366 mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button);
367 searchEditTextLayout.findViewById(R.id.search_magnifying_glass)
368 .setOnClickListener(mSearchViewOnClickListener);
369 searchEditTextLayout.findViewById(R.id.search_box_start_search)
370 .setOnClickListener(mSearchViewOnClickListener);
371 searchEditTextLayout.setOnBackButtonClickedListener(new OnBackButtonClickedListener() {
Yorke Lee11ca39e2014-05-19 20:31:37 -0700372 @Override
373 public void onBackButtonClicked() {
374 onBackPressed();
375 }
376 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700377
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700378 mIsLandscape = getResources().getConfiguration().orientation
Sai Cheemalapati41460652014-06-02 21:05:39 -0700379 == Configuration.ORIENTATION_LANDSCAPE;
Nancy Chen8e066292014-06-18 17:16:10 -0700380
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700381 final View floatingActionButtonContainer = findViewById(
382 R.id.floating_action_button_container);
Andrew Lee405a6e62014-08-20 15:02:16 -0700383 ImageButton floatingActionButton = (ImageButton) findViewById(R.id.floating_action_button);
384 floatingActionButton.setOnClickListener(this);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700385 mFloatingActionButtonController = new FloatingActionButtonController(this,
Andrew Lee405a6e62014-08-20 15:02:16 -0700386 floatingActionButtonContainer, floatingActionButton);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700387
Andrew Lee04675a52014-06-05 18:36:20 -0700388 ImageButton optionsMenuButton =
389 (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button);
Andrew Leee74a10e2014-05-16 14:31:40 -0700390 optionsMenuButton.setOnClickListener(this);
Yorke Lee74edcdc2014-07-11 16:15:08 -0700391 mOverflowMenu = buildOptionsMenu(searchEditTextLayout);
392 optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
Andrew Leee74a10e2014-05-16 14:31:40 -0700393
Yorke Leeef2b7382013-08-09 17:39:25 -0700394 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
395 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700396 if (savedInstanceState == null) {
Ihab Awad526c0b82014-02-27 12:55:36 -0800397 getFragmentManager().beginTransaction()
Yorke Leee00c9fe2014-04-12 12:42:06 -0700398 .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)
Ihab Awad526c0b82014-02-27 12:55:36 -0800399 .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)
400 .commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700401 } else {
402 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700403 mInRegularSearch = savedInstanceState.getBoolean(KEY_IN_REGULAR_SEARCH_UI);
404 mInDialpadSearch = savedInstanceState.getBoolean(KEY_IN_DIALPAD_SEARCH_UI);
Yorke Leeef2b7382013-08-09 17:39:25 -0700405 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Yorke Lee50aba882014-05-28 20:04:31 -0700406 mShowDialpadOnResume = savedInstanceState.getBoolean(KEY_IS_DIALPAD_SHOWN);
Yorke Lee5253be02014-05-21 18:50:03 -0700407 mActionBarController.restoreInstanceState(savedInstanceState);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700408 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700409
Tyler Gunnbf7a95e2014-08-12 12:16:28 -0700410 final boolean isLayoutRtl = DialerUtils.isRtl();
411 if (mIsLandscape) {
412 mSlideIn = AnimationUtils.loadAnimation(this,
413 isLayoutRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
414 mSlideOut = AnimationUtils.loadAnimation(this,
415 isLayoutRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
416 } else {
417 mSlideIn = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
418 mSlideOut = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
419 }
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700420
Yorke Lee2fec47b2014-08-05 18:16:27 -0700421 mSlideIn.setInterpolator(AnimUtils.EASE_IN);
422 mSlideOut.setInterpolator(AnimUtils.EASE_OUT);
423
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700424 mSlideOut.setAnimationListener(mSlideOutListener);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700425
Yorke Lee28aab272014-06-11 10:24:19 -0700426 parentLayout = (FrameLayout) findViewById(R.id.dialtacts_mainlayout);
Andrew Lee0c667702014-05-12 14:31:45 -0700427 parentLayout.setOnDragListener(new LayoutOnDragListener());
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700428 floatingActionButtonContainer.getViewTreeObserver().addOnGlobalLayoutListener(
Sai Cheemalapati41460652014-06-02 21:05:39 -0700429 new ViewTreeObserver.OnGlobalLayoutListener() {
430 @Override
431 public void onGlobalLayout() {
Andrew Lee405a6e62014-08-20 15:02:16 -0700432 final ViewTreeObserver observer =
433 floatingActionButtonContainer.getViewTreeObserver();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700434 if (!observer.isAlive()) {
435 return;
436 }
437 observer.removeOnGlobalLayoutListener(this);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700438 int screenWidth = parentLayout.getWidth();
439 mFloatingActionButtonController.setScreenWidth(screenWidth);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700440 updateFloatingActionButtonControllerAlignment(false /* animate */);
Sai Cheemalapati41460652014-06-02 21:05:39 -0700441 }
442 });
Andrew Lee0c667702014-05-12 14:31:45 -0700443
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700444 setupActivityOverlay();
445
Yorke Lee0baa98b2013-08-22 10:55:16 -0700446 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700447 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700448 }
449
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700450 private void setupActivityOverlay() {
451 final View activityOverlay = findViewById(R.id.activity_overlay);
452 activityOverlay.setOnTouchListener(new OnTouchListener() {
453 @Override
454 public boolean onTouch(View v, MotionEvent event) {
455 if (!mIsDialpadShown) {
456 maybeExitSearchUi();
457 }
458 return false;
459 }
460 });
461 }
462
Chiao Cheng94b10b52012-08-17 16:59:12 -0700463 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700464 protected void onResume() {
465 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700466 if (mFirstLaunch) {
467 displayFragment(getIntent());
Yorke Lee35127cd2013-09-10 14:09:29 -0700468 } else if (!phoneIsInUse() && mInCallDialpadUp) {
469 hideDialpadFragment(false, true);
470 mInCallDialpadUp = false;
Yorke Lee50aba882014-05-28 20:04:31 -0700471 } else if (mShowDialpadOnResume) {
472 showDialpadFragment(false);
473 mShowDialpadOnResume = false;
Yorke Lee98702de2013-08-06 12:03:32 -0700474 }
475 mFirstLaunch = false;
Yorke Lee53a22302014-04-29 18:13:46 -0700476 prepareVoiceSearchButton();
Yorke Leefce269a2013-08-12 11:56:04 -0700477 mDialerDatabaseHelper.startSmartDialUpdateThread();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700478 updateFloatingActionButtonControllerAlignment(false /* animate */);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700479 }
480
481 @Override
Yorke Lee8e5c8b12013-10-01 14:37:55 -0700482 protected void onPause() {
483 if (mClearSearchOnPause) {
484 hideDialpadAndSearchUi();
485 mClearSearchOnPause = false;
486 }
487 super.onPause();
488 }
489
490 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700491 protected void onSaveInstanceState(Bundle outState) {
492 super.onSaveInstanceState(outState);
493 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700494 outState.putBoolean(KEY_IN_REGULAR_SEARCH_UI, mInRegularSearch);
495 outState.putBoolean(KEY_IN_DIALPAD_SEARCH_UI, mInDialpadSearch);
Yorke Leeef2b7382013-08-09 17:39:25 -0700496 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
Yorke Lee50aba882014-05-28 20:04:31 -0700497 outState.putBoolean(KEY_IS_DIALPAD_SHOWN, mIsDialpadShown);
Yorke Lee5253be02014-05-21 18:50:03 -0700498 mActionBarController.saveInstanceState(outState);
Yorke Leeef2b7382013-08-09 17:39:25 -0700499 }
500
501 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700502 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700503 if (fragment instanceof DialpadFragment) {
504 mDialpadFragment = (DialpadFragment) fragment;
Yorke Lee50aba882014-05-28 20:04:31 -0700505 if (!mShowDialpadOnResume) {
506 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
507 transaction.hide(mDialpadFragment);
508 transaction.commit();
509 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700510 } else if (fragment instanceof SmartDialSearchFragment) {
511 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700512 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leeef2b7382013-08-09 17:39:25 -0700513 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700514 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee4e28c1d2014-05-13 15:38:10 -0700515 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(this);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700516 } else if (fragment instanceof ListsFragment) {
517 mListsFragment = (ListsFragment) fragment;
Yorke Leecc4660d2014-04-24 11:22:57 -0700518 mListsFragment.addOnPageChangeListener(this);
Yorke Leec3766332013-07-31 11:13:16 -0700519 }
Yorke Leec3766332013-07-31 11:13:16 -0700520 }
521
Alon Albertb453e5b2013-09-10 15:54:23 -0700522 protected void handleMenuSettings() {
Yorke Leeaf6f1952014-07-14 19:13:16 -0700523 final Intent intent = new Intent(this, DialerSettingsActivity.class);
524 startActivity(intent);
Alon Albertb453e5b2013-09-10 15:54:23 -0700525 }
526
Chiao Cheng94b10b52012-08-17 16:59:12 -0700527 @Override
528 public void onClick(View view) {
529 switch (view.getId()) {
Andrew Leea73e1892014-05-13 13:21:16 -0700530 case R.id.floating_action_button:
Andrew Lee2a58ab82014-05-15 02:16:04 -0700531 if (!mIsDialpadShown) {
Andrew Leea73e1892014-05-13 13:21:16 -0700532 mInCallDialpadUp = false;
533 showDialpadFragment(true);
Andrew Leea73e1892014-05-13 13:21:16 -0700534 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700535 break;
Yorke Leec3766332013-07-31 11:13:16 -0700536 case R.id.voice_search_button:
Yorke Leeda0f9042013-12-05 14:25:51 -0800537 try {
538 startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
539 ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
540 } catch (ActivityNotFoundException e) {
541 Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
542 Toast.LENGTH_SHORT).show();
543 }
Yorke Leec3766332013-07-31 11:13:16 -0700544 break;
Andrew Leee74a10e2014-05-16 14:31:40 -0700545 case R.id.dialtacts_options_menu_button:
Yorke Lee74edcdc2014-07-11 16:15:08 -0700546 mOverflowMenu.show();
Andrew Leee74a10e2014-05-16 14:31:40 -0700547 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700548 default: {
549 Log.wtf(TAG, "Unexpected onClick event from " + view);
550 break;
551 }
552 }
553 }
554
Yorke Leec3766332013-07-31 11:13:16 -0700555 @Override
Andrew Leee74a10e2014-05-16 14:31:40 -0700556 public boolean onMenuItemClick(MenuItem item) {
Yorke Lee86e21f72014-04-02 16:49:38 -0700557 switch (item.getItemId()) {
558 case R.id.menu_history:
Yorke Lee6a1461a2014-04-21 16:27:14 -0700559 showCallHistory();
Yorke Lee86e21f72014-04-02 16:49:38 -0700560 break;
561 case R.id.menu_add_contact:
562 try {
563 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
564 } catch (ActivityNotFoundException e) {
565 Toast toast = Toast.makeText(this,
566 R.string.add_contact_not_available,
567 Toast.LENGTH_SHORT);
568 toast.show();
569 }
570 break;
571 case R.id.menu_import_export:
572 // We hard-code the "contactsAreAvailable" argument because doing it properly would
573 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
574 // now in Dialtacts for (potential) performance reasons. Compare with how it is
575 // done in {@link PeopleActivity}.
576 ImportExportDialogFragment.show(getFragmentManager(), true,
577 DialtactsActivity.class);
578 return true;
579 case R.id.menu_clear_frequents:
Yorke Lee86e21f72014-04-02 16:49:38 -0700580 ClearFrequentsDialog.show(getFragmentManager());
581 return true;
582 case R.id.menu_call_settings:
583 handleMenuSettings();
584 return true;
Yorke Lee86e21f72014-04-02 16:49:38 -0700585 }
586 return false;
587 }
588
589 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700590 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
591 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
592 if (resultCode == RESULT_OK) {
593 final ArrayList<String> matches = data.getStringArrayListExtra(
594 RecognizerIntent.EXTRA_RESULTS);
595 if (matches.size() > 0) {
596 final String match = matches.get(0);
Yorke Lee53a22302014-04-29 18:13:46 -0700597 mSearchView.setText(match);
Yorke Leec3766332013-07-31 11:13:16 -0700598 } else {
599 Log.e(TAG, "Voice search - nothing heard");
600 }
601 } else {
602 Log.e(TAG, "Voice search failed");
603 }
604 }
605 super.onActivityResult(requestCode, resultCode, data);
606 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700607
Andrew Lee2a58ab82014-05-15 02:16:04 -0700608 /**
609 * Initiates a fragment transaction to show the dialpad fragment. Animations and other visual
610 * updates are handled by a callback which is invoked after the dialpad fragment is shown.
611 * @see #onDialpadShown
612 */
Yorke Leec3766332013-07-31 11:13:16 -0700613 private void showDialpadFragment(boolean animate) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700614 if (mIsDialpadShown) {
615 return;
616 }
617 mIsDialpadShown = true;
Andrew Leecdfa6c62014-05-06 15:33:35 -0700618 mDialpadFragment.setAnimate(animate);
Sai Cheemalapati2d7faf62014-08-04 11:48:50 -0700619 mDialpadFragment.sendScreenView();
Andrew Leecdfa6c62014-05-06 15:33:35 -0700620
Chiao Cheng94b10b52012-08-17 16:59:12 -0700621 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700622 ft.show(mDialpadFragment);
623 ft.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700624
Yorke Lee29ae4ae2014-09-09 16:30:34 -0700625 if (animate) {
626 mFloatingActionButtonController.scaleOut();
627 } else {
628 mFloatingActionButtonController.setVisible(false);
629 }
Yorke Lee5253be02014-05-21 18:50:03 -0700630 mActionBarController.onDialpadUp();
631
Andrew Leeb1903842014-05-15 16:11:24 -0700632 if (!isInSearchUi()) {
633 enterSearchUi(true /* isSmartDial */, mSearchQuery);
634 }
Yorke Leec3766332013-07-31 11:13:16 -0700635 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700636
Andrew Lee2a58ab82014-05-15 02:16:04 -0700637 /**
638 * Callback from child DialpadFragment when the dialpad is shown.
639 */
640 public void onDialpadShown() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700641 if (mDialpadFragment.getAnimate()) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700642 mDialpadFragment.getView().startAnimation(mSlideIn);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700643 } else {
644 mDialpadFragment.setYFraction(0);
645 }
646
Andrew Lee2a58ab82014-05-15 02:16:04 -0700647 updateSearchFragmentPosition();
Andrew Lee2a58ab82014-05-15 02:16:04 -0700648 }
649
650 /**
651 * Initiates animations and other visual updates to hide the dialpad. The fragment is hidden in
652 * a callback after the hide animation ends.
653 * @see #commitDialpadFragmentHide
654 */
Yorke Leeca195042013-09-25 16:29:38 -0700655 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700656 if (mDialpadFragment == null) {
657 return;
658 }
Yorke Leef6673d32013-08-23 15:34:17 -0700659 if (clearDialpad) {
660 mDialpadFragment.clearDialpad();
661 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700662 if (!mIsDialpadShown) {
663 return;
Yorke Leec3766332013-07-31 11:13:16 -0700664 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700665 mIsDialpadShown = false;
666 mDialpadFragment.setAnimate(animate);
667
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700668 updateSearchFragmentPosition();
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -0700669
670 updateFloatingActionButtonControllerAlignment(animate);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700671 if (animate) {
Sai Cheemalapati82d6da52014-06-03 13:54:23 -0700672 mDialpadFragment.getView().startAnimation(mSlideOut);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700673 } else {
674 commitDialpadFragmentHide();
675 }
676
Yorke Lee5253be02014-05-21 18:50:03 -0700677 mActionBarController.onDialpadDown();
Yorke Lee11ca39e2014-05-19 20:31:37 -0700678
Andrew Leed4cde832014-05-16 15:56:48 -0700679 if (isInSearchUi()) {
Andrew Lee44e3daf2014-05-19 14:28:16 -0700680 if (TextUtils.isEmpty(mSearchQuery)) {
681 exitSearchUi();
Andrew Lee44e3daf2014-05-19 14:28:16 -0700682 }
Andrew Leed4cde832014-05-16 15:56:48 -0700683 }
Andrew Lee2a58ab82014-05-15 02:16:04 -0700684 }
685
686 /**
687 * Finishes hiding the dialpad fragment after any animations are completed.
688 */
689 private void commitDialpadFragmentHide() {
690 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700691 ft.hide(mDialpadFragment);
692 ft.commit();
Andrew Lee405a6e62014-08-20 15:02:16 -0700693
694 mFloatingActionButtonController.scaleIn(AnimUtils.NO_DELAY);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700695 }
696
Andrew Lee2a58ab82014-05-15 02:16:04 -0700697 private void updateSearchFragmentPosition() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700698 SearchFragment fragment = null;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700699 if (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700700 fragment = mSmartDialSearchFragment;
Andrew Leedbe9a8c2014-05-16 15:18:40 -0700701 } else if (mRegularSearchFragment != null && mRegularSearchFragment.isVisible()) {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700702 fragment = mRegularSearchFragment;
703 }
704 if (fragment != null && fragment.isVisible()) {
Andrew Lee9da8fb42014-06-03 14:03:09 -0700705 fragment.updatePosition(true /* animate */);
Andrew Lee2a58ab82014-05-15 02:16:04 -0700706 }
707 }
708
Yorke Lee5253be02014-05-21 18:50:03 -0700709 @Override
710 public boolean isInSearchUi() {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700711 return mInDialpadSearch || mInRegularSearch;
712 }
713
Yorke Lee5253be02014-05-21 18:50:03 -0700714 @Override
715 public boolean hasSearchQuery() {
716 return !TextUtils.isEmpty(mSearchQuery);
717 }
718
719 @Override
720 public boolean shouldShowActionBar() {
721 return mListsFragment.shouldShowActionBar();
722 }
723
Yorke Leeb207f8a2013-08-29 18:51:06 -0700724 private void setNotInSearchUi() {
725 mInDialpadSearch = false;
726 mInRegularSearch = false;
727 }
728
Yorke Lee311969c2013-08-26 06:31:11 -0700729 private void hideDialpadAndSearchUi() {
Yorke Lee710709d2014-05-29 07:18:42 -0700730 if (mIsDialpadShown) {
731 hideDialpadFragment(false, true);
732 } else {
733 exitSearchUi();
734 }
Yorke Lee311969c2013-08-26 06:31:11 -0700735 }
736
Yorke Lee53a22302014-04-29 18:13:46 -0700737 private void prepareVoiceSearchButton() {
Yorke Lee53a22302014-04-29 18:13:46 -0700738 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
739 if (canIntentBeHandled(voiceIntent)) {
740 mVoiceSearchButton.setVisibility(View.VISIBLE);
741 mVoiceSearchButton.setOnClickListener(this);
742 } else {
743 mVoiceSearchButton.setVisibility(View.GONE);
744 }
745 }
746
Andrew Leee74a10e2014-05-16 14:31:40 -0700747 private OptionsPopupMenu buildOptionsMenu(View invoker) {
748 final OptionsPopupMenu popupMenu = new OptionsPopupMenu(this, invoker);
749 popupMenu.inflate(R.menu.dialtacts_options);
Nancy Chenbeededb2014-06-10 18:30:28 -0700750 final Menu menu = popupMenu.getMenu();
Andrew Leee74a10e2014-05-16 14:31:40 -0700751 popupMenu.setOnMenuItemClickListener(this);
752 return popupMenu;
753 }
754
Yorke Lee86e21f72014-04-02 16:49:38 -0700755 @Override
756 public boolean onCreateOptionsMenu(Menu menu) {
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700757 if (mPendingSearchViewQuery != null) {
Yorke Lee53a22302014-04-29 18:13:46 -0700758 mSearchView.setText(mPendingSearchViewQuery);
Yorke Lee3c9e7cd2014-04-16 11:37:21 -0700759 mPendingSearchViewQuery = null;
760 }
Yorke Leea524ae52014-08-05 18:01:05 -0700761 mActionBarController.restoreActionBarOffset();
Andrew Leee74a10e2014-05-16 14:31:40 -0700762 return false;
Ihab Awadfb00cb82014-03-18 16:19:00 -0700763 }
764
Chiao Cheng94b10b52012-08-17 16:59:12 -0700765 /**
766 * Returns true if the intent is due to hitting the green send key (hardware call button:
767 * KEYCODE_CALL) while in a call.
768 *
769 * @param intent the intent that launched this activity
Chiao Cheng94b10b52012-08-17 16:59:12 -0700770 * @return true if the intent is due to hitting the green send key while in a call
771 */
Yorke Lee62e995c2014-03-28 10:02:56 -0700772 private boolean isSendKeyWhileInCall(Intent intent) {
773 // If there is a call in progress and the user launched the dialer by hitting the call
774 // button, go straight to the in-call screen.
775 final boolean callKey = Intent.ACTION_CALL_BUTTON.equals(intent.getAction());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700776
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700777 if (callKey) {
Nancy Chen105015e2014-08-21 22:50:11 -0700778 getTelecommManager().showInCallScreen(false);
Santos Cordon1d7ef6a2014-05-29 21:46:33 -0700779 return true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700780 }
781
782 return false;
783 }
784
785 /**
786 * Sets the current tab based on the intent's request type
787 *
788 * @param intent Intent that contains information about which tab should be selected
789 */
Yorke Leec3766332013-07-31 11:13:16 -0700790 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700791 // 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 -0700792 if (isSendKeyWhileInCall(intent)) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700793 finish();
794 return;
795 }
796
Yorke Lee669b6082013-09-17 15:43:38 -0700797 if (mDialpadFragment != null) {
798 final boolean phoneIsInUse = phoneIsInUse();
Yorke Lee473dd6c2014-06-10 12:14:20 -0700799 if (phoneIsInUse || (intent.getData() != null && isDialIntent(intent))) {
Yorke Lee669b6082013-09-17 15:43:38 -0700800 mDialpadFragment.setStartedFromNewIntent(true);
801 if (phoneIsInUse && !mDialpadFragment.isVisible()) {
802 mInCallDialpadUp = true;
803 }
804 showDialpadFragment(false);
Yorke Lee35127cd2013-09-10 14:09:29 -0700805 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700806 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700807 }
808
809 @Override
810 public void onNewIntent(Intent newIntent) {
811 setIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700812 displayFragment(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700813
Chiao Cheng94b10b52012-08-17 16:59:12 -0700814 invalidateOptionsMenu();
815 }
816
817 /** Returns true if the given intent contains a phone number to populate the dialer with */
818 private boolean isDialIntent(Intent intent) {
819 final String action = intent.getAction();
820 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
821 return true;
822 }
823 if (Intent.ACTION_VIEW.equals(action)) {
824 final Uri data = intent.getData();
Jay Shraunerae274c02014-09-06 10:09:24 -0700825 if (data != null && PhoneAccount.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700826 return true;
827 }
828 }
829 return false;
830 }
831
832 /**
833 * Returns an appropriate call origin for this Activity. May return null when no call origin
834 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
835 * for remembering the tab in which the user made a phone call, so the external app's DIAL
836 * request should not be counted.)
837 */
838 public String getCallOrigin() {
839 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
840 }
841
Chiao Cheng94b10b52012-08-17 16:59:12 -0700842 /**
Yorke Leec3766332013-07-31 11:13:16 -0700843 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700844 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700845 private void enterSearchUi(boolean smartDialSearch, String query) {
Andrew Lee90374a72014-05-16 15:01:09 -0700846 if (getFragmentManager().isDestroyed()) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700847 // Weird race condition where fragment is doing work after the activity is destroyed
848 // due to talkback being on (b/10209937). Just return since we can't do any
849 // constructive here.
850 return;
851 }
852
Yorke Leeef2b7382013-08-09 17:39:25 -0700853 if (DEBUG) {
854 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
855 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700856
Yorke Leec3766332013-07-31 11:13:16 -0700857 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leee00c9fe2014-04-12 12:42:06 -0700858 if (mInDialpadSearch && mSmartDialSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700859 transaction.remove(mSmartDialSearchFragment);
Yorke Leee00c9fe2014-04-12 12:42:06 -0700860 } else if (mInRegularSearch && mRegularSearchFragment != null) {
Yorke Leeb207f8a2013-08-29 18:51:06 -0700861 transaction.remove(mRegularSearchFragment);
Yorke Leeb207f8a2013-08-29 18:51:06 -0700862 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700863
Yorke Leeb207f8a2013-08-29 18:51:06 -0700864 final String tag;
865 if (smartDialSearch) {
866 tag = TAG_SMARTDIAL_SEARCH_FRAGMENT;
867 } else {
868 tag = TAG_REGULAR_SEARCH_FRAGMENT;
869 }
870 mInDialpadSearch = smartDialSearch;
871 mInRegularSearch = !smartDialSearch;
872
Andrew Lee752956e2014-05-15 11:43:38 -0700873 SearchFragment fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
Andrew Leeb1903842014-05-15 16:11:24 -0700874 transaction.setCustomAnimations(android.R.animator.fade_in, 0);
Yorke Leeef2b7382013-08-09 17:39:25 -0700875 if (fragment == null) {
876 if (smartDialSearch) {
877 fragment = new SmartDialSearchFragment();
878 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700879 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700880 }
Andrew Leeb1903842014-05-15 16:11:24 -0700881 transaction.add(R.id.dialtacts_frame, fragment, tag);
882 } else {
883 transaction.show(fragment);
Yorke Leeef2b7382013-08-09 17:39:25 -0700884 }
Yorke Lee86e21f72014-04-02 16:49:38 -0700885 // DialtactsActivity will provide the options menu
886 fragment.setHasOptionsMenu(false);
Andrew Leeb1903842014-05-15 16:11:24 -0700887 fragment.setShowEmptyListForNullQuery(true);
Andrew Lee99a570c2014-05-15 14:18:50 -0700888 fragment.setQueryString(query, false /* delaySelection */);
Yorke Leeef2b7382013-08-09 17:39:25 -0700889 transaction.commit();
Andrew Leeb1903842014-05-15 16:11:24 -0700890
891 mListsFragment.getView().animate().alpha(0).withLayer();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700892 }
893
894 /**
Yorke Leec3766332013-07-31 11:13:16 -0700895 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700896 */
Yorke Leec3766332013-07-31 11:13:16 -0700897 private void exitSearchUi() {
Yorke Lee3487db72013-09-26 17:12:06 -0700898 // See related bug in enterSearchUI();
899 if (getFragmentManager().isDestroyed()) {
900 return;
901 }
Andrew Leeb1903842014-05-15 16:11:24 -0700902
Andrew Leeb1903842014-05-15 16:11:24 -0700903 mSearchView.setText(null);
904 mDialpadFragment.clearDialpad();
Yorke Leeb207f8a2013-08-29 18:51:06 -0700905 setNotInSearchUi();
Yorke Lee7eccf452014-03-14 12:52:42 -0700906
Andrew Leeb1903842014-05-15 16:11:24 -0700907 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Andrew Leeb1903842014-05-15 16:11:24 -0700908 if (mSmartDialSearchFragment != null) {
909 transaction.remove(mSmartDialSearchFragment);
Yorke Lee7eccf452014-03-14 12:52:42 -0700910 }
Andrew Leeb1903842014-05-15 16:11:24 -0700911 if (mRegularSearchFragment != null) {
912 transaction.remove(mRegularSearchFragment);
913 }
914 transaction.commit();
915
916 mListsFragment.getView().animate().alpha(1).withLayer();
Yorke Lee5253be02014-05-21 18:50:03 -0700917 mActionBarController.onSearchUiExited();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700918 }
919
920 /** Returns an Intent to launch Call Settings screen */
921 public static Intent getCallSettingsIntent() {
Yorke Lee6eec2282014-07-18 12:40:27 -0700922 final Intent intent = new Intent(TelecommManager.ACTION_SHOW_CALL_SETTINGS);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700923 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
924 return intent;
925 }
926
927 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700928 public void onBackPressed() {
Andrew Lee2a58ab82014-05-15 02:16:04 -0700929 if (mIsDialpadShown) {
Andrew Lee9fd8f252014-06-13 17:09:26 -0700930 if (TextUtils.isEmpty(mSearchQuery) ||
931 (mSmartDialSearchFragment != null && mSmartDialSearchFragment.isVisible()
932 && mSmartDialSearchFragment.getAdapter().getCount() == 0)) {
Andrew Leeb1903842014-05-15 16:11:24 -0700933 exitSearchUi();
934 }
Yorke Leef6673d32013-08-23 15:34:17 -0700935 hideDialpadFragment(true, false);
Andrew Leeb1903842014-05-15 16:11:24 -0700936 } else if (isInSearchUi()) {
Andrew Lee99a570c2014-05-15 14:18:50 -0700937 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700938 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec3766332013-07-31 11:13:16 -0700939 } else {
940 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700941 }
Yorke Leec3766332013-07-31 11:13:16 -0700942 }
943
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700944 /**
945 * @return True if the search UI was exited, false otherwise
946 */
947 private boolean maybeExitSearchUi() {
948 if (isInSearchUi() && TextUtils.isEmpty(mSearchQuery)) {
949 exitSearchUi();
Yorke Leef543baa2014-07-24 11:31:13 -0700950 DialerUtils.hideInputMethod(parentLayout);
Yorke Leec7b2a0e2014-05-20 17:21:25 -0700951 return true;
952 }
953 return false;
954 }
955
Yorke Leec3766332013-07-31 11:13:16 -0700956 @Override
957 public void onDialpadQueryChanged(String query) {
Yorke Lee46635872014-04-11 11:20:15 -0700958 if (mSmartDialSearchFragment != null) {
959 mSmartDialSearchFragment.setAddToContactNumber(query);
960 }
Yorke Leec3766332013-07-31 11:13:16 -0700961 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
962 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
Yorke Lee53a22302014-04-29 18:13:46 -0700963
964 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700965 if (DEBUG) {
966 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
967 }
968 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
969 // This callback can happen if the dialpad fragment is recreated because of
970 // activity destruction. In that case, don't update the search view because
971 // that would bring the user back to the search fragment regardless of the
972 // previous state of the application. Instead, just return here and let the
973 // fragment manager correctly figure out whatever fragment was last displayed.
Yorke Lee53a22302014-04-29 18:13:46 -0700974 if (!TextUtils.isEmpty(normalizedQuery)) {
975 mPendingSearchViewQuery = normalizedQuery;
976 }
Yorke Leeef2b7382013-08-09 17:39:25 -0700977 return;
978 }
Yorke Lee53a22302014-04-29 18:13:46 -0700979 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700980 }
981 }
Yorke Leec3766332013-07-31 11:13:16 -0700982
983 @Override
984 public void onListFragmentScrollStateChange(int scrollState) {
985 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700986 hideDialpadFragment(true, false);
Yorke Leef543baa2014-07-24 11:31:13 -0700987 DialerUtils.hideInputMethod(getCurrentFocus());
Yorke Leec3766332013-07-31 11:13:16 -0700988 }
989 }
990
991 @Override
Yorke Lee86e21f72014-04-02 16:49:38 -0700992 public void onListFragmentScroll(int firstVisibleItem, int visibleItemCount,
Andrew Lee99a570c2014-05-15 14:18:50 -0700993 int totalItemCount) {
Yorke Leee00c9fe2014-04-12 12:42:06 -0700994 // TODO: No-op for now. This should eventually show/hide the actionBar based on
995 // interactions with the ListsFragments.
Yorke Lee86e21f72014-04-02 16:49:38 -0700996 }
997
Yorke Leec3766332013-07-31 11:13:16 -0700998 private boolean phoneIsInUse() {
Nancy Chen105015e2014-08-21 22:50:11 -0700999 return getTelecommManager().isInCall();
Yorke Leec3766332013-07-31 11:13:16 -07001000 }
Yorke Lee8dd62002013-08-08 15:57:20 -07001001
Yorke Leee1424812013-09-04 18:24:48 -07001002 public static Intent getAddNumberToContactIntent(CharSequence text) {
1003 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1004 intent.putExtra(Intents.Insert.PHONE, text);
1005 intent.setType(Contacts.CONTENT_ITEM_TYPE);
1006 return intent;
1007 }
1008
Yorke Leeda0f9042013-12-05 14:25:51 -08001009 private boolean canIntentBeHandled(Intent intent) {
1010 final PackageManager packageManager = getPackageManager();
1011 final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
1012 PackageManager.MATCH_DEFAULT_ONLY);
1013 return resolveInfo != null && resolveInfo.size() > 0;
1014 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001015
Yorke Lee6a1461a2014-04-21 16:27:14 -07001016 @Override
1017 public void showCallHistory() {
1018 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
1019 // CONTENT_TYPE, so that we always open our call log from our dialer
1020 final Intent intent = new Intent(this, CallLogActivity.class);
1021 startActivity(intent);
1022 }
1023
Yorke Lee86e21f72014-04-02 16:49:38 -07001024 /**
1025 * Called when the user has long-pressed a contact tile to start a drag operation.
1026 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001027 @Override
Yorke Leeefb2d9c2014-04-18 14:05:01 -07001028 public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001029 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001030 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_SHOWN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001031 }
Andrew Lee18963442014-06-06 17:20:13 -07001032 mListsFragment.showRemoveView(true);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001033 }
1034
1035 @Override
Yorke Lee28266192014-05-01 10:05:52 -07001036 public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
1037 }
Yorke Lee3cefcc62014-01-16 11:26:46 -08001038
Yorke Lee86e21f72014-04-02 16:49:38 -07001039 /**
1040 * Called when the user has released a contact tile after long-pressing it.
1041 */
Yorke Lee3cefcc62014-01-16 11:26:46 -08001042 @Override
1043 public void onDragFinished(int x, int y) {
Andrew Leee9e0ba62014-05-30 14:03:05 -07001044 if (mListsFragment.isPaneOpen()) {
Andrew Lee18963442014-06-06 17:20:13 -07001045 mActionBarController.setAlpha(ListsFragment.REMOVE_VIEW_HIDDEN_ALPHA);
Andrew Leee9e0ba62014-05-30 14:03:05 -07001046 }
Andrew Lee18963442014-06-06 17:20:13 -07001047 mListsFragment.showRemoveView(false);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001048 }
1049
1050 @Override
1051 public void onDroppedOnRemove() {}
1052
1053 /**
Yorke Leed999b712014-04-23 15:10:58 -07001054 * Allows the SpeedDialFragment to attach the drag controller to mRemoveViewContainer
Yorke Lee3cefcc62014-01-16 11:26:46 -08001055 * once it has been attached to the activity.
1056 */
1057 @Override
1058 public void setDragDropController(DragDropController dragController) {
Yorke Lee28266192014-05-01 10:05:52 -07001059 mDragDropController = dragController;
Andrew Lee18963442014-06-06 17:20:13 -07001060 mListsFragment.getRemoveView().setDragDropController(dragController);
Yorke Lee3cefcc62014-01-16 11:26:46 -08001061 }
Yorke Leee00c9fe2014-04-12 12:42:06 -07001062
1063 @Override
1064 public void onPickPhoneNumberAction(Uri dataUri) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001065 // Specify call-origin so that users will see the previous tab instead of
1066 // CallLog screen (search UI will be automatically exited).
1067 PhoneNumberInteraction.startInteractionForPhoneCall(
Andrew Lee99a570c2014-05-15 14:18:50 -07001068 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001069 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001070 }
1071
1072 @Override
1073 public void onCallNumberDirectly(String phoneNumber) {
Andrew Leefc1fed72014-07-02 11:05:53 -07001074 onCallNumberDirectly(phoneNumber, false /* isVideoCall */);
1075 }
1076
1077 @Override
1078 public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
Andrew Leed2a683f2014-07-08 15:54:50 -07001079 Intent intent = isVideoCall ?
Nancy Chen659d2f22014-07-09 10:28:41 -07001080 CallUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
1081 CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Yorke Lee7d20f822014-06-19 17:09:33 -07001082 DialerUtils.startActivityWithErrorToast(this, intent);
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001083 mClearSearchOnPause = true;
Yorke Leee00c9fe2014-04-12 12:42:06 -07001084 }
1085
1086 @Override
1087 public void onShortcutIntentCreated(Intent intent) {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001088 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
Yorke Leee00c9fe2014-04-12 12:42:06 -07001089 }
1090
1091 @Override
1092 public void onHomeInActionBarSelected() {
Yorke Lee4e28c1d2014-05-13 15:38:10 -07001093 exitSearchUi();
Yorke Leee00c9fe2014-04-12 12:42:06 -07001094 }
Yorke Lee33932ff2014-04-16 13:34:32 -07001095
Yorke Leecc4660d2014-04-24 11:22:57 -07001096 @Override
1097 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001098 position = mListsFragment.getRtlPosition(position);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001099 // Only scroll the button when the first tab is selected. The button should scroll from
1100 // the middle to right position only on the transition from the first tab to the second
1101 // tab.
Yorke Lee69c247f2014-07-22 11:49:49 -07001102 // If the app is in RTL mode, we need to check against the second tab, rather than the
1103 // first. This is because if we are scrolling between the first and second tabs, the
1104 // viewpager will report that the starting tab position is 1 rather than 0, due to the
1105 // reversal of the order of the tabs.
1106 final boolean isLayoutRtl = DialerUtils.isRtl();
1107 final boolean shouldScrollButton = position == (isLayoutRtl
1108 ? ListsFragment.TAB_INDEX_RECENTS : ListsFragment.TAB_INDEX_SPEED_DIAL);
1109 if (shouldScrollButton && !mIsLandscape) {
1110 mFloatingActionButtonController.onPageScrolled(
1111 isLayoutRtl ? 1 - positionOffset : positionOffset);
Sai Cheemalapati00a3d5d2014-06-13 10:22:26 -07001112 } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
1113 mFloatingActionButtonController.onPageScrolled(1);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001114 }
Yorke Leecc4660d2014-04-24 11:22:57 -07001115 }
1116
1117 @Override
1118 public void onPageSelected(int position) {
Yorke Lee69c247f2014-07-22 11:49:49 -07001119 position = mListsFragment.getRtlPosition(position);
Yorke Leecc4660d2014-04-24 11:22:57 -07001120 mCurrentTabPosition = position;
Yorke Leecc4660d2014-04-24 11:22:57 -07001121 }
1122
1123 @Override
1124 public void onPageScrollStateChanged(int state) {
1125 }
1126
Santos Cordon1d7ef6a2014-05-29 21:46:33 -07001127 private TelephonyManager getTelephonyManager() {
1128 return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
1129 }
1130
Nancy Chen105015e2014-08-21 22:50:11 -07001131 private TelecommManager getTelecommManager() {
1132 return (TelecommManager) getSystemService(Context.TELECOMM_SERVICE);
Santos Cordond15629d2014-07-07 15:15:29 -07001133 }
1134
Yorke Lee5253be02014-05-21 18:50:03 -07001135 @Override
1136 public boolean isActionBarShowing() {
1137 return mActionBarController.isActionBarShowing();
1138 }
1139
Andrew Lee9da8fb42014-06-03 14:03:09 -07001140 public boolean isDialpadShown() {
1141 return mIsDialpadShown;
1142 }
1143
Yorke Lee5253be02014-05-21 18:50:03 -07001144 @Override
1145 public int getActionBarHideOffset() {
1146 return getActionBar().getHideOffset();
1147 }
1148
1149 @Override
1150 public int getActionBarHeight() {
1151 return mActionBarHeight;
1152 }
1153
1154 @Override
1155 public void setActionBarHideOffset(int hideOffset) {
Yorke Leea524ae52014-08-05 18:01:05 -07001156 mActionBarController.setHideOffset(hideOffset);
Yorke Lee5253be02014-05-21 18:50:03 -07001157 }
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001158
1159 /**
1160 * Updates controller based on currently known information.
1161 *
1162 * @param animate Whether or not to animate the transition.
1163 */
1164 private void updateFloatingActionButtonControllerAlignment(boolean animate) {
Andrew Lee405a6e62014-08-20 15:02:16 -07001165 int align = (!mIsLandscape && mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
1166 FloatingActionButtonController.ALIGN_MIDDLE :
1167 FloatingActionButtonController.ALIGN_END;
Andrew Leef43b32f2014-08-14 17:43:04 -07001168 mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
Sai Cheemalapatic4969ea2014-06-04 16:35:16 -07001169 }
Chiao Cheng94b10b52012-08-17 16:59:12 -07001170}