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

int[]getScreenSizePixels(Context ctx)
get Screen Size Pixels
int widthHeightInPixels[] = new int[2];
try {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        Resources resources = ctx.getResources();
        Configuration config = resources.getConfiguration();
        DisplayMetrics dm = resources.getDisplayMetrics();
        double screenWidthInPixels = (double) config.screenWidthDp
                * dm.density;
...
int[]getRealScreenDimensions(Context context)
get Real Screen Dimensions
WindowManager wm = (WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getRealMetrics(metrics);
return new int[] { metrics.widthPixels, metrics.heightPixels };
intgetScreenHeight(Context context)
get Screen Height
int screenSizeOne = -1;
int screenSizeTwo = -1;
if (screenSizeOne <= 0 || screenSizeTwo <= 0) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wm = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    screenSizeOne = dm.widthPixels;
...
intgetScreenSize(@Nonnull Context context)
Retrieves the screen size category for the device's default display from the Configuration values.
final Configuration conf = context.getResources()
        .getConfiguration();
return conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
intgetScreenWidth(Context context)
get Screen Width
int screenSizeOne = -1;
int screenSizeTwo = -1;
if (screenSizeOne <= 0 || screenSizeTwo <= 0) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wm = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);
    if (wm != null) {
        wm.getDefaultDisplay().getMetrics(dm);
...
intgetScreenDensity(Context context)
get Screen Density
retrieveDisplayMetrics(context);
return (int) (_display_metrics.density * DisplayMetrics.DENSITY_DEFAULT);
int[]getScreenSize(Activity ctx)
get Screen Size
int[] screenSize = new int[2];
DisplayMetrics displayMetrics = new DisplayMetrics();
ctx.getWindowManager().getDefaultDisplay()
        .getMetrics(displayMetrics);
screenSize[0] = displayMetrics.widthPixels;
screenSize[1] = displayMetrics.heightPixels;
return screenSize;
int[]getScreenSize(Context context)
get Screen Size
int[] ints = { 0, 0 };
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager windowManager = ((WindowManager) context
        .getSystemService(Context.WINDOW_SERVICE));
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
ints[0] = displayMetrics.widthPixels;
ints[1] = displayMetrics.heightPixels;
return ints;
...
int[]getScreenSize(Context ctx)
get Screen Size
int[] screenSize = new int[2];
try {
    DisplayMetrics displayMetrics = ctx.getResources()
            .getDisplayMetrics();
    screenSize[0] = displayMetrics.widthPixels < displayMetrics.heightPixels ? displayMetrics.widthPixels
            : displayMetrics.heightPixels;
    screenSize[1] = displayMetrics.widthPixels > displayMetrics.heightPixels ? displayMetrics.widthPixels
            : displayMetrics.heightPixels;
...
intgetMinTouchHeight(Context context)
get Min Touch Height
retrieveDisplayMetrics(context);
return (int) (MIN_TOUCH_SIZE * _display_metrics.density * STANDARD_DPI);