private Item createItem(String label, float percent, int sliceColor, int itemColor) { Item it = new Item(); it.mLabel = label; it.mItemColor = itemColor; it.cSliceColor = sliceColor; it.cPercent = percent; // Log.d(TAG, "Percent for "+it.mLabel+": "+it.cPercent); // Calculate the highlight color. Saturate at 0xff to make sure that high values // don't result in aliasing. it.mItemHighlight = Color.argb( 0xff, Math.min((int) (mHighlightStrength * (float) Color.red(itemColor)), 0xff), Math.min((int) (mHighlightStrength * (float) Color.green(itemColor)), 0xff), Math.min((int) (mHighlightStrength * (float) Color.blue(itemColor)), 0xff)); it.cSliceHighlight = Color.argb( 0xff, Math.min((int) (mHighlightStrength * (float) Color.red(sliceColor)), 0xff), Math.min((int) (mHighlightStrength * (float) Color.green(sliceColor)), 0xff), Math.min((int) (mHighlightStrength * (float) Color.blue(sliceColor)), 0xff)); float centerX = mPieBounds.width() / 2; float centerY = mPieBounds.height() / 2; float itemW = (mPieBounds.width() / 2) * it.cPercent; float itemH = (mPieBounds.height() / 2) * it.cPercent; it.cSliceBounds = new RectF(centerX - itemW, centerY - itemH, centerX + itemW, centerY + itemH); return it; }
protected void initCompassView() { setFocusable(true); Resources r = this.getResources(); circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG); circlePaint.setColor(R.color.transparent_color); circlePaint.setStrokeWidth(1); circlePaint.setStyle(Paint.Style.STROKE); textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); textPaint.setColor(r.getColor(R.color.text_color)); textPaint.setFakeBoldText(true); textPaint.setSubpixelText(true); textPaint.setTextAlign(Align.LEFT); textHeight = (int) textPaint.measureText("yY"); markerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); markerPaint.setColor(r.getColor(R.color.transparent_color)); markerPaint.setAlpha(200); markerPaint.setStrokeWidth(1); markerPaint.setStyle(Paint.Style.STROKE); markerPaint.setShadowLayer(2, 1, 1, r.getColor(R.color.transparent_color)); borderGradientColors = new int[4]; borderGradientPositions = new float[4]; borderGradientColors[3] = r.getColor(R.color.transparent_color); borderGradientColors[2] = r.getColor(R.color.transparent_color); borderGradientColors[1] = r.getColor(R.color.transparent_color); borderGradientColors[0] = r.getColor(R.color.transparent_color); borderGradientPositions[3] = 0.0f; borderGradientPositions[2] = 1 - 0.03f; borderGradientPositions[1] = 1 - 0.06f; borderGradientPositions[0] = 1.0f; glassGradientColors = new int[5]; glassGradientPositions = new float[5]; int glassColor = 245; glassGradientColors[4] = Color.argb(65, glassColor, glassColor, glassColor); glassGradientColors[3] = Color.argb(100, glassColor, glassColor, glassColor); glassGradientColors[2] = Color.argb(50, glassColor, glassColor, glassColor); glassGradientColors[1] = Color.argb(0, glassColor, glassColor, glassColor); glassGradientColors[0] = Color.argb(0, glassColor, glassColor, glassColor); glassGradientPositions[4] = 1 - 0.0f; glassGradientPositions[3] = 1 - 0.06f; glassGradientPositions[2] = 1 - 0.10f; glassGradientPositions[1] = 1 - 0.20f; glassGradientPositions[0] = 1 - 1.0f; skyHorizonColorFrom = r.getColor(R.color.transparent_color); skyHorizonColorTo = r.getColor(R.color.transparent_color); groundHorizonColorFrom = r.getColor(R.color.transparent_color); groundHorizonColorTo = r.getColor(R.color.transparent_color); }
private int rotateColor(int color, float rad) { float deg = rad * 180 / 3.1415927f; int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); ColorMatrix cm = new ColorMatrix(); ColorMatrix tmp = new ColorMatrix(); cm.setRGB2YUV(); tmp.setRotate(0, deg); cm.postConcat(tmp); tmp.setYUV2RGB(); cm.postConcat(tmp); final float[] a = cm.getArray(); int ir = floatToByte(a[0] * r + a[1] * g + a[2] * b); int ig = floatToByte(a[5] * r + a[6] * g + a[7] * b); int ib = floatToByte(a[10] * r + a[11] * g + a[12] * b); return Color.argb( Color.alpha(color), pinToByte(ir), pinToByte(ig), pinToByte(ib)); }
public LegendPainter() { labelPaint.setColor(Color.BLACK); backgroundPaint.setColor(Color.argb(200, 200, 200, 200)); backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE); borderPaint.setColor(Color.BLACK); borderPaint.setStyle(Paint.Style.STROKE); }
private int changeColorAlpha(int color, float value) { int alpha = Math.round(Color.alpha(color) * value); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return Color.argb(alpha, red, green, blue); }
private static int blendColors(int color1, int color2, float factor) { final float inverseFactor = 1f - factor; float a = (Color.alpha(color1) * factor) + (Color.alpha(color2) * inverseFactor); float r = (Color.red(color1) * factor) + (Color.red(color2) * inverseFactor); float g = (Color.green(color1) * factor) + (Color.green(color2) * inverseFactor); float b = (Color.blue(color1) * factor) + (Color.blue(color2) * inverseFactor); return Color.argb((int) a, (int) r, (int) g, (int) b); }
// 그리기 void Draw(Canvas canvas) { Paint pnt = new Paint(); pnt.setAntiAlias(true); int r; int alpha; for (r = rad, alpha = 1; r > 4; r--, alpha += 5) { pnt.setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color))); canvas.drawCircle(x, y, r, pnt); } }
/** Returns the current dim. */ public void setDim(int dim) { mDimAlpha = dim; if (mConfig.useHardwareLayers) { // Defer setting hardware layers if we have not yet measured, or there is no dim to draw if (getMeasuredWidth() > 0 && getMeasuredHeight() > 0) { mDimColorFilter.setColor(Color.argb(mDimAlpha, 0, 0, 0)); mDimLayerPaint.setColorFilter(mDimColorFilter); mContent.setLayerType(LAYER_TYPE_HARDWARE, mDimLayerPaint); } } else { float dimAlpha = mDimAlpha / 255.0f; if (mThumbnailView != null) { mThumbnailView.setDimAlpha(dimAlpha); } if (mHeaderView != null) { mHeaderView.setDimAlpha(dim); } } }
private int interpColor(int colors[], float unit) { if (unit <= 0) { return colors[0]; } if (unit >= 1) { return colors[colors.length - 1]; } float p = unit * (colors.length - 1); int i = (int) p; p -= i; // now p is just the fractional part [0...1) and i is the index int c0 = colors[i]; int c1 = colors[i + 1]; int a = ave(Color.alpha(c0), Color.alpha(c1), p); int r = ave(Color.red(c0), Color.red(c1), p); int g = ave(Color.green(c0), Color.green(c1), p); int b = ave(Color.blue(c0), Color.blue(c1), p); return Color.argb(a, r, g, b); }
public ShowcaseView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Get the attributes for the ShowcaseView final TypedArray styled = context .getTheme() .obtainStyledAttributes( attrs, R.styleable.ShowcaseView, R.attr.showcaseViewStyle, R.style.ShowcaseView); backColor = styled.getInt(R.styleable.ShowcaseView_sv_backgroundColor, Color.argb(128, 80, 80, 80)); detailTextColor = styled.getColor(R.styleable.ShowcaseView_sv_detailTextColor, Color.WHITE); titleTextColor = styled.getColor(R.styleable.ShowcaseView_sv_titleTextColor, Color.parseColor("#49C0EC")); buttonText = styled.getString(R.styleable.ShowcaseView_sv_buttonText); styled.recycle(); metricScale = getContext().getResources().getDisplayMetrics().density; mEndButton = (Button) LayoutInflater.from(context).inflate(R.layout.showcase_button, null); ConfigOptions options = new ConfigOptions(); options.showcaseId = getId(); setConfigOptions(options); }