List of usage examples for java.lang Math max
@HotSpotIntrinsicCandidate public static double max(double a, double b)
From source file:Main.java
/** Returns a Bitmap from the given URI that may be scaled by an integer factor to reduce its size, * so that its width and height are no greater than the corresponding parameters. The scale factor * will be a power of 2./*from ww w . j a va2 s . c o m*/ */ public static Bitmap scaledBitmapFromURIWithMaximumSize(Context context, Uri imageURI, int width, int height) throws FileNotFoundException { BitmapFactory.Options options = computeBitmapSizeFromURI(context, imageURI); options.inJustDecodeBounds = false; int wratio = powerOf2GreaterOrEqual(1.0 * options.outWidth / width); int hratio = powerOf2GreaterOrEqual(1.0 * options.outHeight / height); options.inSampleSize = Math.max(wratio, hratio); return BitmapFactory.decodeStream(context.getContentResolver().openInputStream(imageURI), null, options); }
From source file:Main.java
public static int setMinValue(int color, float newValue) { float hsv[] = new float[3]; Color.colorToHSV(color, hsv); hsv[2] = Math.max(hsv[2], newValue); return Color.HSVToColor(hsv); }
From source file:Main.java
/** * Retuns a darker color from a specified color by the factor. * @param color/*www .j av a 2 s . com*/ * @param factor * @return */ public static int darker(int color, float factor) { int a = Color.alpha(color); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); return Color.argb(a, Math.max((int) (r * factor), 0), Math.max((int) (g * factor), 0), Math.max((int) (b * factor), 0)); }
From source file:Main.java
/** * Get the extension of the file/* www .ja v a 2 s . co m*/ * * @param fileName Name (and location) of the file * @return Extension */ public static String getFileExtension(String fileName) { String extension = ""; int i = fileName.lastIndexOf('.'); int p = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\')); if (i > p) { extension = fileName.substring(i + 1); } return extension; }
From source file:Main.java
/** * //from ww w .j av a 2 s .c om * @param file */ public static void decodeFile(File file) { Bitmap bitmap = null; try { // Decode image size BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; FileInputStream fileInputStream = new FileInputStream(file); BitmapFactory.decodeStream(fileInputStream, null, options); fileInputStream.close(); int scale = 1; if (options.outHeight > 500 || options.outWidth > 500) { scale = (int) Math.pow(2, (int) Math.round( Math.log(500 / (double) Math.max(options.outHeight, options.outWidth)) / Math.log(0.5))); } // Decode with inSampleSize BitmapFactory.Options options2 = new BitmapFactory.Options(); options2.inSampleSize = scale; fileInputStream = new FileInputStream(file); bitmap = BitmapFactory.decodeStream(fileInputStream, null, options2); fileInputStream.close(); FileOutputStream output = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, output); output.flush(); output.close(); } catch (Exception e) { Log.e(TAG, e.getMessage()); } }
From source file:Main.java
public static String serializeOpenTag(String nsUri, String qname, Map<String, String> nsMappings, Attributes attrs, boolean optimizeNs) { String result = "<" + qname; if (nsUri != null && nsUri.length() > 0) { int idx = Math.max(qname.indexOf(':'), 0); nsMappings.put(qname.substring(0, idx), nsUri); }/*from w w w . j av a2s. c o m*/ for (int i = 0; i < attrs.getLength(); i++) { result += " " + attrs.getQName(i) + "=\"" + attrs.getValue(i) + "\""; } for (String key : nsMappings.keySet()) { if (optimizeNs) { boolean found = key.isEmpty() && qname.indexOf(':') == -1 || key.length() > 0 && qname.startsWith(key + ":"); for (int i = 0; i < attrs.getLength(); i++) { String aqn = attrs.getQName(i); if (aqn.startsWith("xml")) { continue; } if (key.isEmpty() && aqn.indexOf(':') == -1 || key.length() > 0 && aqn.startsWith(key + ":")) { found = true; break; } } if (!found) { continue; } } if (key.isEmpty()) { String value = nsMappings.get(key); result += " xmlns=\"" + value + "\""; } else { result += " xmlns:" + key + "=\"" + nsMappings.get(key) + "\""; } } result += ">"; return result; }
From source file:Main.java
public static Bitmap asBitmap(Drawable drawable, int minWidth, int minHeight) { final Rect tmpRect = new Rect(); drawable.copyBounds(tmpRect);//from w w w . ja v a 2s . c om if (tmpRect.isEmpty()) { tmpRect.set(0, 0, Math.max(minWidth, drawable.getIntrinsicWidth()), Math.max(minHeight, drawable.getIntrinsicHeight())); drawable.setBounds(tmpRect); } Bitmap bitmap = Bitmap.createBitmap(tmpRect.width(), tmpRect.height(), Bitmap.Config.ARGB_8888); drawable.draw(new Canvas(bitmap)); return bitmap; }
From source file:Main.java
public static Bitmap resizeDownIfTooBig(final Bitmap bitmap, final int targetSize, final boolean recycle) { final int srcWidth = bitmap.getWidth(); final int srcHeight = bitmap.getHeight(); final float scale = Math.max((float) targetSize / srcWidth, (float) targetSize / srcHeight); if (scale > 0.5f) return bitmap; return resizeBitmapByScale(bitmap, scale, recycle); }
From source file:Main.java
public static void visit(ThreadGroup group, int level, List<Thread> result) { // Get threads in `group' int numThreads = group.activeCount(); Thread[] threads = new Thread[Math.max(numThreads, 2) * 2]; numThreads = group.enumerate(threads, false); // Enumerate each thread in `group' for (int i = 0; i < numThreads; i++) { // Get thread Thread thread = threads[i]; result.add(thread);// w w w .j ava 2 s. c om } // Get thread subgroups of `group' int numGroups = group.activeGroupCount(); ThreadGroup[] groups = new ThreadGroup[numGroups * 2]; numGroups = group.enumerate(groups, false); // Recursively visit each subgroup for (int i = 0; i < numGroups; i++) { visit(groups[i], level + 1, result); } }
From source file:Main.java
private static int getMaxSlashCount(List<String> strings) { int maxCount = 0; for (String string : strings) { maxCount = Math.max(maxCount, getSlashCount(string)); }/*from www . j av a 2 s.c o m*/ return maxCount; }