android.graphics.Color#green ( )源码实例Demo

下面列出了android.graphics.Color#green ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: PHONK   文件: _PDashboardBackground.java
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);
}
 
源代码2 项目: AdapterCommands   文件: ItemAdapter.java
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;
    }

  }
 
源代码3 项目: TemplateAppProject   文件: Utils.java
/**
 * 是否是深色的颜色
 *
 * @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;
}
 
/**
 * 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;
}
 
源代码5 项目: prayer-times-android   文件: MainActivity.java
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);
}
 
源代码6 项目: PowerFileExplorer   文件: ColorHelper.java
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);
}
 
源代码7 项目: Telegram-FOSS   文件: AndroidUtilities.java
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));
}
 
源代码8 项目: shift   文件: SlidingTabStrip.java
/**
 * 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);
}
 
源代码9 项目: dynamic-utils   文件: DynamicColorUtils.java
/**
 * 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);
}
 
源代码10 项目: opengl   文件: myColor.java
static float[] red() {
    return new float[]{
            Color.red(Color.RED) / 255f,
            Color.green(Color.RED) / 255f,
            Color.blue(Color.RED) / 255f,
            1.0f
    };
}
 
源代码11 项目: MonsterHunter4UDatabase   文件: SlidingTabStrip.java
/**
 * 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);
}
 
源代码12 项目: NightWatch   文件: CircleWatchface.java
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);
}
 
源代码13 项目: VideoOS-Android-SDK   文件: ColorUtil.java
/**
 * 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;
}
 
源代码14 项目: react-native-3d-model-view   文件: RN3DView.java
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();
}
 
源代码15 项目: Chimee   文件: PhotoOverlayActivity.java
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);
}
 
源代码16 项目: openlauncher   文件: ContextUtils.java
/**
 * 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)))));
}
 
源代码17 项目: material-drawer   文件: DrawerTheme.java
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;
}
 
源代码18 项目: Crasher   文件: ColorUtils.java
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;
}
 
/**
 * 从颜色找出角度
 * 
 * @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;
}
 
源代码20 项目: SimpleDialogFragments   文件: ColorView.java
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;
}