Example usage for java.lang Math max

List of usage examples for java.lang Math max

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double max(double a, double b) 

Source Link

Document

Returns the greater of two double values.

Usage

From source file:Main.java

public static List<String> calculateResolutions(double dpi, double screenSize, boolean standard) {
    List<String> ret = new ArrayList<>();
    double bothSquaredSum = Math.pow(dpi * screenSize, 2);
    for (int i = 0; i < 10000; i++) {
        double other = Math.sqrt(bothSquaredSum - Math.pow(i, 2));
        double higher = Math.max(i, other), lower = Math.min(i, other);
        if (Double.isNaN(lower)) {
            continue;
        }//from ww w . j av  a2s .c  o  m
        if (standard) {
            double ratio = higher / lower;
            if (ratio == 4.0 / 3.0 || ratio == 16.0 / 9.0 || ratio == 16.0 / 10.0) {
                ret.add(String.format("%.0fx%.0f", higher, lower));
            }
        } else {
            ret.add(String.format("%.0fx%.0f", higher, lower));
        }
    }
    return ret;
}

From source file:Main.java

public static float getScreenLargestWidth() {
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();

    int widthPixels = metrics.widthPixels;
    int heightPixels = metrics.heightPixels;

    float scaleFactor = metrics.density;

    float widthDp = widthPixels / scaleFactor;
    float heightDp = heightPixels / scaleFactor;

    return Math.max(widthDp, heightDp);
}

From source file:Main.java

/**
 * This method returns no sooner than timeToReturns milliseconds have passed since the epoch.
 * /* w  w w .  j  a  va 2 s . c  o  m*/
 * @param timeToReturn when this method should return
 */
public static void sleepUntil(final long timeToReturn) {
    while (System.currentTimeMillis() < timeToReturn) {
        long millisUntilTimeIsUp = timeToReturn - System.currentTimeMillis();
        long delay = Math.max(MINIMUM_DELAY, millisUntilTimeIsUp);
        try {
            Thread.sleep(delay);
        } catch (InterruptedException e) {
            // this is ok
        }
    }
}

From source file:Main.java

public static int caculateInSampleSize(Options options, int reqWidth, int reqHeight) {
    int width = options.outWidth;
    int height = options.outHeight;

    int inSampleSize = 1;

    if (width > reqWidth || height > reqHeight) {
        int widthRadio = Math.round(width * 1.0f / reqWidth);
        int heightRadio = Math.round(height * 1.0f / reqHeight);

        inSampleSize = Math.max(widthRadio, heightRadio);
    }//  w  w  w  .  ja v a 2 s .  c  o m

    return inSampleSize;
}

From source file:Main.java

private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
    int width = options.outWidth;
    int height = options.outHeight;

    int inSampleSize = 1;
    if (width > reqWidth || height > reqHeight) {
        int widthRadio = Math.round(width * 1.0f / reqWidth);
        int heightRadio = Math.round(height * 1.0f / reqHeight);
        inSampleSize = Math.max(widthRadio, heightRadio);
    }/*w ww . j a  v  a  2 s .  c  om*/
    return inSampleSize;
}

From source file:Main.java

/**
 * return either the first space or the first nbsp
 *///from   w  ww. j ava  2  s  .c  o m
public static int findSpace(String haystack, int begin) {
    int space = haystack.indexOf(' ', begin);
    int nbsp = haystack.indexOf('\u00A0', begin);
    if (space == -1 && nbsp == -1) {
        return -1;
    } else if (space >= 0 && nbsp >= 0) {
        return Math.min(space, nbsp);
    } else {
        // eg one is -1, and the other is >= 0
        return Math.max(space, nbsp);
    }
}

From source file:Main.java

private static Bitmap buildBitmap(ArrayList<Bitmap> bitmaps) {
    if (bitmaps == null || bitmaps.size() == 0) {
        return null;
    }// w  ww  .j a v  a 2  s. c o m
    int width = 0;
    int height = 0;
    for (int i = 0; i < bitmaps.size(); i++) {
        width = width + bitmaps.get(i).getWidth();
        height = Math.max(height, bitmaps.get(i).getHeight());
    }
    Bitmap resultBitmap = Bitmap.createBitmap(width, height, Config.ARGB_4444);
    int drawWidth = 0;
    Canvas canvas = new Canvas(resultBitmap);
    for (int j = 0; j < bitmaps.size(); j++) {
        drawWidth = j * bitmaps.get(j).getWidth();
        canvas.drawBitmap(bitmaps.get(j), drawWidth, 0, null);
    }
    return resultBitmap;
}

From source file:Main.java

public static int maxInt(Iterable<Integer> list, int defaultValue) {
    int max = defaultValue;
    for (Integer i : list) {
        if (i != null)
            max = Math.max(max, i);
    }/*from   w  w  w  .  j av  a2s . c  o m*/
    return max;
}

From source file:Main.java

/**
 * Get a darker version of a color/*from w w w  . ja v a  2 s .  co  m*/
 * @param color the color to be darkened
 * @param factor the factor by which to darken the color
 * @return an integer representation of the darkened color
 */
private static int darker(int color, double factor) {
    int a = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    return Color.argb(a, Math.max((int) (r * factor), 0), Math.max((int) (g * factor), 0),
            Math.max((int) (b * factor), 0));
}

From source file:Main.java

static public int getImageSize(String albumArtPath) {
    if (albumArtPath != null) {
        BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inJustDecodeBounds = true;/*from  w w w  . jav a 2  s  .co  m*/
        Bitmap bmTmp = BitmapFactory.decodeFile(albumArtPath, opts);
        if (bmTmp != null)
            bmTmp.recycle();
        return Math.max(opts.outWidth, opts.outWidth);
    }
    return 0;
}