Search in sources :

Example 6 with LinearGradient

use of android.graphics.LinearGradient in project android_frameworks_base by ParanoidAndroid.

the class RecentsScrollViewPerformanceHelper method drawCallback.

public void drawCallback(Canvas canvas, int left, int right, int top, int bottom, int scrollX, int scrollY, float topFadingEdgeStrength, float bottomFadingEdgeStrength, float leftFadingEdgeStrength, float rightFadingEdgeStrength, int mPaddingTop) {
    if ((mSoftwareRendered && OPTIMIZE_SW_RENDERED_RECENTS) || USE_DARK_FADE_IN_HW_ACCELERATED_MODE) {
        if (mFadePaint == null) {
            mFadePaint = new Paint();
            mFadeMatrix = new Matrix();
            // use use a height of 1, and then wack the matrix each time we
            // actually use it.
            mFade = new LinearGradient(0, 0, 0, 1, 0xCC000000, 0, Shader.TileMode.CLAMP);
            // PULL OUT THIS CONSTANT
            mFadePaint.setShader(mFade);
        }
        // draw the fade effect
        boolean drawTop = false;
        boolean drawBottom = false;
        boolean drawLeft = false;
        boolean drawRight = false;
        float topFadeStrength = 0.0f;
        float bottomFadeStrength = 0.0f;
        float leftFadeStrength = 0.0f;
        float rightFadeStrength = 0.0f;
        final float fadeHeight = mFadingEdgeLength;
        int length = (int) fadeHeight;
        // overlapping fades produce odd-looking artifacts
        if (mIsVertical && (top + length > bottom - length)) {
            length = (bottom - top) / 2;
        }
        // also clip horizontal fades if necessary
        if (!mIsVertical && (left + length > right - length)) {
            length = (right - left) / 2;
        }
        if (mIsVertical) {
            topFadeStrength = Math.max(0.0f, Math.min(1.0f, topFadingEdgeStrength));
            drawTop = topFadeStrength * fadeHeight > 1.0f;
            bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, bottomFadingEdgeStrength));
            drawBottom = bottomFadeStrength * fadeHeight > 1.0f;
        }
        if (!mIsVertical) {
            leftFadeStrength = Math.max(0.0f, Math.min(1.0f, leftFadingEdgeStrength));
            drawLeft = leftFadeStrength * fadeHeight > 1.0f;
            rightFadeStrength = Math.max(0.0f, Math.min(1.0f, rightFadingEdgeStrength));
            drawRight = rightFadeStrength * fadeHeight > 1.0f;
        }
        if (drawTop) {
            mFadeMatrix.setScale(1, fadeHeight * topFadeStrength);
            mFadeMatrix.postTranslate(left, top);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(left, top, right, top + length, mFadePaint);
            if (mBlackPaint == null) {
                // Draw under the status bar at the top
                mBlackPaint = new Paint();
                mBlackPaint.setColor(0xFF000000);
            }
            canvas.drawRect(left, top - mPaddingTop, right, top, mBlackPaint);
        }
        if (drawBottom) {
            mFadeMatrix.setScale(1, fadeHeight * bottomFadeStrength);
            mFadeMatrix.postRotate(180);
            mFadeMatrix.postTranslate(left, bottom);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(left, bottom - length, right, bottom, mFadePaint);
        }
        if (drawLeft) {
            mFadeMatrix.setScale(1, fadeHeight * leftFadeStrength);
            mFadeMatrix.postRotate(-90);
            mFadeMatrix.postTranslate(left, top);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(left, top, left + length, bottom, mFadePaint);
        }
        if (drawRight) {
            mFadeMatrix.setScale(1, fadeHeight * rightFadeStrength);
            mFadeMatrix.postRotate(90);
            mFadeMatrix.postTranslate(right, top);
            mFade.setLocalMatrix(mFadeMatrix);
            canvas.drawRect(right - length, top, right, bottom, mFadePaint);
        }
    }
}
Also used : LinearGradient(android.graphics.LinearGradient) Matrix(android.graphics.Matrix) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 7 with LinearGradient

use of android.graphics.LinearGradient in project CustomShapeImageView by MostafaGazar.

the class SVGHandlerTest method testParseLinearGradient_xlink.

@Test
public void testParseLinearGradient_xlink() throws Exception {
    //given
    when(picture.beginRecording(anyInt(), anyInt())).thenReturn(canvas);
    SVGParser.SVGHandler parserHandler = spy(this.parserHandler);
    LinearGradient gr1 = mock(LinearGradient.class);
    PowerMockito.whenNew(LinearGradient.class).withArguments(eq(10.1f), eq(4.1f), eq(11.1f), eq(0.0f), eq(new int[0]), eq(new float[0]), eq(Shader.TileMode.CLAMP)).thenReturn(gr1);
    LinearGradient gr2 = mock(LinearGradient.class);
    PowerMockito.whenNew(LinearGradient.class).withArguments(eq(5.1f), eq(1.1f), eq(20.1f), eq(25.0f), eq(new int[0]), eq(new float[0]), eq(Shader.TileMode.CLAMP)).thenReturn(gr2);
    //when
    startSVG(parserHandler);
    //parent
    startElement(parserHandler, attributes(attr("id", "gr1"), attr("x1", "10.1"), attr("y1", "4.1"), attr("x2", "11.1"), attr("gradientTransform", "matrix(0.2883 0 0 0.2865 153.3307 265.0264)")), "linearGradient");
    endElement(parserHandler, "linearGradient");
    //child
    startElement(parserHandler, attributes(attr("id", "gr2"), attr("x1", "5.1"), attr("y1", "1.1"), attr("x2", "20.1"), attr("y2", "25.0"), attr("href", "#gr1")), "linearGradient");
    endElement(parserHandler, "linearGradient");
    endSVG(parserHandler);
    //then
    verify(gr2).setLocalMatrix(matrix);
}
Also used : LinearGradient(android.graphics.LinearGradient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with LinearGradient

use of android.graphics.LinearGradient in project Signal-Android by WhisperSystems.

the class VerticalSlideColorPicker method onSizeChanged.

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    viewWidth = w;
    viewHeight = h;
    centerX = viewWidth / 2;
    colorPickerRadius = (viewWidth / 2) - borderWidth;
    colorPickerBody = new RectF(centerX - colorPickerRadius, borderWidth + colorPickerRadius, centerX + colorPickerRadius, viewHeight - (borderWidth + colorPickerRadius));
    LinearGradient gradient = new LinearGradient(0, colorPickerBody.top, 0, colorPickerBody.bottom, colors, null, Shader.TileMode.CLAMP);
    paint.setShader(gradient);
    if (bitmap != null) {
        bitmap.recycle();
    }
    bitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
    bitmapCanvas = new Canvas(bitmap);
    resetToDefault();
}
Also used : RectF(android.graphics.RectF) LinearGradient(android.graphics.LinearGradient) Canvas(android.graphics.Canvas)

Example 9 with LinearGradient

use of android.graphics.LinearGradient in project remusic by aa112901.

the class CustomTextView method onSizeChanged.

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    if (mWidth == 0) {
        Log.e(TAG, "*********************");
        mWidth = getMeasuredWidth();
        paint2 = getPaint();
        //颜色渐变器
        gradient = new LinearGradient(0, 0, mWidth, 0, new int[] { Color.GRAY, Color.WHITE, Color.GRAY }, new float[] { 0.3f, 0.5f, 1.0f }, Shader.TileMode.CLAMP);
        paint2.setShader(gradient);
        matrix = new Matrix();
    }
}
Also used : LinearGradient(android.graphics.LinearGradient) Matrix(android.graphics.Matrix)

Example 10 with LinearGradient

use of android.graphics.LinearGradient in project LoadingView by ldoublem.

the class LVRingProgress method drawProgress.

private void drawProgress(Canvas canvas, Paint paint, int sweepAngle) {
    paint.reset();
    paint.setAntiAlias(true);
    paint.setStrokeWidth(mPadding);
    paint.setStyle(Paint.Style.STROKE);
    Path pathProgress = new Path();
    pathProgress.addArc(rectFBg, -90, sweepAngle);
    Shader mShader = new LinearGradient(rectFBg.left, rectFBg.top, rectFBg.left, rectFBg.bottom, new int[] { ProStartColor, ProEndColor }, new float[] { 0f, 1f }, Shader.TileMode.CLAMP);
    paint.setShader(mShader);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeJoin(Paint.Join.ROUND);
    canvas.drawPath(pathProgress, paint);
    paint.setShader(null);
    mPaintText.setTextSize(mPaint.getStrokeWidth() / 2);
    String text = String.valueOf((int) (sweepAngle / MaxAngle * 100)) + "%";
    canvas.drawTextOnPath(text, pathProgress, (float) (Math.PI * rectFBg.width() * (sweepAngle / MaxAngle) - getFontlength(mPaintText, text) * 1.5f), getFontHeight(mPaintText) / 3, mPaintText);
}
Also used : Path(android.graphics.Path) LinearGradient(android.graphics.LinearGradient) Shader(android.graphics.Shader)

Aggregations

LinearGradient (android.graphics.LinearGradient)123 Paint (android.graphics.Paint)70 RectF (android.graphics.RectF)38 RadialGradient (android.graphics.RadialGradient)27 Canvas (android.graphics.Canvas)22 Rect (android.graphics.Rect)21 Path (android.graphics.Path)18 Shader (android.graphics.Shader)18 Bitmap (android.graphics.Bitmap)15 Matrix (android.graphics.Matrix)15 Point (android.graphics.Point)13 SweepGradient (android.graphics.SweepGradient)12 PorterDuffXfermode (android.graphics.PorterDuffXfermode)9 ShapeDrawable (android.graphics.drawable.ShapeDrawable)9 SuppressLint (android.annotation.SuppressLint)6 ComposeShader (android.graphics.ComposeShader)6 PaintDrawable (android.graphics.drawable.PaintDrawable)5 RectShape (android.graphics.drawable.shapes.RectShape)5 ColorMatrix (android.graphics.ColorMatrix)3 PointF (android.graphics.PointF)3