List of usage examples for java.lang Math max
@HotSpotIntrinsicCandidate public static double max(double a, double b)
From source file:Main.java
/** * Method returning color with modified alpha proportional to given values. * * @param color color to modify/*from ww w.j a v a 2s. c om*/ * @param fullValue total value * @param partValue part of fullValue. When partValue equals fullValue, the alpha is 255. * @return color with alpha relative to partValue/fullValue ratio. */ public static int getColorWithProportionalAlpha(int color, float fullValue, float partValue) { float progress = Math.min(Math.max(partValue, 0), fullValue) / fullValue; return Color.argb(Math.round(Color.alpha(color) * progress), Color.red(color), Color.green(color), Color.blue(color)); }
From source file:Util.java
/** * Returns color based on 0-9 scale ranging from black to green. *///from w ww. j a v a 2 s.c om public static Color kgColor(int i) { int[][] rgb = { { 21, 0, 0 }, { 99, 0, 0 }, { 177, 0, 0 }, { 255, 0, 0 }, { 255, 85, 0 }, { 255, 170, 0 }, { 255, 255, 0 }, { 150, 225, 0 }, { 65, 194, 0 }, { 0, 164, 0 } }; int ii = 0; if (i > 9) ii = 9; else ii = Math.max(i, ii); float[] hsb = Color.RGBtoHSB(rgb[ii][0], rgb[ii][1], rgb[ii][2], null); return Color.getHSBColor(hsb[0], hsb[1], hsb[2]); }
From source file:Util.java
/** * Returns color based on 0-9 scale ranging from yellow to red. *///from w w w . j a v a 2 s. c o m public static Color yrColor(int i) { int[][] rgb = { { 255, 202, 0 }, { 255, 180, 0 }, { 255, 157, 0 }, { 255, 135, 0 }, { 255, 112, 0 }, { 255, 90, 0 }, { 255, 67, 0 }, { 255, 45, 0 }, { 255, 22, 0 }, { 255, 0, 0 } }; int ii = 0; if (i > 9) ii = 9; else ii = Math.max(i, ii); float[] hsb = Color.RGBtoHSB(rgb[ii][0], rgb[ii][1], rgb[ii][2], null); return Color.getHSBColor(hsb[0], hsb[1], hsb[2]); }
From source file:Main.java
private static int darkenColor(int color, double fraction) { return (int) Math.max(color - (color * fraction), 0); }
From source file:Main.java
public static Pair<Integer, Integer> getScreenDimensions(Context paramContext) { WindowManager localWindowManager = (WindowManager) paramContext.getSystemService("window"); DisplayMetrics localDisplayMetrics = new DisplayMetrics(); localWindowManager.getDefaultDisplay().getMetrics(localDisplayMetrics); int i = Math.min(localDisplayMetrics.widthPixels, localDisplayMetrics.heightPixels); int j = Math.max(localDisplayMetrics.widthPixels, localDisplayMetrics.heightPixels); return new Pair(Integer.valueOf(i), Integer.valueOf(j)); }
From source file:ColorUtilities.java
public static Color blend(Color c0, Color c1) { double totalAlpha = c0.getAlpha() + c1.getAlpha(); double weight0 = c0.getAlpha() / totalAlpha; double weight1 = c1.getAlpha() / totalAlpha; double r = weight0 * c0.getRed() + weight1 * c1.getRed(); double g = weight0 * c0.getGreen() + weight1 * c1.getGreen(); double b = weight0 * c0.getBlue() + weight1 * c1.getBlue(); double a = Math.max(c0.getAlpha(), c1.getAlpha()); return new Color((int) r, (int) g, (int) b, (int) a); }
From source file:Util.java
/** * Returns color based on 0-9 scale ranging from green to yellow. *//*from w ww .j a v a 2 s .com*/ public static Color gyColor(int i) { int[][] rgb = { { 0, 164, 0 }, { 19, 174, 0 }, { 41, 184, 0 }, { 65, 194, 0 }, { 91, 204, 0 }, { 119, 215, 0 }, { 150, 225, 0 }, { 183, 235, 0 }, { 218, 245, 0 }, { 255, 255, 0 } }; int ii = 0; if (i > 9) ii = 9; else ii = Math.max(i, ii); float[] hsb = Color.RGBtoHSB(rgb[ii][0], rgb[ii][1], rgb[ii][2], null); return Color.getHSBColor(hsb[0], hsb[1], hsb[2]); }
From source file:Main.java
public static Bitmap highlightSelectedFaceThumbnail(Bitmap originalBitmap) { Bitmap bitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, true); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true);/*from ww w.j a v a2 s .c o m*/ paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.parseColor("#3399FF")); int stokeWidth = Math.max(originalBitmap.getWidth(), originalBitmap.getHeight()) / 10; if (stokeWidth == 0) { stokeWidth = 1; } bitmap.getWidth(); paint.setStrokeWidth(stokeWidth); canvas.drawRect(0, 0, bitmap.getWidth(), bitmap.getHeight(), paint); return bitmap; }
From source file:Main.java
public static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // From Android 4.4 (KitKat) onward we can re-use if the byte size of // the new bitmap is smaller than the reusable bitmap candidate // allocation byte count. int width = targetOptions.outWidth / Math.max(1, targetOptions.inSampleSize); int height = targetOptions.outHeight / Math.max(1, targetOptions.inSampleSize); int byteCount = width * height * getBytesPerPixel(candidate.getConfig()); return byteCount <= candidate.getAllocationByteCount(); }//from www. j av a 2 s.c o m // On earlier versions, the dimensions must match exactly and the inSampleSize must be 1 return candidate.getWidth() == targetOptions.outWidth && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1; }
From source file:Util.java
/** * Calculate the minimum and maximum values out of a list of doubles. * /*from www . jav a2 s. c o 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 }; }