If you think the Android project SeniorDesign listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package fakesetgame.seniordesign.view;
//www.java2s.comimport android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
* A custom ImageView that provides shading, for use in visually
* distinguishing selected game tiles from unselected tiles, without
* producing a set of shaded tile images.
*/publicclass ShadedImageView extends ImageView {
public ShadedImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
privateboolean shaded = false;
publicboolean getShaded() {
return shaded;
}
publicvoid setShaded(boolean shaded) {
if (this.shaded != shaded) {
this.shaded = shaded;
postInvalidate();
}
}
@Override
protectedvoid onDraw(@NonNull Canvas canvas) {
super.onDraw(canvas);
if(shaded) {
final RectF rectF = new RectF();
final Paint paint = new Paint();
paint.setARGB(65, 0, 0, 0);
rectF.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
canvas.drawRect(rectF, paint);
}
}
}