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