Example usage for android.content.res Resources getSystem

List of usage examples for android.content.res Resources getSystem

Introduction

In this page you can find the example usage for android.content.res Resources getSystem.

Prototype

public static Resources getSystem() 

Source Link

Document

Return a global shared Resources object that provides access to only system resources (no application resources), and is not configured for the current screen (can not use dimension units, does not change based on orientation, etc).

Usage

From source file:Main.java

static int dp2px(int dp) {
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            Resources.getSystem().getDisplayMetrics());
}

From source file:Main.java

public static float getPixelsFromDp(float dp) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            Resources.getSystem().getDisplayMetrics());
}

From source file:Main.java

/**
 * Returns the number of pixels corresponding to the passed density pixels
 *///from  w  w w.  j  a va 2  s  .  c  o m
public static int convertDpToPixels(int dp) {
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    return (int) (dp * metrics.density + 0.5f);
}

From source file:Main.java

public static int getDimensionSize(int size) {
    return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, size,
            Resources.getSystem().getDisplayMetrics()));
}

From source file:Main.java

public static Drawable bitmapToIcon(final Bitmap bitmap) {
    final Drawable d = new BitmapDrawable(Resources.getSystem(), bitmap);
    return d;//w  w w . j  a  v a 2s  .  co  m
}

From source file:Main.java

public static TextPaint setTextSize(Context c, TextPaint paint, float size) {
    Resources r;//w w w  .  j  a v  a 2 s .c o m
    if (c == null) {
        r = Resources.getSystem();
    } else {
        r = c.getResources();
    }
    if (r != null) {
        paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, size, r.getDisplayMetrics()));
    }
    return paint;
}

From source file:Main.java

/**
 * Return true if the smallest width in DP of the device is equal or greater than the given
 * value.//w w  w.  j a va 2 s. co  m
 */
public static boolean isScreenSw(int smallestWidthDp) {
    DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
    float widthDp = displayMetrics.widthPixels / displayMetrics.density;
    float heightDp = displayMetrics.heightPixels / displayMetrics.density;
    float screenSw = Math.min(widthDp, heightDp);
    return screenSw >= smallestWidthDp;
}

From source file:Main.java

public static int sp2px(float value) {
    Resources r;/* w w  w.j a va 2s.  c o  m*/
    if (mContext == null) {
        r = Resources.getSystem();
    } else {
        r = mContext.getResources();
    }
    float spvalue = value * r.getDisplayMetrics().scaledDensity;
    return (int) (spvalue + 0.5f);
}

From source file:Main.java

private static DisplayMetrics getDisplayMetrics() {
    if (sMetrics == null) {
        sMetrics = Resources.getSystem().getDisplayMetrics();
    }//from w w  w . j  ava2  s .  c  o  m
    return sMetrics;
}

From source file:Main.java

/**
 * Converts the given dp measurement to pixels.
 * @param dp The measurement, in dp/*from w  w  w  .j ava  2  s. c o m*/
 * @return The corresponding amount of pixels based on the device's screen density
 */
public static float dpToPx(float dp) {
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    return dp * (metrics.densityDpi / 160f);
}