List of usage examples for android.graphics RadialGradient RadialGradient
public RadialGradient(float centerX, float centerY, float radius, @ColorInt int centerColor, @ColorInt int edgeColor, @NonNull TileMode tileMode)
From source file:Main.java
/** * Create a Bitmap that will be used as a mask to create the preview window in the background. * The Bitmap will be the given width and height. The Bitmap will be transparent except for a * gradient on the left and bottom sides. * * @param width Width of the mask./*from w w w .j a v a 2 s .co m*/ * @param height Height of the mask. * @param gradientSize Size of the gradient. * @return Bitmap mask that will be used to create a preview window. */ private static Bitmap createPreviewWindowMask(int width, int height, int gradientSize) { // Do nothing if the size is invalid if (width <= 0 || height <= 0) { return null; } // Initialize the mask Bitmap mask = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(mask); canvas.drawColor(Color.TRANSPARENT); // If the gradient size is zero, don't draw the gradients if (gradientSize <= 0) { return mask; } // Calculate gradient rects Rect leftGradientRect = new Rect(0, 0, gradientSize, height - gradientSize); Rect bottomGradientRect = new Rect(leftGradientRect.right, height - gradientSize, width, height); Rect cornerGradientRect = new Rect(leftGradientRect.left, leftGradientRect.bottom, bottomGradientRect.left, bottomGradientRect.bottom); // Create left gradient Paint leftGradientPaint = new Paint(); leftGradientPaint.setDither(true); leftGradientPaint.setShader(new LinearGradient(leftGradientRect.left, 0, leftGradientRect.right, 0, Color.BLACK, Color.TRANSPARENT, Shader.TileMode.CLAMP)); // Create right gradient Paint bottomGradientPaint = new Paint(); bottomGradientPaint.setDither(true); bottomGradientPaint.setShader( new LinearGradient(leftGradientRect.right, bottomGradientRect.bottom, leftGradientRect.right, bottomGradientRect.top, Color.BLACK, Color.TRANSPARENT, Shader.TileMode.CLAMP)); // Create corner gradient Paint cornerGradientPaint = new Paint(); cornerGradientPaint.setDither(true); cornerGradientPaint.setShader(new RadialGradient(cornerGradientRect.right, cornerGradientRect.top, gradientSize, Color.TRANSPARENT, Color.BLACK, Shader.TileMode.CLAMP)); // Draw the gradients canvas.drawRect(leftGradientRect, leftGradientPaint); canvas.drawRect(bottomGradientRect, bottomGradientPaint); canvas.drawRect(cornerGradientRect, cornerGradientPaint); return mask; }
From source file:com.xbm.android.matisse.internal.ui.widget.CheckView.java
private void initShadowPaint() { if (mShadowPaint == null) { mShadowPaint = new Paint(); mShadowPaint.setAntiAlias(true); // all in dp float outerRadius = STROKE_RADIUS + STROKE_WIDTH / 2; float innerRadius = outerRadius - STROKE_WIDTH; float gradientRadius = outerRadius + SHADOW_WIDTH; float stop0 = (innerRadius - SHADOW_WIDTH) / gradientRadius; float stop1 = innerRadius / gradientRadius; float stop2 = outerRadius / gradientRadius; float stop3 = 1.0f; mShadowPaint.setShader(new RadialGradient((float) SIZE * mDensity / 2, (float) SIZE * mDensity / 2, gradientRadius * mDensity, new int[] { Color.parseColor("#00000000"), Color.parseColor("#0D000000"), Color.parseColor("#0D000000"), Color.parseColor("#00000000") }, new float[] { stop0, stop1, stop2, stop3 }, Shader.TileMode.CLAMP)); }/*from ww w .j a va2 s .c o m*/ }
From source file:android.support.wear.widget.drawer.PageIndicatorView.java
private void updateDotPaint(Paint dotPaint, Paint shadowPaint, float baseRadius, float shadowRadius, int color, int shadowColor) { float radius = baseRadius + shadowRadius; float shadowStart = baseRadius / radius; Shader gradient = new RadialGradient(0, 0, radius, new int[] { shadowColor, shadowColor, Color.TRANSPARENT }, new float[] { 0f, shadowStart, 1f }, TileMode.CLAMP);/*from w ww .j a v a 2 s . co m*/ shadowPaint.setShader(gradient); dotPaint.setColor(color); dotPaint.setStyle(Style.FILL); }
From source file:com.vuze.android.remote.activity.LoginActivity.java
@SuppressWarnings("deprecation") private void setBackgroundGradient() { ViewGroup mainLayout = (ViewGroup) findViewById(R.id.main_loginlayout); assert mainLayout != null; int h = mainLayout.getHeight(); int w = mainLayout.getWidth(); View viewCenterOn = findViewById(R.id.login_frog_logo); assert viewCenterOn != null; RectShape shape = new RectShape(); ShapeDrawable mDrawable = new ShapeDrawable(shape); int color1 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_1); int color2 = AndroidUtilsUI.getStyleColor(this, R.attr.login_grad_color_2); RadialGradient shader;/*from w w w . ja v a 2 s .c om*/ if (w > h) { int left = viewCenterOn.getLeft() + (viewCenterOn.getWidth() / 2); int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2); int remaining = w - left; shader = new RadialGradient(left, top, remaining, new int[] { color1, color2 }, new float[] { 0, 1.0f }, Shader.TileMode.CLAMP); } else { int top = viewCenterOn.getTop() + (viewCenterOn.getHeight() / 2); shader = new RadialGradient(w / 2, top, w * 2 / 3, color1, color2, Shader.TileMode.CLAMP); } mDrawable.setBounds(0, 0, w, h); mDrawable.getPaint().setShader(shader); mDrawable.getPaint().setDither(true); mDrawable.getPaint().setAntiAlias(true); mDrawable.setDither(true); mainLayout.setDrawingCacheEnabled(true); mainLayout.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); mainLayout.setAnimationCacheEnabled(false); mainLayout.setBackgroundDrawable(mDrawable); }
From source file:me.lizheng.deckview.helpers.FakeShadowDrawable.java
private void buildShadowCorners() { RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius); RectF outerBounds = new RectF(innerBounds); outerBounds.inset(-mShadowSize, -mShadowSize); if (mCornerShadowPath == null) { mCornerShadowPath = new Path(); } else {/*from w w w.j a va 2s . c o m*/ mCornerShadowPath.reset(); } mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD); mCornerShadowPath.moveTo(-mCornerRadius, 0); mCornerShadowPath.rLineTo(-mShadowSize, 0); // outer arc mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false); // inner arc mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false); mCornerShadowPath.close(); float startRatio = mCornerRadius / (mCornerRadius + mShadowSize); mCornerShadowPaint.setShader(new RadialGradient(0, 0, mCornerRadius + mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, startRatio, 1f }, Shader.TileMode.CLAMP)); // we offset the content shadowSize/2 pixels up to make it more realistic. // this is why edge shadow shader has some extra space // When drawing bottom edge shadow, we use that extra space. mEdgeShadowPaint.setShader(new LinearGradient(0, -mCornerRadius + mShadowSize, 0, -mCornerRadius - mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, .5f, 1f }, Shader.TileMode.CLAMP)); }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void DrawDevices() { Bitmap charty = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888); Canvas DeviceCanvas = new Canvas(charty); final Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(getResources().getColor(R.color.DarkBlue)); paint.setAntiAlias(true);//from www . j a v a 2s .c o m DeviceCanvas.drawOval(new RectF(1, 1, 199, 199), paint); RadialGradient gradient = new RadialGradient(100, 50, 150, 0xFF6b7681, 0xFF000000, android.graphics.Shader.TileMode.CLAMP); paint.setDither(true); paint.setShader(gradient); DeviceCanvas.drawOval(new RectF(6, 6, 194, 194), paint); int Scale = 10; //Special Bits if (DeviceCount < 500) Scale = 750; if (DeviceCount < 250) Scale = 350; if (DeviceCount < 100) Scale = 150; if (DeviceCount < 50) Scale = 50; try { drawScale(DeviceCanvas, false, DeviceCount, Scale); drawGaugeTitle(DeviceCanvas, "Device Count"); drawGaugeNeedle(DeviceCanvas, DeviceCount, Scale); //drawGloss(EventsCanvas); ((ImageView) findViewById(R.id.DeviceGauge)).setImageBitmap(charty); } catch (Exception e) { e.printStackTrace(); } }
From source file:android.support.design.widget.ShadowDrawableWrapper.java
private void buildShadowCorners() { RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius); RectF outerBounds = new RectF(innerBounds); outerBounds.inset(-mShadowSize, -mShadowSize); if (mCornerShadowPath == null) { mCornerShadowPath = new Path(); } else {//from ww w .ja v a2 s. c o m mCornerShadowPath.reset(); } mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD); mCornerShadowPath.moveTo(-mCornerRadius, 0); mCornerShadowPath.rLineTo(-mShadowSize, 0); // outer arc mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false); // inner arc mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false); mCornerShadowPath.close(); float shadowRadius = -outerBounds.top; if (shadowRadius > 0f) { float startRatio = mCornerRadius / shadowRadius; float midRatio = startRatio + ((1f - startRatio) / 2f); mCornerShadowPaint.setShader(new RadialGradient(0, 0, shadowRadius, new int[] { 0, mShadowStartColor, mShadowMiddleColor, mShadowEndColor }, new float[] { 0f, startRatio, midRatio, 1f }, Shader.TileMode.CLAMP)); } // we offset the content shadowSize/2 pixels up to make it more realistic. // this is why edge shadow shader has some extra space // When drawing bottom edge shadow, we use that extra space. mEdgeShadowPaint.setShader(new LinearGradient(0, innerBounds.top, 0, outerBounds.top, new int[] { mShadowStartColor, mShadowMiddleColor, mShadowEndColor }, new float[] { 0f, .5f, 1f }, Shader.TileMode.CLAMP)); mEdgeShadowPaint.setAntiAlias(false); }
From source file:net.networksaremadeofstring.rhybudd.RhybuddDock.java
private void DrawEvents() { Bitmap charty = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888); Canvas EventsCanvas = new Canvas(charty); final Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(getResources().getColor(R.color.DarkBlue)); paint.setAntiAlias(true);//ww w . ja va2s.co m EventsCanvas.drawOval(new RectF(1, 1, 199, 199), paint); RadialGradient gradient = new RadialGradient(200, 200, 200, 0xFF6b7681, 0xFF000000, android.graphics.Shader.TileMode.CLAMP); paint.setDither(true); paint.setShader(gradient); EventsCanvas.drawOval(new RectF(6, 6, 194, 194), paint); //Special Bits int Scale = 100; if (EventCount > 100) ; Scale = EventCount + 50; drawScale(EventsCanvas, true, EventCount, Scale); drawGaugeTitle(EventsCanvas, "Events Count"); drawGaugeNeedle(EventsCanvas, EventCount, Scale); //drawGloss(EventsCanvas); ((ImageView) findViewById(R.id.EventsGauge)).setImageBitmap(charty); }
From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java
public void calculateGradient(float _radius, int _initColor, int _endColor) { int[] Colors = { _initColor, _initColor, _endColor }; shadowPathPaint/*from ww w.ja v a2 s . c o m*/ .setShader(new RadialGradient(medX, medY, _radius, Colors, ColorStops, Shader.TileMode.CLAMP)); }
From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java
public static Drawable createRGradient(int shape, final int[] colors, final float[] positions) { ShapeDrawable shapeDrawable;//from www.j a va 2 s.c o m if (shape == SHAPE_RECT) { shapeDrawable = new ShapeDrawable(new RectShape()); } else { shapeDrawable = new ShapeDrawable(new OvalShape()); } ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { float gradRadius = Math.max(width, height) / 2; RadialGradient rg = new RadialGradient(width / 2, height / 2, gradRadius, colors, positions, Shader.TileMode.CLAMP); return rg; } }; shapeDrawable.setShaderFactory(shaderFactory); return shapeDrawable; }