The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [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 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 17 | package com.android.systemui.statusbar.phone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 19 | import android.app.StatusBarManager; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 20 | import android.bluetooth.BluetoothAdapter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.content.BroadcastReceiver; |
| 22 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.content.Intent; |
| 24 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.media.AudioManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.os.Handler; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 27 | import android.util.Log; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 29 | import com.android.internal.telephony.IccCardConstants; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 30 | import com.android.internal.telephony.TelephonyIntents; |
| 31 | import com.android.internal.telephony.cdma.TtyIntent; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 32 | import com.android.systemui.R; |
| 33 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | /** |
| 35 | * This class contains all of the policy about which icons are installed in the status |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 36 | * bar at boot time. It goes through the normal API for icons, even though it probably |
| 37 | * strictly doesn't need to. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | */ |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 39 | public class PhoneStatusBarPolicy { |
| 40 | private static final String TAG = "PhoneStatusBarPolicy"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | // message codes for the handler |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | private static final int EVENT_BATTERY_CLOSE = 4; |
| 44 | |
Daniel Sandler | 2c195f7 | 2010-05-21 15:42:06 -0400 | [diff] [blame] | 45 | private static final int AM_PM_STYLE_NORMAL = 0; |
| 46 | private static final int AM_PM_STYLE_SMALL = 1; |
| 47 | private static final int AM_PM_STYLE_GONE = 2; |
| 48 | |
| 49 | private static final int AM_PM_STYLE = AM_PM_STYLE_GONE; |
| 50 | |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 51 | private static final int INET_CONDITION_THRESHOLD = 50; |
| 52 | |
Daniel Sandler | b1e8dab | 2011-09-26 20:06:19 -0400 | [diff] [blame] | 53 | private static final boolean SHOW_SYNC_ICON = false; |
| 54 | |
Dianne Hackborn | 4840e14 | 2009-03-24 22:40:29 -0700 | [diff] [blame] | 55 | private final Context mContext; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 56 | private final StatusBarManager mService; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 57 | private final Handler mHandler = new Handler(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | // Assume it's all good unless we hear otherwise. We don't always seem |
| 60 | // to get broadcasts that it *is* there. |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 61 | IccCardConstants.State mSimState = IccCardConstants.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | |
| 63 | // ringer volume |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | private boolean mVolumeVisible; |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 65 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | // bluetooth device status |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 67 | private boolean mBluetoothEnabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | |
| 69 | // wifi |
Robert Greenwalt | d7085fc | 2010-09-08 15:24:47 -0700 | [diff] [blame] | 70 | private static final int[][] sWifiSignalImages = { |
| 71 | { R.drawable.stat_sys_wifi_signal_1, |
| 72 | R.drawable.stat_sys_wifi_signal_2, |
| 73 | R.drawable.stat_sys_wifi_signal_3, |
| 74 | R.drawable.stat_sys_wifi_signal_4 }, |
Robert Greenwalt | 26faee3 | 2010-09-10 09:36:43 -0700 | [diff] [blame] | 75 | { R.drawable.stat_sys_wifi_signal_1_fully, |
| 76 | R.drawable.stat_sys_wifi_signal_2_fully, |
| 77 | R.drawable.stat_sys_wifi_signal_3_fully, |
| 78 | R.drawable.stat_sys_wifi_signal_4_fully } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | }; |
| 80 | private static final int sWifiTemporarilyNotConnectedImage = |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 81 | R.drawable.stat_sys_wifi_signal_0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | |
| 83 | private int mLastWifiSignalLevel = -1; |
| 84 | private boolean mIsWifiConnected = false; |
Robert Greenwalt | 1e9aac2 | 2010-09-15 17:36:33 -0700 | [diff] [blame] | 85 | |
| 86 | // state of inet connection - 0 not connected, 100 connected |
| 87 | private int mInetCondition = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | |
| 89 | // sync state |
| 90 | // If sync is active the SyncActive icon is displayed. If sync is not active but |
| 91 | // sync is failing the SyncFailing icon is displayed. Otherwise neither are displayed. |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 92 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { |
| 94 | @Override |
| 95 | public void onReceive(Context context, Intent intent) { |
| 96 | String action = intent.getAction(); |
Daniel Sandler | 2b69735 | 2011-07-22 16:23:09 -0400 | [diff] [blame] | 97 | if (action.equals(Intent.ACTION_ALARM_CHANGED)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | updateAlarm(intent); |
| 99 | } |
| 100 | else if (action.equals(Intent.ACTION_SYNC_STATE_CHANGED)) { |
| 101 | updateSyncState(intent); |
| 102 | } |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 103 | else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED) || |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 104 | action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | updateBluetooth(intent); |
| 106 | } |
Eric Laurent | bffc3d1 | 2012-05-07 17:43:49 -0700 | [diff] [blame] | 107 | else if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | updateVolume(); |
| 109 | } |
| 110 | else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) { |
| 111 | updateSimState(intent); |
| 112 | } |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 113 | else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) { |
| 114 | updateTTY(intent); |
| 115 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | } |
| 117 | }; |
| 118 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 119 | public PhoneStatusBarPolicy(Context context) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | mContext = context; |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 121 | mService = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 123 | // listen for broadcasts |
| 124 | IntentFilter filter = new IntentFilter(); |
| 125 | filter.addAction(Intent.ACTION_ALARM_CHANGED); |
| 126 | filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED); |
| 127 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 128 | filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); |
| 129 | filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); |
| 130 | filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); |
| 131 | filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION); |
| 132 | mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); |
| 133 | |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 134 | // TTY status |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 135 | mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0, null); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 136 | mService.setIconVisibility("tty", false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 137 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 138 | // Cdma Roaming Indicator, ERI |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 139 | mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0, null); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 140 | mService.setIconVisibility("cdma_eri", false); |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | // bluetooth status |
Nick Pelly | f242b7b | 2009-10-08 00:12:45 +0200 | [diff] [blame] | 143 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 144 | int bluetoothIcon = R.drawable.stat_sys_data_bluetooth; |
Nick Pelly | bd022f4 | 2009-08-14 18:33:38 -0700 | [diff] [blame] | 145 | if (adapter != null) { |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 146 | mBluetoothEnabled = (adapter.getState() == BluetoothAdapter.STATE_ON); |
| 147 | if (adapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTED) { |
| 148 | bluetoothIcon = R.drawable.stat_sys_data_bluetooth_connected; |
| 149 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | } |
Daniel Sandler | e3b7a2d | 2011-10-27 16:16:15 -0400 | [diff] [blame] | 151 | mService.setIcon("bluetooth", bluetoothIcon, 0, null); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 152 | mService.setIconVisibility("bluetooth", mBluetoothEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | // Alarm clock |
Justin Ho | fdfbbf6 | 2011-08-26 08:51:27 -0700 | [diff] [blame] | 155 | mService.setIcon("alarm_clock", R.drawable.stat_sys_alarm, 0, null); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 156 | mService.setIconVisibility("alarm_clock", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | |
| 158 | // Sync state |
Justin Ho | 9f17658 | 2011-09-20 18:16:48 -0700 | [diff] [blame] | 159 | mService.setIcon("sync_active", R.drawable.stat_sys_sync, 0, null); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 160 | mService.setIconVisibility("sync_active", false); |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame^] | 161 | // "sync_failing" is obsolete: b/1297963 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | |
| 163 | // volume |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 164 | mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0, null); |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 165 | mService.setIconVisibility("volume", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | updateVolume(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | } |
| 168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | private final void updateAlarm(Intent intent) { |
| 170 | boolean alarmSet = intent.getBooleanExtra("alarmSet", false); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 171 | mService.setIconVisibility("alarm_clock", alarmSet); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | private final void updateSyncState(Intent intent) { |
Daniel Sandler | b1e8dab | 2011-09-26 20:06:19 -0400 | [diff] [blame] | 175 | if (!SHOW_SYNC_ICON) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | boolean isActive = intent.getBooleanExtra("active", false); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 177 | mService.setIconVisibility("sync_active", isActive); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | } |
| 179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | private final void updateSimState(Intent intent) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 181 | String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); |
| 182 | if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) { |
| 183 | mSimState = IccCardConstants.State.ABSENT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 185 | else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) { |
| 186 | mSimState = IccCardConstants.State.READY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 188 | else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) { |
| 189 | final String lockedReason = |
| 190 | intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON); |
| 191 | if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) { |
| 192 | mSimState = IccCardConstants.State.PIN_REQUIRED; |
johnwang | 347c5a2 | 2009-08-24 22:11:11 -0700 | [diff] [blame] | 193 | } |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 194 | else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) { |
| 195 | mSimState = IccCardConstants.State.PUK_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | } |
| 197 | else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 198 | mSimState = IccCardConstants.State.NETWORK_LOCKED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | } |
| 200 | } else { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 201 | mSimState = IccCardConstants.State.UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | private final void updateVolume() { |
| 206 | AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
| 207 | final int ringerMode = audioManager.getRingerMode(); |
| 208 | final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT || |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 209 | ringerMode == AudioManager.RINGER_MODE_VIBRATE; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 210 | |
| 211 | final int iconId; |
| 212 | String contentDescription = null; |
Eric Laurent | bffc3d1 | 2012-05-07 17:43:49 -0700 | [diff] [blame] | 213 | if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) { |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 214 | iconId = R.drawable.stat_sys_ringer_vibrate; |
| 215 | contentDescription = mContext.getString(R.string.accessibility_ringer_vibrate); |
| 216 | } else { |
| 217 | iconId = R.drawable.stat_sys_ringer_silent; |
| 218 | contentDescription = mContext.getString(R.string.accessibility_ringer_silent); |
| 219 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | |
| 221 | if (visible) { |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 222 | mService.setIcon("volume", iconId, 0, contentDescription); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | } |
| 224 | if (visible != mVolumeVisible) { |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 225 | mService.setIconVisibility("volume", visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | mVolumeVisible = visible; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | private final void updateBluetooth(Intent intent) { |
Joe Onorato | 798ac4c | 2010-05-27 16:39:00 -0400 | [diff] [blame] | 231 | int iconId = R.drawable.stat_sys_data_bluetooth; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 232 | String contentDescription = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | String action = intent.getAction(); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 234 | if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { |
Nick Pelly | b24e11b | 2009-09-08 17:40:43 -0700 | [diff] [blame] | 235 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR); |
Nick Pelly | de893f5 | 2009-09-08 13:15:33 -0700 | [diff] [blame] | 236 | mBluetoothEnabled = state == BluetoothAdapter.STATE_ON; |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 237 | } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { |
Jaikumar Ganesh | 0b63a6a | 2011-07-11 14:34:34 -0700 | [diff] [blame] | 238 | int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, |
Jaikumar Ganesh | d9bb688 | 2010-09-27 17:05:24 -0700 | [diff] [blame] | 239 | BluetoothAdapter.STATE_DISCONNECTED); |
| 240 | if (state == BluetoothAdapter.STATE_CONNECTED) { |
| 241 | iconId = R.drawable.stat_sys_data_bluetooth_connected; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 242 | contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected); |
| 243 | } else { |
| 244 | contentDescription = mContext.getString( |
| 245 | R.string.accessibility_bluetooth_disconnected); |
Jaikumar Ganesh | 084c665 | 2009-12-07 10:58:18 -0800 | [diff] [blame] | 246 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | } else { |
| 248 | return; |
| 249 | } |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 250 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 251 | mService.setIcon("bluetooth", iconId, 0, contentDescription); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 252 | mService.setIconVisibility("bluetooth", mBluetoothEnabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 255 | private final void updateTTY(Intent intent) { |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 256 | final String action = intent.getAction(); |
| 257 | final boolean enabled = intent.getBooleanExtra(TtyIntent.TTY_ENABLED, false); |
| 258 | |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 259 | if (false) Log.v(TAG, "updateTTY: enabled: " + enabled); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 260 | |
| 261 | if (enabled) { |
| 262 | // TTY is on |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 263 | if (false) Log.v(TAG, "updateTTY: set TTY on"); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 264 | mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0, |
| 265 | mContext.getString(R.string.accessibility_tty_enabled)); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 266 | mService.setIconVisibility("tty", true); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 267 | } else { |
| 268 | // TTY is off |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 269 | if (false) Log.v(TAG, "updateTTY: set TTY off"); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 270 | mService.setIconVisibility("tty", false); |
Wink Saville | 04e71b3 | 2009-04-02 11:00:54 -0700 | [diff] [blame] | 271 | } |
| 272 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | } |