2

I've been trying to set the brightness under the limit of Android settings. There are two similar apps in Google Play doing this:

The second one, even allows to use the phone with a black screen, just what I need in my app.

There are a lot of other questions about brightness but not to set it under this system limit, and I've found one question asking almost the same but not helping me: Brightness Screen Filter

So after a lot of search I've got following code:

int brightness=0; //0 to 255, so I set it to a low level (not enough for me)
ContentResolver cResolver = getContentResolver();  

//set the system brightness value, and if active, disable auto mode.
System.putInt(cResolver, System.SCREEN_BRIGHTNESS, brightness);  
System.putInt(cResolver, System.SCREEN_BRIGHTNESS_MODE, System.SCREEN_BRIGHTNESS_MODE_MANUAL);  

//previous lines don't set the brightness to the current screen so we set it like this: 
LayoutParams layoutpars = getWindow().getAttributes();  
layoutpars.screenBrightness = brightness / (float)255; 

//Now we have brightness to the minimum allowed by Android but
//to achieve what these apps do, I have to reduce alpha of the window to the min
//then the screen is black like I want, and totally usable!
layoutpars.alpha=0.05f;
window.setAttributes(layoutpars);

Here the alpha is the key, this is doing what I want, but only for current window/screen, and I need to save to the system this alpha as default, like I'm doing with the brightness and the Manual mode for applying everywhere.

Do you know how I should do this? I'm unable to find a value "System.SCREEN_ALPHA" to set it with System.putInt or another way to do this.

In the other question I linked before, pheelicks replied with a suggestion of using a transparent non-touchable over screen, but this is not working for me, and the result does not give the feeling of a turned off screen like previous apps.

Thanks.

Community
  • 1
  • 1
Darklord5
  • 388
  • 5
  • 14

1 Answers1

0

I decided to implemented this feature just inside my app with alpha. So I couldn't solve the initial question at all....

Anyways, in the end seems that the solution to this question is the one Pheelicks replied here: https://stackoverflow.com/a/4287597/1667990

-This is launching an activity to be always on top,

-with alpha to 0.0f so it be transparent,

-that redirects the touch to the activity behind:

//Let touches go through to apps/activities underneath.
Window window = activity.getWindow();
window.addFlags(FLAG_NOT_TOUCHABLE);

-And most important thing not explained in the previous link, is to set the dim behind our window to 1 (like the dim in a messagebox, but setting to the max to be black behind :D )

window.setDimAmount ((float)1.0) ;
window.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
    WindowManager.LayoutParams.FLAG_DIM_BEHIND);

I haven't tried that and decided not to do it in my app as it could bring unexpected behavior in my circumstances, but I think it should definitely work, if anyone try please add your feedback!

Community
  • 1
  • 1
Darklord5
  • 388
  • 5
  • 14