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