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