Android Utililty Methods Screen Size Get

List of utility methods to do Screen Size Get

Description

The list of methods to do Screen Size Get are organized into topic(s).

Method

intgetMinTouchWidth(Context context)
get Min Touch Width
retrieveDisplayMetrics(context);
return (int) (MIN_TOUCH_SIZE * _display_metrics.density * STANDARD_DPI);
intgetDisplayHeight(Context context)
get Display Height
Display display = ((WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE))
        .getDefaultDisplay();
return display.getHeight() - getStatusBarHeight(display.getWidth());
StringgetDisplayMetrics(Context context)
get Display Metrics
WindowManager windowManager = (WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(metrics);
return String.format("%dx%d", metrics.widthPixels,
        metrics.heightPixels);
intgetDisplayWidth(Context context)
get Display Width
Display display = ((WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE))
        .getDefaultDisplay();
return display.getWidth();
intgetRawDisplayHeight(Context context)
get Raw Display Height
Display display = ((WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE))
        .getDefaultDisplay();
return display.getHeight();
intgetScreenHeight(Context context)
get Screen Height
WindowManager wm = (WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.heightPixels;
intgetScreenWidth(Context context)
get Screen Width
WindowManager wm = (WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.widthPixels;
intgetStatusHeight(Context context)
get Status Height
int statusHeight = -1;
try {
    Class<?> clazz = Class.forName("com.android.internal.R$dimen");
    Object object = clazz.newInstance();
    int height = Integer.parseInt(clazz
            .getField("status_bar_height").get(object).toString());
    statusHeight = context.getResources().getDimensionPixelSize(
            height);
...
intgetScreenSize(@Nonnull Context context)
Retrieves the screen size category for the device's default display from the Configuration values.
Configuration conf = context.getResources().getConfiguration();
return conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
intgetScreenHeight(Context context)
get Screen Height
WindowManager wm = (WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
return dm.heightPixels;