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 getStatusBarHeight(Activity activity) {
    Rect rectgle = new Rect();
    Window window = activity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
    int StatusBarHeight = rectgle.top;
    return StatusBarHeight;
}

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  w  w  . j a va  2 s  .c om*/
    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:Main.java

private static void hideBar(Activity context) {
    if (Build.VERSION.SDK_INT < 16) {
        context.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {/*from  w  w w  .j av  a 2s .c o  m*/
        View decorView = context.getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    }
}

From source file:Main.java

private static void showBar(Activity context) {
    if (Build.VERSION.SDK_INT < 16) {
        context.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {//from  w  w w.j  a  va2  s.  c  o  m
        View decorView = context.getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
        decorView.setSystemUiVisibility(uiOptions);
    }
}

From source file:Main.java

public static void setScreenBrightness(Activity activity, float screenBrightness) {
    WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
    lp.screenBrightness = screenBrightness / 255f;
    activity.getWindow().setAttributes(lp);
}

From source file:Main.java

/**
 * get status bar plus app bar height, just content's({@link Window#ID_ANDROID_CONTENT}) top.
 *
 * @param activity/* w  w w .ja  v  a 2 s . c  o  m*/
 * @return
 */
public static int getContentTopHeight(Activity activity) {
    return activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
}

From source file:Main.java

public static Bitmap snapShotWithoutStatusBar(Activity activity) {
    View decorView = activity.getWindow().getDecorView();
    decorView.setDrawingCacheEnabled(true);
    decorView.buildDrawingCache();// w  w w  . j a v a2s.c  o  m
    Bitmap bmp = decorView.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;

    int width = getScreenWidth(activity);
    int height = getScreenHeight(activity);
    Bitmap bitMap = null;
    bitMap = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight);
    decorView.destroyDrawingCache();
    return bitMap;
}

From source file:Main.java

public static Bitmap snapShotWithoutStatusBar(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.setDrawingCacheEnabled(true);/*www .j a  v a2 s. co m*/
    view.buildDrawingCache();
    Bitmap bmp = view.getDrawingCache();
    Rect frame = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
    int statusBarHeight = frame.top;

    int width = getScreenWidth(activity);
    int height = getScreenHeight(activity);
    Bitmap bp = null;
    bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return bp;

}

From source file:Main.java

public static void onResume(Activity activity) {
    View decorView = activity.getWindow().getDecorView();
    hideSystemUI(decorView);/*w  w w. j  av  a  2  s .c o  m*/
    decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
            hideSystemUI(decorView);
        }
    });
}

From source file:Main.java

public static Bitmap getCrop(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.buildDrawingCache();//from   www. ja  v  a2 s  . c  om

    Rect rect = new Rect();
    view.getWindowVisibleDisplayFrame(rect);
    int stateBarHeight = rect.top;

    view.setDrawingCacheEnabled(true);

    Bitmap bmpCache = view.getDrawingCache();
    Bitmap bmp = Bitmap.createBitmap(bmpCache, 0, stateBarHeight, bmpCache.getWidth(),
            bmpCache.getHeight() - stateBarHeight);

    view.destroyDrawingCache();

    return bmp;
}