• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.phone;
18 
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.app.Dialog;
22 import android.app.StatusBarManager;
23 import android.content.BroadcastReceiver;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.content.IntentFilter;
27 import android.content.res.Resources;
28 import android.media.AudioManager;
29 import android.media.ToneGenerator;
30 import android.net.Uri;
31 import android.os.Bundle;
32 import android.os.PersistableBundle;
33 import android.provider.Settings;
34 import android.telecom.PhoneAccount;
35 import android.telephony.CarrierConfigManager;
36 import android.telephony.PhoneNumberUtils;
37 import android.telephony.SubscriptionManager;
38 import android.text.Editable;
39 import android.text.TextUtils;
40 import android.text.TextWatcher;
41 import android.text.method.DialerKeyListener;
42 import android.text.style.TtsSpan;
43 import android.util.Log;
44 import android.view.KeyEvent;
45 import android.view.MenuItem;
46 import android.view.MotionEvent;
47 import android.view.View;
48 import android.view.WindowManager;
49 import android.view.accessibility.AccessibilityManager;
50 import android.widget.EditText;
51 
52 import com.android.phone.common.HapticFeedback;
53 import com.android.phone.common.dialpad.DialpadKeyButton;
54 import com.android.phone.common.util.ViewUtil;
55 
56 
57 /**
58  * EmergencyDialer is a special dialer that is used ONLY for dialing emergency calls.
59  *
60  * It's a simplified version of the regular dialer (i.e. the TwelveKeyDialer
61  * activity from apps/Contacts) that:
62  *   1. Allows ONLY emergency calls to be dialed
63  *   2. Disallows voicemail functionality
64  *   3. Uses the FLAG_SHOW_WHEN_LOCKED window manager flag to allow this
65  *      activity to stay in front of the keyguard.
66  *
67  * TODO: Even though this is an ultra-simplified version of the normal
68  * dialer, there's still lots of code duplication between this class and
69  * the TwelveKeyDialer class from apps/Contacts.  Could the common code be
70  * moved into a shared base class that would live in the framework?
71  * Or could we figure out some way to move *this* class into apps/Contacts
72  * also?
73  */
74 public class EmergencyDialer extends Activity implements View.OnClickListener,
75         View.OnLongClickListener, View.OnKeyListener, TextWatcher,
76         DialpadKeyButton.OnPressedListener {
77     // Keys used with onSaveInstanceState().
78     private static final String LAST_NUMBER = "lastNumber";
79 
80     // Intent action for this activity.
81     public static final String ACTION_DIAL = "com.android.phone.EmergencyDialer.DIAL";
82 
83     // List of dialer button IDs.
84     private static final int[] DIALER_KEYS = new int[] {
85             R.id.one, R.id.two, R.id.three,
86             R.id.four, R.id.five, R.id.six,
87             R.id.seven, R.id.eight, R.id.nine,
88             R.id.star, R.id.zero, R.id.pound };
89 
90     // Debug constants.
91     private static final boolean DBG = false;
92     private static final String LOG_TAG = "EmergencyDialer";
93 
94     private StatusBarManager mStatusBarManager;
95 
96     /** The length of DTMF tones in milliseconds */
97     private static final int TONE_LENGTH_MS = 150;
98 
99     /** The DTMF tone volume relative to other sounds in the stream */
100     private static final int TONE_RELATIVE_VOLUME = 80;
101 
102     /** Stream type used to play the DTMF tones off call, and mapped to the volume control keys */
103     private static final int DIAL_TONE_STREAM_TYPE = AudioManager.STREAM_DTMF;
104 
105     private static final int BAD_EMERGENCY_NUMBER_DIALOG = 0;
106 
107     // private static final int USER_ACTIVITY_TIMEOUT_WHEN_NO_PROX_SENSOR = 15000; // millis
108 
109     EditText mDigits;
110     private View mDialButton;
111     private View mDelete;
112 
113     private ToneGenerator mToneGenerator;
114     private Object mToneGeneratorLock = new Object();
115 
116     // determines if we want to playback local DTMF tones.
117     private boolean mDTMFToneEnabled;
118 
119     // Haptic feedback (vibration) for dialer key presses.
120     private HapticFeedback mHaptic = new HapticFeedback();
121 
122     private EmergencyActionGroup mEmergencyActionGroup;
123 
124     // close activity when screen turns off
125     private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
126         @Override
127         public void onReceive(Context context, Intent intent) {
128             if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
129                 finishAndRemoveTask();
130             }
131         }
132     };
133 
134     private String mLastNumber; // last number we tried to dial. Used to restore error dialog.
135 
136     @Override
beforeTextChanged(CharSequence s, int start, int count, int after)137     public void beforeTextChanged(CharSequence s, int start, int count, int after) {
138         // Do nothing
139     }
140 
141     @Override
onTextChanged(CharSequence input, int start, int before, int changeCount)142     public void onTextChanged(CharSequence input, int start, int before, int changeCount) {
143         // Do nothing
144     }
145 
146     @Override
afterTextChanged(Editable input)147     public void afterTextChanged(Editable input) {
148         // Check for special sequences, in particular the "**04" or "**05"
149         // sequences that allow you to enter PIN or PUK-related codes.
150         //
151         // But note we *don't* allow most other special sequences here,
152         // like "secret codes" (*#*#<code>#*#*) or IMEI display ("*#06#"),
153         // since those shouldn't be available if the device is locked.
154         //
155         // So we call SpecialCharSequenceMgr.handleCharsForLockedDevice()
156         // here, not the regular handleChars() method.
157         if (SpecialCharSequenceMgr.handleCharsForLockedDevice(this, input.toString(), this)) {
158             // A special sequence was entered, clear the digits
159             mDigits.getText().clear();
160         }
161 
162         updateDialAndDeleteButtonStateEnabledAttr();
163         updateTtsSpans();
164     }
165 
166     @Override
onCreate(Bundle icicle)167     protected void onCreate(Bundle icicle) {
168         super.onCreate(icicle);
169 
170         mStatusBarManager = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE);
171 
172         // Allow this activity to be displayed in front of the keyguard / lockscreen.
173         WindowManager.LayoutParams lp = getWindow().getAttributes();
174         lp.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
175 
176         // When no proximity sensor is available, use a shorter timeout.
177         // TODO: Do we enable this for non proximity devices any more?
178         // lp.userActivityTimeout = USER_ACTIVITY_TIMEOUT_WHEN_NO_PROX_SENSOR;
179 
180         getWindow().setAttributes(lp);
181 
182         setContentView(R.layout.emergency_dialer);
183 
184         mDigits = (EditText) findViewById(R.id.digits);
185         mDigits.setKeyListener(DialerKeyListener.getInstance());
186         mDigits.setOnClickListener(this);
187         mDigits.setOnKeyListener(this);
188         mDigits.setLongClickable(false);
189         maybeAddNumberFormatting();
190 
191         // Check for the presence of the keypad
192         View view = findViewById(R.id.one);
193         if (view != null) {
194             setupKeypad();
195         }
196 
197         mDelete = findViewById(R.id.deleteButton);
198         mDelete.setOnClickListener(this);
199         mDelete.setOnLongClickListener(this);
200 
201         mDialButton = findViewById(R.id.floating_action_button);
202 
203         // Check whether we should show the onscreen "Dial" button and co.
204         // Read carrier config through the public API because PhoneGlobals is not available when we
205         // run as a secondary user.
206         CarrierConfigManager configMgr =
207                 (CarrierConfigManager) getSystemService(Context.CARRIER_CONFIG_SERVICE);
208         PersistableBundle carrierConfig =
209                 configMgr.getConfigForSubId(SubscriptionManager.getDefaultVoiceSubId());
210         if (carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_ONSCREEN_DIAL_BUTTON_BOOL)) {
211             mDialButton.setOnClickListener(this);
212         } else {
213             mDialButton.setVisibility(View.GONE);
214         }
215         ViewUtil.setupFloatingActionButton(mDialButton, getResources());
216 
217         if (icicle != null) {
218             super.onRestoreInstanceState(icicle);
219         }
220 
221         // Extract phone number from intent
222         Uri data = getIntent().getData();
223         if (data != null && (PhoneAccount.SCHEME_TEL.equals(data.getScheme()))) {
224             String number = PhoneNumberUtils.getNumberFromIntent(getIntent(), this);
225             if (number != null) {
226                 mDigits.setText(number);
227             }
228         }
229 
230         // if the mToneGenerator creation fails, just continue without it.  It is
231         // a local audio signal, and is not as important as the dtmf tone itself.
232         synchronized (mToneGeneratorLock) {
233             if (mToneGenerator == null) {
234                 try {
235                     mToneGenerator = new ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME);
236                 } catch (RuntimeException e) {
237                     Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e);
238                     mToneGenerator = null;
239                 }
240             }
241         }
242 
243         final IntentFilter intentFilter = new IntentFilter();
244         intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
245         registerReceiver(mBroadcastReceiver, intentFilter);
246 
247         try {
248             mHaptic.init(
249                     this,
250                     carrierConfig.getBoolean(
251                             CarrierConfigManager.KEY_ENABLE_DIALER_KEY_VIBRATION_BOOL));
252         } catch (Resources.NotFoundException nfe) {
253              Log.e(LOG_TAG, "Vibrate control bool missing.", nfe);
254         }
255 
256         mEmergencyActionGroup = (EmergencyActionGroup) findViewById(R.id.emergency_action_group);
257     }
258 
259     @Override
onDestroy()260     protected void onDestroy() {
261         super.onDestroy();
262         synchronized (mToneGeneratorLock) {
263             if (mToneGenerator != null) {
264                 mToneGenerator.release();
265                 mToneGenerator = null;
266             }
267         }
268         unregisterReceiver(mBroadcastReceiver);
269     }
270 
271     @Override
onRestoreInstanceState(Bundle icicle)272     protected void onRestoreInstanceState(Bundle icicle) {
273         mLastNumber = icicle.getString(LAST_NUMBER);
274     }
275 
276     @Override
onSaveInstanceState(Bundle outState)277     protected void onSaveInstanceState(Bundle outState) {
278         super.onSaveInstanceState(outState);
279         outState.putString(LAST_NUMBER, mLastNumber);
280     }
281 
282     /**
283      * Explicitly turn off number formatting, since it gets in the way of the emergency
284      * number detector
285      */
maybeAddNumberFormatting()286     protected void maybeAddNumberFormatting() {
287         // Do nothing.
288     }
289 
290     @Override
onPostCreate(Bundle savedInstanceState)291     protected void onPostCreate(Bundle savedInstanceState) {
292         super.onPostCreate(savedInstanceState);
293 
294         // This can't be done in onCreate(), since the auto-restoring of the digits
295         // will play DTMF tones for all the old digits if it is when onRestoreSavedInstanceState()
296         // is called. This method will be called every time the activity is created, and
297         // will always happen after onRestoreSavedInstanceState().
298         mDigits.addTextChangedListener(this);
299     }
300 
setupKeypad()301     private void setupKeypad() {
302         // Setup the listeners for the buttons
303         for (int id : DIALER_KEYS) {
304             final DialpadKeyButton key = (DialpadKeyButton) findViewById(id);
305             key.setOnPressedListener(this);
306         }
307 
308         View view = findViewById(R.id.zero);
309         view.setOnLongClickListener(this);
310     }
311 
312     /**
313      * handle key events
314      */
315     @Override
onKeyDown(int keyCode, KeyEvent event)316     public boolean onKeyDown(int keyCode, KeyEvent event) {
317         switch (keyCode) {
318             // Happen when there's a "Call" hard button.
319             case KeyEvent.KEYCODE_CALL: {
320                 if (TextUtils.isEmpty(mDigits.getText().toString())) {
321                     // if we are adding a call from the InCallScreen and the phone
322                     // number entered is empty, we just close the dialer to expose
323                     // the InCallScreen under it.
324                     finish();
325                 } else {
326                     // otherwise, we place the call.
327                     placeCall();
328                 }
329                 return true;
330             }
331         }
332         return super.onKeyDown(keyCode, event);
333     }
334 
keyPressed(int keyCode)335     private void keyPressed(int keyCode) {
336         mHaptic.vibrate();
337         KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
338         mDigits.onKeyDown(keyCode, event);
339     }
340 
341     @Override
onKey(View view, int keyCode, KeyEvent event)342     public boolean onKey(View view, int keyCode, KeyEvent event) {
343         switch (view.getId()) {
344             case R.id.digits:
345                 // Happen when "Done" button of the IME is pressed. This can happen when this
346                 // Activity is forced into landscape mode due to a desk dock.
347                 if (keyCode == KeyEvent.KEYCODE_ENTER
348                         && event.getAction() == KeyEvent.ACTION_UP) {
349                     placeCall();
350                     return true;
351                 }
352                 break;
353         }
354         return false;
355     }
356 
357     @Override
dispatchTouchEvent(MotionEvent ev)358     public boolean dispatchTouchEvent(MotionEvent ev) {
359         mEmergencyActionGroup.onPreTouchEvent(ev);
360         boolean handled = super.dispatchTouchEvent(ev);
361         mEmergencyActionGroup.onPostTouchEvent(ev);
362         return handled;
363     }
364 
365     @Override
onClick(View view)366     public void onClick(View view) {
367         switch (view.getId()) {
368             case R.id.deleteButton: {
369                 keyPressed(KeyEvent.KEYCODE_DEL);
370                 return;
371             }
372             case R.id.floating_action_button: {
373                 mHaptic.vibrate();  // Vibrate here too, just like we do for the regular keys
374                 placeCall();
375                 return;
376             }
377             case R.id.digits: {
378                 if (mDigits.length() != 0) {
379                     mDigits.setCursorVisible(true);
380                 }
381                 return;
382             }
383         }
384     }
385 
386     @Override
onPressed(View view, boolean pressed)387     public void onPressed(View view, boolean pressed) {
388         if (!pressed) {
389             return;
390         }
391         switch (view.getId()) {
392             case R.id.one: {
393                 playTone(ToneGenerator.TONE_DTMF_1);
394                 keyPressed(KeyEvent.KEYCODE_1);
395                 return;
396             }
397             case R.id.two: {
398                 playTone(ToneGenerator.TONE_DTMF_2);
399                 keyPressed(KeyEvent.KEYCODE_2);
400                 return;
401             }
402             case R.id.three: {
403                 playTone(ToneGenerator.TONE_DTMF_3);
404                 keyPressed(KeyEvent.KEYCODE_3);
405                 return;
406             }
407             case R.id.four: {
408                 playTone(ToneGenerator.TONE_DTMF_4);
409                 keyPressed(KeyEvent.KEYCODE_4);
410                 return;
411             }
412             case R.id.five: {
413                 playTone(ToneGenerator.TONE_DTMF_5);
414                 keyPressed(KeyEvent.KEYCODE_5);
415                 return;
416             }
417             case R.id.six: {
418                 playTone(ToneGenerator.TONE_DTMF_6);
419                 keyPressed(KeyEvent.KEYCODE_6);
420                 return;
421             }
422             case R.id.seven: {
423                 playTone(ToneGenerator.TONE_DTMF_7);
424                 keyPressed(KeyEvent.KEYCODE_7);
425                 return;
426             }
427             case R.id.eight: {
428                 playTone(ToneGenerator.TONE_DTMF_8);
429                 keyPressed(KeyEvent.KEYCODE_8);
430                 return;
431             }
432             case R.id.nine: {
433                 playTone(ToneGenerator.TONE_DTMF_9);
434                 keyPressed(KeyEvent.KEYCODE_9);
435                 return;
436             }
437             case R.id.zero: {
438                 playTone(ToneGenerator.TONE_DTMF_0);
439                 keyPressed(KeyEvent.KEYCODE_0);
440                 return;
441             }
442             case R.id.pound: {
443                 playTone(ToneGenerator.TONE_DTMF_P);
444                 keyPressed(KeyEvent.KEYCODE_POUND);
445                 return;
446             }
447             case R.id.star: {
448                 playTone(ToneGenerator.TONE_DTMF_S);
449                 keyPressed(KeyEvent.KEYCODE_STAR);
450                 return;
451             }
452         }
453     }
454 
455     /**
456      * called for long touch events
457      */
458     @Override
onLongClick(View view)459     public boolean onLongClick(View view) {
460         int id = view.getId();
461         switch (id) {
462             case R.id.deleteButton: {
463                 mDigits.getText().clear();
464                 return true;
465             }
466             case R.id.zero: {
467                 removePreviousDigitIfPossible();
468                 keyPressed(KeyEvent.KEYCODE_PLUS);
469                 return true;
470             }
471         }
472         return false;
473     }
474 
475     @Override
onResume()476     protected void onResume() {
477         super.onResume();
478 
479         // retrieve the DTMF tone play back setting.
480         mDTMFToneEnabled = Settings.System.getInt(getContentResolver(),
481                 Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1;
482 
483         // Retrieve the haptic feedback setting.
484         mHaptic.checkSystemSetting();
485 
486         // if the mToneGenerator creation fails, just continue without it.  It is
487         // a local audio signal, and is not as important as the dtmf tone itself.
488         synchronized (mToneGeneratorLock) {
489             if (mToneGenerator == null) {
490                 try {
491                     mToneGenerator = new ToneGenerator(AudioManager.STREAM_DTMF,
492                             TONE_RELATIVE_VOLUME);
493                 } catch (RuntimeException e) {
494                     Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e);
495                     mToneGenerator = null;
496                 }
497             }
498         }
499 
500         // Disable the status bar and set the poke lock timeout to medium.
501         // There is no need to do anything with the wake lock.
502         if (DBG) Log.d(LOG_TAG, "disabling status bar, set to long timeout");
503         mStatusBarManager.disable(StatusBarManager.DISABLE_EXPAND);
504 
505         updateDialAndDeleteButtonStateEnabledAttr();
506     }
507 
508     @Override
onPause()509     public void onPause() {
510         // Reenable the status bar and set the poke lock timeout to default.
511         // There is no need to do anything with the wake lock.
512         if (DBG) Log.d(LOG_TAG, "reenabling status bar and closing the dialer");
513         mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);
514 
515         super.onPause();
516 
517         synchronized (mToneGeneratorLock) {
518             if (mToneGenerator != null) {
519                 mToneGenerator.release();
520                 mToneGenerator = null;
521             }
522         }
523     }
524 
525     /**
526      * place the call, but check to make sure it is a viable number.
527      */
placeCall()528     private void placeCall() {
529         mLastNumber = mDigits.getText().toString();
530         if (PhoneNumberUtils.isLocalEmergencyNumber(this, mLastNumber)) {
531             if (DBG) Log.d(LOG_TAG, "placing call to " + mLastNumber);
532 
533             // place the call if it is a valid number
534             if (mLastNumber == null || !TextUtils.isGraphic(mLastNumber)) {
535                 // There is no number entered.
536                 playTone(ToneGenerator.TONE_PROP_NACK);
537                 return;
538             }
539             Intent intent = new Intent(Intent.ACTION_CALL_EMERGENCY);
540             intent.setData(Uri.fromParts(PhoneAccount.SCHEME_TEL, mLastNumber, null));
541             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
542             startActivity(intent);
543         } else {
544             if (DBG) Log.d(LOG_TAG, "rejecting bad requested number " + mLastNumber);
545 
546             showDialog(BAD_EMERGENCY_NUMBER_DIALOG);
547         }
548         mDigits.getText().delete(0, mDigits.getText().length());
549     }
550 
551     /**
552      * Plays the specified tone for TONE_LENGTH_MS milliseconds.
553      *
554      * The tone is played locally, using the audio stream for phone calls.
555      * Tones are played only if the "Audible touch tones" user preference
556      * is checked, and are NOT played if the device is in silent mode.
557      *
558      * @param tone a tone code from {@link ToneGenerator}
559      */
playTone(int tone)560     void playTone(int tone) {
561         // if local tone playback is disabled, just return.
562         if (!mDTMFToneEnabled) {
563             return;
564         }
565 
566         // Also do nothing if the phone is in silent mode.
567         // We need to re-check the ringer mode for *every* playTone()
568         // call, rather than keeping a local flag that's updated in
569         // onResume(), since it's possible to toggle silent mode without
570         // leaving the current activity (via the ENDCALL-longpress menu.)
571         AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
572         int ringerMode = audioManager.getRingerMode();
573         if ((ringerMode == AudioManager.RINGER_MODE_SILENT)
574             || (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
575             return;
576         }
577 
578         synchronized (mToneGeneratorLock) {
579             if (mToneGenerator == null) {
580                 Log.w(LOG_TAG, "playTone: mToneGenerator == null, tone: " + tone);
581                 return;
582             }
583 
584             // Start the new tone (will stop any playing tone)
585             mToneGenerator.startTone(tone, TONE_LENGTH_MS);
586         }
587     }
588 
createErrorMessage(String number)589     private CharSequence createErrorMessage(String number) {
590         if (!TextUtils.isEmpty(number)) {
591             return getString(R.string.dial_emergency_error, mLastNumber);
592         } else {
593             return getText(R.string.dial_emergency_empty_error).toString();
594         }
595     }
596 
597     @Override
onCreateDialog(int id)598     protected Dialog onCreateDialog(int id) {
599         AlertDialog dialog = null;
600         if (id == BAD_EMERGENCY_NUMBER_DIALOG) {
601             // construct dialog
602             dialog = new AlertDialog.Builder(this)
603                     .setTitle(getText(R.string.emergency_enable_radio_dialog_title))
604                     .setMessage(createErrorMessage(mLastNumber))
605                     .setPositiveButton(R.string.ok, null)
606                     .setCancelable(true).create();
607 
608             // blur stuff behind the dialog
609             dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
610             dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
611         }
612         return dialog;
613     }
614 
615     @Override
onPrepareDialog(int id, Dialog dialog)616     protected void onPrepareDialog(int id, Dialog dialog) {
617         super.onPrepareDialog(id, dialog);
618         if (id == BAD_EMERGENCY_NUMBER_DIALOG) {
619             AlertDialog alert = (AlertDialog) dialog;
620             alert.setMessage(createErrorMessage(mLastNumber));
621         }
622     }
623 
624     @Override
onOptionsItemSelected(MenuItem item)625     public boolean onOptionsItemSelected(MenuItem item) {
626         final int itemId = item.getItemId();
627         if (itemId == android.R.id.home) {
628             onBackPressed();
629             return true;
630         }
631         return super.onOptionsItemSelected(item);
632     }
633 
634     /**
635      * Update the enabledness of the "Dial" and "Backspace" buttons if applicable.
636      */
updateDialAndDeleteButtonStateEnabledAttr()637     private void updateDialAndDeleteButtonStateEnabledAttr() {
638         final boolean notEmpty = mDigits.length() != 0;
639 
640         mDelete.setEnabled(notEmpty);
641     }
642 
643     /**
644      * Remove the digit just before the current position. Used by various long pressed callbacks
645      * to remove the digit that was populated as a result of the short click.
646      */
removePreviousDigitIfPossible()647     private void removePreviousDigitIfPossible() {
648         final int currentPosition = mDigits.getSelectionStart();
649         if (currentPosition > 0) {
650             mDigits.setSelection(currentPosition);
651             mDigits.getText().delete(currentPosition - 1, currentPosition);
652         }
653     }
654 
655     /**
656      * Update the text-to-speech annotations in the edit field.
657      */
updateTtsSpans()658     private void updateTtsSpans() {
659         for (Object o : mDigits.getText().getSpans(0, mDigits.getText().length(), TtsSpan.class)) {
660             mDigits.getText().removeSpan(o);
661         }
662         PhoneNumberUtils.ttsSpanAsPhoneNumber(mDigits.getText(), 0, mDigits.getText().length());
663     }
664 }
665