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[] getStringArray(Context context, int arrayId) {
    return context.getResources().getStringArray(arrayId);
}

From source file:Main.java

/**
 * Get an identifier by string name//from  w w  w  .  j  a  va 2  s .  c om
 * @param context The context
 * @param name The identifier name
 * @return The identifier
 */
public static int getDrawableIdentifier(Context context, String name) {
    return context.getResources().getIdentifier(name, "drawable", context.getPackageName());
}

From source file:Main.java

public static int getScanHeight(Context context) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    return (int) (metrics.widthPixels * 0.6);
}

From source file:Main.java

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

From source file:Main.java

public static int dip2px(Context context, int dip) {
    float scale = context.getResources().getDisplayMetrics().density;
    return (int) (dip * scale + 0.5f * (dip >= 0 ? 1 : -1));
}

From source file:Main.java

public static int getScreenSp(Context context) {
    final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
    return (int) (fontScale + 0.5f);
}

From source file:Main.java

public static int dipToPx(Context context, int dip) {
    Resources r = context.getResources();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics());
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static int getScreenHeight(Context context) {

    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    return dm.heightPixels;
}