Example usage for android.util DisplayMetrics DENSITY_HIGH

List of usage examples for android.util DisplayMetrics DENSITY_HIGH

Introduction

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

Prototype

int DENSITY_HIGH

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

Click Source Link

Document

Standard quantized DPI for high-density screens.

Usage

From source file:Main.java

public static int getNoneDp(Context mContext) {
    if (mContext.getResources().getDisplayMetrics().densityDpi <= DisplayMetrics.DENSITY_HIGH) {
        return 6;
    } else {//from   w  w w. jav a 2 s. c  o m
        return 7;
    }
}

From source file:Main.java

public static int getCircleDp(Context mContext) {
    if (mContext.getResources().getDisplayMetrics().densityDpi <= DisplayMetrics.DENSITY_HIGH) {
        return 10;
    } else {// w w  w  .j a  v  a2 s  .c  om
        return 15;
    }
}

From source file:Main.java

public static int getRectWidthDp(Context mContext) {
    if (mContext.getResources().getDisplayMetrics().densityDpi <= DisplayMetrics.DENSITY_HIGH) {
        return 15;
    } else {/*  ww  w .j a  v  a  2  s .  c o m*/
        return 25;
    }
}

From source file:Main.java

public static final float getNormalTextSize(Context context) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    switch (metrics.densityDpi) {
    case DisplayMetrics.DENSITY_HIGH:
        return 18;
    case DisplayMetrics.DENSITY_XHIGH:
        return 24;
    case DisplayMetrics.DENSITY_XXHIGH:
        return 32;
    case DisplayMetrics.DENSITY_XXXHIGH:
        return 48;
    default:/*  w  w  w .  java2  s  .co  m*/
        return 12;
    }
}

From source file:Main.java

public static boolean isRunningOn2xOrGreaterScreen(Context context) {
    if (context == null) {
        return false;
    }//from  w ww .  j av a2  s .co m
    int density = context.getResources().getDisplayMetrics().densityDpi;
    boolean result = density >= DisplayMetrics.DENSITY_HIGH;
    Log.d(TAG, String.format("Device density is %d, and result of @2x check is %b", density, result));
    return result;
}

From source file:Main.java

/**
 * Gets device's display density.//  w  w w  . j  a v  a  2s . c  om
 * @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

/**
 * The screen density expressed as dots-per-inch.
 * @param density_dpi "densityDpi"/*ww  w.j  a  v a2s. 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

private static Bitmap loadAssetBitmap(Context context, String assetPath) {
    InputStream is = null;/*from   w w w. j  a v a  2s . c om*/
    try {
        Resources resources = context.getResources();
        Options options = new Options();
        options.inDensity = DisplayMetrics.DENSITY_HIGH;
        options.inScreenDensity = resources.getDisplayMetrics().densityDpi;
        options.inTargetDensity = resources.getDisplayMetrics().densityDpi;
        is = context.getAssets().open(assetPath);
        Bitmap bitmap = BitmapFactory.decodeStream(is, new Rect(), options);
        if (bitmap != null) {
            drawableCache.put(assetPath, bitmap);
        }
        return bitmap;
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}

From source file:Main.java

public static Drawable getIconFromPackageName(String packageName, Context context) {
    PackageManager pm = context.getPackageManager();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        try {// w ww.j  a va2  s .c o m
            PackageInfo pi = pm.getPackageInfo(packageName, 0);
            Context otherAppCtx = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY);

            int displayMetrics[] = { DisplayMetrics.DENSITY_XXXHIGH, DisplayMetrics.DENSITY_XXHIGH,
                    DisplayMetrics.DENSITY_XHIGH, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_MEDIUM,
                    DisplayMetrics.DENSITY_TV };

            for (int displayMetric : displayMetrics) {
                try {
                    Drawable d = otherAppCtx.getResources().getDrawableForDensity(pi.applicationInfo.icon,
                            displayMetric);
                    if (d != null) {

                        return d;
                    }
                } catch (Resources.NotFoundException e) {
                }
            }

        } catch (Exception e) {
            // Handle Error here
        }
    }

    ApplicationInfo appInfo = null;
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        return null;
    }

    return appInfo.loadIcon(pm);
}

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;/* w w w . j a v  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;
}