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

/**
 * gets string from resource values//from  w  ww  . j a  va2  s.  c o m
 *
 * @param context  context of calling activity
 * @param stringId resource id
 * @return string
 */
public static String getStringResource(Context context, int stringId) {
    return context.getResources().getString(stringId);
}

From source file:Main.java

public static int pxToSp(Context context, int pxValue) {
    float scale = context.getResources().getDisplayMetrics().scaledDensity;
    return (int) (pxValue / scale + 0.5f);
}

From source file:Main.java

public static int dptopx(Context ctxt, int dp) {
    DisplayMetrics m = ctxt.getResources().getDisplayMetrics();
    return dp * (m.densityDpi / 160);
}

From source file:Main.java

public static int dip2pix(Context context, int dips) {
    int densityDpi = context.getResources().getDisplayMetrics().densityDpi;
    return (dips * densityDpi) / 160;
}

From source file:Main.java

public static int getDimenDp(Context context, int dimenId) {
    return ((int) (context.getResources().getDimension(dimenId)
            / context.getResources().getDisplayMetrics().density));
}

From source file:Main.java

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

From source file:Main.java

public static int dpToPixel(Context context, int dp) {
    final float scale = context.getResources().getDisplayMetrics().density;
    // convert the DP into pixel
    return (int) (dp * scale + 0.5f);
}

From source file:Main.java

public static Bitmap decodeFromResource(Context context, int id) {
    Resources res = context.getResources();
    Bitmap bitmap = BitmapFactory.decodeResource(res, id).copy(Bitmap.Config.ARGB_8888, true);
    return bitmap;
}

From source file:Main.java

public static Point getScreenMetrics(Context context) {
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    int w_screen = dm.widthPixels;
    int h_screen = dm.heightPixels;
    return new Point(w_screen, h_screen);
}

From source file:Main.java

static public int getStringResource(Context ctx, String name) {
    return ctx.getResources().getIdentifier(name, "string", ctx.getPackageName());
}