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 Bitmap getBitmapFromResId(Activity a, int id) {
    return ((BitmapDrawable) a.getResources().getDrawable(id)).getBitmap();
}

From source file:Main.java

public static boolean isOrientationPortrait(Activity activity) {

    int orientation = activity.getResources().getConfiguration().orientation;

    switch (orientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        return false;
    case Configuration.ORIENTATION_PORTRAIT:
        return true;
    }//  ww  w  . j  av a  2  s .  c om
    return true;
}

From source file:Main.java

public static int getSystemUiStatusBarHeight(Activity activity) {
    final int statusBarResId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (statusBarResId > 0) {
        return activity.getResources().getDimensionPixelSize(statusBarResId);
    } else {/*  w w w.ja  v a 2 s .c om*/
        final Rect rect = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
        return rect.top;
    }
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static ImageReader createImageReader(Activity c) {
    DisplayMetrics metrics = c.getResources().getDisplayMetrics();
    int density = metrics.densityDpi;
    int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC; //DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;
    Display display = c.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);/* w w  w  .ja v  a 2s.c  o m*/

    return ImageReader.newInstance(size.x, size.y, PixelFormat.RGB_565, 2);
}

From source file:Main.java

public static int getResIDByResName(Activity activity, String iconName) {
    Resources resources = activity.getResources();
    int indentify = resources.getIdentifier(activity.getPackageName() + ":drawable/" + iconName, null, null);
    return indentify;
}

From source file:Main.java

public static int dpToPx(Activity context, int dp) {
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    int px = Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
    return px;// w w  w . j  a va2 s  . co m
}

From source file:Main.java

public static int getStatusBarHeight(Activity activity) {
    int result = 0;
    int resId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resId > 0) {
        result = activity.getResources().getDimensionPixelSize(resId);
    }/*w ww .ja  v  a  2s. c  o  m*/
    return result;
}

From source file:Main.java

public static int getNavigationBarHeight(Activity activity) {
    Resources resources = activity.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }/* w  ww.  j  a  v  a 2 s.com*/
    return 0;
}

From source file:Main.java

public static void showFailure(Activity activity, int id) {
    Toast.makeText(activity, activity.getResources().getString(id), Toast.LENGTH_LONG).show();
}

From source file:Main.java

public static int getStatusBarHeight(Activity activity) {
    int result = 0;
    int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = activity.getResources().getDimensionPixelSize(resourceId);
    }//ww w. j av a  2 s .c  om
    return result;
}