adding accessibilty strings to ui items
Change-Id: I3f2356c765bd2799dfa1009ff6707fc3af87383e
diff --git a/src/com/android/camera/ButtonManager.java b/src/com/android/camera/ButtonManager.java
index 7cf909c..8e8ba7d 100644
--- a/src/com/android/camera/ButtonManager.java
+++ b/src/com/android/camera/ButtonManager.java
@@ -454,6 +454,8 @@
if (resIdImages > 0) {
button.overrideImageIds(resIdImages);
}
+ button.overrideContentDescriptions(R.array.camera_flash_descriptions);
+
int index = mSettingsManager.getStringValueIndex(SettingsManager.SETTING_FLASH_MODE);
button.setState(index >= 0 ? index : 0, false);
@@ -477,6 +479,8 @@
if (resIdImages > 0) {
button.overrideImageIds(resIdImages);
}
+ button.overrideContentDescriptions(R.array.video_flash_descriptions);
+
int index = mSettingsManager.getStringValueIndex(
SettingsManager.SETTING_VIDEOCAMERA_FLASH_MODE);
button.setState(index >= 0 ? index : 0, false);
@@ -529,6 +533,7 @@
if (resIdImages > 0) {
button.overrideImageIds(resIdImages);
}
+ button.overrideContentDescriptions(R.array.hdr_plus_descriptions);
int index = mSettingsManager.getStringValueIndex(SettingsManager.SETTING_CAMERA_HDR);
button.setState(index >= 0 ? index : 0, false);
diff --git a/src/com/android/camera/MultiToggleImageButton.java b/src/com/android/camera/MultiToggleImageButton.java
index 49b073f..6b43cd6 100644
--- a/src/com/android/camera/MultiToggleImageButton.java
+++ b/src/com/android/camera/MultiToggleImageButton.java
@@ -22,6 +22,7 @@
import android.util.AttributeSet;
import android.widget.ImageButton;
import android.view.View;
+import android.view.accessibility.AccessibilityEvent;
import com.android.camera2.R;
@@ -50,6 +51,7 @@
private OnStateChangeListener mOnStateChangeListener;
private int mState;
private int[] mImageIds;
+ private int[] mDescIds;
private int mLevel;
public MultiToggleImageButton(Context context) {
@@ -107,6 +109,9 @@
public void setState(int state, boolean callListener) {
mState = state;
setImageResource(mImageIds[mState]);
+ setContentDescription(getResources().getString(mDescIds[mState]));
+ // TODO get talkback to announce the current button state
+ //sendAccessibilityEvent(AccessibilityEvent.CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION);
super.setImageLevel(mLevel);
if (callListener && mOnStateChangeListener != null) {
mOnStateChangeListener.stateChanged(this, getState());
@@ -135,8 +140,12 @@
attrs,
R.styleable.MultiToggleImageButton,
0, 0);
- int resId = a.getResourceId(R.styleable.MultiToggleImageButton_imageIds, 0);
- overrideImageIds(resId);
+ int imageIds = a.getResourceId(R.styleable.MultiToggleImageButton_imageIds, 0);
+ overrideImageIds(imageIds);
+
+ int descIds = a.getResourceId(R.styleable.MultiToggleImageButton_contentDescriptionIds, 0);
+ overrideContentDescriptions(descIds);
+
a.recycle();
}
@@ -158,6 +167,24 @@
}
}
+ /**
+ * Override the content descriptions of this button.
+ */
+ public void overrideContentDescriptions(int resId) {
+ TypedArray ids = null;
+ try {
+ ids = getResources().obtainTypedArray(resId);
+ mDescIds = new int[ids.length()];
+ for (int i = 0; i < ids.length(); i++) {
+ mDescIds[i] = ids.getResourceId(i, 0);
+ }
+ } finally {
+ if (ids != null) {
+ ids.recycle();
+ }
+ }
+ }
+
@Override
public void setImageLevel(int level) {
super.setImageLevel(level);
diff --git a/src/com/android/camera/ui/ModeListView.java b/src/com/android/camera/ui/ModeListView.java
index d7386b9..939c643 100644
--- a/src/com/android/camera/ui/ModeListView.java
+++ b/src/com/android/camera/ui/ModeListView.java
@@ -368,6 +368,11 @@
// Set text
selectorItem.setText(CameraUtil.getCameraModeText(modeId, getContext()));
+
+ // Set content description (for a11y)
+ selectorItem.setContentDescription(CameraUtil
+ .getCameraModeContentDescription(modeId, getContext()));
+
mModeSelectorItems[i] = selectorItem;
}
diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java
index 7af8670..fbce28e 100644
--- a/src/com/android/camera/util/CameraUtil.java
+++ b/src/com/android/camera/util/CameraUtil.java
@@ -1053,6 +1053,23 @@
}
/**
+ * Gets the mode content description of a specific mode.
+ *
+ * @param modeIndex index of the mode
+ * @param context current context
+ * @return mode content description if the index is valid, otherwise a new empty string
+ */
+ public static String getCameraModeContentDescription(int modeIndex, Context context) {
+ String[] cameraModesDesc = context.getResources()
+ .getStringArray(R.array.camera_mode_content_description);
+ if (modeIndex < 0 || modeIndex >= cameraModesDesc.length) {
+ Log.e(TAG, "Invalid mode index: " + modeIndex);
+ return new String();
+ }
+ return cameraModesDesc[modeIndex];
+ }
+
+ /**
* Gets the shutter icon res id for a specific mode.
*
* @param modeIndex index of the mode