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