diff options
author | Kaikai Wang <kaikai@google.com> | 2014-12-08 19:45:10 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-12-08 19:45:10 +0000 |
commit | 63fb4a209ef45bc777a22b99da42e8168ba13d6e (patch) | |
tree | 1cf3ccc4a1b405dfebe149ed13f63e285bde02b5 | |
parent | 514c24c669f5eb34d6d5ab8bca49b83e352cad05 (diff) | |
parent | 1f20a74925ab5ca73b451a437a718eb72f9a22b3 (diff) | |
download | android_frameworks_opt_colorpicker-63fb4a209ef45bc777a22b99da42e8168ba13d6e.tar.gz android_frameworks_opt_colorpicker-63fb4a209ef45bc777a22b99da42e8168ba13d6e.tar.bz2 android_frameworks_opt_colorpicker-63fb4a209ef45bc777a22b99da42e8168ba13d6e.zip |
am 1f20a749: Adding custom color swatch content description support to color picker for accessibility
* commit '1f20a74925ab5ca73b451a437a718eb72f9a22b3':
Adding custom color swatch content description support to color picker for accessibility
-rw-r--r-- | src/com/android/colorpicker/ColorPickerDialog.java | 14 | ||||
-rw-r--r-- | src/com/android/colorpicker/ColorPickerPalette.java | 41 |
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); } |