DialtactsActivity.java revision fce269a30e2ec112ea4c287d97e08ef7b3b31b89
194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng/* 2c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * Copyright (C) 2013 The Android Open Source Project 394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Licensed under the Apache License, Version 2.0 (the "License"); 594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * you may not use this file except in compliance with the License. 694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * You may obtain a copy of the License at 794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * http://www.apache.org/licenses/LICENSE-2.0 994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 1094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Unless required by applicable law or agreed to in writing, software 1194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * distributed under the License is distributed on an "AS IS" BASIS, 1294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * See the License for the specific language governing permissions and 1494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * limitations under the License. 1594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 1694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 1794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengpackage com.android.dialer; 1894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 19c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.animation.Animator; 20c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.animation.Animator.AnimatorListener; 21c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.animation.AnimatorListenerAdapter; 2294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.app.Activity; 239c1e0653addc1fff03601289a9f9a57b1daeaf57Christine Chenimport android.app.backup.BackupManager; 2494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.app.Fragment; 2594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.app.FragmentManager; 2694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.app.FragmentTransaction; 27073b5cf341964796ccf082d30aff63225d3adb28Chiao Chengimport android.content.ActivityNotFoundException; 2894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.content.Context; 2994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.content.Intent; 3094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.content.SharedPreferences; 31c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.content.res.Resources; 3294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.net.Uri; 3394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.os.Bundle; 3494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.os.RemoteException; 3594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.os.ServiceManager; 3694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.provider.CallLog.Calls; 37c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.provider.ContactsContract; 3894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.provider.ContactsContract.Contacts; 3994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.provider.ContactsContract.Intents.UI; 40c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.provider.Settings; 41c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.speech.RecognizerIntent; 42c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.support.v4.app.NavUtils; 43c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.telephony.TelephonyManager; 44c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.text.Editable; 4594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.text.TextUtils; 46c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.text.TextWatcher; 4794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.util.Log; 4894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.view.Menu; 4994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.view.MenuItem; 5094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.view.View; 5194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.view.View.OnFocusChangeListener; 5294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.view.ViewConfiguration; 5394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.view.inputmethod.InputMethodManager; 54c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.widget.AbsListView.OnScrollListener; 55c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.widget.EditText; 56c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport android.widget.ImageView; 5794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.widget.PopupMenu; 5894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.widget.SearchView; 5994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.widget.SearchView.OnCloseListener; 6094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.widget.SearchView.OnQueryTextListener; 61073b5cf341964796ccf082d30aff63225d3adb28Chiao Chengimport android.widget.Toast; 6294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 639d4f3b20793a007b4489547aa40fc1049d0d8fefChiao Chengimport com.android.contacts.common.CallUtil; 64603ff6858d321e8265b3af6363a63df2827e0334Chiao Chengimport com.android.contacts.common.activity.TransactionSafeActivity; 65c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport com.android.contacts.common.dialog.ClearFrequentsDialog; 66c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport com.android.contacts.common.interactions.ImportExportDialogFragment; 671429f1a5c2b993a5013bfda7cfd75a2c43ead2bfChiao Chengimport com.android.contacts.common.list.ContactListItemView; 688efbcf920eeebc826c18b3c474e9c62b77dcd232Chiao Chengimport com.android.contacts.common.list.OnPhoneNumberPickerActionListener; 698efbcf920eeebc826c18b3c474e9c62b77dcd232Chiao Chengimport com.android.contacts.common.list.PhoneNumberPickerFragment; 70c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport com.android.dialer.calllog.CallLogActivity; 71fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Leeimport com.android.dialer.database.DialerDatabaseHelper; 72f74011e7a9b4007f6795ecee5adc2739d5fad4e6Yorke Leeimport com.android.dialer.dialpad.DialpadFragment; 73c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport com.android.dialer.dialpad.SmartDialNameMatcher; 74fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Leeimport com.android.dialer.dialpad.SmartDialPrefix; 751429f1a5c2b993a5013bfda7cfd75a2c43ead2bfChiao Chengimport com.android.dialer.interactions.PhoneNumberInteraction; 768dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Leeimport com.android.dialer.list.AllContactsActivity; 778898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Leeimport com.android.dialer.list.PhoneFavoriteFragment; 78c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport com.android.dialer.list.OnListFragmentScrolledListener; 79c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport com.android.dialer.list.SmartDialSearchFragment; 8094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport com.android.internal.telephony.ITelephony; 8194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 82c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leeimport java.util.ArrayList; 83c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 8494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng/** 8594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * The dialer tab's title is 'phone', a more common name (see strings.xml). 8694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 87c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Leepublic class DialtactsActivity extends TransactionSafeActivity implements View.OnClickListener, 88f74011e7a9b4007f6795ecee5adc2739d5fad4e6Yorke Lee DialpadFragment.OnDialpadQueryChangedListener, PopupMenu.OnMenuItemClickListener, 89c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee OnListFragmentScrolledListener, 908898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Lee PhoneFavoriteFragment.OnPhoneFavoriteFragmentStartedListener, 918dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee DialpadFragment.OnDialpadFragmentStartedListener, 928dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee PhoneFavoriteFragment.OnShowAllContactsListener { 9394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final String TAG = "DialtactsActivity"; 9494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 9594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public static final boolean DEBUG = false; 9694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 97f74011e7a9b4007f6795ecee5adc2739d5fad4e6Yorke Lee public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences"; 98f74011e7a9b4007f6795ecee5adc2739d5fad4e6Yorke Lee 9994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** Used to open Call Setting */ 10094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final String PHONE_PACKAGE = "com.android.phone"; 10194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final String CALL_SETTINGS_CLASS_NAME = 10294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng "com.android.phone.CallFeaturesSetting"; 10394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** @see #getCallOrigin() */ 10494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final String CALL_ORIGIN_DIALTACTS = 10594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng "com.android.dialer.DialtactsActivity"; 10694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 107ef2b7388569a94432278a617b528f628385fbb8cYorke Lee private static final String KEY_IN_SEARCH_UI = "in_search_ui"; 108ef2b7388569a94432278a617b528f628385fbb8cYorke Lee private static final String KEY_SEARCH_QUERY = "search_query"; 109ef2b7388569a94432278a617b528f628385fbb8cYorke Lee private static final String KEY_FIRST_LAUNCH = "first_launch"; 110ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 111c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private static final String TAG_DIALPAD_FRAGMENT = "dialpad"; 112c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private static final String TAG_REGULAR_SEARCH_FRAGMENT = "search"; 113c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private static final String TAG_SMARTDIAL_SEARCH_FRAGMENT = "smartdial"; 114c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private static final String TAG_FAVORITES_FRAGMENT = "favorites"; 115c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 11694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 11794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Just for backward compatibility. Should behave as same as {@link Intent#ACTION_DIAL}. 11894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 11994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final String ACTION_TOUCH_DIALER = "com.android.phone.action.TOUCH_DIALER"; 12094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 12194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private static final int SUBACTIVITY_ACCOUNT_FILTER = 1; 12294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 123c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1; 12494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 125c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private String mFilterText; 12694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 12794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 128c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * The main fragment displaying the user's favorites and frequent contacts 12994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 1308898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Lee private PhoneFavoriteFragment mPhoneFavoriteFragment; 131c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 13294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 133c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * Fragment containing the dialpad that slides into view 13494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 135f74011e7a9b4007f6795ecee5adc2739d5fad4e6Yorke Lee private DialpadFragment mDialpadFragment; 13694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 137c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee /** 138c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * Fragment for searching phone numbers using the alphanumeric keyboard. 139c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee */ 1408898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Lee private SearchFragment mRegularSearchFragment; 14194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 142c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee /** 143c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * Fragment for searching phone numbers using the dialpad. 144c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee */ 145c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private SmartDialSearchFragment mSmartDialSearchFragment; 14694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 14794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private View mMenuButton; 148c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private View mCallHistoryButton; 149c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private View mDialpadButton; 15094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 151c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // Padding view used to shift the fragments up when the dialpad is shown. 152c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private View mBottomPaddingView; 15394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 15494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 15594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * True when this Activity is in its search UI (with a {@link SearchView} and 15694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * {@link PhoneNumberPickerFragment}). 15794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 15894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private boolean mInSearchUi; 159ef2b7388569a94432278a617b528f628385fbb8cYorke Lee /** 160ef2b7388569a94432278a617b528f628385fbb8cYorke Lee * True when this activity has been launched for the first time. 161ef2b7388569a94432278a617b528f628385fbb8cYorke Lee */ 16298702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee private boolean mFirstLaunch; 163c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private View mSearchViewContainer; 164c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private View mSearchViewCloseButton; 165c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private View mVoiceSearchButton; 166c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private EditText mSearchView; 16794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 168ef2b7388569a94432278a617b528f628385fbb8cYorke Lee private String mSearchQuery; 169ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 170fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Lee private DialerDatabaseHelper mDialerDatabaseHelper; 171fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Lee 17294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 17394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Listener used when one of phone numbers in search UI is selected. This will initiate a 17494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * phone call using the phone number. 17594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 17694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private final OnPhoneNumberPickerActionListener mPhoneNumberPickerActionListener = 17794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng new OnPhoneNumberPickerActionListener() { 17894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 17994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onPickPhoneNumberAction(Uri dataUri) { 18094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // Specify call-origin so that users will see the previous tab instead of 18194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // CallLog screen (search UI will be automatically exited). 18294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng PhoneNumberInteraction.startInteractionForPhoneCall( 183c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee DialtactsActivity.this, dataUri, getCallOrigin()); 18494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 18594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 18694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 18731a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner public void onCallNumberDirectly(String phoneNumber) { 18831a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin()); 18931a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner startActivity(intent); 19031a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner } 19131a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner 19231a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner @Override 19394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onShortcutIntentCreated(Intent intent) { 19494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring."); 19594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 19694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 19794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 19894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onHomeInActionBarSelected() { 19994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng exitSearchUi(); 20094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 20194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng }; 20294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 20394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 20494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Listener used to send search queries to the phone search fragment. 20594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 206c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() { 207c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 208c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void beforeTextChanged(CharSequence s, int start, int count, int after) { 209c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 21094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 211c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 212c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onTextChanged(CharSequence s, int start, int before, int count) { 213c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final String newText = s.toString(); 214ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (newText.equals(mSearchQuery)) { 215ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // If the query hasn't changed (perhaps due to activity being destroyed 216ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // and restored, or user launching the same DIAL intent twice), then there is 217ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // no need to do anything here. 218ef2b7388569a94432278a617b528f628385fbb8cYorke Lee return; 219ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 220ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mSearchQuery = newText; 221ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (DEBUG) { 222ef2b7388569a94432278a617b528f628385fbb8cYorke Lee Log.d(TAG, "onTextChange for mSearchView called with new query: " + s); 223ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 224ef2b7388569a94432278a617b528f628385fbb8cYorke Lee final boolean smartDialSearch = isDialpadShowing(); 225ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 226c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // Show search result with non-empty text. Show a bare list otherwise. 227c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (TextUtils.isEmpty(newText) && mInSearchUi) { 228c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee exitSearchUi(); 229c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewCloseButton.setVisibility(View.GONE); 230c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return; 231c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else if (!TextUtils.isEmpty(newText) && !mInSearchUi) { 232ef2b7388569a94432278a617b528f628385fbb8cYorke Lee enterSearchUi(smartDialSearch, newText); 23394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 23494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 235ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (smartDialSearch && mSmartDialSearchFragment != null) { 236ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mSmartDialSearchFragment.setQueryString(newText, false); 237ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else if (mRegularSearchFragment != null) { 238c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mRegularSearchFragment.setQueryString(newText, false); 23994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 240c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewCloseButton.setVisibility(View.VISIBLE); 241c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return; 242c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 24394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 244c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 245c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void afterTextChanged(Editable s) { 246c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 24794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng }; 24894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 249c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private boolean isDialpadShowing() { 250c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return mDialpadFragment != null && mDialpadFragment.isVisible(); 251c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 252c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 25394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 254c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee protected void onCreate(Bundle savedInstanceState) { 255c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee super.onCreate(savedInstanceState); 25698702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee mFirstLaunch = true; 25798702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee 25894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final Intent intent = getIntent(); 25994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng fixIntent(intent); 26094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 2618898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Lee setContentView(R.layout.dialtacts_activity); 26294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 263c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee getActionBar().hide(); 26494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 265ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState 266ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // is null. Otherwise the fragment manager takes care of recreating these fragments. 267c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (savedInstanceState == null) { 268ef2b7388569a94432278a617b528f628385fbb8cYorke Lee final PhoneFavoriteFragment phoneFavoriteFragment = new PhoneFavoriteFragment(); 269ef2b7388569a94432278a617b528f628385fbb8cYorke Lee phoneFavoriteFragment.setListener(mPhoneFavoriteListener); 27094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 271c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final FragmentTransaction ft = getFragmentManager().beginTransaction(); 272ef2b7388569a94432278a617b528f628385fbb8cYorke Lee ft.add(R.id.dialtacts_frame, phoneFavoriteFragment, TAG_FAVORITES_FRAGMENT); 273ef2b7388569a94432278a617b528f628385fbb8cYorke Lee ft.add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT); 274c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.commit(); 275ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else { 276ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY); 277ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mInSearchUi = savedInstanceState.getBoolean(KEY_IN_SEARCH_UI); 278ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH); 27994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 28094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 281c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mBottomPaddingView = findViewById(R.id.dialtacts_bottom_padding); 282c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee prepareSearchView(); 28394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 28494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction()) 285c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee && savedInstanceState == null) { 28694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng setupFilterText(intent); 28794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 288fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Lee 289fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Lee mDialerDatabaseHelper = DialerDatabaseHelper.getInstance(this); 290fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Lee SmartDialPrefix.initializeNanpSettings(this); 29194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 29294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 29394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 294c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee protected void onResume() { 295c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee super.onResume(); 29698702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee if (mFirstLaunch) { 29798702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee displayFragment(getIntent()); 29898702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee } 29998702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee mFirstLaunch = false; 300fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Lee mDialerDatabaseHelper.startSmartDialUpdateThread(); 301c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 30294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 303c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 304ef2b7388569a94432278a617b528f628385fbb8cYorke Lee protected void onSaveInstanceState(Bundle outState) { 305ef2b7388569a94432278a617b528f628385fbb8cYorke Lee super.onSaveInstanceState(outState); 306ef2b7388569a94432278a617b528f628385fbb8cYorke Lee outState.putString(KEY_SEARCH_QUERY, mSearchQuery); 307ef2b7388569a94432278a617b528f628385fbb8cYorke Lee outState.putBoolean(KEY_IN_SEARCH_UI, mInSearchUi); 308ef2b7388569a94432278a617b528f628385fbb8cYorke Lee outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch); 309ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 310ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 311ef2b7388569a94432278a617b528f628385fbb8cYorke Lee @Override 312c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onAttachFragment(Fragment fragment) { 313ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (fragment instanceof DialpadFragment) { 314ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mDialpadFragment = (DialpadFragment) fragment; 315c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final FragmentTransaction transaction = getFragmentManager().beginTransaction(); 316ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.hide(mDialpadFragment); 317c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee transaction.commit(); 318ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else if (fragment instanceof SmartDialSearchFragment) { 319ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mSmartDialSearchFragment = (SmartDialSearchFragment) fragment; 320ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else if (fragment instanceof SearchFragment) { 321ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mRegularSearchFragment = (SearchFragment) fragment; 322ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else if (fragment instanceof PhoneFavoriteFragment) { 323ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mPhoneFavoriteFragment = (PhoneFavoriteFragment) fragment; 32494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 325c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 326c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 327c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 328c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public boolean onMenuItemClick(MenuItem item) { 329c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee switch (item.getItemId()) { 330c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.menu_import_export: 331c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // We hard-code the "contactsAreAvailable" argument because doing it properly would 332c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // involve querying a {@link ProviderStatusLoader}, which we don't want to do right 333c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // now in Dialtacts for (potential) performance reasons. Compare with how it is 334c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // done in {@link PeopleActivity}. 335c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ImportExportDialogFragment.show(getFragmentManager(), true, 336f74011e7a9b4007f6795ecee5adc2739d5fad4e6Yorke Lee DialtactsActivity.class); 337c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return true; 338c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.menu_clear_frequents: 339c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ClearFrequentsDialog.show(getFragmentManager()); 340c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return true; 341c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.add_contact: 342c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee try { 343c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI)); 344c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } catch (ActivityNotFoundException e) { 345c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Toast toast = Toast.makeText(this, 346c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee R.string.add_contact_not_available, 347c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Toast.LENGTH_SHORT); 348c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee toast.show(); 349c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 350c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return true; 351c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.menu_call_settings: 352f74011e7a9b4007f6795ecee5adc2739d5fad4e6Yorke Lee final Intent settingsIntent = DialtactsActivity.getCallSettingsIntent(); 353c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee startActivity(settingsIntent); 354c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 355c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return false; 35694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 35794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 35894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 35994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onClick(View view) { 36094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng switch (view.getId()) { 361c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.overflow_menu: { 362c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final PopupMenu popupMenu = new PopupMenu(DialtactsActivity.this, view); 363c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final Menu menu = popupMenu.getMenu(); 3648898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Lee popupMenu.inflate(R.menu.dialtacts_options); 365f420a5344995b2c450379159f679809690bc9880Yorke Lee final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents); 3660d391b481d691fb26fb114a82d98100a5804ca62Yorke Lee clearFrequents.setVisible(mPhoneFavoriteFragment.hasFrequents()); 367c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee popupMenu.setOnMenuItemClickListener(this); 368c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee popupMenu.show(); 36994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng break; 37094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 371c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.dialpad_button: 372c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee showDialpadFragment(true); 373c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee break; 374c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.call_history_on_dialpad_button: 375c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.call_history_button: 376f420a5344995b2c450379159f679809690bc9880Yorke Lee // Use explicit CallLogActivity intent instead of ACTION_VIEW + 377f420a5344995b2c450379159f679809690bc9880Yorke Lee // CONTENT_TYPE, so that we always open our call log from our dialer 378c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final Intent intent = new Intent(this, CallLogActivity.class); 379c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee startActivity(intent); 380c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee break; 381c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.search_close_button: 382c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // Clear the search field 383c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (!TextUtils.isEmpty(mSearchView.getText())) { 384c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setText(""); 38594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 38694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng break; 387c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.voice_search_button: 388c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 389c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee startActivityForResult(voiceIntent, ACTIVITY_REQUEST_CODE_VOICE_SEARCH); 390c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee break; 39194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng default: { 39294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Log.wtf(TAG, "Unexpected onClick event from " + view); 39394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng break; 39494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 39594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 39694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 39794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 398c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 399c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee protected void onActivityResult(int requestCode, int resultCode, Intent data) { 400c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) { 401c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (resultCode == RESULT_OK) { 402c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final ArrayList<String> matches = data.getStringArrayListExtra( 403c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee RecognizerIntent.EXTRA_RESULTS); 404c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (matches.size() > 0) { 405c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final String match = matches.get(0); 406c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setText(match); 407c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else { 408c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Log.e(TAG, "Voice search - nothing heard"); 409c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 410c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else { 411c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Log.e(TAG, "Voice search failed"); 412c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 413c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 414c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee super.onActivityResult(requestCode, resultCode, data); 415c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 41694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 417c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private void showDialpadFragment(boolean animate) { 418ea695cb0f877ad49a98df184efe982de83ed09d7Yorke Lee mDialpadFragment.setAdjustTranslationForAnimation(animate); 419c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final FragmentTransaction ft = getFragmentManager().beginTransaction(); 420c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (animate) { 421c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.setCustomAnimations(R.anim.slide_in, 0); 422ea695cb0f877ad49a98df184efe982de83ed09d7Yorke Lee } else { 423ea695cb0f877ad49a98df184efe982de83ed09d7Yorke Lee mDialpadFragment.setYFraction(0); 424c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 425c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.show(mDialpadFragment); 426c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.commit(); 427c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 428c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 429c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private void hideDialpadFragment(boolean animate) { 430ea695cb0f877ad49a98df184efe982de83ed09d7Yorke Lee mDialpadFragment.setAdjustTranslationForAnimation(animate); 431c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final FragmentTransaction ft = getFragmentManager().beginTransaction(); 432c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (animate) { 433c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.setCustomAnimations(0, R.anim.slide_out); 434c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 435c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.hide(mDialpadFragment); 436c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.commit(); 437c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 43894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 43994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private void prepareSearchView() { 440c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer = findViewById(R.id.search_view_container); 441c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewCloseButton = findViewById(R.id.search_close_button); 442c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewCloseButton.setOnClickListener(this); 443c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mVoiceSearchButton = findViewById(R.id.voice_search_button); 444c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mVoiceSearchButton.setOnClickListener(this); 445c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView = (EditText) findViewById(R.id.search_view); 446c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); 447c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setHint(getString(R.string.dialer_hint_find_contact)); 448c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setOnFocusChangeListener(new OnFocusChangeListener() { 44994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 45094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onFocusChange(View view, boolean hasFocus) { 45194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (hasFocus) { 45294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng showInputMethod(view.findFocus()); 45394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 45494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 45594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng }); 456c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 457c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 458c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private void hideDialpadFragmentIfNecessary() { 459ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (mDialpadFragment != null && mDialpadFragment.isVisible()) { 460c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee hideDialpadFragment(true); 461c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 462c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 46394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 464c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final AnimatorListener mHideListener = new AnimatorListenerAdapter() { 465c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 466c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onAnimationEnd(Animator animation) { 467c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setVisibility(View.GONE); 46894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 469c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee }; 47094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 471c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void hideSearchBar() { 472c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee hideSearchBar(true); 473c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 474c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 475c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void hideSearchBar(boolean shiftView) { 476c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (shiftView) { 477c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.animate().cancel(); 478c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setAlpha(1); 479c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setTranslationY(0); 480c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.animate().withLayer().alpha(0).translationY(-mSearchView.getHeight()) 481c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee .setDuration(200).setListener(mHideListener); 482c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 483ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (mPhoneFavoriteFragment == null || mPhoneFavoriteFragment.getView() == null) { 484ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mBottomPaddingView.setVisibility(View.VISIBLE); 485ef2b7388569a94432278a617b528f628385fbb8cYorke Lee return; 486ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 487ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 488c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mPhoneFavoriteFragment.getView().animate().withLayer() 489c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee .translationY(-mSearchViewContainer.getHeight()).setDuration(200).setListener( 490c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee new AnimatorListenerAdapter() { 491c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 492c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onAnimationEnd(Animator animation) { 493c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mBottomPaddingView.setVisibility(View.VISIBLE); 494ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (mPhoneFavoriteFragment.getView() != null) { 495ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mPhoneFavoriteFragment.getView().setTranslationY(0); 496ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 497c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 498c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee }); 499c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else { 500c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setTranslationY(-mSearchView.getHeight()); 501c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 50294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 50394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 504c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void showSearchBar() { 505ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 506ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 507c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.animate().cancel(); 508c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setAlpha(0); 509c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setTranslationY(-mSearchViewContainer.getHeight()); 510c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.animate().withLayer().alpha(1).translationY(0).setDuration(200) 511c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee .setListener(new AnimatorListenerAdapter() { 512c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 513c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onAnimationStart(Animator animation) { 514c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setVisibility(View.VISIBLE); 515c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 516c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee }); 517c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 518ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // If the favorites fragment hasn't been fully created before the dialpad fragment 519ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // is hidden (i.e. onResume), don't bother animating 520ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (mPhoneFavoriteFragment == null || mPhoneFavoriteFragment.getView() == null) { 521ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mBottomPaddingView.setVisibility(View.GONE); 522ef2b7388569a94432278a617b528f628385fbb8cYorke Lee return; 523ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 524c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mPhoneFavoriteFragment.getView().setTranslationY(-mSearchViewContainer.getHeight()); 525c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mPhoneFavoriteFragment.getView().animate().withLayer().translationY(0).setDuration(200) 526c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee .setListener( 527c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee new AnimatorListenerAdapter() { 528c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 529c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onAnimationStart(Animator animation) { 530c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mBottomPaddingView.setVisibility(View.GONE); 531c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 532c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee }); 53394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 53494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 53594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 536c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void setupFakeActionBarItemsForFavoritesFragment() { 537c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mMenuButton = findViewById(R.id.overflow_menu); 538c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (mMenuButton != null) { 539c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mMenuButton.setOnClickListener(this); 540c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 541c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 542c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mCallHistoryButton = findViewById(R.id.call_history_button); 543c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // mCallHistoryButton.setMinimumWidth(fakeMenuItemWidth); 544c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mCallHistoryButton.setOnClickListener(this); 545c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 546c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mDialpadButton = findViewById(R.id.dialpad_button); 547c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // DialpadButton.setMinimumWidth(fakeMenuItemWidth); 548c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mDialpadButton.setOnClickListener(this); 5499c1e0653addc1fff03601289a9f9a57b1daeaf57Christine Chen } 5509c1e0653addc1fff03601289a9f9a57b1daeaf57Christine Chen 551c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void setupFakeActionBarItemsForDialpadFragment() { 552c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final View callhistoryButton = findViewById(R.id.call_history_on_dialpad_button); 553c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee callhistoryButton.setOnClickListener(this); 55494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 55594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 55694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private void fixIntent(Intent intent) { 55794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // This should be cleaned up: the call key used to send an Intent 55894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // that just said to go to the recent calls list. It now sends this 55994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // abstract action, but this class hasn't been rewritten to deal with it. 56094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (Intent.ACTION_CALL_BUTTON.equals(intent.getAction())) { 56194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.setDataAndType(Calls.CONTENT_URI, Calls.CONTENT_TYPE); 56294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.putExtra("call_key", true); 56394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng setIntent(intent); 56494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 56594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 56694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 56794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 56894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Returns true if the intent is due to hitting the green send key (hardware call button: 56994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * KEYCODE_CALL) while in a call. 57094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 57194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @param intent the intent that launched this activity 57294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @param recentCallsRequest true if the intent is requesting to view recent calls 57394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @return true if the intent is due to hitting the green send key while in a call 57494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 575c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private boolean isSendKeyWhileInCall(Intent intent, boolean recentCallsRequest) { 57694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // If there is a call in progress go to the call screen 57794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (recentCallsRequest) { 57894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final boolean callKey = intent.getBooleanExtra("call_key", false); 57994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 58094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng try { 58194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); 58294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (callKey && phone != null && phone.showCallScreen()) { 58394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return true; 58494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 58594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } catch (RemoteException e) { 58694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Log.e(TAG, "Failed to handle send while in call", e); 58794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 58894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 58994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 59094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return false; 59194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 59294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 59394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 59494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Sets the current tab based on the intent's request type 59594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 59694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @param intent Intent that contains information about which tab should be selected 59794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 598c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private void displayFragment(Intent intent) { 59994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // If we got here by hitting send and we're in call forward along to the in-call activity 60094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent.resolveType( 60194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng getContentResolver())); 60294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (isSendKeyWhileInCall(intent, recentCallsRequest)) { 60394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng finish(); 60494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return; 60594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 60694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 60798702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee if (mDialpadFragment != null && (phoneIsInUse() || isDialIntent(intent))) { 608c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mDialpadFragment.setStartedFromNewIntent(true); 609ea695cb0f877ad49a98df184efe982de83ed09d7Yorke Lee showDialpadFragment(false); 61094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 61194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 61294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 61394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 61494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onNewIntent(Intent newIntent) { 61594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng setIntent(newIntent); 61694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng fixIntent(newIntent); 617c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee displayFragment(newIntent); 61894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final String action = newIntent.getAction(); 619c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 62094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng invalidateOptionsMenu(); 62194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 62294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 62394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** Returns true if the given intent contains a phone number to populate the dialer with */ 62494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private boolean isDialIntent(Intent intent) { 62594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final String action = intent.getAction(); 62694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) { 62794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return true; 62894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 62994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (Intent.ACTION_VIEW.equals(action)) { 63094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final Uri data = intent.getData(); 6319d4f3b20793a007b4489547aa40fc1049d0d8fefChiao Cheng if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) { 63294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return true; 63394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 63494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 63594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return false; 63694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 63794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 63894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 63994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Returns an appropriate call origin for this Activity. May return null when no call origin 64094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * should be used (e.g. when some 3rd party application launched the screen. Call origin is 64194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * for remembering the tab in which the user made a phone call, so the external app's DIAL 64294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * request should not be counted.) 64394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 64494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public String getCallOrigin() { 64594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null; 64694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 64794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 64894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 64994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Retrieves the filter text stored in {@link #setupFilterText(Intent)}. 65094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * This text originally came from a FILTER_CONTACTS_ACTION intent received 65194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * by this activity. The stored text will then be cleared after after this 65294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * method returns. 65394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 65494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @return The stored filter text 65594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 65694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public String getAndClearFilterText() { 65794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng String filterText = mFilterText; 65894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng mFilterText = null; 65994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return filterText; 66094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 66194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 66294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 66394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Stores the filter text associated with a FILTER_CONTACTS_ACTION intent. 66494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * This is so child activities can check if they are supposed to display a filter. 66594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 66694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @param intent The intent received in {@link #onNewIntent(Intent)} 66794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 66894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private void setupFilterText(Intent intent) { 66994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // If the intent was relaunched from history, don't apply the filter text. 67094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { 67194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return; 67294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 67394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng String filter = intent.getStringExtra(UI.FILTER_TEXT_EXTRA_KEY); 67494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (filter != null && filter.length() > 0) { 67594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng mFilterText = filter; 67694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 67794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 67894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 6798898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Lee private final PhoneFavoriteFragment.Listener mPhoneFavoriteListener = 6808898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Lee new PhoneFavoriteFragment.Listener() { 68194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 68294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onContactSelected(Uri contactUri) { 68394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng PhoneNumberInteraction.startInteractionForPhoneCall( 684c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee DialtactsActivity.this, contactUri, getCallOrigin()); 68594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 68694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 68794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 68894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onCallNumberDirectly(String phoneNumber) { 6899d4f3b20793a007b4489547aa40fc1049d0d8fefChiao Cheng Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin()); 69094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng startActivity(intent); 69194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 69294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng }; 69394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 694c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee /* TODO krelease: This is only relevant for phones that have a hard button search key (i.e. 695c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * Nexus S). Supporting it is a little more tricky because of the dialpad fragment might 696c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * be showing when the search key is pressed so there is more state management involved. 69794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 69894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 69994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void startSearch(String initialQuery, boolean selectInitialQuery, 70094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Bundle appSearchData, boolean globalSearch) { 701c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (mRegularSearchFragment != null && mRegularSearchFragment.isAdded() && !globalSearch) { 70294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (mInSearchUi) { 70394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (mSearchView.hasFocus()) { 70494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng showInputMethod(mSearchView.findFocus()); 70594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } else { 70694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng mSearchView.requestFocus(); 70794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 70894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } else { 70994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng enterSearchUi(); 71094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 71194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } else { 71294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); 71394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 714c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee }*/ 71594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 71694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private void showInputMethod(View view) { 717c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final InputMethodManager imm = (InputMethodManager) getSystemService( 718c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Context.INPUT_METHOD_SERVICE); 71994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (imm != null) { 720c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee imm.showSoftInput(view, 0); 72194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 72294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 72394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 72494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private void hideInputMethod(View view) { 725c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final InputMethodManager imm = (InputMethodManager) getSystemService( 726c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Context.INPUT_METHOD_SERVICE); 72794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (imm != null && view != null) { 72894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 72994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 73094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 73194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 73294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 733c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * Shows the search fragment 73494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 735ef2b7388569a94432278a617b528f628385fbb8cYorke Lee private void enterSearchUi(boolean smartDialSearch, String query) { 736ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (DEBUG) { 737ef2b7388569a94432278a617b528f628385fbb8cYorke Lee Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch); 738ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 739ef2b7388569a94432278a617b528f628385fbb8cYorke Lee final String tag = smartDialSearch ? TAG_SMARTDIAL_SEARCH_FRAGMENT : 740ef2b7388569a94432278a617b528f628385fbb8cYorke Lee TAG_REGULAR_SEARCH_FRAGMENT; 741ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 742c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final FragmentTransaction transaction = getFragmentManager().beginTransaction(); 743c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 744ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 745ef2b7388569a94432278a617b528f628385fbb8cYorke Lee SearchFragment fragment; 746ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 747ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.remove(mPhoneFavoriteFragment); 748ef2b7388569a94432278a617b528f628385fbb8cYorke Lee fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag); 749ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (fragment == null) { 750ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (smartDialSearch) { 751ef2b7388569a94432278a617b528f628385fbb8cYorke Lee fragment = new SmartDialSearchFragment(); 752ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else { 753ef2b7388569a94432278a617b528f628385fbb8cYorke Lee fragment = new SearchFragment(); 754ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 755ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.replace(R.id.dialtacts_frame, fragment, tag); 756c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else { 757ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.attach(fragment); 75894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 75994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 760ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.addToBackStack(null); 761ef2b7388569a94432278a617b528f628385fbb8cYorke Lee fragment.setQueryString(query, false); 762ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.commit(); 763c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mInSearchUi = true; 76494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 76594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 76694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 767c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * Hides the search fragment 76894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 769c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private void exitSearchUi() { 770ef2b7388569a94432278a617b528f628385fbb8cYorke Lee getFragmentManager().popBackStack(); 771c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mInSearchUi = false; 77294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 77394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 77494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** Returns an Intent to launch Call Settings screen */ 77594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public static Intent getCallSettingsIntent() { 77694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final Intent intent = new Intent(Intent.ACTION_MAIN); 77794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME); 77894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 77994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return intent; 78094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 78194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 78294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 783c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onBackPressed() { 784ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (mDialpadFragment != null && mDialpadFragment.isVisible()) { 785c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee hideDialpadFragment(true); 786c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else if (mInSearchUi) { 787c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setText(null); 788c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else if (isTaskRoot()) { 789c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // Instead of stopping, simply push this to the back of the stack. 790c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // This is only done when running at the top of the stack; 791c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // otherwise, we have been launched by someone else so need to 792c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // allow the user to go back to the caller. 793c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee moveTaskToBack(false); 794c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else { 795c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee super.onBackPressed(); 79694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 797c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 798c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 799c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 800c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onDialpadQueryChanged(String query) { 801c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query, 802c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee SmartDialNameMatcher.LATIN_SMART_DIAL_MAP); 803c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) { 804ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (DEBUG) { 805ef2b7388569a94432278a617b528f628385fbb8cYorke Lee Log.d(TAG, "onDialpadQueryChanged - new query: " + query); 806ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 807ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (mDialpadFragment == null || !mDialpadFragment.isVisible()) { 808ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // This callback can happen if the dialpad fragment is recreated because of 809ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // activity destruction. In that case, don't update the search view because 810ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // that would bring the user back to the search fragment regardless of the 811ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // previous state of the application. Instead, just return here and let the 812ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // fragment manager correctly figure out whatever fragment was last displayed. 813ef2b7388569a94432278a617b528f628385fbb8cYorke Lee return; 814ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 815c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setText(normalizedQuery); 81694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 81794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 818c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 819c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 820c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onListFragmentScrollStateChange(int scrollState) { 821c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { 822c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee hideDialpadFragmentIfNecessary(); 823c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee hideInputMethod(getCurrentFocus()); 824c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 825c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 826c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 827c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 828c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onPhoneFavoriteFragmentStarted() { 829c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee setupFakeActionBarItemsForFavoritesFragment(); 830c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 831c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 832c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 833c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onDialpadFragmentStarted() { 834c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee setupFakeActionBarItemsForDialpadFragment(); 835c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 836c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 837c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private boolean phoneIsInUse() { 838c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final TelephonyManager tm = (TelephonyManager) getSystemService( 839c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Context.TELEPHONY_SERVICE); 840c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return tm.getCallState() != TelephonyManager.CALL_STATE_IDLE; 841c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 8428dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee 8438dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee @Override 8448dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee public void onShowAllContacts() { 8458dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee final Intent intent = new Intent(this, AllContactsActivity.class); 8468dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee startActivity(intent); 8478dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee } 84894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng} 849