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