I have Activity that is started from GCM with FLAG_TURN_SCREEN_ON
Below is the code snippet:-
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
addFlags();
}
private void addFlags() {
//Screen On
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
private void clearFlags() {
//Don't forget to clear the flags at some point in time.
getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (!hasFocus) {
clearFlags();
}
super.onWindowFocusChanged(hasFocus);
}
After device wake up I want to schedule screen DIM (after 15 sec I use AA framework). I have try to clearFlags() after 15 sec but nothings changed.
@UiThread(delay = 15000)
void dimDisplay() {
if (!isFinishing()) {
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0.0f;// i needed to dim the display
getWindow().setAttributes(params);
}
}
and after user touch screen screenBrightness=1
@Touch
void container() {
if (!isFinishing()) {
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 1f;
getWindow().setAttributes(params);
}
}
Do you know more clean solution of the problem.. this code DIM display only one time. And I want to avoid usage of deprecated PowerManager.SCREEN_DIM_WAKE_LOCK
/** @deprecated Most applications should use
* {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} instead
* of this type of wake lock, as it will be correctly managed by the platform
* as the user moves between applications and doesn't require a special permission.
*/
@Deprecated
public static final int SCREEN_DIM_WAKE_LOCK = 0x00000006;
User contributions licensed under CC BY-SA 3.0