Example usage for android.app Activity getWindowManager

List of usage examples for android.app Activity getWindowManager

Introduction

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

Prototype

public WindowManager getWindowManager() 

Source Link

Document

Retrieve the window manager for showing custom windows.

Usage

From source file:tv.ouya.sdk.OuyaUnityPlugin.java

private static int getDisplayHeight() {
    Activity activity = IOuyaActivity.GetActivity();
    WindowManager windowManager = activity.getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);// www.  ja  v a 2s .co  m
    return size.y;
}

From source file:menion.android.whereyougo.gui.extension.activity.CustomActivity.java

protected static void customOnCreate(Activity activity) {
    // Logger.v(activity.getLocalClassName(), "customOnCreate(), id:" +
    // activity.hashCode());
    // set main activity parameters
    if (!(activity instanceof CustomMainActivity)) {
        // Settings.setLanguage(this);
        setScreenBasic(activity);/*  w w  w.  ja v a 2 s  .  co m*/
    }

    // set screen size
    Const.SCREEN_WIDTH = activity.getWindowManager().getDefaultDisplay().getWidth();
    Const.SCREEN_HEIGHT = activity.getWindowManager().getDefaultDisplay().getHeight();

    switch (Preferences.APPEARANCE_FONT_SIZE) {
    case PreferenceValues.VALUE_FONT_SIZE_SMALL:
        activity.setTheme(R.style.FontSizeSmall);
        break;
    case PreferenceValues.VALUE_FONT_SIZE_MEDIUM:
        activity.setTheme(R.style.FontSizeMedium);
        break;
    case PreferenceValues.VALUE_FONT_SIZE_LARGE:
        activity.setTheme(R.style.FontSizeLarge);
        break;
    }
}

From source file:Main.java

public static HashMap<String, Integer> parseImageSizeWithUrl(Activity activity, String imageUrl) {

    int widthPx = DEFAULT_POST_IMAGE_WIDTH;
    int heightPx = DEFAULT_POST_IMAGE_HEIGHT;

    String[] file = imageUrl.split("\\.");
    int index = file.length - 2;
    String[] snippet = file[index].split("_");

    int snippetCount = snippet.length;
    if (snippetCount >= 3) {

        if (null != snippet[1]) {
            widthPx = Integer.parseInt(snippet[1]);
        }//from w w w .ja v  a2 s .c o  m

        if (null != snippet[2]) {
            heightPx = Integer.parseInt(snippet[2]);
        }
    }
    WindowManager windowManager = activity.getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    int screenWidth = 0;
    int screenHeight = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
    } else {
        screenWidth = display.getWidth();
        screenHeight = display.getHeight();
    }

    if (widthPx > screenWidth) {
        widthPx = screenWidth;
    } else if (widthPx < DEFAULT_POST_IMAGE_WIDTH) {
        widthPx = DEFAULT_POST_IMAGE_WIDTH;
    }

    if (heightPx > screenHeight) {
        heightPx = screenHeight;
    } else if (heightPx < DEFAULT_POST_IMAGE_HEIGHT) {
        heightPx = DEFAULT_POST_IMAGE_HEIGHT;
    }

    HashMap<String, Integer> imageSize = new HashMap<String, Integer>();
    imageSize.put("widthPx", widthPx);
    imageSize.put("heightPx", heightPx);
    return imageSize;
}

From source file:com.android.purenexussettings.TinkerActivity.java

public static void lockCurrentOrientation(Activity activity) {
    int currentRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int orientation = activity.getResources().getConfiguration().orientation;
    int frozenRotation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
    switch (currentRotation) {
    case Surface.ROTATION_0:
        frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
                ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
                : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        break;/*from   ww  w.  j a v  a 2s.c  o  m*/
    case Surface.ROTATION_90:
        frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
                ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
                : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        break;
    case Surface.ROTATION_180:
        frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
                ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
                : ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
        break;
    case Surface.ROTATION_270:
        frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
                ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
                : ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
        break;
    }
    activity.setRequestedOrientation(frozenRotation);
}

From source file:Main.java

public static Size getOptimalPreviewSize(Activity currentActivity, List<Size> sizes, double targetRatio) {
    // Use a very small tolerance because we want an exact match.
    final double ASPECT_TOLERANCE = 0.001;
    if (sizes == null)
        return null;

    Size optimalSize = null;//from  ww  w  .  ja v  a 2 s .  c  om
    double minDiff = Double.MAX_VALUE;

    // Because of bugs of overlay and layout, we sometimes will try to
    // layout the viewfinder in the portrait orientation and thus get the
    // wrong size of mSurfaceView. When we change the preview size, the
    // new overlay will be created before the old one closed, which causes
    // an exception. For now, just get the screen size

    Display display = currentActivity.getWindowManager().getDefaultDisplay();
    int targetHeight = Math.min(display.getHeight(), display.getWidth());

    if (targetHeight <= 0) {
        // We don't know the size of SurfaceView, use screen height
        targetHeight = display.getHeight();
    }

    // Try to find an size match aspect ratio and size
    for (Size size : sizes) {
        double ratio = (double) size.width / size.height;
        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
            continue;
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }

    // Cannot find the one match the aspect ratio. This should not happen.
    // Ignore the requirement.
    if (optimalSize == null) {
        Log.w(TAG, "No preview size match the aspect ratio");
        minDiff = Double.MAX_VALUE;
        for (Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}

From source file:de.spiritcroc.modular_remote.Util.java

public static int suggestBlockSize(Activity activity, boolean yDir) {
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    double size;//from  w  w  w  . j a va2s.c o m
    if (yDir) {
        size = (double) dm.heightPixels / (double) dm.densityDpi;
    } else {
        size = (double) dm.widthPixels / (double) dm.densityDpi;
    }
    return ((int) (size / suggestedBlockSizeInInch / suggestMultipleOf)) * suggestMultipleOf;
}

From source file:com.todoroo.astrid.activity.FilterListFragment.java

public static Bitmap superImposeListIcon(Activity activity, Bitmap listingIcon, String listingTitle) {
    Bitmap emblem = listingIcon;//from w  w  w .j a  va  2  s.c om
    if (emblem == null)
        emblem = ((BitmapDrawable) activity.getResources()
                .getDrawable(TagService.getDefaultImageIDForTag(listingTitle))).getBitmap();

    // create icon by superimposing astrid w/ icon
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    Bitmap bitmap = ((BitmapDrawable) activity.getResources().getDrawable(R.drawable.icon_blank)).getBitmap();
    bitmap = bitmap.copy(bitmap.getConfig(), true);
    Canvas canvas = new Canvas(bitmap);
    int dimension = 22;
    canvas.drawBitmap(emblem, new Rect(0, 0, emblem.getWidth(), emblem.getHeight()),
            new Rect(bitmap.getWidth() - dimension, bitmap.getHeight() - dimension, bitmap.getWidth(),
                    bitmap.getHeight()),
            null);
    return bitmap;
}

From source file:com.almalence.util.Util.java

public static int getDisplayRotation(Activity activity) {
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    switch (rotation) {
    case Surface.ROTATION_0:
        return 0;
    case Surface.ROTATION_90:
        return 90;
    case Surface.ROTATION_180:
        return 180;
    case Surface.ROTATION_270:
        return 270;
    default:/*from   www.jav  a  2 s  . c  om*/
        break;
    }
    return 0;
}

From source file:org.csware.ee.utils.Tools.java

public static int getScreenWidth(Activity context) {
    DisplayMetrics dm = new DisplayMetrics();
    context.getWindowManager().getDefaultDisplay().getMetrics(dm);
    return dm.widthPixels;
}

From source file:com.gm.goldencity.util.Utils.java

/**
 * Get Display Width//from   w  w w  .j  a  va2  s.co  m
 *
 * @param context Application context
 * @return
 */
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static int getDisplayWidth(Context context) {
    Activity activity = (Activity) context;
    if (Integer.valueOf(Build.VERSION.SDK_INT) < 13) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        return display.getWidth();
    } else {
        Display display = activity.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        return size.x;
    }
}