Java Code Examples for android.graphics.Color#green()
The following examples show how to use
android.graphics.Color#green() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: _PDashboardBackground.java From PHONK with GNU General Public License v3.0 | 6 votes |
public void updateColor(String hex) throws JSONException, UnknownHostException { int c = Color.parseColor(hex); float alpha = (float) (Color.alpha(c) / 255.0); //html uses normalized values int r = Color.red(c); int g = Color.green(c); int b = Color.blue(c); JSONObject values = new JSONObject() .put("type", "background") .put("a", alpha) .put("r", r) .put("g", g) .put("b", b); JSONObject msg = new JSONObject() .put("type", "widget") .put("action", "add") .put("values", values); //TODO change to events //CustomWebsocketServer.getInstance(getContext()).send(msg); }
Example 2
Source File: ItemAdapter.java From AdapterCommands with Apache License 2.0 | 6 votes |
private int calculateTextColor(int color) { rgb[0] = Color.red(color); rgb[1] = Color.green(color); rgb[2] = Color.blue(color); for (int i = 0; i < rgb.length; i++) { double c = rgb[i]; c = c / 255.0; if (c <= 0.03928) { c = c / 12.92; } else { c = Math.pow((c + 0.055) / 1.055, 2.4); } rgbRes[i] = c; } double luminance = 0.2126 * rgbRes[0] + 0.7152 * rgbRes[1] + 0.0722 * rgbRes[2]; if (luminance > 0.179) { return Color.BLACK; } else { return Color.WHITE; } }
Example 3
Source File: AndroidUtilities.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public static int getAverageColor(int color1, int color2) { int r1 = Color.red(color1); int r2 = Color.red(color2); int g1 = Color.green(color1); int g2 = Color.green(color2); int b1 = Color.blue(color1); int b2 = Color.blue(color2); return Color.argb(255, (r1 / 2 + r2 / 2), (g1 / 2 + g2 / 2), (b1 / 2 + b2 / 2)); }
Example 4
Source File: RN3DView.java From react-native-3d-model-view with MIT License | 5 votes |
public void setBackgroundColor(final Integer color) { if (color == null) { return; } float red = (float) Color.red(color) / 255f; float green = (float) Color.green(color) / 255f; float blue = (float) Color.blue(color) / 255f; float alpha = (float) Color.alpha(color) / 255f; this.backgroundColor = new float[] {red, green, blue, alpha}; this.tryInitScene(); }
Example 5
Source File: ColorUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
/** * convert a color to hex string * * @param color * @return */ public static Integer getHexColor(Integer color) { if (color != null) { int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return (red / 16) * 1048576 + (red % 16) * 65536 + (green / 16) * 4096 + (green % 16) * 256 + (blue / 16) * 16 + (blue % 16); } return 0; }
Example 6
Source File: CircleWatchface.java From NightWatch with GNU General Public License v3.0 | 5 votes |
public int darken(int color, double fraction) { int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); red = darkenColor(red, fraction); green = darkenColor(green, fraction); blue = darkenColor(blue, fraction); int alpha = Color.alpha(color); return Color.argb(alpha, red, green, blue); }
Example 7
Source File: SlidingTabStrip.java From MonsterHunter4UDatabase with MIT License | 5 votes |
/** * Blend {@code color1} and {@code color2} using the given ratio. * * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend, * 0.0 will return {@code color2}. */ private static int blendColors(int color1, int color2, float ratio) { final float inverseRation = 1f - ratio; float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation); float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation); float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation); return Color.rgb((int) r, (int) g, (int) b); }
Example 8
Source File: myColor.java From opengl with Apache License 2.0 | 5 votes |
static float[] red() { return new float[]{ Color.red(Color.RED) / 255f, Color.green(Color.RED) / 255f, Color.blue(Color.RED) / 255f, 1.0f }; }
Example 9
Source File: DynamicColorUtils.java From dynamic-utils with Apache License 2.0 | 5 votes |
/** * Adjust alpha of a color according to the given parameter. * * @param color The color whose alpha to be adjusted. * @param factor Factor in float by which adjust the alpha. * * @return The color with adjusted alpha. */ public static @ColorInt int adjustAlpha(@ColorInt int color, float factor) { int alpha = Math.min(255, (int) (Color.alpha(color) * factor)); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return Color.argb(alpha, red, green, blue); }
Example 10
Source File: SlidingTabStrip.java From shift with Apache License 2.0 | 5 votes |
/** * Blend {@code color1} and {@code color2} using the given ratio. * * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend, * 0.0 will return {@code color2}. */ private static int blendColors(int color1, int color2, float ratio) { final float inverseRation = 1f - ratio; float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation); float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation); float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation); return Color.rgb((int) r, (int) g, (int) b); }
Example 11
Source File: Utils.java From TemplateAppProject with Apache License 2.0 | 5 votes |
/** * 是否是深色的颜色 * * @param color * @return */ public static boolean isColorDark(@ColorInt int color) { double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255; return darkness >= 0.382; }
Example 12
Source File: ColorHelper.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
public static int disableColor(int color) { int alpha = Color.alpha(color); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return Color.argb((int) (alpha * 0.2f), red, green, blue); }
Example 13
Source File: MainActivity.java From prayer-times-android with Apache License 2.0 | 5 votes |
public static int blendColors(int color1, int color2, float ratio) { final float inverseRation = 1f - ratio; float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation); float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation); float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation); return Color.rgb((int) r, (int) g, (int) b); }
Example 14
Source File: FlatFragmentActivity.java From SimpleDialogFragments with Apache License 2.0 | 5 votes |
/** * Let the hosting fragment or activity implement this interface * to receive results from the dialog * * @param dialogTag the tag passed to {@link SimpleDialog#show} * @param which result type, one of {@link #BUTTON_POSITIVE}, {@link #BUTTON_NEGATIVE}, * {@link #BUTTON_NEUTRAL} or {@link #CANCELED} * @param extras the extras passed to {@link SimpleDialog#extra(Bundle)} * @return true if the result was handled, false otherwise */ @Override public boolean onResult(@NonNull String dialogTag, int which, @NonNull Bundle extras) { // handle results as usual if (COLOR_FRAGMENT.equals(dialogTag) && which == BUTTON_POSITIVE) { @ColorInt int color = extras.getInt(SimpleColorDialog.COLOR); // Sets action bar colors if (getSupportActionBar() != null) { getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xFF000000 | color)); boolean dark = Color.red(color) * 0.299 + Color.green(color) * 0.587 + Color.blue(color) * 0.114 < 180; SpannableString s = new SpannableString(getSupportActionBar().getTitle()); s.setSpan(new ForegroundColorSpan(dark ? Color.WHITE : Color.BLACK), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); getSupportActionBar().setTitle(s); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= 0.75; getWindow().setStatusBarColor(Color.HSVToColor(hsv)); } return true; } return false; }
Example 15
Source File: ColorCircularSeekBar.java From Gizwits-SmartBuld_Android with MIT License | 4 votes |
/** * 从颜色找出角度 * * @param color * @return */ private float fromColor2Degree(int color) { float degree = 0; int diff = 360 / (mCircleColors.length - 1); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); int[] mColor = { b, g, r }; // 把最大的,置0xFF,最小的,置0 int min = findMin(b, g, r); int max = findMax(b, g, r); int temp = (0xff << (max * 8)) +( 0xff << (8 * 3)); if (max == min) {//证明RGB相等; return 90;// 九十度 } int mid = 3 - max - min; int start = 0; int end = 0; for (int i = 0; i < mCircleColors.length - 2; i++) { if (mCircleColors[i] - temp == 0) start = i; if (mCircleColors[i] - temp == (0xff << (mid * 8))) end = i; } float percent = (float) mColor[mid] / (float) 0xff; int degreeDiff = (int) (percent * diff); if (start < end) { degree = start * diff; degree += degreeDiff; } else { degree = start * diff; degree -= degreeDiff; } degree += 90; if (degree > 360) degree -= 360; return degree; }
Example 16
Source File: ColorView.java From SimpleDialogFragments with Apache License 2.0 | 4 votes |
public static boolean isColorDark(@ColorInt int color) { double brightness = Color.red(color) * 0.299 + Color.green(color) * 0.587 + Color.blue(color) * 0.114; return brightness < 180; }
Example 17
Source File: ColorUtils.java From Crasher with Apache License 2.0 | 4 votes |
public static boolean isColorDark(int color) { return (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255 < 0.5; }
Example 18
Source File: DrawerTheme.java From material-drawer with MIT License | 4 votes |
private boolean isLightColor(int color) { return (1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255) < 0.5; }
Example 19
Source File: ContextUtils.java From openlauncher with Apache License 2.0 | 4 votes |
/** * Try to guess if the color on top of the given {@code colorOnBottomInt} * should be light or dark. Returns true if top color should be light */ public boolean shouldColorOnTopBeLight(@ColorInt final int colorOnBottomInt) { return 186 > (((0.299 * Color.red(colorOnBottomInt)) + ((0.587 * Color.green(colorOnBottomInt)) + (0.114 * Color.blue(colorOnBottomInt))))); }
Example 20
Source File: PhotoOverlayActivity.java From Chimee with MIT License | 4 votes |
private int getColorWithAlpha(int alpha, int color) { int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return Color.argb(alpha, red, green, blue); }