Skip to content

Commit d1e6d27

Browse files
committed
Without provided color name, read RGB value
1 parent d4bc967 commit d1e6d27

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

simpledialogfragments/src/main/java/eltos/simpledialogfragment/color/ColorView.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import android.widget.FrameLayout;
4747
import android.widget.ImageView;
4848

49+
import java.util.Locale;
50+
4951
import eltos.simpledialogfragment.R;
5052

5153

@@ -108,12 +110,17 @@ public void setStyle(Style style){
108110
return mColor;
109111
}
110112

113+
/**
114+
* Will implicitly set content description. Thus custom content description must be set after this
115+
* method is called
116+
*/
111117
public void setColor(@ColorInt int color) {
112118
if ((color & 0xFF000000) == 0 && color != 0){ // if alpha value omitted, set now
113119
color = color | 0xFF000000;
114120
}
115121
if (mColor != color) {
116122
mColor = color;
123+
setContentDescription(colorToRGBString(mColor));
117124
update();
118125
}
119126
}
@@ -289,6 +296,12 @@ public static boolean isColorDark(@ColorInt int color) {
289296
return Color.HSVToColor(hsv);
290297
}
291298

299+
public static String colorToRGBString(int color) {
300+
int red = Color.red(color);
301+
int green = Color.green(color);
302+
int blue = Color.blue(color);
303+
return String.format(Locale.ROOT, "RGB(%d, %d, %d)", red, green, blue);
304+
}
292305

293306
}
294307

simpledialogfragments/src/main/java/eltos/simpledialogfragment/color/SimpleColorDialog.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,14 @@ public View getView(int position, View convertView, ViewGroup parent) {
401401
if (pair.first == PICKER){
402402
item.setColor(mCustomColor);
403403
item.setStyle(ColorView.Style.PALETTE);
404+
item.setContentDescription(getString(R.string.color_picker) + (mCustomColor == NONE ? "" : ": " + ColorView.colorToRGBString(mCustomColor)));
404405
} else {
405406
item.setColor(pair.first);
406407
item.setStyle(ColorView.Style.CHECK);
408+
if (pair.second != null) {
409+
item.setContentDescription(pair.second);
410+
}
407411
}
408-
item.setContentDescription(pair.second);
409412

410413
@ColorInt int outline = getArgs().getInt(OUTLINE, ColorView.NONE);
411414
if (outline != NONE){

simpledialogfragments/src/main/java/eltos/simpledialogfragment/form/ColorViewHolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected void setUpView(View view, final Context context, Bundle savedInstanceS
100100

101101
private void setColor(@ColorInt int color){
102102
colorView.setColor(color);
103-
if(field.colorNames != null && field.colorNames.length >= field.colors.length) {
103+
if (field.colorNames != null && field.colorNames.length >= field.colors.length) {
104104
for (int i = 0; i < field.colors.length; i++) {
105105
if (field.colors[i] == color) {
106106
colorView.setContentDescription(field.colorNames[i]);

0 commit comments

Comments
 (0)