Example usage for android.view Display getWidth

List of usage examples for android.view Display getWidth

Introduction

In this page you can find the example usage for android.view Display getWidth.

Prototype

@Deprecated
public int getWidth() 

Source Link

Usage

From source file:Main.java

public static int getScreenOrientation(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    int orientation = Configuration.ORIENTATION_UNDEFINED;
    if (display.getWidth() == display.getHeight()) {
        orientation = Configuration.ORIENTATION_SQUARE;
    } else {/*from   w  ww  .java2 s  . c om*/
        if (display.getWidth() < display.getHeight()) {
            orientation = Configuration.ORIENTATION_PORTRAIT;
        } else {
            orientation = Configuration.ORIENTATION_LANDSCAPE;
        }
    }
    return orientation;
}

From source file:Main.java

public static Point getScreenSize(Context context) {
    if (screenSize != null) {
        return screenSize;
    }//from   w  w  w  .  j  a  v a2s. c  om
    int pxWidth;
    int pxHeight;

    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    pxWidth = display.getWidth();
    pxHeight = display.getHeight();

    screenSize = new Point(pxWidth, pxHeight);
    return screenSize;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static String getDisplayMetrics(Context ctx) {
    String metrics = "";
    try {//from  w w  w.ja v  a 2 s  .c  o  m
        Display display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
        metrics += width;
        metrics += "x";
        metrics += height;
    } catch (Exception e) {
    }

    return metrics;
}

From source file:Main.java

public static int getOrientation(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display getOrient = windowManager.getDefaultDisplay();
    int orientation = Configuration.ORIENTATION_UNDEFINED;
    if (getOrient.getWidth() == getOrient.getHeight()) {
        orientation = Configuration.ORIENTATION_SQUARE;
    } else {//from   w w w. ja  v  a  2 s .  c  o m
        if (getOrient.getWidth() < getOrient.getHeight()) {
            orientation = Configuration.ORIENTATION_PORTRAIT;
        } else {
            orientation = Configuration.ORIENTATION_LANDSCAPE;
        }
    }
    return orientation;
}

From source file:Main.java

public static int getScreenOrientation(Context context) {
    Display display = getDefaultDisplay(context);
    int orientation = Configuration.ORIENTATION_UNDEFINED;
    if (display.getWidth() == display.getHeight())
        orientation = Configuration.ORIENTATION_SQUARE;
    else {//from w  w  w  . j a  v a  2  s .c  o m
        if (display.getWidth() < display.getHeight())
            orientation = Configuration.ORIENTATION_PORTRAIT;
        else
            orientation = Configuration.ORIENTATION_LANDSCAPE;
    }

    return orientation;
}

From source file:Main.java

public static int getScreenOrientation(Activity activity) {
    Display getOrient = activity.getWindowManager().getDefaultDisplay();
    int orientation = Configuration.ORIENTATION_UNDEFINED;
    if (getOrient.getWidth() == getOrient.getHeight()) {
        orientation = Configuration.ORIENTATION_SQUARE;
    } else {//from www. jav a  2 s.  c o  m
        if (getOrient.getWidth() < getOrient.getHeight()) {
            orientation = Configuration.ORIENTATION_PORTRAIT;
        } else {
            orientation = Configuration.ORIENTATION_LANDSCAPE;
        }
    }
    return orientation;
}

From source file:Main.java

public static Bitmap getFitableBitmapWithReflection(Context context, Bitmap bitmap) {
    if (bitmap == null) {
        return null;
    }//from www  .  j  av a2s  .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

/**
 * <pre>/* ww w. j  a  v  a 2s. c  o m*/
 * Get sizes of screen in pixels.
 * </pre>
 * @return interger array with 2 elements: width and height
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
@SuppressWarnings("deprecation")
public static int[] getDisplaySizes() {
    Context context = getCurrentContext();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    if (Build.VERSION.SDK_INT < 13) {
        return new int[] { display.getWidth(), display.getHeight() };
    } else {
        Point point = new Point();
        display.getSize(point);
        return new int[] { point.x, point.y };
    }
}

From source file:Main.java

/**
 * Get a BitmapDrawable from a local file that is scaled down
 * to fit the current Window size./*  ww  w. j av  a  2 s  . co m*/
 */
@SuppressWarnings("deprecation")
static BitmapDrawable getScaledBitmap(String path, Activity a) {
    Display display = a.getWindowManager().getDefaultDisplay();
    float destWidth = display.getWidth();
    float destHeight = display.getHeight();

    // read in the dimensions of the image on disk
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, options);

    float srcWidth = options.outWidth;
    float srcHeight = options.outHeight;

    int inSampleSize = 1;
    if (srcHeight > destHeight || srcWidth > destWidth) {
        if (srcWidth > srcHeight) {
            inSampleSize = Math.round(srcHeight / destHeight);
        } else {
            inSampleSize = Math.round(srcWidth / destWidth);
        }
    }

    options = new BitmapFactory.Options();
    options.inSampleSize = inSampleSize;

    Bitmap bitmap = BitmapFactory.decodeFile(path, options);
    return new BitmapDrawable(a.getResources(), bitmap);
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getWindowWidth(Context context) {
    Display display = ((WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();/*  www  .  ja  v a 2s . c  o  m*/
    return display.getWidth();
}