set Window Brightness - Android Phone

Android examples for Phone:Screen

Description

set Window Brightness

Demo Code


//package com.java2s;

import android.app.Activity;

import android.view.Window;
import android.view.WindowManager;

public class Main {

    public static void setWindowBrightness(Activity activity,
            float screenBrightness) {
        float brightness = screenBrightness;
        if (screenBrightness < 1) {
            brightness = 1;/*from w w w.  j ava 2s . com*/
        } else if (screenBrightness > 255) {
            brightness = screenBrightness % 255;
            if (brightness == 0) {
                brightness = 255;
            }
        }
        Window window = activity.getWindow();
        WindowManager.LayoutParams localLayoutParams = window
                .getAttributes();
        localLayoutParams.screenBrightness = (float) brightness / 255;
        window.setAttributes(localLayoutParams);
    }
}

Related Tutorials