Example usage for android.view Window getAttributes

List of usage examples for android.view Window getAttributes

Introduction

In this page you can find the example usage for android.view Window getAttributes.

Prototype

public final WindowManager.LayoutParams getAttributes() 

Source Link

Document

Retrieve the current window attributes associated with this panel.

Usage

From source file:Main.java

/**
 * Sets the screen brightness for this activity. The screen brightness will
 * change immediately. As soon as the activity terminates, the brightness will
 * return to the system brightness. Valid brightnesses range from 0 to 255.
 * //from   www .j a va  2s.c o m
 * @param window
 *          The activity window.
 * @param brightnessUnits
 *          An integer between 0 and 255.
 */
static void setActivityBrightness(Window window, int brightnessUnits) {
    // Set the brightness of the current window. This takes effect immediately.
    // When the window is closed, the new system brightness is used.
    // (Scale 0.0 - 1.0).
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.screenBrightness = brightnessUnits / 255.0f;
    window.setAttributes(lp);
}

From source file:enterprayz.megatools.Tools.java

@TargetApi(19)
private static void setTranslucentStatus(Activity activity, boolean on) {
    Window win = activity.getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    if (on) {/*w  w  w .jav a2s. co m*/
        winParams.flags |= bits;
    } else {
        winParams.flags &= ~bits;
    }
    win.setAttributes(winParams);
}

From source file:Main.java

public static void initializeScreenBrightness(Window win, ContentResolver resolver) {
    // Overright the brightness settings if it is automatic
    int mode = Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS_MODE,
            Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
    if (mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
        WindowManager.LayoutParams winParams = win.getAttributes();
        winParams.screenBrightness = DEFAULT_CAMERA_BRIGHTNESS;
        win.setAttributes(winParams);/*from  ww  w  .j  av a2s .co  m*/
    }
}

From source file:Main.java

public static void dimBackground(final float from, final float to, Activity context) {
    final Window window = context.getWindow();
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(from, to);
    valueAnimator.setDuration(500);//  w  ww .j  a  v a  2s .co  m
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            WindowManager.LayoutParams params = window.getAttributes();
            params.alpha = (Float) animation.getAnimatedValue();
            window.setAttributes(params);
        }
    });
    valueAnimator.start();
}

From source file:com.cardvlaue.sys.util.ScreenUtil.java

/**
 * ???Flyme4.0 ???Flyme/*from ww  w.j ava2s  .c om*/
 *
 * @param window ??
 * @param dark ????
 * @return boolean ?true
 */
public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) {
    boolean result = false;
    if (window != null) {
        try {
            WindowManager.LayoutParams lp = window.getAttributes();
            Field darkFlag = WindowManager.LayoutParams.class
                    .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
            Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
            darkFlag.setAccessible(true);
            meizuFlags.setAccessible(true);
            int bit = darkFlag.getInt(null);
            int value = meizuFlags.getInt(lp);
            if (dark) {
                value |= bit;
            } else {
                value &= ~bit;
            }
            meizuFlags.setInt(lp, value);
            window.setAttributes(lp);
            result = true;
        } catch (Exception e) {
            // e.printStackTrace();
        }
    }
    return result;
}

From source file:com.almalence.opencam.Fragment.java

public static void setScreenBrightness(boolean setMax) {
    try {//from  ww w. j a  va 2  s  . c o m
        Window window = thiz.getActivity().getWindow();

        WindowManager.LayoutParams layoutpars = window.getAttributes();

        // Set the brightness of this window
        if (setMax)
            layoutpars.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL;
        else
            layoutpars.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;

        // Apply attribute changes to this window
        window.setAttributes(layoutpars);
    } catch (Exception e) {

    }
}

From source file:com.almalence.util.Util.java

public static void enterLightsOutMode(Window window) {
    WindowManager.LayoutParams params = window.getAttributes();
    window.setAttributes(params);/*w  ww .java 2  s  . c o  m*/
}

From source file:com.xxxifan.devbox.core.util.ViewUtils.java

/**
 * set status bar icon to light theme, which is called dark mode.
 * should be called in onCreate()//from  w ww . j  ava 2s. c  o  m
 */
public static void setStatusBarLightMode(Activity activity, boolean lightMode) {
    if (activity == null || activity.getWindow() == null) {
        return;
    }

    Window window = activity.getWindow();
    boolean changed = false;
    // try miui
    try {
        Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        int darkIcon = field.getInt(layoutParams);
        Method extraFlagField = window.getClass().getMethod("setExtraFlags", int.class, int.class);
        extraFlagField.invoke(window, lightMode ? darkIcon : 0, darkIcon);
        changed = true;
    } catch (Exception ignored) {
    }

    // try flyme
    try {
        WindowManager.LayoutParams lp = window.getAttributes();
        Field darkIcon = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
        Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
        darkIcon.setAccessible(true);
        meizuFlags.setAccessible(true);
        int bit = darkIcon.getInt(null);
        int value = meizuFlags.getInt(lp);
        if (lightMode) {
            value |= bit;
        } else {
            value &= ~bit;
        }
        meizuFlags.setInt(lp, value);
        window.setAttributes(lp);
        changed = true;
    } catch (Exception ignored) {
    }

    if (!changed && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        int visibility = window.getDecorView().getSystemUiVisibility();
        if (lightMode) {
            visibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        } else {
            visibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
        }
        window.getDecorView().setSystemUiVisibility(visibility);
    }
}

From source file:com.esminis.server.library.dialog.about.AboutViewImpl.java

@Override
public void setupOnCreate() {
    final Window window = getWindow();
    final WindowManager.LayoutParams params = window.getAttributes();
    params.width = getContext().getResources().getDimensionPixelSize(R.dimen.about_dialog_width);
    params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    window.setAttributes(params);/*from  w  ww  .  j  ava2s .  co m*/
}

From source file:com.github.michaelins.lightstatusbar.LightStatusBar.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private void setTranslucentStatus(Window win, boolean on) {
    WindowManager.LayoutParams winParams = win.getAttributes();
    final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    if (on) {//from  w  ww.  j  a v  a  2  s .  com
        winParams.flags |= bits;
    } else {
        winParams.flags &= ~bits;
    }
    win.setAttributes(winParams);
}