set Window Brightness - Android User Interface

Android examples for User Interface:Window

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  . jav a2 s  .  c o m
        } 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