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 dpToPixels(Context context, float dps) {
    final float scale = context.getResources().getDisplayMetrics().density;
    return (int) (dps * scale + 0.5f);
}

From source file:Main.java

public static float spToPixel(Context context, float sp) {
    float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
    return sp * scaledDensity;
}

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 dp2px(Context context, float dp) {
    return (int) (0.5F + context.getResources().getDisplayMetrics().density * dp);
}

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.5f);
}

From source file:Main.java

public static int getDip(Context context, int resId) {
    return Math.round(context.getResources().getDimension(resId));
}

From source file:Main.java

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

From source file:Main.java

public static DisplayMetrics getDisplayMetrics(Context context) {
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    return dm;//from  w w w.j  ava 2  s.c  o  m
}

From source file:Main.java

public static void showToast(Context context, int id) {
    showToast(context, context.getResources().getString(id));
}

From source file:Main.java

public static float pxToDp(Context context, float pxValue) {
    float density = context.getResources().getDisplayMetrics().density;

    return density / pxValue + 0.5f;
}