亮度屏幕滤镜

发布于 2024-10-04 09:30:12 字数 201 浏览 0 评论 0原文

有谁知道如何实现像这里这样的亮度屏幕过滤器:

http: //www.appbrain.com/app/screen-filter/com.haxor

我需要一个起点,但我不知道该怎么做。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

拥醉 2024-10-11 09:30:12

只需制作一个透明的全屏活动,让触摸通过即可。要使触摸通过,请在设置 contentView 之前使用以下窗口标志:

@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);

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:

@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);
}

For your main.xml layout file just use a full screen LinearLayout with a transparent background:

<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>

Then to adjust the "brightness" just change the value of the background colour from your code somewhere:

findViewById(R.id.background).setBackgroundColor(0x66000000);
呆萌少年 2024-10-11 09:30:12
  • 获取 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.height = LayoutParams.FILL_PARENT; 
    布局Params.width = LayoutParams.FILL_PARENT;
    布局参数.flags = 280; // 你也可以尝试 LayoutParams.FLAG_FULLSCREEN
    layoutParams.format = PixelFormat.TRANSLUCENT; // 你可以尝试不同的格式
    layoutParams.windowAnimations = android.R.style.Animation_Toast; // 您只能使用系统可以访问的动画
    布局参数.type = 布局参数.TYPE_SYSTEM_OVERLAY;
    layoutParams.gravity = Gravity.BOTTOM;
    布局参数.x = 0;
    布局参数.y = 0;
    布局参数.verticalWeight = 1.0F;
    布局参数.horizo​​ntalWeight = 1.0F;
    布局参数.verticalMargin = 0.0F;
    布局参数.horizo​​ntalMargin = 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));
    返回新的 ColorDrawable(Color.argb(j, 0, 0, 0));}
    
  • 最后将视图添加到您之前创建的 windowManager 中。

    windowManager.addView(view, layoutParams);

注意:您需要 SYSTEM_ALERT_WINDOW 权限才能在屏幕上放置叠加层。

<uses-permission android:name="android.permission.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

    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;
    
  • Key step: You can set what percentage of brightness you need.
    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));}
    
  • 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.

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

Have tested this and it works. Let me know if you get stuck.

溺深海 2024-10-11 09:30:12

当然,您不能将其用作生产代码,但如果您正在玩……请尝试这个无证黑客

它使用:

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"/>

Of course, you can't use this as production code, but if you are playing around .. try this Undocumented hack

It uses :

private void setBrightness(int brightness) {
try {
  IHardwareService hardware = IHardwareService.Stub.asInterface(
   ServiceManager.getService("hardware"));
  if (hardware != null) {
    hardware.setScreenBacklight(brightness);
  }
 } catch (RemoteException doe) {          
  }        
 }

Remember that it uses this permission :

 <uses-permission android:name="android.permission.HARDWARE_TEST"/>
剩一世无双 2024-10-11 09:30:12

你也可以尝试这个:

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);

    }

You ca try this also:

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);

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文