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 getScreenHeight(Context context) {
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    int h_screen = dm.heightPixels;
    return h_screen;
}

From source file:Main.java

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

From source file:Main.java

public static int convertDensityPixelToPixel(Context context, int i) {
    return (int) ((i * context.getResources().getDisplayMetrics().density) + 0.5);
}

From source file:Main.java

public static String getStringByName(Context context, String name) {
    int id = context.getResources().getIdentifier(name, STRING, context.getPackageName());
    return context.getString(id);
}

From source file:Main.java

private static float pxToDp(Context context, float px) {
    return px / context.getResources().getDisplayMetrics().density;
}

From source file:Main.java

public static boolean isPortrait(Context context) {
    return isPortrait(context.getResources().getConfiguration());
}

From source file:Main.java

private static String getString(Context context, @StringRes int id) {
    return context.getResources().getString(id);
}

From source file:Main.java

/***
 * @param context/*from  ww  w . j ava 2 s.c o  m*/
 * @param value
 * @return
 */
private static float convertDpToPixel(Context context, float value) {
    return context.getResources().getDisplayMetrics().density * value;
}

From source file:Main.java

private static boolean isTablet(Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

From source file:Main.java

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