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