summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaikai Wang <kaikai@google.com>2014-12-05 15:04:50 -0800
committerKaikai Wang <kaikai@google.com>2014-12-05 15:47:58 -0800
commit1f20a74925ab5ca73b451a437a718eb72f9a22b3 (patch)
tree1cf3ccc4a1b405dfebe149ed13f63e285bde02b5
parent5592cb927e2dd42297121124b21c983a0131bf4a (diff)
downloadandroid_frameworks_opt_colorpicker-1f20a74925ab5ca73b451a437a718eb72f9a22b3.tar.gz
android_frameworks_opt_colorpicker-1f20a74925ab5ca73b451a437a718eb72f9a22b3.tar.bz2
android_frameworks_opt_colorpicker-1f20a74925ab5ca73b451a437a718eb72f9a22b3.zip
Adding custom color swatch content description support to color picker for accessibility
Bug: 18538668 color in color picker does not have name in talk back mode Change-Id: Ib09b7cc21eabca4bfb64d8b7dcd856bf63992aef
-rw-r--r--src/com/android/colorpicker/ColorPickerDialog.java14
-rw-r--r--src/com/android/colorpicker/ColorPickerPalette.java41
2 files changed, 39 insertions, 16 deletions
diff --git a/src/com/android/colorpicker/ColorPickerDialog.java b/src/com/android/colorpicker/ColorPickerDialog.java
index 188c5c2..0d24b49 100644
--- a/src/com/android/colorpicker/ColorPickerDialog.java
+++ b/src/com/android/colorpicker/ColorPickerDialog.java
@@ -40,12 +40,14 @@ public class ColorPickerDialog extends DialogFragment implements OnColorSelected
protected static final String KEY_TITLE_ID = "title_id";
protected static final String KEY_COLORS = "colors";
+ protected static final String KEY_COLOR_CONTENT_DESCRIPTIONS = "color_content_descriptions";
protected static final String KEY_SELECTED_COLOR = "selected_color";
protected static final String KEY_COLUMNS = "columns";
protected static final String KEY_SIZE = "size";
protected int mTitleResId = R.string.color_picker_default_title;
protected int[] mColors = null;
+ protected String[] mColorContentDescriptions = null;
protected int mSelectedColor;
protected int mColumns;
protected int mSize;
@@ -96,6 +98,8 @@ public class ColorPickerDialog extends DialogFragment implements OnColorSelected
if (savedInstanceState != null) {
mColors = savedInstanceState.getIntArray(KEY_COLORS);
mSelectedColor = (Integer) savedInstanceState.getSerializable(KEY_SELECTED_COLOR);
+ mColorContentDescriptions = savedInstanceState.getStringArray(
+ KEY_COLOR_CONTENT_DESCRIPTIONS);
}
}
@@ -178,9 +182,16 @@ public class ColorPickerDialog extends DialogFragment implements OnColorSelected
}
}
+ public void setColorContentDescriptions(String[] colorContentDescriptions) {
+ if (mColorContentDescriptions != colorContentDescriptions) {
+ mColorContentDescriptions = colorContentDescriptions;
+ refreshPalette();
+ }
+ }
+
private void refreshPalette() {
if (mPalette != null && mColors != null) {
- mPalette.drawPalette(mColors, mSelectedColor);
+ mPalette.drawPalette(mColors, mSelectedColor, mColorContentDescriptions);
}
}
@@ -197,5 +208,6 @@ public class ColorPickerDialog extends DialogFragment implements OnColorSelected
super.onSaveInstanceState(outState);
outState.putIntArray(KEY_COLORS, mColors);
outState.putSerializable(KEY_SELECTED_COLOR, mSelectedColor);
+ outState.putStringArray(KEY_COLOR_CONTENT_DESCRIPTIONS, mColorContentDescriptions);
}
}
diff --git a/src/com/android/colorpicker/ColorPickerPalette.java b/src/com/android/colorpicker/ColorPickerPalette.java
index e0d0203..1512213 100644
--- a/src/com/android/colorpicker/ColorPickerPalette.java
+++ b/src/com/android/colorpicker/ColorPickerPalette.java
@@ -82,6 +82,13 @@ public class ColorPickerPalette extends TableLayout {
* Adds swatches to table in a serpentine format.
*/
public void drawPalette(int[] colors, int selectedColor) {
+ drawPalette(colors, selectedColor, null);
+ }
+
+ /**
+ * Adds swatches to table in a serpentine format.
+ */
+ public void drawPalette(int[] colors, int selectedColor, String[] colorContentDescriptions) {
if (colors == null) {
return;
}
@@ -98,7 +105,7 @@ public class ColorPickerPalette extends TableLayout {
View colorSwatch = createColorSwatch(color, selectedColor);
setSwatchDescription(rowNumber, tableElements, rowElements, color == selectedColor,
- colorSwatch);
+ colorSwatch, colorContentDescriptions);
addSwatchToRow(row, colorSwatch, rowNumber);
rowElements++;
@@ -139,22 +146,26 @@ public class ColorPickerPalette extends TableLayout {
* will arrange them for accessibility purposes.
*/
private void setSwatchDescription(int rowNumber, int index, int rowElements, boolean selected,
- View swatch) {
- int accessibilityIndex;
- if (rowNumber % 2 == 0) {
- // We're in a regular-ordered row
- accessibilityIndex = index;
- } else {
- // We're in a backwards-ordered row.
- int rowMax = ((rowNumber + 1) * mNumColumns);
- accessibilityIndex = rowMax - rowElements;
- }
-
+ View swatch, String[] contentDescriptions) {
String description;
- if (selected) {
- description = String.format(mDescriptionSelected, accessibilityIndex);
+ if (contentDescriptions != null && contentDescriptions.length > index) {
+ description = contentDescriptions[index];
} else {
- description = String.format(mDescription, accessibilityIndex);
+ int accessibilityIndex;
+ if (rowNumber % 2 == 0) {
+ // We're in a regular-ordered row
+ accessibilityIndex = index;
+ } else {
+ // We're in a backwards-ordered row.
+ int rowMax = ((rowNumber + 1) * mNumColumns);
+ accessibilityIndex = rowMax - rowElements;
+ }
+
+ if (selected) {
+ description = String.format(mDescriptionSelected, accessibilityIndex);
+ } else {
+ description = String.format(mDescription, accessibilityIndex);
+ }
}
swatch.setContentDescription(description);
}