Example usage for android.content Context WINDOW_SERVICE

List of usage examples for android.content Context WINDOW_SERVICE

Introduction

In this page you can find the example usage for android.content Context WINDOW_SERVICE.

Prototype

String WINDOW_SERVICE

To view the source code for android.content Context WINDOW_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.view.WindowManager for accessing the system's window manager.

Usage

From source file:Main.java

public static Bitmap getFitableBitmapWithReflection(Context context, Bitmap bitmap) {
    if (bitmap == null) {
        return null;
    }/* ww w  .j a v  a2  s .  c  o m*/
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    int width = display.getWidth();
    float scale = 1.0f;
    if (width > 400) {
        scale = 1.8f;
    } else if (width > 300) {
        scale = 1.2f;
    } else {
        scale = 1.0f;
    }
    Log.i(TAG, "" + scale);
    Bitmap scaleBitmap = zoomBitmap(bitmap, scale);
    return createReflectionImageWithOrigin(scaleBitmap);
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getWindowWidth(Context context) {
    Display display = ((WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();/*w w w .jav  a 2 s .com*/
    return display.getWidth();
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getWindowHeight(Context context) {
    Display display = ((WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();//from   ww w.  j  a va 2  s . c om
    return display.getHeight();
}

From source file:Main.java

public static DisplayMetrics getDisplayMetrics(Context context) {
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);/*from  w  w  w. jav a  2s  .  c o m*/
    return metrics;
}

From source file:Main.java

public static int getSurfaceOrientation(Activity activity) {

    // Sanity check:
    if (activity == null) {
        return -1; // invalid value
    }/*from ww w.j  a  va  2s. c  om*/

    Configuration config = activity.getResources().getConfiguration();
    Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    int displayRotation;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        displayRotation = display.getRotation(); // only available from Froyo
    } else {
        displayRotation = display.getOrientation();
    }

    int activityOrientation = SCREEN_ORIENTATION_UNKNOWN;

    switch (config.orientation) {
    case Configuration.ORIENTATION_PORTRAIT:
    case Configuration.ORIENTATION_SQUARE:
        activityOrientation = ((displayRotation == Surface.ROTATION_0
                || displayRotation == Surface.ROTATION_270) ? SCREEN_ORIENTATION_PORTRAIT
                        : SCREEN_ORIENTATION_PORTRAITUPSIDEDOWN);
        break;

    case Configuration.ORIENTATION_LANDSCAPE:
        activityOrientation = ((displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_90)
                ? SCREEN_ORIENTATION_LANDSCAPELEFT
                : SCREEN_ORIENTATION_LANDSCAPERIGHT);
        break;

    case Configuration.ORIENTATION_UNDEFINED:
    default:
        break;
    }

    return activityOrientation;
}

From source file:Main.java

/**
 * Returns a valid DisplayMetrics object
 *
 * @param context valid context//from  ww w.ja v a 2s  . c  om
 * @return DisplayMetrics object
 */
public static DisplayMetrics getDisplayMetrics(final Context context) {
    final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    final DisplayMetrics metrics = new DisplayMetrics();
    windowManager.getDefaultDisplay().getMetrics(metrics);
    return metrics;
}

From source file:Main.java

public static Rect getDisplaySize(Context context) {
    Rect rect = new Rect();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    rect.set(0, 0, display.getWidth(), display.getHeight());
    return rect;/*from  w  w  w . java 2  s. c  om*/
}

From source file:Main.java

/**
 * Returns the screen/display size/*from w ww .  ja  v a2  s  . c o m*/
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size;
}

From source file:Main.java

private static Point getScreenSizeInternal(final Context context) {
    Point size = null;//from  w  w w.  jav a2 s .co  m
    final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    if (windowManager != null) {
        final Display display = windowManager.getDefaultDisplay();
        if (display != null) {
            // only works if Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2
            size = new Point();
            display.getSize(size);
        }
    }
    return size;
}

From source file:Main.java

public static DisplayMetrics getScreenPix(Context context) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(dm);
    return dm;/*  w ww . j a  v a 2 s .  c  o  m*/
}