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