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 final <T> List<List<T>> devide(List<T> origin, int size) { if (origin == null || origin.isEmpty() || size <= 0) { return Collections.emptyList(); }/* w w w . j a va 2 s . c o m*/ final int block = origin.size() / size + (origin.size() % size > 0 ? 1 : 0); List<List<T>> devidedList = new ArrayList<List<T>>(block); for (int i = 0; i < block; i++) { final int start = i * size; final int end = Math.min(start + size, origin.size()); devidedList.add(new ArrayList<T>(origin.subList(start, end))); } return devidedList; }
From source file:Main.java
private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; }//from w w w . j ava 2 s. co m if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }
From source file:Util.java
/** * Calculate the minimum and maximum values out of a list of doubles. * // ww w . ja v a2 s .co m * @param values * the input values * @return an array with the minimum and maximum values */ public static double[] minmax(List<Double> values) { if (values.size() == 0) { return new double[2]; } double min = values.get(0); double max = min; int length = values.size(); for (int i = 1; i < length; i++) { double value = values.get(i); min = Math.min(min, value); max = Math.max(max, value); } return new double[] { min, max }; }
From source file:Main.java
/** * Method returning given color modified to lighter color (positive translation) or darker * (negative translation)./*from www .jav a2 s. c o m*/ * * @param primaryColor basic color * @param translation positive or negative value of color translation * @return lighter/darker color */ public static int getColorWithTranslateBrightness(int primaryColor, int translation) { if (translation >= 0) { return Color.argb(Color.alpha(primaryColor), Math.min(Color.red(primaryColor) + translation, 255), Math.min(Color.green(primaryColor) + translation, 255), Math.min(Color.blue(primaryColor) + translation, 255)); } else { return Color.argb(Color.alpha(primaryColor), Math.max(Color.red(primaryColor) + translation, 0), Math.max(Color.green(primaryColor) + translation, 0), Math.max(Color.blue(primaryColor) + translation, 0)); } }
From source file:Main.java
private static int lightenColor(int color, double fraction) { return (int) Math.min(color + (color * fraction), 255); }
From source file:Main.java
public static Bitmap createRoundedFramedImage(Drawable imageDrawable, int borderThickness) { int size = Math.min(imageDrawable.getMinimumWidth(), imageDrawable.getMinimumHeight()); // Drawable imageDrawable = (image != null) ? new BitmapDrawable(image) : placeHolder; Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); RectF outerRect = new RectF(0, 0, size, size); float cornerRadius = size / 18f; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.RED);/*from w w w .ja v a2 s. com*/ canvas.drawRoundRect(outerRect, cornerRadius, cornerRadius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); imageDrawable.setBounds(0, 0, size, size); // Save the layer to apply the paint canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG); imageDrawable.draw(canvas); canvas.restore(); // FRAMING THE PHOTO float border = size / 15f; // 1. Create offscreen bitmap link: http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU#t=1035s Bitmap framedOutput = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas framedCanvas = new Canvas(framedOutput); // End of Step 1 // Start - TODO IMPORTANT - this section shouldn't be included in the final code // It's needed here to differentiate step 2 (red) with the background color of the activity // It's should be commented out after the codes includes step 3 onwards // Paint squaredPaint = new Paint(Paint.ANTI_ALIAS_FLAG); // squaredPaint.setColor(Color.BLUE); // framedCanvas.drawRoundRect(outerRect, 0f, 0f, squaredPaint); // End // 2. Draw an opaque rounded rectangle link: // http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU#t=1044s RectF innerRect = new RectF(border, border, size - border, size - border); Paint innerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); innerPaint.setColor(Color.RED); framedCanvas.drawRoundRect(innerRect, cornerRadius, cornerRadius, innerPaint); // 3. Set the Power Duff mode link: // http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU#t=1056s Paint outerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); outerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); // 4. Draw a translucent rounded rectangle link: // http://www.youtube.com/watch?feature=player_detailpage&v=jF6Ad4GYjRU outerPaint.setColor(Color.argb(100, 0, 0, 0)); framedCanvas.drawRoundRect(outerRect, cornerRadius, cornerRadius, outerPaint); // 5. Draw the frame on top of original bitmap canvas.drawBitmap(framedOutput, 0f, 0f, null); return output; }
From source file:Main.java
public static Bitmap GetBitmapClippedCircle(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Path path = new Path(); path.addCircle((float) (width / 2), (float) (height / 2), (float) Math.min(width, (height / 2)), Path.Direction.CCW);// w w w .ja va 2 s . c o m Canvas canvas = new Canvas(outputBitmap); canvas.clipPath(path); canvas.drawBitmap(bitmap, 0, 0, null); return outputBitmap; }
From source file:Main.java
public static Bitmap getScaledCircleCroppedBitmap(Bitmap bitmap, int destSize) { if (bitmap == null) return null; Bitmap output = Bitmap.createBitmap(destSize, destSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int srcSize = Math.min(bitmap.getWidth(), bitmap.getHeight()); final int srcX = (bitmap.getWidth() - srcSize) / 2; final int srcY = (bitmap.getHeight() - srcSize) / 2; final Rect srcRect = new Rect(srcX, srcY, srcX + srcSize, srcY + srcSize); final Rect destRect = new Rect(0, 0, destSize, destSize); final int color = 0xff424242; final Paint paint = new Paint(); paint.setAntiAlias(true);// w w w. ja v a 2 s . co m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(destSize / 2, destSize / 2, destSize / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, srcRect, destRect, paint); return output; }
From source file:Main.java
public static boolean endWiths(byte[] all, int length, byte[] sub) { if (all == null || sub == null || length < sub.length) return false; int allLen = Math.min(all.length, length); int subLen = sub.length; for (int i = 1; i < (subLen + 1); i++) { if (all[allLen - i] != sub[subLen - i]) return false; }//from ww w . ja v a 2s. c om return true; }
From source file:Main.java
public static Bitmap resize(final Bitmap b, final int newWidth, final int newHeight) { if (b == null) { return null; }/*ww w.java 2 s . c o m*/ int oldWidth = b.getWidth(); int oldHeight = b.getHeight(); if (oldWidth == newWidth && oldHeight == newHeight) { return b; } float scaleWidth = ((float) newWidth) / oldWidth; float scaleHeight = ((float) newHeight) / oldHeight; float scaleFactor = Math.min(scaleWidth, scaleHeight); Matrix scale = new Matrix(); scale.postScale(scaleFactor, scaleFactor); Bitmap result = Bitmap.createBitmap(b, 0, 0, oldWidth, oldHeight, scale, false); b.recycle(); return result; }