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 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 21 | import android.app.Activity; |
| 22 | import android.app.AlertDialog; |
| 23 | import android.app.Dialog; |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 24 | import android.app.WallpaperManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 25 | import android.content.BroadcastReceiver; |
| 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
| 28 | import android.content.IntentFilter; |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 29 | import android.graphics.Point; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.media.AudioManager; |
| 31 | import android.media.ToneGenerator; |
| 32 | import android.net.Uri; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 33 | import android.os.AsyncTask; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 34 | import android.os.Bundle; |
Jonathan Basseri | c31f1f3 | 2015-05-12 10:13:03 -0700 | [diff] [blame] | 35 | import android.os.PersistableBundle; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.provider.Settings; |
Tyler Gunn | 4d45d1c | 2014-09-12 22:17:53 -0700 | [diff] [blame] | 37 | import android.telecom.PhoneAccount; |
Tyler Gunn | fa77e20 | 2018-03-23 07:47:00 -0700 | [diff] [blame] | 38 | import android.telecom.TelecomManager; |
Jonathan Basseri | 3649bdb | 2015-04-30 22:39:11 -0700 | [diff] [blame] | 39 | import android.telephony.CarrierConfigManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.telephony.PhoneNumberUtils; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 41 | import android.telephony.ServiceState; |
Santos Cordon | e137eed | 2015-06-23 15:34:47 -0700 | [diff] [blame] | 42 | import android.telephony.SubscriptionManager; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 43 | import android.telephony.TelephonyManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.text.Editable; |
Hall Liu | bdc9c88 | 2016-05-25 15:25:28 -0700 | [diff] [blame] | 45 | import android.text.InputType; |
Hall Liu | dc27431 | 2016-03-01 16:34:45 -0800 | [diff] [blame] | 46 | import android.text.Spannable; |
| 47 | import android.text.SpannableString; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 48 | import android.text.TextUtils; |
| 49 | import android.text.TextWatcher; |
| 50 | import android.text.method.DialerKeyListener; |
Ihab Awad | f7c1a5a | 2014-12-08 19:24:23 -0800 | [diff] [blame] | 51 | import android.text.style.TtsSpan; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.util.Log; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 53 | import android.util.TypedValue; |
Yorke Lee | 116dd07 | 2015-08-31 11:38:39 -0700 | [diff] [blame] | 54 | import android.view.HapticFeedbackConstants; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.view.KeyEvent; |
Andrew Lee | d5631e8 | 2014-10-08 16:03:58 -0700 | [diff] [blame] | 56 | import android.view.MenuItem; |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 57 | import android.view.MotionEvent; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.view.View; |
| 59 | import android.view.WindowManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | |
Lucas Dupin | af9e991 | 2017-06-22 12:39:39 -0700 | [diff] [blame] | 61 | import com.android.internal.colorextraction.ColorExtractor; |
| 62 | import com.android.internal.colorextraction.ColorExtractor.GradientColors; |
| 63 | import com.android.internal.colorextraction.drawable.GradientDrawable; |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 64 | import com.android.phone.common.dialpad.DialpadKeyButton; |
Sai Cheemalapati | 14462b6 | 2014-06-18 13:53:56 -0700 | [diff] [blame] | 65 | import com.android.phone.common.util.ViewUtil; |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 66 | import com.android.phone.common.widget.ResizingTextEditText; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 67 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 68 | /** |
| 69 | * EmergencyDialer is a special dialer that is used ONLY for dialing emergency calls. |
| 70 | * |
| 71 | * It's a simplified version of the regular dialer (i.e. the TwelveKeyDialer |
| 72 | * activity from apps/Contacts) that: |
| 73 | * 1. Allows ONLY emergency calls to be dialed |
| 74 | * 2. Disallows voicemail functionality |
| 75 | * 3. Uses the FLAG_SHOW_WHEN_LOCKED window manager flag to allow this |
| 76 | * activity to stay in front of the keyguard. |
| 77 | * |
| 78 | * TODO: Even though this is an ultra-simplified version of the normal |
| 79 | * dialer, there's still lots of code duplication between this class and |
| 80 | * the TwelveKeyDialer class from apps/Contacts. Could the common code be |
| 81 | * moved into a shared base class that would live in the framework? |
| 82 | * Or could we figure out some way to move *this* class into apps/Contacts |
| 83 | * also? |
| 84 | */ |
| 85 | public class EmergencyDialer extends Activity implements View.OnClickListener, |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 86 | View.OnLongClickListener, View.OnKeyListener, TextWatcher, |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 87 | DialpadKeyButton.OnPressedListener, ColorExtractor.OnColorsChangedListener { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 88 | // Keys used with onSaveInstanceState(). |
| 89 | private static final String LAST_NUMBER = "lastNumber"; |
| 90 | |
| 91 | // Intent action for this activity. |
| 92 | public static final String ACTION_DIAL = "com.android.phone.EmergencyDialer.DIAL"; |
| 93 | |
| 94 | // List of dialer button IDs. |
| 95 | private static final int[] DIALER_KEYS = new int[] { |
| 96 | R.id.one, R.id.two, R.id.three, |
| 97 | R.id.four, R.id.five, R.id.six, |
| 98 | R.id.seven, R.id.eight, R.id.nine, |
| 99 | R.id.star, R.id.zero, R.id.pound }; |
| 100 | |
| 101 | // Debug constants. |
| 102 | private static final boolean DBG = false; |
| 103 | private static final String LOG_TAG = "EmergencyDialer"; |
| 104 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 105 | /** The length of DTMF tones in milliseconds */ |
| 106 | private static final int TONE_LENGTH_MS = 150; |
| 107 | |
| 108 | /** The DTMF tone volume relative to other sounds in the stream */ |
| 109 | private static final int TONE_RELATIVE_VOLUME = 80; |
| 110 | |
| 111 | /** Stream type used to play the DTMF tones off call, and mapped to the volume control keys */ |
| 112 | private static final int DIAL_TONE_STREAM_TYPE = AudioManager.STREAM_DTMF; |
| 113 | |
| 114 | private static final int BAD_EMERGENCY_NUMBER_DIALOG = 0; |
| 115 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 116 | /** 90% opacity, different from other gradients **/ |
| 117 | private static final int BACKGROUND_GRADIENT_ALPHA = 230; |
| 118 | |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 119 | ResizingTextEditText mDigits; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 120 | private View mDialButton; |
| 121 | private View mDelete; |
| 122 | |
| 123 | private ToneGenerator mToneGenerator; |
| 124 | private Object mToneGeneratorLock = new Object(); |
| 125 | |
| 126 | // determines if we want to playback local DTMF tones. |
| 127 | private boolean mDTMFToneEnabled; |
| 128 | |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 129 | private EmergencyActionGroup mEmergencyActionGroup; |
| 130 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | // close activity when screen turns off |
| 132 | private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 133 | @Override |
| 134 | public void onReceive(Context context, Intent intent) { |
| 135 | if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) { |
Adrian Roos | 061c723 | 2015-04-21 12:37:07 -0700 | [diff] [blame] | 136 | finishAndRemoveTask(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | }; |
| 140 | |
| 141 | private String mLastNumber; // last number we tried to dial. Used to restore error dialog. |
| 142 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 143 | // Background gradient |
| 144 | private ColorExtractor mColorExtractor; |
| 145 | private GradientDrawable mBackgroundGradient; |
| 146 | private boolean mSupportsDarkText; |
| 147 | |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 148 | private boolean mIsWfcEmergencyCallingWarningEnabled; |
| 149 | private float mDefaultDigitsTextSize; |
| 150 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 151 | @Override |
| 152 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 153 | // Do nothing |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public void onTextChanged(CharSequence input, int start, int before, int changeCount) { |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 158 | maybeChangeHintSize(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public void afterTextChanged(Editable input) { |
| 163 | // Check for special sequences, in particular the "**04" or "**05" |
| 164 | // sequences that allow you to enter PIN or PUK-related codes. |
| 165 | // |
| 166 | // But note we *don't* allow most other special sequences here, |
| 167 | // like "secret codes" (*#*#<code>#*#*) or IMEI display ("*#06#"), |
| 168 | // since those shouldn't be available if the device is locked. |
| 169 | // |
| 170 | // So we call SpecialCharSequenceMgr.handleCharsForLockedDevice() |
| 171 | // here, not the regular handleChars() method. |
| 172 | if (SpecialCharSequenceMgr.handleCharsForLockedDevice(this, input.toString(), this)) { |
| 173 | // A special sequence was entered, clear the digits |
| 174 | mDigits.getText().clear(); |
| 175 | } |
| 176 | |
| 177 | updateDialAndDeleteButtonStateEnabledAttr(); |
Ihab Awad | f7c1a5a | 2014-12-08 19:24:23 -0800 | [diff] [blame] | 178 | updateTtsSpans(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | @Override |
| 182 | protected void onCreate(Bundle icicle) { |
| 183 | super.onCreate(icicle); |
| 184 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | // Allow this activity to be displayed in front of the keyguard / lockscreen. |
Mengjun Leng | b9d14f0 | 2017-10-31 14:28:14 +0800 | [diff] [blame^] | 186 | setShowWhenLocked(true); |
| 187 | // Allow turning screen on |
| 188 | setTurnScreenOn(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 189 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 190 | mColorExtractor = new ColorExtractor(this); |
Lucas Dupin | 94b566f | 2017-05-28 11:45:52 -0700 | [diff] [blame] | 191 | GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK, |
| 192 | ColorExtractor.TYPE_EXTRA_DARK); |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 193 | updateTheme(lockScreenColors.supportsDarkText()); |
| 194 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 195 | setContentView(R.layout.emergency_dialer); |
| 196 | |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 197 | mDigits = (ResizingTextEditText) findViewById(R.id.digits); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | mDigits.setKeyListener(DialerKeyListener.getInstance()); |
| 199 | mDigits.setOnClickListener(this); |
| 200 | mDigits.setOnKeyListener(this); |
| 201 | mDigits.setLongClickable(false); |
Hall Liu | bdc9c88 | 2016-05-25 15:25:28 -0700 | [diff] [blame] | 202 | mDigits.setInputType(InputType.TYPE_NULL); |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 203 | mDefaultDigitsTextSize = mDigits.getScaledTextSize(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 204 | maybeAddNumberFormatting(); |
| 205 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 206 | mBackgroundGradient = new GradientDrawable(this); |
| 207 | Point displaySize = new Point(); |
| 208 | ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) |
| 209 | .getDefaultDisplay().getSize(displaySize); |
| 210 | mBackgroundGradient.setScreenSize(displaySize.x, displaySize.y); |
| 211 | mBackgroundGradient.setAlpha(BACKGROUND_GRADIENT_ALPHA); |
| 212 | getWindow().setBackgroundDrawable(mBackgroundGradient); |
| 213 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 214 | // Check for the presence of the keypad |
| 215 | View view = findViewById(R.id.one); |
| 216 | if (view != null) { |
| 217 | setupKeypad(); |
| 218 | } |
| 219 | |
| 220 | mDelete = findViewById(R.id.deleteButton); |
| 221 | mDelete.setOnClickListener(this); |
| 222 | mDelete.setOnLongClickListener(this); |
| 223 | |
Sai Cheemalapati | 14462b6 | 2014-06-18 13:53:56 -0700 | [diff] [blame] | 224 | mDialButton = findViewById(R.id.floating_action_button); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 225 | |
| 226 | // Check whether we should show the onscreen "Dial" button and co. |
Jonathan Basseri | e619a4c | 2015-06-26 14:52:26 -0700 | [diff] [blame] | 227 | // Read carrier config through the public API because PhoneGlobals is not available when we |
| 228 | // run as a secondary user. |
| 229 | CarrierConfigManager configMgr = |
| 230 | (CarrierConfigManager) getSystemService(Context.CARRIER_CONFIG_SERVICE); |
| 231 | PersistableBundle carrierConfig = |
Shishir Agrawal | d3480e0 | 2016-01-25 13:05:49 -0800 | [diff] [blame] | 232 | configMgr.getConfigForSubId(SubscriptionManager.getDefaultVoiceSubscriptionId()); |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 233 | |
Jonathan Basseri | 9504c6b | 2015-06-04 14:23:32 -0700 | [diff] [blame] | 234 | if (carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_ONSCREEN_DIAL_BUTTON_BOOL)) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 235 | mDialButton.setOnClickListener(this); |
| 236 | } else { |
| 237 | mDialButton.setVisibility(View.GONE); |
| 238 | } |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 239 | mIsWfcEmergencyCallingWarningEnabled = carrierConfig.getInt( |
| 240 | CarrierConfigManager.KEY_EMERGENCY_NOTIFICATION_DELAY_INT) > -1; |
| 241 | maybeShowWfcEmergencyCallingWarning(); |
| 242 | |
Adrian Roos | c9fdb6c | 2015-05-25 15:10:21 -0700 | [diff] [blame] | 243 | ViewUtil.setupFloatingActionButton(mDialButton, getResources()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 244 | |
| 245 | if (icicle != null) { |
| 246 | super.onRestoreInstanceState(icicle); |
| 247 | } |
| 248 | |
| 249 | // Extract phone number from intent |
| 250 | Uri data = getIntent().getData(); |
Jay Shrauner | 137458b | 2014-09-05 14:27:25 -0700 | [diff] [blame] | 251 | if (data != null && (PhoneAccount.SCHEME_TEL.equals(data.getScheme()))) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 252 | String number = PhoneNumberUtils.getNumberFromIntent(getIntent(), this); |
| 253 | if (number != null) { |
| 254 | mDigits.setText(number); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | // if the mToneGenerator creation fails, just continue without it. It is |
| 259 | // a local audio signal, and is not as important as the dtmf tone itself. |
| 260 | synchronized (mToneGeneratorLock) { |
| 261 | if (mToneGenerator == null) { |
| 262 | try { |
| 263 | mToneGenerator = new ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME); |
| 264 | } catch (RuntimeException e) { |
| 265 | Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e); |
| 266 | mToneGenerator = null; |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | final IntentFilter intentFilter = new IntentFilter(); |
| 272 | intentFilter.addAction(Intent.ACTION_SCREEN_OFF); |
| 273 | registerReceiver(mBroadcastReceiver, intentFilter); |
| 274 | |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 275 | mEmergencyActionGroup = (EmergencyActionGroup) findViewById(R.id.emergency_action_group); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | @Override |
| 279 | protected void onDestroy() { |
| 280 | super.onDestroy(); |
| 281 | synchronized (mToneGeneratorLock) { |
| 282 | if (mToneGenerator != null) { |
| 283 | mToneGenerator.release(); |
| 284 | mToneGenerator = null; |
| 285 | } |
| 286 | } |
| 287 | unregisterReceiver(mBroadcastReceiver); |
| 288 | } |
| 289 | |
| 290 | @Override |
| 291 | protected void onRestoreInstanceState(Bundle icicle) { |
| 292 | mLastNumber = icicle.getString(LAST_NUMBER); |
| 293 | } |
| 294 | |
| 295 | @Override |
| 296 | protected void onSaveInstanceState(Bundle outState) { |
| 297 | super.onSaveInstanceState(outState); |
| 298 | outState.putString(LAST_NUMBER, mLastNumber); |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Explicitly turn off number formatting, since it gets in the way of the emergency |
| 303 | * number detector |
| 304 | */ |
| 305 | protected void maybeAddNumberFormatting() { |
| 306 | // Do nothing. |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | protected void onPostCreate(Bundle savedInstanceState) { |
| 311 | super.onPostCreate(savedInstanceState); |
| 312 | |
| 313 | // This can't be done in onCreate(), since the auto-restoring of the digits |
| 314 | // will play DTMF tones for all the old digits if it is when onRestoreSavedInstanceState() |
| 315 | // is called. This method will be called every time the activity is created, and |
| 316 | // will always happen after onRestoreSavedInstanceState(). |
| 317 | mDigits.addTextChangedListener(this); |
| 318 | } |
| 319 | |
| 320 | private void setupKeypad() { |
| 321 | // Setup the listeners for the buttons |
| 322 | for (int id : DIALER_KEYS) { |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 323 | final DialpadKeyButton key = (DialpadKeyButton) findViewById(id); |
| 324 | key.setOnPressedListener(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | View view = findViewById(R.id.zero); |
| 328 | view.setOnLongClickListener(this); |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * handle key events |
| 333 | */ |
| 334 | @Override |
| 335 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 336 | switch (keyCode) { |
| 337 | // Happen when there's a "Call" hard button. |
| 338 | case KeyEvent.KEYCODE_CALL: { |
| 339 | if (TextUtils.isEmpty(mDigits.getText().toString())) { |
| 340 | // if we are adding a call from the InCallScreen and the phone |
| 341 | // number entered is empty, we just close the dialer to expose |
| 342 | // the InCallScreen under it. |
| 343 | finish(); |
| 344 | } else { |
| 345 | // otherwise, we place the call. |
| 346 | placeCall(); |
| 347 | } |
| 348 | return true; |
| 349 | } |
| 350 | } |
| 351 | return super.onKeyDown(keyCode, event); |
| 352 | } |
| 353 | |
| 354 | private void keyPressed(int keyCode) { |
Yorke Lee | 116dd07 | 2015-08-31 11:38:39 -0700 | [diff] [blame] | 355 | mDigits.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode); |
| 357 | mDigits.onKeyDown(keyCode, event); |
| 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public boolean onKey(View view, int keyCode, KeyEvent event) { |
| 362 | switch (view.getId()) { |
| 363 | case R.id.digits: |
| 364 | // Happen when "Done" button of the IME is pressed. This can happen when this |
| 365 | // Activity is forced into landscape mode due to a desk dock. |
| 366 | if (keyCode == KeyEvent.KEYCODE_ENTER |
| 367 | && event.getAction() == KeyEvent.ACTION_UP) { |
| 368 | placeCall(); |
| 369 | return true; |
| 370 | } |
| 371 | break; |
| 372 | } |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | @Override |
Adrian Roos | 1c4b47f | 2015-04-13 14:53:32 -0700 | [diff] [blame] | 377 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 378 | mEmergencyActionGroup.onPreTouchEvent(ev); |
| 379 | boolean handled = super.dispatchTouchEvent(ev); |
| 380 | mEmergencyActionGroup.onPostTouchEvent(ev); |
| 381 | return handled; |
| 382 | } |
| 383 | |
| 384 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 385 | public void onClick(View view) { |
| 386 | switch (view.getId()) { |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 387 | case R.id.deleteButton: { |
| 388 | keyPressed(KeyEvent.KEYCODE_DEL); |
| 389 | return; |
| 390 | } |
| 391 | case R.id.floating_action_button: { |
Yorke Lee | 116dd07 | 2015-08-31 11:38:39 -0700 | [diff] [blame] | 392 | view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); |
Yorke Lee | 23a7073 | 2014-08-14 17:12:01 -0700 | [diff] [blame] | 393 | placeCall(); |
| 394 | return; |
| 395 | } |
| 396 | case R.id.digits: { |
| 397 | if (mDigits.length() != 0) { |
| 398 | mDigits.setCursorVisible(true); |
| 399 | } |
| 400 | return; |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | @Override |
| 406 | public void onPressed(View view, boolean pressed) { |
| 407 | if (!pressed) { |
| 408 | return; |
| 409 | } |
| 410 | switch (view.getId()) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 411 | case R.id.one: { |
| 412 | playTone(ToneGenerator.TONE_DTMF_1); |
| 413 | keyPressed(KeyEvent.KEYCODE_1); |
| 414 | return; |
| 415 | } |
| 416 | case R.id.two: { |
| 417 | playTone(ToneGenerator.TONE_DTMF_2); |
| 418 | keyPressed(KeyEvent.KEYCODE_2); |
| 419 | return; |
| 420 | } |
| 421 | case R.id.three: { |
| 422 | playTone(ToneGenerator.TONE_DTMF_3); |
| 423 | keyPressed(KeyEvent.KEYCODE_3); |
| 424 | return; |
| 425 | } |
| 426 | case R.id.four: { |
| 427 | playTone(ToneGenerator.TONE_DTMF_4); |
| 428 | keyPressed(KeyEvent.KEYCODE_4); |
| 429 | return; |
| 430 | } |
| 431 | case R.id.five: { |
| 432 | playTone(ToneGenerator.TONE_DTMF_5); |
| 433 | keyPressed(KeyEvent.KEYCODE_5); |
| 434 | return; |
| 435 | } |
| 436 | case R.id.six: { |
| 437 | playTone(ToneGenerator.TONE_DTMF_6); |
| 438 | keyPressed(KeyEvent.KEYCODE_6); |
| 439 | return; |
| 440 | } |
| 441 | case R.id.seven: { |
| 442 | playTone(ToneGenerator.TONE_DTMF_7); |
| 443 | keyPressed(KeyEvent.KEYCODE_7); |
| 444 | return; |
| 445 | } |
| 446 | case R.id.eight: { |
| 447 | playTone(ToneGenerator.TONE_DTMF_8); |
| 448 | keyPressed(KeyEvent.KEYCODE_8); |
| 449 | return; |
| 450 | } |
| 451 | case R.id.nine: { |
| 452 | playTone(ToneGenerator.TONE_DTMF_9); |
| 453 | keyPressed(KeyEvent.KEYCODE_9); |
| 454 | return; |
| 455 | } |
| 456 | case R.id.zero: { |
| 457 | playTone(ToneGenerator.TONE_DTMF_0); |
| 458 | keyPressed(KeyEvent.KEYCODE_0); |
| 459 | return; |
| 460 | } |
| 461 | case R.id.pound: { |
| 462 | playTone(ToneGenerator.TONE_DTMF_P); |
| 463 | keyPressed(KeyEvent.KEYCODE_POUND); |
| 464 | return; |
| 465 | } |
| 466 | case R.id.star: { |
| 467 | playTone(ToneGenerator.TONE_DTMF_S); |
| 468 | keyPressed(KeyEvent.KEYCODE_STAR); |
| 469 | return; |
| 470 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | |
| 474 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 475 | * called for long touch events |
| 476 | */ |
| 477 | @Override |
| 478 | public boolean onLongClick(View view) { |
| 479 | int id = view.getId(); |
| 480 | switch (id) { |
| 481 | case R.id.deleteButton: { |
| 482 | mDigits.getText().clear(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 483 | return true; |
| 484 | } |
| 485 | case R.id.zero: { |
Yorke Lee | 9131166 | 2014-10-24 14:50:45 -0700 | [diff] [blame] | 486 | removePreviousDigitIfPossible(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 487 | keyPressed(KeyEvent.KEYCODE_PLUS); |
| 488 | return true; |
| 489 | } |
| 490 | } |
| 491 | return false; |
| 492 | } |
| 493 | |
| 494 | @Override |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 495 | protected void onStart() { |
| 496 | super.onStart(); |
| 497 | |
| 498 | mColorExtractor.addOnColorsChangedListener(this); |
Lucas Dupin | 94b566f | 2017-05-28 11:45:52 -0700 | [diff] [blame] | 499 | GradientColors lockScreenColors = mColorExtractor.getColors(WallpaperManager.FLAG_LOCK, |
| 500 | ColorExtractor.TYPE_EXTRA_DARK); |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 501 | // Do not animate when view isn't visible yet, just set an initial state. |
| 502 | mBackgroundGradient.setColors(lockScreenColors, false); |
| 503 | updateTheme(lockScreenColors.supportsDarkText()); |
| 504 | } |
| 505 | |
| 506 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 507 | protected void onResume() { |
| 508 | super.onResume(); |
| 509 | |
| 510 | // retrieve the DTMF tone play back setting. |
| 511 | mDTMFToneEnabled = Settings.System.getInt(getContentResolver(), |
| 512 | Settings.System.DTMF_TONE_WHEN_DIALING, 1) == 1; |
| 513 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 514 | // if the mToneGenerator creation fails, just continue without it. It is |
| 515 | // a local audio signal, and is not as important as the dtmf tone itself. |
| 516 | synchronized (mToneGeneratorLock) { |
| 517 | if (mToneGenerator == null) { |
| 518 | try { |
| 519 | mToneGenerator = new ToneGenerator(AudioManager.STREAM_DTMF, |
| 520 | TONE_RELATIVE_VOLUME); |
| 521 | } catch (RuntimeException e) { |
| 522 | Log.w(LOG_TAG, "Exception caught while creating local tone generator: " + e); |
| 523 | mToneGenerator = null; |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 528 | updateDialAndDeleteButtonStateEnabledAttr(); |
| 529 | } |
| 530 | |
| 531 | @Override |
| 532 | public void onPause() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 533 | super.onPause(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 536 | @Override |
| 537 | protected void onStop() { |
| 538 | super.onStop(); |
| 539 | |
| 540 | mColorExtractor.removeOnColorsChangedListener(this); |
| 541 | } |
| 542 | |
| 543 | /** |
| 544 | * Sets theme based on gradient colors |
| 545 | * @param supportsDarkText true if gradient supports dark text |
| 546 | */ |
| 547 | private void updateTheme(boolean supportsDarkText) { |
| 548 | if (mSupportsDarkText == supportsDarkText) { |
| 549 | return; |
| 550 | } |
| 551 | mSupportsDarkText = supportsDarkText; |
| 552 | |
| 553 | // We can't change themes after inflation, in this case we'll have to recreate |
| 554 | // the whole activity. |
| 555 | if (mBackgroundGradient != null) { |
| 556 | recreate(); |
| 557 | return; |
| 558 | } |
| 559 | |
| 560 | int vis = getWindow().getDecorView().getSystemUiVisibility(); |
| 561 | if (supportsDarkText) { |
| 562 | vis |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 563 | vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 564 | setTheme(R.style.EmergencyDialerThemeDark); |
| 565 | } else { |
| 566 | vis &= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 567 | vis &= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 568 | setTheme(R.style.EmergencyDialerTheme); |
| 569 | } |
| 570 | getWindow().getDecorView().setSystemUiVisibility(vis); |
| 571 | } |
| 572 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 573 | /** |
| 574 | * place the call, but check to make sure it is a viable number. |
| 575 | */ |
| 576 | private void placeCall() { |
| 577 | mLastNumber = mDigits.getText().toString(); |
Wei Huang | 6904b14 | 2017-04-21 19:06:40 +0900 | [diff] [blame] | 578 | |
| 579 | // Convert into emergency number according to emergency conversion map. |
| 580 | // If conversion map is not defined (this is default), this method does |
| 581 | // nothing and just returns input number. |
| 582 | mLastNumber = PhoneNumberUtils.convertToEmergencyNumber(this, mLastNumber); |
| 583 | |
Yorke Lee | 36bb254 | 2014-06-05 08:09:52 -0700 | [diff] [blame] | 584 | if (PhoneNumberUtils.isLocalEmergencyNumber(this, mLastNumber)) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 585 | if (DBG) Log.d(LOG_TAG, "placing call to " + mLastNumber); |
| 586 | |
| 587 | // place the call if it is a valid number |
| 588 | if (mLastNumber == null || !TextUtils.isGraphic(mLastNumber)) { |
| 589 | // There is no number entered. |
| 590 | playTone(ToneGenerator.TONE_PROP_NACK); |
| 591 | return; |
| 592 | } |
Tyler Gunn | fa77e20 | 2018-03-23 07:47:00 -0700 | [diff] [blame] | 593 | TelecomManager tm = (TelecomManager) getSystemService(TELECOM_SERVICE); |
| 594 | tm.placeCall(Uri.fromParts(PhoneAccount.SCHEME_TEL, mLastNumber, null), null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 595 | } else { |
| 596 | if (DBG) Log.d(LOG_TAG, "rejecting bad requested number " + mLastNumber); |
| 597 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 598 | showDialog(BAD_EMERGENCY_NUMBER_DIALOG); |
| 599 | } |
Yorke Lee | 9b34151 | 2014-10-17 11:36:41 -0700 | [diff] [blame] | 600 | mDigits.getText().delete(0, mDigits.getText().length()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | /** |
| 604 | * Plays the specified tone for TONE_LENGTH_MS milliseconds. |
| 605 | * |
| 606 | * The tone is played locally, using the audio stream for phone calls. |
| 607 | * Tones are played only if the "Audible touch tones" user preference |
| 608 | * is checked, and are NOT played if the device is in silent mode. |
| 609 | * |
| 610 | * @param tone a tone code from {@link ToneGenerator} |
| 611 | */ |
| 612 | void playTone(int tone) { |
| 613 | // if local tone playback is disabled, just return. |
| 614 | if (!mDTMFToneEnabled) { |
| 615 | return; |
| 616 | } |
| 617 | |
| 618 | // Also do nothing if the phone is in silent mode. |
| 619 | // We need to re-check the ringer mode for *every* playTone() |
| 620 | // call, rather than keeping a local flag that's updated in |
| 621 | // onResume(), since it's possible to toggle silent mode without |
| 622 | // leaving the current activity (via the ENDCALL-longpress menu.) |
| 623 | AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); |
| 624 | int ringerMode = audioManager.getRingerMode(); |
| 625 | if ((ringerMode == AudioManager.RINGER_MODE_SILENT) |
| 626 | || (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) { |
| 627 | return; |
| 628 | } |
| 629 | |
| 630 | synchronized (mToneGeneratorLock) { |
| 631 | if (mToneGenerator == null) { |
| 632 | Log.w(LOG_TAG, "playTone: mToneGenerator == null, tone: " + tone); |
| 633 | return; |
| 634 | } |
| 635 | |
| 636 | // Start the new tone (will stop any playing tone) |
| 637 | mToneGenerator.startTone(tone, TONE_LENGTH_MS); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | private CharSequence createErrorMessage(String number) { |
| 642 | if (!TextUtils.isEmpty(number)) { |
Hall Liu | dc27431 | 2016-03-01 16:34:45 -0800 | [diff] [blame] | 643 | String errorString = getString(R.string.dial_emergency_error, number); |
| 644 | int startingPosition = errorString.indexOf(number); |
| 645 | int endingPosition = startingPosition + number.length(); |
| 646 | Spannable result = new SpannableString(errorString); |
| 647 | PhoneNumberUtils.addTtsSpan(result, startingPosition, endingPosition); |
| 648 | return result; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 649 | } else { |
| 650 | return getText(R.string.dial_emergency_empty_error).toString(); |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | @Override |
| 655 | protected Dialog onCreateDialog(int id) { |
| 656 | AlertDialog dialog = null; |
| 657 | if (id == BAD_EMERGENCY_NUMBER_DIALOG) { |
| 658 | // construct dialog |
Lucas Dupin | 0d666f9 | 2017-06-01 14:04:48 -0700 | [diff] [blame] | 659 | dialog = new AlertDialog.Builder(this, R.style.EmergencyDialerAlertDialogTheme) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 660 | .setTitle(getText(R.string.emergency_enable_radio_dialog_title)) |
| 661 | .setMessage(createErrorMessage(mLastNumber)) |
| 662 | .setPositiveButton(R.string.ok, null) |
| 663 | .setCancelable(true).create(); |
| 664 | |
| 665 | // blur stuff behind the dialog |
| 666 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
Tyler Gunn | cd6a1a9 | 2018-03-29 13:48:29 -0700 | [diff] [blame] | 667 | setShowWhenLocked(true); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 668 | } |
| 669 | return dialog; |
| 670 | } |
| 671 | |
| 672 | @Override |
| 673 | protected void onPrepareDialog(int id, Dialog dialog) { |
| 674 | super.onPrepareDialog(id, dialog); |
| 675 | if (id == BAD_EMERGENCY_NUMBER_DIALOG) { |
| 676 | AlertDialog alert = (AlertDialog) dialog; |
| 677 | alert.setMessage(createErrorMessage(mLastNumber)); |
| 678 | } |
| 679 | } |
| 680 | |
Andrew Lee | d5631e8 | 2014-10-08 16:03:58 -0700 | [diff] [blame] | 681 | @Override |
| 682 | public boolean onOptionsItemSelected(MenuItem item) { |
| 683 | final int itemId = item.getItemId(); |
| 684 | if (itemId == android.R.id.home) { |
| 685 | onBackPressed(); |
| 686 | return true; |
| 687 | } |
| 688 | return super.onOptionsItemSelected(item); |
| 689 | } |
| 690 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 691 | /** |
| 692 | * Update the enabledness of the "Dial" and "Backspace" buttons if applicable. |
| 693 | */ |
| 694 | private void updateDialAndDeleteButtonStateEnabledAttr() { |
| 695 | final boolean notEmpty = mDigits.length() != 0; |
| 696 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 697 | mDelete.setEnabled(notEmpty); |
| 698 | } |
Yorke Lee | 9131166 | 2014-10-24 14:50:45 -0700 | [diff] [blame] | 699 | |
| 700 | /** |
| 701 | * Remove the digit just before the current position. Used by various long pressed callbacks |
| 702 | * to remove the digit that was populated as a result of the short click. |
| 703 | */ |
| 704 | private void removePreviousDigitIfPossible() { |
| 705 | final int currentPosition = mDigits.getSelectionStart(); |
| 706 | if (currentPosition > 0) { |
| 707 | mDigits.setSelection(currentPosition); |
| 708 | mDigits.getText().delete(currentPosition - 1, currentPosition); |
| 709 | } |
| 710 | } |
Ihab Awad | f7c1a5a | 2014-12-08 19:24:23 -0800 | [diff] [blame] | 711 | |
| 712 | /** |
| 713 | * Update the text-to-speech annotations in the edit field. |
| 714 | */ |
| 715 | private void updateTtsSpans() { |
| 716 | for (Object o : mDigits.getText().getSpans(0, mDigits.getText().length(), TtsSpan.class)) { |
| 717 | mDigits.getText().removeSpan(o); |
| 718 | } |
| 719 | PhoneNumberUtils.ttsSpanAsPhoneNumber(mDigits.getText(), 0, mDigits.getText().length()); |
| 720 | } |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 721 | |
| 722 | @Override |
Lucas Dupin | 94b566f | 2017-05-28 11:45:52 -0700 | [diff] [blame] | 723 | public void onColorsChanged(ColorExtractor extractor, int which) { |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 724 | if ((which & WallpaperManager.FLAG_LOCK) != 0) { |
Lucas Dupin | 94b566f | 2017-05-28 11:45:52 -0700 | [diff] [blame] | 725 | GradientColors colors = extractor.getColors(WallpaperManager.FLAG_LOCK, |
| 726 | ColorExtractor.TYPE_EXTRA_DARK); |
Lucas Dupin | eb9c570 | 2017-05-10 16:57:09 -0700 | [diff] [blame] | 727 | mBackgroundGradient.setColors(colors); |
| 728 | updateTheme(colors.supportsDarkText()); |
| 729 | } |
| 730 | } |
Tyler Gunn | c542897 | 2018-03-28 14:15:34 -0700 | [diff] [blame] | 731 | |
| 732 | /** |
| 733 | * Where a carrier requires a warning that emergency calling is not available while on WFC, |
| 734 | * add hint text above the dial pad which warns the user of this case. |
| 735 | */ |
| 736 | private void maybeShowWfcEmergencyCallingWarning() { |
| 737 | if (!mIsWfcEmergencyCallingWarningEnabled) { |
| 738 | Log.i(LOG_TAG, "maybeShowWfcEmergencyCallingWarning: warning disabled by carrier."); |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | // Use an async task rather than calling into Telephony on UI thread. |
| 743 | AsyncTask<Void, Void, Boolean> showWfcWarningTask = new AsyncTask<Void, Void, Boolean>() { |
| 744 | @Override |
| 745 | protected Boolean doInBackground(Void... voids) { |
| 746 | TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); |
| 747 | boolean isWfcAvailable = tm.isWifiCallingAvailable(); |
| 748 | ServiceState ss = tm.getServiceState(); |
| 749 | boolean isCellAvailable = |
| 750 | ss.getRilVoiceRadioTechnology() != RIL_RADIO_TECHNOLOGY_UNKNOWN; |
| 751 | Log.i(LOG_TAG, "showWfcWarningTask: isWfcAvailable=" + isWfcAvailable |
| 752 | + " isCellAvailable=" + isCellAvailable |
| 753 | + "(rat=" + ss.getRilVoiceRadioTechnology() + ")"); |
| 754 | return isWfcAvailable && !isCellAvailable; |
| 755 | } |
| 756 | |
| 757 | @Override |
| 758 | protected void onPostExecute(Boolean result) { |
| 759 | if (result.booleanValue()) { |
| 760 | Log.i(LOG_TAG, "showWfcWarningTask: showing ecall warning"); |
| 761 | mDigits.setHint(R.string.dial_emergency_calling_not_available); |
| 762 | } else { |
| 763 | Log.i(LOG_TAG, "showWfcWarningTask: hiding ecall warning"); |
| 764 | mDigits.setHint(""); |
| 765 | } |
| 766 | maybeChangeHintSize(); |
| 767 | } |
| 768 | }; |
| 769 | showWfcWarningTask.execute((Void) null); |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * Where a hint is applied and there are no digits dialed, disable autoresize of the dial digits |
| 774 | * edit view and set the font size to a smaller size appropriate for the emergency calling |
| 775 | * warning. |
| 776 | */ |
| 777 | private void maybeChangeHintSize() { |
| 778 | if (TextUtils.isEmpty(mDigits.getHint()) |
| 779 | || !TextUtils.isEmpty(mDigits.getText().toString())) { |
| 780 | // No hint or there are dialed digits, so use default size. |
| 781 | mDigits.setTextSize(TypedValue.COMPLEX_UNIT_SP, mDefaultDigitsTextSize); |
| 782 | // By default, the digits view auto-resizes to fit the text it contains, so |
| 783 | // enable that now. |
| 784 | mDigits.setResizeEnabled(true); |
| 785 | Log.i(LOG_TAG, "no hint - setting to " + mDigits.getScaledTextSize()); |
| 786 | } else { |
| 787 | // Hint present and no dialed digits, set custom font size appropriate for the warning. |
| 788 | mDigits.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize( |
| 789 | R.dimen.emergency_call_warning_size)); |
| 790 | // Since we're populating this with a static text string, disable auto-resize. |
| 791 | mDigits.setResizeEnabled(false); |
| 792 | Log.i(LOG_TAG, "hint - setting to " + mDigits.getScaledTextSize()); |
| 793 | } |
| 794 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 795 | } |