List of usage examples for android.graphics Color WHITE
int WHITE
To view the source code for android.graphics Color WHITE.
Click Source Link
From source file:Main.java
@Deprecated public static int getContrastYIQ(int color, int threshold) { return getContrastYIQ(color, threshold, Color.BLACK, Color.WHITE); }
From source file:Main.java
/** * save the bitmap to local,add give a white bg color * @param bitmap/*from w w w. j a va 2s . com*/ * @param path * @return */ public static boolean saveBitmapNoBgToSdCard(Bitmap bitmap, String path) { BufferedOutputStream bos = null; try { File file = new File(path); if (file.exists()) file.delete(); bos = new BufferedOutputStream(new FileOutputStream(file)); int w = bitmap.getWidth(); int h = bitmap.getHeight(); int w_new = w; int h_new = h; Bitmap resultBitmap = Bitmap.createBitmap(w_new, h_new, Bitmap.Config.ARGB_8888); // Paint paint = new Paint(); // paint.setColor(Color.WHITE); Canvas canvas = new Canvas(resultBitmap); canvas.drawColor(Color.WHITE); canvas.drawBitmap(bitmap, new Rect(0, 0, w, h), new Rect(0, 0, w_new, h_new), null); resultBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); bos.flush(); resultBitmap.recycle(); return true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (bos != null) { try { bos.close(); } catch (IOException e) { e.printStackTrace(); } } } return false; }
From source file:Main.java
public static int getContrastYIQ(int color, int threshold) { return getContrastYIQ(color, threshold, Color.BLACK, Color.WHITE); }
From source file:Main.java
public static Bitmap drawTextToBitmap(Context gContext, int gResId, String gText) { Resources resources = gContext.getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId); Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = Bitmap.Config.ARGB_8888; }// w ww . j av a 2 s.co m // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #808080 paint.setColor(Color.rgb(127, 127, 127)); // text size in pixels paint.setTextSize((int) (14 * scale * 5)); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.WHITE); // draw text to the Canvas center Rect bounds = new Rect(); paint.getTextBounds(gText, 0, gText.length(), bounds); // int x = (bitmap.getWidth() - bounds.width()) / 2; // int y = (bitmap.getHeight() + bounds.height()) / 2; //draw text to the bottom int x = (bitmap.getWidth() - bounds.width()) / 10 * 9; int y = (bitmap.getHeight() + bounds.height()) / 10 * 9; canvas.drawText(gText, x, y, paint); return bitmap; }
From source file:Main.java
/** * Create an spectrum color palette from a base color. Max 8 colors; after that * color are filled but with a reused color. *//*from w w w . jav a 2 s . c o m*/ public static int[] createMaterialSpectrumPalette(int color, final int count) { int[] palette = new int[count]; if (count > 0) { final boolean isDarkColor = isDarkColor(color); final float[] opacity = isDarkColor ? new float[] { .75f, .50f, .25f, .10f, .85f, .75f, .50f, .25f } : new float[] { .85f, .75f, .50f, .25f, .75f, .50f, .25f, .10f }; for (int i = 0; i < count; i++) { final int op = i % opacity.length; int mask = (isDarkColor && op < 4) || (!isDarkColor && op >= 4) ? Color.WHITE : Color.BLACK; float alpha = opacity[op]; palette[i] = applyMaskColor(color, mask, alpha); } } return palette; }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static Drawable getRippleDrawable(int pressedColor, Integer normalColor) { ColorStateList colorStateList = getPressedColorSelector(pressedColor); Drawable mask, content = null;/*ww w. j a v a2s .c o m*/ if (null == normalColor) { mask = new ShapeDrawable(); } else { content = new ColorDrawable(normalColor); mask = getRippleMask(Color.WHITE); } return new RippleDrawable(colorStateList, content, mask); }
From source file:Main.java
/** * Creates a color states-list./* w ww .j a v a 2s . c om*/ * * @param color * @return A state-list */ public static ColorStateList createColorStateList(int color) { // @formatter:off // FIXME - This is buggy. The minute we set the color in, the button is no longer clickable.... // [[-16842910], [16842908, -16842910], [16842919], [16842913], [16842908], []] // [-2147483648, -2147483648, -1, -1, -1, -16777216] return new ColorStateList( new int[][] { new int[] { -android.R.attr.state_enabled }, new int[] { android.R.attr.state_focused, -android.R.attr.state_enabled }, new int[] { android.R.attr.state_pressed }, new int[] { android.R.attr.state_selected }, new int[] { android.R.attr.state_focused }, new int[0] }, new int[] { Integer.MIN_VALUE, // !enabled Integer.MIN_VALUE, // focused & !enabled Color.WHITE, // pressed Color.WHITE, // selected Color.WHITE, // focused color }); // @formatter:on }
From source file:Main.java
private static int bitToRGB(int bit) { if (bit == 1) { return Color.WHITE; } else {//from w w w.ja va2 s.c o m return Color.BLACK; } }
From source file:Main.java
public static Bitmap drawTextToBitmap(Bitmap bitmap, String gText) { //Resources resources = gContext.getResources(); //float scale = resources.getDisplayMetrics().density; android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; }/*from w ww. j a v a 2 s.c o m*/ // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #3D3D3D paint.setColor(Color.rgb(61, 61, 61)); // text size in pixels paint.setTextSize((int) (21)); //* scale)); // text shadow paint.setShadowLayer(2f, 1f, 1f, Color.WHITE); // draw text to the Canvas center //Rect bounds = new Rect(); //paint.getTextBounds(gText, 0, gText.length(), bounds); int x = bitmap.getWidth() - 150;//bounds.width()) - 150; int y = bitmap.getHeight() - 27;//bounds.height()) - 30; // fill canvas.drawRect(x, y, x + 150, y + 27, paint); canvas.drawText(gText, x, y + 20, paint); return bitmap; }
From source file:Main.java
public static Bitmap getColorPreviewBitmap(final Context context, final int color, final boolean border) { if (context == null) return null; final float density = context.getResources().getDisplayMetrics().density; final int width = (int) (32 * density), height = (int) (32 * density); final Bitmap bm = Bitmap.createBitmap(width, height, Config.ARGB_8888); final Canvas canvas = new Canvas(bm); final int rectangleSize = (int) (density * 5); final int numRectanglesHorizontal = (int) Math.ceil(width / rectangleSize); final int numRectanglesVertical = (int) Math.ceil(height / rectangleSize); final Rect r = new Rect(); boolean verticalStartWhite = true; for (int i = 0; i <= numRectanglesVertical; i++) { boolean isWhite = verticalStartWhite; for (int j = 0; j <= numRectanglesHorizontal; j++) { r.top = i * rectangleSize;/* www . j a v a 2s. c o m*/ r.left = j * rectangleSize; r.bottom = r.top + rectangleSize; r.right = r.left + rectangleSize; final Paint paint = new Paint(); paint.setColor(isWhite ? Color.WHITE : Color.GRAY); canvas.drawRect(r, paint); isWhite = !isWhite; } verticalStartWhite = !verticalStartWhite; } canvas.drawColor(color); if (border) { final Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setStrokeWidth(1f * density); final float[] points = new float[] { 0, 0, width, 0, 0, 0, 0, height, width, 0, width, height, 0, height, width, height }; canvas.drawLines(points, paint); } return bm; }