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

public static void setScreenBrightness(int paramInt, Activity context) {
    Window localWindow = context.getWindow();
    WindowManager.LayoutParams localLayoutParams = localWindow.getAttributes();
    float f = paramInt / 255.0F;
    localLayoutParams.screenBrightness = f;
    localWindow.setAttributes(localLayoutParams);
}

From source file:Main.java

/**
 * set status bar translucency//from   www  . j  a  va2 s  .c o m
 */
public static void setTranslucentStatus(Activity activity, boolean on) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window win = activity.getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }
}

From source file:Main.java

public static void setFullScreen(Activity activity) {
    activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
    Window window = activity.getWindow();
    WindowManager.LayoutParams params = window.getAttributes();
    params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    window.setAttributes(params);/*from   www  .j a  v a 2s  . c om*/
    window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

From source file:Main.java

public static void setFullScreen(Activity activity, boolean isFull) {
    Window window = activity.getWindow();
    WindowManager.LayoutParams params = window.getAttributes();
    if (isFull) {
        params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
        window.setAttributes(params);/*from w w  w  .ja  v a 2  s .  co m*/
        window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    } else {
        params.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
        window.setAttributes(params);
        window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }
}

From source file:Main.java

/**
 * @param pActivity/*from   ww w  . ja v a 2s.co m*/
 * @param pScreenBrightness [0..1]
 */
public static void setScreenBrightness(final Activity pActivity, final float pScreenBrightness) {
    final Window window = pActivity.getWindow();
    final WindowManager.LayoutParams windowLayoutParams = window.getAttributes();
    windowLayoutParams.screenBrightness = pScreenBrightness;
    window.setAttributes(windowLayoutParams);
}

From source file:Main.java

public static void setScreenBrightness(int paramInt, Activity mActivity) {
    if (paramInt <= 5) {
        paramInt = 5;/* w  w w  .j  av a 2 s .  co  m*/
    }
    Window localWindow = mActivity.getWindow();
    WindowManager.LayoutParams localLayoutParams = localWindow.getAttributes();
    float f = paramInt / 100.0F;
    localLayoutParams.screenBrightness = f;
    localWindow.setAttributes(localLayoutParams);
}

From source file:Main.java

public static void setWindowBrightness(Activity activity, float screenBrightness) {
    float brightness = screenBrightness;
    if (screenBrightness < 1) {
        brightness = 1;/*  w ww  .j a v 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);
}

From source file:Main.java

public static boolean setStatusBarDarkIcon(Window window, boolean dark) {
    boolean result = false;
    if (window != null) {
        try {/*www . j a  v a2 s .  c om*/
            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 ignored) {
        }
    }
    return result;
}

From source file:Main.java

/**
 * meizu Flyme set status bar light mode
 */// ww  w  .j  av a 2s .  co m
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) {

        }
    }
    return result;
}

From source file:Main.java

public static void showAsPopup(Activity activity) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        return;/*from w  w w  . j  a  v  a2 s  .c o  m*/
    }
    activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);

    //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
    Window window = activity.getWindow();
    window.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

    Display display = activity.getWindowManager().getDefaultDisplay();
    WindowManager.LayoutParams params = window.getAttributes();
    params.height = (int) (display.getHeight() * 0.95);
    params.width = Math.min((int) (display.getWidth() * 0.9), (int) (params.height * 0.85));
    params.gravity = Gravity.BOTTOM;
    params.alpha = 1.0f;
    params.dimAmount = 0.5f;
    window.setAttributes(params);
}