diff options
author | Kaikai Wang <kaikai@google.com> | 2014-12-09 23:19:11 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-12-09 23:19:11 +0000 |
commit | f7c6f5c7a1c5ff8de3c5570770f8fc732b021b48 (patch) | |
tree | 232c7d1382eeae1fd32809289b1f2db94a71d7c5 /src/com/android/colorpicker/ColorPickerPalette.java | |
parent | 7477bcee420aa61f097a5cff98ab97ac0f661800 (diff) | |
parent | 63fb4a209ef45bc777a22b99da42e8168ba13d6e (diff) | |
download | android_frameworks_opt_colorpicker-f7c6f5c7a1c5ff8de3c5570770f8fc732b021b48.tar.gz android_frameworks_opt_colorpicker-f7c6f5c7a1c5ff8de3c5570770f8fc732b021b48.tar.bz2 android_frameworks_opt_colorpicker-f7c6f5c7a1c5ff8de3c5570770f8fc732b021b48.zip |
am 63fb4a20: am 1f20a749: Adding custom color swatch content description support to color picker for accessibility
* commit '63fb4a209ef45bc777a22b99da42e8168ba13d6e':
Adding custom color swatch content description support to color picker for accessibility
Diffstat (limited to 'src/com/android/colorpicker/ColorPickerPalette.java')
-rw-r--r-- | src/com/android/colorpicker/ColorPickerPalette.java | 41 |
1 files changed, 26 insertions, 15 deletions
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); } |