Example usage for android.app Activity getWindow

List of usage examples for android.app Activity getWindow

Introduction

In this page you can find the example usage for android.app Activity getWindow.

Prototype

public Window getWindow() 

Source Link

Document

Retrieve the current android.view.Window for the activity.

Usage

From source file:Main.java

public static int getScreenStatusBarHeight(Activity activity) {
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    return frame.top;
}

From source file:Main.java

public static void makeVisible(Activity activity) {
    Window w = activity.getWindow(); // in Activity's onCreate() for
    // instance// w  w  w . j a v  a 2 s  . co m
    int flags = /*
                 * WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
                 */WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
    w.setFlags(flags, flags);
}

From source file:Main.java

public static void setTranslucentStatus(Activity activity, boolean on) {
    Window win = activity.getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    if (on)/*from  w  ww  . j  a  v  a2 s . c o m*/
        winParams.flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    else
        winParams.flags &= ~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    win.setAttributes(winParams);
}

From source file:Main.java

public static void hideNotificationBar(Activity aContext) {
    WindowManager.LayoutParams attrs = aContext.getWindow().getAttributes();
    attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    aContext.getWindow().setAttributes(attrs);
}

From source file:Main.java

public static Bitmap takeScreenShot(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);//  w  w w. j  a v  a 2 s .  c om
    view.buildDrawingCache();
    Bitmap b1 = view.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;
    int width = activity.getWindowManager().getDefaultDisplay().getWidth();
    int height = activity.getWindowManager().getDefaultDisplay().getHeight();

    Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return b;
}

From source file:Main.java

public static float getBrightness(Activity activity) {

    return activity.getWindow().getAttributes().screenBrightness;
}

From source file:Main.java

public static int getStatusBarHeight(Activity activity) {
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;
    return statusBarHeight;
}

From source file:Main.java

public static void showStatusBar(Activity activity) {
    WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
    attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    activity.getWindow().setAttributes(attrs);
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

From source file:Main.java

public static void hideStatusBar(Activity activity) {
    WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
    attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    activity.getWindow().setAttributes(attrs);
    activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

From source file:Main.java

public static boolean isFullScreen(Activity activity) {
    WindowManager.LayoutParams params = activity.getWindow().getAttributes();
    return (params.flags
            & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN;
}