diff options
Diffstat (limited to 'src/com/android/colorpicker/ColorPickerPalette.java')
-rw-r--r-- | src/com/android/colorpicker/ColorPickerPalette.java | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/src/com/android/colorpicker/ColorPickerPalette.java b/src/com/android/colorpicker/ColorPickerPalette.java index e0d0203..9ca46c3 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; } @@ -94,13 +101,12 @@ public class ColorPickerPalette extends TableLayout { // Fills the table with swatches based on the array of colors. TableRow row = createTableRow(); for (int color : colors) { - tableElements++; - View colorSwatch = createColorSwatch(color, selectedColor); setSwatchDescription(rowNumber, tableElements, rowElements, color == selectedColor, - colorSwatch); + colorSwatch, colorContentDescriptions); addSwatchToRow(row, colorSwatch, rowNumber); + tableElements++; rowElements++; if (rowElements == mNumColumns) { addView(row); @@ -139,22 +145,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 + 1; + } 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); } |