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 boolean screenIsPortrait(Context context) {
    return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
}

From source file:Main.java

public static int ConvertToPx(Context c, int dip) {
    Resources r = c.getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, r.getDisplayMetrics());
    return (int) px;
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static int getImageId(Context context, String imageName) {
    return context.getResources().getIdentifier("drawable/" + imageName, null, context.getPackageName());
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static boolean isLandscape(Context context) {
    Configuration cf = context.getResources().getConfiguration();
    return cf.orientation == Configuration.ORIENTATION_LANDSCAPE;
}

From source file:Main.java

public static int getPixcelFromDp(Context context, int resourceId) {
    return context.getResources().getDimensionPixelSize(resourceId);
}

From source file:Main.java

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