Example usage for android.util DisplayMetrics DENSITY_LOW

List of usage examples for android.util DisplayMetrics DENSITY_LOW

Introduction

In this page you can find the example usage for android.util DisplayMetrics DENSITY_LOW.

Prototype

int DENSITY_LOW

To view the source code for android.util DisplayMetrics DENSITY_LOW.

Click Source Link

Document

Standard quantized DPI for low-density screens.

Usage

From source file:Main.java

/**
 * The screen density expressed as dots-per-inch.
 * @param density_dpi "densityDpi"/*  w  ww  . j a  va  2 s .c o m*/
 */
public static String getDensityDPIStr(int density_dpi) {
    switch (density_dpi) {
    case DisplayMetrics.DENSITY_LOW://120
        return "DENSITY_LOW";
    case DisplayMetrics.DENSITY_MEDIUM://160
        return "DENSITY_MEDIUM/DENSITY_DEFAULT";
    //case DisplayMetrics.DENSITY_DEFAULT://160
    //    return "DENSITY_DEFAULT";
    case DisplayMetrics.DENSITY_TV://213
        return "DENSITY_TV";
    case DisplayMetrics.DENSITY_HIGH://240
        return "DENSITY_HIGH";
    case DisplayMetrics.DENSITY_280://280
        return "DENSITY_280";
    case DisplayMetrics.DENSITY_XHIGH://320
        return "DENSITY_XHIGH";
    case DisplayMetrics.DENSITY_360://360
        return "DENSITY_360";
    case DisplayMetrics.DENSITY_400://400
        return "DENSITY_400";
    case DisplayMetrics.DENSITY_420://420
        return "DENSITY_420";
    case DisplayMetrics.DENSITY_XXHIGH://480
        return "DENSITY_XXHDPI";
    case DisplayMetrics.DENSITY_560://560
        return "DENSITY_560";
    case DisplayMetrics.DENSITY_XXXHIGH://640
        return "DENSITY_XXXHDPI";
    default:
        return UNKNOWN;
    }
}

From source file:Main.java

/**
 * Gets device's display density./*from  w w  w  .  j a va2s  .  co m*/
 * @since   0.1.0
 * @param   aContext The context from which the display metrics information is retrieved.
 * @return   The density in String or an empty String if display metrics is not retrievable.
 */
public static String getScreenDpi(Context aContext) {
    DisplayMetrics metrics = aContext.getResources().getDisplayMetrics();
    switch (metrics.densityDpi) {
    case DisplayMetrics.DENSITY_LOW:
        return "ldpi";
    case DisplayMetrics.DENSITY_MEDIUM:
        return "mdpi";
    case DisplayMetrics.DENSITY_HIGH:
        return "hdpi";
    case DisplayMetrics.DENSITY_XHIGH:
        return "xhdpi";
    case DisplayMetrics.DENSITY_XXHIGH:
        return "xxhdpi";
    case DisplayMetrics.DENSITY_XXXHIGH:
        return "xxxhdpi";
    default:
        return "";
    }
}

From source file:Main.java

public static String getDensity(Context ctx) {
    String densityStr = null;/*from   w  w  w  . j  ava 2s . com*/
    final int density = ctx.getResources().getDisplayMetrics().densityDpi;
    switch (density) {
    case DisplayMetrics.DENSITY_LOW:
        densityStr = "LDPI";
        break;
    case DisplayMetrics.DENSITY_MEDIUM:
        densityStr = "MDPI";
        break;
    case DisplayMetrics.DENSITY_TV:
        densityStr = "TVDPI";
        break;
    case DisplayMetrics.DENSITY_HIGH:
        densityStr = "HDPI";
        break;
    case DisplayMetrics.DENSITY_XHIGH:
        densityStr = "XHDPI";
        break;
    case DisplayMetrics.DENSITY_400:
        densityStr = "XMHDPI";
        break;
    case DisplayMetrics.DENSITY_XXHIGH:
        densityStr = "XXHDPI";
        break;
    case DisplayMetrics.DENSITY_XXXHIGH:
        densityStr = "XXXHDPI";
        break;
    }
    return densityStr;
}

From source file:Main.java

public static int getImageButtonSize(Activity activity) {
    if (mImageButtonSize == -1) {
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        switch (metrics.densityDpi) {
        case DisplayMetrics.DENSITY_LOW:
            mImageButtonSize = 16;// www  .j  av  a 2s. c  o  m
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            mImageButtonSize = 32;
            break;
        case DisplayMetrics.DENSITY_HIGH:
            mImageButtonSize = 48;
            break;
        default:
            mImageButtonSize = 32;
        }
    }

    return mImageButtonSize;
}

From source file:Main.java

/**
 * Get the required size of the favicon, depending on current screen density.
 * @param activity The current activity.
 * @return The size of the favicon, in pixels.
 *///ww w .j a  va2 s . co  m
public static int getFaviconSize(Activity activity) {
    if (mFaviconSize == -1) {
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        switch (metrics.densityDpi) {
        case DisplayMetrics.DENSITY_LOW:
            mFaviconSize = 12;
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            mFaviconSize = 24;
            break;
        case DisplayMetrics.DENSITY_HIGH:
            mFaviconSize = 32;
            break;
        default:
            mFaviconSize = 24;
        }
    }

    return mFaviconSize;
}

From source file:Main.java

/**
 * Get the required size of the favicon, depending on current screen density.
 * @param activity The current activity.
 * @return The size of the favicon, in pixels.
 *///from  w  w  w  . j a v  a2s  . c  om
public static int getFaviconSizeForBookmarks(Activity activity) {
    if (mFaviconSizeForBookmarks == -1) {
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        switch (metrics.densityDpi) {
        case DisplayMetrics.DENSITY_LOW:
            mFaviconSizeForBookmarks = 12;
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            mFaviconSizeForBookmarks = 16;
            break;
        case DisplayMetrics.DENSITY_HIGH:
            mFaviconSizeForBookmarks = 24;
            break;
        default:
            mFaviconSizeForBookmarks = 16;
        }
    }

    return mFaviconSizeForBookmarks;
}

From source file:com.mruddy.devdataviewer.DevDataListFragment.java

@SuppressLint("InlinedApi")
private static void initMaps() {
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_LOW, "LDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_MEDIUM, "MDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_HIGH, "HDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XHIGH, "XHDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XXHIGH, "XXHDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XXXHIGH, "XXXHDPI");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_0, "0");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_90, "90");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_180, "180");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_270, "270");
    DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_UNDEFINED, "undefined");
    DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_PORTRAIT, "portrait");
    DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_LANDSCAPE, "landscape");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_UNDEFINED, "undefined");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_SMALL, "small");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_NORMAL, "normal");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_LARGE, "large");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_XLARGE, "xlarge");
}

From source file:Main.java

public static void getDisplayDpi(Context ctx) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
    double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
    double screenInches = Math.sqrt(x + y);
    int screenInch = (int) Math.round(screenInches);
    Log.d("screeninch", String.valueOf(screenInch));
    int dapi = dm.densityDpi;
    Log.d("dapi", String.valueOf(dapi));
    try {//from w  w  w  . j a  v  a2s  . c  om
        switch (dm.densityDpi) {

        case DisplayMetrics.DENSITY_LOW:
            UI_DENSITY = 120;
            if (screenInch <= 7) {
                UI_SIZE = 4;

            } else {
                UI_SIZE = 10;
            }
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            UI_DENSITY = 160;
            if (screenInch <= 7) {
                UI_SIZE = 4;
            } else {
                UI_SIZE = 10;
            }
            break;
        case DisplayMetrics.DENSITY_HIGH:
            UI_DENSITY = 240;
            if (screenInch <= 7) {
                UI_SIZE = 4;
            } else {
                UI_SIZE = 10;
            }
            break;

        default:
            break;
        }
    } catch (Exception e) {
        // Caught exception here
    }
}

From source file:Main.java

/**
 * Reports to the log information about the device's display. This information includes
 * the width and height, and density (low, medium, high). 
 * @param activity The Activity to report on.
 *///from  ww  w .  j av a 2  s . c  om
public static void reportDisplayInformation(Activity activity) {

    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int displayWidth = metrics.widthPixels;
    int displayHeight = metrics.heightPixels;

    String density = "unknown";
    switch (metrics.densityDpi) {
    case DisplayMetrics.DENSITY_LOW:
        density = "Low";
        break;
    case DisplayMetrics.DENSITY_MEDIUM:
        density = "Medium";
        break;
    case DisplayMetrics.DENSITY_HIGH:
        density = "High";
        break;
    }

    Log.i(TAG, "Display is " + displayWidth + "x" + displayHeight + ", Density: " + density);

}

From source file:count.ly.messaging.DeviceInfo.java

/**
 * Maps the current display density to a string constant.
 * @param context context to use to retrieve the current display metrics
 * @return a string constant representing the current display density, or the
 *         empty string if the density is unknown
 *///from  w  w  w .j  ava2s . c o m
static String getDensity(final Context context) {
    String densityStr = "";
    final int density = context.getResources().getDisplayMetrics().densityDpi;
    switch (density) {
    case DisplayMetrics.DENSITY_LOW:
        densityStr = "LDPI";
        break;
    case DisplayMetrics.DENSITY_MEDIUM:
        densityStr = "MDPI";
        break;
    case DisplayMetrics.DENSITY_TV:
        densityStr = "TVDPI";
        break;
    case DisplayMetrics.DENSITY_HIGH:
        densityStr = "HDPI";
        break;
    case DisplayMetrics.DENSITY_XHIGH:
        densityStr = "XHDPI";
        break;
    case DisplayMetrics.DENSITY_400:
        densityStr = "XMHDPI";
        break;
    case DisplayMetrics.DENSITY_XXHIGH:
        densityStr = "XXHDPI";
        break;
    case DisplayMetrics.DENSITY_XXXHIGH:
        densityStr = "XXXHDPI";
        break;
    }
    return densityStr;
}