I'm trying to make app for Android which manipulate its screen (its colours, to be specific). I've got these two following classes:
static class ScreenAdjuster {
public static void setAlpha(Layer view, int alpha){
//Handle all conditions
view.setColor(alpha, 0, 0, 0);
}
public static void setContrast(Layer view, int contrast){
//Handle all conditions
view.setColor(contrast, 100, 100, 100);
}
public static void setColor(Layer redView, Layer greenView, Layer blueView, int r, int g, int b){
//Handle all conditions
redView.setColor(r, 255, 0, 0);
greenView.setColor(g, 0, 255, 0);
blueView.setColor(b, 0, 0, 255);
Log.d("display", "setting..." + r + " " + g + " " + b);
}
}
class Layer extends View
{
private int a;
private int b;
private int g;
private int r;
public Layer(Context context){
super(context);
}
@Override
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
canvas.drawARGB(this.a, this.r, this.g, this.b);
Log.d("display", "rendering..");
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
this.setMeasuredDimension(parentWidth/2, parentHeight);
this.setLayoutParams(new ViewGroup.LayoutParams(parentWidth/2,parentHeight));
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Log.d("display", "filling...");
}
public void setColor(int a, int r, int g, int b){
this.a = a;
this.r = r;
this.g = g;
this.b = b;
invalidate();
}
}
I'm adding views to manager in this function:
public void setColorsViews() {
if(!colorsFirstTime) {
view = new Layer(cordova.getActivity());
redView = new Layer(cordova.getActivity());
greenView = new Layer(cordova.getActivity());
blueView = new Layer(cordova.getActivity());
WindowManager localWindowManager = (WindowManager)cordova.getActivity().getSystemService("window");
WindowManager.LayoutParams layoutParams = cordova.getActivity().getWindow().getAttributes();
localWindowManager.addView(view, layoutParams);
localWindowManager.addView(greenView, layoutParams);
localWindowManager.addView(redView, layoutParams);
localWindowManager.addView(blueView, layoutParams);
colorsFirstTime = true;
Log.d("display", "views added");
}
}
(It will be plugin for Cordova, so I get Activity by cordova.getActivity()
. It works with my another functions, so I suppose it works here too).
I invoke all this by: ScreenAdjuster.setColor(redView, greenView, blueView, red, green, blue) ;
But... nothing happens. All functions are invoked( onDraw()
, onMeasure()
, setColorsViews()
, but screen remains the same.
What am I doing wrong?
Thanks in advance!