Example usage for java.lang Math round

List of usage examples for java.lang Math round

Introduction

In this page you can find the example usage for java.lang Math round.

Prototype

public static long round(double a) 

Source Link

Document

Returns the closest long to the argument, with ties rounding to positive infinity.

Usage

From source file:Main.java

public static int dpToPx(Context context, int dp) {
    float density = context.getResources().getDisplayMetrics().density;
    return Math.round((float) dp * density);
}

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 int dpToPx(int dp, Context context) {
    float density = context.getResources().getDisplayMetrics().density;
    return Math.round((float) dp * density);
}

From source file:Main.java

/**
 * @return luma value according to to YIQ color space.
 *//*from w  w  w .  j a v  a2 s  .co m*/
public static final int calculateYiqLuma(int color) {
    return Math.round((299 * Color.red(color) + 587 * Color.green(color) + 114 * Color.green(color)) / 1000f);
}

From source file:Main.java

private static int dpToPx(int dp, Context context) {
    float density = context.getResources().getDisplayMetrics().density;
    return Math.round((float) dp * density);
}

From source file:Main.java

public static int calcSampleSize(BitmapFactory.Options options, int targetWidth, int targetHeigth) {
    final int heightRatio = Math.round((float) options.outHeight / (float) targetHeigth);
    final int widthRatio = Math.round((float) options.outWidth / (float) targetWidth);
    int inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
    return inSampleSize;
}

From source file:Main.java

public static int dp2px(Context context, float dp) {
    float density = context.getResources().getDisplayMetrics().density;
    return Math.round(dp * density);
}

From source file:Main.java

public static int convertToDIP(Context context, int pixels) {
    return Math.round(pixels * context.getResources().getDisplayMetrics().density);
    // DIP/*from   www. ja va  2  s. c  o m*/
}

From source file:Main.java

public static int getColor(int baseColor, float alphaPercent) {
    return (baseColor & 0x00FFFFFF) | (Math.round(Color.alpha(baseColor) * alphaPercent) << 24);
}

From source file:Main.java

public static int dpToPx(Context context, float dp) {
    final float scale = context.getResources().getDisplayMetrics().density;
    return Math.round(dp * scale);
}