Search in sources :

Example 11 with Shader

use of android.graphics.Shader in project XobotOS by xamarin.

the class GLES20Canvas method setupModifiers.

private int setupModifiers(Paint paint) {
    int modifiers = MODIFIER_NONE;
    if (paint.hasShadow) {
        nSetupShadow(mRenderer, paint.shadowRadius, paint.shadowDx, paint.shadowDy, paint.shadowColor);
        modifiers |= MODIFIER_SHADOW;
    }
    final Shader shader = paint.getShader();
    if (shader != null) {
        nSetupShader(mRenderer, shader.native_shader);
        modifiers |= MODIFIER_SHADER;
    }
    final ColorFilter filter = paint.getColorFilter();
    if (filter != null) {
        nSetupColorFilter(mRenderer, filter.nativeColorFilter);
        modifiers |= MODIFIER_COLOR_FILTER;
    }
    return modifiers;
}
Also used : ColorFilter(android.graphics.ColorFilter) Shader(android.graphics.Shader) Paint(android.graphics.Paint)

Example 12 with Shader

use of android.graphics.Shader in project XobotOS by xamarin.

the class BitmapDrawable method draw.

@Override
public void draw(Canvas canvas) {
    Bitmap bitmap = mBitmap;
    if (bitmap != null) {
        final BitmapState state = mBitmapState;
        if (state.mRebuildShader) {
            Shader.TileMode tmx = state.mTileModeX;
            Shader.TileMode tmy = state.mTileModeY;
            if (tmx == null && tmy == null) {
                state.mPaint.setShader(null);
            } else {
                state.mPaint.setShader(new BitmapShader(bitmap, tmx == null ? Shader.TileMode.CLAMP : tmx, tmy == null ? Shader.TileMode.CLAMP : tmy));
            }
            state.mRebuildShader = false;
            copyBounds(mDstRect);
        }
        Shader shader = state.mPaint.getShader();
        if (shader == null) {
            if (mApplyGravity) {
                final int layoutDirection = getResolvedLayoutDirectionSelf();
                Gravity.apply(state.mGravity, mBitmapWidth, mBitmapHeight, getBounds(), mDstRect, layoutDirection);
                mApplyGravity = false;
            }
            canvas.drawBitmap(bitmap, null, mDstRect, state.mPaint);
        } else {
            if (mApplyGravity) {
                copyBounds(mDstRect);
                mApplyGravity = false;
            }
            canvas.drawRect(mDstRect, state.mPaint);
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) BitmapShader(android.graphics.BitmapShader) Shader(android.graphics.Shader) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint)

Example 13 with Shader

use of android.graphics.Shader in project android_frameworks_base by AOSPA.

the class BitmapDrawable method onBoundsChange.

@Override
protected void onBoundsChange(Rect bounds) {
    mDstRectAndInsetsDirty = true;
    final Bitmap bitmap = mBitmapState.mBitmap;
    final Shader shader = mBitmapState.mPaint.getShader();
    if (bitmap != null && shader != null) {
        updateShaderMatrix(bitmap, mBitmapState.mPaint, shader, needMirroring());
    }
}
Also used : Bitmap(android.graphics.Bitmap) Shader(android.graphics.Shader) BitmapShader(android.graphics.BitmapShader)

Example 14 with Shader

use of android.graphics.Shader in project weex-example by KalicyZhou.

the class BorderDrawable method preparePaint.

private void preparePaint(@BorderWidthStyleColorType int side) {
    float borderWidth = getBorderWidth(side);
    int color = WXViewUtils.multiplyColorAlpha(getBorderColor(side), mAlpha);
    BorderStyle borderStyle = BorderStyle.values()[getBorderStyle(side)];
    Shader shader = borderStyle.getLineShader(borderWidth, color, side);
    mPaint.setShader(shader);
    mPaint.setColor(color);
    mPaint.setStrokeWidth(borderWidth);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
}
Also used : Shader(android.graphics.Shader) Paint(android.graphics.Paint)

Example 15 with Shader

use of android.graphics.Shader in project weex-example by KalicyZhou.

the class WXResourceUtils method getShader.

/**
   * Assembly gradients
   * @param image gradient values contains direction、colors
   * @param width component width
   * @param height component height
   * @return gradient shader
   */
public static Shader getShader(String image, float width, float height) {
    List<String> valueList = parseGradientValues(image);
    if (valueList != null && valueList.size() == 3) {
        float[] points = parseGradientDirection(valueList.get(0), width, height);
        Shader shader = new LinearGradient(points[0], points[1], points[2], points[3], getColor(valueList.get(1), Color.WHITE), getColor(valueList.get(2), Color.WHITE), Shader.TileMode.REPEAT);
        return shader;
    }
    return null;
}
Also used : LinearGradient(android.graphics.LinearGradient) Shader(android.graphics.Shader)

Aggregations

Shader (android.graphics.Shader)77 Paint (android.graphics.Paint)41 LinearGradient (android.graphics.LinearGradient)38 BitmapShader (android.graphics.BitmapShader)21 Bitmap (android.graphics.Bitmap)17 ShapeDrawable (android.graphics.drawable.ShapeDrawable)15 Matrix (android.graphics.Matrix)13 RectShape (android.graphics.drawable.shapes.RectShape)9 PaintDrawable (android.graphics.drawable.PaintDrawable)8 Point (android.graphics.Point)7 SuppressLint (android.annotation.SuppressLint)6 ColorDrawable (android.graphics.drawable.ColorDrawable)6 Drawable (android.graphics.drawable.Drawable)5 OvalShape (android.graphics.drawable.shapes.OvalShape)5 CallSuper (android.annotation.CallSuper)4 Rect (android.graphics.Rect)4 RectF (android.graphics.RectF)4 ShaderFactory (android.graphics.drawable.ShapeDrawable.ShaderFactory)4 Test (org.junit.Test)4 Canvas (android.graphics.Canvas)3