Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 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 | |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 19 | import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN; |
| 20 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 21 | import android.animation.Animator; |
| 22 | import android.animation.AnimatorListenerAdapter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 23 | import android.app.Activity; |
| 24 | import android.app.AlertDialog; |
| 25 | import android.app.Dialog; |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 26 | import android.app.WallpaperManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.content.BroadcastReceiver; |
| 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
| 30 | import android.content.IntentFilter; |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 31 | import android.database.DataSetObserver; |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 32 | import android.graphics.Color; |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 33 | import android.graphics.Point; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.media.AudioManager; |
| 35 | import android.media.ToneGenerator; |
| 36 | import android.net.Uri; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 37 | import android.os.AsyncTask; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.os.Bundle; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 39 | import android.os.PersistableBundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.provider.Settings; |
Shaotang Li | 5d906c1 | 2018-07-19 17:32:42 +0800 | [diff] [blame^] | 41 | import android.telecom.ParcelableCallAnalytics; |
Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 42 | import android.telecom.PhoneAccount; |
Tyler Gunn | fa77e20 | 2018-03-23 07:47:00 -0700 | [diff] [blame] | 43 | import android.telecom.TelecomManager; |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 44 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.telephony.PhoneNumberUtils; |
Billy Chi | 17ec228 | 2018-06-15 19:00:15 +0800 | [diff] [blame] | 46 | import android.telephony.Rlog; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 47 | import android.telephony.ServiceState; |
Santos Cordon | e137eed | 2015-06-23 15:34:47 -0700 | [diff] [blame] | 48 | import android.telephony.SubscriptionManager; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 49 | import android.telephony.TelephonyManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.text.Editable; |
Hall Liu | bdc9c88 | 2016-05-25 15:25:28 -0700 | [diff] [blame] | 51 | import android.text.InputType; |
Hall Liu | dc27431 | 2016-03-01 16:34:45 -0800 | [diff] [blame] | 52 | import android.text.Spannable; |
| 53 | import android.text.SpannableString; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.text.TextUtils; |
| 55 | import android.text.TextWatcher; |
| 56 | import android.text.method.DialerKeyListener; |
Ihab Awad | f7c1a5a | 2014-12-08 19:24:23 -0800 | [diff] [blame] | 57 | import android.text.style.TtsSpan; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.util.Log; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 59 | import android.util.TypedValue; |
Yorke Lee | 116dd07 | 2015-08-31 11:38:39 -0700 | [diff] [blame] | 60 | import android.view.HapticFeedbackConstants; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 61 | import android.view.KeyEvent; |
Andrew Lee | d5631e8 | 2014-10-08 16:03:58 -0700 | [diff] [blame] | 62 | import android.view.MenuItem; |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 63 | import android.view.MotionEvent; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.view.View; |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 65 | import android.view.ViewGroup; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | import android.view.WindowManager; |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 67 | import android.widget.TextView; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | |
Lucas Dupin | af9e991 | 2017-06-22 12:39:39 -0700 | [diff] [blame] | 69 | import com.android.internal.colorextraction.ColorExtractor; |
| 70 | import com.android.internal.colorextraction.ColorExtractor.GradientColors; |
| 71 | import com.android.internal.colorextraction.drawable.GradientDrawable; |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 72 | import com.android.phone.common.dialpad.DialpadKeyButton; |
Sai Cheemalapati | 14462b6 | 2014-06-18 13:53:56 -0700 | [diff] [blame] | 73 | import com.android.phone.common.util.ViewUtil; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 74 | import com.android.phone.common.widget.ResizingTextEditText; |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 75 | import com.android.phone.ecc.CountryEccInfo; |
| 76 | import com.android.phone.ecc.EccInfoHelper; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 77 | |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 78 | import java.util.ArrayList; |
| 79 | import java.util.List; |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 80 | import java.util.Locale; |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 81 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 82 | /** |
| 83 | * EmergencyDialer is a special dialer that is used ONLY for dialing emergency calls. |
| 84 | * |
| 85 | * It's a simplified version of the regular dialer (i.e. the TwelveKeyDialer |
| 86 | * activity from apps/Contacts) that: |
| 87 | * 1. Allows ONLY emergency calls to be dialed |
| 88 | * 2. Disallows voicemail functionality |
| 89 | * 3. Uses the FLAG_SHOW_WHEN_LOCKED window manager flag to allow this |
| 90 | * activity to stay in front of the keyguard. |
| 91 | * |
| 92 | * TODO: Even though this is an ultra-simplified version of the normal |
| 93 | * dialer, there's still lots of code duplication between this class and |
| 94 | * the TwelveKeyDialer class from apps/Contacts. Could the common code be |
| 95 | * moved into a shared base class that would live in the framework? |
| 96 | * Or could we figure out some way to move *this* class into apps/Contacts |
| 97 | * also? |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 98 | * |
| 99 | * TODO: Implement emergency dialer shortcut. |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 100 | * Emergency dialer shortcut offer a local emergency number list. Directly clicking a call button |
| 101 | * to place an emergency phone call without entering numbers from dialpad. |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 102 | * TODO item: |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 103 | * 1.integrate emergency phone number table. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | */ |
| 105 | public class EmergencyDialer extends Activity implements View.OnClickListener, |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 106 | View.OnLongClickListener, View.OnKeyListener, TextWatcher, |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 107 | DialpadKeyButton.OnPressedListener, ColorExtractor.OnColorsChangedListener, |
| 108 | EmergencyShortcutButton.OnConfirmClickListener { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 109 | // Keys used with onSaveInstanceState(). |
| 110 | private static final String LAST_NUMBER = "lastNumber"; |
| 111 | |
| 112 | // Intent action for this activity. |
| 113 | public static final String ACTION_DIAL = "com.android.phone.EmergencyDialer.DIAL"; |
| 114 | |
| 115 | // List of dialer button IDs. |
| 116 | private static final int[] DIALER_KEYS = new int[] { |
| 117 | R.id.one, R.id.two, R.id.three, |
| 118 | R.id.four, R.id.five, R.id.six, |
| 119 | R.id.seven, R.id.eight, R.id.nine, |
| 120 | R.id.star, R.id.zero, R.id.pound }; |
| 121 | |
| 122 | // Debug constants. |
| 123 | private static final boolean DBG = false; |
| 124 | private static final String LOG_TAG = "EmergencyDialer"; |
| 125 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | /** The length of DTMF tones in milliseconds */ |
| 127 | private static final int TONE_LENGTH_MS = 150; |
| 128 | |
| 129 | /** The DTMF tone volume relative to other sounds in the stream */ |
| 130 | private static final int TONE_RELATIVE_VOLUME = 80; |
| 131 | |
| 132 | /** Stream type used to play the DTMF tones off call, and mapped to the volume control keys */ |
| 133 | private static final int DIAL_TONE_STREAM_TYPE = AudioManager.STREAM_DTMF; |
| 134 | |
| 135 | private static final int BAD_EMERGENCY_NUMBER_DIALOG = 0; |
| 136 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 137 | /** 90% opacity, different from other gradients **/ |
| 138 | private static final int BACKGROUND_GRADIENT_ALPHA = 230; |
| 139 | |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 140 | /** 85% opacity for black background **/ |
| 141 | private static final int BLACK_BACKGROUND_GRADIENT_ALPHA = 217; |
| 142 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 143 | /** Size limit of emergency shortcut buttons container. **/ |
| 144 | private static final int SHORTCUT_SIZE_LIMIT = 3; |
| 145 | |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 146 | ResizingTextEditText mDigits; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 147 | private View mDialButton; |
| 148 | private View mDelete; |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 149 | private View mEmergencyShortcutView; |
| 150 | private View mDialpadView; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 151 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 152 | private EccInfoHelper mEccInfoHelper; |
| 153 | |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 154 | private List<EmergencyShortcutButton> mEmergencyShortcutButtonList; |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 155 | private EccShortcutAdapter mShortcutAdapter; |
| 156 | private DataSetObserver mShortcutDataSetObserver = null; |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 157 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 158 | private ToneGenerator mToneGenerator; |
| 159 | private Object mToneGeneratorLock = new Object(); |
| 160 | |
| 161 | // determines if we want to playback local DTMF tones. |
| 162 | private boolean mDTMFToneEnabled; |
| 163 | |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 164 | private EmergencyActionGroup mEmergencyActionGroup; |
| 165 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | // close activity when screen turns off |
| 167 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 168 | @Override |
| 169 | public void onReceive(Context context, Intent intent) { |
| 170 | if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) { |
Adrian Roos | 061c723 | 2015-04-21 12:37:07 -0700 | [diff] [blame] | 171 | finishAndRemoveTask(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | }; |
| 175 | |
| 176 | private String mLastNumber; // last number we tried to dial. Used to restore error dialog. |
| 177 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 178 | // Background gradient |
| 179 | private ColorExtractor mColorExtractor; |
| 180 | private GradientDrawable mBackgroundGradient; |
| 181 | private boolean mSupportsDarkText; |
| 182 | |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 183 | private boolean mIsWfcEmergencyCallingWarningEnabled; |
| 184 | private float mDefaultDigitsTextSize; |
| 185 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 186 | private boolean mAreEmergencyDialerShortcutsEnabled; |
| 187 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 188 | @Override |
| 189 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 190 | // Do nothing |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public void onTextChanged(CharSequence input, int start, int before, int changeCount) { |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 195 | maybeChangeHintSize(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | @Override |
| 199 | public void afterTextChanged(Editable input) { |
| 200 | // Check for special sequences, in particular the "**04" or "**05" |
| 201 | // sequences that allow you to enter PIN or PUK-related codes. |
| 202 | // |
| 203 | // But note we *don't* allow most other special sequences here, |
| 204 | // like "secret codes" (*#*#<code>#*#*) or IMEI display ("*#06#"), |
| 205 | // since those shouldn't be available if the device is locked. |
| 206 | // |
| 207 | // So we call SpecialCharSequenceMgr.handleCharsForLockedDevice() |
| 208 | // here, not the regular handleChars() method. |
| 209 | if (SpecialCharSequenceMgr.handleCharsForLockedDevice(this, input.toString(), this)) { |
| 210 | // A special sequence was entered, clear the digits |
| 211 | mDigits.getText().clear(); |
| 212 | } |
| 213 | |
| 214 | updateDialAndDeleteButtonStateEnabledAttr(); |
Ihab Awad | f7c1a5a | 2014-12-08 19:24:23 -0800 | [diff] [blame] | 215 | updateTtsSpans(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | @Override |
| 219 | protected void onCreate(Bundle icicle) { |
| 220 | super.onCreate(icicle); |
| 221 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 222 | // Allow this activity to be displayed in front of the keyguard / lockscreen. |
Mengjun Leng | b9d14f0 | 2017-10-31 14:28:14 +0800 | [diff] [blame] | 223 | setShowWhenLocked(true); |
| 224 | // Allow turning screen on |
| 225 | setTurnScreenOn(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 226 | |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 227 | mAreEmergencyDialerShortcutsEnabled = Settings.Global.getInt(getContentResolver(), |
| 228 | Settings.Global.FASTER_EMERGENCY_PHONE_CALL_ENABLED, 0) != 0; |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 229 | Log.d(LOG_TAG, "Enable emergency dialer shortcut: " |
| 230 | + mAreEmergencyDialerShortcutsEnabled); |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 231 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 232 | mColorExtractor = new ColorExtractor(this); |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 233 | |
| 234 | // It does not support dark text theme, when emergency dialer shortcuts are enabled. |
| 235 | // And the background color is black with 85% opacity. |
| 236 | if (mAreEmergencyDialerShortcutsEnabled) { |
| 237 | updateTheme(false); |
| 238 | } else { |
| 239 | GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK, |
| 240 | ColorExtractor.TYPE_EXTRA_DARK); |
| 241 | updateTheme(lockScreenColors.supportsDarkText()); |
| 242 | } |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 243 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 244 | setContentView(R.layout.emergency_dialer); |
| 245 | |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 246 | mDigits = (ResizingTextEditText) findViewById(R.id.digits); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 247 | mDigits.setKeyListener(DialerKeyListener.getInstance()); |
| 248 | mDigits.setOnClickListener(this); |
| 249 | mDigits.setOnKeyListener(this); |
| 250 | mDigits.setLongClickable(false); |
Hall Liu | bdc9c88 | 2016-05-25 15:25:28 -0700 | [diff] [blame] | 251 | mDigits.setInputType(InputType.TYPE_NULL); |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 252 | mDefaultDigitsTextSize = mDigits.getScaledTextSize(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 253 | maybeAddNumberFormatting(); |
| 254 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 255 | mBackgroundGradient = new GradientDrawable(this); |
| 256 | Point displaySize = new Point(); |
| 257 | ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) |
| 258 | .getDefaultDisplay().getSize(displaySize); |
| 259 | mBackgroundGradient.setScreenSize(displaySize.x, displaySize.y); |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 260 | mBackgroundGradient.setAlpha(mAreEmergencyDialerShortcutsEnabled |
| 261 | ? BLACK_BACKGROUND_GRADIENT_ALPHA : BACKGROUND_GRADIENT_ALPHA); |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 262 | getWindow().setBackgroundDrawable(mBackgroundGradient); |
| 263 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 264 | // Check for the presence of the keypad |
| 265 | View view = findViewById(R.id.one); |
| 266 | if (view != null) { |
| 267 | setupKeypad(); |
| 268 | } |
| 269 | |
| 270 | mDelete = findViewById(R.id.deleteButton); |
| 271 | mDelete.setOnClickListener(this); |
| 272 | mDelete.setOnLongClickListener(this); |
| 273 | |
Sai Cheemalapati | 14462b6 | 2014-06-18 13:53:56 -0700 | [diff] [blame] | 274 | mDialButton = findViewById(R.id.floating_action_button); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 275 | |
| 276 | // Check whether we should show the onscreen "Dial" button and co. |
Jonathan Basseri | e619a4c | 2015-06-26 14:52:26 -0700 | [diff] [blame] | 277 | // Read carrier config through the public API because PhoneGlobals is not available when we |
| 278 | // run as a secondary user. |
| 279 | CarrierConfigManager configMgr = |
| 280 | (CarrierConfigManager) getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 281 | PersistableBundle carrierConfig = |
Shishir Agrawal | d3480e0 | 2016-01-25 13:05:49 -0800 | [diff] [blame] | 282 | configMgr.getConfigForSubId(SubscriptionManager.getDefaultVoiceSubscriptionId()); |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 283 | |
Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 284 | if (carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_ONSCREEN_DIAL_BUTTON_BOOL)) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 285 | mDialButton.setOnClickListener(this); |
| 286 | } else { |
| 287 | mDialButton.setVisibility(View.GONE); |
| 288 | } |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 289 | mIsWfcEmergencyCallingWarningEnabled = carrierConfig.getInt( |
| 290 | CarrierConfigManager.KEY_EMERGENCY_NOTIFICATION_DELAY_INT) > -1; |
| 291 | maybeShowWfcEmergencyCallingWarning(); |
| 292 | |
Adrian Roos | c9fdb6c | 2015-05-25 15:10:21 -0700 | [diff] [blame] | 293 | ViewUtil.setupFloatingActionButton(mDialButton, getResources()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 294 | |
| 295 | if (icicle != null) { |
| 296 | super.onRestoreInstanceState(icicle); |
| 297 | } |
| 298 | |
| 299 | // Extract phone number from intent |
| 300 | Uri data = getIntent().getData(); |
Jay Shrauner | 137458b | 2014-09-05 14:27:25 -0700 | [diff] [blame] | 301 | if (data != null && (PhoneAccount.SCHEME_TEL.equals(data.getScheme()))) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 302 | String number = PhoneNumberUtils.getNumberFromIntent(getIntent(), this); |
| 303 | if (number != null) { |
| 304 | mDigits.setText(number); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | // if the mToneGenerator creation fails, just continue without it. It is |
| 309 | // a local audio signal, and is not as important as the dtmf tone itself. |
| 310 | synchronized (mToneGeneratorLock) { |
| 311 | if (mToneGenerator == null) { |
| 312 | try { |
| 313 | mToneGenerator = new ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME); |
| 314 | } catch (RuntimeException e) { |
| 315 | Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e); |
| 316 | mToneGenerator = null; |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | final IntentFilter intentFilter = new IntentFilter(); |
| 322 | intentFilter.addAction(Intent.ACTION_SCREEN_OFF); |
| 323 | registerReceiver(mBroadcastReceiver, intentFilter); |
| 324 | |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 325 | mEmergencyActionGroup = (EmergencyActionGroup) findViewById(R.id.emergency_action_group); |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 326 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 327 | if (mAreEmergencyDialerShortcutsEnabled) { |
| 328 | setupEmergencyShortcutsView(); |
| 329 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | @Override |
| 333 | protected void onDestroy() { |
| 334 | super.onDestroy(); |
| 335 | synchronized (mToneGeneratorLock) { |
| 336 | if (mToneGenerator != null) { |
| 337 | mToneGenerator.release(); |
| 338 | mToneGenerator = null; |
| 339 | } |
| 340 | } |
| 341 | unregisterReceiver(mBroadcastReceiver); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 342 | if (mShortcutAdapter != null && mShortcutDataSetObserver != null) { |
| 343 | mShortcutAdapter.unregisterDataSetObserver(mShortcutDataSetObserver); |
| 344 | mShortcutDataSetObserver = null; |
| 345 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | @Override |
| 349 | protected void onRestoreInstanceState(Bundle icicle) { |
| 350 | mLastNumber = icicle.getString(LAST_NUMBER); |
| 351 | } |
| 352 | |
| 353 | @Override |
| 354 | protected void onSaveInstanceState(Bundle outState) { |
| 355 | super.onSaveInstanceState(outState); |
| 356 | outState.putString(LAST_NUMBER, mLastNumber); |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Explicitly turn off number formatting, since it gets in the way of the emergency |
| 361 | * number detector |
| 362 | */ |
| 363 | protected void maybeAddNumberFormatting() { |
| 364 | // Do nothing. |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | protected void onPostCreate(Bundle savedInstanceState) { |
| 369 | super.onPostCreate(savedInstanceState); |
| 370 | |
| 371 | // This can't be done in onCreate(), since the auto-restoring of the digits |
| 372 | // will play DTMF tones for all the old digits if it is when onRestoreSavedInstanceState() |
| 373 | // is called. This method will be called every time the activity is created, and |
| 374 | // will always happen after onRestoreSavedInstanceState(). |
| 375 | mDigits.addTextChangedListener(this); |
| 376 | } |
| 377 | |
| 378 | private void setupKeypad() { |
| 379 | // Setup the listeners for the buttons |
| 380 | for (int id : DIALER_KEYS) { |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 381 | final DialpadKeyButton key = (DialpadKeyButton) findViewById(id); |
| 382 | key.setOnPressedListener(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | View view = findViewById(R.id.zero); |
| 386 | view.setOnLongClickListener(this); |
| 387 | } |
| 388 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 389 | @Override |
| 390 | public void onBackPressed() { |
| 391 | // If emergency dialer shortcut is enabled and Dialpad view is visible, pressing the |
Billy Chi | 17ec228 | 2018-06-15 19:00:15 +0800 | [diff] [blame] | 392 | // back key will back to display EmergencyShortcutView view. |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 393 | // Otherwise, it would finish the activity. |
| 394 | if (mAreEmergencyDialerShortcutsEnabled && mDialpadView != null |
| 395 | && mDialpadView.getVisibility() == View.VISIBLE) { |
| 396 | switchView(mEmergencyShortcutView, mDialpadView, true); |
| 397 | return; |
| 398 | } |
| 399 | super.onBackPressed(); |
| 400 | } |
| 401 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 402 | /** |
| 403 | * handle key events |
| 404 | */ |
| 405 | @Override |
| 406 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 407 | switch (keyCode) { |
| 408 | // Happen when there's a "Call" hard button. |
| 409 | case KeyEvent.KEYCODE_CALL: { |
| 410 | if (TextUtils.isEmpty(mDigits.getText().toString())) { |
| 411 | // if we are adding a call from the InCallScreen and the phone |
| 412 | // number entered is empty, we just close the dialer to expose |
| 413 | // the InCallScreen under it. |
| 414 | finish(); |
| 415 | } else { |
| 416 | // otherwise, we place the call. |
| 417 | placeCall(); |
| 418 | } |
| 419 | return true; |
| 420 | } |
| 421 | } |
| 422 | return super.onKeyDown(keyCode, event); |
| 423 | } |
| 424 | |
| 425 | private void keyPressed(int keyCode) { |
Yorke Lee | 116dd07 | 2015-08-31 11:38:39 -0700 | [diff] [blame] | 426 | mDigits.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode); |
| 428 | mDigits.onKeyDown(keyCode, event); |
| 429 | } |
| 430 | |
| 431 | @Override |
| 432 | public boolean onKey(View view, int keyCode, KeyEvent event) { |
| 433 | switch (view.getId()) { |
| 434 | case R.id.digits: |
| 435 | // Happen when "Done" button of the IME is pressed. This can happen when this |
| 436 | // Activity is forced into landscape mode due to a desk dock. |
| 437 | if (keyCode == KeyEvent.KEYCODE_ENTER |
| 438 | && event.getAction() == KeyEvent.ACTION_UP) { |
| 439 | placeCall(); |
| 440 | return true; |
| 441 | } |
| 442 | break; |
| 443 | } |
| 444 | return false; |
| 445 | } |
| 446 | |
| 447 | @Override |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 448 | public boolean dispatchTouchEvent(MotionEvent ev) { |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 449 | onPreTouchEvent(ev); |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 450 | boolean handled = super.dispatchTouchEvent(ev); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 451 | onPostTouchEvent(ev); |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 452 | return handled; |
| 453 | } |
| 454 | |
| 455 | @Override |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 456 | public void onConfirmClick(EmergencyShortcutButton button) { |
| 457 | if (button == null) return; |
| 458 | |
| 459 | String phoneNumber = button.getPhoneNumber(); |
| 460 | |
| 461 | if (!TextUtils.isEmpty(phoneNumber)) { |
Billy Chi | 17ec228 | 2018-06-15 19:00:15 +0800 | [diff] [blame] | 462 | if (DBG) Log.d(LOG_TAG, "dial emergency number: " + Rlog.pii(LOG_TAG, phoneNumber)); |
Shaotang Li | 5d906c1 | 2018-07-19 17:32:42 +0800 | [diff] [blame^] | 463 | Bundle extras = new Bundle(); |
| 464 | extras.putInt(TelecomManager.EXTRA_CALL_SOURCE, |
| 465 | ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_SHORTCUT); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 466 | TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE); |
Shaotang Li | 5d906c1 | 2018-07-19 17:32:42 +0800 | [diff] [blame^] | 467 | tm.placeCall(Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null), extras); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 468 | } else { |
| 469 | Log.d(LOG_TAG, "emergency number is empty"); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 474 | public void onClick(View view) { |
| 475 | switch (view.getId()) { |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 476 | case R.id.deleteButton: { |
| 477 | keyPressed(KeyEvent.KEYCODE_DEL); |
| 478 | return; |
| 479 | } |
| 480 | case R.id.floating_action_button: { |
Yorke Lee | 116dd07 | 2015-08-31 11:38:39 -0700 | [diff] [blame] | 481 | view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 482 | placeCall(); |
| 483 | return; |
| 484 | } |
| 485 | case R.id.digits: { |
| 486 | if (mDigits.length() != 0) { |
| 487 | mDigits.setCursorVisible(true); |
| 488 | } |
| 489 | return; |
| 490 | } |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 491 | case R.id.floating_action_button_dialpad: { |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 492 | mDigits.getText().clear(); |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 493 | switchView(mDialpadView, mEmergencyShortcutView, true); |
| 494 | return; |
| 495 | } |
| 496 | case R.id.emergency_info_button: { |
| 497 | Intent intent = (Intent) view.getTag(R.id.tag_intent); |
| 498 | if (intent != null) { |
| 499 | startActivity(intent); |
| 500 | } |
| 501 | return; |
| 502 | } |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | |
| 506 | @Override |
| 507 | public void onPressed(View view, boolean pressed) { |
| 508 | if (!pressed) { |
| 509 | return; |
| 510 | } |
| 511 | switch (view.getId()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 512 | case R.id.one: { |
| 513 | playTone(ToneGenerator.TONE_DTMF_1); |
| 514 | keyPressed(KeyEvent.KEYCODE_1); |
| 515 | return; |
| 516 | } |
| 517 | case R.id.two: { |
| 518 | playTone(ToneGenerator.TONE_DTMF_2); |
| 519 | keyPressed(KeyEvent.KEYCODE_2); |
| 520 | return; |
| 521 | } |
| 522 | case R.id.three: { |
| 523 | playTone(ToneGenerator.TONE_DTMF_3); |
| 524 | keyPressed(KeyEvent.KEYCODE_3); |
| 525 | return; |
| 526 | } |
| 527 | case R.id.four: { |
| 528 | playTone(ToneGenerator.TONE_DTMF_4); |
| 529 | keyPressed(KeyEvent.KEYCODE_4); |
| 530 | return; |
| 531 | } |
| 532 | case R.id.five: { |
| 533 | playTone(ToneGenerator.TONE_DTMF_5); |
| 534 | keyPressed(KeyEvent.KEYCODE_5); |
| 535 | return; |
| 536 | } |
| 537 | case R.id.six: { |
| 538 | playTone(ToneGenerator.TONE_DTMF_6); |
| 539 | keyPressed(KeyEvent.KEYCODE_6); |
| 540 | return; |
| 541 | } |
| 542 | case R.id.seven: { |
| 543 | playTone(ToneGenerator.TONE_DTMF_7); |
| 544 | keyPressed(KeyEvent.KEYCODE_7); |
| 545 | return; |
| 546 | } |
| 547 | case R.id.eight: { |
| 548 | playTone(ToneGenerator.TONE_DTMF_8); |
| 549 | keyPressed(KeyEvent.KEYCODE_8); |
| 550 | return; |
| 551 | } |
| 552 | case R.id.nine: { |
| 553 | playTone(ToneGenerator.TONE_DTMF_9); |
| 554 | keyPressed(KeyEvent.KEYCODE_9); |
| 555 | return; |
| 556 | } |
| 557 | case R.id.zero: { |
| 558 | playTone(ToneGenerator.TONE_DTMF_0); |
| 559 | keyPressed(KeyEvent.KEYCODE_0); |
| 560 | return; |
| 561 | } |
| 562 | case R.id.pound: { |
| 563 | playTone(ToneGenerator.TONE_DTMF_P); |
| 564 | keyPressed(KeyEvent.KEYCODE_POUND); |
| 565 | return; |
| 566 | } |
| 567 | case R.id.star: { |
| 568 | playTone(ToneGenerator.TONE_DTMF_S); |
| 569 | keyPressed(KeyEvent.KEYCODE_STAR); |
| 570 | return; |
| 571 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | |
| 575 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 576 | * called for long touch events |
| 577 | */ |
| 578 | @Override |
| 579 | public boolean onLongClick(View view) { |
| 580 | int id = view.getId(); |
| 581 | switch (id) { |
| 582 | case R.id.deleteButton: { |
| 583 | mDigits.getText().clear(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 584 | return true; |
| 585 | } |
| 586 | case R.id.zero: { |
Yorke Lee | 9131166 | 2014-10-24 14:50:45 -0700 | [diff] [blame] | 587 | removePreviousDigitIfPossible(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 588 | keyPressed(KeyEvent.KEYCODE_PLUS); |
| 589 | return true; |
| 590 | } |
| 591 | } |
| 592 | return false; |
| 593 | } |
| 594 | |
| 595 | @Override |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 596 | protected void onStart() { |
| 597 | super.onStart(); |
Chihhang Chuang | f8d3300 | 2018-07-02 11:08:50 +0800 | [diff] [blame] | 598 | // It does not support dark text theme, when emergency dialer shortcuts are enabled. |
| 599 | // And set background color to black. |
| 600 | if (mAreEmergencyDialerShortcutsEnabled) { |
| 601 | mBackgroundGradient.setColors(Color.BLACK, Color.BLACK, false); |
| 602 | updateTheme(false); |
| 603 | } else { |
| 604 | mColorExtractor.addOnColorsChangedListener(this); |
| 605 | GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK, |
| 606 | ColorExtractor.TYPE_EXTRA_DARK); |
| 607 | // Do not animate when view isn't visible yet, just set an initial state. |
| 608 | mBackgroundGradient.setColors(lockScreenColors, false); |
| 609 | updateTheme(lockScreenColors.supportsDarkText()); |
| 610 | } |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 611 | |
| 612 | if (mAreEmergencyDialerShortcutsEnabled && mEccInfoHelper != null) { |
| 613 | final Context context = this; |
| 614 | mEccInfoHelper.getCountryEccInfoAsync(context, |
| 615 | new EccInfoHelper.CountryEccInfoResultCallback() { |
| 616 | @Override |
| 617 | public void onSuccess(String iso, CountryEccInfo countryEccInfo) { |
| 618 | Log.d(LOG_TAG, "Retrieve ECC info success, country ISO: " |
| 619 | + Rlog.pii(LOG_TAG, iso)); |
| 620 | updateLocationAndEccInfo(iso, countryEccInfo); |
| 621 | } |
| 622 | |
| 623 | @Override |
| 624 | public void onDetectCountryFailed() { |
| 625 | Log.w(LOG_TAG, "Cannot detect current country."); |
| 626 | updateLocationAndEccInfo(null, null); |
| 627 | } |
| 628 | |
| 629 | @Override |
| 630 | public void onRetrieveCountryEccInfoFailed(String iso) { |
| 631 | Log.w(LOG_TAG, "Retrieve ECC info failed, country ISO: " |
| 632 | + Rlog.pii(LOG_TAG, iso)); |
| 633 | updateLocationAndEccInfo(iso, null); |
| 634 | } |
| 635 | }); |
| 636 | } |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 640 | protected void onResume() { |
| 641 | super.onResume(); |
| 642 | |
| 643 | // retrieve the DTMF tone play back setting. |
| 644 | mDTMFToneEnabled = Settings.System.getInt(getContentResolver(), |
| 645 | Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1; |
| 646 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 647 | // if the mToneGenerator creation fails, just continue without it. It is |
| 648 | // a local audio signal, and is not as important as the dtmf tone itself. |
| 649 | synchronized (mToneGeneratorLock) { |
| 650 | if (mToneGenerator == null) { |
| 651 | try { |
| 652 | mToneGenerator = new ToneGenerator(AudioManager.STREAM_DTMF, |
| 653 | TONE_RELATIVE_VOLUME); |
| 654 | } catch (RuntimeException e) { |
| 655 | Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e); |
| 656 | mToneGenerator = null; |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 661 | updateDialAndDeleteButtonStateEnabledAttr(); |
| 662 | } |
| 663 | |
| 664 | @Override |
| 665 | public void onPause() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 666 | super.onPause(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 669 | @Override |
| 670 | protected void onStop() { |
| 671 | super.onStop(); |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 672 | mColorExtractor.removeOnColorsChangedListener(this); |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * Sets theme based on gradient colors |
| 677 | * @param supportsDarkText true if gradient supports dark text |
| 678 | */ |
| 679 | private void updateTheme(boolean supportsDarkText) { |
| 680 | if (mSupportsDarkText == supportsDarkText) { |
| 681 | return; |
| 682 | } |
| 683 | mSupportsDarkText = supportsDarkText; |
| 684 | |
| 685 | // We can't change themes after inflation, in this case we'll have to recreate |
| 686 | // the whole activity. |
| 687 | if (mBackgroundGradient != null) { |
| 688 | recreate(); |
| 689 | return; |
| 690 | } |
| 691 | |
| 692 | int vis = getWindow().getDecorView().getSystemUiVisibility(); |
| 693 | if (supportsDarkText) { |
| 694 | vis |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 695 | vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 696 | setTheme(R.style.EmergencyDialerThemeDark); |
| 697 | } else { |
| 698 | vis &= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 699 | vis &= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 700 | setTheme(R.style.EmergencyDialerTheme); |
| 701 | } |
| 702 | getWindow().getDecorView().setSystemUiVisibility(vis); |
| 703 | } |
| 704 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 705 | /** |
| 706 | * place the call, but check to make sure it is a viable number. |
| 707 | */ |
| 708 | private void placeCall() { |
| 709 | mLastNumber = mDigits.getText().toString(); |
Wei Huang | 6904b14 | 2017-04-21 19:06:40 +0900 | [diff] [blame] | 710 | |
| 711 | // Convert into emergency number according to emergency conversion map. |
| 712 | // If conversion map is not defined (this is default), this method does |
| 713 | // nothing and just returns input number. |
| 714 | mLastNumber = PhoneNumberUtils.convertToEmergencyNumber(this, mLastNumber); |
| 715 | |
Yorke Lee | 36bb254 | 2014-06-05 08:09:52 -0700 | [diff] [blame] | 716 | if (PhoneNumberUtils.isLocalEmergencyNumber(this, mLastNumber)) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 717 | if (DBG) Log.d(LOG_TAG, "placing call to " + mLastNumber); |
| 718 | |
| 719 | // place the call if it is a valid number |
| 720 | if (mLastNumber == null || !TextUtils.isGraphic(mLastNumber)) { |
| 721 | // There is no number entered. |
| 722 | playTone(ToneGenerator.TONE_PROP_NACK); |
| 723 | return; |
| 724 | } |
Shaotang Li | 5d906c1 | 2018-07-19 17:32:42 +0800 | [diff] [blame^] | 725 | Bundle extras = new Bundle(); |
| 726 | extras.putInt(TelecomManager.EXTRA_CALL_SOURCE, |
| 727 | ParcelableCallAnalytics.CALL_SOURCE_EMERGENCY_DIALPAD); |
Tyler Gunn | fa77e20 | 2018-03-23 07:47:00 -0700 | [diff] [blame] | 728 | TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE); |
Shaotang Li | 5d906c1 | 2018-07-19 17:32:42 +0800 | [diff] [blame^] | 729 | tm.placeCall(Uri.fromParts(PhoneAccount.SCHEME_TEL, mLastNumber, null), extras); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 730 | } else { |
| 731 | if (DBG) Log.d(LOG_TAG, "rejecting bad requested number " + mLastNumber); |
| 732 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 733 | showDialog(BAD_EMERGENCY_NUMBER_DIALOG); |
| 734 | } |
Yorke Lee | 9b34151 | 2014-10-17 11:36:41 -0700 | [diff] [blame] | 735 | mDigits.getText().delete(0, mDigits.getText().length()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /** |
| 739 | * Plays the specified tone for TONE_LENGTH_MS milliseconds. |
| 740 | * |
| 741 | * The tone is played locally, using the audio stream for phone calls. |
| 742 | * Tones are played only if the "Audible touch tones" user preference |
| 743 | * is checked, and are NOT played if the device is in silent mode. |
| 744 | * |
| 745 | * @param tone a tone code from {@link ToneGenerator} |
| 746 | */ |
| 747 | void playTone(int tone) { |
| 748 | // if local tone playback is disabled, just return. |
| 749 | if (!mDTMFToneEnabled) { |
| 750 | return; |
| 751 | } |
| 752 | |
| 753 | // Also do nothing if the phone is in silent mode. |
| 754 | // We need to re-check the ringer mode for *every* playTone() |
| 755 | // call, rather than keeping a local flag that's updated in |
| 756 | // onResume(), since it's possible to toggle silent mode without |
| 757 | // leaving the current activity (via the ENDCALL-longpress menu.) |
| 758 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 759 | int ringerMode = audioManager.getRingerMode(); |
| 760 | if ((ringerMode == AudioManager.RINGER_MODE_SILENT) |
| 761 | || (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) { |
| 762 | return; |
| 763 | } |
| 764 | |
| 765 | synchronized (mToneGeneratorLock) { |
| 766 | if (mToneGenerator == null) { |
| 767 | Log.w(LOG_TAG, "playTone: mToneGenerator == null, tone: " + tone); |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | // Start the new tone (will stop any playing tone) |
| 772 | mToneGenerator.startTone(tone, TONE_LENGTH_MS); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | private CharSequence createErrorMessage(String number) { |
| 777 | if (!TextUtils.isEmpty(number)) { |
Hall Liu | dc27431 | 2016-03-01 16:34:45 -0800 | [diff] [blame] | 778 | String errorString = getString(R.string.dial_emergency_error, number); |
| 779 | int startingPosition = errorString.indexOf(number); |
| 780 | int endingPosition = startingPosition + number.length(); |
| 781 | Spannable result = new SpannableString(errorString); |
| 782 | PhoneNumberUtils.addTtsSpan(result, startingPosition, endingPosition); |
| 783 | return result; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 784 | } else { |
| 785 | return getText(R.string.dial_emergency_empty_error).toString(); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | @Override |
| 790 | protected Dialog onCreateDialog(int id) { |
| 791 | AlertDialog dialog = null; |
| 792 | if (id == BAD_EMERGENCY_NUMBER_DIALOG) { |
| 793 | // construct dialog |
Lucas Dupin | 0d666f9 | 2017-06-01 14:04:48 -0700 | [diff] [blame] | 794 | dialog = new AlertDialog.Builder(this, R.style.EmergencyDialerAlertDialogTheme) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 795 | .setTitle(getText(R.string.emergency_enable_radio_dialog_title)) |
| 796 | .setMessage(createErrorMessage(mLastNumber)) |
| 797 | .setPositiveButton(R.string.ok, null) |
| 798 | .setCancelable(true).create(); |
| 799 | |
| 800 | // blur stuff behind the dialog |
| 801 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
Tyler Gunn | cd6a1a9 | 2018-03-29 13:48:29 -0700 | [diff] [blame] | 802 | setShowWhenLocked(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 803 | } |
| 804 | return dialog; |
| 805 | } |
| 806 | |
| 807 | @Override |
| 808 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 809 | super.onPrepareDialog(id, dialog); |
| 810 | if (id == BAD_EMERGENCY_NUMBER_DIALOG) { |
| 811 | AlertDialog alert = (AlertDialog) dialog; |
| 812 | alert.setMessage(createErrorMessage(mLastNumber)); |
| 813 | } |
| 814 | } |
| 815 | |
Andrew Lee | d5631e8 | 2014-10-08 16:03:58 -0700 | [diff] [blame] | 816 | @Override |
| 817 | public boolean onOptionsItemSelected(MenuItem item) { |
| 818 | final int itemId = item.getItemId(); |
| 819 | if (itemId == android.R.id.home) { |
| 820 | onBackPressed(); |
| 821 | return true; |
| 822 | } |
| 823 | return super.onOptionsItemSelected(item); |
| 824 | } |
| 825 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 826 | /** |
| 827 | * Update the enabledness of the "Dial" and "Backspace" buttons if applicable. |
| 828 | */ |
| 829 | private void updateDialAndDeleteButtonStateEnabledAttr() { |
| 830 | final boolean notEmpty = mDigits.length() != 0; |
| 831 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 832 | mDelete.setEnabled(notEmpty); |
| 833 | } |
Yorke Lee | 9131166 | 2014-10-24 14:50:45 -0700 | [diff] [blame] | 834 | |
| 835 | /** |
| 836 | * Remove the digit just before the current position. Used by various long pressed callbacks |
| 837 | * to remove the digit that was populated as a result of the short click. |
| 838 | */ |
| 839 | private void removePreviousDigitIfPossible() { |
| 840 | final int currentPosition = mDigits.getSelectionStart(); |
| 841 | if (currentPosition > 0) { |
| 842 | mDigits.setSelection(currentPosition); |
| 843 | mDigits.getText().delete(currentPosition - 1, currentPosition); |
| 844 | } |
| 845 | } |
Ihab Awad | f7c1a5a | 2014-12-08 19:24:23 -0800 | [diff] [blame] | 846 | |
| 847 | /** |
| 848 | * Update the text-to-speech annotations in the edit field. |
| 849 | */ |
| 850 | private void updateTtsSpans() { |
| 851 | for (Object o : mDigits.getText().getSpans(0, mDigits.getText().length(), TtsSpan.class)) { |
| 852 | mDigits.getText().removeSpan(o); |
| 853 | } |
| 854 | PhoneNumberUtils.ttsSpanAsPhoneNumber(mDigits.getText(), 0, mDigits.getText().length()); |
| 855 | } |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 856 | |
| 857 | @Override |
Lucas Dupin | 94b566f | 2017-05-28 11:45:52 -0700 | [diff] [blame] | 858 | public void onColorsChanged(ColorExtractor extractor, int which) { |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 859 | if ((which & WallpaperManager.FLAG_LOCK) != 0) { |
Lucas Dupin | 94b566f | 2017-05-28 11:45:52 -0700 | [diff] [blame] | 860 | GradientColors colors = extractor.getColors(WallpaperManager.FLAG_LOCK, |
| 861 | ColorExtractor.TYPE_EXTRA_DARK); |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 862 | mBackgroundGradient.setColors(colors); |
| 863 | updateTheme(colors.supportsDarkText()); |
| 864 | } |
| 865 | } |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 866 | |
| 867 | /** |
| 868 | * Where a carrier requires a warning that emergency calling is not available while on WFC, |
| 869 | * add hint text above the dial pad which warns the user of this case. |
| 870 | */ |
| 871 | private void maybeShowWfcEmergencyCallingWarning() { |
| 872 | if (!mIsWfcEmergencyCallingWarningEnabled) { |
| 873 | Log.i(LOG_TAG, "maybeShowWfcEmergencyCallingWarning: warning disabled by carrier."); |
| 874 | return; |
| 875 | } |
| 876 | |
| 877 | // Use an async task rather than calling into Telephony on UI thread. |
| 878 | AsyncTask<Void, Void, Boolean> showWfcWarningTask = new AsyncTask<Void, Void, Boolean>() { |
| 879 | @Override |
| 880 | protected Boolean doInBackground(Void... voids) { |
| 881 | TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); |
| 882 | boolean isWfcAvailable = tm.isWifiCallingAvailable(); |
| 883 | ServiceState ss = tm.getServiceState(); |
| 884 | boolean isCellAvailable = |
| 885 | ss.getRilVoiceRadioTechnology() != RIL_RADIO_TECHNOLOGY_UNKNOWN; |
| 886 | Log.i(LOG_TAG, "showWfcWarningTask: isWfcAvailable=" + isWfcAvailable |
| 887 | + " isCellAvailable=" + isCellAvailable |
| 888 | + "(rat=" + ss.getRilVoiceRadioTechnology() + ")"); |
| 889 | return isWfcAvailable && !isCellAvailable; |
| 890 | } |
| 891 | |
| 892 | @Override |
| 893 | protected void onPostExecute(Boolean result) { |
| 894 | if (result.booleanValue()) { |
| 895 | Log.i(LOG_TAG, "showWfcWarningTask: showing ecall warning"); |
| 896 | mDigits.setHint(R.string.dial_emergency_calling_not_available); |
| 897 | } else { |
| 898 | Log.i(LOG_TAG, "showWfcWarningTask: hiding ecall warning"); |
| 899 | mDigits.setHint(""); |
| 900 | } |
| 901 | maybeChangeHintSize(); |
| 902 | } |
| 903 | }; |
| 904 | showWfcWarningTask.execute((Void) null); |
| 905 | } |
| 906 | |
| 907 | /** |
| 908 | * Where a hint is applied and there are no digits dialed, disable autoresize of the dial digits |
| 909 | * edit view and set the font size to a smaller size appropriate for the emergency calling |
| 910 | * warning. |
| 911 | */ |
| 912 | private void maybeChangeHintSize() { |
| 913 | if (TextUtils.isEmpty(mDigits.getHint()) |
| 914 | || !TextUtils.isEmpty(mDigits.getText().toString())) { |
| 915 | // No hint or there are dialed digits, so use default size. |
| 916 | mDigits.setTextSize(TypedValue.COMPLEX_UNIT_SP, mDefaultDigitsTextSize); |
| 917 | // By default, the digits view auto-resizes to fit the text it contains, so |
| 918 | // enable that now. |
| 919 | mDigits.setResizeEnabled(true); |
| 920 | Log.i(LOG_TAG, "no hint - setting to " + mDigits.getScaledTextSize()); |
| 921 | } else { |
| 922 | // Hint present and no dialed digits, set custom font size appropriate for the warning. |
| 923 | mDigits.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize( |
| 924 | R.dimen.emergency_call_warning_size)); |
| 925 | // Since we're populating this with a static text string, disable auto-resize. |
| 926 | mDigits.setResizeEnabled(false); |
| 927 | Log.i(LOG_TAG, "hint - setting to " + mDigits.getScaledTextSize()); |
| 928 | } |
| 929 | } |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 930 | |
| 931 | private void setupEmergencyShortcutsView() { |
| 932 | mEmergencyShortcutView = findViewById(R.id.emergency_dialer_shortcuts); |
| 933 | mDialpadView = findViewById(R.id.emergency_dialer); |
| 934 | |
| 935 | final View dialpadButton = findViewById(R.id.floating_action_button_dialpad); |
| 936 | dialpadButton.setOnClickListener(this); |
| 937 | |
| 938 | final View emergencyInfoButton = findViewById(R.id.emergency_info_button); |
| 939 | emergencyInfoButton.setOnClickListener(this); |
| 940 | |
| 941 | // EmergencyActionGroup is replaced by EmergencyInfoGroup. |
| 942 | mEmergencyActionGroup.setVisibility(View.GONE); |
| 943 | |
| 944 | // Setup dialpad title. |
| 945 | final View emergencyDialpadTitle = findViewById(R.id.emergency_dialpad_title_container); |
| 946 | emergencyDialpadTitle.setVisibility(View.VISIBLE); |
| 947 | |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 948 | mEmergencyShortcutButtonList = new ArrayList<>(); |
| 949 | setupEmergencyCallShortcutButton(); |
| 950 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 951 | updateLocationAndEccInfo(null, null); |
| 952 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 953 | switchView(mEmergencyShortcutView, mDialpadView, false); |
| 954 | } |
| 955 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 956 | private void setLocationInfo(String countryIso) { |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 957 | final View locationInfo = findViewById(R.id.location_info); |
| 958 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 959 | String countryName = null; |
| 960 | if (!TextUtils.isEmpty(countryIso)) { |
| 961 | Locale locale = Locale.getDefault(); |
| 962 | countryName = new Locale(locale.getLanguage(), countryIso, locale.getVariant()) |
| 963 | .getDisplayCountry(); |
| 964 | } |
| 965 | if (TextUtils.isEmpty(countryName)) { |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 966 | locationInfo.setVisibility(View.INVISIBLE); |
| 967 | } else { |
| 968 | final TextView location = (TextView) locationInfo.findViewById(R.id.location_text); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 969 | location.setText(countryName); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 970 | locationInfo.setVisibility(View.VISIBLE); |
| 971 | } |
| 972 | } |
| 973 | |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 974 | private void setupEmergencyCallShortcutButton() { |
| 975 | final ViewGroup shortcutButtonContainer = findViewById( |
| 976 | R.id.emergency_shortcut_buttons_container); |
| 977 | shortcutButtonContainer.setClipToOutline(true); |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 978 | final TextView emergencyNumberTitle = findViewById(R.id.emergency_number_title); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 979 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 980 | mShortcutAdapter = new EccShortcutAdapter(this) { |
| 981 | @Override |
| 982 | public View inflateView(View convertView, ViewGroup parent, CharSequence number, |
| 983 | CharSequence description, int iconRes) { |
| 984 | EmergencyShortcutButton button = (EmergencyShortcutButton) getLayoutInflater() |
| 985 | .inflate(R.layout.emergency_shortcut_button, parent, false); |
| 986 | button.setPhoneNumber(number); |
| 987 | button.setPhoneDescription(description); |
| 988 | button.setPhoneTypeIcon(iconRes); |
| 989 | button.setOnConfirmClickListener(EmergencyDialer.this); |
| 990 | return button; |
| 991 | } |
| 992 | }; |
| 993 | mShortcutDataSetObserver = new DataSetObserver() { |
| 994 | @Override |
| 995 | public void onChanged() { |
| 996 | super.onChanged(); |
| 997 | updateLayout(); |
| 998 | } |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 999 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1000 | @Override |
| 1001 | public void onInvalidated() { |
| 1002 | super.onInvalidated(); |
| 1003 | updateLayout(); |
| 1004 | } |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1005 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1006 | private void updateLayout() { |
| 1007 | // clear previous added buttons |
| 1008 | shortcutButtonContainer.removeAllViews(); |
| 1009 | mEmergencyShortcutButtonList.clear(); |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1010 | |
CY Cheng | 9a69c18 | 2018-06-15 21:20:10 +0800 | [diff] [blame] | 1011 | for (int i = 0; i < mShortcutAdapter.getCount() && i < SHORTCUT_SIZE_LIMIT; ++i) { |
| 1012 | EmergencyShortcutButton button = (EmergencyShortcutButton) |
| 1013 | mShortcutAdapter.getView(i, null, shortcutButtonContainer); |
| 1014 | mEmergencyShortcutButtonList.add(button); |
| 1015 | shortcutButtonContainer.addView(button); |
| 1016 | } |
| 1017 | |
| 1018 | // update emergency numbers title for numerous buttons. |
| 1019 | if (mEmergencyShortcutButtonList.size() > 1) { |
| 1020 | emergencyNumberTitle.setText(getString( |
| 1021 | R.string.numerous_emergency_numbers_title)); |
| 1022 | } else { |
| 1023 | emergencyNumberTitle.setText(getText(R.string.single_emergency_number_title)); |
| 1024 | } |
| 1025 | } |
| 1026 | }; |
| 1027 | mShortcutAdapter.registerDataSetObserver(mShortcutDataSetObserver); |
| 1028 | } |
| 1029 | |
| 1030 | private void updateLocationAndEccInfo(String iso, CountryEccInfo countryEccInfo) { |
| 1031 | if (!isFinishing() && !isDestroyed()) { |
| 1032 | setLocationInfo(iso); |
| 1033 | if (mShortcutAdapter != null) { |
| 1034 | mShortcutAdapter.updateCountryEccInfo(this, countryEccInfo); |
| 1035 | } |
Chihhang Chuang | 92cfe51 | 2018-06-07 16:25:27 +0800 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | /** |
| 1040 | * Called by the activity before a touch event is dispatched to the view hierarchy. |
| 1041 | */ |
| 1042 | private void onPreTouchEvent(MotionEvent event) { |
| 1043 | mEmergencyActionGroup.onPreTouchEvent(event); |
| 1044 | |
| 1045 | if (mEmergencyShortcutButtonList != null) { |
| 1046 | for (EmergencyShortcutButton button : mEmergencyShortcutButtonList) { |
| 1047 | button.onPreTouchEvent(event); |
| 1048 | } |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | /** |
| 1053 | * Called by the activity after a touch event is dispatched to the view hierarchy. |
| 1054 | */ |
| 1055 | private void onPostTouchEvent(MotionEvent event) { |
| 1056 | mEmergencyActionGroup.onPostTouchEvent(event); |
| 1057 | |
| 1058 | if (mEmergencyShortcutButtonList != null) { |
| 1059 | for (EmergencyShortcutButton button : mEmergencyShortcutButtonList) { |
| 1060 | button.onPostTouchEvent(event); |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | |
Chihhang Chuang | f264cfb | 2018-06-05 15:29:06 +0800 | [diff] [blame] | 1065 | /** |
| 1066 | * Switch two view. |
| 1067 | * |
| 1068 | * @param displayView the view would be displayed. |
| 1069 | * @param hideView the view would be hidden. |
| 1070 | * @param hasAnimation is {@code true} when the view should be displayed with animation. |
| 1071 | */ |
| 1072 | private void switchView(View displayView, View hideView, boolean hasAnimation) { |
| 1073 | if (displayView == null || hideView == null) { |
| 1074 | return; |
| 1075 | } |
| 1076 | |
| 1077 | if (displayView.getVisibility() == View.VISIBLE) { |
| 1078 | return; |
| 1079 | } |
| 1080 | |
| 1081 | if (hasAnimation) { |
| 1082 | crossfade(hideView, displayView); |
| 1083 | } else { |
| 1084 | hideView.setVisibility(View.GONE); |
| 1085 | displayView.setVisibility(View.VISIBLE); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | /** |
| 1090 | * Fade out and fade in animation between two view transition. |
| 1091 | */ |
| 1092 | private void crossfade(View fadeOutView, View fadeInView) { |
| 1093 | if (fadeOutView == null || fadeInView == null) { |
| 1094 | return; |
| 1095 | } |
| 1096 | final int shortAnimationDuration = getResources().getInteger( |
| 1097 | android.R.integer.config_shortAnimTime); |
| 1098 | |
| 1099 | fadeInView.setAlpha(0f); |
| 1100 | fadeInView.setVisibility(View.VISIBLE); |
| 1101 | |
| 1102 | fadeInView.animate() |
| 1103 | .alpha(1f) |
| 1104 | .setDuration(shortAnimationDuration) |
| 1105 | .setListener(null); |
| 1106 | |
| 1107 | fadeOutView.animate() |
| 1108 | .alpha(0f) |
| 1109 | .setDuration(shortAnimationDuration) |
| 1110 | .setListener(new AnimatorListenerAdapter() { |
| 1111 | @Override |
| 1112 | public void onAnimationEnd(Animator animation) { |
| 1113 | fadeOutView.setVisibility(View.GONE); |
| 1114 | } |
| 1115 | }); |
| 1116 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1117 | } |