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

public static float convertDpToPixels(int dp) {
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
}

From source file:Main.java

public static Point getScreenSize() {
    DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
    return new Point(displayMetrics.widthPixels, displayMetrics.heightPixels);
}

From source file:Main.java

public static float dipToPixels(float dipValue) {
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics);
}

From source file:Main.java

public static float pixelsToDips(float pixelValue) {
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    float dip = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, metrics);
    return pixelValue / dip;
}

From source file:Main.java

/**device methods*/

public static float getDisplayPPI() {
    DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
    return (displayMetrics.xdpi + displayMetrics.ydpi) / 2.0f;
}

From source file:Main.java

public static DisplayMetrics getDisplayMetrics(Context context) {
    Resources mResources;//from   w  w w .j  av  a  2  s  .c o m
    if (context == null) {
        mResources = Resources.getSystem();

    } else {
        mResources = context.getResources();
    }
    //DisplayMetrics{density=1.5, width=480, height=854, scaledDensity=1.5, xdpi=160.421, ydpi=159.497}
    //DisplayMetrics{density=2.0, width=720, height=1280, scaledDensity=2.0, xdpi=160.42105, ydpi=160.15764}
    DisplayMetrics mDisplayMetrics = mResources.getDisplayMetrics();
    return mDisplayMetrics;
}

From source file:Main.java

/**
 * Create round, coloured bitmap with text embedded.
 * @param circleColor The color to use.//from   ww w . j  av  a2 s. c o  m
 * @param diameterDP The diameter of the circle.
 * @param text The text to embed.
 * @return Bitmap showing a text.
 */
public static Bitmap generateCircleBitmap(int circleColor, float diameterDP, String text) {
    /**
     *
     * http://stackoverflow.com/questions/31168636/rounded-quickcontactbadge-with-text
     */
    final int textColor = 0xffffffff;

    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    float diameterPixels = diameterDP * (metrics.densityDpi / 160f);
    float radiusPixels = diameterPixels / 2;

    // Create the bitmap
    Bitmap output = Bitmap.createBitmap((int) diameterPixels, (int) diameterPixels, Bitmap.Config.ARGB_8888);

    // Create the canvas to draw on
    Canvas canvas = new Canvas(output);
    canvas.drawARGB(0, 0, 0, 0);

    // Draw the circle
    final Paint paintC = new Paint();
    paintC.setAntiAlias(true);
    paintC.setColor(circleColor);
    canvas.drawCircle(radiusPixels, radiusPixels, radiusPixels, paintC);

    // Draw the text
    if (text != null && text.length() > 0) {
        final Paint paintT = new Paint();
        paintT.setColor(textColor);
        paintT.setAntiAlias(true);
        paintT.setTextSize(radiusPixels * 2);
        paintT.setTypeface(Typeface.SANS_SERIF);
        final Rect textBounds = new Rect();
        paintT.getTextBounds(text, 0, text.length(), textBounds);
        canvas.drawText(text, radiusPixels - textBounds.exactCenterX(),
                radiusPixels - textBounds.exactCenterY(), paintT);
    }

    return output;
}

From source file:Main.java

public static float getRawSize(Context context, int unit, float size) {
    Resources r;//from w  ww .  j a  v  a  2 s . c  om

    if (context == null)
        r = Resources.getSystem();
    else
        r = context.getResources();

    return TypedValue.applyDimension(unit, size, r.getDisplayMetrics());
}

From source file:Main.java

public static DisplayMetrics getDisplayMetrics(Context context) {
    Resources res;/*from   w  ww .jav a2  s .c o m*/
    if (context == null) {
        res = Resources.getSystem();
    } else {
        res = context.getResources();
    }
    return res.getDisplayMetrics();
}

From source file:Main.java

private static void getFormatTime(Context context, Time time, int i, boolean flag, CharBuffer charbuffer) {
    long l = time.toMillis(true);
    boolean flag1;
    if ((i & 1) != 0)
        flag1 = true;//w  w w  .  j a  v a 2 s .c o  m
    else
        flag1 = false;
    if (flag)
        charbuffer.append(DateUtils.formatDateRange(context, l, l, i));
    else if (flag1) {
        if ((i ^ 1) != 0) {
            charbuffer.append(DateUtils.formatDateRange(context, l, l, i ^ 1));
            charbuffer.append(" ");
        }
        String s = getDetailedAmPm(time.hour);
        if (time.hour > 12)
            time.hour = -12 + time.hour;
        long l1 = time.toMillis(true);
        String s1 = DateUtils.formatDateRange(context, l1, l1, 129);
        Resources resources = Resources.getSystem();
        Object aobj[] = new Object[2];
        aobj[0] = s1;
        aobj[1] = s;
        charbuffer.append(resources.getString(0x60c01f7, aobj));
    } else {
        charbuffer.append(DateUtils.formatDateRange(context, l, l, i));
    }
}