DialtactsActivity.java revision 311969c96e36da85118d4aabdddbd98e5ab6a3c8
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()); 184f6673d3e5cbd10febea04f02035591ab15c5c7c0Yorke Lee hideDialpadAndSearchUi(); 18594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 18694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 18794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 18831a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner public void onCallNumberDirectly(String phoneNumber) { 18931a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin()); 19031a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner startActivity(intent); 191f6673d3e5cbd10febea04f02035591ab15c5c7c0Yorke Lee hideDialpadAndSearchUi(); 19231a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner } 19331a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner 19431a760be9135b5ef05e504dbd1594e1617af0326Jay Shrauner @Override 19594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onShortcutIntentCreated(Intent intent) { 19694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Log.w(TAG, "Unsupported intent has come (" + intent + "). Ignoring."); 19794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 19894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 19994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 20094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onHomeInActionBarSelected() { 20194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng exitSearchUi(); 20294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 20394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng }; 20494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 20594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 20694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Listener used to send search queries to the phone search fragment. 20794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 208c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() { 209c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 210c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void beforeTextChanged(CharSequence s, int start, int count, int after) { 211c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 21294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 213c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 214c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onTextChanged(CharSequence s, int start, int before, int count) { 215c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final String newText = s.toString(); 216ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (newText.equals(mSearchQuery)) { 217ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // If the query hasn't changed (perhaps due to activity being destroyed 218ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // and restored, or user launching the same DIAL intent twice), then there is 219ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // no need to do anything here. 220ef2b7388569a94432278a617b528f628385fbb8cYorke Lee return; 221ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 222ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mSearchQuery = newText; 223ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (DEBUG) { 224ef2b7388569a94432278a617b528f628385fbb8cYorke Lee Log.d(TAG, "onTextChange for mSearchView called with new query: " + s); 225ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 226ef2b7388569a94432278a617b528f628385fbb8cYorke Lee final boolean smartDialSearch = isDialpadShowing(); 227ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 228c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // Show search result with non-empty text. Show a bare list otherwise. 229c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (TextUtils.isEmpty(newText) && mInSearchUi) { 230c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee exitSearchUi(); 231c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewCloseButton.setVisibility(View.GONE); 232c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return; 233c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else if (!TextUtils.isEmpty(newText) && !mInSearchUi) { 234ef2b7388569a94432278a617b528f628385fbb8cYorke Lee enterSearchUi(smartDialSearch, newText); 23594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 23694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 237ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (smartDialSearch && mSmartDialSearchFragment != null) { 238ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mSmartDialSearchFragment.setQueryString(newText, false); 239ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else if (mRegularSearchFragment != null) { 240c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mRegularSearchFragment.setQueryString(newText, false); 24194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 242c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewCloseButton.setVisibility(View.VISIBLE); 243c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return; 244c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 24594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 246c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 247c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void afterTextChanged(Editable s) { 248c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 24994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng }; 25094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 251c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private boolean isDialpadShowing() { 252c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return mDialpadFragment != null && mDialpadFragment.isVisible(); 253c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 254c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 25594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 256c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee protected void onCreate(Bundle savedInstanceState) { 257c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee super.onCreate(savedInstanceState); 25898702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee mFirstLaunch = true; 25998702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee 26094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final Intent intent = getIntent(); 26194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng fixIntent(intent); 26294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 2638898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Lee setContentView(R.layout.dialtacts_activity); 26494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 265c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee getActionBar().hide(); 26694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 267ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState 268ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // is null. Otherwise the fragment manager takes care of recreating these fragments. 269c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (savedInstanceState == null) { 270ef2b7388569a94432278a617b528f628385fbb8cYorke Lee final PhoneFavoriteFragment phoneFavoriteFragment = new PhoneFavoriteFragment(); 27194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 272c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final FragmentTransaction ft = getFragmentManager().beginTransaction(); 273ef2b7388569a94432278a617b528f628385fbb8cYorke Lee ft.add(R.id.dialtacts_frame, phoneFavoriteFragment, TAG_FAVORITES_FRAGMENT); 274ef2b7388569a94432278a617b528f628385fbb8cYorke Lee ft.add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT); 275c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.commit(); 276ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else { 277ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY); 278ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mInSearchUi = savedInstanceState.getBoolean(KEY_IN_SEARCH_UI); 279ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mFirstLaunch = savedInstanceState.getBoolean(KEY_FIRST_LAUNCH); 28094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 28194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 282c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mBottomPaddingView = findViewById(R.id.dialtacts_bottom_padding); 283c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee prepareSearchView(); 28494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 28594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction()) 286c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee && savedInstanceState == null) { 28794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng setupFilterText(intent); 28894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 289fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Lee 290fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Lee mDialerDatabaseHelper = DialerDatabaseHelper.getInstance(this); 291fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Lee SmartDialPrefix.initializeNanpSettings(this); 29294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 29394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 29494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 295c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee protected void onResume() { 296c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee super.onResume(); 29798702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee if (mFirstLaunch) { 29898702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee displayFragment(getIntent()); 29998702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee } 30098702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee mFirstLaunch = false; 301fce269a30e2ec112ea4c287d97e08ef7b3b31b89Yorke Lee mDialerDatabaseHelper.startSmartDialUpdateThread(); 302c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 30394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 304c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 305ef2b7388569a94432278a617b528f628385fbb8cYorke Lee protected void onSaveInstanceState(Bundle outState) { 306ef2b7388569a94432278a617b528f628385fbb8cYorke Lee super.onSaveInstanceState(outState); 307ef2b7388569a94432278a617b528f628385fbb8cYorke Lee outState.putString(KEY_SEARCH_QUERY, mSearchQuery); 308ef2b7388569a94432278a617b528f628385fbb8cYorke Lee outState.putBoolean(KEY_IN_SEARCH_UI, mInSearchUi); 309ef2b7388569a94432278a617b528f628385fbb8cYorke Lee outState.putBoolean(KEY_FIRST_LAUNCH, mFirstLaunch); 310ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 311ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 312ef2b7388569a94432278a617b528f628385fbb8cYorke Lee @Override 313c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onAttachFragment(Fragment fragment) { 314ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (fragment instanceof DialpadFragment) { 315ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mDialpadFragment = (DialpadFragment) fragment; 316c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final FragmentTransaction transaction = getFragmentManager().beginTransaction(); 317ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.hide(mDialpadFragment); 318c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee transaction.commit(); 319ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else if (fragment instanceof SmartDialSearchFragment) { 320ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mSmartDialSearchFragment = (SmartDialSearchFragment) fragment; 32163ea4cd19569c8d5ee6f9a7ce2c933d09359fc0bYorke Lee mSmartDialSearchFragment.setOnPhoneNumberPickerActionListener( 32263ea4cd19569c8d5ee6f9a7ce2c933d09359fc0bYorke Lee mPhoneNumberPickerActionListener); 323ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else if (fragment instanceof SearchFragment) { 324ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mRegularSearchFragment = (SearchFragment) fragment; 32563ea4cd19569c8d5ee6f9a7ce2c933d09359fc0bYorke Lee mRegularSearchFragment.setOnPhoneNumberPickerActionListener( 32663ea4cd19569c8d5ee6f9a7ce2c933d09359fc0bYorke Lee mPhoneNumberPickerActionListener); 327ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else if (fragment instanceof PhoneFavoriteFragment) { 328ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mPhoneFavoriteFragment = (PhoneFavoriteFragment) fragment; 3295781afe916100c4ed709e8edacac4a71db090108Yorke Lee mPhoneFavoriteFragment.setListener(mPhoneFavoriteListener); 33094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 331c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 332c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 333c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 334c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public boolean onMenuItemClick(MenuItem item) { 335c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee switch (item.getItemId()) { 336c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.menu_import_export: 337c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // We hard-code the "contactsAreAvailable" argument because doing it properly would 338c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // involve querying a {@link ProviderStatusLoader}, which we don't want to do right 339c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // now in Dialtacts for (potential) performance reasons. Compare with how it is 340c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // done in {@link PeopleActivity}. 341c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ImportExportDialogFragment.show(getFragmentManager(), true, 342f74011e7a9b4007f6795ecee5adc2739d5fad4e6Yorke Lee DialtactsActivity.class); 343c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return true; 344c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.menu_clear_frequents: 345c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ClearFrequentsDialog.show(getFragmentManager()); 346c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return true; 347c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.add_contact: 348c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee try { 349c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI)); 350c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } catch (ActivityNotFoundException e) { 351c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Toast toast = Toast.makeText(this, 352c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee R.string.add_contact_not_available, 353c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Toast.LENGTH_SHORT); 354c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee toast.show(); 355c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 356c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return true; 357c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.menu_call_settings: 358f74011e7a9b4007f6795ecee5adc2739d5fad4e6Yorke Lee final Intent settingsIntent = DialtactsActivity.getCallSettingsIntent(); 359c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee startActivity(settingsIntent); 360c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 361c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return false; 36294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 36394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 36494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 36594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onClick(View view) { 36694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng switch (view.getId()) { 367c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.overflow_menu: { 368c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final PopupMenu popupMenu = new PopupMenu(DialtactsActivity.this, view); 369c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final Menu menu = popupMenu.getMenu(); 3708898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Lee popupMenu.inflate(R.menu.dialtacts_options); 371f420a5344995b2c450379159f679809690bc9880Yorke Lee final MenuItem clearFrequents = menu.findItem(R.id.menu_clear_frequents); 3720d391b481d691fb26fb114a82d98100a5804ca62Yorke Lee clearFrequents.setVisible(mPhoneFavoriteFragment.hasFrequents()); 373c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee popupMenu.setOnMenuItemClickListener(this); 374c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee popupMenu.show(); 37594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng break; 37694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 377c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.dialpad_button: 378c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee showDialpadFragment(true); 379c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee break; 380c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.call_history_on_dialpad_button: 381c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.call_history_button: 382f420a5344995b2c450379159f679809690bc9880Yorke Lee // Use explicit CallLogActivity intent instead of ACTION_VIEW + 383f420a5344995b2c450379159f679809690bc9880Yorke Lee // CONTENT_TYPE, so that we always open our call log from our dialer 384c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final Intent intent = new Intent(this, CallLogActivity.class); 385c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee startActivity(intent); 386c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee break; 387c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.search_close_button: 388c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // Clear the search field 389c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (!TextUtils.isEmpty(mSearchView.getText())) { 390c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setText(""); 39194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 39294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng break; 393c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee case R.id.voice_search_button: 394c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 395c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee startActivityForResult(voiceIntent, ACTIVITY_REQUEST_CODE_VOICE_SEARCH); 396c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee break; 39794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng default: { 39894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Log.wtf(TAG, "Unexpected onClick event from " + view); 39994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng break; 40094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 40194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 40294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 40394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 404c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 405c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee protected void onActivityResult(int requestCode, int resultCode, Intent data) { 406c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) { 407c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (resultCode == RESULT_OK) { 408c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final ArrayList<String> matches = data.getStringArrayListExtra( 409c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee RecognizerIntent.EXTRA_RESULTS); 410c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (matches.size() > 0) { 411c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final String match = matches.get(0); 412c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setText(match); 413c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else { 414c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Log.e(TAG, "Voice search - nothing heard"); 415c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 416c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else { 417c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Log.e(TAG, "Voice search failed"); 418c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 419c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 420c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee super.onActivityResult(requestCode, resultCode, data); 421c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 42294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 423c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private void showDialpadFragment(boolean animate) { 424ea695cb0f877ad49a98df184efe982de83ed09d7Yorke Lee mDialpadFragment.setAdjustTranslationForAnimation(animate); 425c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final FragmentTransaction ft = getFragmentManager().beginTransaction(); 426c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (animate) { 427c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.setCustomAnimations(R.anim.slide_in, 0); 428ea695cb0f877ad49a98df184efe982de83ed09d7Yorke Lee } else { 429ea695cb0f877ad49a98df184efe982de83ed09d7Yorke Lee mDialpadFragment.setYFraction(0); 430c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 431c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.show(mDialpadFragment); 432c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.commit(); 433c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 434c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 435f6673d3e5cbd10febea04f02035591ab15c5c7c0Yorke Lee private void hideDialpadFragment(boolean animate, boolean clearDialpad) { 436f6673d3e5cbd10febea04f02035591ab15c5c7c0Yorke Lee if (mDialpadFragment == null) return; 437f6673d3e5cbd10febea04f02035591ab15c5c7c0Yorke Lee if (clearDialpad) { 438f6673d3e5cbd10febea04f02035591ab15c5c7c0Yorke Lee mDialpadFragment.clearDialpad(); 439f6673d3e5cbd10febea04f02035591ab15c5c7c0Yorke Lee } 440f6673d3e5cbd10febea04f02035591ab15c5c7c0Yorke Lee if (!mDialpadFragment.isVisible()) return; 441ea695cb0f877ad49a98df184efe982de83ed09d7Yorke Lee mDialpadFragment.setAdjustTranslationForAnimation(animate); 442c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final FragmentTransaction ft = getFragmentManager().beginTransaction(); 443c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (animate) { 444c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.setCustomAnimations(0, R.anim.slide_out); 445c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 446c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.hide(mDialpadFragment); 447c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee ft.commit(); 448c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 44994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 45094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private void prepareSearchView() { 451c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer = findViewById(R.id.search_view_container); 452c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewCloseButton = findViewById(R.id.search_close_button); 453c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewCloseButton.setOnClickListener(this); 454c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mVoiceSearchButton = findViewById(R.id.voice_search_button); 455c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mVoiceSearchButton.setOnClickListener(this); 456c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView = (EditText) findViewById(R.id.search_view); 457c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); 458c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setHint(getString(R.string.dialer_hint_find_contact)); 459c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setOnFocusChangeListener(new OnFocusChangeListener() { 46094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 46194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onFocusChange(View view, boolean hasFocus) { 46294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (hasFocus) { 46394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng showInputMethod(view.findFocus()); 46494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 46594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 46694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng }); 467c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 468c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 469c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final AnimatorListener mHideListener = new AnimatorListenerAdapter() { 470c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 471c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onAnimationEnd(Animator animation) { 472c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setVisibility(View.GONE); 47394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 474c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee }; 47594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 476311969c96e36da85118d4aabdddbd98e5ab6a3c8Yorke Lee private void hideDialpadAndSearchUi() { 477311969c96e36da85118d4aabdddbd98e5ab6a3c8Yorke Lee if (mInSearchUi) { 478311969c96e36da85118d4aabdddbd98e5ab6a3c8Yorke Lee exitSearchUi(); 479311969c96e36da85118d4aabdddbd98e5ab6a3c8Yorke Lee } 480311969c96e36da85118d4aabdddbd98e5ab6a3c8Yorke Lee hideDialpadFragment(false, true); 481311969c96e36da85118d4aabdddbd98e5ab6a3c8Yorke Lee } 482311969c96e36da85118d4aabdddbd98e5ab6a3c8Yorke Lee 483c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void hideSearchBar() { 484c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee hideSearchBar(true); 485c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 486c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 487c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void hideSearchBar(boolean shiftView) { 488c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (shiftView) { 489c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.animate().cancel(); 490c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setAlpha(1); 491c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setTranslationY(0); 492c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.animate().withLayer().alpha(0).translationY(-mSearchView.getHeight()) 493c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee .setDuration(200).setListener(mHideListener); 494c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 495ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (mPhoneFavoriteFragment == null || mPhoneFavoriteFragment.getView() == null) { 496ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mBottomPaddingView.setVisibility(View.VISIBLE); 497ef2b7388569a94432278a617b528f628385fbb8cYorke Lee return; 498ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 499ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 500c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mPhoneFavoriteFragment.getView().animate().withLayer() 501c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee .translationY(-mSearchViewContainer.getHeight()).setDuration(200).setListener( 502c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee new AnimatorListenerAdapter() { 503c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 504c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onAnimationEnd(Animator animation) { 505c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mBottomPaddingView.setVisibility(View.VISIBLE); 506ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (mPhoneFavoriteFragment.getView() != null) { 507ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mPhoneFavoriteFragment.getView().setTranslationY(0); 508ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 509c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 510c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee }); 511c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else { 512c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setTranslationY(-mSearchView.getHeight()); 513c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 51494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 51594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 516c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void showSearchBar() { 517ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 518ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 519c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.animate().cancel(); 520c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setAlpha(0); 521c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setTranslationY(-mSearchViewContainer.getHeight()); 522c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.animate().withLayer().alpha(1).translationY(0).setDuration(200) 523c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee .setListener(new AnimatorListenerAdapter() { 524c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 525c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onAnimationStart(Animator animation) { 526c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchViewContainer.setVisibility(View.VISIBLE); 527c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 528c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee }); 529c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 530ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // If the favorites fragment hasn't been fully created before the dialpad fragment 531ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // is hidden (i.e. onResume), don't bother animating 532ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (mPhoneFavoriteFragment == null || mPhoneFavoriteFragment.getView() == null) { 533ef2b7388569a94432278a617b528f628385fbb8cYorke Lee mBottomPaddingView.setVisibility(View.GONE); 534ef2b7388569a94432278a617b528f628385fbb8cYorke Lee return; 535ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 536c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mPhoneFavoriteFragment.getView().setTranslationY(-mSearchViewContainer.getHeight()); 537c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mPhoneFavoriteFragment.getView().animate().withLayer().translationY(0).setDuration(200) 538c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee .setListener( 539c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee new AnimatorListenerAdapter() { 540c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 541c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onAnimationStart(Animator animation) { 542c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mBottomPaddingView.setVisibility(View.GONE); 543c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 544c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee }); 54594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 54694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 54794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 548c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void setupFakeActionBarItemsForFavoritesFragment() { 549c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mMenuButton = findViewById(R.id.overflow_menu); 550c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (mMenuButton != null) { 551c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mMenuButton.setOnClickListener(this); 552c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 553c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 554c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mCallHistoryButton = findViewById(R.id.call_history_button); 555c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // mCallHistoryButton.setMinimumWidth(fakeMenuItemWidth); 556c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mCallHistoryButton.setOnClickListener(this); 557c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 558c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mDialpadButton = findViewById(R.id.dialpad_button); 559c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // DialpadButton.setMinimumWidth(fakeMenuItemWidth); 560c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mDialpadButton.setOnClickListener(this); 5619c1e0653addc1fff03601289a9f9a57b1daeaf57Christine Chen } 5629c1e0653addc1fff03601289a9f9a57b1daeaf57Christine Chen 563c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void setupFakeActionBarItemsForDialpadFragment() { 564c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final View callhistoryButton = findViewById(R.id.call_history_on_dialpad_button); 565c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee callhistoryButton.setOnClickListener(this); 56694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 56794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 56894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private void fixIntent(Intent intent) { 56994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // This should be cleaned up: the call key used to send an Intent 57094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // that just said to go to the recent calls list. It now sends this 57194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // abstract action, but this class hasn't been rewritten to deal with it. 57294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (Intent.ACTION_CALL_BUTTON.equals(intent.getAction())) { 57394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.setDataAndType(Calls.CONTENT_URI, Calls.CONTENT_TYPE); 57494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.putExtra("call_key", true); 57594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng setIntent(intent); 57694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 57794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 57894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 57994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 58094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Returns true if the intent is due to hitting the green send key (hardware call button: 58194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * KEYCODE_CALL) while in a call. 58294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 58394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @param intent the intent that launched this activity 58494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @param recentCallsRequest true if the intent is requesting to view recent calls 58594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @return true if the intent is due to hitting the green send key while in a call 58694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 587c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private boolean isSendKeyWhileInCall(Intent intent, boolean recentCallsRequest) { 58894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // If there is a call in progress go to the call screen 58994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (recentCallsRequest) { 59094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final boolean callKey = intent.getBooleanExtra("call_key", false); 59194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 59294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng try { 59394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); 59494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (callKey && phone != null && phone.showCallScreen()) { 59594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return true; 59694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 59794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } catch (RemoteException e) { 59894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Log.e(TAG, "Failed to handle send while in call", e); 59994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 60094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 60194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 60294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return false; 60394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 60494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 60594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 60694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Sets the current tab based on the intent's request type 60794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 60894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @param intent Intent that contains information about which tab should be selected 60994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 610c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private void displayFragment(Intent intent) { 61194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // If we got here by hitting send and we're in call forward along to the in-call activity 61294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng boolean recentCallsRequest = Calls.CONTENT_TYPE.equals(intent.resolveType( 61394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng getContentResolver())); 61494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (isSendKeyWhileInCall(intent, recentCallsRequest)) { 61594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng finish(); 61694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return; 61794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 61894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 61998702de246d42c844fabdb8a1f3407bf1747d379Yorke Lee if (mDialpadFragment != null && (phoneIsInUse() || isDialIntent(intent))) { 620c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mDialpadFragment.setStartedFromNewIntent(true); 621ea695cb0f877ad49a98df184efe982de83ed09d7Yorke Lee showDialpadFragment(false); 62294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 62394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 62494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 62594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 62694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onNewIntent(Intent newIntent) { 62794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng setIntent(newIntent); 62894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng fixIntent(newIntent); 629c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee displayFragment(newIntent); 63094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final String action = newIntent.getAction(); 631c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 63294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng invalidateOptionsMenu(); 63394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 63494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 63594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** Returns true if the given intent contains a phone number to populate the dialer with */ 63694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private boolean isDialIntent(Intent intent) { 63794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final String action = intent.getAction(); 63894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (Intent.ACTION_DIAL.equals(action) || ACTION_TOUCH_DIALER.equals(action)) { 63994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return true; 64094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 64194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (Intent.ACTION_VIEW.equals(action)) { 64294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final Uri data = intent.getData(); 6439d4f3b20793a007b4489547aa40fc1049d0d8fefChiao Cheng if (data != null && CallUtil.SCHEME_TEL.equals(data.getScheme())) { 64494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return true; 64594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 64694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 64794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return false; 64894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 64994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 65094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 65194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Returns an appropriate call origin for this Activity. May return null when no call origin 65294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * should be used (e.g. when some 3rd party application launched the screen. Call origin is 65394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * for remembering the tab in which the user made a phone call, so the external app's DIAL 65494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * request should not be counted.) 65594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 65694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public String getCallOrigin() { 65794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return !isDialIntent(getIntent()) ? CALL_ORIGIN_DIALTACTS : null; 65894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 65994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 66094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 66194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Retrieves the filter text stored in {@link #setupFilterText(Intent)}. 66294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * This text originally came from a FILTER_CONTACTS_ACTION intent received 66394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * by this activity. The stored text will then be cleared after after this 66494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * method returns. 66594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 66694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @return The stored filter text 66794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 66894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public String getAndClearFilterText() { 66994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng String filterText = mFilterText; 67094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng mFilterText = null; 67194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return filterText; 67294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 67394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 67494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 67594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Stores the filter text associated with a FILTER_CONTACTS_ACTION intent. 67694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * This is so child activities can check if they are supposed to display a filter. 67794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 67894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * @param intent The intent received in {@link #onNewIntent(Intent)} 67994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 68094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private void setupFilterText(Intent intent) { 68194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // If the intent was relaunched from history, don't apply the filter text. 68294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { 68394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return; 68494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 68594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng String filter = intent.getStringExtra(UI.FILTER_TEXT_EXTRA_KEY); 68694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (filter != null && filter.length() > 0) { 68794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng mFilterText = filter; 68894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 68994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 69094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 6918898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Lee private final PhoneFavoriteFragment.Listener mPhoneFavoriteListener = 6928898cd0577d41cfa4e6acf785c9e904bd71fbdfdYorke Lee new PhoneFavoriteFragment.Listener() { 69394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 69494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onContactSelected(Uri contactUri) { 69594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng PhoneNumberInteraction.startInteractionForPhoneCall( 696c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee DialtactsActivity.this, contactUri, getCallOrigin()); 69794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 69894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 69994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 70094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void onCallNumberDirectly(String phoneNumber) { 7019d4f3b20793a007b4489547aa40fc1049d0d8fefChiao Cheng Intent intent = CallUtil.getCallIntent(phoneNumber, getCallOrigin()); 70294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng startActivity(intent); 70394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 70494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng }; 70594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 706c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee /* TODO krelease: This is only relevant for phones that have a hard button search key (i.e. 707c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * Nexus S). Supporting it is a little more tricky because of the dialpad fragment might 708c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * be showing when the search key is pressed so there is more state management involved. 70994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 71094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 71194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public void startSearch(String initialQuery, boolean selectInitialQuery, 71294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Bundle appSearchData, boolean globalSearch) { 713c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (mRegularSearchFragment != null && mRegularSearchFragment.isAdded() && !globalSearch) { 71494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (mInSearchUi) { 71594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (mSearchView.hasFocus()) { 71694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng showInputMethod(mSearchView.findFocus()); 71794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } else { 71894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng mSearchView.requestFocus(); 71994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 72094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } else { 72194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng enterSearchUi(); 72294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 72394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } else { 72494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); 72594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 726c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee }*/ 72794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 72894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private void showInputMethod(View view) { 729c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final InputMethodManager imm = (InputMethodManager) getSystemService( 730c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Context.INPUT_METHOD_SERVICE); 73194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (imm != null) { 732c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee imm.showSoftInput(view, 0); 73394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 73494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 73594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 73694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng private void hideInputMethod(View view) { 737c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final InputMethodManager imm = (InputMethodManager) getSystemService( 738c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Context.INPUT_METHOD_SERVICE); 73994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (imm != null && view != null) { 74094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 74194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 74294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 74394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 74494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 745c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * Shows the search fragment 74694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 747ef2b7388569a94432278a617b528f628385fbb8cYorke Lee private void enterSearchUi(boolean smartDialSearch, String query) { 74834bdf87700194c35ab8f43c001391bb2ac8bc993Yorke Lee if (getFragmentManager().isDestroyed()) { 74934bdf87700194c35ab8f43c001391bb2ac8bc993Yorke Lee // Weird race condition where fragment is doing work after the activity is destroyed 75034bdf87700194c35ab8f43c001391bb2ac8bc993Yorke Lee // due to talkback being on (b/10209937). Just return since we can't do any 75134bdf87700194c35ab8f43c001391bb2ac8bc993Yorke Lee // constructive here. 75234bdf87700194c35ab8f43c001391bb2ac8bc993Yorke Lee return; 75334bdf87700194c35ab8f43c001391bb2ac8bc993Yorke Lee } 75434bdf87700194c35ab8f43c001391bb2ac8bc993Yorke Lee 755ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (DEBUG) { 756ef2b7388569a94432278a617b528f628385fbb8cYorke Lee Log.d(TAG, "Entering search UI - smart dial " + smartDialSearch); 757ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 758ef2b7388569a94432278a617b528f628385fbb8cYorke Lee final String tag = smartDialSearch ? TAG_SMARTDIAL_SEARCH_FRAGMENT : 759ef2b7388569a94432278a617b528f628385fbb8cYorke Lee TAG_REGULAR_SEARCH_FRAGMENT; 760ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 761c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final FragmentTransaction transaction = getFragmentManager().beginTransaction(); 762c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 763ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 764ef2b7388569a94432278a617b528f628385fbb8cYorke Lee SearchFragment fragment; 765ef2b7388569a94432278a617b528f628385fbb8cYorke Lee 766ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.remove(mPhoneFavoriteFragment); 767ef2b7388569a94432278a617b528f628385fbb8cYorke Lee fragment = (SearchFragment) getFragmentManager().findFragmentByTag(tag); 768ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (fragment == null) { 769ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (smartDialSearch) { 770ef2b7388569a94432278a617b528f628385fbb8cYorke Lee fragment = new SmartDialSearchFragment(); 771ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } else { 772ef2b7388569a94432278a617b528f628385fbb8cYorke Lee fragment = new SearchFragment(); 773ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 774ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.replace(R.id.dialtacts_frame, fragment, tag); 775c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else { 776ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.attach(fragment); 77794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 77894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 779ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.addToBackStack(null); 780ef2b7388569a94432278a617b528f628385fbb8cYorke Lee fragment.setQueryString(query, false); 781ef2b7388569a94432278a617b528f628385fbb8cYorke Lee transaction.commit(); 782c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mInSearchUi = true; 78394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 78494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 78594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** 786c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee * Hides the search fragment 78794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 788c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private void exitSearchUi() { 789ef2b7388569a94432278a617b528f628385fbb8cYorke Lee getFragmentManager().popBackStack(); 790c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mInSearchUi = false; 79194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 79294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 79394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng /** Returns an Intent to launch Call Settings screen */ 79494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public static Intent getCallSettingsIntent() { 79594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final Intent intent = new Intent(Intent.ACTION_MAIN); 79694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.setClassName(PHONE_PACKAGE, CALL_SETTINGS_CLASS_NAME); 79794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 79894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return intent; 79994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 80094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 80194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 802c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onBackPressed() { 803ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (mDialpadFragment != null && mDialpadFragment.isVisible()) { 804f6673d3e5cbd10febea04f02035591ab15c5c7c0Yorke Lee hideDialpadFragment(true, false); 805c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else if (mInSearchUi) { 806c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setText(null); 807f6673d3e5cbd10febea04f02035591ab15c5c7c0Yorke Lee mDialpadFragment.clearDialpad(); 808c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else if (isTaskRoot()) { 809c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // Instead of stopping, simply push this to the back of the stack. 810c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // This is only done when running at the top of the stack; 811c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // otherwise, we have been launched by someone else so need to 812c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee // allow the user to go back to the caller. 813c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee moveTaskToBack(false); 814c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } else { 815c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee super.onBackPressed(); 81694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 817c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 818c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 819c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 820c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onDialpadQueryChanged(String query) { 821c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final String normalizedQuery = SmartDialNameMatcher.normalizeNumber(query, 822c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee SmartDialNameMatcher.LATIN_SMART_DIAL_MAP); 823c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) { 824ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (DEBUG) { 825ef2b7388569a94432278a617b528f628385fbb8cYorke Lee Log.d(TAG, "onDialpadQueryChanged - new query: " + query); 826ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 827ef2b7388569a94432278a617b528f628385fbb8cYorke Lee if (mDialpadFragment == null || !mDialpadFragment.isVisible()) { 828ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // This callback can happen if the dialpad fragment is recreated because of 829ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // activity destruction. In that case, don't update the search view because 830ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // that would bring the user back to the search fragment regardless of the 831ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // previous state of the application. Instead, just return here and let the 832ef2b7388569a94432278a617b528f628385fbb8cYorke Lee // fragment manager correctly figure out whatever fragment was last displayed. 833ef2b7388569a94432278a617b528f628385fbb8cYorke Lee return; 834ef2b7388569a94432278a617b528f628385fbb8cYorke Lee } 835c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee mSearchView.setText(normalizedQuery); 83694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 83794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 838c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 839c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 840c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onListFragmentScrollStateChange(int scrollState) { 841c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { 842f6673d3e5cbd10febea04f02035591ab15c5c7c0Yorke Lee hideDialpadFragment(true, false); 843c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee hideInputMethod(getCurrentFocus()); 844c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 845c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 846c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 847c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 848c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onPhoneFavoriteFragmentStarted() { 849c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee setupFakeActionBarItemsForFavoritesFragment(); 850c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 851c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 852c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee @Override 853c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee public void onDialpadFragmentStarted() { 854c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee setupFakeActionBarItemsForDialpadFragment(); 855c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 856c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee 857c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee private boolean phoneIsInUse() { 858c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee final TelephonyManager tm = (TelephonyManager) getSystemService( 859c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee Context.TELEPHONY_SERVICE); 860c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee return tm.getCallState() != TelephonyManager.CALL_STATE_IDLE; 861c3766338b312f9c8a6bdb2facaf4b0a4bd199de4Yorke Lee } 8628dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee 8638dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee @Override 8648dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee public void onShowAllContacts() { 8658dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee final Intent intent = new Intent(this, AllContactsActivity.class); 8668dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee startActivity(intent); 8678dd6200bef2eb07486f4c7e288941cfcfed35e79Yorke Lee } 86894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng} 869