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 String getResourceNameById(Context context, int resId) {
    return context.getResources().getResourceName(resId);
}

From source file:Main.java

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

From source file:Main.java

public static int getscreenWidthDp(Context context) {
    int widthPx = context.getResources().getDisplayMetrics().widthPixels;
    return px2dip(context, widthPx);//widthPx/oneDpToPx;
}

From source file:Main.java

public static int getNavigationBarHeight(Context context) {
    int resId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
    if (resId > 0)
        return context.getResources().getDimensionPixelSize(resId);
    else/*from   ww w . j av a  2s  .c om*/
        return 0;
}

From source file:Main.java

public static int getStatusBarHeight(Context context) {
    int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resId > 0)
        return context.getResources().getDimensionPixelSize(resId);
    else/*w  w  w .j  av a  2  s .co  m*/
        return 0;
}

From source file:Main.java

public static int getPixelValue(Context ctx, float dp) {
    float scale = ctx.getResources().getDisplayMetrics().density;
    return (int) (scale * dp);
}

From source file:Main.java

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

From source file:Main.java

public static int getScreenW(Context aty) {
    DisplayMetrics dm = aty.getResources().getDisplayMetrics();
    return dm.widthPixels;
}

From source file:Main.java

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

From source file:Main.java

public static String getResourcesString(Context context, int stringId) {
    return context.getResources().getString(stringId);
}