What I want to do is add a view on top of my application which will be sort of a filter view (I want to manipulate the colors of the screen) and I also want to be able to change the brightness of the screen at the same time. Both of these things seem to work separately, but not together.
Here is my code:
Adding view:
colourView = new Layer(cordova.getActivity());
WindowManager localWindowManager = (WindowManager) cordova.getActivity().getWindowManager();
LayoutParams layoutParams = cordova.getActivity().getWindow().getAttributes();
layoutParams.format = PixelFormat.TRANSLUCENT;
layoutParams.type=LayoutParams.TYPE_SYSTEM_ALERT;
layoutParams.flags=LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_NOT_FOCUSABLE | LayoutParams.FLAG_NOT_TOUCHABLE;
layoutParams.gravity=Gravity.LEFT|Gravity.TOP;
localWindowManager.addView(colourView, layoutParams);
Layer class:
class Layer extends View
{
private int a = 0;
private int b = 0;
private int g = 0;
private int r = 0;
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);
//Since you are attatching it to the window use window layout params.
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(parentWidth / 2,
parentHeight);
this.setLayoutParams(layoutParams);
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();
}
}
Changing brightness:
WindowManager.LayoutParams layout = cordova.getActivity().getWindow().getAttributes();
try {
layout.screenBrightness = (float) arg_object.getDouble("brightness");
// ^ When I comment this line, it doesn't work either.
} catch (JSONException e) {
e.printStackTrace();
}
cordova.getActivity().getWindow().setAttributes(layout);
When I add the view to the application and, after that, I want to change brightness of the screen - brightness is changing, but I can't click on anything on the screen. After few second I get an 'Application not responding message.
What causes my application to freeze?
Thanks in advance.