有没有人有一个想法如何实现像这里的一个的亮度滤网:亮度滤网
http://www.appbrain.com/app/screen-filter/com.haxor
我需要一个起点,我无法弄清楚如何做到这一点。
有没有人有一个想法如何实现像这里的一个的亮度滤网:亮度滤网
http://www.appbrain.com/app/screen-filter/com.haxor
我需要一个起点,我无法弄清楚如何做到这一点。
只需制作透明的全屏活动即可让触摸通过。为了使触摸通过使用下面的窗口标志设置内容查看前:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Window window = getWindow();
// Let touches go through to apps/activities underneath.
window.addFlags(FLAG_NOT_TOUCHABLE);
// Now set up content view
setContentView(R.layout.main);
}
为了您的main.xml布局文件只使用一个全屏幕的LinearLayout具有透明背景:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#33000000">
</LinearLayout>
然后调整“亮度”只是从你的代码某处改变背景颜色的值:
findViewById(R.id.background).setBackgroundColor(0x66000000);
您CA也试试这个:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.max_bright);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 100/100.0f;
getWindow().setAttributes(lp);
}
当然,你不能使用,这是生产代码,但如果你玩了..尝试这个Undocumented hack
它使用:
private void setBrightness(int brightness) {
try {
IHardwareService hardware = IHardwareService.Stub.asInterface(
ServiceManager.getService("hardware"));
if (hardware != null) {
hardware.setScreenBacklight(brightness);
}
} catch (RemoteException doe) {
}
}
请记住,使用此权限:
<uses-permission android:name="android.permission.HARDWARE_TEST"/>
获取一个实例的WindowManager。
WindowManager windowManager = (WindowManager) Class.forName("android.view.WindowManagerImpl").getMethod("getDefault", new Class[0]).invoke(null, new Object[0]);
创建一个全屏幕的布局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.height = LayoutParams.FILL_PARENT;
layoutParams.width = LayoutParams.FILL_PARENT;
layoutParams.flags = 280; // You can try LayoutParams.FLAG_FULLSCREEN too
layoutParams.format = PixelFormat.TRANSLUCENT; // You can try different formats
layoutParams.windowAnimations = android.R.style.Animation_Toast; // You can use only animations that the system to can access
layoutParams.type = LayoutParams.TYPE_SYSTEM_OVERLAY;
layoutParams.gravity = Gravity.BOTTOM;
layoutParams.x = 0;
layoutParams.y = 0;
layoutParams.verticalWeight = 1.0F;
layoutParams.horizontalWeight = 1.0F;
layoutParams.verticalMargin = 0.0F;
layoutParams.horizontalMargin = 0.0F;
关键的一步:你可以设置你所需要的百分比的亮度。 layoutParams.setBackgroundDrawable(getBackgroundDrawable(i));
private Drawable getBackgroundDrawable(int i) {
int j = 255 - (int) Math.round(255D * Math.exp(4D * ((double) i/100D) - 4D));
return new ColorDrawable(Color.argb(j, 0, 0, 0));}
最后补充以您先前创建的窗口管理。
windowManager.addView(view, layoutParams);
注意:您需要SYSTEM_ALERT_WINDOW
许可奠定了屏幕上的覆盖。
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
已经测试过,它的工作原理。让我知道如果你卡住了。
我面临同样的问题。我也发布了这个问题http://stackoverflow.com/questions/2222146/control-screen-brightness-in-android-using-background-service。我能解决这个问题。你可以在帖子中看到正确的方法。 – 2011-04-14 08:09:50
试试这个链接它可能会帮助你一点:http://android-er.blogspot.com/2011/02/change-android-screen-brightness.html – 2011-05-20 12:56:03