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