List of usage examples for android.graphics Color BLACK
int BLACK
To view the source code for android.graphics Color BLACK.
Click Source Link
From source file:Main.java
/** * @see android.view.Window#setStatusBarColor(int color). *//*from w w w . jav a 2s .c o m*/ public static void setStatusBarColor(Window window, int statusBarColor) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // If both system bars are black, we can remove these from our layout, // removing or shrinking the SurfaceFlinger overlay required for our views. if (statusBarColor == Color.BLACK && window.getNavigationBarColor() == Color.BLACK) { window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); } else { window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); } window.setStatusBarColor(statusBarColor); } }
From source file:Main.java
public static int getReadableTextColor(final int backgroundColor) { final int greyValue = grayscaleFromRGB(backgroundColor); // 186 chosen rather than the seemingly obvious 128 because of gamma. if (greyValue < 186) { return Color.WHITE; } else {//from w w w. ja v a2s .c om return Color.BLACK; } }
From source file:Main.java
public static Bitmap roundCorner(Bitmap src, float round) { int width = src.getWidth(); int height = src.getHeight(); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); canvas.drawARGB(0, 0, 0, 0);//w ww. j a v a 2 s . c om final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.BLACK); final Rect rect = new Rect(0, 0, width, height); final RectF rectF = new RectF(rect); canvas.drawRoundRect(rectF, round, round, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, rect, rect, paint); return result; }
From source file:Main.java
public static Bitmap getTextImage(String text, float size, int width, int height) { final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Paint paint = new Paint(); final Canvas canvas = new Canvas(bmp); canvas.drawColor(Color.WHITE); paint.setColor(Color.BLACK); paint.setStyle(Style.FILL);//w w w . java2 s. co m paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); paint.setTextSize(size); paint.setTypeface(Typeface.DEFAULT); canvas.drawText(text, width / 2, height / 2, paint); return bmp; }
From source file:Main.java
/** * @param color//from w ww. jav a2s.co m * @return */ public static int getTextColor(int color) { if (luminosity(color) > 122) return Color.BLACK; else return Color.WHITE; }
From source file:Main.java
protected static Bitmap creatCodeBitmap(String contents, int width, int height, Context context) { TextView tv = new TextView(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); tv.setLayoutParams(layoutParams);/*w w w . j a va 2s . co m*/ tv.setText(contents); tv.setHeight(height); tv.setGravity(Gravity.CENTER_HORIZONTAL); tv.setWidth(width); tv.setDrawingCacheEnabled(true); tv.setTextColor(Color.BLACK); tv.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight()); tv.buildDrawingCache(); Bitmap bitmapCode = tv.getDrawingCache(); return bitmapCode; }
From source file:Main.java
public static int getColor(String colorHex) { if (!colorHex.startsWith("#")) colorHex = "#" + colorHex; int a;//from ww w. j a v a2s. c om int r; int g; int b; if (colorHex.length() == 7) { a = 0xFF; r = Integer.parseInt(colorHex.substring(1, 3), 16); g = Integer.parseInt(colorHex.substring(3, 5), 16); b = Integer.parseInt(colorHex.substring(5, 7), 16); } else if (colorHex.length() == 9) { a = Integer.parseInt(colorHex.substring(1, 3), 16); r = Integer.parseInt(colorHex.substring(3, 5), 16); g = Integer.parseInt(colorHex.substring(5, 7), 16); b = Integer.parseInt(colorHex.substring(7, 9), 16); } else return Color.BLACK; int c = Color.argb(a, r, g, b); return c; }
From source file:Main.java
public static Bitmap addLabelToBitmap(Bitmap src, String label) { float densityFactor = Resources.getSystem().getDisplayMetrics().density; final float textPadding = src.getWidth() * 0.05f; Bitmap result = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); Paint textPaint = new Paint(); textPaint.setAntiAlias(true);// w w w . j a v a 2s . c o m textPaint.setTextSize(12 * densityFactor); textPaint.setColor(Color.WHITE); textPaint.setStrokeWidth(2 * densityFactor); textPaint.setShadowLayer(1 * densityFactor, 0, 0, Color.BLACK); float textWidth = textPaint.measureText(label); float scaleFactor = (src.getWidth() - textPadding * 2) / textWidth; canvas.drawBitmap(src, 0, 0, textPaint); canvas.save(); canvas.scale(scaleFactor, scaleFactor); float textPosX = (src.getWidth() / scaleFactor - textWidth) / 2; float textPosY = (src.getHeight() - textPadding) / scaleFactor; canvas.drawText(label, textPosX, textPosY, textPaint); canvas.restore(); return result; }
From source file:Main.java
static public int getAccentColor(Context context) { int identifier = context.getResources().getIdentifier("colorAccent", "attr", context.getPackageName()); if (identifier == 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { identifier = android.R.attr.colorAccent; }/*from w w w .jav a 2 s . c o m*/ if (identifier > 0) { TypedValue typedValue = new TypedValue(); TypedArray a = context.obtainStyledAttributes(typedValue.data, new int[] { identifier }); if (a != null) { int color = a.getColor(0, 0); a.recycle(); return color; } } return Color.BLACK; }
From source file:Main.java
public static int getBlackWhiteColor(int color) { double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255; if (darkness >= 0.5) { return Color.WHITE; } else//from ww w.j ava 2s . c om return Color.BLACK; }