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 float convertDpToPixel(float dp, Context context) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    return dp * (metrics.densityDpi / 160f);
}

From source file:Main.java

static String getString(Context context, int resId) {
    return context.getResources().getString(resId);
}

From source file:Main.java

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

From source file:Main.java

public static int convertDpToPixels(Context context, int dp) {
    Resources res = context.getResources();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, res.getDisplayMetrics());
}

From source file:Main.java

public static final int getWidthInDp(Context context) {
    final float width = context.getResources().getDisplayMetrics().widthPixels;
    int widthInDp = px2dip(context, width);
    return widthInDp;
}

From source file:Main.java

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

From source file:Main.java

public static int getScreenHeight(Context context) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    return metrics.heightPixels;
}

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

/**
 * is portrait//from  ww  w  .  java2  s. c om
 *
 * @param context
 * @return
 */
public static boolean isPortrait(Context context) {
    return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
}

From source file:Main.java

public static int getPixels(Context c, int dipValue) {
    Resources r = c.getResources();
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics());
    return px;/*from   www.  j a  va2s.c o m*/
}