Example usage for android.app Activity getResources

List of usage examples for android.app Activity getResources

Introduction

In this page you can find the example usage for android.app Activity getResources.

Prototype

@Override
    public Resources getResources() 

Source Link

Usage

From source file:Main.java

public static int getDensityDPI(Activity active) {
    DisplayMetrics dm = active.getResources().getDisplayMetrics();
    return dm.densityDpi;
}

From source file:Main.java

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

From source file:Main.java

public static int getScreenHeight(Activity active) {
    DisplayMetrics dm = active.getResources().getDisplayMetrics();
    return dm.heightPixels;
}

From source file:Main.java

public static boolean isVerticalScreen(Activity activity) {
    int flag = activity.getResources().getConfiguration().orientation;
    if (flag == 0) {
        return false;
    } else {//from   www  . j  a  va2 s  .com
        return true;
    }
}

From source file:Main.java

public static View findViewByIdString(Activity a, String s) {
    return a.findViewById(a.getResources().getIdentifier(s, "id", a.getPackageName()));
}

From source file:Main.java

public static Bitmap getBitmapFromResources(Activity act, int resId) {
    Resources res = act.getResources();
    return BitmapFactory.decodeResource(res, resId);
}

From source file:Main.java

public static boolean isPhone(Activity context) {
    return ((context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) < Configuration.SCREENLAYOUT_SIZE_LARGE)
            || getPhysicalSize(context) < 6;
}

From source file:Main.java

public static float convertDpToPixel(float dp, Activity context) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float px = dp * (metrics.densityDpi / 160f);
    return px;//from w  w  w. jav  a 2s.  c  om
}

From source file:Main.java

public static int getImageItemWidth(Activity activity) {
    int screenWidth = activity.getResources().getDisplayMetrics().widthPixels;
    int densityDpi = activity.getResources().getDisplayMetrics().densityDpi;
    int cols = screenWidth / densityDpi;
    cols = cols < 3 ? 3 : cols;/*from w ww  .j a v  a2s  . com*/
    int columnSpace = (int) (2 * activity.getResources().getDisplayMetrics().density);
    return (screenWidth - columnSpace * (cols - 1)) / cols;
}

From source file:Main.java

public static void setViewTag(View v, Activity activity, int sourceId) {
    v.setTag(activity.getResources().getStringArray(sourceId));
}