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 px2dip(int pxValue, Context context) {
    return (int) ((pxValue - 0.5f) / context.getResources().getDisplayMetrics().density);
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static int getResId(Context context, String id, String type) {
    return context.getResources().getIdentifier(id, type, context.getPackageName());
}

From source file:Main.java

public static int dp2Px(Context context, float dp) {
    final float scale = context.getResources().getDisplayMetrics().density;
    return (int) (dp * scale + 0.5);
}

From source file:Main.java

public static int dip2px(Context context, float dp) {
    Resources r = context.getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
    return Math.round(px);
}

From source file:Main.java

public static int calWidth(Context ctx, int pxValue) {
    final float density = ctx.getResources().getDisplayMetrics().density;
    return (int) ((pxValue / 3) * density + 0.5f);
}

From source file:Main.java

public static int dpToPx(Context context, int dp) {
    final float scale = context.getResources().getDisplayMetrics().density;
    int px = (int) (dp * scale + 0.5f);
    return px;//from   www  .  ja v a 2s  .co  m
}

From source file:Main.java

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

From source file:Main.java

public static int dp2px(Context context, int dp) {
    final float scale = context.getResources().getDisplayMetrics().density;
    int px = (int) (dp * scale + 0.5f);
    return px;//  w ww . j  a  v  a  2 s .co m
}