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 boolean isTablet(Context context) {
    int screenLayout = context.getResources().getConfiguration().screenLayout;
    return (screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

From source file:Main.java

public static final boolean isPortrait(Context context) {
    return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
}

From source file:Main.java

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

From source file:Main.java

public static int dpiToPixels(Context c, int dpi) {
    return (int) (dpi * c.getResources().getDisplayMetrics().density);
}

From source file:Main.java

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

From source file:Main.java

public static int getStringResId(Context context, String name) {
    return context.getResources().getIdentifier(name, android.R.string.class.getSimpleName(),
            context.getPackageName());/* w  w  w . j  av a  2  s.  c om*/
}

From source file:Main.java

public static int px2dp(Context context, int px) {
    float scale = context.getResources().getDisplayMetrics().density;
    return (int) (px / scale + 0.5f * (px >= 0 ? 1 : -1));
}

From source file:Main.java

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

From source file:Main.java

public static String getDisplaySize(Context context) {
    int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
    int screenHeight = context.getResources().getDisplayMetrics().heightPixels;
    return screenHeight + "*" + screenWidth;
}

From source file:Main.java

public static float getSpSize(Context context, float spValue) {
    return context.getResources().getDisplayMetrics().scaledDensity * spValue;
}