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

@TargetApi(Build.VERSION_CODES.KITKAT)
private static void transparentStatusBar(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {// ww  w .j ava  2s.c om
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
}

From source file:Main.java

public static void hideKeyboard(Activity a) {
    ((InputMethodManager) a.getSystemService(Context.INPUT_METHOD_SERVICE))
            .hideSoftInputFromWindow(a.getWindow().getDecorView().getWindowToken(), 0);
}

From source file:Main.java

public static void setFullScreen(Activity activity) {
    if (activity == null) {
        return;//  w  w w .java 2s  . co  m
    }
    WindowManager.LayoutParams params = activity.getWindow().getAttributes();
    params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    activity.getWindow().setAttributes(params);
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

From source file:Main.java

public static void setNoFullScreen(Activity activity) {
    if (activity == null) {
        return;//from   www  . ja v  a  2 s  .c om
    }
    WindowManager.LayoutParams params = activity.getWindow().getAttributes();
    params.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
    activity.getWindow().setAttributes(params);
    activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

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);/*  w w w .  j  a  v  a  2 s .com*/
    window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

From source file:Main.java

/**
 * @param activity/*from   w  ww.  jav a 2  s  .co  m*/
 * @return > 0 success; <= 0 fail
 */
public static int getStatusHeight(Activity activity) {
    int statusHeight = 0;
    Rect localRect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
    statusHeight = localRect.top;
    if (0 == statusHeight) {
        Class<?> localClass;
        try {
            localClass = Class.forName("com.android.internal.R$dimen");
            Object localObject = localClass.newInstance();
            int i5 = Integer.parseInt(localClass.getField("status_bar_height").get(localObject).toString());
            statusHeight = activity.getResources().getDimensionPixelSize(i5);
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException
                | IllegalArgumentException | SecurityException | NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
    return statusHeight;
}

From source file:Main.java

public static void setScreenBrightness(int paramInt, Activity mActivity) {
    if (paramInt <= 5) {
        paramInt = 5;//from   www .j a  v  a 2  s  . c  o 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 int getStatusHeight(Activity activity) {
    int statusHeight = 0;
    Rect localRect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
    statusHeight = localRect.top;/*from   ww  w . j a v a 2 s .  c om*/
    if (0 == statusHeight) {
        Class<?> localClass;
        try {
            localClass = Class.forName("com.android.internal.R$dimen");
            Object localObject = localClass.newInstance();
            int i5 = Integer.parseInt(localClass.getField("status_bar_height").get(localObject).toString());
            statusHeight = activity.getResources().getDimensionPixelSize(i5);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
    return statusHeight;
}

From source file:Main.java

public static boolean getBrightness(final Activity activity, float brightness) {
    final WindowManager.LayoutParams layoutParams = activity.getWindow().getAttributes();
    layoutParams.screenBrightness = brightness;

    if (isUIThread())
        activity.getWindow().setAttributes(layoutParams);
    else/*  w w  w .j  av  a 2s  .c o m*/
        activity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                activity.getWindow().setAttributes(layoutParams);

            }
        });

    return false;

}

From source file:Main.java

public static void setTranslucentForDrawerLayoutHalf(Activity activity, DrawerLayout drawerLayout) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        contentLayout.setFitsSystemWindows(true);
        contentLayout.setClipToPadding(true);
        ViewGroup vg = (ViewGroup) drawerLayout.getChildAt(1);
        vg.setFitsSystemWindows(false);/*  w w w  . j  a  v  a 2s  . c o  m*/
        drawerLayout.setFitsSystemWindows(false);
    }
}