Android LinearGradient - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android LinearGradient class.

This code example shows how to use the following methods:
			float x1 = endPoint.getX().getAsPixels(view);
			float y1 = endPoint.getY().getAsPixels(view);
 
			switch (gradientType) {
			case LINEAR_GRADIENT:
				return new LinearGradient(x0, y0, x1, y1, colors, offsets, TileMode.CLAMP);
			case RADIAL_GRADIENT:
				// TODO: implement radial gradient 
				return null; 
			default: 
				throw new AssertionError("No valid gradient type set.");
			} 
		} 
	} 
 
	public int[] getColors() 
	{ 
		return colors;
	} 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		if (paint == null) {
			paint = new Paint();
			luar = new LinearGradient(0.f, 0.f, 0.f, this.getMeasuredHeight(), 0xffffffff, 0xff000000, TileMode.CLAMP);
		} 
		int rgb = Color.HSVToColor(color);
		Shader dalam = new LinearGradient(0.f, 0.f, this.getMeasuredWidth(), 0.f, 0xffffffff, rgb, TileMode.CLAMP);
		ComposeShader shader = new ComposeShader(luar, dalam, PorterDuff.Mode.MULTIPLY);
		paint.setShader(shader);
		canvas.drawRect(0.f, 0.f, this.getMeasuredWidth(), this.getMeasuredHeight(), paint);
	} 
 
	void setHue(float hue) {
		color[0] = hue;
		invalidate();
	} 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
       //Draw in the reflection 
       canvas.drawBitmap(reflectionImage,0, height-6, null);
        
       //Create a shader that is a linear gradient that covers the reflection 
       Paint paint = new Paint(); 
       LinearGradient shader = new LinearGradient(0, original.getHeight(), 0, 
         bitmapWithReflection.getHeight(), 0x70ffffff, 0x00ffffff, 
         TileMode.CLAMP); 
       //Set the paint to use this shader (linear gradient) 
       paint.setShader(shader); 
       //Set the Transfer mode to be porter duff and destination in 
       paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); 
       //Draw a rectangle using the paint with our linear gradient 
       canvas.drawRect(0, height-6, width, 
         bitmapWithReflection.getHeight(), paint); 
       //Draw in the original image 
       canvas.drawBitmap(original, 0, 0, null);
       original.recycle();
       reflectionImage.recycle();
       try{ 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
        } else { 
            mColorGradientPaint.setShader(new LinearGradient(
                    0, 0, 0, off-2, MIDDLE_COLOR&0xffffff, MIDDLE_COLOR, Shader.TileMode.CLAMP));
        } 
        mEdgeGradientPaint.setShader(new LinearGradient(
                0, 0, 0, off/2, 0x00a0a0a0, 0xffa0a0a0, Shader.TileMode.CLAMP));
    } 
 
    @Override 
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        updateIndicator(); 
    } 
 
    @Override 
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
 
        int width = getWidth();
 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
	@Override 
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		final int width = getWidth(), height = getHeight();
		final Paint paint = new Paint();
		final LinearGradient shader = new LinearGradient(width / 2, 0, width / 2, height, 0xffffffff, 0x00ffffff,
				Shader.TileMode.CLAMP);
		paint.setShader(shader);
		paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
		canvas.drawRect(0, 0, width, height, paint);
	} 
 
	@Override 
	protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
		final int width = MeasureSpec.getSize(widthMeasureSpec);
		setMeasuredDimension(width, width / 2);
		// super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
	} 
 
	@Override 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
        // Clamp mode will repeat the last row of pixels. 
        // Hence its better to have an endAlpha of 0 for the linear-gradient. 
	BitmapShader bitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
 
	// A linear-gradient to specify the opacity of the bitmap. 
	LinearGradient gradient = new LinearGradient(0, 0, 0, mBitmap.getHeight(), mStartColor, mEndColor, Shader.TileMode.CLAMP);
 
	// Make a combined shader -- a performance win. 
        // The linear-gradient is the 'SRC' and the bitmap-shader is the 'DST'. 
	// Drawing the DST in the SRC will provide the opacity. 
	mPaint.setShader(new ComposeShader(bitmapShader, gradient, PorterDuff.Mode.DST_IN));
    } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setShader
			mGreenText.setText(Integer.toString(green)); 
			mBlueText.setText(Integer.toString(blue)); 
            redSeekBar.setProgress(red); 
            greenSeekBar.setProgress(green); 
            blueSeekBar.setProgress(blue); 
			mNewBoxBackground.getPaint().setShader(getPreviewBackground(newColor, mNewBoxBackground.getBounds())); 
			mPreviousBoxBackground.getPaint().setShader(getPreviewBackground(mPreviousColor, mPreviousBoxBackground.getBounds())); 
			mNewBoxBackground.invalidateSelf(); 
			mPreviousBoxBackground.invalidateSelf(); 
			broadcastColorChange(); 
		} 
 
	}; 
 
	/** 
	 * Returns a "glossy" background using the given color and the given bounds. Currently, 
	 * the gloss is applied vertically from top to bottom. 
	 * 
	 * @param color the color to be "glossed" 
	 * @param rect the bounds of the area to be glossed 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
This code example shows how to use the following methods:
        canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);
 
        canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
 
        Paint paint = new Paint();
        LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
                bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,
                0x00ffffff, TileMode.CLAMP);
        paint.setShader(shader);
        // Set the Transfer mode to be porter duff and destination in 
        paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
        // Draw a rectangle using the paint with our linear gradient 
        canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
                + reflectionGap, paint);
 
        return bitmapWithReflection;
    } 
     
    /** 
     * 将bitmap转化为drawable 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
					mBarPointerHaloRadius,
					0, 
					(mBarLength + mBarPointerHaloRadius),
					mBarThickness,
					new int[] { Color.HSVToColor(0xFF, mHSVColor), Color.BLACK },
					null, Shader.TileMode.CLAMP);
		} else { 
			shader = new LinearGradient(mBarPointerHaloRadius, 0,
					(mBarLength + mBarPointerHaloRadius), mBarThickness,
					new int[] { 0xff81ff00, Color.BLACK }, null,
					Shader.TileMode.CLAMP);
			Color.colorToHSV(0xff81ff00, mHSVColor);
		} 
 
		mBarPaint.setShader(shader);
		mPosToSatFactor = 1 / ((float) mBarLength);
		mSatToPosFactor = ((float) mBarLength) / 1;
 
		float[] hsvColor = new float[3];
		Color.colorToHSV(mColor, hsvColor);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android LinearGradient Questions & Answers:

See Code Examples for Android LinearGradient Methods: