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 getOrientacao(Context context) {
    return context.getResources().getConfiguration().orientation;
}

From source file:Main.java

public static int dpToPx(int dp, Context ctx) {
    Resources r = ctx.getResources();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
}

From source file:Main.java

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

From source file:Main.java

public static int getResId(final String variableName, final Context context) {
    return context.getResources().getIdentifier(variableName, "drawable", context.getPackageName());
}

From source file:Main.java

public static float pxToDp(float px, Context context) {
    return px / context.getResources().getDisplayMetrics().density;
}

From source file:Main.java

/**
 * @param context//from w  w w  .  j  a v  a  2s . c  o  m
 * @return true if Hardware keyboard is available
 */
public static boolean isHardwareKeyboardAvailable(Context context) {
    return context.getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;
}

From source file:Main.java

public static int getScreenWidth(Context context) {
    return (int) (context.getResources().getDisplayMetrics().widthPixels + 0.5);
}

From source file:Main.java

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

From source file:Main.java

public static DisplayMetrics getDisplayMetrics(Context context) {
    return context.getResources().getDisplayMetrics();
}

From source file:Main.java

public static int getRectWidthDp(Context mContext) {
    if (mContext.getResources().getDisplayMetrics().densityDpi <= DisplayMetrics.DENSITY_HIGH) {
        return 15;
    } else {/*from  ww w  . j  a v  a  2  s  .c  o m*/
        return 25;
    }
}