Example usage for java.lang Math ceil

List of usage examples for java.lang Math ceil

Introduction

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

Prototype

public static double ceil(double a) 

Source Link

Document

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:Main.java

public static int dpf(float value) {
    return (int) Math.ceil(density * value);
}

From source file:Main.java

public static int getSampleSizeAdjustToScreen(String filePath, int[] screenSize) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;/*from   ww  w  . ja  va  2  s . co  m*/
    BitmapFactory.decodeFile(filePath, options);

    int w = (int) Math.ceil(options.outWidth / (float) screenSize[0]);
    int h = (int) Math.ceil(options.outHeight / (float) screenSize[1]);

    if (h > 1 || w > 1) {
        if (h > w) {
            options.inSampleSize = h;

        } else {
            options.inSampleSize = w;
        }
    }
    return options.inSampleSize;
}

From source file:Main.java

public static int getTextWidth(Paint paint, String str) {
    int iRet = 0;
    if (str != null && str.length() > 0) {
        int len = str.length();
        float[] widths = new float[len];
        paint.getTextWidths(str, widths);
        for (int j = 0; j < len; j++) {
            iRet += (int) Math.ceil(widths[j]);
        }/*www  .  j  a  v  a2s.  com*/
    }
    return iRet;
}

From source file:Main.java

public static int getStringWidth(Paint paint, String str) {
    int iRet = 0;
    if (str != null && str.length() > 0) {
        int len = str.length();
        float[] widths = new float[len];
        paint.getTextWidths(str, widths);
        for (int j = 0; j < len; j++) {
            iRet += (int) Math.ceil(widths[j]);
        }/* w w  w . ja v a  2  s. c  o  m*/
    }
    return iRet;
}

From source file:Main.java

private static int computeSampleSize1(BitmapFactory.Options options, int targetW, int targetH) {

    //      int s = 2;
    //      while ((options.outWidth / s > targetW) || (options.outHeight / s > targetH)) {
    //         s *= 2;
    //      }//from  ww w  .  j  a va  2  s. c om
    //      return s;

    int yRatio = (int) Math.ceil(options.outHeight / targetH);
    int xRatio = (int) Math.ceil(options.outWidth / targetW);
    if (yRatio > 1 || xRatio > 1) {
        if (yRatio > xRatio) {
            return yRatio;
        } else {
            return xRatio;
        }
    }

    return 1;
}

From source file:Main.java

public static int getInterval(long timeInMillis, long currentTimeInMillis) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTimeInMillis);
    Long timeInMillisInterval = timeInMillis - calendar.getTimeInMillis();
    Float x = Float.valueOf(timeInMillisInterval) / 1000 / 3600 / 24;
    return (int) Math.ceil(x);
}

From source file:Main.java

public static int getWeekNum() {
    int num = 1;/* w w  w  . ja v a 2 s  .c om*/
    try {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        long to = new Date().getTime();
        long from = df.parse("2014-9-8 00:00:00").getTime();
        num = (int) Math.ceil((to - from) * 1.0 / (1000 * 60 * 60 * 24) / 7.0);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return num;
}

From source file:Main.java

/**
 * Converts density pixels into pixels.//from   w w w . jav a  2  s.com
 *
 * @param context the application context.
 * @param densityPixels the amount of DPs to convert.
 * @return the amount in pixels.
 */
public static int getPixels(Context context, int densityPixels) {
    return (int) Math.ceil(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, densityPixels,
            context.getResources().getDisplayMetrics()));
}

From source file:Main.java

public static int getFontHeight(Context context, float fontSize) {
    TextPaint paint = new TextPaint();
    setTextSize(context, paint, fontSize);
    FontMetrics fm = paint.getFontMetrics();
    return (int) Math.ceil(fm.descent - fm.ascent);
}

From source file:Main.java

public static float pixelsToDp(Context ctx, float px) {
    WindowManager wm = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE));
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    float logicalDensity = metrics.density;
    return (float) Math.ceil(px * logicalDensity);
}