List of usage examples for java.lang Math min
@HotSpotIntrinsicCandidate public static double min(double a, double b)
From source file:Main.java
public static long getNext(int index, byte[] data, final int offset) { long result = 0; for (int lengthRemain = offset, start = getBitPos(index); lengthRemain != 0; start = 0) { int end = Math.min(lengthRemain + start - 1, 5); int length = end - start + 1; for (int i = 0; i < length; i++, index++) result = (result << 1) + (getNext(index, data) ? 1 : 0); lengthRemain -= length;/*from w w w . j a va2 s . com*/ } return result; }
From source file:Main.java
public static int colsToInt(int r, int g, int b) { return (255 << 24) + (Math.max(Math.min(r, 255), 0) << 16) + (Math.max(Math.min(g, 255), 0) << 8) + Math.max(Math.min(b, 255), 0); }
From source file:Main.java
public static int calcDesiredSize(Context context, int parentWidth, int parentHeight) { int orientation = context.getResources().getConfiguration().orientation; int desiredSize = (orientation == Configuration.ORIENTATION_LANDSCAPE) ? parentHeight / 2 : parentHeight / 3;/*from w w w. ja v a2 s . co m*/ return Math.min(desiredSize, parentWidth); }
From source file:Main.java
/** * Scale down the bitmap in order to make color analysis faster. Taken from Palette. *//*from w w w . j a v a2s.com*/ private static Bitmap scaleBitmapDown(@NonNull Bitmap bitmap) { final int CALCULATE_BITMAP_MIN_DIMENSION = 100; final int minDimension = Math.min(bitmap.getWidth(), bitmap.getHeight()); if (minDimension <= CALCULATE_BITMAP_MIN_DIMENSION) { // If the bitmap is small enough already, just return it return bitmap; } final float scaleRatio = CALCULATE_BITMAP_MIN_DIMENSION / (float) minDimension; return Bitmap.createScaledBitmap(bitmap, Math.round(bitmap.getWidth() * scaleRatio), Math.round(bitmap.getHeight() * scaleRatio), false); }
From source file:Main.java
public static Bitmap circleCrop(Bitmap bitmap) { int size = Math.min(bitmap.getWidth(), bitmap.getHeight()); Bitmap output = Bitmap.createBitmap(size, size, Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, size, size); paint.setAntiAlias(true);/*from w w w.j av a 2 s .c om*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); // canvas.drawRoundRect(rectF, roundPx, roundPx, paint); canvas.drawCircle(size / 2, size / 2, size / 2, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); // Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false); // return _bmp; return output; }
From source file:Main.java
public static int getScreenShortSize(Context context) { getScreenSize(context);//from w w w . j a va2 s . c o m return Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels); }
From source file:Main.java
private static List<String> getParts(String string, int partitionSize) { List<String> parts = new ArrayList<String>(); int len = string.length(); for (int i = 0; i < len; i += partitionSize) { parts.add(string.substring(i, Math.min(len, i + partitionSize))); }/*from w w w . j av a2s . c o m*/ return parts; }
From source file:Main.java
public static <T> T[] resize(T[] x, int size) { T[] out = null;/*from www . j ava2 s.co m*/ try { out = (T[]) Array.newInstance(x.getClass().getComponentType(), size); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } int n = Math.min(x.length, size); System.arraycopy(x, 0, out, 0, n); return out; }
From source file:Main.java
public static Bitmap makeCircleBitmap(Bitmap original) { final int width = original.getWidth(); final int height = original.getHeight(); final float radius = Math.min(width, height) / 2; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Paint paint = new Paint(); paint.setAntiAlias(true);//from ww w . java 2s .co m paint.setShader(new BitmapShader(original, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); Canvas canvas = new Canvas(bitmap); canvas.drawCircle(radius, radius, radius, paint); original.recycle(); return bitmap; }
From source file:Main.java
public static int calculateImageSize(WindowManager window, int divider) { Display display = window.getDefaultDisplay(); Point resolution = new Point(); display.getSize(resolution);//from w w w. j av a2 s . com int width = resolution.x / divider; int height = resolution.y / divider; return Math.min(width, height); }