List of usage examples for java.lang Math min
@HotSpotIntrinsicCandidate public static double min(double a, double b)
From source file:Main.java
private static int adjustColorBrightness(int argb, float factor) { final float[] hsv = new float[3]; Color.colorToHSV(argb, hsv);/* w w w . ja va2 s . c o m*/ hsv[2] = Math.min(hsv[2] * factor, 1f); return Color.HSVToColor(Color.alpha(argb), hsv); }
From source file:Main.java
public static void setImageViewWidthBitmap(String imgPath, ImageView imageView) throws IOException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//from w w w . j av a 2s . com BitmapFactory.decodeFile(imgPath, options); options.inSampleSize = Math.min(options.outWidth / imageView.getWidth(), options.outHeight / imageView.getWidth()); options.inJustDecodeBounds = false; options.inPurgeable = true; options.inInputShareable = true; FileInputStream fis = new FileInputStream(imgPath); imageView.setImageBitmap(BitmapFactory.decodeFileDescriptor(fis.getFD(), null, options)); }
From source file:Main.java
public static int getFitInSampleSize(int reqWidth, int reqHeight, BitmapFactory.Options options) { int inSampleSize = 1; if (options.outWidth > reqWidth || options.outHeight > reqHeight) { int widthRatio = Math.round((float) options.outWidth / (float) reqWidth); int heightRatio = Math.round((float) options.outHeight / (float) reqHeight); inSampleSize = Math.min(widthRatio, heightRatio); }/*from w w w . ja va 2 s . c o m*/ return inSampleSize; }
From source file:Main.java
public static Bitmap getCircularBitmap(Bitmap srcBitmap) { // Calculate the circular bitmap width with border int squareBitmapWidth = Math.min(srcBitmap.getWidth(), srcBitmap.getHeight()); //int squareBitmapWidth = 300; // Initialize a new instance of Bitmap Bitmap dstBitmap = Bitmap.createBitmap(squareBitmapWidth, // Width squareBitmapWidth, // Height Bitmap.Config.ARGB_8888 // Config );// w w w . j av a2 s . c om Canvas canvas = new Canvas(dstBitmap); // Initialize a new Paint instance Paint paint = new Paint(); paint.setAntiAlias(true); Rect rect = new Rect(0, 0, squareBitmapWidth, squareBitmapWidth); RectF rectF = new RectF(rect); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); // Calculate the left and top of copied bitmap float left = (squareBitmapWidth - srcBitmap.getWidth()) / 2; float top = (squareBitmapWidth - srcBitmap.getHeight()) / 2; canvas.drawBitmap(srcBitmap, left, top, paint); srcBitmap.recycle(); return dstBitmap; }
From source file:Main.java
/** * Resizes an array of Objects to a specified size. * * @param list Array to be resized./*from w w w. ja va 2s .com*/ * @param newSize Array size after resizing * @return Array of type Object with the specified size */ static public Object resizeArray(Object[] list, int newSize) { Class type = list.getClass().getComponentType(); Object temp = Array.newInstance(type, newSize); System.arraycopy(list, 0, temp, 0, Math.min(Array.getLength(list), newSize)); return temp; }
From source file:Main.java
public static Bitmap createFramedImage(Drawable imageDrawable, int borderThickness) { int size = Math.min(imageDrawable.getMinimumWidth(), imageDrawable.getMinimumHeight()); Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); RectF outerRect = new RectF(0, 0, size, size); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.RED);/*from w w w . j ava 2s .c o m*/ canvas.drawRect(outerRect, 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: 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, outerPaint); framedCanvas.drawRect(innerRect, innerPaint); // 3. Set the Power Duff mode link: Paint outerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); outerPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); // 4. Draw a translucent rounded rectangle link: outerPaint.setColor(Color.argb(255, 255, 255, 255)); // framedCanvas.drawRoundRect(outerRect, cornerRadius, cornerRadius, outerPaint); framedCanvas.drawRect(outerRect, 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 final String invertMountPrefix(final String fileName) { for (int i = 0, n = Math.min(aliases.size(), mounts.size()); i < n; i++) { final String alias = aliases.get(i); final String mount = mounts.get(i); if (fileName.equals(alias)) { return mount; }/*from w ww. java 2 s. c o m*/ if (fileName.equals(mount)) { return alias; } } for (int i = 0, n = Math.min(aliasesPR.size(), mountsPR.size()); i < n; i++) { final String alias = aliasesPR.get(i); final String mount = mountsPR.get(i); if (fileName.startsWith(alias)) { return mount + fileName.substring(alias.length()); } if (fileName.startsWith(mount)) { return alias + fileName.substring(mount.length()); } } return null; }
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);// w w w.j a v 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
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; }// w w w . j ava2s . co 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 double[] minmax(List<Double> paramList) { if (paramList.size() == 0) { return new double[2]; }/*from w w w.j a va2s .c o m*/ double d1 = ((Double) paramList.get(0)).doubleValue(); double d2 = d1; int i = paramList.size(); for (int j = 1;; j++) { if (j >= i) { return new double[] { d1, d2 }; } double d3 = ((Double) paramList.get(j)).doubleValue(); d1 = Math.min(d1, d3); d2 = Math.max(d2, d3); } }