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

/**
 * Get the name from the location identifier
 * @param location/* ww  w.  j  a v a 2  s . c o m*/
 * @return
 */
public static String getLocationName(Context context, String location) {
    return context.getResources()
            .getString(context.getResources().getIdentifier(location, "string", context.getPackageName()));
}

From source file:Main.java

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

From source file:Main.java

public static int px2Dip(Context context, float px) {
    final float scale = context.getResources().getDisplayMetrics().density;
    return (int) (px / scale + 0.5f);
}

From source file:Main.java

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

From source file:Main.java

public static float pixelsToSp(Context context, float sp) {
    float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
    return sp * scaledDensity;
}

From source file:Main.java

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

From source file:Main.java

public static int convertPixelsToDp(float px, Context context) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float dp = px / (metrics.densityDpi / 160f);
    return (int) dp;
}

From source file:Main.java

static float dpToPx(Context context, int dp) {
    final float density = context.getResources().getDisplayMetrics().density;
    return density * dp / 160;
}

From source file:Main.java

public static Bitmap fetchBitmapFromRes(Context context, int resId) {
    Resources res = context.getResources();
    Bitmap bmp = BitmapFactory.decodeResource(res, resId);
    return bmp;/* w  ww  . ja v a 2  s.  co  m*/
}

From source file:Main.java

static int dpToPx(Context context, float dp) {
    final float scale = context.getResources().getDisplayMetrics().density;
    return Math.round(dp * scale);
}