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