blob: 99855f4e050548ef9dc1668ea3d2cb20b7039cce [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 Leec3766332013-07-31 11:13:16 -070019import android.animation.Animator;
20import android.animation.Animator.AnimatorListener;
21import android.animation.AnimatorListenerAdapter;
Chiao Cheng94b10b52012-08-17 16:59:12 -070022import android.app.Activity;
Christine Chen9c1e0652013-05-23 15:40:19 -070023import android.app.backup.BackupManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070024import android.app.Fragment;
25import android.app.FragmentManager;
26import android.app.FragmentTransaction;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080027import android.content.ActivityNotFoundException;
Chiao Cheng94b10b52012-08-17 16:59:12 -070028import android.content.Context;
29import android.content.Intent;
30import android.content.SharedPreferences;
Yorke Leec3766332013-07-31 11:13:16 -070031import android.content.res.Resources;
Chiao Cheng94b10b52012-08-17 16:59:12 -070032import android.net.Uri;
33import android.os.Bundle;
34import android.os.RemoteException;
35import android.os.ServiceManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070036import android.provider.CallLog.Calls;
Yorke Leec3766332013-07-31 11:13:16 -070037import android.provider.ContactsContract;
Chiao Cheng94b10b52012-08-17 16:59:12 -070038import android.provider.ContactsContract.Contacts;
39import android.provider.ContactsContract.Intents.UI;
Yorke Leec3766332013-07-31 11:13:16 -070040import android.provider.Settings;
41import android.speech.RecognizerIntent;
42import android.support.v4.app.NavUtils;
43import android.telephony.TelephonyManager;
44import android.text.Editable;
Chiao Cheng94b10b52012-08-17 16:59:12 -070045import android.text.TextUtils;
Yorke Leec3766332013-07-31 11:13:16 -070046import android.text.TextWatcher;
Chiao Cheng94b10b52012-08-17 16:59:12 -070047import android.util.Log;
48import android.view.Menu;
Chiao Cheng94b10b52012-08-17 16:59:12 -070049import android.view.MenuItem;
Chiao Cheng94b10b52012-08-17 16:59:12 -070050import android.view.View;
Chiao Cheng94b10b52012-08-17 16:59:12 -070051import android.view.View.OnFocusChangeListener;
52import android.view.ViewConfiguration;
Chiao Cheng94b10b52012-08-17 16:59:12 -070053import android.view.inputmethod.InputMethodManager;
Yorke Leec3766332013-07-31 11:13:16 -070054import android.widget.AbsListView.OnScrollListener;
55import android.widget.EditText;
56import android.widget.ImageView;
Chiao Cheng94b10b52012-08-17 16:59:12 -070057import android.widget.PopupMenu;
58import android.widget.SearchView;
59import android.widget.SearchView.OnCloseListener;
60import android.widget.SearchView.OnQueryTextListener;
Chiao Cheng073b5cf2012-12-07 11:36:00 -080061import android.widget.Toast;
Chiao Cheng94b10b52012-08-17 16:59:12 -070062
Chiao Cheng9d4f3b22012-09-05 16:00:16 -070063import com.android.contacts.common.CallUtil;
Chiao Cheng603ff682012-10-24 15:18:40 -070064import com.android.contacts.common.activity.TransactionSafeActivity;
Yorke Leec3766332013-07-31 11:13:16 -070065import com.android.contacts.common.dialog.ClearFrequentsDialog;
66import com.android.contacts.common.interactions.ImportExportDialogFragment;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070067import com.android.contacts.common.list.ContactListItemView;
Chiao Cheng8efbcf92012-12-04 17:43:02 -080068import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
69import com.android.contacts.common.list.PhoneNumberPickerFragment;
Yorke Leec3766332013-07-31 11:13:16 -070070import com.android.dialer.calllog.CallLogActivity;
Yorke Leefce269a2013-08-12 11:56:04 -070071import com.android.dialer.database.DialerDatabaseHelper;
Yorke Leef74011e2013-08-02 11:30:30 -070072import com.android.dialer.dialpad.DialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -070073import com.android.dialer.dialpad.SmartDialNameMatcher;
Yorke Leefce269a2013-08-12 11:56:04 -070074import com.android.dialer.dialpad.SmartDialPrefix;
Chiao Cheng1429f1a2012-11-01 16:35:28 -070075import com.android.dialer.interactions.PhoneNumberInteraction;
Yorke Lee8dd62002013-08-08 15:57:20 -070076import com.android.dialer.list.AllContactsActivity;
Yorke Lee8898cd02013-08-08 10:24:27 -070077import com.android.dialer.list.PhoneFavoriteFragment;
Yorke Leec3766332013-07-31 11:13:16 -070078import com.android.dialer.list.OnListFragmentScrolledListener;
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;
Yorke Lee0baa98b2013-08-22 10:55:16 -070082import com.android.dialerbind.DatabaseHelperManager;
Chiao Cheng94b10b52012-08-17 16:59:12 -070083import com.android.internal.telephony.ITelephony;
84
Yorke Leec3766332013-07-31 11:13:16 -070085import java.util.ArrayList;
86
Chiao Cheng94b10b52012-08-17 16:59:12 -070087/**
Chiao Cheng94b10b52012-08-17 16:59:12 -070088 * The dialer tab's title is 'phone', a more common name (see strings.xml).
89 */
Yorke Leec3766332013-07-31 11:13:16 -070090public class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener,
Yorke Leef74011e2013-08-02 11:30:30 -070091 DialpadFragment.OnDialpadQueryChangedListener, PopupMenu.OnMenuItemClickListener,
Yorke Leec3766332013-07-31 11:13:16 -070092 OnListFragmentScrolledListener,
Yorke Lee8898cd02013-08-08 10:24:27 -070093 PhoneFavoriteFragment.OnPhoneFavoriteFragmentStartedListener,
Yorke Lee8dd62002013-08-08 15:57:20 -070094 DialpadFragment.OnDialpadFragmentStartedListener,
95 PhoneFavoriteFragment.OnShowAllContactsListener {
Chiao Cheng94b10b52012-08-17 16:59:12 -070096 private static final String TAG = "DialtactsActivity";
97
98 public static final boolean DEBUG = false;
99
Yorke Leef74011e2013-08-02 11:30:30 -0700100 public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
101
Chiao Cheng94b10b52012-08-17 16:59:12 -0700102 /** Used to open Call Setting */
103 private static final String PHONE_PACKAGE = "com.android.phone";
104 private static final String CALL_SETTINGS_CLASS_NAME =
105 "com.android.phone.CallFeaturesSetting";
Chiao Cheng94b10b52012-08-17 16:59:12 -0700106 /** @see #getCallOrigin() */
107 private static final String CALL_ORIGIN_DIALTACTS =
108 "com.android.dialer.DialtactsActivity";
109
Yorke Leeef2b7382013-08-09 17:39:25 -0700110 private static final String KEY_IN_SEARCH_UI = "in_search_ui";
111 private static final String KEY_SEARCH_QUERY = "search_query";
112 private static final String KEY_FIRST_LAUNCH = "first_launch";
113
Yorke Leec3766332013-07-31 11:13:16 -0700114 private static final String TAG_DIALPAD_FRAGMENT = "dialpad";
115 private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search";
116 private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial";
117 private static final String TAG_FAVORITES_FRAGMENT = "favorites";
Yorke Leec3766332013-07-31 11:13:16 -0700118
Chiao Cheng94b10b52012-08-17 16:59:12 -0700119 /**
120 * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}.
121 */
122 private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER";
123
Chiao Cheng94b10b52012-08-17 16:59:12 -0700124 private static final int SUBACTIVITY_ACCOUNT_FILTER = 1;
125
Yorke Leec3766332013-07-31 11:13:16 -0700126 private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700127
128 private String mFilterText;
129
Yorke Leec3766332013-07-31 11:13:16 -0700130 /**
131 * The main fragment displaying the user's favorites and frequent contacts
132 */
Yorke Lee8898cd02013-08-08 10:24:27 -0700133 private PhoneFavoriteFragment mPhoneFavoriteFragment;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700134
135 /**
Yorke Leec3766332013-07-31 11:13:16 -0700136 * Fragment containing the dialpad that slides into view
Chiao Cheng94b10b52012-08-17 16:59:12 -0700137 */
Yorke Leef74011e2013-08-02 11:30:30 -0700138 private DialpadFragment mDialpadFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700139
140 /**
141 * Fragment for searching phone numbers using the alphanumeric keyboard.
142 */
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700143 private RegularSearchFragment mRegularSearchFragment;
Yorke Leec3766332013-07-31 11:13:16 -0700144
145 /**
146 * Fragment for searching phone numbers using the dialpad.
147 */
148 private SmartDialSearchFragment mSmartDialSearchFragment;
149
Yorke Leec3766332013-07-31 11:13:16 -0700150 private View mMenuButton;
151 private View mCallHistoryButton;
152 private View mDialpadButton;
153
154 // Padding view used to shift the fragments up when the dialpad is shown.
155 private View mBottomPaddingView;
156
Chiao Cheng94b10b52012-08-17 16:59:12 -0700157 /**
158 * True when this Activity is in its search UI (with a {@link SearchView} and
159 * {@link PhoneNumberPickerFragment}).
160 */
161 private boolean mInSearchUi;
Yorke Leeef2b7382013-08-09 17:39:25 -0700162 /**
163 * True when this activity has been launched for the first time.
164 */
Yorke Lee98702de2013-08-06 12:03:32 -0700165 private boolean mFirstLaunch;
Yorke Leec3766332013-07-31 11:13:16 -0700166 private View mSearchViewContainer;
167 private View mSearchViewCloseButton;
168 private View mVoiceSearchButton;
169 private EditText mSearchView;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700170
Yorke Leeef2b7382013-08-09 17:39:25 -0700171 private String mSearchQuery;
172
Yorke Leefce269a2013-08-12 11:56:04 -0700173 private DialerDatabaseHelper mDialerDatabaseHelper;
174
Chiao Cheng94b10b52012-08-17 16:59:12 -0700175 /**
176 * Listener used when one of phone numbers in search UI is selected. This will initiate a
177 * phone call using the phone number.
178 */
179 private final OnPhoneNumberPickerActionListener mPhoneNumberPickerActionListener =
180 new OnPhoneNumberPickerActionListener() {
181 @Override
182 public void onPickPhoneNumberAction(Uri dataUri) {
183 // Specify call-origin so that users will see the previous tab instead of
184 // CallLog screen (search UI will be automatically exited).
185 PhoneNumberInteraction.startInteractionForPhoneCall(
Yorke Leec3766332013-07-31 11:13:16 -0700186 DialtactsActivity.this, dataUri, getCallOrigin());
Yorke Leef6673d32013-08-23 15:34:17 -0700187 hideDialpadAndSearchUi();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700188 }
189
190 @Override
Jay Shrauner31a760b2013-07-26 09:34:49 -0700191 public void onCallNumberDirectly(String phoneNumber) {
192 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
193 startActivity(intent);
Yorke Leef6673d32013-08-23 15:34:17 -0700194 hideDialpadAndSearchUi();
Jay Shrauner31a760b2013-07-26 09:34:49 -0700195 }
196
197 @Override
Chiao Cheng94b10b52012-08-17 16:59:12 -0700198 public void onShortcutIntentCreated(Intent intent) {
199 Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring.");
200 }
201
202 @Override
203 public void onHomeInActionBarSelected() {
204 exitSearchUi();
205 }
206 };
207
208 /**
209 * Listener used to send search queries to the phone search fragment.
210 */
Yorke Leec3766332013-07-31 11:13:16 -0700211 private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() {
212 @Override
213 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
214 }
215
216 @Override
217 public void onTextChanged(CharSequence s, int start, int before, int count) {
Yorke Leec3766332013-07-31 11:13:16 -0700218 final String newText = s.toString();
Yorke Leeef2b7382013-08-09 17:39:25 -0700219 if (newText.equals(mSearchQuery)) {
220 // If the query hasn't changed (perhaps due to activity being destroyed
221 // and restored, or user launching the same DIAL intent twice), then there is
222 // no need to do anything here.
223 return;
224 }
225 mSearchQuery = newText;
226 if (DEBUG) {
227 Log.d(TAG, "onTextChange for mSearchView called with new query: " + s);
228 }
229 final boolean smartDialSearch = isDialpadShowing();
230
Yorke Leec3766332013-07-31 11:13:16 -0700231 // Show search result with non-empty text. Show a bare list otherwise.
232 if (TextUtils.isEmpty(newText) && mInSearchUi) {
233 exitSearchUi();
234 mSearchViewCloseButton.setVisibility(View.GONE);
235 return;
236 } else if (!TextUtils.isEmpty(newText) && !mInSearchUi) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700237 enterSearchUi(smartDialSearch, newText);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700238 }
239
Yorke Leeef2b7382013-08-09 17:39:25 -0700240 if (smartDialSearch && mSmartDialSearchFragment != null) {
241 mSmartDialSearchFragment.setQueryString(newText, false);
242 } else if (mRegularSearchFragment != null) {
Yorke Leec3766332013-07-31 11:13:16 -0700243 mRegularSearchFragment.setQueryString(newText, false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700244 }
Yorke Leec3766332013-07-31 11:13:16 -0700245 mSearchViewCloseButton.setVisibility(View.VISIBLE);
246 return;
247 }
248
249 @Override
250 public void afterTextChanged(Editable s) {
251 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700252 };
253
Yorke Leec3766332013-07-31 11:13:16 -0700254 private boolean isDialpadShowing() {
255 return mDialpadFragment != null && mDialpadFragment.isVisible();
256 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700257
258 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700259 protected void onCreate(Bundle savedInstanceState) {
260 super.onCreate(savedInstanceState);
Yorke Lee98702de2013-08-06 12:03:32 -0700261 mFirstLaunch = true;
262
Chiao Cheng94b10b52012-08-17 16:59:12 -0700263 final Intent intent = getIntent();
264 fixIntent(intent);
265
Yorke Lee8898cd02013-08-08 10:24:27 -0700266 setContentView(R.layout.dialtacts_activity);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700267
Yorke Leec3766332013-07-31 11:13:16 -0700268 getActionBar().hide();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700269
Yorke Leeef2b7382013-08-09 17:39:25 -0700270 // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState
271 // is null. Otherwise the fragment manager takes care of recreating these fragments.
Yorke Leec3766332013-07-31 11:13:16 -0700272 if (savedInstanceState == null) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700273 final PhoneFavoriteFragment phoneFavoriteFragment = new PhoneFavoriteFragment();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700274
Yorke Leec3766332013-07-31 11:13:16 -0700275 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leeef2b7382013-08-09 17:39:25 -0700276 ft.add(R.id.dialtacts_frame, phoneFavoriteFragment, TAG_FAVORITES_FRAGMENT);
277 ft.add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT);
Yorke Leec3766332013-07-31 11:13:16 -0700278 ft.commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700279 } else {
280 mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
281 mInSearchUi = savedInstanceState.getBoolean(KEY_IN_SEARCH_UI);
282 mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700283 }
284
Yorke Leec3766332013-07-31 11:13:16 -0700285 mBottomPaddingView = findViewById(R.id.dialtacts_bottom_padding);
286 prepareSearchView();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700287
Chiao Cheng94b10b52012-08-17 16:59:12 -0700288 if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction())
Yorke Leec3766332013-07-31 11:13:16 -0700289 && savedInstanceState == null) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700290 setupFilterText(intent);
291 }
Yorke Leefce269a2013-08-12 11:56:04 -0700292
Yorke Lee0baa98b2013-08-22 10:55:16 -0700293 mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
Yorke Leefce269a2013-08-12 11:56:04 -0700294 SmartDialPrefix.initializeNanpSettings(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700295 }
296
297 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700298 protected void onResume() {
299 super.onResume();
Yorke Lee98702de2013-08-06 12:03:32 -0700300 if (mFirstLaunch) {
301 displayFragment(getIntent());
302 }
303 mFirstLaunch = false;
Yorke Leefce269a2013-08-12 11:56:04 -0700304 mDialerDatabaseHelper.startSmartDialUpdateThread();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700305 }
306
307 @Override
Yorke Leeef2b7382013-08-09 17:39:25 -0700308 protected void onSaveInstanceState(Bundle outState) {
309 super.onSaveInstanceState(outState);
310 outState.putString(KEY_SEARCH_QUERY, mSearchQuery);
311 outState.putBoolean(KEY_IN_SEARCH_UI, mInSearchUi);
312 outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch);
313 }
314
315 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700316 public void onAttachFragment(Fragment fragment) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700317 if (fragment instanceof DialpadFragment) {
318 mDialpadFragment = (DialpadFragment) fragment;
Yorke Leec3766332013-07-31 11:13:16 -0700319 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
Yorke Leeef2b7382013-08-09 17:39:25 -0700320 transaction.hide(mDialpadFragment);
Yorke Leec3766332013-07-31 11:13:16 -0700321 transaction.commit();
Yorke Leeef2b7382013-08-09 17:39:25 -0700322 } else if (fragment instanceof SmartDialSearchFragment) {
323 mSmartDialSearchFragment = (SmartDialSearchFragment) fragment;
Yorke Lee63ea4cd2013-08-12 11:04:47 -0700324 mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener(
325 mPhoneNumberPickerActionListener);
Yorke Leeef2b7382013-08-09 17:39:25 -0700326 } else if (fragment instanceof SearchFragment) {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700327 mRegularSearchFragment = (RegularSearchFragment) fragment;
Yorke Lee63ea4cd2013-08-12 11:04:47 -0700328 mRegularSearchFragment.setOnPhoneNumberPickerActionListener(
329 mPhoneNumberPickerActionListener);
Yorke Leeef2b7382013-08-09 17:39:25 -0700330 } else if (fragment instanceof PhoneFavoriteFragment) {
331 mPhoneFavoriteFragment = (PhoneFavoriteFragment) fragment;
Yorke Lee5781afe2013-08-12 11:12:59 -0700332 mPhoneFavoriteFragment.setListener(mPhoneFavoriteListener);
Yorke Leec3766332013-07-31 11:13:16 -0700333 }
Yorke Leec3766332013-07-31 11:13:16 -0700334 }
335
336 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700337 public boolean onMenuItemClick(MenuItem item) {
338 switch (item.getItemId()) {
339 case R.id.menu_import_export:
340 // We hard-code the "contactsAreAvailable" argument because doing it properly would
341 // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
342 // now in Dialtacts for (potential) performance reasons. Compare with how it is
343 // done in {@link PeopleActivity}.
344 ImportExportDialogFragment.show(getFragmentManager(), true,
Yorke Leef74011e2013-08-02 11:30:30 -0700345 DialtactsActivity.class);
Yorke Leec3766332013-07-31 11:13:16 -0700346 return true;
347 case R.id.menu_clear_frequents:
348 ClearFrequentsDialog.show(getFragmentManager());
349 return true;
Yorke Lee5e931972013-08-30 11:37:53 -0700350 case R.id.menu_add_contact:
Yorke Leec3766332013-07-31 11:13:16 -0700351 try {
352 startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
353 } catch (ActivityNotFoundException e) {
354 Toast toast = Toast.makeText(this,
355 R.string.add_contact_not_available,
356 Toast.LENGTH_SHORT);
357 toast.show();
358 }
359 return true;
360 case R.id.menu_call_settings:
Yorke Leef74011e2013-08-02 11:30:30 -0700361 final Intent settingsIntent = DialtactsActivity.getCallSettingsIntent();
Yorke Leec3766332013-07-31 11:13:16 -0700362 startActivity(settingsIntent);
Yorke Lee5e931972013-08-30 11:37:53 -0700363 return true;
364 case R.id.menu_all_contacts:
365 onShowAllContacts();
366 return true;
Yorke Leec3766332013-07-31 11:13:16 -0700367 }
368 return false;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700369 }
370
371 @Override
372 public void onClick(View view) {
373 switch (view.getId()) {
Yorke Leec3766332013-07-31 11:13:16 -0700374 case R.id.overflow_menu: {
375 final PopupMenu popupMenu = new PopupMenu(DialtactsActivity.this, view);
376 final Menu menu = popupMenu.getMenu();
Yorke Lee8898cd02013-08-08 10:24:27 -0700377 popupMenu.inflate(R.menu.dialtacts_options);
Yorke Leef420a532013-08-09 15:16:10 -0700378 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Yorke Lee0d391b42013-08-09 17:27:00 -0700379 clearFrequents.setVisible(mPhoneFavoriteFragment.hasFrequents());
Yorke Leec3766332013-07-31 11:13:16 -0700380 popupMenu.setOnMenuItemClickListener(this);
381 popupMenu.show();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700382 break;
383 }
Yorke Leec3766332013-07-31 11:13:16 -0700384 case R.id.dialpad_button:
385 showDialpadFragment(true);
386 break;
387 case R.id.call_history_on_dialpad_button:
388 case R.id.call_history_button:
Yorke Leef420a532013-08-09 15:16:10 -0700389 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
390 // CONTENT_TYPE, so that we always open our call log from our dialer
Yorke Leec3766332013-07-31 11:13:16 -0700391 final Intent intent = new Intent(this, CallLogActivity.class);
392 startActivity(intent);
393 break;
394 case R.id.search_close_button:
395 // Clear the search field
396 if (!TextUtils.isEmpty(mSearchView.getText())) {
397 mSearchView.setText("");
Chiao Cheng94b10b52012-08-17 16:59:12 -0700398 }
399 break;
Yorke Leec3766332013-07-31 11:13:16 -0700400 case R.id.voice_search_button:
401 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
402 startActivityForResult(voiceIntent, ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
403 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700404 default: {
405 Log.wtf(TAG, "Unexpected onClick event from " + view);
406 break;
407 }
408 }
409 }
410
Yorke Leec3766332013-07-31 11:13:16 -0700411 @Override
412 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
413 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
414 if (resultCode == RESULT_OK) {
415 final ArrayList<String> matches = data.getStringArrayListExtra(
416 RecognizerIntent.EXTRA_RESULTS);
417 if (matches.size() > 0) {
418 final String match = matches.get(0);
419 mSearchView.setText(match);
420 } else {
421 Log.e(TAG, "Voice search - nothing heard");
422 }
423 } else {
424 Log.e(TAG, "Voice search failed");
425 }
426 }
427 super.onActivityResult(requestCode, resultCode, data);
428 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700429
Yorke Leec3766332013-07-31 11:13:16 -0700430 private void showDialpadFragment(boolean animate) {
Yorke Leeea695cb2013-08-09 11:02:26 -0700431 mDialpadFragment.setAdjustTranslationForAnimation(animate);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700432 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700433 if (animate) {
434 ft.setCustomAnimations(R.anim.slide_in, 0);
Yorke Leeea695cb2013-08-09 11:02:26 -0700435 } else {
436 mDialpadFragment.setYFraction(0);
Yorke Leec3766332013-07-31 11:13:16 -0700437 }
438 ft.show(mDialpadFragment);
439 ft.commit();
440 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700441
Yorke Leef6673d32013-08-23 15:34:17 -0700442 private void hideDialpadFragment(boolean animate, boolean clearDialpad) {
443 if (mDialpadFragment == null) return;
444 if (clearDialpad) {
445 mDialpadFragment.clearDialpad();
446 }
447 if (!mDialpadFragment.isVisible()) return;
Yorke Leeea695cb2013-08-09 11:02:26 -0700448 mDialpadFragment.setAdjustTranslationForAnimation(animate);
Yorke Leec3766332013-07-31 11:13:16 -0700449 final FragmentTransaction ft = getFragmentManager().beginTransaction();
450 if (animate) {
451 ft.setCustomAnimations(0, R.anim.slide_out);
452 }
453 ft.hide(mDialpadFragment);
454 ft.commit();
455 }
456
Chiao Cheng94b10b52012-08-17 16:59:12 -0700457 private void prepareSearchView() {
Yorke Leec3766332013-07-31 11:13:16 -0700458 mSearchViewContainer = findViewById(R.id.search_view_container);
459 mSearchViewCloseButton = findViewById(R.id.search_close_button);
460 mSearchViewCloseButton.setOnClickListener(this);
461 mVoiceSearchButton = findViewById(R.id.voice_search_button);
462 mVoiceSearchButton.setOnClickListener(this);
463 mSearchView = (EditText) findViewById(R.id.search_view);
464 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
465 mSearchView.setHint(getString(R.string.dialer_hint_find_contact));
466 mSearchView.setOnFocusChangeListener(new OnFocusChangeListener() {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700467 @Override
468 public void onFocusChange(View view, boolean hasFocus) {
469 if (hasFocus) {
470 showInputMethod(view.findFocus());
471 }
472 }
473 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700474 }
475
Yorke Leec3766332013-07-31 11:13:16 -0700476 final AnimatorListener mHideListener = new AnimatorListenerAdapter() {
477 @Override
478 public void onAnimationEnd(Animator animation) {
479 mSearchViewContainer.setVisibility(View.GONE);
480 }
481 };
Chiao Cheng94b10b52012-08-17 16:59:12 -0700482
Yorke Lee311969c2013-08-26 06:31:11 -0700483 private void hideDialpadAndSearchUi() {
484 if (mInSearchUi) {
485 exitSearchUi();
486 }
487 hideDialpadFragment(false, true);
488 }
489
Yorke Leec3766332013-07-31 11:13:16 -0700490 public void hideSearchBar() {
491 hideSearchBar(true);
Christine Chen9c1e0652013-05-23 15:40:19 -0700492 }
493
Yorke Leec3766332013-07-31 11:13:16 -0700494 public void hideSearchBar(boolean shiftView) {
495 if (shiftView) {
496 mSearchViewContainer.animate().cancel();
497 mSearchViewContainer.setAlpha(1);
498 mSearchViewContainer.setTranslationY(0);
499 mSearchViewContainer.animate().withLayer().alpha(0).translationY(-mSearchView.getHeight())
500 .setDuration(200).setListener(mHideListener);
501
Yorke Leeef2b7382013-08-09 17:39:25 -0700502 if (mPhoneFavoriteFragment == null || mPhoneFavoriteFragment.getView() == null) {
503 mBottomPaddingView.setVisibility(View.VISIBLE);
504 return;
505 }
506
Yorke Leec3766332013-07-31 11:13:16 -0700507 mPhoneFavoriteFragment.getView().animate().withLayer()
508 .translationY(-mSearchViewContainer.getHeight()).setDuration(200).setListener(
509 new AnimatorListenerAdapter() {
510 @Override
511 public void onAnimationEnd(Animator animation) {
512 mBottomPaddingView.setVisibility(View.VISIBLE);
Yorke Leeef2b7382013-08-09 17:39:25 -0700513 if (mPhoneFavoriteFragment.getView() != null) {
514 mPhoneFavoriteFragment.getView().setTranslationY(0);
515 }
Yorke Leec3766332013-07-31 11:13:16 -0700516 }
517 });
518 } else {
519 mSearchViewContainer.setTranslationY(-mSearchView.getHeight());
520 }
521 }
522
523 public void showSearchBar() {
Yorke Leeef2b7382013-08-09 17:39:25 -0700524
525
Yorke Leec3766332013-07-31 11:13:16 -0700526 mSearchViewContainer.animate().cancel();
527 mSearchViewContainer.setAlpha(0);
528 mSearchViewContainer.setTranslationY(-mSearchViewContainer.getHeight());
529 mSearchViewContainer.animate().withLayer().alpha(1).translationY(0).setDuration(200)
530 .setListener(new AnimatorListenerAdapter() {
531 @Override
532 public void onAnimationStart(Animator animation) {
533 mSearchViewContainer.setVisibility(View.VISIBLE);
534 }
535 });
536
Yorke Leeef2b7382013-08-09 17:39:25 -0700537 // If the favorites fragment hasn't been fully created before the dialpad fragment
538 // is hidden (i.e. onResume), don't bother animating
539 if (mPhoneFavoriteFragment == null || mPhoneFavoriteFragment.getView() == null) {
540 mBottomPaddingView.setVisibility(View.GONE);
541 return;
542 }
Yorke Leec3766332013-07-31 11:13:16 -0700543 mPhoneFavoriteFragment.getView().setTranslationY(-mSearchViewContainer.getHeight());
544 mPhoneFavoriteFragment.getView().animate().withLayer().translationY(0).setDuration(200)
545 .setListener(
546 new AnimatorListenerAdapter() {
547 @Override
548 public void onAnimationStart(Animator animation) {
549 mBottomPaddingView.setVisibility(View.GONE);
550 }
551 });
552 }
553
554
555 public void setupFakeActionBarItemsForFavoritesFragment() {
556 mMenuButton = findViewById(R.id.overflow_menu);
557 if (mMenuButton != null) {
558 mMenuButton.setOnClickListener(this);
559 }
560
561 mCallHistoryButton = findViewById(R.id.call_history_button);
562 // mCallHistoryButton.setMinimumWidth(fakeMenuItemWidth);
563 mCallHistoryButton.setOnClickListener(this);
564
565 mDialpadButton = findViewById(R.id.dialpad_button);
566 // DialpadButton.setMinimumWidth(fakeMenuItemWidth);
567 mDialpadButton.setOnClickListener(this);
568 }
569
570 public void setupFakeActionBarItemsForDialpadFragment() {
571 final View callhistoryButton = findViewById(R.id.call_history_on_dialpad_button);
572 callhistoryButton.setOnClickListener(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700573 }
574
575 private void fixIntent(Intent intent) {
576 // This should be cleaned up: the call key used to send an Intent
577 // that just said to go to the recent calls list. It now sends this
578 // abstract action, but this class hasn't been rewritten to deal with it.
579 if (Intent.ACTION_CALL_BUTTON.equals(intent.getAction())) {
580 intent.setDataAndType(Calls.CONTENT_URI, Calls.CONTENT_TYPE);
581 intent.putExtra("call_key", true);
582 setIntent(intent);
583 }
584 }
585
Chiao Cheng94b10b52012-08-17 16:59:12 -0700586 /**
587 * Returns true if the intent is due to hitting the green send key (hardware call button:
588 * KEYCODE_CALL) while in a call.
589 *
590 * @param intent the intent that launched this activity
591 * @param recentCallsRequest true if the intent is requesting to view recent calls
592 * @return true if the intent is due to hitting the green send key while in a call
593 */
Yorke Leec3766332013-07-31 11:13:16 -0700594 private boolean isSendKeyWhileInCall(Intent intent, boolean recentCallsRequest) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700595 // If there is a call in progress go to the call screen
596 if (recentCallsRequest) {
597 final boolean callKey = intent.getBooleanExtra("call_key", false);
598
599 try {
600 ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
601 if (callKey && phone != null && phone.showCallScreen()) {
602 return true;
603 }
604 } catch (RemoteException e) {
605 Log.e(TAG, "Failed to handle send while in call", e);
606 }
607 }
608
609 return false;
610 }
611
612 /**
613 * Sets the current tab based on the intent's request type
614 *
615 * @param intent Intent that contains information about which tab should be selected
616 */
Yorke Leec3766332013-07-31 11:13:16 -0700617 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700618 // If we got here by hitting send and we're in call forward along to the in-call activity
619 boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent.resolveType(
620 getContentResolver()));
621 if (isSendKeyWhileInCall(intent, recentCallsRequest)) {
622 finish();
623 return;
624 }
625
Yorke Lee98702de2013-08-06 12:03:32 -0700626 if (mDialpadFragment != null && (phoneIsInUse() || isDialIntent(intent))) {
Yorke Leec3766332013-07-31 11:13:16 -0700627 mDialpadFragment.setStartedFromNewIntent(true);
Yorke Leeea695cb2013-08-09 11:02:26 -0700628 showDialpadFragment(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700629 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700630 }
631
632 @Override
633 public void onNewIntent(Intent newIntent) {
634 setIntent(newIntent);
635 fixIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700636 displayFragment(newIntent);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700637 final String action = newIntent.getAction();
Yorke Leec3766332013-07-31 11:13:16 -0700638
Chiao Cheng94b10b52012-08-17 16:59:12 -0700639 invalidateOptionsMenu();
640 }
641
642 /** Returns true if the given intent contains a phone number to populate the dialer with */
643 private boolean isDialIntent(Intent intent) {
644 final String action = intent.getAction();
645 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
646 return true;
647 }
648 if (Intent.ACTION_VIEW.equals(action)) {
649 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700650 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700651 return true;
652 }
653 }
654 return false;
655 }
656
657 /**
658 * Returns an appropriate call origin for this Activity. May return null when no call origin
659 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
660 * for remembering the tab in which the user made a phone call, so the external app's DIAL
661 * request should not be counted.)
662 */
663 public String getCallOrigin() {
664 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
665 }
666
667 /**
668 * Retrieves the filter text stored in {@link #setupFilterText(Intent)}.
669 * This text originally came from a FILTER_CONTACTS_ACTION intent received
670 * by this activity. The stored text will then be cleared after after this
671 * method returns.
672 *
673 * @return The stored filter text
674 */
675 public String getAndClearFilterText() {
676 String filterText = mFilterText;
677 mFilterText = null;
678 return filterText;
679 }
680
681 /**
682 * Stores the filter text associated with a FILTER_CONTACTS_ACTION intent.
683 * This is so child activities can check if they are supposed to display a filter.
684 *
685 * @param intent The intent received in {@link #onNewIntent(Intent)}
686 */
687 private void setupFilterText(Intent intent) {
688 // If the intent was relaunched from history, don't apply the filter text.
689 if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
690 return;
691 }
692 String filter = intent.getStringExtra(UI.FILTER_TEXT_EXTRA_KEY);
693 if (filter != null && filter.length() > 0) {
694 mFilterText = filter;
695 }
696 }
697
Yorke Lee8898cd02013-08-08 10:24:27 -0700698 private final PhoneFavoriteFragment.Listener mPhoneFavoriteListener =
699 new PhoneFavoriteFragment.Listener() {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700700 @Override
701 public void onContactSelected(Uri contactUri) {
702 PhoneNumberInteraction.startInteractionForPhoneCall(
Yorke Leec3766332013-07-31 11:13:16 -0700703 DialtactsActivity.this, contactUri, getCallOrigin());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700704 }
705
706 @Override
707 public void onCallNumberDirectly(String phoneNumber) {
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700708 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700709 startActivity(intent);
710 }
711 };
712
Yorke Leec3766332013-07-31 11:13:16 -0700713 /* TODO krelease: This is only relevant for phones that have a hard button search key (i.e.
714 * Nexus S). Supporting it is a little more tricky because of the dialpad fragment might
715 * be showing when the search key is pressed so there is more state management involved.
Chiao Cheng94b10b52012-08-17 16:59:12 -0700716
717 @Override
718 public void startSearch(String initialQuery, boolean selectInitialQuery,
719 Bundle appSearchData, boolean globalSearch) {
Yorke Leec3766332013-07-31 11:13:16 -0700720 if (mRegularSearchFragment != null && mRegularSearchFragment.isAdded() && !globalSearch) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700721 if (mInSearchUi) {
722 if (mSearchView.hasFocus()) {
723 showInputMethod(mSearchView.findFocus());
724 } else {
725 mSearchView.requestFocus();
726 }
727 } else {
728 enterSearchUi();
729 }
730 } else {
731 super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
732 }
Yorke Leec3766332013-07-31 11:13:16 -0700733 }*/
Chiao Cheng94b10b52012-08-17 16:59:12 -0700734
735 private void showInputMethod(View view) {
Yorke Leec3766332013-07-31 11:13:16 -0700736 final InputMethodManager imm = (InputMethodManager) getSystemService(
737 Context.INPUT_METHOD_SERVICE);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700738 if (imm != null) {
Yorke Leec3766332013-07-31 11:13:16 -0700739 imm.showSoftInput(view, 0);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700740 }
741 }
742
743 private void hideInputMethod(View view) {
Yorke Leec3766332013-07-31 11:13:16 -0700744 final InputMethodManager imm = (InputMethodManager) getSystemService(
745 Context.INPUT_METHOD_SERVICE);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700746 if (imm != null && view != null) {
747 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
748 }
749 }
750
751 /**
Yorke Leec3766332013-07-31 11:13:16 -0700752 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700753 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700754 private void enterSearchUi(boolean smartDialSearch, String query) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700755 if (getFragmentManager().isDestroyed()) {
756 // Weird race condition where fragment is doing work after the activity is destroyed
757 // due to talkback being on (b/10209937). Just return since we can't do any
758 // constructive here.
759 return;
760 }
761
Yorke Leeef2b7382013-08-09 17:39:25 -0700762 if (DEBUG) {
763 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
764 }
765 final String tag = smartDialSearch ? TAG_SMARTDIAL_SEARCH_FRAGMENT :
766 TAG_REGULAR_SEARCH_FRAGMENT;
767
Yorke Leec3766332013-07-31 11:13:16 -0700768 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
769 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700770
Yorke Leeef2b7382013-08-09 17:39:25 -0700771 SearchFragment fragment;
772
773 transaction.remove(mPhoneFavoriteFragment);
774 fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
775 if (fragment == null) {
776 if (smartDialSearch) {
777 fragment = new SmartDialSearchFragment();
778 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700779 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700780 }
781 transaction.replace(R.id.dialtacts_frame, fragment, tag);
782 } else {
783 transaction.attach(fragment);
784 }
785
786 transaction.addToBackStack(null);
787 fragment.setQueryString(query, false);
788 transaction.commit();
Yorke Leec3766332013-07-31 11:13:16 -0700789 mInSearchUi = true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700790 }
791
792 /**
Yorke Leec3766332013-07-31 11:13:16 -0700793 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700794 */
Yorke Leec3766332013-07-31 11:13:16 -0700795 private void exitSearchUi() {
Yorke Leeef2b7382013-08-09 17:39:25 -0700796 getFragmentManager().popBackStack();
Yorke Leec3766332013-07-31 11:13:16 -0700797 mInSearchUi = false;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700798 }
799
800 /** Returns an Intent to launch Call Settings screen */
801 public static Intent getCallSettingsIntent() {
802 final Intent intent = new Intent(Intent.ACTION_MAIN);
803 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
804 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
805 return intent;
806 }
807
808 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700809 public void onBackPressed() {
Yorke Leeef2b7382013-08-09 17:39:25 -0700810 if (mDialpadFragment != null && mDialpadFragment.isVisible()) {
Yorke Leef6673d32013-08-23 15:34:17 -0700811 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -0700812 } else if (mInSearchUi) {
813 mSearchView.setText(null);
Yorke Leef6673d32013-08-23 15:34:17 -0700814 mDialpadFragment.clearDialpad();
Yorke Leec3766332013-07-31 11:13:16 -0700815 } else if (isTaskRoot()) {
816 // Instead of stopping, simply push this to the back of the stack.
817 // This is only done when running at the top of the stack;
818 // otherwise, we have been launched by someone else so need to
819 // allow the user to go back to the caller.
820 moveTaskToBack(false);
821 } else {
822 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700823 }
Yorke Leec3766332013-07-31 11:13:16 -0700824 }
825
826 @Override
827 public void onDialpadQueryChanged(String query) {
828 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
829 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
830 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700831 if (DEBUG) {
832 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
833 }
834 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
835 // This callback can happen if the dialpad fragment is recreated because of
836 // activity destruction. In that case, don't update the search view because
837 // that would bring the user back to the search fragment regardless of the
838 // previous state of the application. Instead, just return here and let the
839 // fragment manager correctly figure out whatever fragment was last displayed.
840 return;
841 }
Yorke Leec3766332013-07-31 11:13:16 -0700842 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700843 }
844 }
Yorke Leec3766332013-07-31 11:13:16 -0700845
846 @Override
847 public void onListFragmentScrollStateChange(int scrollState) {
848 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700849 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -0700850 hideInputMethod(getCurrentFocus());
851 }
852 }
853
854 @Override
855 public void onPhoneFavoriteFragmentStarted() {
856 setupFakeActionBarItemsForFavoritesFragment();
857 }
858
859 @Override
860 public void onDialpadFragmentStarted() {
861 setupFakeActionBarItemsForDialpadFragment();
862 }
863
864 private boolean phoneIsInUse() {
865 final TelephonyManager tm = (TelephonyManager) getSystemService(
866 Context.TELEPHONY_SERVICE);
867 return tm.getCallState() != TelephonyManager.CALL_STATE_IDLE;
868 }
Yorke Lee8dd62002013-08-08 15:57:20 -0700869
870 @Override
871 public void onShowAllContacts() {
872 final Intent intent = new Intent(this, AllContactsActivity.class);
873 startActivity(intent);
874 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700875}