CLICK DISPLAY ;
image_code.setBackground(Drawables.getSelectableDrawableFor(Color.parseColor("#E0E0E0")));
image_code.setClickable(true);
}
public static class Drawables {
public static android.graphics.drawable.Drawable getSelectableDrawableFor(int color) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
android.graphics.drawable.StateListDrawable stateListDrawable = new android.graphics.drawable.StateListDrawable();
stateListDrawable.addState(
new int[]{android.R.attr.state_pressed},
new android.graphics.drawable.ColorDrawable(Color.parseColor("#ffffff"))
);
stateListDrawable.addState(
new int[]{android.R.attr.state_focused},
new android.graphics.drawable.ColorDrawable(Color.parseColor("#00ffffff"))
);
stateListDrawable.addState(
new int[]{},
new android.graphics.drawable.ColorDrawable(Color.parseColor("#00ffffff"))
);
return stateListDrawable;
} else {
android.content.res.ColorStateList pressedColor = android.content.res.ColorStateList.valueOf(color);
android.graphics.drawable.ColorDrawable defaultColor = new android.graphics.drawable.ColorDrawable(Color.parseColor("#00ffffff"));
android.graphics.drawable.Drawable rippleColor = getRippleColor(color);
return new android.graphics.drawable.RippleDrawable(
pressedColor,
defaultColor,
rippleColor
);
}
}
private static android.graphics.drawable.Drawable getRippleColor(int color) {
float[] outerRadii = new float[8];
Arrays.fill(outerRadii, 0);
android.graphics.drawable.shapes.RoundRectShape r = new android.graphics.drawable.shapes.RoundRectShape(outerRadii, null, null);
android.graphics.drawable.ShapeDrawable shapeDrawable = new
android.graphics.drawable.ShapeDrawable(r);
shapeDrawable.getPaint().setColor(color);
return shapeDrawable;
}
private static int lightenOrDarken(int color, double fraction) {
if (canLighten(color, fraction)) {
return lighten(color, fraction);
} else {
return darken(color, fraction);
}
}
private static int lighten(int color, double fraction) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
red = lightenColor(red, fraction);
green = lightenColor(green, fraction);
blue = lightenColor(blue, fraction);
int alpha = Color.alpha(color);
return Color.argb(alpha, red, green, blue);
}
private static int darken(int color, double fraction) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
red = darkenColor(red, fraction);
green = darkenColor(green, fraction);
blue = darkenColor(blue, fraction);
int alpha = Color.alpha(color);
return Color.argb(alpha, red, green, blue);
}
private static boolean canLighten(int color, double fraction) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
return canLightenComponent(red, fraction)
&& canLightenComponent(green, fraction)
&& canLightenComponent(blue, fraction);
}
private static boolean canLightenComponent(int colorComponent, double fraction) {
int red = Color.red(colorComponent);
int green = Color.green(colorComponent);
int blue = Color.blue(colorComponent);
return red + (red * fraction) < 255
&& green + (green * fraction) < 255
&& blue + (blue * fraction) < 255;
}
private static int darkenColor(int color, double fraction) {
return (int) Math.max(color - (color * fraction), 0);
}
private static int lightenColor(int color, double fraction) {
return (int) Math.min(color + (color * fraction), 255);
}
}
public static class CircleDrawables {
public static android.graphics.drawable.Drawable getSelectableDrawableFor(int color) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
android.graphics.drawable.StateListDrawable stateListDrawable = new android.graphics.drawable.StateListDrawable();
stateListDrawable.addState(
new int[]{android.R.attr.state_pressed},
new android.graphics.drawable.ColorDrawable(Color.parseColor("#ffffff"))
);
stateListDrawable.addState(
new int[]{android.R.attr.state_focused},
new android.graphics.drawable.ColorDrawable(Color.parseColor("#00ffffff"))
);
stateListDrawable.addState(
new int[]{},
new android.graphics.drawable.ColorDrawable(Color.parseColor("#00ffffff"))
);
return stateListDrawable;
} else {
android.content.res.ColorStateList pressedColor = android.content.res.ColorStateList.valueOf(color);
android.graphics.drawable.ColorDrawable defaultColor = new android.graphics.drawable.ColorDrawable(Color.parseColor("#00ffffff"));
android.graphics.drawable.Drawable rippleColor = getRippleColor(color);
return new android.graphics.drawable.RippleDrawable(
pressedColor,
defaultColor,
rippleColor
);
}
}
private static android.graphics.drawable.Drawable getRippleColor(int color) {
float[] outerRadii = new float[180];
Arrays.fill(outerRadii, 80);
android.graphics.drawable.shapes.RoundRectShape r = new android.graphics.drawable.shapes.RoundRectShape(outerRadii, null, null);
android.graphics.drawable.ShapeDrawable shapeDrawable = new
android.graphics.drawable.ShapeDrawable(r);
shapeDrawable.getPaint().setColor(color);
return shapeDrawable;
}
private static int lightenOrDarken(int color, double fraction) {
if (canLighten(color, fraction)) {
return lighten(color, fraction);
} else {
return darken(color, fraction);
}
}
private static int lighten(int color, double fraction) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
red = lightenColor(red, fraction);
green = lightenColor(green, fraction);
blue = lightenColor(blue, fraction);
int alpha = Color.alpha(color);
return Color.argb(alpha, red, green, blue);
}
private static int darken(int color, double fraction) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
red = darkenColor(red, fraction);
green = darkenColor(green, fraction);
blue = darkenColor(blue, fraction);
int alpha = Color.alpha(color);
return Color.argb(alpha, red, green, blue);
}
private static boolean canLighten(int color, double fraction) {
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
return canLightenComponent(red, fraction)
&& canLightenComponent(green, fraction)
&& canLightenComponent(blue, fraction);
}
private static boolean canLightenComponent(int colorComponent, double fraction) {
int red = Color.red(colorComponent);
int green = Color.green(colorComponent);
int blue = Color.blue(colorComponent);
return red + (red * fraction) < 255
&& green + (green * fraction) < 255
&& blue + (blue * fraction) < 255;
}
private static int darkenColor(int color, double fraction) {
return (int) Math.max(color - (color * fraction), 0);
}
private static int lightenColor(int color, double fraction) {
return (int) Math.min(color + (color * fraction), 255);
}
0 Comments: