From 929674acc5ff2798b767692bbad4143575d31c3b Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Fri, 18 Aug 2017 15:03:13 -0700 Subject: Refactor dialpad fragment out of dialer/app to be reused in nui This change updates a few things: - Adds a listener for the dialpad to call into dialtacts activity - updates FragmentUtils to accept non-support fragments - migrates a few other related (tightly coupled) classes to their own package - general QoL changes Bug: 37748839,37208802 Test: existing PiperOrigin-RevId: 165757904 Change-Id: I506e97ad9a01d07c760e766eccc4d146f8e0931a --- java/com/android/dialer/app/DialtactsActivity.java | 27 +- .../android/dialer/app/SpecialCharSequenceMgr.java | 492 ------ .../dialer/app/dialpad/DialpadFragment.java | 1740 -------------------- .../app/dialpad/PseudoEmergencyAnimator.java | 161 -- .../dialer/app/dialpad/SmartDialCursorLoader.java | 183 -- .../app/dialpad/UnicodeDialerKeyListener.java | 56 - .../android/dialer/app/list/SearchFragment.java | 2 +- .../app/list/SmartDialNumberListAdapter.java | 10 +- .../dialer/app/list/SmartDialSearchFragment.java | 2 +- .../res/drawable-hdpi/ic_dialer_fork_add_call.png | Bin 1649 -> 0 bytes .../drawable-hdpi/ic_dialer_fork_current_call.png | Bin 2305 -> 0 bytes .../res/drawable-hdpi/ic_dialer_fork_tt_keypad.png | Bin 2419 -> 0 bytes .../res/drawable-mdpi/ic_dialer_fork_add_call.png | Bin 1309 -> 0 bytes .../drawable-mdpi/ic_dialer_fork_current_call.png | Bin 1581 -> 0 bytes .../res/drawable-mdpi/ic_dialer_fork_tt_keypad.png | Bin 1586 -> 0 bytes .../res/drawable-xhdpi/ic_dialer_fork_add_call.png | Bin 2150 -> 0 bytes .../drawable-xhdpi/ic_dialer_fork_current_call.png | Bin 3154 -> 0 bytes .../drawable-xhdpi/ic_dialer_fork_tt_keypad.png | Bin 3298 -> 0 bytes .../drawable-xxhdpi/ic_dialer_fork_add_call.png | Bin 2583 -> 0 bytes .../ic_dialer_fork_current_call.png | Bin 3622 -> 0 bytes .../drawable-xxhdpi/ic_dialer_fork_tt_keypad.png | Bin 3229 -> 0 bytes .../dialer/app/res/drawable/ic_wifi_calling.xml | 29 - .../dialer/app/res/drawable/shadow_fade_left.xml | 24 - .../dialer/app/res/drawable/shadow_fade_up.xml | 24 - .../app/res/layout-land/dialpad_fragment.xml | 82 - .../app/res/layout/dialpad_chooser_list_item.xml | 38 - .../dialer/app/res/layout/dialpad_fragment.xml | 72 - .../dialer/app/res/menu/dialpad_options.xml | 30 - java/com/android/dialer/app/res/values/dimens.xml | 3 - .../app/res/values/donottranslate_config.xml | 5 - java/com/android/dialer/app/res/values/strings.xml | 53 - 31 files changed, 27 insertions(+), 3006 deletions(-) delete mode 100644 java/com/android/dialer/app/SpecialCharSequenceMgr.java delete mode 100644 java/com/android/dialer/app/dialpad/DialpadFragment.java delete mode 100644 java/com/android/dialer/app/dialpad/PseudoEmergencyAnimator.java delete mode 100644 java/com/android/dialer/app/dialpad/SmartDialCursorLoader.java delete mode 100644 java/com/android/dialer/app/dialpad/UnicodeDialerKeyListener.java delete mode 100755 java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_add_call.png delete mode 100755 java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_current_call.png delete mode 100755 java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_tt_keypad.png delete mode 100644 java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_add_call.png delete mode 100644 java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_current_call.png delete mode 100644 java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_tt_keypad.png delete mode 100644 java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_add_call.png delete mode 100644 java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_current_call.png delete mode 100644 java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_tt_keypad.png delete mode 100644 java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_add_call.png delete mode 100644 java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_current_call.png delete mode 100644 java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_tt_keypad.png delete mode 100644 java/com/android/dialer/app/res/drawable/ic_wifi_calling.xml delete mode 100644 java/com/android/dialer/app/res/drawable/shadow_fade_left.xml delete mode 100644 java/com/android/dialer/app/res/drawable/shadow_fade_up.xml delete mode 100644 java/com/android/dialer/app/res/layout-land/dialpad_fragment.xml delete mode 100644 java/com/android/dialer/app/res/layout/dialpad_chooser_list_item.xml delete mode 100644 java/com/android/dialer/app/res/layout/dialpad_fragment.xml delete mode 100644 java/com/android/dialer/app/res/menu/dialpad_options.xml (limited to 'java/com/android/dialer/app') diff --git a/java/com/android/dialer/app/DialtactsActivity.java b/java/com/android/dialer/app/DialtactsActivity.java index d7edc6838..04545b5c7 100644 --- a/java/com/android/dialer/app/DialtactsActivity.java +++ b/java/com/android/dialer/app/DialtactsActivity.java @@ -73,10 +73,10 @@ import com.android.dialer.animation.AnimUtils; import com.android.dialer.animation.AnimationListenerAdapter; import com.android.dialer.app.calllog.CallLogActivity; import com.android.dialer.app.calllog.CallLogAdapter; +import com.android.dialer.app.calllog.CallLogAsync; import com.android.dialer.app.calllog.CallLogFragment; import com.android.dialer.app.calllog.CallLogNotificationsService; import com.android.dialer.app.calllog.IntentProvider; -import com.android.dialer.app.dialpad.DialpadFragment; import com.android.dialer.app.list.DialtactsPagerAdapter; import com.android.dialer.app.list.DialtactsPagerAdapter.TabIndex; import com.android.dialer.app.list.DragDropController; @@ -102,6 +102,9 @@ import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.constants.ActivityRequestCodes; import com.android.dialer.database.Database; import com.android.dialer.database.DialerDatabaseHelper; +import com.android.dialer.dialpadview.DialpadFragment; +import com.android.dialer.dialpadview.DialpadFragment.DialpadListener; +import com.android.dialer.dialpadview.DialpadFragment.LastOutgoingCallCallback; import com.android.dialer.interactions.PhoneNumberInteraction; import com.android.dialer.interactions.PhoneNumberInteraction.InteractionErrorCode; import com.android.dialer.logging.DialerImpression; @@ -153,7 +156,8 @@ public class DialtactsActivity extends TransactionSafeActivity ActionBarController.ActivityUi, PhoneNumberInteraction.InteractionErrorListener, PhoneNumberInteraction.DisambigDialogDismissedListener, - ActivityCompat.OnRequestPermissionsResultCallback { + ActivityCompat.OnRequestPermissionsResultCallback, + DialpadListener { public static final boolean DEBUG = false; @VisibleForTesting public static final String TAG_DIALPAD_FRAGMENT = "dialpad"; @@ -346,6 +350,7 @@ public class DialtactsActivity extends TransactionSafeActivity return false; } }; + /** * The text returned from a voice search query. Set in {@link #onActivityResult} and used in * {@link #onResume()} to populate the search box. @@ -403,12 +408,12 @@ public class DialtactsActivity extends TransactionSafeActivity actionBar.setBackgroundDrawable(null); SearchEditTextLayout searchEditTextLayout = - (SearchEditTextLayout) actionBar.getCustomView().findViewById(R.id.search_view_container); + actionBar.getCustomView().findViewById(R.id.search_view_container); searchEditTextLayout.setPreImeKeyListener(mSearchEditTextLayoutListener); mActionBarController = new ActionBarController(this, searchEditTextLayout); - mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view); + mSearchView = searchEditTextLayout.findViewById(R.id.search_view); mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); mVoiceSearchButton = searchEditTextLayout.findViewById(R.id.voice_search_button); searchEditTextLayout @@ -431,14 +436,13 @@ public class DialtactsActivity extends TransactionSafeActivity mIsLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; mPreviouslySelectedTabIndex = DialtactsPagerAdapter.TAB_INDEX_SPEED_DIAL; - FloatingActionButton floatingActionButton = - (FloatingActionButton) findViewById(R.id.floating_action_button); + FloatingActionButton floatingActionButton = findViewById(R.id.floating_action_button); floatingActionButton.setOnClickListener(this); mFloatingActionButtonController = new FloatingActionButtonController(this, floatingActionButton); ImageButton optionsMenuButton = - (ImageButton) searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button); + searchEditTextLayout.findViewById(R.id.dialtacts_options_menu_button); optionsMenuButton.setOnClickListener(this); mOverflowMenu = buildOptionsMenu(optionsMenuButton); optionsMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener()); @@ -857,7 +861,15 @@ public class DialtactsActivity extends TransactionSafeActivity setTitle(R.string.launcherDialpadActivityLabel); } + @Override + public void getLastOutgoingCall(LastOutgoingCallCallback callback) { + new CallLogAsync() + .getLastOutgoingCall( + new CallLogAsync.GetLastOutgoingCallArgs(this, callback::lastOutgoingCall)); + } + /** Callback from child DialpadFragment when the dialpad is shown. */ + @Override public void onDialpadShown() { LogUtil.d("DialtactsActivity.onDialpadShown", ""); Assert.isNotNull(mDialpadFragment); @@ -876,6 +888,7 @@ public class DialtactsActivity extends TransactionSafeActivity * * @see #commitDialpadFragmentHide */ + @Override public void hideDialpadFragment(boolean animate, boolean clearDialpad) { if (mDialpadFragment == null || mDialpadFragment.getView() == null) { return; diff --git a/java/com/android/dialer/app/SpecialCharSequenceMgr.java b/java/com/android/dialer/app/SpecialCharSequenceMgr.java deleted file mode 100644 index fd67f4704..000000000 --- a/java/com/android/dialer/app/SpecialCharSequenceMgr.java +++ /dev/null @@ -1,492 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.app; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.DialogFragment; -import android.app.KeyguardManager; -import android.app.ProgressDialog; -import android.content.ActivityNotFoundException; -import android.content.ContentResolver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.database.Cursor; -import android.net.Uri; -import android.provider.Settings; -import android.support.annotation.Nullable; -import android.telecom.PhoneAccount; -import android.telecom.PhoneAccountHandle; -import android.telephony.PhoneNumberUtils; -import android.telephony.TelephonyManager; -import android.text.TextUtils; -import android.view.WindowManager; -import android.widget.EditText; -import android.widget.Toast; -import com.android.common.io.MoreCloseables; -import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler; -import com.android.contacts.common.util.ContactDisplayUtils; -import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; -import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener; -import com.android.dialer.calllogutils.PhoneAccountUtils; -import com.android.dialer.common.Assert; -import com.android.dialer.common.LogUtil; -import com.android.dialer.compat.telephony.TelephonyManagerCompat; -import com.android.dialer.oem.MotorolaUtils; -import com.android.dialer.telecom.TelecomUtil; -import java.util.ArrayList; -import java.util.List; - -/** - * Helper class to listen for some magic character sequences that are handled specially by the - * dialer. - * - *

Note the Phone app also handles these sequences too (in a couple of relatively obscure places - * in the UI), so there's a separate version of this class under apps/Phone. - * - *

TODO: there's lots of duplicated code between this class and the corresponding class under - * apps/Phone. Let's figure out a way to unify these two classes (in the framework? in a common - * shared library?) - */ -public class SpecialCharSequenceMgr { - - private static final String TAG = "SpecialCharSequenceMgr"; - - private static final String TAG_SELECT_ACCT_FRAGMENT = "tag_select_acct_fragment"; - - private static final String MMI_IMEI_DISPLAY = "*#06#"; - private static final String MMI_REGULATORY_INFO_DISPLAY = "*#07#"; - /** ***** This code is used to handle SIM Contact queries ***** */ - private static final String ADN_PHONE_NUMBER_COLUMN_NAME = "number"; - - private static final String ADN_NAME_COLUMN_NAME = "name"; - private static final int ADN_QUERY_TOKEN = -1; - /** - * Remembers the previous {@link QueryHandler} and cancel the operation when needed, to prevent - * possible crash. - * - *

QueryHandler may call {@link ProgressDialog#dismiss()} when the screen is already gone, - * which will cause the app crash. This variable enables the class to prevent the crash on {@link - * #cleanup()}. - * - *

TODO: Remove this and replace it (and {@link #cleanup()}) with better implementation. One - * complication is that we have SpecialCharSequenceMgr in Phone package too, which has *slightly* - * different implementation. Note that Phone package doesn't have this problem, so the class on - * Phone side doesn't have this functionality. Fundamental fix would be to have one shared - * implementation and resolve this corner case more gracefully. - */ - private static QueryHandler sPreviousAdnQueryHandler; - - /** This class is never instantiated. */ - private SpecialCharSequenceMgr() {} - - public static boolean handleChars(Context context, String input, EditText textField) { - //get rid of the separators so that the string gets parsed correctly - String dialString = PhoneNumberUtils.stripSeparators(input); - - if (handleDeviceIdDisplay(context, dialString) - || handleRegulatoryInfoDisplay(context, dialString) - || handlePinEntry(context, dialString) - || handleAdnEntry(context, dialString, textField) - || handleSecretCode(context, dialString)) { - return true; - } - - if (MotorolaUtils.handleSpecialCharSequence(context, input)) { - return true; - } - - return false; - } - - /** - * Cleanup everything around this class. Must be run inside the main thread. - * - *

This should be called when the screen becomes background. - */ - public static void cleanup() { - Assert.isMainThread(); - - if (sPreviousAdnQueryHandler != null) { - sPreviousAdnQueryHandler.cancel(); - sPreviousAdnQueryHandler = null; - } - } - - /** - * Handles secret codes to launch arbitrary activities in the form of *#*##*#*. - * - * @param context the context to use - * @param input the text to check for a secret code in - * @return true if a secret code was encountered and handled - */ - static boolean handleSecretCode(Context context, String input) { - // Secret codes are accessed by dialing *#*##*#* - - int len = input.length(); - if (len <= 8 || !input.startsWith("*#*#") || !input.endsWith("#*#*")) { - return false; - } - String secretCode = input.substring(4, len - 4); - TelephonyManagerCompat.handleSecretCode(context, secretCode); - return true; - } - - /** - * Handle ADN requests by filling in the SIM contact number into the requested EditText. - * - *

This code works alongside the Asynchronous query handler {@link QueryHandler} and query - * cancel handler implemented in {@link SimContactQueryCookie}. - */ - static boolean handleAdnEntry(Context context, String input, EditText textField) { - /* ADN entries are of the form "N(N)(N)#" */ - TelephonyManager telephonyManager = - (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - if (telephonyManager == null - || telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_GSM) { - return false; - } - - // if the phone is keyguard-restricted, then just ignore this - // input. We want to make sure that sim card contacts are NOT - // exposed unless the phone is unlocked, and this code can be - // accessed from the emergency dialer. - KeyguardManager keyguardManager = - (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); - if (keyguardManager.inKeyguardRestrictedInputMode()) { - return false; - } - - int len = input.length(); - if ((len > 1) && (len < 5) && (input.endsWith("#"))) { - try { - // get the ordinal number of the sim contact - final int index = Integer.parseInt(input.substring(0, len - 1)); - - // The original code that navigated to a SIM Contacts list view did not - // highlight the requested contact correctly, a requirement for PTCRB - // certification. This behaviour is consistent with the UI paradigm - // for touch-enabled lists, so it does not make sense to try to work - // around it. Instead we fill in the the requested phone number into - // the dialer text field. - - // create the async query handler - final QueryHandler handler = new QueryHandler(context.getContentResolver()); - - // create the cookie object - final SimContactQueryCookie sc = - new SimContactQueryCookie(index - 1, handler, ADN_QUERY_TOKEN); - - // setup the cookie fields - sc.contactNum = index - 1; - sc.setTextField(textField); - - // create the progress dialog - sc.progressDialog = new ProgressDialog(context); - sc.progressDialog.setTitle(R.string.simContacts_title); - sc.progressDialog.setMessage(context.getText(R.string.simContacts_emptyLoading)); - sc.progressDialog.setIndeterminate(true); - sc.progressDialog.setCancelable(true); - sc.progressDialog.setOnCancelListener(sc); - sc.progressDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); - - List subscriptionAccountHandles = - PhoneAccountUtils.getSubscriptionPhoneAccounts(context); - Context applicationContext = context.getApplicationContext(); - boolean hasUserSelectedDefault = - subscriptionAccountHandles.contains( - TelecomUtil.getDefaultOutgoingPhoneAccount( - applicationContext, PhoneAccount.SCHEME_TEL)); - - if (subscriptionAccountHandles.size() <= 1 || hasUserSelectedDefault) { - Uri uri = TelecomUtil.getAdnUriForPhoneAccount(applicationContext, null); - handleAdnQuery(handler, sc, uri); - } else { - SelectPhoneAccountListener callback = - new HandleAdnEntryAccountSelectedCallback(applicationContext, handler, sc); - - DialogFragment dialogFragment = - SelectPhoneAccountDialogFragment.newInstance( - subscriptionAccountHandles, callback, null); - dialogFragment.show(((Activity) context).getFragmentManager(), TAG_SELECT_ACCT_FRAGMENT); - } - - return true; - } catch (NumberFormatException ex) { - // Ignore - } - } - return false; - } - - private static void handleAdnQuery(QueryHandler handler, SimContactQueryCookie cookie, Uri uri) { - if (handler == null || cookie == null || uri == null) { - LogUtil.w("SpecialCharSequenceMgr.handleAdnQuery", "queryAdn parameters incorrect"); - return; - } - - // display the progress dialog - cookie.progressDialog.show(); - - // run the query. - handler.startQuery( - ADN_QUERY_TOKEN, - cookie, - uri, - new String[] {ADN_PHONE_NUMBER_COLUMN_NAME}, - null, - null, - null); - - if (sPreviousAdnQueryHandler != null) { - // It is harmless to call cancel() even after the handler's gone. - sPreviousAdnQueryHandler.cancel(); - } - sPreviousAdnQueryHandler = handler; - } - - static boolean handlePinEntry(final Context context, final String input) { - if ((input.startsWith("**04") || input.startsWith("**05")) && input.endsWith("#")) { - List subscriptionAccountHandles = - PhoneAccountUtils.getSubscriptionPhoneAccounts(context); - boolean hasUserSelectedDefault = - subscriptionAccountHandles.contains( - TelecomUtil.getDefaultOutgoingPhoneAccount(context, PhoneAccount.SCHEME_TEL)); - - if (subscriptionAccountHandles.size() <= 1 || hasUserSelectedDefault) { - // Don't bring up the dialog for single-SIM or if the default outgoing account is - // a subscription account. - return TelecomUtil.handleMmi(context, input, null); - } else { - SelectPhoneAccountListener listener = new HandleMmiAccountSelectedCallback(context, input); - - DialogFragment dialogFragment = - SelectPhoneAccountDialogFragment.newInstance( - subscriptionAccountHandles, listener, null); - dialogFragment.show(((Activity) context).getFragmentManager(), TAG_SELECT_ACCT_FRAGMENT); - } - return true; - } - return false; - } - - // TODO: Use TelephonyCapabilities.getDeviceIdLabel() to get the device id label instead of a - // hard-coded string. - static boolean handleDeviceIdDisplay(Context context, String input) { - TelephonyManager telephonyManager = - (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - - if (telephonyManager != null && input.equals(MMI_IMEI_DISPLAY)) { - int labelResId = - (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) - ? R.string.imei - : R.string.meid; - - List deviceIds = new ArrayList(); - if (TelephonyManagerCompat.getPhoneCount(telephonyManager) > 1) { - for (int slot = 0; slot < telephonyManager.getPhoneCount(); slot++) { - String deviceId = telephonyManager.getDeviceId(slot); - if (!TextUtils.isEmpty(deviceId)) { - deviceIds.add(deviceId); - } - } - } else { - deviceIds.add(telephonyManager.getDeviceId()); - } - - new AlertDialog.Builder(context) - .setTitle(labelResId) - .setItems(deviceIds.toArray(new String[deviceIds.size()]), null) - .setPositiveButton(android.R.string.ok, null) - .setCancelable(false) - .show(); - return true; - } - return false; - } - - private static boolean handleRegulatoryInfoDisplay(Context context, String input) { - if (input.equals(MMI_REGULATORY_INFO_DISPLAY)) { - LogUtil.i( - "SpecialCharSequenceMgr.handleRegulatoryInfoDisplay", "sending intent to settings app"); - Intent showRegInfoIntent = new Intent(Settings.ACTION_SHOW_REGULATORY_INFO); - try { - context.startActivity(showRegInfoIntent); - } catch (ActivityNotFoundException e) { - LogUtil.e( - "SpecialCharSequenceMgr.handleRegulatoryInfoDisplay", "startActivity() failed: ", e); - } - return true; - } - return false; - } - - public static class HandleAdnEntryAccountSelectedCallback extends SelectPhoneAccountListener { - - private final Context mContext; - private final QueryHandler mQueryHandler; - private final SimContactQueryCookie mCookie; - - public HandleAdnEntryAccountSelectedCallback( - Context context, QueryHandler queryHandler, SimContactQueryCookie cookie) { - mContext = context; - mQueryHandler = queryHandler; - mCookie = cookie; - } - - @Override - public void onPhoneAccountSelected( - PhoneAccountHandle selectedAccountHandle, boolean setDefault, @Nullable String callId) { - Uri uri = TelecomUtil.getAdnUriForPhoneAccount(mContext, selectedAccountHandle); - handleAdnQuery(mQueryHandler, mCookie, uri); - // TODO: Show error dialog if result isn't valid. - } - } - - public static class HandleMmiAccountSelectedCallback extends SelectPhoneAccountListener { - - private final Context mContext; - private final String mInput; - - public HandleMmiAccountSelectedCallback(Context context, String input) { - mContext = context.getApplicationContext(); - mInput = input; - } - - @Override - public void onPhoneAccountSelected( - PhoneAccountHandle selectedAccountHandle, boolean setDefault, @Nullable String callId) { - TelecomUtil.handleMmi(mContext, mInput, selectedAccountHandle); - } - } - - /** - * Cookie object that contains everything we need to communicate to the handler's onQuery - * Complete, as well as what we need in order to cancel the query (if requested). - * - *

Note, access to the textField field is going to be synchronized, because the user can - * request a cancel at any time through the UI. - */ - private static class SimContactQueryCookie implements DialogInterface.OnCancelListener { - - public ProgressDialog progressDialog; - public int contactNum; - - // Used to identify the query request. - private int mToken; - private QueryHandler mHandler; - - // The text field we're going to update - private EditText textField; - - public SimContactQueryCookie(int number, QueryHandler handler, int token) { - contactNum = number; - mHandler = handler; - mToken = token; - } - - /** Synchronized getter for the EditText. */ - public synchronized EditText getTextField() { - return textField; - } - - /** Synchronized setter for the EditText. */ - public synchronized void setTextField(EditText text) { - textField = text; - } - - /** - * Cancel the ADN query by stopping the operation and signaling the cookie that a cancel request - * is made. - */ - @Override - public synchronized void onCancel(DialogInterface dialog) { - // close the progress dialog - if (progressDialog != null) { - progressDialog.dismiss(); - } - - // setting the textfield to null ensures that the UI does NOT get - // updated. - textField = null; - - // Cancel the operation if possible. - mHandler.cancelOperation(mToken); - } - } - - /** - * Asynchronous query handler that services requests to look up ADNs - * - *

Queries originate from {@link #handleAdnEntry}. - */ - private static class QueryHandler extends NoNullCursorAsyncQueryHandler { - - private boolean mCanceled; - - public QueryHandler(ContentResolver cr) { - super(cr); - } - - /** Override basic onQueryComplete to fill in the textfield when we're handed the ADN cursor. */ - @Override - protected void onNotNullableQueryComplete(int token, Object cookie, Cursor c) { - try { - sPreviousAdnQueryHandler = null; - if (mCanceled) { - return; - } - - SimContactQueryCookie sc = (SimContactQueryCookie) cookie; - - // close the progress dialog. - sc.progressDialog.dismiss(); - - // get the EditText to update or see if the request was cancelled. - EditText text = sc.getTextField(); - - // if the TextView is valid, and the cursor is valid and positionable on the - // Nth number, then we update the text field and display a toast indicating the - // caller name. - if ((c != null) && (text != null) && (c.moveToPosition(sc.contactNum))) { - String name = c.getString(c.getColumnIndexOrThrow(ADN_NAME_COLUMN_NAME)); - String number = c.getString(c.getColumnIndexOrThrow(ADN_PHONE_NUMBER_COLUMN_NAME)); - - // fill the text in. - text.getText().replace(0, 0, number); - - // display the name as a toast - Context context = sc.progressDialog.getContext(); - CharSequence msg = - ContactDisplayUtils.getTtsSpannedPhoneNumber( - context.getResources(), R.string.menu_callNumber, name); - Toast.makeText(context, msg, Toast.LENGTH_SHORT).show(); - } - } finally { - MoreCloseables.closeQuietly(c); - } - } - - public void cancel() { - mCanceled = true; - // Ask AsyncQueryHandler to cancel the whole request. This will fail when the query is - // already started. - cancelOperation(ADN_QUERY_TOKEN); - } - } -} diff --git a/java/com/android/dialer/app/dialpad/DialpadFragment.java b/java/com/android/dialer/app/dialpad/DialpadFragment.java deleted file mode 100644 index d58caa50a..000000000 --- a/java/com/android/dialer/app/dialpad/DialpadFragment.java +++ /dev/null @@ -1,1740 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.app.dialpad; - -import android.Manifest.permission; -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.DialogFragment; -import android.app.Fragment; -import android.content.BroadcastReceiver; -import android.content.ContentResolver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.pm.PackageManager; -import android.content.res.Resources; -import android.database.Cursor; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.media.AudioManager; -import android.media.ToneGenerator; -import android.net.Uri; -import android.os.Bundle; -import android.os.Trace; -import android.provider.Contacts.People; -import android.provider.Contacts.Phones; -import android.provider.Contacts.PhonesColumns; -import android.provider.Settings; -import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.content.ContextCompat; -import android.telecom.PhoneAccount; -import android.telecom.PhoneAccountHandle; -import android.telephony.PhoneNumberFormattingTextWatcher; -import android.telephony.PhoneNumberUtils; -import android.telephony.TelephonyManager; -import android.text.Editable; -import android.text.TextUtils; -import android.text.TextWatcher; -import android.util.AttributeSet; -import android.view.HapticFeedbackConstants; -import android.view.KeyEvent; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.BaseAdapter; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.ListView; -import android.widget.PopupMenu; -import android.widget.RelativeLayout; -import android.widget.TextView; -import com.android.contacts.common.dialog.CallSubjectDialog; -import com.android.contacts.common.util.StopWatch; -import com.android.contacts.common.widget.FloatingActionButtonController; -import com.android.dialer.animation.AnimUtils; -import com.android.dialer.app.DialtactsActivity; -import com.android.dialer.app.R; -import com.android.dialer.app.SpecialCharSequenceMgr; -import com.android.dialer.app.calllog.CallLogAsync; -import com.android.dialer.callintent.CallInitiationType; -import com.android.dialer.callintent.CallIntentBuilder; -import com.android.dialer.calllogutils.PhoneAccountUtils; -import com.android.dialer.common.LogUtil; -import com.android.dialer.common.concurrent.DialerExecutor; -import com.android.dialer.common.concurrent.DialerExecutor.Worker; -import com.android.dialer.common.concurrent.DialerExecutors; -import com.android.dialer.dialpadview.DialpadKeyButton; -import com.android.dialer.dialpadview.DialpadView; -import com.android.dialer.location.GeoUtil; -import com.android.dialer.logging.UiAction; -import com.android.dialer.oem.MotorolaUtils; -import com.android.dialer.performancereport.PerformanceReport; -import com.android.dialer.proguard.UsedByReflection; -import com.android.dialer.telecom.TelecomUtil; -import com.android.dialer.util.CallUtil; -import com.android.dialer.util.DialerUtils; -import com.android.dialer.util.PermissionsUtil; -import java.util.HashSet; -import java.util.List; - -/** Fragment that displays a twelve-key phone dialpad. */ -public class DialpadFragment extends Fragment - implements View.OnClickListener, - View.OnLongClickListener, - View.OnKeyListener, - AdapterView.OnItemClickListener, - TextWatcher, - PopupMenu.OnMenuItemClickListener, - DialpadKeyButton.OnPressedListener { - - private static final String TAG = "DialpadFragment"; - private static final boolean DEBUG = DialtactsActivity.DEBUG; - private static final String EMPTY_NUMBER = ""; - private static final char PAUSE = ','; - private static final char WAIT = ';'; - /** The length of DTMF tones in milliseconds */ - private static final int TONE_LENGTH_MS = 150; - - private static final int TONE_LENGTH_INFINITE = -1; - /** The DTMF tone volume relative to other sounds in the stream */ - private static final int TONE_RELATIVE_VOLUME = 80; - /** Stream type used to play the DTMF tones off call, and mapped to the volume control keys */ - private static final int DIAL_TONE_STREAM_TYPE = AudioManager.STREAM_DTMF; - /** Identifier for the "Add Call" intent extra. */ - private static final String ADD_CALL_MODE_KEY = "add_call_mode"; - /** - * Identifier for intent extra for sending an empty Flash message for CDMA networks. This message - * is used by the network to simulate a press/depress of the "hookswitch" of a landline phone. Aka - * "empty flash". - * - *

TODO: Using an intent extra to tell the phone to send this flash is a temporary measure. To - * be replaced with an Telephony/TelecomManager call in the future. TODO: Keep in sync with the - * string defined in OutgoingCallBroadcaster.java in Phone app until this is replaced with the - * Telephony/Telecom API. - */ - private static final String EXTRA_SEND_EMPTY_FLASH = "com.android.phone.extra.SEND_EMPTY_FLASH"; - - private static final String PREF_DIGITS_FILLED_BY_INTENT = "pref_digits_filled_by_intent"; - private final Object mToneGeneratorLock = new Object(); - /** Set of dialpad keys that are currently being pressed */ - private final HashSet mPressedDialpadKeys = new HashSet(12); - // Last number dialed, retrieved asynchronously from the call DB - // in onCreate. This number is displayed when the user hits the - // send key and cleared in onPause. - private final CallLogAsync mCallLog = new CallLogAsync(); - private OnDialpadQueryChangedListener mDialpadQueryListener; - private DialpadView mDialpadView; - private EditText mDigits; - private int mDialpadSlideInDuration; - /** Remembers if we need to clear digits field when the screen is completely gone. */ - private boolean mClearDigitsOnStop; - - private View mOverflowMenuButton; - private PopupMenu mOverflowPopupMenu; - private View mDelete; - private ToneGenerator mToneGenerator; - private View mSpacer; - private FloatingActionButtonController mFloatingActionButtonController; - private ListView mDialpadChooser; - private DialpadChooserAdapter mDialpadChooserAdapter; - /** Regular expression prohibiting manual phone call. Can be empty, which means "no rule". */ - private String mProhibitedPhoneNumberRegexp; - - private PseudoEmergencyAnimator mPseudoEmergencyAnimator; - private String mLastNumberDialed = EMPTY_NUMBER; - - // determines if we want to playback local DTMF tones. - private boolean mDTMFToneEnabled; - private String mCurrentCountryIso; - private CallStateReceiver mCallStateReceiver; - private boolean mWasEmptyBeforeTextChange; - /** - * This field is set to true while processing an incoming DIAL intent, in order to make sure that - * SpecialCharSequenceMgr actions can be triggered by user input but *not* by a tel: URI passed by - * some other app. It will be set to false when all digits are cleared. - */ - private boolean mDigitsFilledByIntent; - - private boolean mStartedFromNewIntent = false; - private boolean mFirstLaunch = false; - private boolean mAnimate = false; - - private DialerExecutor initPhoneNumberFormattingTextWatcherExecutor; - - /** - * Determines whether an add call operation is requested. - * - * @param intent The intent. - * @return {@literal true} if add call operation was requested. {@literal false} otherwise. - */ - public static boolean isAddCallMode(Intent intent) { - if (intent == null) { - return false; - } - final String action = intent.getAction(); - if (Intent.ACTION_DIAL.equals(action) || Intent.ACTION_VIEW.equals(action)) { - // see if we are "adding a call" from the InCallScreen; false by default. - return intent.getBooleanExtra(ADD_CALL_MODE_KEY, false); - } else { - return false; - } - } - - /** - * Format the provided string of digits into one that represents a properly formatted phone - * number. - * - * @param dialString String of characters to format - * @param normalizedNumber the E164 format number whose country code is used if the given - * phoneNumber doesn't have the country code. - * @param countryIso The country code representing the format to use if the provided normalized - * number is null or invalid. - * @return the provided string of digits as a formatted phone number, retaining any post-dial - * portion of the string. - */ - @VisibleForTesting - static String getFormattedDigits(String dialString, String normalizedNumber, String countryIso) { - String number = PhoneNumberUtils.extractNetworkPortion(dialString); - // Also retrieve the post dial portion of the provided data, so that the entire dial - // string can be reconstituted later. - final String postDial = PhoneNumberUtils.extractPostDialPortion(dialString); - - if (TextUtils.isEmpty(number)) { - return postDial; - } - - number = PhoneNumberUtils.formatNumber(number, normalizedNumber, countryIso); - - if (TextUtils.isEmpty(postDial)) { - return number; - } - - return number.concat(postDial); - } - - /** - * Returns true of the newDigit parameter can be added at the current selection point, otherwise - * returns false. Only prevents input of WAIT and PAUSE digits at an unsupported position. Fails - * early if start == -1 or start is larger than end. - */ - @VisibleForTesting - /* package */ static boolean canAddDigit(CharSequence digits, int start, int end, char newDigit) { - if (newDigit != WAIT && newDigit != PAUSE) { - throw new IllegalArgumentException( - "Should not be called for anything other than PAUSE & WAIT"); - } - - // False if no selection, or selection is reversed (end < start) - if (start == -1 || end < start) { - return false; - } - - // unsupported selection-out-of-bounds state - if (start > digits.length() || end > digits.length()) { - return false; - } - - // Special digit cannot be the first digit - if (start == 0) { - return false; - } - - if (newDigit == WAIT) { - // preceding char is ';' (WAIT) - if (digits.charAt(start - 1) == WAIT) { - return false; - } - - // next char is ';' (WAIT) - if ((digits.length() > end) && (digits.charAt(end) == WAIT)) { - return false; - } - } - - return true; - } - - private TelephonyManager getTelephonyManager() { - return (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); - } - - @Override - public Context getContext() { - return getActivity(); - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - mWasEmptyBeforeTextChange = TextUtils.isEmpty(s); - } - - @Override - public void onTextChanged(CharSequence input, int start, int before, int changeCount) { - if (mWasEmptyBeforeTextChange != TextUtils.isEmpty(input)) { - final Activity activity = getActivity(); - if (activity != null) { - activity.invalidateOptionsMenu(); - updateMenuOverflowButton(mWasEmptyBeforeTextChange); - } - } - - // DTMF Tones do not need to be played here any longer - - // the DTMF dialer handles that functionality now. - } - - @Override - public void afterTextChanged(Editable input) { - // When DTMF dialpad buttons are being pressed, we delay SpecialCharSequenceMgr sequence, - // since some of SpecialCharSequenceMgr's behavior is too abrupt for the "touch-down" - // behavior. - if (!mDigitsFilledByIntent - && SpecialCharSequenceMgr.handleChars(getActivity(), input.toString(), mDigits)) { - // A special sequence was entered, clear the digits - mDigits.getText().clear(); - } - - if (isDigitsEmpty()) { - mDigitsFilledByIntent = false; - mDigits.setCursorVisible(false); - } - - if (mDialpadQueryListener != null) { - mDialpadQueryListener.onDialpadQueryChanged(mDigits.getText().toString()); - } - - updateDeleteButtonEnabledState(); - } - - @Override - public void onCreate(Bundle state) { - Trace.beginSection(TAG + " onCreate"); - super.onCreate(state); - - mFirstLaunch = state == null; - - mCurrentCountryIso = GeoUtil.getCurrentCountryIso(getActivity()); - - mProhibitedPhoneNumberRegexp = - getResources().getString(R.string.config_prohibited_phone_number_regexp); - - if (state != null) { - mDigitsFilledByIntent = state.getBoolean(PREF_DIGITS_FILLED_BY_INTENT); - } - - mDialpadSlideInDuration = getResources().getInteger(R.integer.dialpad_slide_in_duration); - - if (mCallStateReceiver == null) { - IntentFilter callStateIntentFilter = - new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED); - mCallStateReceiver = new CallStateReceiver(); - getActivity().registerReceiver(mCallStateReceiver, callStateIntentFilter); - } - - initPhoneNumberFormattingTextWatcherExecutor = - DialerExecutors.createUiTaskBuilder( - getFragmentManager(), - "DialpadFragment.initPhoneNumberFormattingTextWatcher", - new InitPhoneNumberFormattingTextWatcherWorker()) - .onSuccess(watcher -> mDialpadView.getDigits().addTextChangedListener(watcher)) - .build(); - Trace.endSection(); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { - Trace.beginSection(TAG + " onCreateView"); - Trace.beginSection(TAG + " inflate view"); - final View fragmentView = inflater.inflate(R.layout.dialpad_fragment, container, false); - Trace.endSection(); - Trace.beginSection(TAG + " buildLayer"); - fragmentView.buildLayer(); - Trace.endSection(); - - Trace.beginSection(TAG + " setup views"); - - mDialpadView = (DialpadView) fragmentView.findViewById(R.id.dialpad_view); - mDialpadView.setCanDigitsBeEdited(true); - mDigits = mDialpadView.getDigits(); - mDigits.setKeyListener(UnicodeDialerKeyListener.INSTANCE); - mDigits.setOnClickListener(this); - mDigits.setOnKeyListener(this); - mDigits.setOnLongClickListener(this); - mDigits.addTextChangedListener(this); - mDigits.setElegantTextHeight(false); - - initPhoneNumberFormattingTextWatcherExecutor.executeSerial( - GeoUtil.getCurrentCountryIso(getActivity())); - - // Check for the presence of the keypad - View oneButton = fragmentView.findViewById(R.id.one); - if (oneButton != null) { - configureKeypadListeners(fragmentView); - } - - mDelete = mDialpadView.getDeleteButton(); - - if (mDelete != null) { - mDelete.setOnClickListener(this); - mDelete.setOnLongClickListener(this); - } - - mSpacer = fragmentView.findViewById(R.id.spacer); - mSpacer.setOnTouchListener( - new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - if (isDigitsEmpty()) { - if (getActivity() != null) { - return ((HostInterface) getActivity()).onDialpadSpacerTouchWithEmptyQuery(); - } - return true; - } - return false; - } - }); - - mDigits.setCursorVisible(false); - - // Set up the "dialpad chooser" UI; see showDialpadChooser(). - mDialpadChooser = (ListView) fragmentView.findViewById(R.id.dialpadChooser); - mDialpadChooser.setOnItemClickListener(this); - - FloatingActionButton floatingActionButton = - (FloatingActionButton) fragmentView.findViewById(R.id.dialpad_floating_action_button); - floatingActionButton.setOnClickListener(this); - mFloatingActionButtonController = - new FloatingActionButtonController(getActivity(), floatingActionButton); - Trace.endSection(); - Trace.endSection(); - return fragmentView; - } - - private boolean isLayoutReady() { - return mDigits != null; - } - - @VisibleForTesting - public EditText getDigitsWidget() { - return mDigits; - } - - /** @return true when {@link #mDigits} is actually filled by the Intent. */ - private boolean fillDigitsIfNecessary(Intent intent) { - // Only fills digits from an intent if it is a new intent. - // Otherwise falls back to the previously used number. - if (!mFirstLaunch && !mStartedFromNewIntent) { - return false; - } - - final String action = intent.getAction(); - if (Intent.ACTION_DIAL.equals(action) || Intent.ACTION_VIEW.equals(action)) { - Uri uri = intent.getData(); - if (uri != null) { - if (PhoneAccount.SCHEME_TEL.equals(uri.getScheme())) { - // Put the requested number into the input area - String data = uri.getSchemeSpecificPart(); - // Remember it is filled via Intent. - mDigitsFilledByIntent = true; - final String converted = - PhoneNumberUtils.convertKeypadLettersToDigits( - PhoneNumberUtils.replaceUnicodeDigits(data)); - setFormattedDigits(converted, null); - return true; - } else { - if (!PermissionsUtil.hasContactsReadPermissions(getActivity())) { - return false; - } - String type = intent.getType(); - if (People.CONTENT_ITEM_TYPE.equals(type) || Phones.CONTENT_ITEM_TYPE.equals(type)) { - // Query the phone number - Cursor c = - getActivity() - .getContentResolver() - .query( - intent.getData(), - new String[] {PhonesColumns.NUMBER, PhonesColumns.NUMBER_KEY}, - null, - null, - null); - if (c != null) { - try { - if (c.moveToFirst()) { - // Remember it is filled via Intent. - mDigitsFilledByIntent = true; - // Put the number into the input area - setFormattedDigits(c.getString(0), c.getString(1)); - return true; - } - } finally { - c.close(); - } - } - } - } - } - } - return false; - } - - /** - * Checks the given Intent and changes dialpad's UI state. For example, if the Intent requires the - * screen to enter "Add Call" mode, this method will show correct UI for the mode. - */ - private void configureScreenFromIntent(Activity parent) { - // If we were not invoked with a DIAL intent, - if (!(parent instanceof DialtactsActivity)) { - setStartedFromNewIntent(false); - return; - } - // See if we were invoked with a DIAL intent. If we were, fill in the appropriate - // digits in the dialer field. - Intent intent = parent.getIntent(); - - if (!isLayoutReady()) { - // This happens typically when parent's Activity#onNewIntent() is called while - // Fragment#onCreateView() isn't called yet, and thus we cannot configure Views at - // this point. onViewCreate() should call this method after preparing layouts, so - // just ignore this call now. - LogUtil.i( - "DialpadFragment.configureScreenFromIntent", - "Screen configuration is requested before onCreateView() is called. Ignored"); - return; - } - - boolean needToShowDialpadChooser = false; - - // Be sure *not* to show the dialpad chooser if this is an - // explicit "Add call" action, though. - final boolean isAddCallMode = isAddCallMode(intent); - if (!isAddCallMode) { - - // Don't show the chooser when called via onNewIntent() and phone number is present. - // i.e. User clicks a telephone link from gmail for example. - // In this case, we want to show the dialpad with the phone number. - final boolean digitsFilled = fillDigitsIfNecessary(intent); - if (!(mStartedFromNewIntent && digitsFilled)) { - - final String action = intent.getAction(); - if (Intent.ACTION_DIAL.equals(action) - || Intent.ACTION_VIEW.equals(action) - || Intent.ACTION_MAIN.equals(action)) { - // If there's already an active call, bring up an intermediate UI to - // make the user confirm what they really want to do. - if (isPhoneInUse()) { - needToShowDialpadChooser = true; - } - } - } - } - showDialpadChooser(needToShowDialpadChooser); - setStartedFromNewIntent(false); - } - - public void setStartedFromNewIntent(boolean value) { - mStartedFromNewIntent = value; - } - - public void clearCallRateInformation() { - setCallRateInformation(null, null); - } - - public void setCallRateInformation(String countryName, String displayRate) { - mDialpadView.setCallRateInformation(countryName, displayRate); - } - - /** Sets formatted digits to digits field. */ - private void setFormattedDigits(String data, String normalizedNumber) { - final String formatted = getFormattedDigits(data, normalizedNumber, mCurrentCountryIso); - if (!TextUtils.isEmpty(formatted)) { - Editable digits = mDigits.getText(); - digits.replace(0, digits.length(), formatted); - // for some reason this isn't getting called in the digits.replace call above.. - // but in any case, this will make sure the background drawable looks right - afterTextChanged(digits); - } - } - - private void configureKeypadListeners(View fragmentView) { - final int[] buttonIds = - new int[] { - R.id.one, - R.id.two, - R.id.three, - R.id.four, - R.id.five, - R.id.six, - R.id.seven, - R.id.eight, - R.id.nine, - R.id.star, - R.id.zero, - R.id.pound - }; - - DialpadKeyButton dialpadKey; - - for (int i = 0; i < buttonIds.length; i++) { - dialpadKey = (DialpadKeyButton) fragmentView.findViewById(buttonIds[i]); - dialpadKey.setOnPressedListener(this); - } - - // Long-pressing one button will initiate Voicemail. - final DialpadKeyButton one = (DialpadKeyButton) fragmentView.findViewById(R.id.one); - one.setOnLongClickListener(this); - - // Long-pressing zero button will enter '+' instead. - final DialpadKeyButton zero = (DialpadKeyButton) fragmentView.findViewById(R.id.zero); - zero.setOnLongClickListener(this); - } - - @Override - public void onStart() { - LogUtil.d("DialpadFragment.onStart", "first launch: %b", mFirstLaunch); - Trace.beginSection(TAG + " onStart"); - super.onStart(); - // if the mToneGenerator creation fails, just continue without it. It is - // a local audio signal, and is not as important as the dtmf tone itself. - final long start = System.currentTimeMillis(); - synchronized (mToneGeneratorLock) { - if (mToneGenerator == null) { - try { - mToneGenerator = new ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME); - } catch (RuntimeException e) { - LogUtil.e( - "DialpadFragment.onStart", - "Exception caught while creating local tone generator: " + e); - mToneGenerator = null; - } - } - } - final long total = System.currentTimeMillis() - start; - if (total > 50) { - LogUtil.i("DialpadFragment.onStart", "Time for ToneGenerator creation: " + total); - } - Trace.endSection(); - } - - @Override - public void onResume() { - LogUtil.d("DialpadFragment.onResume", ""); - Trace.beginSection(TAG + " onResume"); - super.onResume(); - - Resources res = getResources(); - int iconId = R.drawable.quantum_ic_call_vd_theme_24; - if (MotorolaUtils.isWifiCallingAvailable(getContext())) { - iconId = R.drawable.ic_wifi_calling; - } - mFloatingActionButtonController.changeIcon( - res.getDrawable(iconId, null), res.getString(R.string.description_dial_button)); - - final DialtactsActivity activity = (DialtactsActivity) getActivity(); - mDialpadQueryListener = activity; - - final StopWatch stopWatch = StopWatch.start("Dialpad.onResume"); - - // Query the last dialed number. Do it first because hitting - // the DB is 'slow'. This call is asynchronous. - queryLastOutgoingCall(); - - stopWatch.lap("qloc"); - - final ContentResolver contentResolver = activity.getContentResolver(); - - // retrieve the DTMF tone play back setting. - mDTMFToneEnabled = - Settings.System.getInt(contentResolver, Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1; - - stopWatch.lap("dtwd"); - - stopWatch.lap("hptc"); - - mPressedDialpadKeys.clear(); - - configureScreenFromIntent(getActivity()); - - stopWatch.lap("fdin"); - - if (!isPhoneInUse()) { - // A sanity-check: the "dialpad chooser" UI should not be visible if the phone is idle. - showDialpadChooser(false); - } - - stopWatch.lap("hnt"); - - updateDeleteButtonEnabledState(); - - stopWatch.lap("bes"); - - stopWatch.stopAndLog(TAG, 50); - - // Populate the overflow menu in onResume instead of onCreate, so that if the SMS activity - // is disabled while Dialer is paused, the "Send a text message" option can be correctly - // removed when resumed. - mOverflowMenuButton = mDialpadView.getOverflowMenuButton(); - mOverflowPopupMenu = buildOptionsMenu(mOverflowMenuButton); - mOverflowMenuButton.setOnTouchListener(mOverflowPopupMenu.getDragToOpenListener()); - mOverflowMenuButton.setOnClickListener(this); - mOverflowMenuButton.setVisibility(isDigitsEmpty() ? View.INVISIBLE : View.VISIBLE); - - if (mFirstLaunch) { - // The onHiddenChanged callback does not get called the first time the fragment is - // attached, so call it ourselves here. - onHiddenChanged(false); - } - - mFirstLaunch = false; - Trace.endSection(); - } - - @Override - public void onPause() { - super.onPause(); - - // Make sure we don't leave this activity with a tone still playing. - stopTone(); - mPressedDialpadKeys.clear(); - - // TODO: I wonder if we should not check if the AsyncTask that - // lookup the last dialed number has completed. - mLastNumberDialed = EMPTY_NUMBER; // Since we are going to query again, free stale number. - - SpecialCharSequenceMgr.cleanup(); - } - - @Override - public void onStop() { - super.onStop(); - - synchronized (mToneGeneratorLock) { - if (mToneGenerator != null) { - mToneGenerator.release(); - mToneGenerator = null; - } - } - - if (mClearDigitsOnStop) { - mClearDigitsOnStop = false; - clearDialpad(); - } - } - - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putBoolean(PREF_DIGITS_FILLED_BY_INTENT, mDigitsFilledByIntent); - } - - @Override - public void onDestroy() { - super.onDestroy(); - if (mPseudoEmergencyAnimator != null) { - mPseudoEmergencyAnimator.destroy(); - mPseudoEmergencyAnimator = null; - } - getActivity().unregisterReceiver(mCallStateReceiver); - } - - private void keyPressed(int keyCode) { - if (getView() == null || getView().getTranslationY() != 0) { - return; - } - switch (keyCode) { - case KeyEvent.KEYCODE_1: - playTone(ToneGenerator.TONE_DTMF_1, TONE_LENGTH_INFINITE); - break; - case KeyEvent.KEYCODE_2: - playTone(ToneGenerator.TONE_DTMF_2, TONE_LENGTH_INFINITE); - break; - case KeyEvent.KEYCODE_3: - playTone(ToneGenerator.TONE_DTMF_3, TONE_LENGTH_INFINITE); - break; - case KeyEvent.KEYCODE_4: - playTone(ToneGenerator.TONE_DTMF_4, TONE_LENGTH_INFINITE); - break; - case KeyEvent.KEYCODE_5: - playTone(ToneGenerator.TONE_DTMF_5, TONE_LENGTH_INFINITE); - break; - case KeyEvent.KEYCODE_6: - playTone(ToneGenerator.TONE_DTMF_6, TONE_LENGTH_INFINITE); - break; - case KeyEvent.KEYCODE_7: - playTone(ToneGenerator.TONE_DTMF_7, TONE_LENGTH_INFINITE); - break; - case KeyEvent.KEYCODE_8: - playTone(ToneGenerator.TONE_DTMF_8, TONE_LENGTH_INFINITE); - break; - case KeyEvent.KEYCODE_9: - playTone(ToneGenerator.TONE_DTMF_9, TONE_LENGTH_INFINITE); - break; - case KeyEvent.KEYCODE_0: - playTone(ToneGenerator.TONE_DTMF_0, TONE_LENGTH_INFINITE); - break; - case KeyEvent.KEYCODE_POUND: - playTone(ToneGenerator.TONE_DTMF_P, TONE_LENGTH_INFINITE); - break; - case KeyEvent.KEYCODE_STAR: - playTone(ToneGenerator.TONE_DTMF_S, TONE_LENGTH_INFINITE); - break; - default: - break; - } - - getView().performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); - KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode); - mDigits.onKeyDown(keyCode, event); - - // If the cursor is at the end of the text we hide it. - final int length = mDigits.length(); - if (length == mDigits.getSelectionStart() && length == mDigits.getSelectionEnd()) { - mDigits.setCursorVisible(false); - } - } - - @Override - public boolean onKey(View view, int keyCode, KeyEvent event) { - if (view.getId() == R.id.digits) { - if (keyCode == KeyEvent.KEYCODE_ENTER) { - handleDialButtonPressed(); - return true; - } - } - return false; - } - - /** - * When a key is pressed, we start playing DTMF tone, do vibration, and enter the digit - * immediately. When a key is released, we stop the tone. Note that the "key press" event will be - * delivered by the system with certain amount of delay, it won't be synced with user's actual - * "touch-down" behavior. - */ - @Override - public void onPressed(View view, boolean pressed) { - if (DEBUG) { - LogUtil.d("DialpadFragment.onPressed", "view: " + view + ", pressed: " + pressed); - } - if (pressed) { - int resId = view.getId(); - if (resId == R.id.one) { - keyPressed(KeyEvent.KEYCODE_1); - } else if (resId == R.id.two) { - keyPressed(KeyEvent.KEYCODE_2); - } else if (resId == R.id.three) { - keyPressed(KeyEvent.KEYCODE_3); - } else if (resId == R.id.four) { - keyPressed(KeyEvent.KEYCODE_4); - } else if (resId == R.id.five) { - keyPressed(KeyEvent.KEYCODE_5); - } else if (resId == R.id.six) { - keyPressed(KeyEvent.KEYCODE_6); - } else if (resId == R.id.seven) { - keyPressed(KeyEvent.KEYCODE_7); - } else if (resId == R.id.eight) { - keyPressed(KeyEvent.KEYCODE_8); - } else if (resId == R.id.nine) { - keyPressed(KeyEvent.KEYCODE_9); - } else if (resId == R.id.zero) { - keyPressed(KeyEvent.KEYCODE_0); - } else if (resId == R.id.pound) { - keyPressed(KeyEvent.KEYCODE_POUND); - } else if (resId == R.id.star) { - keyPressed(KeyEvent.KEYCODE_STAR); - } else { - LogUtil.e( - "DialpadFragment.onPressed", "Unexpected onTouch(ACTION_DOWN) event from: " + view); - } - mPressedDialpadKeys.add(view); - } else { - mPressedDialpadKeys.remove(view); - if (mPressedDialpadKeys.isEmpty()) { - stopTone(); - } - } - } - - /** - * Called by the containing Activity to tell this Fragment to build an overflow options menu for - * display by the container when appropriate. - * - * @param invoker the View that invoked the options menu, to act as an anchor location. - */ - private PopupMenu buildOptionsMenu(View invoker) { - final PopupMenu popupMenu = - new PopupMenu(getActivity(), invoker) { - @Override - public void show() { - final Menu menu = getMenu(); - - boolean enable = !isDigitsEmpty(); - for (int i = 0; i < menu.size(); i++) { - MenuItem item = menu.getItem(i); - item.setEnabled(enable); - if (item.getItemId() == R.id.menu_call_with_note) { - item.setVisible(CallUtil.isCallWithSubjectSupported(getContext())); - } - } - super.show(); - } - }; - popupMenu.inflate(R.menu.dialpad_options); - popupMenu.setOnMenuItemClickListener(this); - return popupMenu; - } - - @Override - public void onClick(View view) { - int resId = view.getId(); - if (resId == R.id.dialpad_floating_action_button) { - view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); - handleDialButtonPressed(); - } else if (resId == R.id.deleteButton) { - keyPressed(KeyEvent.KEYCODE_DEL); - } else if (resId == R.id.digits) { - if (!isDigitsEmpty()) { - mDigits.setCursorVisible(true); - } - } else if (resId == R.id.dialpad_overflow) { - mOverflowPopupMenu.show(); - } else { - LogUtil.w("DialpadFragment.onClick", "Unexpected event from: " + view); - return; - } - } - - @Override - public boolean onLongClick(View view) { - final Editable digits = mDigits.getText(); - final int id = view.getId(); - if (id == R.id.deleteButton) { - digits.clear(); - return true; - } else if (id == R.id.one) { - if (isDigitsEmpty() || TextUtils.equals(mDigits.getText(), "1")) { - // We'll try to initiate voicemail and thus we want to remove irrelevant string. - removePreviousDigitIfPossible('1'); - - List subscriptionAccountHandles = - PhoneAccountUtils.getSubscriptionPhoneAccounts(getActivity()); - boolean hasUserSelectedDefault = - subscriptionAccountHandles.contains( - TelecomUtil.getDefaultOutgoingPhoneAccount( - getActivity(), PhoneAccount.SCHEME_VOICEMAIL)); - boolean needsAccountDisambiguation = - subscriptionAccountHandles.size() > 1 && !hasUserSelectedDefault; - - if (needsAccountDisambiguation || isVoicemailAvailable()) { - // On a multi-SIM phone, if the user has not selected a default - // subscription, initiate a call to voicemail so they can select an account - // from the "Call with" dialog. - callVoicemail(); - } else if (getActivity() != null) { - // Voicemail is unavailable maybe because Airplane mode is turned on. - // Check the current status and show the most appropriate error message. - final boolean isAirplaneModeOn = - Settings.System.getInt( - getActivity().getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) - != 0; - if (isAirplaneModeOn) { - DialogFragment dialogFragment = - ErrorDialogFragment.newInstance(R.string.dialog_voicemail_airplane_mode_message); - dialogFragment.show(getFragmentManager(), "voicemail_request_during_airplane_mode"); - } else { - DialogFragment dialogFragment = - ErrorDialogFragment.newInstance(R.string.dialog_voicemail_not_ready_message); - dialogFragment.show(getFragmentManager(), "voicemail_not_ready"); - } - } - return true; - } - return false; - } else if (id == R.id.zero) { - if (mPressedDialpadKeys.contains(view)) { - // If the zero key is currently pressed, then the long press occurred by touch - // (and not via other means like certain accessibility input methods). - // Remove the '0' that was input when the key was first pressed. - removePreviousDigitIfPossible('0'); - } - keyPressed(KeyEvent.KEYCODE_PLUS); - stopTone(); - mPressedDialpadKeys.remove(view); - return true; - } else if (id == R.id.digits) { - mDigits.setCursorVisible(true); - return false; - } - return false; - } - - /** - * Remove the digit just before the current position of the cursor, iff the following conditions - * are true: 1) The cursor is not positioned at index 0. 2) The digit before the current cursor - * position matches the current digit. - * - * @param digit to remove from the digits view. - */ - private void removePreviousDigitIfPossible(char digit) { - final int currentPosition = mDigits.getSelectionStart(); - if (currentPosition > 0 && digit == mDigits.getText().charAt(currentPosition - 1)) { - mDigits.setSelection(currentPosition); - mDigits.getText().delete(currentPosition - 1, currentPosition); - } - } - - public void callVoicemail() { - DialerUtils.startActivityWithErrorToast( - getActivity(), - new CallIntentBuilder(CallUtil.getVoicemailUri(), CallInitiationType.Type.DIALPAD).build()); - hideAndClearDialpad(false); - } - - private void hideAndClearDialpad(boolean animate) { - ((DialtactsActivity) getActivity()).hideDialpadFragment(animate, true); - } - - /** - * In most cases, when the dial button is pressed, there is a number in digits area. Pack it in - * the intent, start the outgoing call broadcast as a separate task and finish this activity. - * - *

When there is no digit and the phone is CDMA and off hook, we're sending a blank flash for - * CDMA. CDMA networks use Flash messages when special processing needs to be done, mainly for - * 3-way or call waiting scenarios. Presumably, here we're in a special 3-way scenario where the - * network needs a blank flash before being able to add the new participant. (This is not the case - * with all 3-way calls, just certain CDMA infrastructures.) - * - *

Otherwise, there is no digit, display the last dialed number. Don't finish since the user - * may want to edit it. The user needs to press the dial button again, to dial it (general case - * described above). - */ - private void handleDialButtonPressed() { - if (isDigitsEmpty()) { // No number entered. - // No real call made, so treat it as a click - PerformanceReport.recordClick(UiAction.Type.PRESS_CALL_BUTTON_WITHOUT_CALLING); - handleDialButtonClickWithEmptyDigits(); - } else { - final String number = mDigits.getText().toString(); - - // "persist.radio.otaspdial" is a temporary hack needed for one carrier's automated - // test equipment. - // TODO: clean it up. - if (number != null - && !TextUtils.isEmpty(mProhibitedPhoneNumberRegexp) - && number.matches(mProhibitedPhoneNumberRegexp)) { - PerformanceReport.recordClick(UiAction.Type.PRESS_CALL_BUTTON_WITHOUT_CALLING); - LogUtil.i( - "DialpadFragment.handleDialButtonPressed", - "The phone number is prohibited explicitly by a rule."); - if (getActivity() != null) { - DialogFragment dialogFragment = - ErrorDialogFragment.newInstance(R.string.dialog_phone_call_prohibited_message); - dialogFragment.show(getFragmentManager(), "phone_prohibited_dialog"); - } - - // Clear the digits just in case. - clearDialpad(); - } else { - final Intent intent = - new CallIntentBuilder(number, CallInitiationType.Type.DIALPAD).build(); - DialerUtils.startActivityWithErrorToast(getActivity(), intent); - hideAndClearDialpad(false); - } - } - } - - public void clearDialpad() { - if (mDigits != null) { - mDigits.getText().clear(); - } - } - - private void handleDialButtonClickWithEmptyDigits() { - if (phoneIsCdma() && isPhoneInUse()) { - // TODO: Move this logic into services/Telephony - // - // This is really CDMA specific. On GSM is it possible - // to be off hook and wanted to add a 3rd party using - // the redial feature. - startActivity(newFlashIntent()); - } else { - if (!TextUtils.isEmpty(mLastNumberDialed)) { - // Dialpad will be filled with last called number, - // but we don't want to record it as user action - PerformanceReport.setIgnoreActionOnce(UiAction.Type.TEXT_CHANGE_WITH_INPUT); - - // Recall the last number dialed. - mDigits.setText(mLastNumberDialed); - - // ...and move the cursor to the end of the digits string, - // so you'll be able to delete digits using the Delete - // button (just as if you had typed the number manually.) - // - // Note we use mDigits.getText().length() here, not - // mLastNumberDialed.length(), since the EditText widget now - // contains a *formatted* version of mLastNumberDialed (due to - // mTextWatcher) and its length may have changed. - mDigits.setSelection(mDigits.getText().length()); - } else { - // There's no "last number dialed" or the - // background query is still running. There's - // nothing useful for the Dial button to do in - // this case. Note: with a soft dial button, this - // can never happens since the dial button is - // disabled under these conditons. - playTone(ToneGenerator.TONE_PROP_NACK); - } - } - } - - /** Plays the specified tone for TONE_LENGTH_MS milliseconds. */ - private void playTone(int tone) { - playTone(tone, TONE_LENGTH_MS); - } - - /** - * Play the specified tone for the specified milliseconds - * - *

The tone is played locally, using the audio stream for phone calls. Tones are played only if - * the "Audible touch tones" user preference is checked, and are NOT played if the device is in - * silent mode. - * - *

The tone length can be -1, meaning "keep playing the tone." If the caller does so, it should - * call stopTone() afterward. - * - * @param tone a tone code from {@link ToneGenerator} - * @param durationMs tone length. - */ - private void playTone(int tone, int durationMs) { - // if local tone playback is disabled, just return. - if (!mDTMFToneEnabled) { - return; - } - - // Also do nothing if the phone is in silent mode. - // We need to re-check the ringer mode for *every* playTone() - // call, rather than keeping a local flag that's updated in - // onResume(), since it's possible to toggle silent mode without - // leaving the current activity (via the ENDCALL-longpress menu.) - AudioManager audioManager = - (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); - int ringerMode = audioManager.getRingerMode(); - if ((ringerMode == AudioManager.RINGER_MODE_SILENT) - || (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) { - return; - } - - synchronized (mToneGeneratorLock) { - if (mToneGenerator == null) { - LogUtil.w("DialpadFragment.playTone", "mToneGenerator == null, tone: " + tone); - return; - } - - // Start the new tone (will stop any playing tone) - mToneGenerator.startTone(tone, durationMs); - } - } - - /** Stop the tone if it is played. */ - private void stopTone() { - // if local tone playback is disabled, just return. - if (!mDTMFToneEnabled) { - return; - } - synchronized (mToneGeneratorLock) { - if (mToneGenerator == null) { - LogUtil.w("DialpadFragment.stopTone", "mToneGenerator == null"); - return; - } - mToneGenerator.stopTone(); - } - } - - /** - * Brings up the "dialpad chooser" UI in place of the usual Dialer elements (the textfield/button - * and the dialpad underneath). - * - *

We show this UI if the user brings up the Dialer while a call is already in progress, since - * there's a good chance we got here accidentally (and the user really wanted the in-call dialpad - * instead). So in this situation we display an intermediate UI that lets the user explicitly - * choose between the in-call dialpad ("Use touch tone keypad") and the regular Dialer ("Add - * call"). (Or, the option "Return to call in progress" just goes back to the in-call UI with no - * dialpad at all.) - * - * @param enabled If true, show the "dialpad chooser" instead of the regular Dialer UI - */ - private void showDialpadChooser(boolean enabled) { - if (getActivity() == null) { - return; - } - // Check if onCreateView() is already called by checking one of View objects. - if (!isLayoutReady()) { - return; - } - - if (enabled) { - LogUtil.i("DialpadFragment.showDialpadChooser", "Showing dialpad chooser!"); - if (mDialpadView != null) { - mDialpadView.setVisibility(View.GONE); - } - - if (mOverflowPopupMenu != null) { - mOverflowPopupMenu.dismiss(); - } - - mFloatingActionButtonController.setVisible(false); - mDialpadChooser.setVisibility(View.VISIBLE); - - // Instantiate the DialpadChooserAdapter and hook it up to the - // ListView. We do this only once. - if (mDialpadChooserAdapter == null) { - mDialpadChooserAdapter = new DialpadChooserAdapter(getActivity()); - } - mDialpadChooser.setAdapter(mDialpadChooserAdapter); - } else { - LogUtil.i("DialpadFragment.showDialpadChooser", "Displaying normal Dialer UI."); - if (mDialpadView != null) { - mDialpadView.setVisibility(View.VISIBLE); - } else { - mDigits.setVisibility(View.VISIBLE); - } - - // mFloatingActionButtonController must also be 'scaled in', in order to be visible after - // 'scaleOut()' hidden method. - if (!mFloatingActionButtonController.isVisible()) { - // Just call 'scaleIn()' method if the mFloatingActionButtonController was not already - // previously visible. - mFloatingActionButtonController.scaleIn(0); - } - mDialpadChooser.setVisibility(View.GONE); - } - } - - /** @return true if we're currently showing the "dialpad chooser" UI. */ - private boolean isDialpadChooserVisible() { - return mDialpadChooser.getVisibility() == View.VISIBLE; - } - - /** Handle clicks from the dialpad chooser. */ - @Override - public void onItemClick(AdapterView parent, View v, int position, long id) { - DialpadChooserAdapter.ChoiceItem item = - (DialpadChooserAdapter.ChoiceItem) parent.getItemAtPosition(position); - int itemId = item.id; - if (itemId == DialpadChooserAdapter.DIALPAD_CHOICE_USE_DTMF_DIALPAD) { - // Fire off an intent to go back to the in-call UI - // with the dialpad visible. - returnToInCallScreen(true); - } else if (itemId == DialpadChooserAdapter.DIALPAD_CHOICE_RETURN_TO_CALL) { - // Fire off an intent to go back to the in-call UI - // (with the dialpad hidden). - returnToInCallScreen(false); - } else if (itemId == DialpadChooserAdapter.DIALPAD_CHOICE_ADD_NEW_CALL) { - // Ok, guess the user really did want to be here (in the - // regular Dialer) after all. Bring back the normal Dialer UI. - showDialpadChooser(false); - } else { - LogUtil.w("DialpadFragment.onItemClick", "Unexpected itemId: " + itemId); - } - } - - /** - * Returns to the in-call UI (where there's presumably a call in progress) in response to the user - * selecting "use touch tone keypad" or "return to call" from the dialpad chooser. - */ - private void returnToInCallScreen(boolean showDialpad) { - TelecomUtil.showInCallScreen(getActivity(), showDialpad); - - // Finally, finish() ourselves so that we don't stay on the - // activity stack. - // Note that we do this whether or not the showCallScreenWithDialpad() - // call above had any effect or not! (That call is a no-op if the - // phone is idle, which can happen if the current call ends while - // the dialpad chooser is up. In this case we can't show the - // InCallScreen, and there's no point staying here in the Dialer, - // so we just take the user back where he came from...) - getActivity().finish(); - } - - /** - * @return true if the phone is "in use", meaning that at least one line is active (ie. off hook - * or ringing or dialing, or on hold). - */ - private boolean isPhoneInUse() { - final Context context = getActivity(); - if (context != null) { - return TelecomUtil.isInCall(context); - } - return false; - } - - /** @return true if the phone is a CDMA phone type */ - private boolean phoneIsCdma() { - return getTelephonyManager().getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA; - } - - @Override - public boolean onMenuItemClick(MenuItem item) { - int resId = item.getItemId(); - if (resId == R.id.menu_2s_pause) { - updateDialString(PAUSE); - return true; - } else if (resId == R.id.menu_add_wait) { - updateDialString(WAIT); - return true; - } else if (resId == R.id.menu_call_with_note) { - CallSubjectDialog.start(getActivity(), mDigits.getText().toString()); - hideAndClearDialpad(false); - return true; - } else { - return false; - } - } - - /** - * Updates the dial string (mDigits) after inserting a Pause character (,) or Wait character (;). - */ - private void updateDialString(char newDigit) { - if (newDigit != WAIT && newDigit != PAUSE) { - throw new IllegalArgumentException("Not expected for anything other than PAUSE & WAIT"); - } - - int selectionStart; - int selectionEnd; - - // SpannableStringBuilder editable_text = new SpannableStringBuilder(mDigits.getText()); - int anchor = mDigits.getSelectionStart(); - int point = mDigits.getSelectionEnd(); - - selectionStart = Math.min(anchor, point); - selectionEnd = Math.max(anchor, point); - - if (selectionStart == -1) { - selectionStart = selectionEnd = mDigits.length(); - } - - Editable digits = mDigits.getText(); - - if (canAddDigit(digits, selectionStart, selectionEnd, newDigit)) { - digits.replace(selectionStart, selectionEnd, Character.toString(newDigit)); - - if (selectionStart != selectionEnd) { - // Unselect: back to a regular cursor, just pass the character inserted. - mDigits.setSelection(selectionStart + 1); - } - } - } - - /** Update the enabledness of the "Dial" and "Backspace" buttons if applicable. */ - private void updateDeleteButtonEnabledState() { - if (getActivity() == null) { - return; - } - final boolean digitsNotEmpty = !isDigitsEmpty(); - mDelete.setEnabled(digitsNotEmpty); - } - - /** - * Handle transitions for the menu button depending on the state of the digits edit text. - * Transition out when going from digits to no digits and transition in when the first digit is - * pressed. - * - * @param transitionIn True if transitioning in, False if transitioning out - */ - private void updateMenuOverflowButton(boolean transitionIn) { - mOverflowMenuButton = mDialpadView.getOverflowMenuButton(); - if (transitionIn) { - AnimUtils.fadeIn(mOverflowMenuButton, AnimUtils.DEFAULT_DURATION); - } else { - AnimUtils.fadeOut(mOverflowMenuButton, AnimUtils.DEFAULT_DURATION); - } - } - - /** - * Check if voicemail is enabled/accessible. - * - * @return true if voicemail is enabled and accessible. Note that this can be false "temporarily" - * after the app boot. - */ - private boolean isVoicemailAvailable() { - try { - PhoneAccountHandle defaultUserSelectedAccount = - TelecomUtil.getDefaultOutgoingPhoneAccount(getActivity(), PhoneAccount.SCHEME_VOICEMAIL); - if (defaultUserSelectedAccount == null) { - // In a single-SIM phone, there is no default outgoing phone account selected by - // the user, so just call TelephonyManager#getVoicemailNumber directly. - return !TextUtils.isEmpty(getTelephonyManager().getVoiceMailNumber()); - } else { - return !TextUtils.isEmpty( - TelecomUtil.getVoicemailNumber(getActivity(), defaultUserSelectedAccount)); - } - } catch (SecurityException se) { - // Possibly no READ_PHONE_STATE privilege. - LogUtil.w( - "DialpadFragment.isVoicemailAvailable", - "SecurityException is thrown. Maybe privilege isn't sufficient."); - } - return false; - } - - /** @return true if the widget with the phone number digits is empty. */ - private boolean isDigitsEmpty() { - return mDigits.length() == 0; - } - - /** - * Starts the asyn query to get the last dialed/outgoing number. When the background query - * finishes, mLastNumberDialed is set to the last dialed number or an empty string if none exists - * yet. - */ - private void queryLastOutgoingCall() { - mLastNumberDialed = EMPTY_NUMBER; - if (ContextCompat.checkSelfPermission(getActivity(), permission.READ_CALL_LOG) - != PackageManager.PERMISSION_GRANTED) { - return; - } - CallLogAsync.GetLastOutgoingCallArgs lastCallArgs = - new CallLogAsync.GetLastOutgoingCallArgs( - getActivity(), - new CallLogAsync.OnLastOutgoingCallComplete() { - @Override - public void lastOutgoingCall(String number) { - // TODO: Filter out emergency numbers if - // the carrier does not want redial for - // these. - // If the fragment has already been detached since the last time - // we called queryLastOutgoingCall in onResume there is no point - // doing anything here. - if (getActivity() == null) { - return; - } - mLastNumberDialed = number; - updateDeleteButtonEnabledState(); - } - }); - mCallLog.getLastOutgoingCall(lastCallArgs); - } - - private Intent newFlashIntent() { - Intent intent = new CallIntentBuilder(EMPTY_NUMBER, CallInitiationType.Type.DIALPAD).build(); - intent.putExtra(EXTRA_SEND_EMPTY_FLASH, true); - return intent; - } - - @Override - public void onHiddenChanged(boolean hidden) { - super.onHiddenChanged(hidden); - final DialtactsActivity activity = (DialtactsActivity) getActivity(); - if (activity == null || getView() == null) { - return; - } - final DialpadView dialpadView = (DialpadView) getView().findViewById(R.id.dialpad_view); - if (!hidden && !isDialpadChooserVisible()) { - if (mAnimate) { - dialpadView.animateShow(); - } - mFloatingActionButtonController.setVisible(false); - mFloatingActionButtonController.scaleIn(mAnimate ? mDialpadSlideInDuration : 0); - activity.onDialpadShown(); - mDigits.requestFocus(); - } - if (hidden) { - if (mAnimate) { - mFloatingActionButtonController.scaleOut(); - } else { - mFloatingActionButtonController.setVisible(false); - } - } - } - - public boolean getAnimate() { - return mAnimate; - } - - public void setAnimate(boolean value) { - mAnimate = value; - } - - public void setYFraction(float yFraction) { - ((DialpadSlidingRelativeLayout) getView()).setYFraction(yFraction); - } - - public int getDialpadHeight() { - if (mDialpadView == null) { - return 0; - } - return mDialpadView.getHeight(); - } - - public void process_quote_emergency_unquote(String query) { - if (PseudoEmergencyAnimator.PSEUDO_EMERGENCY_NUMBER.equals(query)) { - if (mPseudoEmergencyAnimator == null) { - mPseudoEmergencyAnimator = - new PseudoEmergencyAnimator( - new PseudoEmergencyAnimator.ViewProvider() { - @Override - public View getView() { - return DialpadFragment.this.getView(); - } - }); - } - mPseudoEmergencyAnimator.start(); - } else { - if (mPseudoEmergencyAnimator != null) { - mPseudoEmergencyAnimator.end(); - } - } - } - - public interface OnDialpadQueryChangedListener { - - void onDialpadQueryChanged(String query); - } - - public interface HostInterface { - - /** - * Notifies the parent activity that the space above the dialpad has been tapped with no query - * in the dialpad present. In most situations this will cause the dialpad to be dismissed, - * unless there happens to be content showing. - */ - boolean onDialpadSpacerTouchWithEmptyQuery(); - } - - /** - * LinearLayout with getter and setter methods for the translationY property using floats, for - * animation purposes. - */ - public static class DialpadSlidingRelativeLayout extends RelativeLayout { - - public DialpadSlidingRelativeLayout(Context context) { - super(context); - } - - public DialpadSlidingRelativeLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public DialpadSlidingRelativeLayout(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - @UsedByReflection(value = "dialpad_fragment.xml") - public float getYFraction() { - final int height = getHeight(); - if (height == 0) { - return 0; - } - return getTranslationY() / height; - } - - @UsedByReflection(value = "dialpad_fragment.xml") - public void setYFraction(float yFraction) { - setTranslationY(yFraction * getHeight()); - } - } - - public static class ErrorDialogFragment extends DialogFragment { - - private static final String ARG_TITLE_RES_ID = "argTitleResId"; - private static final String ARG_MESSAGE_RES_ID = "argMessageResId"; - private int mTitleResId; - private int mMessageResId; - - public static ErrorDialogFragment newInstance(int messageResId) { - return newInstance(0, messageResId); - } - - public static ErrorDialogFragment newInstance(int titleResId, int messageResId) { - final ErrorDialogFragment fragment = new ErrorDialogFragment(); - final Bundle args = new Bundle(); - args.putInt(ARG_TITLE_RES_ID, titleResId); - args.putInt(ARG_MESSAGE_RES_ID, messageResId); - fragment.setArguments(args); - return fragment; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mTitleResId = getArguments().getInt(ARG_TITLE_RES_ID); - mMessageResId = getArguments().getInt(ARG_MESSAGE_RES_ID); - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - if (mTitleResId != 0) { - builder.setTitle(mTitleResId); - } - if (mMessageResId != 0) { - builder.setMessage(mMessageResId); - } - builder.setPositiveButton( - android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dismiss(); - } - }); - return builder.create(); - } - } - - /** - * Simple list adapter, binding to an icon + text label for each item in the "dialpad chooser" - * list. - */ - private static class DialpadChooserAdapter extends BaseAdapter { - - // IDs for the possible "choices": - static final int DIALPAD_CHOICE_USE_DTMF_DIALPAD = 101; - static final int DIALPAD_CHOICE_RETURN_TO_CALL = 102; - static final int DIALPAD_CHOICE_ADD_NEW_CALL = 103; - private static final int NUM_ITEMS = 3; - private LayoutInflater mInflater; - private ChoiceItem[] mChoiceItems = new ChoiceItem[NUM_ITEMS]; - - public DialpadChooserAdapter(Context context) { - // Cache the LayoutInflate to avoid asking for a new one each time. - mInflater = LayoutInflater.from(context); - - // Initialize the possible choices. - // TODO: could this be specified entirely in XML? - - // - "Use touch tone keypad" - mChoiceItems[0] = - new ChoiceItem( - context.getString(R.string.dialer_useDtmfDialpad), - BitmapFactory.decodeResource( - context.getResources(), R.drawable.ic_dialer_fork_tt_keypad), - DIALPAD_CHOICE_USE_DTMF_DIALPAD); - - // - "Return to call in progress" - mChoiceItems[1] = - new ChoiceItem( - context.getString(R.string.dialer_returnToInCallScreen), - BitmapFactory.decodeResource( - context.getResources(), R.drawable.ic_dialer_fork_current_call), - DIALPAD_CHOICE_RETURN_TO_CALL); - - // - "Add call" - mChoiceItems[2] = - new ChoiceItem( - context.getString(R.string.dialer_addAnotherCall), - BitmapFactory.decodeResource( - context.getResources(), R.drawable.ic_dialer_fork_add_call), - DIALPAD_CHOICE_ADD_NEW_CALL); - } - - @Override - public int getCount() { - return NUM_ITEMS; - } - - /** Return the ChoiceItem for a given position. */ - @Override - public Object getItem(int position) { - return mChoiceItems[position]; - } - - /** Return a unique ID for each possible choice. */ - @Override - public long getItemId(int position) { - return position; - } - - /** Make a view for each row. */ - @Override - public View getView(int position, View convertView, ViewGroup parent) { - // When convertView is non-null, we can reuse it (there's no need - // to reinflate it.) - if (convertView == null) { - convertView = mInflater.inflate(R.layout.dialpad_chooser_list_item, null); - } - - TextView text = (TextView) convertView.findViewById(R.id.text); - text.setText(mChoiceItems[position].text); - - ImageView icon = (ImageView) convertView.findViewById(R.id.icon); - icon.setImageBitmap(mChoiceItems[position].icon); - - return convertView; - } - - // Simple struct for a single "choice" item. - static class ChoiceItem { - - String text; - Bitmap icon; - int id; - - public ChoiceItem(String s, Bitmap b, int i) { - text = s; - icon = b; - id = i; - } - } - } - - private class CallStateReceiver extends BroadcastReceiver { - - /** - * Receive call state changes so that we can take down the "dialpad chooser" if the phone - * becomes idle while the chooser UI is visible. - */ - @Override - public void onReceive(Context context, Intent intent) { - String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); - if ((TextUtils.equals(state, TelephonyManager.EXTRA_STATE_IDLE) - || TextUtils.equals(state, TelephonyManager.EXTRA_STATE_OFFHOOK)) - && isDialpadChooserVisible()) { - // Note there's a race condition in the UI here: the - // dialpad chooser could conceivably disappear (on its - // own) at the exact moment the user was trying to select - // one of the choices, which would be confusing. (But at - // least that's better than leaving the dialpad chooser - // onscreen, but useless...) - showDialpadChooser(false); - } - } - } - - /** - * Input: the ISO 3166-1 two letters country code of the country the user is in - * - *

Output: PhoneNumberFormattingTextWatcher. Note: It is unusual to return a non-data value - * from a worker, but it is a limitation in libphonenumber API that the watcher cannot be - * initialized on the main thread. - */ - private static class InitPhoneNumberFormattingTextWatcherWorker - implements Worker { - - @Nullable - @Override - public PhoneNumberFormattingTextWatcher doInBackground(@Nullable String countryCode) { - return new PhoneNumberFormattingTextWatcher(countryCode); - } - } -} diff --git a/java/com/android/dialer/app/dialpad/PseudoEmergencyAnimator.java b/java/com/android/dialer/app/dialpad/PseudoEmergencyAnimator.java deleted file mode 100644 index be2964dfe..000000000 --- a/java/com/android/dialer/app/dialpad/PseudoEmergencyAnimator.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.app.dialpad; - -import android.animation.Animator; -import android.animation.Animator.AnimatorListener; -import android.animation.ArgbEvaluator; -import android.animation.ValueAnimator; -import android.animation.ValueAnimator.AnimatorUpdateListener; -import android.content.Context; -import android.graphics.Color; -import android.graphics.ColorFilter; -import android.graphics.LightingColorFilter; -import android.os.Handler; -import android.os.Vibrator; -import android.view.View; -import com.android.dialer.app.R; - -/** Animates the dial button on "emergency" phone numbers. */ -public class PseudoEmergencyAnimator { - - public static final String PSEUDO_EMERGENCY_NUMBER = "01189998819991197253"; - private static final int VIBRATE_LENGTH_MILLIS = 200; - private static final int ITERATION_LENGTH_MILLIS = 1000; - private static final int ANIMATION_ITERATION_COUNT = 6; - private ViewProvider mViewProvider; - private ValueAnimator mPseudoEmergencyColorAnimator; - - PseudoEmergencyAnimator(ViewProvider viewProvider) { - mViewProvider = viewProvider; - } - - public void destroy() { - end(); - mViewProvider = null; - } - - public void start() { - if (mPseudoEmergencyColorAnimator == null) { - Integer colorFrom = Color.BLUE; - Integer colorTo = Color.RED; - mPseudoEmergencyColorAnimator = - ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); - - mPseudoEmergencyColorAnimator.addUpdateListener( - new AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animator) { - try { - int color = (int) animator.getAnimatedValue(); - ColorFilter colorFilter = new LightingColorFilter(Color.BLACK, color); - - View floatingActionButtonContainer = - getView().findViewById(R.id.floating_action_button); - if (floatingActionButtonContainer != null) { - floatingActionButtonContainer.getBackground().setColorFilter(colorFilter); - } - } catch (Exception e) { - animator.cancel(); - } - } - }); - - mPseudoEmergencyColorAnimator.addListener( - new AnimatorListener() { - @Override - public void onAnimationCancel(Animator animation) {} - - @Override - public void onAnimationRepeat(Animator animation) { - try { - vibrate(VIBRATE_LENGTH_MILLIS); - } catch (Exception e) { - animation.cancel(); - } - } - - @Override - public void onAnimationStart(Animator animation) {} - - @Override - public void onAnimationEnd(Animator animation) { - try { - View floatingActionButtonContainer = - getView().findViewById(R.id.floating_action_button); - if (floatingActionButtonContainer != null) { - floatingActionButtonContainer.getBackground().clearColorFilter(); - } - - new Handler() - .postDelayed( - new Runnable() { - @Override - public void run() { - try { - vibrate(VIBRATE_LENGTH_MILLIS); - } catch (Exception e) { - // ignored - } - } - }, - ITERATION_LENGTH_MILLIS); - } catch (Exception e) { - animation.cancel(); - } - } - }); - - mPseudoEmergencyColorAnimator.setDuration(VIBRATE_LENGTH_MILLIS); - mPseudoEmergencyColorAnimator.setRepeatMode(ValueAnimator.REVERSE); - mPseudoEmergencyColorAnimator.setRepeatCount(ANIMATION_ITERATION_COUNT); - } - if (!mPseudoEmergencyColorAnimator.isStarted()) { - mPseudoEmergencyColorAnimator.start(); - } - } - - public void end() { - if (mPseudoEmergencyColorAnimator != null && mPseudoEmergencyColorAnimator.isStarted()) { - mPseudoEmergencyColorAnimator.end(); - } - } - - private View getView() { - return mViewProvider == null ? null : mViewProvider.getView(); - } - - private Context getContext() { - View view = getView(); - return view != null ? view.getContext() : null; - } - - private void vibrate(long milliseconds) { - Context context = getContext(); - if (context != null) { - Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - if (vibrator != null) { - vibrator.vibrate(milliseconds); - } - } - } - - public interface ViewProvider { - - View getView(); - } -} diff --git a/java/com/android/dialer/app/dialpad/SmartDialCursorLoader.java b/java/com/android/dialer/app/dialpad/SmartDialCursorLoader.java deleted file mode 100644 index a0c8b18d3..000000000 --- a/java/com/android/dialer/app/dialpad/SmartDialCursorLoader.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.app.dialpad; - -import android.content.AsyncTaskLoader; -import android.content.Context; -import android.database.Cursor; -import android.database.MatrixCursor; -import com.android.contacts.common.list.PhoneNumberListAdapter.PhoneQuery; -import com.android.dialer.common.LogUtil; -import com.android.dialer.database.Database; -import com.android.dialer.database.DialerDatabaseHelper; -import com.android.dialer.database.DialerDatabaseHelper.ContactNumber; -import com.android.dialer.smartdial.SmartDialNameMatcher; -import com.android.dialer.smartdial.SmartDialPrefix; -import com.android.dialer.util.PermissionsUtil; -import java.util.ArrayList; - -/** Implements a Loader class to asynchronously load SmartDial search results. */ -public class SmartDialCursorLoader extends AsyncTaskLoader { - - private static final String TAG = "SmartDialCursorLoader"; - private static final boolean DEBUG = false; - - private final Context mContext; - - private Cursor mCursor; - - private String mQuery; - private SmartDialNameMatcher mNameMatcher; - - private boolean mShowEmptyListForNullQuery = true; - - public SmartDialCursorLoader(Context context) { - super(context); - mContext = context; - } - - /** - * Configures the query string to be used to find SmartDial matches. - * - * @param query The query string user typed. - */ - public void configureQuery(String query) { - if (DEBUG) { - LogUtil.v(TAG, "Configure new query to be " + query); - } - mQuery = SmartDialNameMatcher.normalizeNumber(query, SmartDialPrefix.getMap()); - - /** Constructs a name matcher object for matching names. */ - mNameMatcher = new SmartDialNameMatcher(mQuery, SmartDialPrefix.getMap()); - mNameMatcher.setShouldMatchEmptyQuery(!mShowEmptyListForNullQuery); - } - - /** - * Queries the SmartDial database and loads results in background. - * - * @return Cursor of contacts that matches the SmartDial query. - */ - @Override - public Cursor loadInBackground() { - if (DEBUG) { - LogUtil.v(TAG, "Load in background " + mQuery); - } - - if (!PermissionsUtil.hasContactsReadPermissions(mContext)) { - return new MatrixCursor(PhoneQuery.PROJECTION_PRIMARY); - } - - /** Loads results from the database helper. */ - final DialerDatabaseHelper dialerDatabaseHelper = - Database.get(mContext).getDatabaseHelper(mContext); - final ArrayList allMatches = - dialerDatabaseHelper.getLooseMatches(mQuery, mNameMatcher); - - if (DEBUG) { - LogUtil.v(TAG, "Loaded matches " + allMatches.size()); - } - - /** Constructs a cursor for the returned array of results. */ - final MatrixCursor cursor = new MatrixCursor(PhoneQuery.PROJECTION_PRIMARY); - Object[] row = new Object[PhoneQuery.PROJECTION_PRIMARY.length]; - for (ContactNumber contact : allMatches) { - row[PhoneQuery.PHONE_ID] = contact.dataId; - row[PhoneQuery.PHONE_NUMBER] = contact.phoneNumber; - row[PhoneQuery.CONTACT_ID] = contact.id; - row[PhoneQuery.LOOKUP_KEY] = contact.lookupKey; - row[PhoneQuery.PHOTO_ID] = contact.photoId; - row[PhoneQuery.DISPLAY_NAME] = contact.displayName; - row[PhoneQuery.CARRIER_PRESENCE] = contact.carrierPresence; - cursor.addRow(row); - } - return cursor; - } - - @Override - public void deliverResult(Cursor cursor) { - if (isReset()) { - /** The Loader has been reset; ignore the result and invalidate the data. */ - releaseResources(cursor); - return; - } - - /** Hold a reference to the old data so it doesn't get garbage collected. */ - Cursor oldCursor = mCursor; - mCursor = cursor; - - if (isStarted()) { - /** If the Loader is in a started state, deliver the results to the client. */ - super.deliverResult(cursor); - } - - /** Invalidate the old data as we don't need it any more. */ - if (oldCursor != null && oldCursor != cursor) { - releaseResources(oldCursor); - } - } - - @Override - protected void onStartLoading() { - if (mCursor != null) { - /** Deliver any previously loaded data immediately. */ - deliverResult(mCursor); - } - if (mCursor == null) { - /** Force loads every time as our results change with queries. */ - forceLoad(); - } - } - - @Override - protected void onStopLoading() { - /** The Loader is in a stopped state, so we should attempt to cancel the current load. */ - cancelLoad(); - } - - @Override - protected void onReset() { - /** Ensure the loader has been stopped. */ - onStopLoading(); - - /** Release all previously saved query results. */ - if (mCursor != null) { - releaseResources(mCursor); - mCursor = null; - } - } - - @Override - public void onCanceled(Cursor cursor) { - super.onCanceled(cursor); - - /** The load has been canceled, so we should release the resources associated with 'data'. */ - releaseResources(cursor); - } - - private void releaseResources(Cursor cursor) { - if (cursor != null) { - cursor.close(); - } - } - - public void setShowEmptyListForNullQuery(boolean show) { - mShowEmptyListForNullQuery = show; - if (mNameMatcher != null) { - mNameMatcher.setShouldMatchEmptyQuery(!show); - } - } -} diff --git a/java/com/android/dialer/app/dialpad/UnicodeDialerKeyListener.java b/java/com/android/dialer/app/dialpad/UnicodeDialerKeyListener.java deleted file mode 100644 index 051daf46e..000000000 --- a/java/com/android/dialer/app/dialpad/UnicodeDialerKeyListener.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.app.dialpad; - -import android.telephony.PhoneNumberUtils; -import android.text.Spanned; -import android.text.method.DialerKeyListener; - -/** - * {@link DialerKeyListener} with Unicode support. Converts any Unicode(e.g. Arabic) characters that - * represent digits into digits before filtering the results so that we can support pasted digits - * from Unicode languages. - */ -public class UnicodeDialerKeyListener extends DialerKeyListener { - - public static final UnicodeDialerKeyListener INSTANCE = new UnicodeDialerKeyListener(); - - @Override - public CharSequence filter( - CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { - final String converted = - PhoneNumberUtils.convertKeypadLettersToDigits( - PhoneNumberUtils.replaceUnicodeDigits(source.toString())); - // PhoneNumberUtils.replaceUnicodeDigits performs a character for character replacement, - // so we can assume that start and end positions should remain unchanged. - CharSequence result = super.filter(converted, start, end, dest, dstart, dend); - if (result == null) { - if (source.equals(converted)) { - // There was no conversion or filtering performed. Just return null according to - // the behavior of DialerKeyListener. - return null; - } else { - // filter returns null if the charsequence is to be returned unchanged/unfiltered. - // But in this case we do want to return a modified character string (even if - // none of the characters in the modified string are filtered). So if - // result == null we return the unfiltered but converted numeric string instead. - return converted.subSequence(start, end); - } - } - return result; - } -} diff --git a/java/com/android/dialer/app/list/SearchFragment.java b/java/com/android/dialer/app/list/SearchFragment.java index 00a2708a1..e21e073bd 100644 --- a/java/com/android/dialer/app/list/SearchFragment.java +++ b/java/com/android/dialer/app/list/SearchFragment.java @@ -38,10 +38,10 @@ import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; import com.android.contacts.common.list.PhoneNumberPickerFragment; import com.android.dialer.animation.AnimUtils; import com.android.dialer.app.R; -import com.android.dialer.app.dialpad.DialpadFragment.ErrorDialogFragment; import com.android.dialer.app.widget.DialpadSearchEmptyContentView; import com.android.dialer.callintent.CallSpecificAppData; import com.android.dialer.common.LogUtil; +import com.android.dialer.dialpadview.DialpadFragment.ErrorDialogFragment; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; import com.android.dialer.util.DialerUtils; diff --git a/java/com/android/dialer/app/list/SmartDialNumberListAdapter.java b/java/com/android/dialer/app/list/SmartDialNumberListAdapter.java index 566a15d53..3b00c7643 100644 --- a/java/com/android/dialer/app/list/SmartDialNumberListAdapter.java +++ b/java/com/android/dialer/app/list/SmartDialNumberListAdapter.java @@ -20,9 +20,9 @@ import android.database.Cursor; import android.support.annotation.NonNull; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; -import android.util.Log; import com.android.contacts.common.list.ContactListItemView; -import com.android.dialer.app.dialpad.SmartDialCursorLoader; +import com.android.dialer.common.LogUtil; +import com.android.dialer.dialpadview.SmartDialCursorLoader; import com.android.dialer.smartdial.SmartDialMatchPosition; import com.android.dialer.smartdial.SmartDialNameMatcher; import com.android.dialer.smartdial.SmartDialPrefix; @@ -43,14 +43,14 @@ public class SmartDialNumberListAdapter extends DialerPhoneNumberListAdapter { setShortcutEnabled(SmartDialNumberListAdapter.SHORTCUT_DIRECT_CALL, false); if (DEBUG) { - Log.v(TAG, "Constructing List Adapter"); + LogUtil.v(TAG, "Constructing List Adapter"); } } /** Sets query for the SmartDialCursorLoader. */ public void configureLoader(SmartDialCursorLoader loader) { if (DEBUG) { - Log.v(TAG, "Configure Loader with query" + getQueryString()); + LogUtil.v(TAG, "Configure Loader with query" + getQueryString()); } if (getQueryString() == null) { @@ -77,7 +77,7 @@ public class SmartDialNumberListAdapter extends DialerPhoneNumberListAdapter { for (SmartDialMatchPosition match : nameMatches) { view.addNameHighlightSequence(match.start, match.end); if (DEBUG) { - Log.v( + LogUtil.v( TAG, cursor.getString(PhoneQuery.DISPLAY_NAME) + " " diff --git a/java/com/android/dialer/app/list/SmartDialSearchFragment.java b/java/com/android/dialer/app/list/SmartDialSearchFragment.java index 2ebc06bc3..e97a16c19 100644 --- a/java/com/android/dialer/app/list/SmartDialSearchFragment.java +++ b/java/com/android/dialer/app/list/SmartDialSearchFragment.java @@ -28,10 +28,10 @@ import android.os.Bundle; import android.support.v13.app.FragmentCompat; import com.android.contacts.common.list.ContactEntryListAdapter; import com.android.dialer.app.R; -import com.android.dialer.app.dialpad.SmartDialCursorLoader; import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.common.LogUtil; import com.android.dialer.database.DialerDatabaseHelper; +import com.android.dialer.dialpadview.SmartDialCursorLoader; import com.android.dialer.util.PermissionsUtil; import com.android.dialer.widget.EmptyContentView; import java.util.Arrays; diff --git a/java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_add_call.png b/java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_add_call.png deleted file mode 100755 index 4e0d5649e..000000000 Binary files a/java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_add_call.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_current_call.png b/java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_current_call.png deleted file mode 100755 index 2cf41d598..000000000 Binary files a/java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_current_call.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_tt_keypad.png b/java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_tt_keypad.png deleted file mode 100755 index 043685fd9..000000000 Binary files a/java/com/android/dialer/app/res/drawable-hdpi/ic_dialer_fork_tt_keypad.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_add_call.png b/java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_add_call.png deleted file mode 100644 index 56ac2a33a..000000000 Binary files a/java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_add_call.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_current_call.png b/java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_current_call.png deleted file mode 100644 index 16a44a078..000000000 Binary files a/java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_current_call.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_tt_keypad.png b/java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_tt_keypad.png deleted file mode 100644 index 66df69eac..000000000 Binary files a/java/com/android/dialer/app/res/drawable-mdpi/ic_dialer_fork_tt_keypad.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_add_call.png b/java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_add_call.png deleted file mode 100644 index aff140fcd..000000000 Binary files a/java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_add_call.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_current_call.png b/java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_current_call.png deleted file mode 100644 index 8975727e0..000000000 Binary files a/java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_current_call.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_tt_keypad.png b/java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_tt_keypad.png deleted file mode 100644 index 4d48ea9ea..000000000 Binary files a/java/com/android/dialer/app/res/drawable-xhdpi/ic_dialer_fork_tt_keypad.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_add_call.png b/java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_add_call.png deleted file mode 100644 index 1657da4e2..000000000 Binary files a/java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_add_call.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_current_call.png b/java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_current_call.png deleted file mode 100644 index f25cce695..000000000 Binary files a/java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_current_call.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_tt_keypad.png b/java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_tt_keypad.png deleted file mode 100644 index 7ac4d8b58..000000000 Binary files a/java/com/android/dialer/app/res/drawable-xxhdpi/ic_dialer_fork_tt_keypad.png and /dev/null differ diff --git a/java/com/android/dialer/app/res/drawable/ic_wifi_calling.xml b/java/com/android/dialer/app/res/drawable/ic_wifi_calling.xml deleted file mode 100644 index 968713376..000000000 --- a/java/com/android/dialer/app/res/drawable/ic_wifi_calling.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/java/com/android/dialer/app/res/drawable/shadow_fade_left.xml b/java/com/android/dialer/app/res/drawable/shadow_fade_left.xml deleted file mode 100644 index 6271a8f86..000000000 --- a/java/com/android/dialer/app/res/drawable/shadow_fade_left.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - diff --git a/java/com/android/dialer/app/res/drawable/shadow_fade_up.xml b/java/com/android/dialer/app/res/drawable/shadow_fade_up.xml deleted file mode 100644 index 86d37a9bc..000000000 --- a/java/com/android/dialer/app/res/drawable/shadow_fade_up.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/java/com/android/dialer/app/res/layout-land/dialpad_fragment.xml b/java/com/android/dialer/app/res/layout-land/dialpad_fragment.xml deleted file mode 100644 index 45ef933cb..000000000 --- a/java/com/android/dialer/app/res/layout-land/dialpad_fragment.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/java/com/android/dialer/app/res/layout/dialpad_chooser_list_item.xml b/java/com/android/dialer/app/res/layout/dialpad_chooser_list_item.xml deleted file mode 100644 index e00529614..000000000 --- a/java/com/android/dialer/app/res/layout/dialpad_chooser_list_item.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - diff --git a/java/com/android/dialer/app/res/layout/dialpad_fragment.xml b/java/com/android/dialer/app/res/layout/dialpad_fragment.xml deleted file mode 100644 index 9b95e1fbf..000000000 --- a/java/com/android/dialer/app/res/layout/dialpad_fragment.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/java/com/android/dialer/app/res/menu/dialpad_options.xml b/java/com/android/dialer/app/res/menu/dialpad_options.xml deleted file mode 100644 index 2921ea3bb..000000000 --- a/java/com/android/dialer/app/res/menu/dialpad_options.xml +++ /dev/null @@ -1,30 +0,0 @@ - - -

- - - - - diff --git a/java/com/android/dialer/app/res/values/dimens.xml b/java/com/android/dialer/app/res/values/dimens.xml index 90a8bb879..4327fb908 100644 --- a/java/com/android/dialer/app/res/values/dimens.xml +++ b/java/com/android/dialer/app/res/values/dimens.xml @@ -107,9 +107,6 @@ so this extra padding makes the entire touch target 40dp --> 8dp - - 10dp - 16dp 16dp diff --git a/java/com/android/dialer/app/res/values/donottranslate_config.xml b/java/com/android/dialer/app/res/values/donottranslate_config.xml index e7a8e6fc3..0d18d551e 100644 --- a/java/com/android/dialer/app/res/values/donottranslate_config.xml +++ b/java/com/android/dialer/app/res/values/donottranslate_config.xml @@ -29,9 +29,4 @@ keys, but for maximum flexibility it's controlled by a flag here (which can be overridden on a per-product basis.) --> true - - - - diff --git a/java/com/android/dialer/app/res/values/strings.xml b/java/com/android/dialer/app/res/values/strings.xml index 5549881c3..4a7c68f91 100644 --- a/java/com/android/dialer/app/res/values/strings.xml +++ b/java/com/android/dialer/app/res/values/strings.xml @@ -176,12 +176,6 @@ --> search - - dial - Show all calls - - Add 2-sec pause - Add wait - Settings @@ -264,21 +254,6 @@ All contacts - - Use touch tone keypad - - - Return to call in progress - - - Add call - Incoming calls @@ -381,9 +356,6 @@ Start voice search - - Call %s - Voicemail @@ -425,34 +397,9 @@ %1$s \u2022 %2$s - - Can\'t call this number - - - To set up voicemail, go to Menu > Settings. - - - To call voicemail, first turn off Airplane mode. - Loading\u2026 - - IMEI - - - MEID - - - Loading from SIM card\u2026 - - - SIM card contacts - Voice search not available -- cgit v1.2.3