blob: 4e5592a521c9d1d03b945a48a66a6aab264ce402 [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;
350 case R.id.add_contact:
351 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);
363 }
364 return false;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700365 }
366
367 @Override
368 public void onClick(View view) {
369 switch (view.getId()) {
Yorke Leec3766332013-07-31 11:13:16 -0700370 case R.id.overflow_menu: {
371 final PopupMenu popupMenu = new PopupMenu(DialtactsActivity.this, view);
372 final Menu menu = popupMenu.getMenu();
Yorke Lee8898cd02013-08-08 10:24:27 -0700373 popupMenu.inflate(R.menu.dialtacts_options);
Yorke Leef420a532013-08-09 15:16:10 -0700374 final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents);
Yorke Lee0d391b42013-08-09 17:27:00 -0700375 clearFrequents.setVisible(mPhoneFavoriteFragment.hasFrequents());
Yorke Leec3766332013-07-31 11:13:16 -0700376 popupMenu.setOnMenuItemClickListener(this);
377 popupMenu.show();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700378 break;
379 }
Yorke Leec3766332013-07-31 11:13:16 -0700380 case R.id.dialpad_button:
381 showDialpadFragment(true);
382 break;
383 case R.id.call_history_on_dialpad_button:
384 case R.id.call_history_button:
Yorke Leef420a532013-08-09 15:16:10 -0700385 // Use explicit CallLogActivity intent instead of ACTION_VIEW +
386 // CONTENT_TYPE, so that we always open our call log from our dialer
Yorke Leec3766332013-07-31 11:13:16 -0700387 final Intent intent = new Intent(this, CallLogActivity.class);
388 startActivity(intent);
389 break;
390 case R.id.search_close_button:
391 // Clear the search field
392 if (!TextUtils.isEmpty(mSearchView.getText())) {
393 mSearchView.setText("");
Chiao Cheng94b10b52012-08-17 16:59:12 -0700394 }
395 break;
Yorke Leec3766332013-07-31 11:13:16 -0700396 case R.id.voice_search_button:
397 final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
398 startActivityForResult(voiceIntent, ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
399 break;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700400 default: {
401 Log.wtf(TAG, "Unexpected onClick event from " + view);
402 break;
403 }
404 }
405 }
406
Yorke Leec3766332013-07-31 11:13:16 -0700407 @Override
408 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
409 if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
410 if (resultCode == RESULT_OK) {
411 final ArrayList<String> matches = data.getStringArrayListExtra(
412 RecognizerIntent.EXTRA_RESULTS);
413 if (matches.size() > 0) {
414 final String match = matches.get(0);
415 mSearchView.setText(match);
416 } else {
417 Log.e(TAG, "Voice search - nothing heard");
418 }
419 } else {
420 Log.e(TAG, "Voice search failed");
421 }
422 }
423 super.onActivityResult(requestCode, resultCode, data);
424 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700425
Yorke Leec3766332013-07-31 11:13:16 -0700426 private void showDialpadFragment(boolean animate) {
Yorke Leeea695cb2013-08-09 11:02:26 -0700427 mDialpadFragment.setAdjustTranslationForAnimation(animate);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700428 final FragmentTransaction ft = getFragmentManager().beginTransaction();
Yorke Leec3766332013-07-31 11:13:16 -0700429 if (animate) {
430 ft.setCustomAnimations(R.anim.slide_in, 0);
Yorke Leeea695cb2013-08-09 11:02:26 -0700431 } else {
432 mDialpadFragment.setYFraction(0);
Yorke Leec3766332013-07-31 11:13:16 -0700433 }
434 ft.show(mDialpadFragment);
435 ft.commit();
436 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700437
Yorke Leef6673d32013-08-23 15:34:17 -0700438 private void hideDialpadFragment(boolean animate, boolean clearDialpad) {
439 if (mDialpadFragment == null) return;
440 if (clearDialpad) {
441 mDialpadFragment.clearDialpad();
442 }
443 if (!mDialpadFragment.isVisible()) return;
Yorke Leeea695cb2013-08-09 11:02:26 -0700444 mDialpadFragment.setAdjustTranslationForAnimation(animate);
Yorke Leec3766332013-07-31 11:13:16 -0700445 final FragmentTransaction ft = getFragmentManager().beginTransaction();
446 if (animate) {
447 ft.setCustomAnimations(0, R.anim.slide_out);
448 }
449 ft.hide(mDialpadFragment);
450 ft.commit();
451 }
452
Chiao Cheng94b10b52012-08-17 16:59:12 -0700453 private void prepareSearchView() {
Yorke Leec3766332013-07-31 11:13:16 -0700454 mSearchViewContainer = findViewById(R.id.search_view_container);
455 mSearchViewCloseButton = findViewById(R.id.search_close_button);
456 mSearchViewCloseButton.setOnClickListener(this);
457 mVoiceSearchButton = findViewById(R.id.voice_search_button);
458 mVoiceSearchButton.setOnClickListener(this);
459 mSearchView = (EditText) findViewById(R.id.search_view);
460 mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener);
461 mSearchView.setHint(getString(R.string.dialer_hint_find_contact));
462 mSearchView.setOnFocusChangeListener(new OnFocusChangeListener() {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700463 @Override
464 public void onFocusChange(View view, boolean hasFocus) {
465 if (hasFocus) {
466 showInputMethod(view.findFocus());
467 }
468 }
469 });
Chiao Cheng94b10b52012-08-17 16:59:12 -0700470 }
471
Yorke Leec3766332013-07-31 11:13:16 -0700472 final AnimatorListener mHideListener = new AnimatorListenerAdapter() {
473 @Override
474 public void onAnimationEnd(Animator animation) {
475 mSearchViewContainer.setVisibility(View.GONE);
476 }
477 };
Chiao Cheng94b10b52012-08-17 16:59:12 -0700478
Yorke Lee311969c2013-08-26 06:31:11 -0700479 private void hideDialpadAndSearchUi() {
480 if (mInSearchUi) {
481 exitSearchUi();
482 }
483 hideDialpadFragment(false, true);
484 }
485
Yorke Leec3766332013-07-31 11:13:16 -0700486 public void hideSearchBar() {
487 hideSearchBar(true);
Christine Chen9c1e0652013-05-23 15:40:19 -0700488 }
489
Yorke Leec3766332013-07-31 11:13:16 -0700490 public void hideSearchBar(boolean shiftView) {
491 if (shiftView) {
492 mSearchViewContainer.animate().cancel();
493 mSearchViewContainer.setAlpha(1);
494 mSearchViewContainer.setTranslationY(0);
495 mSearchViewContainer.animate().withLayer().alpha(0).translationY(-mSearchView.getHeight())
496 .setDuration(200).setListener(mHideListener);
497
Yorke Leeef2b7382013-08-09 17:39:25 -0700498 if (mPhoneFavoriteFragment == null || mPhoneFavoriteFragment.getView() == null) {
499 mBottomPaddingView.setVisibility(View.VISIBLE);
500 return;
501 }
502
Yorke Leec3766332013-07-31 11:13:16 -0700503 mPhoneFavoriteFragment.getView().animate().withLayer()
504 .translationY(-mSearchViewContainer.getHeight()).setDuration(200).setListener(
505 new AnimatorListenerAdapter() {
506 @Override
507 public void onAnimationEnd(Animator animation) {
508 mBottomPaddingView.setVisibility(View.VISIBLE);
Yorke Leeef2b7382013-08-09 17:39:25 -0700509 if (mPhoneFavoriteFragment.getView() != null) {
510 mPhoneFavoriteFragment.getView().setTranslationY(0);
511 }
Yorke Leec3766332013-07-31 11:13:16 -0700512 }
513 });
514 } else {
515 mSearchViewContainer.setTranslationY(-mSearchView.getHeight());
516 }
517 }
518
519 public void showSearchBar() {
Yorke Leeef2b7382013-08-09 17:39:25 -0700520
521
Yorke Leec3766332013-07-31 11:13:16 -0700522 mSearchViewContainer.animate().cancel();
523 mSearchViewContainer.setAlpha(0);
524 mSearchViewContainer.setTranslationY(-mSearchViewContainer.getHeight());
525 mSearchViewContainer.animate().withLayer().alpha(1).translationY(0).setDuration(200)
526 .setListener(new AnimatorListenerAdapter() {
527 @Override
528 public void onAnimationStart(Animator animation) {
529 mSearchViewContainer.setVisibility(View.VISIBLE);
530 }
531 });
532
Yorke Leeef2b7382013-08-09 17:39:25 -0700533 // If the favorites fragment hasn't been fully created before the dialpad fragment
534 // is hidden (i.e. onResume), don't bother animating
535 if (mPhoneFavoriteFragment == null || mPhoneFavoriteFragment.getView() == null) {
536 mBottomPaddingView.setVisibility(View.GONE);
537 return;
538 }
Yorke Leec3766332013-07-31 11:13:16 -0700539 mPhoneFavoriteFragment.getView().setTranslationY(-mSearchViewContainer.getHeight());
540 mPhoneFavoriteFragment.getView().animate().withLayer().translationY(0).setDuration(200)
541 .setListener(
542 new AnimatorListenerAdapter() {
543 @Override
544 public void onAnimationStart(Animator animation) {
545 mBottomPaddingView.setVisibility(View.GONE);
546 }
547 });
548 }
549
550
551 public void setupFakeActionBarItemsForFavoritesFragment() {
552 mMenuButton = findViewById(R.id.overflow_menu);
553 if (mMenuButton != null) {
554 mMenuButton.setOnClickListener(this);
555 }
556
557 mCallHistoryButton = findViewById(R.id.call_history_button);
558 // mCallHistoryButton.setMinimumWidth(fakeMenuItemWidth);
559 mCallHistoryButton.setOnClickListener(this);
560
561 mDialpadButton = findViewById(R.id.dialpad_button);
562 // DialpadButton.setMinimumWidth(fakeMenuItemWidth);
563 mDialpadButton.setOnClickListener(this);
564 }
565
566 public void setupFakeActionBarItemsForDialpadFragment() {
567 final View callhistoryButton = findViewById(R.id.call_history_on_dialpad_button);
568 callhistoryButton.setOnClickListener(this);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700569 }
570
571 private void fixIntent(Intent intent) {
572 // This should be cleaned up: the call key used to send an Intent
573 // that just said to go to the recent calls list. It now sends this
574 // abstract action, but this class hasn't been rewritten to deal with it.
575 if (Intent.ACTION_CALL_BUTTON.equals(intent.getAction())) {
576 intent.setDataAndType(Calls.CONTENT_URI, Calls.CONTENT_TYPE);
577 intent.putExtra("call_key", true);
578 setIntent(intent);
579 }
580 }
581
Chiao Cheng94b10b52012-08-17 16:59:12 -0700582 /**
583 * Returns true if the intent is due to hitting the green send key (hardware call button:
584 * KEYCODE_CALL) while in a call.
585 *
586 * @param intent the intent that launched this activity
587 * @param recentCallsRequest true if the intent is requesting to view recent calls
588 * @return true if the intent is due to hitting the green send key while in a call
589 */
Yorke Leec3766332013-07-31 11:13:16 -0700590 private boolean isSendKeyWhileInCall(Intent intent, boolean recentCallsRequest) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700591 // If there is a call in progress go to the call screen
592 if (recentCallsRequest) {
593 final boolean callKey = intent.getBooleanExtra("call_key", false);
594
595 try {
596 ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
597 if (callKey && phone != null && phone.showCallScreen()) {
598 return true;
599 }
600 } catch (RemoteException e) {
601 Log.e(TAG, "Failed to handle send while in call", e);
602 }
603 }
604
605 return false;
606 }
607
608 /**
609 * Sets the current tab based on the intent's request type
610 *
611 * @param intent Intent that contains information about which tab should be selected
612 */
Yorke Leec3766332013-07-31 11:13:16 -0700613 private void displayFragment(Intent intent) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700614 // If we got here by hitting send and we're in call forward along to the in-call activity
615 boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent.resolveType(
616 getContentResolver()));
617 if (isSendKeyWhileInCall(intent, recentCallsRequest)) {
618 finish();
619 return;
620 }
621
Yorke Lee98702de2013-08-06 12:03:32 -0700622 if (mDialpadFragment != null && (phoneIsInUse() || isDialIntent(intent))) {
Yorke Leec3766332013-07-31 11:13:16 -0700623 mDialpadFragment.setStartedFromNewIntent(true);
Yorke Leeea695cb2013-08-09 11:02:26 -0700624 showDialpadFragment(false);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700625 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700626 }
627
628 @Override
629 public void onNewIntent(Intent newIntent) {
630 setIntent(newIntent);
631 fixIntent(newIntent);
Yorke Leec3766332013-07-31 11:13:16 -0700632 displayFragment(newIntent);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700633 final String action = newIntent.getAction();
Yorke Leec3766332013-07-31 11:13:16 -0700634
Chiao Cheng94b10b52012-08-17 16:59:12 -0700635 invalidateOptionsMenu();
636 }
637
638 /** Returns true if the given intent contains a phone number to populate the dialer with */
639 private boolean isDialIntent(Intent intent) {
640 final String action = intent.getAction();
641 if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) {
642 return true;
643 }
644 if (Intent.ACTION_VIEW.equals(action)) {
645 final Uri data = intent.getData();
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700646 if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700647 return true;
648 }
649 }
650 return false;
651 }
652
653 /**
654 * Returns an appropriate call origin for this Activity. May return null when no call origin
655 * should be used (e.g. when some 3rd party application launched the screen. Call origin is
656 * for remembering the tab in which the user made a phone call, so the external app's DIAL
657 * request should not be counted.)
658 */
659 public String getCallOrigin() {
660 return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null;
661 }
662
663 /**
664 * Retrieves the filter text stored in {@link #setupFilterText(Intent)}.
665 * This text originally came from a FILTER_CONTACTS_ACTION intent received
666 * by this activity. The stored text will then be cleared after after this
667 * method returns.
668 *
669 * @return The stored filter text
670 */
671 public String getAndClearFilterText() {
672 String filterText = mFilterText;
673 mFilterText = null;
674 return filterText;
675 }
676
677 /**
678 * Stores the filter text associated with a FILTER_CONTACTS_ACTION intent.
679 * This is so child activities can check if they are supposed to display a filter.
680 *
681 * @param intent The intent received in {@link #onNewIntent(Intent)}
682 */
683 private void setupFilterText(Intent intent) {
684 // If the intent was relaunched from history, don't apply the filter text.
685 if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
686 return;
687 }
688 String filter = intent.getStringExtra(UI.FILTER_TEXT_EXTRA_KEY);
689 if (filter != null && filter.length() > 0) {
690 mFilterText = filter;
691 }
692 }
693
Yorke Lee8898cd02013-08-08 10:24:27 -0700694 private final PhoneFavoriteFragment.Listener mPhoneFavoriteListener =
695 new PhoneFavoriteFragment.Listener() {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700696 @Override
697 public void onContactSelected(Uri contactUri) {
698 PhoneNumberInteraction.startInteractionForPhoneCall(
Yorke Leec3766332013-07-31 11:13:16 -0700699 DialtactsActivity.this, contactUri, getCallOrigin());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700700 }
701
702 @Override
703 public void onCallNumberDirectly(String phoneNumber) {
Chiao Cheng9d4f3b22012-09-05 16:00:16 -0700704 Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin());
Chiao Cheng94b10b52012-08-17 16:59:12 -0700705 startActivity(intent);
706 }
707 };
708
Yorke Leec3766332013-07-31 11:13:16 -0700709 /* TODO krelease: This is only relevant for phones that have a hard button search key (i.e.
710 * Nexus S). Supporting it is a little more tricky because of the dialpad fragment might
711 * be showing when the search key is pressed so there is more state management involved.
Chiao Cheng94b10b52012-08-17 16:59:12 -0700712
713 @Override
714 public void startSearch(String initialQuery, boolean selectInitialQuery,
715 Bundle appSearchData, boolean globalSearch) {
Yorke Leec3766332013-07-31 11:13:16 -0700716 if (mRegularSearchFragment != null && mRegularSearchFragment.isAdded() && !globalSearch) {
Chiao Cheng94b10b52012-08-17 16:59:12 -0700717 if (mInSearchUi) {
718 if (mSearchView.hasFocus()) {
719 showInputMethod(mSearchView.findFocus());
720 } else {
721 mSearchView.requestFocus();
722 }
723 } else {
724 enterSearchUi();
725 }
726 } else {
727 super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
728 }
Yorke Leec3766332013-07-31 11:13:16 -0700729 }*/
Chiao Cheng94b10b52012-08-17 16:59:12 -0700730
731 private void showInputMethod(View view) {
Yorke Leec3766332013-07-31 11:13:16 -0700732 final InputMethodManager imm = (InputMethodManager) getSystemService(
733 Context.INPUT_METHOD_SERVICE);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700734 if (imm != null) {
Yorke Leec3766332013-07-31 11:13:16 -0700735 imm.showSoftInput(view, 0);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700736 }
737 }
738
739 private void hideInputMethod(View view) {
Yorke Leec3766332013-07-31 11:13:16 -0700740 final InputMethodManager imm = (InputMethodManager) getSystemService(
741 Context.INPUT_METHOD_SERVICE);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700742 if (imm != null && view != null) {
743 imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
744 }
745 }
746
747 /**
Yorke Leec3766332013-07-31 11:13:16 -0700748 * Shows the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700749 */
Yorke Leeef2b7382013-08-09 17:39:25 -0700750 private void enterSearchUi(boolean smartDialSearch, String query) {
Yorke Lee34bdf872013-08-15 14:11:50 -0700751 if (getFragmentManager().isDestroyed()) {
752 // Weird race condition where fragment is doing work after the activity is destroyed
753 // due to talkback being on (b/10209937). Just return since we can't do any
754 // constructive here.
755 return;
756 }
757
Yorke Leeef2b7382013-08-09 17:39:25 -0700758 if (DEBUG) {
759 Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch);
760 }
761 final String tag = smartDialSearch ? TAG_SMARTDIAL_SEARCH_FRAGMENT :
762 TAG_REGULAR_SEARCH_FRAGMENT;
763
Yorke Leec3766332013-07-31 11:13:16 -0700764 final FragmentTransaction transaction = getFragmentManager().beginTransaction();
765 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700766
Yorke Leeef2b7382013-08-09 17:39:25 -0700767 SearchFragment fragment;
768
769 transaction.remove(mPhoneFavoriteFragment);
770 fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag);
771 if (fragment == null) {
772 if (smartDialSearch) {
773 fragment = new SmartDialSearchFragment();
774 } else {
Jay Shrauner2e5b34b2013-08-29 10:52:40 -0700775 fragment = new RegularSearchFragment();
Yorke Leeef2b7382013-08-09 17:39:25 -0700776 }
777 transaction.replace(R.id.dialtacts_frame, fragment, tag);
778 } else {
779 transaction.attach(fragment);
780 }
781
782 transaction.addToBackStack(null);
783 fragment.setQueryString(query, false);
784 transaction.commit();
Yorke Leec3766332013-07-31 11:13:16 -0700785 mInSearchUi = true;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700786 }
787
788 /**
Yorke Leec3766332013-07-31 11:13:16 -0700789 * Hides the search fragment
Chiao Cheng94b10b52012-08-17 16:59:12 -0700790 */
Yorke Leec3766332013-07-31 11:13:16 -0700791 private void exitSearchUi() {
Yorke Leeef2b7382013-08-09 17:39:25 -0700792 getFragmentManager().popBackStack();
Yorke Leec3766332013-07-31 11:13:16 -0700793 mInSearchUi = false;
Chiao Cheng94b10b52012-08-17 16:59:12 -0700794 }
795
796 /** Returns an Intent to launch Call Settings screen */
797 public static Intent getCallSettingsIntent() {
798 final Intent intent = new Intent(Intent.ACTION_MAIN);
799 intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME);
800 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
801 return intent;
802 }
803
804 @Override
Yorke Leec3766332013-07-31 11:13:16 -0700805 public void onBackPressed() {
Yorke Leeef2b7382013-08-09 17:39:25 -0700806 if (mDialpadFragment != null && mDialpadFragment.isVisible()) {
Yorke Leef6673d32013-08-23 15:34:17 -0700807 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -0700808 } else if (mInSearchUi) {
809 mSearchView.setText(null);
Yorke Leef6673d32013-08-23 15:34:17 -0700810 mDialpadFragment.clearDialpad();
Yorke Leec3766332013-07-31 11:13:16 -0700811 } else if (isTaskRoot()) {
812 // Instead of stopping, simply push this to the back of the stack.
813 // This is only done when running at the top of the stack;
814 // otherwise, we have been launched by someone else so need to
815 // allow the user to go back to the caller.
816 moveTaskToBack(false);
817 } else {
818 super.onBackPressed();
Chiao Cheng94b10b52012-08-17 16:59:12 -0700819 }
Yorke Leec3766332013-07-31 11:13:16 -0700820 }
821
822 @Override
823 public void onDialpadQueryChanged(String query) {
824 final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query,
825 SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
826 if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
Yorke Leeef2b7382013-08-09 17:39:25 -0700827 if (DEBUG) {
828 Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
829 }
830 if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
831 // This callback can happen if the dialpad fragment is recreated because of
832 // activity destruction. In that case, don't update the search view because
833 // that would bring the user back to the search fragment regardless of the
834 // previous state of the application. Instead, just return here and let the
835 // fragment manager correctly figure out whatever fragment was last displayed.
836 return;
837 }
Yorke Leec3766332013-07-31 11:13:16 -0700838 mSearchView.setText(normalizedQuery);
Chiao Cheng94b10b52012-08-17 16:59:12 -0700839 }
840 }
Yorke Leec3766332013-07-31 11:13:16 -0700841
842 @Override
843 public void onListFragmentScrollStateChange(int scrollState) {
844 if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Yorke Leef6673d32013-08-23 15:34:17 -0700845 hideDialpadFragment(true, false);
Yorke Leec3766332013-07-31 11:13:16 -0700846 hideInputMethod(getCurrentFocus());
847 }
848 }
849
850 @Override
851 public void onPhoneFavoriteFragmentStarted() {
852 setupFakeActionBarItemsForFavoritesFragment();
853 }
854
855 @Override
856 public void onDialpadFragmentStarted() {
857 setupFakeActionBarItemsForDialpadFragment();
858 }
859
860 private boolean phoneIsInUse() {
861 final TelephonyManager tm = (TelephonyManager) getSystemService(
862 Context.TELEPHONY_SERVICE);
863 return tm.getCallState() != TelephonyManager.CALL_STATE_IDLE;
864 }
Yorke Lee8dd62002013-08-08 15:57:20 -0700865
866 @Override
867 public void onShowAllContacts() {
868 final Intent intent = new Intent(this, AllContactsActivity.class);
869 startActivity(intent);
870 }
Chiao Cheng94b10b52012-08-17 16:59:12 -0700871}