List of usage examples for java.lang Math max
@HotSpotIntrinsicCandidate public static double max(double a, double b)
From source file:Main.java
public static float brightness(int argb) { int r = (argb >> 16) & 0xFF; int g = (argb >> 8) & 0xFF; int b = argb & 0xFF; int V = Math.max(b, Math.max(r, g)); return (V / 255.f); }
From source file:Main.java
public static boolean rectOnRect(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { if (x1 >= Math.min(x3, x4) && x1 <= Math.max(x3, x4) && y1 >= Math.min(y3, y4) && y1 <= Math.max(y3, y4) && x2 >= Math.min(x3, x4) && x2 <= Math.max(x3, x4) && y2 >= Math.min(y3, y4) && y2 <= Math.max(y3, y4)) { return true; } else {/*from w ww . jav a 2s .com*/ return false; } }
From source file:Main.java
/** * Scrolls the given component by its unit or block increment in the given direction (actually a scale factor, so use +1 or -1). * Useful for implementing behavior like in Apple's Mail where page up/page down in the list cause scrolling in the text. *///from ww w. j a v a2s. c o m public static void scroll(JComponent c, boolean byBlock, int direction) { JScrollPane scrollPane = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, c); JScrollBar scrollBar = scrollPane.getVerticalScrollBar(); int increment = byBlock ? scrollBar.getBlockIncrement(direction) : scrollBar.getUnitIncrement(direction); int newValue = scrollBar.getValue() + direction * increment; newValue = Math.min(newValue, scrollBar.getMaximum()); newValue = Math.max(newValue, scrollBar.getMinimum()); scrollBar.setValue(newValue); }
From source file:Main.java
public static String getFileExtension(String path) { // 'archive.tar.gz' -> 'gz' // '/path/to.a/file' -> '' // '/root/case/g.txt' -> 'txt' // '/root/case/g.txt.gg' -> 'gg' // '/root/case/g.txt.gg/' -> '' // '.htaccess' -> 'htaccess' // '/.htaccess' -> 'htaccess' // '/s/.htaccess' -> 'htaccess' String extension = null;/*w ww. j a va2 s.c o m*/ int i = path.lastIndexOf('.'); int p = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\')); if (i > p) { extension = path.substring(i + 1); } return extension; }
From source file:Main.java
public static Bitmap bitmapLoad(Resources res, int resId, int width, int height) { // calc scale, load appropriately sampled bitmap from given resource BitmapFactory.Options resOptions = new BitmapFactory.Options(); resOptions.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, resOptions); int resHeight = resOptions.outHeight; int resWidth = resOptions.outWidth; float xScale = (float) width / (float) resWidth; float yScale = (float) height / (float) resHeight; float scale = Math.max(xScale, yScale); if (scale > 1) if (width == 0) width = Math.round(resWidth / scale); else if (height == 0) height = Math.round(resHeight / scale); resOptions.inSampleSize = sampleSize(scale); resWidth /= resOptions.inSampleSize; resHeight /= resOptions.inSampleSize; resOptions.inJustDecodeBounds = false; Bitmap rawBitmap = BitmapFactory.decodeResource(res, resId, resOptions); // compare aspect ratio and crop rawBitmap = bitmapCrop(rawBitmap, width, height, resWidth, resHeight); // scale to desired size return Bitmap.createScaledBitmap(rawBitmap, width, height, true); }
From source file:Main.java
/** * Returns the part of 'tail' that is not present at the end of 'text'. For * example if text = 'abc' and tail = 'cd' this method returns 'd'. If 'tail' can * not be found at the end of 'text', 'tail' is returned as is. */// w ww. ja v a2 s . co m public static String getMissingTail(String text, String tail) { for (int i = 1; i < tail.length(); i++) { int endIndex = text.length(); int end = Math.max(0, endIndex); int start = Math.max(0, end - i); String contentTail = text.substring(start, end); String proposalHead = tail.substring(0, i); if (contentTail.equals(proposalHead)) { return tail.substring(i); } } return tail; }
From source file:Main.java
public static int getMinTabletSide() { if (!isSmallTablet()) { int smallSide = Math.min(displaySize.x, displaySize.y); int leftSide = smallSide * 35 / 100; if (leftSide < dp(320)) { leftSide = dp(320);//from w ww. jav a2 s .c om } return smallSide - leftSide; } else { int smallSide = Math.min(displaySize.x, displaySize.y); int maxSide = Math.max(displaySize.x, displaySize.y); int leftSide = maxSide * 35 / 100; if (leftSide < dp(320)) { leftSide = dp(320); } return Math.min(smallSide, maxSide - leftSide); } }
From source file:Main.java
/** * Method returning color between start and end color proportional to given values. * * @param colorStart start color//from w ww .j a v a2 s. c om * @param colorEnd end color * @param fullValue total value * @param partValue part of fullValue. When partValue equals 0, returning color is colorStart, * when partValue is fullValue returning color is endColor. Otherwise returning * color is from between those, relative to partValue/fullValue ratio. * @return color from between start and end color relative to partValue/fullValue ratio. */ public static int getProportionalColor(int colorStart, int colorEnd, float fullValue, float partValue) { float progress = Math.min(Math.max(partValue, 0f), fullValue) / fullValue; return Color.argb(Math.round(Color.alpha(colorStart) * (1 - progress) + Color.alpha(colorEnd) * progress), Math.round(Color.red(colorStart) * (1 - progress) + Color.red(colorEnd) * progress), Math.round(Color.green(colorStart) * (1 - progress) + Color.green(colorEnd) * progress), Math.round(Color.blue(colorStart) * (1 - progress) + Color.blue(colorEnd) * progress)); }
From source file:Main.java
public static float hue(int argb) { int r = (argb >> 16) & 0xFF; int g = (argb >> 8) & 0xFF; int b = argb & 0xFF; int V = Math.max(b, Math.max(r, g)); int temp = Math.min(b, Math.min(r, g)); float H;/*w w w. j av a2 s. c o m*/ if (V == temp) { H = 0; } else { final float vtemp = (float) (V - temp); final float cr = (V - r) / vtemp; final float cg = (V - g) / vtemp; final float cb = (V - b) / vtemp; if (r == V) { H = cb - cg; } else if (g == V) { H = 2 + cr - cb; } else { H = 4 + cg - cr; } H /= 6.f; if (H < 0) { H++; } } return H; }
From source file:Main.java
public static Bitmap getUploadBitmap(String imagePath) { BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(imagePath, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; /* Figure out which way needs to be reduced less */ int scaleFactor; if (photoW < MAX_WIDTH && photoH < MAX_HEIGHT) { scaleFactor = 1;//from w ww . ja v a 2 s .co m } else { scaleFactor = Math.max(photoW / MAX_WIDTH, photoH / MAX_HEIGHT); } Log.d(TAG, "scaleFactor:" + scaleFactor); /* Set bitmap options to scale the image decode target */ bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; /* Decode the JPEG file into a Bitmap */ return BitmapFactory.decodeFile(imagePath, bmOptions); }