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 float constrain(float min, float max, float v) {
    return Math.max(min, Math.min(max, v));
}

From source file:Main.java

/**
 * Returns the most reasonable position for the specified rectangle to be placed at so as to
 * maximize its containment by the specified bounding rectangle while still placing it as near
 * its original coordinates as possible.
 *
 * @param rect the rectangle to be positioned.
 * @param bounds the containing rectangle.
 *///from w ww  .  ja  v a 2  s .c  o  m
public static Point fitRectInRect(Rectangle rect, Rectangle bounds) {
    // Guarantee that the right and bottom edges will be contained and do our best for the top
    // and left edges.
    return new Point(Math.min(bounds.x + bounds.width - rect.width, Math.max(rect.x, bounds.x)),
            Math.min(bounds.y + bounds.height - rect.height, Math.max(rect.y, bounds.y)));
}

From source file:Main.java

@SuppressLint("NewApi")
public static void revealView(View toBeRevealed, View frame) {
    try {/*from w ww .  ja  v  a  2 s  . c  om*/
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            // get the center for the clipping circle
            int cx = (frame.getLeft() + frame.getRight()) / 2;
            int cy = (frame.getTop() + frame.getBottom()) / 2;

            // get the final radius for the clipping circle
            int finalRadius = Math.max(frame.getWidth(), frame.getHeight());
            Log.v("INFO", "Radius: " + finalRadius);

            // create the animator for this view (the start radius is zero)
            Animator anim = ViewAnimationUtils.createCircularReveal(toBeRevealed, cx, cy, 0, finalRadius);

            // make the view visible and start the animation
            toBeRevealed.setVisibility(View.VISIBLE);
            anim.start();
        } else {
            toBeRevealed.setVisibility(View.VISIBLE);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

@NonNull
public static List<String> getSplitString(String stringToSplit, int stringSplitLength) {
    /*/*from  w w w . j a  va  2 s  . co m*/
       length to split string needs to be at least as long as the longest series of non-whitespace in the string.
       E.G. if the following is the longest series of non-whitespace in the string
      "licences:"
       then stringSplitLength needs to be at least 9 (8 letters plus a colon)
     */
    stringSplitLength = Math.max(getLengthOfLongestWord(stringToSplit), stringSplitLength);

    List<String> splitString = new ArrayList<>();

    Pattern p = Pattern.compile("\\G\\s*(.{1," + stringSplitLength + "})(?=\\s|$)", Pattern.DOTALL);
    Matcher m2 = p.matcher(stringToSplit);
    while (m2.find()) {
        splitString.add(m2.group(1));
    }
    return splitString;
}

From source file:Main.java

public static Point max(Point p1, Point p2) {
    return new Point(Math.max(p1.x, p2.x), Math.max(p1.y, p2.y));
}

From source file:Main.java

public static int stringToFourCC(String stringCode) {
    int theCode = 0;
    int count = Math.max(stringCode.length(), 4);
    for (int i = 0; i < count; ++i) {
        char c = stringCode.charAt(i);
        theCode <<= 8;//from w ww  . ja v a  2s. c o  m
        theCode |= c;
    }
    return theCode;
}

From source file:Main.java

public static Bitmap Bytes2Bimap(byte[] bytes, int maxSize) {
    try {/*from ww  w  .j a  va2 s  . c  o m*/
        if (bytes == null) {
            return null;
        }

        if (bytes.length != 0) {
            BitmapFactory.Options opt = new BitmapFactory.Options();
            opt.inJustDecodeBounds = true;
            BitmapFactory.decodeByteArray(bytes, 0, bytes.length, opt);

            int scale = 1;

            if ((opt.outHeight > maxSize) || (opt.outWidth > maxSize)) {
                scale = (int) Math.pow(2, (int) Math.round(
                        Math.log(maxSize / (double) Math.max(opt.outHeight, opt.outWidth)) / Math.log(0.5)));
            }

            BitmapFactory.Options newOpt = new BitmapFactory.Options();
            newOpt.inSampleSize = scale;

            return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, newOpt);
        } else {
            return null;
        }
    } catch (Exception ex) {
        return null;
    }
}

From source file:Main.java

public static void ensureMinimumSize(JDialog dialog, Dimension size) {
    Dimension s = dialog.getSize();
    Rectangle screen = availableScreenSize();

    if (s.width <= screen.width * 0.15 || s.height <= screen.height * 0.15) {
        // if the window as dimension less than 15% in some direction
        // increase it
        if (size == null) {
            Dimension m = new Dimension((int) (screen.width * 0.625), (int) (screen.height * 0.708));
            dialog.setSize(m);// w ww  .ja v a2 s.co  m
        } else {

            Dimension m = new Dimension(Math.max(s.width, size.width), Math.max(s.height, size.height));
            dialog.setSize(m);
        }
    }

}

From source file:Main.java

public static int setColorAlpha(int color, float alpha) {
    int alpha_int = Math.min(Math.max((int) (alpha * 255.0f), 0), 255);
    return Color.argb(alpha_int, Color.red(color), Color.green(color), Color.blue(color));
}

From source file:Main.java

/**
 * Ensures that all buttons are the same size, and that the chosen size is sufficient to contain the content of any.
 *///from ww w. j  a  v a  2  s  .  c  o  m
public static void tieButtonSizes(List<JButton> buttons) {
    int maxWidth = 0;
    int maxHeight = 0;
    for (JButton button : buttons) {
        Dimension buttonSize = button.getPreferredSize();
        maxWidth = (int) Math.max(buttonSize.getWidth(), maxWidth);
        maxHeight = (int) Math.max(buttonSize.getHeight(), maxHeight);
    }
    Dimension maxButtonSize = new Dimension(maxWidth, maxHeight);
    for (JButton button : buttons) {
        // Seemingly, to get the GTK+ LAF to behave when there are buttons with and without icons, we need to set every size.
        button.setPreferredSize(maxButtonSize);
        button.setMinimumSize(maxButtonSize);
        button.setMaximumSize(maxButtonSize);
        button.setSize(maxButtonSize);
    }
}