亮度屏幕滤镜
Does anyone have an idea how to implement an Brightness Screen Filter like the one here:
http://www.appbrain.com/app/screen-filter/com.haxor
I need a starting point and I can't figure out how to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需制作一个透明的全屏活动,让触摸通过即可。要使触摸通过,请在设置 contentView 之前使用以下窗口标志:
对于 main.xml 布局文件,只需使用具有透明背景的全屏 LinearLayout:
然后要调整“亮度”,只需更改背景颜色的值某处代码:
Just make a transparent full screen activity that lets touches pass through. To make touches pass through use the following Window flags before setting the contentView:
For your main.xml layout file just use a full screen LinearLayout with a transparent background:
Then to adjust the "brightness" just change the value of the background colour from your code somewhere:
获取 WindowManager 的实例。
WindowManager windowManager = (WindowManager) Class.forName("android.view.WindowManagerImpl").getMethod("getDefault", new Class[0]).invoke(null, new Object[0]);< /code>
创建全屏布局xml(布局参数设置为
fill_parent
)将您的视图设置为不可点击、不可聚焦、不可长时间点击等,以便触摸传递到您的应用程序并且应用程序可以检测到它。
view.setFocusable(false);
view.setClickable(false);
view.setKeepScreenOn(false);
view.setLongClickable(false);
view.setFocusableInTouchMode(false);
创建一个
android.view.WindowManager.LayoutParams
类型的布局参数。LayoutParams layoutParams = new LayoutParams();
设置高度、宽度等布局参数
关键步骤:您可以设置所需的亮度百分比。
layoutParams.setBackgroundDrawable(getBackgroundDrawable(i));
最后将视图添加到您之前创建的 windowManager 中。
windowManager.addView(view, layoutParams);
注意:您需要
SYSTEM_ALERT_WINDOW
权限才能在屏幕上放置叠加层。已经测试过这个并且它有效。如果您遇到困难请告诉我。
Get an instance of WindowManager.
WindowManager windowManager = (WindowManager) Class.forName("android.view.WindowManagerImpl").getMethod("getDefault", new Class[0]).invoke(null, new Object[0]);
Create a full screen layout xml(layout parameters set to
fill_parent
)Set your view as not clickable, not focusable, not long clickable, etc so that touch is passed through to your app and the app can detect it.
view.setFocusable(false);
view.setClickable(false);
view.setKeepScreenOn(false);
view.setLongClickable(false);
view.setFocusableInTouchMode(false);
Create a layout parameter of type
android.view.WindowManager.LayoutParams
.LayoutParams layoutParams = new LayoutParams();
Set layout parameter like height, width etc
Key step: You can set what percentage of brightness you need.
layoutParams.setBackgroundDrawable(getBackgroundDrawable(i));
Finally add view to windowManager that you created earlier.
windowManager.addView(view, layoutParams);
Note: You need
SYSTEM_ALERT_WINDOW
permission to lay an overlay on the screen.Have tested this and it works. Let me know if you get stuck.
当然,您不能将其用作生产代码,但如果您正在玩……请尝试这个无证黑客
它使用:
记住它使用此权限:
Of course, you can't use this as production code, but if you are playing around .. try this Undocumented hack
It uses :
Remember that it uses this permission :
你也可以尝试这个:
You ca try this also: