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 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 .ja  v a 2  s.co m*/
}

From source file:Main.java

public static boolean isLandscapeMode(Activity activity) {
    Display d = activity.getWindowManager().getDefaultDisplay();
    if (d.getWidth() > d.getHeight())
        return true;
    else// w w w. j a  va 2s  .c o  m
        return false;
}

From source file:Main.java

@SuppressWarnings("deprecation")
/**/*from   www.ja  va 2s. c o m*/
 * Returns the screen/display size
 *
 * @param ctx
 * @return
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    return new Point(width, height);
}

From source file:Main.java

/**
 * Get current {@link Activity} screen width.
 * /*w w w .j  a  va2 s . com*/
 * @param activity Object of {@link Activity}
 * @return Screen width, failed will return 0.
 */
public final static int getScreenWidth(Activity activity) {
    if (null == activity) {
        return 0;
    }

    try {
        Display d = activity.getWindowManager().getDefaultDisplay();
        return d.getWidth();
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }
}

From source file:Main.java

/**
 * Gets the available width using only the DisplayMetrics class and removing known decorations.
 *//*from   ww  w .  ja v  a  2 s.  c  om*/
@SuppressWarnings("deprecation")
public static int getDisplayWidth(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    return display.getWidth();
}

From source file:Main.java

public static boolean is_tablet(Context ctx) {
    Display display = ((Activity) ctx).getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();

    if ((width > 1000) || (height > 1000))
        return true;
    else/*from   w w  w . j  av a 2s .  c  o m*/
        return false;
}

From source file:Main.java

/**
 *
 * @param activity//from w  w w . j av  a 2 s  . com
 * @return
 */
public static int getDisplaySmallerSideSize(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    return Math.min(display.getHeight(), display.getWidth());
}

From source file:Main.java

public static int getWidthScreen(Context context) {
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    return display.getWidth();
}

From source file:Main.java

public static Point getScreenSize(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    size.set(display.getWidth(), display.getHeight());
    return size;//from  w w  w.  j  av  a 2s  .  c  o  m
}

From source file:Main.java

/**
 * Get a BitmapDrawable from a local file that is scaled down
 * to fit the current Window size./* w w w . java  2s.  c o m*/
 */
@SuppressWarnings("deprecation")
public static BitmapDrawable getScaledDrawable(Activity a, String path) {
    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((float) srcHeight / ((float) destHeight) * 3);
        } else {
            inSampleSize = Math.round((float) srcWidth / ((float) destWidth) * 3);
        }
    }

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

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