Brightness Screen Filter
Asked Answered
F

4

17

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.

Forethought answered 26/11, 2010 at 14:24 Comment(2)
i have faced same issue. i have also posted this question #2222646. I was able to resolve the issue. U can see the right method in the post.Casady
try this link it may help you a little: android-er.blogspot.com/2011/02/…Cootch
T
8

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);
Tigre answered 26/11, 2010 at 18:3 Comment(6)
Thanks, it's working related to setting the transparency, but the touch events seems to work strange, I can scroll but when I click an program icon seems like it freeze (not quite freeze, but not opening the programs)Forethought
Any other ideas ?I don't think that having an transparent activity on top is the solutionForethought
I'm not giving up, nor I have any new ideas beside something related to OpenGL and surfaceview, but I still hope that someone could have a clear idea how this is done.Forethought
Alex, I do think my solution should work. I have done something similar and have no issues with touches getting passed through to the app behind. Try playing around with the window flags to see if you can make it workTigre
I have implemented independently almost this exact solution and it is working perfectly, even with sophisticated touch events like pinch-zoom. The touch events problem may be separate.Countermove
2016 window.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);Gossett
B
5
  • 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.

Breathtaking answered 16/4, 2013 at 10:12 Comment(1)
please can you post a complete answer to this question Using examples will be highly appreciatedUnblock
B
1

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"/>
Breve answered 9/12, 2010 at 10:33 Comment(1)
where can i find hardware09.jar? for this [tutorial(tutorialforandroid.com/2009/01/changing-screen-brightness.html)Unblock
B
0

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

    }
Borries answered 30/11, 2010 at 13:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.