The "device type" icons in "Bluetooth device list" screen are

not accessible to TalkBack users.

b/28199679 Changed method to for setting the talk-back
attribute on "device type".

Change-Id: I63820d861ea1075195b98c82004ba95470448a53
This commit is contained in:
pkanwar
2016-04-29 17:43:24 -07:00
parent 56f7bc44a1
commit 8fa3d44596
2 changed files with 54 additions and 14 deletions

View File

@@ -7473,4 +7473,24 @@
<!-- [CHAR LIMIT=NONE] The preference summary for enabling cross-profile remote contact search --> <!-- [CHAR LIMIT=NONE] The preference summary for enabling cross-profile remote contact search -->
<string name="managed_profile_contact_search_summary">Allow contact searches by your organization to identify callers and contacts</string> <string name="managed_profile_contact_search_summary">Allow contact searches by your organization to identify callers and contacts</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_computer">Computer</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_headset">Headset</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_phone">Phone</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_imaging">Imaging</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_headphone">Headphone</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_input_peripheral">Input Peripheral</string>
<!-- Message for telling the user the kind of BT device being displayed in list. -->
<string name="bluetooth_talkback_bluetooth">Bluetooth</string>
</resources> </resources>

View File

@@ -21,12 +21,14 @@ import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.UserManager; import android.os.UserManager;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder; import android.support.v7.preference.PreferenceViewHolder;
import android.text.Html; import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.Pair;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
@@ -59,6 +61,19 @@ public final class BluetoothDevicePreference extends Preference implements
private AlertDialog mDisconnectDialog; private AlertDialog mDisconnectDialog;
private String contentDescription = null;
/* Talk-back descriptions for various BT icons */
Resources r = getContext().getResources();
public final String COMPUTER = r.getString(R.string.bluetooth_talkback_computer);
public final String INPUT_PERIPHERAL = r.getString(
R.string.bluetooth_talkback_input_peripheral);
public final String HEADSET = r.getString(R.string.bluetooth_talkback_headset);
public final String PHONE = r.getString(R.string.bluetooth_talkback_phone);
public final String IMAGING = r.getString(R.string.bluetooth_talkback_imaging);
public final String HEADPHONE = r.getString(R.string.bluetooth_talkback_headphone);
public final String BLUETOOTH = r.getString(R.string.bluetooth_talkback_bluetooth);
public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice) { public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice) {
super(context); super(context);
@@ -121,9 +136,11 @@ public final class BluetoothDevicePreference extends Preference implements
setSummary(null); // empty summary for unpaired devices setSummary(null); // empty summary for unpaired devices
} }
int iconResId = getBtClassDrawable();
if (iconResId != 0) { Pair<Integer, String> pair = getBtClassDrawableWithDescription();
setIcon(iconResId); if (pair.first != 0) {
setIcon(pair.first);
contentDescription = pair.second;
} }
// Used to gray out the item // Used to gray out the item
@@ -148,7 +165,10 @@ public final class BluetoothDevicePreference extends Preference implements
deviceDetails.setTag(mCachedDevice); deviceDetails.setTag(mCachedDevice);
} }
} }
final ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
if (imageView != null) {
imageView.setContentDescription(contentDescription);
}
super.onBindViewHolder(view); super.onBindViewHolder(view);
} }
@@ -234,21 +254,22 @@ public final class BluetoothDevicePreference extends Preference implements
} }
} }
private int getBtClassDrawable() { private Pair<Integer, String> getBtClassDrawableWithDescription() {
BluetoothClass btClass = mCachedDevice.getBtClass(); BluetoothClass btClass = mCachedDevice.getBtClass();
if (btClass != null) { if (btClass != null) {
switch (btClass.getMajorDeviceClass()) { switch (btClass.getMajorDeviceClass()) {
case BluetoothClass.Device.Major.COMPUTER: case BluetoothClass.Device.Major.COMPUTER:
return R.drawable.ic_bt_laptop; return new Pair<Integer, String>(R.drawable.ic_bt_laptop, COMPUTER);
case BluetoothClass.Device.Major.PHONE: case BluetoothClass.Device.Major.PHONE:
return R.drawable.ic_bt_cellphone; return new Pair<Integer, String>(R.drawable.ic_bt_cellphone, PHONE);
case BluetoothClass.Device.Major.PERIPHERAL: case BluetoothClass.Device.Major.PERIPHERAL:
return HidProfile.getHidClassDrawable(btClass); return new Pair<Integer, String>(HidProfile.getHidClassDrawable(btClass),
INPUT_PERIPHERAL);
case BluetoothClass.Device.Major.IMAGING: case BluetoothClass.Device.Major.IMAGING:
return R.drawable.ic_bt_imaging; return new Pair<Integer, String>(R.drawable.ic_bt_imaging, IMAGING);
default: default:
// unrecognized device class; continue // unrecognized device class; continue
@@ -261,18 +282,17 @@ public final class BluetoothDevicePreference extends Preference implements
for (LocalBluetoothProfile profile : profiles) { for (LocalBluetoothProfile profile : profiles) {
int resId = profile.getDrawableResource(btClass); int resId = profile.getDrawableResource(btClass);
if (resId != 0) { if (resId != 0) {
return resId; return new Pair<Integer, String>(resId, null);
} }
} }
if (btClass != null) { if (btClass != null) {
if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) { if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
return R.drawable.ic_bt_headphones_a2dp; return new Pair<Integer, String>(R.drawable.ic_bt_headphones_a2dp, HEADPHONE);
} }
if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) { if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
return R.drawable.ic_bt_headset_hfp; return new Pair<Integer, String>(R.drawable.ic_bt_headset_hfp, HEADSET);
} }
} }
return R.drawable.ic_settings_bluetooth; return new Pair<Integer, String>(R.drawable.ic_settings_bluetooth, BLUETOOTH);
} }
} }