【发布时间】:2014-02-12 12:58:50
【问题描述】:
我想做的是在我的应用程序顶部添加一个视图,这将是一个过滤视图(我想操纵屏幕的颜色),我还希望能够改变屏幕的亮度同时。这两件事似乎是分开工作的,但不是一起工作的。
这是我的代码:
添加视图:
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);
图层类:
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();
}
}
改变亮度:
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);
当我将视图添加到应用程序后,我想更改屏幕的亮度 - 亮度正在更改,但我无法单击屏幕上的任何内容。几秒钟后,我收到一条“应用程序未响应消息”。
是什么导致我的应用程序冻结?
提前致谢。
【问题讨论】: