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 px2dp(Context context, int px) {
    float density = context.getResources().getDisplayMetrics().density;
    return (int) (px / density + 0.5f);
}

From source file:Main.java

public static Resources getResources(Context context) {
    return context != null ? context.getResources() : null;
}

From source file:Main.java

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

From source file:Main.java

/** get Resources */
public static Resources getResources(Context context) {
    return context.getResources();
}

From source file:Main.java

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

From source file:Main.java

public static float getDensity(Context context) {
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    return dm.density;
}

From source file:Main.java

public static float getDipByPix(Context context, int Pix) {
    float scale = context.getResources().getDisplayMetrics().density;
    return Pix / scale;
}

From source file:Main.java

public static int getOrientation(Context context) {
    return context.getResources().getConfiguration().orientation - 1;
}

From source file:Main.java

public static int getPixByDip(Context context, int dip) {
    float scale = context.getResources().getDisplayMetrics().density;
    return (int) (dip * scale);
}

From source file:Main.java

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