OSDN Git Service

The "device type" icons in "Bluetooth device list" screen are
authorpkanwar <pkanwar@google.com>
Sat, 30 Apr 2016 00:43:24 +0000 (17:43 -0700)
committerpkanwar <pkanwar@google.com>
Thu, 5 May 2016 18:25:46 +0000 (11:25 -0700)
not accessible to TalkBack users.

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

Change-Id: I63820d861ea1075195b98c82004ba95470448a53

res/values/strings.xml
src/com/android/settings/bluetooth/BluetoothDevicePreference.java

index ea4da30..51c54c9 100644 (file)
     <!-- [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>
 
+    <!-- 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>
index 6d95351..a45e7b4 100644 (file)
@@ -21,12 +21,14 @@ import android.bluetooth.BluetoothClass;
 import android.bluetooth.BluetoothDevice;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.content.res.Resources;
 import android.os.UserManager;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.PreferenceViewHolder;
 import android.text.Html;
 import android.text.TextUtils;
 import android.util.Log;
+import android.util.Pair;
 import android.util.TypedValue;
 import android.view.View;
 import android.view.View.OnClickListener;
@@ -59,6 +61,19 @@ public final class BluetoothDevicePreference extends Preference implements
 
     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) {
         super(context);
 
@@ -121,9 +136,11 @@ public final class BluetoothDevicePreference extends Preference implements
             setSummary(null);   // empty summary for unpaired devices
         }
 
-        int iconResId = getBtClassDrawable();
-        if (iconResId != 0) {
-            setIcon(iconResId);
+
+        Pair<Integer, String> pair = getBtClassDrawableWithDescription();
+        if (pair.first != 0) {
+            setIcon(pair.first);
+            contentDescription = pair.second;
         }
 
         // Used to gray out the item
@@ -148,7 +165,10 @@ public final class BluetoothDevicePreference extends Preference implements
                 deviceDetails.setTag(mCachedDevice);
             }
         }
-
+        final ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
+        if (imageView != null) {
+            imageView.setContentDescription(contentDescription);
+        }
         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();
         if (btClass != null) {
             switch (btClass.getMajorDeviceClass()) {
                 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:
-                    return R.drawable.ic_bt_cellphone;
+                    return new Pair<Integer, String>(R.drawable.ic_bt_cellphone, PHONE);
 
                 case BluetoothClass.Device.Major.PERIPHERAL:
-                    return HidProfile.getHidClassDrawable(btClass);
+                    return new Pair<Integer, String>(HidProfile.getHidClassDrawable(btClass),
+                                                     INPUT_PERIPHERAL);
 
                 case BluetoothClass.Device.Major.IMAGING:
-                    return R.drawable.ic_bt_imaging;
+                    return new Pair<Integer, String>(R.drawable.ic_bt_imaging, IMAGING);
 
                 default:
                     // unrecognized device class; continue
@@ -261,18 +282,17 @@ public final class BluetoothDevicePreference extends Preference implements
         for (LocalBluetoothProfile profile : profiles) {
             int resId = profile.getDrawableResource(btClass);
             if (resId != 0) {
-                return resId;
+                return new Pair<Integer, String>(resId, null);
             }
         }
         if (btClass != null) {
             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)) {
-                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);
     }
 }