Example usage for android.content Context getResources

List of usage examples for android.content Context getResources

Introduction

In this page you can find the example usage for android.content Context getResources.

Prototype

public abstract Resources getResources();

Source Link

Document

Returns a Resources instance for the application's package.

Usage

From source file:Main.java

public static int getDeviceDpi(Context context) {
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    return dm.densityDpi;
}

From source file:Main.java

public static int getId(Context context, String resName) {
    return context.getResources().getIdentifier(resName, "id", context.getPackageName());
}

From source file:Main.java

public static float dp2px(Context context, float dp) {
    return dp * context.getResources().getDisplayMetrics().density;
}

From source file:Main.java

public static int getColorId(Context context, String resName) {
    return context.getResources().getIdentifier(resName, "color", context.getPackageName());
}

From source file:Main.java

public static int dp2px(float value, Context context) {
    final float scale = context.getResources().getDisplayMetrics().densityDpi;
    return (int) (value * (scale / 160) + 0.5f);
}

From source file:Main.java

public static int getDrawableResId(Context context, String name) {
    return context.getResources().getIdentifier(name, android.R.drawable.class.getSimpleName(),
            context.getPackageName());/*from  w  w  w .j a  v  a 2 s . co  m*/
}

From source file:Main.java

public static int sp2px(float spValue, Context context) {
    final float scale = context.getResources().getDisplayMetrics().density;
    return (int) (spValue * scale + 0.5f);
}

From source file:Main.java

public static float getDpSize(Context context, float dpValue) {
    return context.getResources().getDisplayMetrics().density * dpValue;
}

From source file:Main.java

public static int dip2px(float dpValue, Context context) {
    final float scale = context.getResources().getDisplayMetrics().density;
    return (int) (dpValue * scale + 0.5f);
}

From source file:Main.java

public static float pxFromDp(Context context, float dp) {
    return dp * context.getResources().getDisplayMetrics().density;
}