blob: 951fae9ca7a209ba4683fd59b2593497b1e99187 [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
Tyler Gunn1acf54a2018-03-28 14:15:34 -070019import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;
20
Chihhang Chuangd301d9a2018-06-05 15:29:06 +080021import android.animation.Animator;
22import android.animation.AnimatorListenerAdapter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023import android.app.Activity;
24import android.app.AlertDialog;
25import android.app.Dialog;
Lucas Dupineb9c5702017-05-10 16:57:09 -070026import android.app.WallpaperManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.BroadcastReceiver;
28import android.content.Context;
29import android.content.Intent;
30import android.content.IntentFilter;
Chihhang Chuanga26f07b2018-07-02 11:08:50 +080031import android.graphics.Color;
Lucas Dupineb9c5702017-05-10 16:57:09 -070032import android.graphics.Point;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.media.AudioManager;
34import android.media.ToneGenerator;
35import android.net.Uri;
Tyler Gunn1acf54a2018-03-28 14:15:34 -070036import android.os.AsyncTask;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.os.Bundle;
Jonathan Basseric31f1f32015-05-12 10:13:03 -070038import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.provider.Settings;
Tyler Gunn4d45d1c2014-09-12 22:17:53 -070040import android.telecom.PhoneAccount;
Tyler Gunnca7dfef2018-03-27 18:50:05 +000041import android.telecom.TelecomManager;
Jonathan Basseri3649bdb2015-04-30 22:39:11 -070042import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.telephony.PhoneNumberUtils;
Billy Chi9614de82018-06-15 19:00:15 +080044import android.telephony.Rlog;
Tyler Gunn1acf54a2018-03-28 14:15:34 -070045import android.telephony.ServiceState;
Santos Cordone137eed2015-06-23 15:34:47 -070046import android.telephony.SubscriptionManager;
Tyler Gunn1acf54a2018-03-28 14:15:34 -070047import android.telephony.TelephonyManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.text.Editable;
Hall Liubdc9c882016-05-25 15:25:28 -070049import android.text.InputType;
Hall Liudc274312016-03-01 16:34:45 -080050import android.text.Spannable;
51import android.text.SpannableString;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.text.TextUtils;
53import android.text.TextWatcher;
54import android.text.method.DialerKeyListener;
Ihab Awadf7c1a5a2014-12-08 19:24:23 -080055import android.text.style.TtsSpan;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.util.Log;
Tyler Gunn1acf54a2018-03-28 14:15:34 -070057import android.util.TypedValue;
Yorke Lee116dd072015-08-31 11:38:39 -070058import android.view.HapticFeedbackConstants;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.view.KeyEvent;
Andrew Leed5631e82014-10-08 16:03:58 -070060import android.view.MenuItem;
Adrian Roos1c4b47f2015-04-13 14:53:32 -070061import android.view.MotionEvent;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062import android.view.View;
Chihhang Chuang4f2b7812018-06-07 16:25:27 +080063import android.view.ViewGroup;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.view.WindowManager;
Chihhang Chuang4f2b7812018-06-07 16:25:27 +080065import android.widget.TextView;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066
Lucas Dupinaf9e9912017-06-22 12:39:39 -070067import com.android.internal.colorextraction.ColorExtractor;
68import com.android.internal.colorextraction.ColorExtractor.GradientColors;
69import com.android.internal.colorextraction.drawable.GradientDrawable;
Yorke Lee23a70732014-08-14 17:12:01 -070070import com.android.phone.common.dialpad.DialpadKeyButton;
Sai Cheemalapati14462b62014-06-18 13:53:56 -070071import com.android.phone.common.util.ViewUtil;
Tyler Gunn1acf54a2018-03-28 14:15:34 -070072import com.android.phone.common.widget.ResizingTextEditText;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073
Chihhang Chuang4f2b7812018-06-07 16:25:27 +080074import java.util.ArrayList;
75import java.util.List;
76
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077/**
78 * EmergencyDialer is a special dialer that is used ONLY for dialing emergency calls.
79 *
80 * It's a simplified version of the regular dialer (i.e. the TwelveKeyDialer
81 * activity from apps/Contacts) that:
82 * 1. Allows ONLY emergency calls to be dialed
83 * 2. Disallows voicemail functionality
84 * 3. Uses the FLAG_SHOW_WHEN_LOCKED window manager flag to allow this
85 * activity to stay in front of the keyguard.
86 *
87 * TODO: Even though this is an ultra-simplified version of the normal
88 * dialer, there's still lots of code duplication between this class and
89 * the TwelveKeyDialer class from apps/Contacts. Could the common code be
90 * moved into a shared base class that would live in the framework?
91 * Or could we figure out some way to move *this* class into apps/Contacts
92 * also?
Chihhang Chuangd301d9a2018-06-05 15:29:06 +080093 *
94 * TODO: Implement emergency dialer shortcut.
Chihhang Chuang4f2b7812018-06-07 16:25:27 +080095 * Emergency dialer shortcut offer a local emergency number list. Directly clicking a call button
96 * to place an emergency phone call without entering numbers from dialpad.
Chihhang Chuangd301d9a2018-06-05 15:29:06 +080097 * TODO item:
Chihhang Chuang4f2b7812018-06-07 16:25:27 +080098 * 1.integrate emergency phone number table.
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099 */
100public class EmergencyDialer extends Activity implements View.OnClickListener,
Yorke Lee23a70732014-08-14 17:12:01 -0700101 View.OnLongClickListener, View.OnKeyListener, TextWatcher,
Chihhang Chuang4f2b7812018-06-07 16:25:27 +0800102 DialpadKeyButton.OnPressedListener, ColorExtractor.OnColorsChangedListener,
103 EmergencyShortcutButton.OnConfirmClickListener {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104 // Keys used with onSaveInstanceState().
105 private static final String LAST_NUMBER = "lastNumber";
106
107 // Intent action for this activity.
108 public static final String ACTION_DIAL = "com.android.phone.EmergencyDialer.DIAL";
109
110 // List of dialer button IDs.
111 private static final int[] DIALER_KEYS = new int[] {
112 R.id.one, R.id.two, R.id.three,
113 R.id.four, R.id.five, R.id.six,
114 R.id.seven, R.id.eight, R.id.nine,
115 R.id.star, R.id.zero, R.id.pound };
116
117 // Debug constants.
118 private static final boolean DBG = false;
119 private static final String LOG_TAG = "EmergencyDialer";
120
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121 /** The length of DTMF tones in milliseconds */
122 private static final int TONE_LENGTH_MS = 150;
123
124 /** The DTMF tone volume relative to other sounds in the stream */
125 private static final int TONE_RELATIVE_VOLUME = 80;
126
127 /** Stream type used to play the DTMF tones off call, and mapped to the volume control keys */
128 private static final int DIAL_TONE_STREAM_TYPE = AudioManager.STREAM_DTMF;
129
130 private static final int BAD_EMERGENCY_NUMBER_DIALOG = 0;
131
Lucas Dupineb9c5702017-05-10 16:57:09 -0700132 /** 90% opacity, different from other gradients **/
133 private static final int BACKGROUND_GRADIENT_ALPHA = 230;
134
Chihhang Chuanga26f07b2018-07-02 11:08:50 +0800135 /** 85% opacity for black background **/
136 private static final int BLACK_BACKGROUND_GRADIENT_ALPHA = 217;
137
Tyler Gunn1acf54a2018-03-28 14:15:34 -0700138 ResizingTextEditText mDigits;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139 private View mDialButton;
140 private View mDelete;
Chihhang Chuangd301d9a2018-06-05 15:29:06 +0800141 private View mEmergencyShortcutView;
142 private View mDialpadView;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143
Chihhang Chuang4f2b7812018-06-07 16:25:27 +0800144 private List<EmergencyShortcutButton> mEmergencyShortcutButtonList;
145
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146 private ToneGenerator mToneGenerator;
147 private Object mToneGeneratorLock = new Object();
148
149 // determines if we want to playback local DTMF tones.
150 private boolean mDTMFToneEnabled;
151
Adrian Roos1c4b47f2015-04-13 14:53:32 -0700152 private EmergencyActionGroup mEmergencyActionGroup;
153
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154 // close activity when screen turns off
155 private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
156 @Override
157 public void onReceive(Context context, Intent intent) {
158 if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
Adrian Roos061c7232015-04-21 12:37:07 -0700159 finishAndRemoveTask();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160 }
161 }
162 };
163
164 private String mLastNumber; // last number we tried to dial. Used to restore error dialog.
165
Lucas Dupineb9c5702017-05-10 16:57:09 -0700166 // Background gradient
167 private ColorExtractor mColorExtractor;
168 private GradientDrawable mBackgroundGradient;
169 private boolean mSupportsDarkText;
170
Tyler Gunn1acf54a2018-03-28 14:15:34 -0700171 private boolean mIsWfcEmergencyCallingWarningEnabled;
172 private float mDefaultDigitsTextSize;
173
Chihhang Chuangd301d9a2018-06-05 15:29:06 +0800174 private boolean mAreEmergencyDialerShortcutsEnabled;
175
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176 @Override
177 public void beforeTextChanged(CharSequence s, int start, int count, int after) {
178 // Do nothing
179 }
180
181 @Override
182 public void onTextChanged(CharSequence input, int start, int before, int changeCount) {
Tyler Gunn1acf54a2018-03-28 14:15:34 -0700183 maybeChangeHintSize();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184 }
185
186 @Override
187 public void afterTextChanged(Editable input) {
188 // Check for special sequences, in particular the "**04" or "**05"
189 // sequences that allow you to enter PIN or PUK-related codes.
190 //
191 // But note we *don't* allow most other special sequences here,
192 // like "secret codes" (*#*#<code>#*#*) or IMEI display ("*#06#"),
193 // since those shouldn't be available if the device is locked.
194 //
195 // So we call SpecialCharSequenceMgr.handleCharsForLockedDevice()
196 // here, not the regular handleChars() method.
197 if (SpecialCharSequenceMgr.handleCharsForLockedDevice(this, input.toString(), this)) {
198 // A special sequence was entered, clear the digits
199 mDigits.getText().clear();
200 }
201
202 updateDialAndDeleteButtonStateEnabledAttr();
Ihab Awadf7c1a5a2014-12-08 19:24:23 -0800203 updateTtsSpans();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204 }
205
206 @Override
207 protected void onCreate(Bundle icicle) {
208 super.onCreate(icicle);
209
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700210 // Allow this activity to be displayed in front of the keyguard / lockscreen.
211 WindowManager.LayoutParams lp = getWindow().getAttributes();
212 lp.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Santos Cordonfc309812013-08-20 18:33:16 -0700213
214 // When no proximity sensor is available, use a shorter timeout.
Christine Chen07fae162013-09-19 15:05:56 -0700215 // TODO: Do we enable this for non proximity devices any more?
Santos Cordonfc309812013-08-20 18:33:16 -0700216 // lp.userActivityTimeout = USER_ACTIVITY_TIMEOUT_WHEN_NO_PROX_SENSOR;
217
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218 getWindow().setAttributes(lp);
219
Chihhang Chuanga26f07b2018-07-02 11:08:50 +0800220 mAreEmergencyDialerShortcutsEnabled = Settings.Global.getInt(getContentResolver(),
221 Settings.Global.FASTER_EMERGENCY_PHONE_CALL_ENABLED, 0) != 0;
222
Lucas Dupineb9c5702017-05-10 16:57:09 -0700223 mColorExtractor = new ColorExtractor(this);
Chihhang Chuanga26f07b2018-07-02 11:08:50 +0800224
225 // It does not support dark text theme, when emergency dialer shortcuts are enabled.
226 // And the background color is black with 85% opacity.
227 if (mAreEmergencyDialerShortcutsEnabled) {
228 updateTheme(false);
229 } else {
230 GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK,
231 ColorExtractor.TYPE_EXTRA_DARK);
232 updateTheme(lockScreenColors.supportsDarkText());
233 }
Lucas Dupineb9c5702017-05-10 16:57:09 -0700234
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235 setContentView(R.layout.emergency_dialer);
236
Tyler Gunn1acf54a2018-03-28 14:15:34 -0700237 mDigits = (ResizingTextEditText) findViewById(R.id.digits);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238 mDigits.setKeyListener(DialerKeyListener.getInstance());
239 mDigits.setOnClickListener(this);
240 mDigits.setOnKeyListener(this);
241 mDigits.setLongClickable(false);
Hall Liubdc9c882016-05-25 15:25:28 -0700242 mDigits.setInputType(InputType.TYPE_NULL);
Tyler Gunn1acf54a2018-03-28 14:15:34 -0700243 mDefaultDigitsTextSize = mDigits.getScaledTextSize();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244 maybeAddNumberFormatting();
245
Lucas Dupineb9c5702017-05-10 16:57:09 -0700246 mBackgroundGradient = new GradientDrawable(this);
247 Point displaySize = new Point();
248 ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
249 .getDefaultDisplay().getSize(displaySize);
250 mBackgroundGradient.setScreenSize(displaySize.x, displaySize.y);
Chihhang Chuanga26f07b2018-07-02 11:08:50 +0800251 mBackgroundGradient.setAlpha(mAreEmergencyDialerShortcutsEnabled
252 ? BLACK_BACKGROUND_GRADIENT_ALPHA : BACKGROUND_GRADIENT_ALPHA);
Lucas Dupineb9c5702017-05-10 16:57:09 -0700253 getWindow().setBackgroundDrawable(mBackgroundGradient);
254
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255 // Check for the presence of the keypad
256 View view = findViewById(R.id.one);
257 if (view != null) {
258 setupKeypad();
259 }
260
261 mDelete = findViewById(R.id.deleteButton);
262 mDelete.setOnClickListener(this);
263 mDelete.setOnLongClickListener(this);
264
Sai Cheemalapati14462b62014-06-18 13:53:56 -0700265 mDialButton = findViewById(R.id.floating_action_button);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266
267 // Check whether we should show the onscreen "Dial" button and co.
Jonathan Basserie619a4c2015-06-26 14:52:26 -0700268 // Read carrier config through the public API because PhoneGlobals is not available when we
269 // run as a secondary user.
270 CarrierConfigManager configMgr =
271 (CarrierConfigManager) getSystemService(Context.CARRIER_CONFIG_SERVICE);
272 PersistableBundle carrierConfig =
Shishir Agrawald3480e02016-01-25 13:05:49 -0800273 configMgr.getConfigForSubId(SubscriptionManager.getDefaultVoiceSubscriptionId());
Tyler Gunn1acf54a2018-03-28 14:15:34 -0700274
Jonathan Basseri9504c6b2015-06-04 14:23:32 -0700275 if (carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_ONSCREEN_DIAL_BUTTON_BOOL)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 mDialButton.setOnClickListener(this);
277 } else {
278 mDialButton.setVisibility(View.GONE);
279 }
Tyler Gunn1acf54a2018-03-28 14:15:34 -0700280 mIsWfcEmergencyCallingWarningEnabled = carrierConfig.getInt(
281 CarrierConfigManager.KEY_EMERGENCY_NOTIFICATION_DELAY_INT) > -1;
282 maybeShowWfcEmergencyCallingWarning();
283
Adrian Roosc9fdb6c2015-05-25 15:10:21 -0700284 ViewUtil.setupFloatingActionButton(mDialButton, getResources());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285
286 if (icicle != null) {
287 super.onRestoreInstanceState(icicle);
288 }
289
290 // Extract phone number from intent
291 Uri data = getIntent().getData();
Jay Shrauner137458b2014-09-05 14:27:25 -0700292 if (data != null && (PhoneAccount.SCHEME_TEL.equals(data.getScheme()))) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293 String number = PhoneNumberUtils.getNumberFromIntent(getIntent(), this);
294 if (number != null) {
295 mDigits.setText(number);
296 }
297 }
298
299 // if the mToneGenerator creation fails, just continue without it. It is
300 // a local audio signal, and is not as important as the dtmf tone itself.
301 synchronized (mToneGeneratorLock) {
302 if (mToneGenerator == null) {
303 try {
304 mToneGenerator = new ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME);
305 } catch (RuntimeException e) {
306 Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e);
307 mToneGenerator = null;
308 }
309 }
310 }
311
312 final IntentFilter intentFilter = new IntentFilter();
313 intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
314 registerReceiver(mBroadcastReceiver, intentFilter);
315
Adrian Roos1c4b47f2015-04-13 14:53:32 -0700316 mEmergencyActionGroup = (EmergencyActionGroup) findViewById(R.id.emergency_action_group);
Chihhang Chuangd301d9a2018-06-05 15:29:06 +0800317
Chihhang Chuangd301d9a2018-06-05 15:29:06 +0800318 if (mAreEmergencyDialerShortcutsEnabled) {
319 setupEmergencyShortcutsView();
320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321 }
322
323 @Override
324 protected void onDestroy() {
325 super.onDestroy();
326 synchronized (mToneGeneratorLock) {
327 if (mToneGenerator != null) {
328 mToneGenerator.release();
329 mToneGenerator = null;
330 }
331 }
332 unregisterReceiver(mBroadcastReceiver);
333 }
334
335 @Override
336 protected void onRestoreInstanceState(Bundle icicle) {
337 mLastNumber = icicle.getString(LAST_NUMBER);
338 }
339
340 @Override
341 protected void onSaveInstanceState(Bundle outState) {
342 super.onSaveInstanceState(outState);
343 outState.putString(LAST_NUMBER, mLastNumber);
344 }
345
346 /**
347 * Explicitly turn off number formatting, since it gets in the way of the emergency
348 * number detector
349 */
350 protected void maybeAddNumberFormatting() {
351 // Do nothing.
352 }
353
354 @Override
355 protected void onPostCreate(Bundle savedInstanceState) {
356 super.onPostCreate(savedInstanceState);
357
358 // This can't be done in onCreate(), since the auto-restoring of the digits
359 // will play DTMF tones for all the old digits if it is when onRestoreSavedInstanceState()
360 // is called. This method will be called every time the activity is created, and
361 // will always happen after onRestoreSavedInstanceState().
362 mDigits.addTextChangedListener(this);
363 }
364
365 private void setupKeypad() {
366 // Setup the listeners for the buttons
367 for (int id : DIALER_KEYS) {
Yorke Lee23a70732014-08-14 17:12:01 -0700368 final DialpadKeyButton key = (DialpadKeyButton) findViewById(id);
369 key.setOnPressedListener(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 }
371
372 View view = findViewById(R.id.zero);
373 view.setOnLongClickListener(this);
374 }
375
Chihhang Chuangd301d9a2018-06-05 15:29:06 +0800376 @Override
377 public void onBackPressed() {
378 // If emergency dialer shortcut is enabled and Dialpad view is visible, pressing the
Billy Chi9614de82018-06-15 19:00:15 +0800379 // back key will back to display EmergencyShortcutView view.
Chihhang Chuangd301d9a2018-06-05 15:29:06 +0800380 // Otherwise, it would finish the activity.
381 if (mAreEmergencyDialerShortcutsEnabled && mDialpadView != null
382 && mDialpadView.getVisibility() == View.VISIBLE) {
383 switchView(mEmergencyShortcutView, mDialpadView, true);
384 return;
385 }
386 super.onBackPressed();
387 }
388
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389 /**
390 * handle key events
391 */
392 @Override
393 public boolean onKeyDown(int keyCode, KeyEvent event) {
394 switch (keyCode) {
395 // Happen when there's a "Call" hard button.
396 case KeyEvent.KEYCODE_CALL: {
397 if (TextUtils.isEmpty(mDigits.getText().toString())) {
398 // if we are adding a call from the InCallScreen and the phone
399 // number entered is empty, we just close the dialer to expose
400 // the InCallScreen under it.
401 finish();
402 } else {
403 // otherwise, we place the call.
404 placeCall();
405 }
406 return true;
407 }
408 }
409 return super.onKeyDown(keyCode, event);
410 }
411
412 private void keyPressed(int keyCode) {
Yorke Lee116dd072015-08-31 11:38:39 -0700413 mDigits.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
415 mDigits.onKeyDown(keyCode, event);
416 }
417
418 @Override
419 public boolean onKey(View view, int keyCode, KeyEvent event) {
420 switch (view.getId()) {
421 case R.id.digits:
422 // Happen when "Done" button of the IME is pressed. This can happen when this
423 // Activity is forced into landscape mode due to a desk dock.
424 if (keyCode == KeyEvent.KEYCODE_ENTER
425 && event.getAction() == KeyEvent.ACTION_UP) {
426 placeCall();
427 return true;
428 }
429 break;
430 }
431 return false;
432 }
433
434 @Override
Adrian Roos1c4b47f2015-04-13 14:53:32 -0700435 public boolean dispatchTouchEvent(MotionEvent ev) {
Chihhang Chuang4f2b7812018-06-07 16:25:27 +0800436 onPreTouchEvent(ev);
Adrian Roos1c4b47f2015-04-13 14:53:32 -0700437 boolean handled = super.dispatchTouchEvent(ev);
Chihhang Chuang4f2b7812018-06-07 16:25:27 +0800438 onPostTouchEvent(ev);
Adrian Roos1c4b47f2015-04-13 14:53:32 -0700439 return handled;
440 }
441
442 @Override
Chihhang Chuang4f2b7812018-06-07 16:25:27 +0800443 public void onConfirmClick(EmergencyShortcutButton button) {
444 if (button == null) return;
445
446 String phoneNumber = button.getPhoneNumber();
447
448 if (!TextUtils.isEmpty(phoneNumber)) {
Billy Chi9614de82018-06-15 19:00:15 +0800449 if (DBG) Log.d(LOG_TAG, "dial emergency number: " + Rlog.pii(LOG_TAG, phoneNumber));
Chihhang Chuang4f2b7812018-06-07 16:25:27 +0800450 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
451 tm.placeCall(Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null), null);
452 } else {
453 Log.d(LOG_TAG, "emergency number is empty");
454 }
455 }
456
457 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458 public void onClick(View view) {
459 switch (view.getId()) {
Yorke Lee23a70732014-08-14 17:12:01 -0700460 case R.id.deleteButton: {
461 keyPressed(KeyEvent.KEYCODE_DEL);
462 return;
463 }
464 case R.id.floating_action_button: {
Yorke Lee116dd072015-08-31 11:38:39 -0700465 view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Yorke Lee23a70732014-08-14 17:12:01 -0700466 placeCall();
467 return;
468 }
469 case R.id.digits: {
470 if (mDigits.length() != 0) {
471 mDigits.setCursorVisible(true);
472 }
473 return;
474 }
Chihhang Chuangd301d9a2018-06-05 15:29:06 +0800475 case R.id.floating_action_button_dialpad: {
Chihhang Chuanga26f07b2018-07-02 11:08:50 +0800476 mDigits.getText().clear();
Chihhang Chuangd301d9a2018-06-05 15:29:06 +0800477 switchView(mDialpadView, mEmergencyShortcutView, true);
478 return;
479 }
480 case R.id.emergency_info_button: {
481 Intent intent = (Intent) view.getTag(R.id.tag_intent);
482 if (intent != null) {
483 startActivity(intent);
484 }
485 return;
486 }
Yorke Lee23a70732014-08-14 17:12:01 -0700487 }
488 }
489
490 @Override
491 public void onPressed(View view, boolean pressed) {
492 if (!pressed) {
493 return;
494 }
495 switch (view.getId()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700496 case R.id.one: {
497 playTone(ToneGenerator.TONE_DTMF_1);
498 keyPressed(KeyEvent.KEYCODE_1);
499 return;
500 }
501 case R.id.two: {
502 playTone(ToneGenerator.TONE_DTMF_2);
503 keyPressed(KeyEvent.KEYCODE_2);
504 return;
505 }
506 case R.id.three: {
507 playTone(ToneGenerator.TONE_DTMF_3);
508 keyPressed(KeyEvent.KEYCODE_3);
509 return;
510 }
511 case R.id.four: {
512 playTone(ToneGenerator.TONE_DTMF_4);
513 keyPressed(KeyEvent.KEYCODE_4);
514 return;
515 }
516 case R.id.five: {
517 playTone(ToneGenerator.TONE_DTMF_5);
518 keyPressed(KeyEvent.KEYCODE_5);
519 return;
520 }
521 case R.id.six: {
522 playTone(ToneGenerator.TONE_DTMF_6);
523 keyPressed(KeyEvent.KEYCODE_6);
524 return;
525 }
526 case R.id.seven: {
527 playTone(ToneGenerator.TONE_DTMF_7);
528 keyPressed(KeyEvent.KEYCODE_7);
529 return;
530 }
531 case R.id.eight: {
532 playTone(ToneGenerator.TONE_DTMF_8);
533 keyPressed(KeyEvent.KEYCODE_8);
534 return;
535 }
536 case R.id.nine: {
537 playTone(ToneGenerator.TONE_DTMF_9);
538 keyPressed(KeyEvent.KEYCODE_9);
539 return;
540 }
541 case R.id.zero: {
542 playTone(ToneGenerator.TONE_DTMF_0);
543 keyPressed(KeyEvent.KEYCODE_0);
544 return;
545 }
546 case R.id.pound: {
547 playTone(ToneGenerator.TONE_DTMF_P);
548 keyPressed(KeyEvent.KEYCODE_POUND);
549 return;
550 }
551 case R.id.star: {
552 playTone(ToneGenerator.TONE_DTMF_S);
553 keyPressed(KeyEvent.KEYCODE_STAR);
554 return;
555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700556 }
557 }
558
559 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700560 * called for long touch events
561 */
562 @Override
563 public boolean onLongClick(View view) {
564 int id = view.getId();
565 switch (id) {
566 case R.id.deleteButton: {
567 mDigits.getText().clear();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700568 return true;
569 }
570 case R.id.zero: {
Yorke Lee91311662014-10-24 14:50:45 -0700571 removePreviousDigitIfPossible();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700572 keyPressed(KeyEvent.KEYCODE_PLUS);
573 return true;
574 }
575 }
576 return false;
577 }
578
579 @Override
Lucas Dupineb9c5702017-05-10 16:57:09 -0700580 protected void onStart() {
581 super.onStart();
Chihhang Chuanga26f07b2018-07-02 11:08:50 +0800582 // It does not support dark text theme, when emergency dialer shortcuts are enabled.
583 // And set background color to black.
584 if (mAreEmergencyDialerShortcutsEnabled) {
585 mBackgroundGradient.setColors(Color.BLACK, Color.BLACK, false);
586 updateTheme(false);
587 } else {
588 mColorExtractor.addOnColorsChangedListener(this);
589 GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK,
590 ColorExtractor.TYPE_EXTRA_DARK);
591 // Do not animate when view isn't visible yet, just set an initial state.
592 mBackgroundGradient.setColors(lockScreenColors, false);
593 updateTheme(lockScreenColors.supportsDarkText());
594 }
Lucas Dupineb9c5702017-05-10 16:57:09 -0700595 }
596
597 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700598 protected void onResume() {
599 super.onResume();
600
601 // retrieve the DTMF tone play back setting.
602 mDTMFToneEnabled = Settings.System.getInt(getContentResolver(),
603 Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1;
604
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700605 // if the mToneGenerator creation fails, just continue without it. It is
606 // a local audio signal, and is not as important as the dtmf tone itself.
607 synchronized (mToneGeneratorLock) {
608 if (mToneGenerator == null) {
609 try {
610 mToneGenerator = new ToneGenerator(AudioManager.STREAM_DTMF,
611 TONE_RELATIVE_VOLUME);
612 } catch (RuntimeException e) {
613 Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e);
614 mToneGenerator = null;
615 }
616 }
617 }
618
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700619 updateDialAndDeleteButtonStateEnabledAttr();
620 }
621
622 @Override
623 public void onPause() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700624 super.onPause();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700625 }
626
Lucas Dupineb9c5702017-05-10 16:57:09 -0700627 @Override
628 protected void onStop() {
629 super.onStop();
Lucas Dupineb9c5702017-05-10 16:57:09 -0700630 mColorExtractor.removeOnColorsChangedListener(this);
631 }
632
633 /**
634 * Sets theme based on gradient colors
635 * @param supportsDarkText true if gradient supports dark text
636 */
637 private void updateTheme(boolean supportsDarkText) {
638 if (mSupportsDarkText == supportsDarkText) {
639 return;
640 }
641 mSupportsDarkText = supportsDarkText;
642
643 // We can't change themes after inflation, in this case we'll have to recreate
644 // the whole activity.
645 if (mBackgroundGradient != null) {
646 recreate();
647 return;
648 }
649
650 int vis = getWindow().getDecorView().getSystemUiVisibility();
651 if (supportsDarkText) {
652 vis |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
653 vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
654 setTheme(R.style.EmergencyDialerThemeDark);
655 } else {
656 vis &= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
657 vis &= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
658 setTheme(R.style.EmergencyDialerTheme);
659 }
660 getWindow().getDecorView().setSystemUiVisibility(vis);
661 }
662
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700663 /**
664 * place the call, but check to make sure it is a viable number.
665 */
666 private void placeCall() {
667 mLastNumber = mDigits.getText().toString();
Wei Huang6904b142017-04-21 19:06:40 +0900668
669 // Convert into emergency number according to emergency conversion map.
670 // If conversion map is not defined (this is default), this method does
671 // nothing and just returns input number.
672 mLastNumber = PhoneNumberUtils.convertToEmergencyNumber(this, mLastNumber);
673
Yorke Lee36bb2542014-06-05 08:09:52 -0700674 if (PhoneNumberUtils.isLocalEmergencyNumber(this, mLastNumber)) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700675 if (DBG) Log.d(LOG_TAG, "placing call to " + mLastNumber);
676
677 // place the call if it is a valid number
678 if (mLastNumber == null || !TextUtils.isGraphic(mLastNumber)) {
679 // There is no number entered.
680 playTone(ToneGenerator.TONE_PROP_NACK);
681 return;
682 }
Tyler Gunnca7dfef2018-03-27 18:50:05 +0000683 TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE);
684 tm.placeCall(Uri.fromParts(PhoneAccount.SCHEME_TEL, mLastNumber, null), null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700685 } else {
686 if (DBG) Log.d(LOG_TAG, "rejecting bad requested number " + mLastNumber);
687
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700688 showDialog(BAD_EMERGENCY_NUMBER_DIALOG);
689 }
Yorke Lee9b341512014-10-17 11:36:41 -0700690 mDigits.getText().delete(0, mDigits.getText().length());
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700691 }
692
693 /**
694 * Plays the specified tone for TONE_LENGTH_MS milliseconds.
695 *
696 * The tone is played locally, using the audio stream for phone calls.
697 * Tones are played only if the "Audible touch tones" user preference
698 * is checked, and are NOT played if the device is in silent mode.
699 *
700 * @param tone a tone code from {@link ToneGenerator}
701 */
702 void playTone(int tone) {
703 // if local tone playback is disabled, just return.
704 if (!mDTMFToneEnabled) {
705 return;
706 }
707
708 // Also do nothing if the phone is in silent mode.
709 // We need to re-check the ringer mode for *every* playTone()
710 // call, rather than keeping a local flag that's updated in
711 // onResume(), since it's possible to toggle silent mode without
712 // leaving the current activity (via the ENDCALL-longpress menu.)
713 AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
714 int ringerMode = audioManager.getRingerMode();
715 if ((ringerMode == AudioManager.RINGER_MODE_SILENT)
716 || (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
717 return;
718 }
719
720 synchronized (mToneGeneratorLock) {
721 if (mToneGenerator == null) {
722 Log.w(LOG_TAG, "playTone: mToneGenerator == null, tone: " + tone);
723 return;
724 }
725
726 // Start the new tone (will stop any playing tone)
727 mToneGenerator.startTone(tone, TONE_LENGTH_MS);
728 }
729 }
730
731 private CharSequence createErrorMessage(String number) {
732 if (!TextUtils.isEmpty(number)) {
Hall Liudc274312016-03-01 16:34:45 -0800733 String errorString = getString(R.string.dial_emergency_error, number);
734 int startingPosition = errorString.indexOf(number);
735 int endingPosition = startingPosition + number.length();
736 Spannable result = new SpannableString(errorString);
737 PhoneNumberUtils.addTtsSpan(result, startingPosition, endingPosition);
738 return result;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700739 } else {
740 return getText(R.string.dial_emergency_empty_error).toString();
741 }
742 }
743
744 @Override
745 protected Dialog onCreateDialog(int id) {
746 AlertDialog dialog = null;
747 if (id == BAD_EMERGENCY_NUMBER_DIALOG) {
748 // construct dialog
Lucas Dupin0d666f92017-06-01 14:04:48 -0700749 dialog = new AlertDialog.Builder(this, R.style.EmergencyDialerAlertDialogTheme)
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700750 .setTitle(getText(R.string.emergency_enable_radio_dialog_title))
751 .setMessage(createErrorMessage(mLastNumber))
752 .setPositiveButton(R.string.ok, null)
753 .setCancelable(true).create();
754
755 // blur stuff behind the dialog
756 dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Tyler Gunn75638602018-03-29 13:48:29 -0700757 setShowWhenLocked(true);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700758 }
759 return dialog;
760 }
761
762 @Override
763 protected void onPrepareDialog(int id, Dialog dialog) {
764 super.onPrepareDialog(id, dialog);
765 if (id == BAD_EMERGENCY_NUMBER_DIALOG) {
766 AlertDialog alert = (AlertDialog) dialog;
767 alert.setMessage(createErrorMessage(mLastNumber));
768 }
769 }
770
Andrew Leed5631e82014-10-08 16:03:58 -0700771 @Override
772 public boolean onOptionsItemSelected(MenuItem item) {
773 final int itemId = item.getItemId();
774 if (itemId == android.R.id.home) {
775 onBackPressed();
776 return true;
777 }
778 return super.onOptionsItemSelected(item);
779 }
780
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700781 /**
782 * Update the enabledness of the "Dial" and "Backspace" buttons if applicable.
783 */
784 private void updateDialAndDeleteButtonStateEnabledAttr() {
785 final boolean notEmpty = mDigits.length() != 0;
786
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700787 mDelete.setEnabled(notEmpty);
788 }
Yorke Lee91311662014-10-24 14:50:45 -0700789
790 /**
791 * Remove the digit just before the current position. Used by various long pressed callbacks
792 * to remove the digit that was populated as a result of the short click.
793 */
794 private void removePreviousDigitIfPossible() {
795 final int currentPosition = mDigits.getSelectionStart();
796 if (currentPosition > 0) {
797 mDigits.setSelection(currentPosition);
798 mDigits.getText().delete(currentPosition - 1, currentPosition);
799 }
800 }
Ihab Awadf7c1a5a2014-12-08 19:24:23 -0800801
802 /**
803 * Update the text-to-speech annotations in the edit field.
804 */
805 private void updateTtsSpans() {
806 for (Object o : mDigits.getText().getSpans(0, mDigits.getText().length(), TtsSpan.class)) {
807 mDigits.getText().removeSpan(o);
808 }
809 PhoneNumberUtils.ttsSpanAsPhoneNumber(mDigits.getText(), 0, mDigits.getText().length());
810 }
Lucas Dupineb9c5702017-05-10 16:57:09 -0700811
812 @Override
Lucas Dupin94b566f2017-05-28 11:45:52 -0700813 public void onColorsChanged(ColorExtractor extractor, int which) {
Lucas Dupineb9c5702017-05-10 16:57:09 -0700814 if ((which & WallpaperManager.FLAG_LOCK) != 0) {
Lucas Dupin94b566f2017-05-28 11:45:52 -0700815 GradientColors colors = extractor.getColors(WallpaperManager.FLAG_LOCK,
816 ColorExtractor.TYPE_EXTRA_DARK);
Lucas Dupineb9c5702017-05-10 16:57:09 -0700817 mBackgroundGradient.setColors(colors);
818 updateTheme(colors.supportsDarkText());
819 }
820 }
Tyler Gunn1acf54a2018-03-28 14:15:34 -0700821
822 /**
823 * Where a carrier requires a warning that emergency calling is not available while on WFC,
824 * add hint text above the dial pad which warns the user of this case.
825 */
826 private void maybeShowWfcEmergencyCallingWarning() {
827 if (!mIsWfcEmergencyCallingWarningEnabled) {
828 Log.i(LOG_TAG, "maybeShowWfcEmergencyCallingWarning: warning disabled by carrier.");
829 return;
830 }
831
832 // Use an async task rather than calling into Telephony on UI thread.
833 AsyncTask<Void, Void, Boolean> showWfcWarningTask = new AsyncTask<Void, Void, Boolean>() {
834 @Override
835 protected Boolean doInBackground(Void... voids) {
836 TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
837 boolean isWfcAvailable = tm.isWifiCallingAvailable();
838 ServiceState ss = tm.getServiceState();
839 boolean isCellAvailable =
840 ss.getRilVoiceRadioTechnology() != RIL_RADIO_TECHNOLOGY_UNKNOWN;
841 Log.i(LOG_TAG, "showWfcWarningTask: isWfcAvailable=" + isWfcAvailable
842 + " isCellAvailable=" + isCellAvailable
843 + "(rat=" + ss.getRilVoiceRadioTechnology() + ")");
844 return isWfcAvailable && !isCellAvailable;
845 }
846
847 @Override
848 protected void onPostExecute(Boolean result) {
849 if (result.booleanValue()) {
850 Log.i(LOG_TAG, "showWfcWarningTask: showing ecall warning");
851 mDigits.setHint(R.string.dial_emergency_calling_not_available);
852 } else {
853 Log.i(LOG_TAG, "showWfcWarningTask: hiding ecall warning");
854 mDigits.setHint("");
855 }
856 maybeChangeHintSize();
857 }
858 };
859 showWfcWarningTask.execute((Void) null);
860 }
861
862 /**
863 * Where a hint is applied and there are no digits dialed, disable autoresize of the dial digits
864 * edit view and set the font size to a smaller size appropriate for the emergency calling
865 * warning.
866 */
867 private void maybeChangeHintSize() {
868 if (TextUtils.isEmpty(mDigits.getHint())
869 || !TextUtils.isEmpty(mDigits.getText().toString())) {
870 // No hint or there are dialed digits, so use default size.
871 mDigits.setTextSize(TypedValue.COMPLEX_UNIT_SP, mDefaultDigitsTextSize);
872 // By default, the digits view auto-resizes to fit the text it contains, so
873 // enable that now.
874 mDigits.setResizeEnabled(true);
875 Log.i(LOG_TAG, "no hint - setting to " + mDigits.getScaledTextSize());
876 } else {
877 // Hint present and no dialed digits, set custom font size appropriate for the warning.
878 mDigits.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(
879 R.dimen.emergency_call_warning_size));
880 // Since we're populating this with a static text string, disable auto-resize.
881 mDigits.setResizeEnabled(false);
882 Log.i(LOG_TAG, "hint - setting to " + mDigits.getScaledTextSize());
883 }
884 }
Chihhang Chuangd301d9a2018-06-05 15:29:06 +0800885
886 private void setupEmergencyShortcutsView() {
887 mEmergencyShortcutView = findViewById(R.id.emergency_dialer_shortcuts);
888 mDialpadView = findViewById(R.id.emergency_dialer);
889
890 final View dialpadButton = findViewById(R.id.floating_action_button_dialpad);
891 dialpadButton.setOnClickListener(this);
892
893 final View emergencyInfoButton = findViewById(R.id.emergency_info_button);
894 emergencyInfoButton.setOnClickListener(this);
895
896 // EmergencyActionGroup is replaced by EmergencyInfoGroup.
897 mEmergencyActionGroup.setVisibility(View.GONE);
898
899 // Setup dialpad title.
900 final View emergencyDialpadTitle = findViewById(R.id.emergency_dialpad_title_container);
901 emergencyDialpadTitle.setVisibility(View.VISIBLE);
902
Chihhang Chuang4f2b7812018-06-07 16:25:27 +0800903 // TODO: Integrating emergency phone number table will get location information.
904 // Using null to present no location status.
905 setLocationInfo(null);
906
907 mEmergencyShortcutButtonList = new ArrayList<>();
908 setupEmergencyCallShortcutButton();
909
Chihhang Chuangd301d9a2018-06-05 15:29:06 +0800910 switchView(mEmergencyShortcutView, mDialpadView, false);
911 }
912
Chihhang Chuang4f2b7812018-06-07 16:25:27 +0800913 private void setLocationInfo(String country) {
914 final View locationInfo = findViewById(R.id.location_info);
915
916 if (TextUtils.isEmpty(country)) {
917 locationInfo.setVisibility(View.INVISIBLE);
918 } else {
919 final TextView location = (TextView) locationInfo.findViewById(R.id.location_text);
920 location.setText(country);
921 locationInfo.setVisibility(View.VISIBLE);
922 }
923 }
924
925 // TODO: Integrate emergency phone number table.
926 // Using default layout(no location, phone number is 112, description is Emergency,
927 // and icon is cross shape) until integrating emergency phone number table.
928 private void setupEmergencyCallShortcutButton() {
929 final ViewGroup shortcutButtonContainer = findViewById(
930 R.id.emergency_shortcut_buttons_container);
931 shortcutButtonContainer.setClipToOutline(true);
932
933 final EmergencyShortcutButton button =
934 (EmergencyShortcutButton) getLayoutInflater().inflate(
935 R.layout.emergency_shortcut_button,
936 shortcutButtonContainer, false);
937
938 button.setPhoneNumber("112");
939 button.setPhoneDescription("Emergency");
940 button.setPhoneTypeIcon(R.drawable.ic_emergency_number_24);
941 button.setOnConfirmClickListener(this);
942
943 shortcutButtonContainer.addView(button);
944 mEmergencyShortcutButtonList.add(button);
945
946 //Set emergency number title for numerous buttons.
947 if (shortcutButtonContainer.getChildCount() > 1) {
948 final TextView emergencyNumberTitle = findViewById(R.id.emergency_number_title);
949 emergencyNumberTitle.setText(getString(R.string.numerous_emergency_numbers_title));
950 }
951 }
952
953 /**
954 * Called by the activity before a touch event is dispatched to the view hierarchy.
955 */
956 private void onPreTouchEvent(MotionEvent event) {
957 mEmergencyActionGroup.onPreTouchEvent(event);
958
959 if (mEmergencyShortcutButtonList != null) {
960 for (EmergencyShortcutButton button : mEmergencyShortcutButtonList) {
961 button.onPreTouchEvent(event);
962 }
963 }
964 }
965
966 /**
967 * Called by the activity after a touch event is dispatched to the view hierarchy.
968 */
969 private void onPostTouchEvent(MotionEvent event) {
970 mEmergencyActionGroup.onPostTouchEvent(event);
971
972 if (mEmergencyShortcutButtonList != null) {
973 for (EmergencyShortcutButton button : mEmergencyShortcutButtonList) {
974 button.onPostTouchEvent(event);
975 }
976 }
977 }
978
Chihhang Chuangd301d9a2018-06-05 15:29:06 +0800979 /**
980 * Switch two view.
981 *
982 * @param displayView the view would be displayed.
983 * @param hideView the view would be hidden.
984 * @param hasAnimation is {@code true} when the view should be displayed with animation.
985 */
986 private void switchView(View displayView, View hideView, boolean hasAnimation) {
987 if (displayView == null || hideView == null) {
988 return;
989 }
990
991 if (displayView.getVisibility() == View.VISIBLE) {
992 return;
993 }
994
995 if (hasAnimation) {
996 crossfade(hideView, displayView);
997 } else {
998 hideView.setVisibility(View.GONE);
999 displayView.setVisibility(View.VISIBLE);
1000 }
1001 }
1002
1003 /**
1004 * Fade out and fade in animation between two view transition.
1005 */
1006 private void crossfade(View fadeOutView, View fadeInView) {
1007 if (fadeOutView == null || fadeInView == null) {
1008 return;
1009 }
1010 final int shortAnimationDuration = getResources().getInteger(
1011 android.R.integer.config_shortAnimTime);
1012
1013 fadeInView.setAlpha(0f);
1014 fadeInView.setVisibility(View.VISIBLE);
1015
1016 fadeInView.animate()
1017 .alpha(1f)
1018 .setDuration(shortAnimationDuration)
1019 .setListener(null);
1020
1021 fadeOutView.animate()
1022 .alpha(0f)
1023 .setDuration(shortAnimationDuration)
1024 .setListener(new AnimatorListenerAdapter() {
1025 @Override
1026 public void onAnimationEnd(Animator animation) {
1027 fadeOutView.setVisibility(View.GONE);
1028 }
1029 });
1030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001031}