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 final int getWidthInPx(Context context) {
    final int width = context.getResources().getDisplayMetrics().widthPixels;
    return width;
}

From source file:Main.java

public static boolean isLocalCN(Context context) {
    Locale locale = context.getResources().getConfiguration().locale;
    String language = locale.getLanguage();
    return language.equals("zh");
}

From source file:Main.java

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

From source file:Main.java

public static int getIconId(Context context, String name) {
    return context.getResources().getIdentifier(name, "drawable", context.getPackageName());
}

From source file:Main.java

public static Bitmap drawableTobitmap(int bmpid, Context ctx) {
    Resources res = ctx.getResources();
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 1;//from w  w  w . j a v  a2 s.co m
    return BitmapFactory.decodeResource(res, bmpid, options);
}

From source file:Main.java

public static int getScreenH(Context aty) {
    DisplayMetrics dm = aty.getResources().getDisplayMetrics();
    return dm.heightPixels;
}

From source file:Main.java

public static boolean isZh(Context context) {
    Locale locale = context.getResources().getConfiguration().locale;
    String language = locale.getLanguage();
    return language.endsWith("zh");
}

From source file:Main.java

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

From source file:Main.java

private static InputStream res2InputStream(Context context, int resID) {
    return context.getResources().openRawResource(resID);
}

From source file:Main.java

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