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