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 getWindowFeatures(Activity activity) {
    Window window = activity.getWindow();
    if (window == null) {
        return 0;
    }//from   ww  w  . j  av  a 2 s.  c om
    try {
        // Method m =
        // activity.getWindow().getClass().getMethod("getFeatures");
        // Method[] m = window.getClass().getMethods();
        // m.setAccessible(true);
        // return (Integer) m.invoke(window);
        return 0;
    } catch (Exception e) {
        return 0;
    }
}

From source file:Main.java

/**
 * Force screen to turn on if the phone is asleep.
 *
 * @param context The current Context or Activity that this method is called from
 *///from  w  ww.ja  va 2 s  .  c o m
public static void turnScreenOn(Activity context) {
    try {
        Window window = context.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    } catch (Exception ex) {
        Log.e("PercolateAndroidUtils", "Unable to turn on screen for activity " + context);
    }
}

From source file:Main.java

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

From source file:Main.java

/**
 * Get the hamburger icon and return it (Used for setting colors to it)
 * @param activity activity referencing/*  w  w w. j a v  a2  s  .  c o m*/
 * @return
 */
public static View getToolbarHamburgerButton(Activity activity) {
    try {
        View view = ((View) activity.getWindow().getDecorView().findViewById(android.R.id.home));
        return view;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

/**
 * Sets custom title background colour,//  w w  w  .j  a  v  a2s . co  m
 * see http://stackoverflow.com/questions/2251714/set-title-background-color
 * @param colour
 */
public static void setApplicationTitleBackgroundColour(int colour, Activity activity) {
    View titleView = activity.getWindow().findViewById(android.R.id.title);
    if (titleView == null) {
        return;
    }
    ViewParent parent = titleView.getParent();
    if (parent == null || !(parent instanceof View)) {
        return;
    }
    View parentView = (View) parent;
    parentView.setBackgroundColor(colour);
}

From source file:Main.java

/**
 * get activity screen shot bitmap. system status bar is not included.
 * @param activity the activity//from   www.ja  v  a 2  s .c o  m
 * @return bitmap
 */
public static Bitmap capture(Activity activity) {
    View view = activity.getWindow().getDecorView();
    view.buildDrawingCache();
    Bitmap bitmap = 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(bitmap, 0, statusBarHeight, width, height - statusBarHeight);
    view.destroyDrawingCache();
    return b;
}

From source file:Main.java

public static int getStatusBarHeight(Activity context) {
    Rect rectangle = new Rect();
    Window window = context.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
    return rectangle.top;
}

From source file:Main.java

public static void changeBrightness(Activity activity, float brightness) {

    WindowManager.LayoutParams layout = activity.getWindow().getAttributes();
    layout.screenBrightness = brightness; //1F;
    activity.getWindow().setAttributes(layout);
}

From source file:Main.java

public static float getScreenDensity(Activity activity) {
    DisplayMetrics metric = new DisplayMetrics();
    activity.getWindow().getWindowManager().getDefaultDisplay().getMetrics(metric);

    return metric.density;
}

From source file:Main.java

public static void setScreeBrightness(int progress, Activity activity) {
    android.view.WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
    if (progress < 10) {
        progress = 10;/*w  w  w. j  ava  2s. c  o m*/
    } else if (progress >= 100) {
        progress = 99;
    }
    float f = progress * 1.0f / 100.0f;
    lp.screenBrightness = f;
    activity.getWindow().setAttributes(lp);
}