Search in sources :

Example 81 with BitmapShader

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

the class RoundImageView method make.

private void make(Bitmap bitmap) {
    mBitmap = getCroppedRoundBitmap(bitmap, 255, 15);
    mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mBitmapPaint.setAntiAlias(true);
    mBitmapPaint.setShader(mBitmapShader);
    mDrawableRect.set(0, 0, getWidth(), getHeight());
    mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
    mBitmapHeight = mBitmap.getHeight();
    mBitmapWidth = mBitmap.getWidth();
    updateShaderMatrix();
    invalidate();
}
Also used : BitmapShader(android.graphics.BitmapShader)

Example 82 with BitmapShader

use of android.graphics.BitmapShader in project Carbon by ZieIony.

the class EditText method initEditText.

private void initEditText(AttributeSet attrs, int defStyleAttr) {
    if (isInEditMode())
        return;
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EditText, defStyleAttr, R.style.carbon_EditText);
    int ap = a.getResourceId(R.styleable.EditText_android_textAppearance, -1);
    if (ap != -1)
        setTextAppearanceInternal(ap);
    for (int i = 0; i < a.getIndexCount(); i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.EditText_carbon_textAllCaps) {
            setAllCaps(a.getBoolean(attr, false));
        } else if (!isInEditMode() && attr == R.styleable.EditText_carbon_fontPath) {
            String path = a.getString(attr);
            Typeface typeface = TypefaceUtils.getTypeface(getContext(), path);
            setTypeface(typeface);
        } else if (attr == R.styleable.EditText_carbon_fontFamily) {
            int textStyle = a.getInt(R.styleable.EditText_android_textStyle, 0);
            Typeface typeface = TypefaceUtils.getTypeface(getContext(), a.getString(attr), textStyle);
            setTypeface(typeface);
        }
    }
    setCursorColor(a.getColor(R.styleable.EditText_carbon_cursorColor, 0));
    setPattern(a.getString(R.styleable.EditText_carbon_pattern));
    DIVIDER_PADDING = (int) getResources().getDimension(R.dimen.carbon_paddingHalf);
    setMatchingView(a.getResourceId(R.styleable.EditText_carbon_matchingView, 0));
    setUnderline(a.getBoolean(R.styleable.EditText_carbon_underline, true));
    Carbon.initRippleDrawable(this, a, rippleIds);
    Carbon.initTint(this, a, tintIds);
    Carbon.initElevation(this, a, elevationIds);
    Carbon.initAnimations(this, a, animationIds);
    Carbon.initTouchMargin(this, a, touchMarginIds);
    setCornerRadius(a.getDimension(R.styleable.EditText_carbon_cornerRadius, 0));
    Carbon.initHtmlText(this, a, R.styleable.EditText_carbon_htmlText);
    a.recycle();
    try {
        Field mHighlightPaintField = android.widget.TextView.class.getDeclaredField("mHighlightPaint");
        mHighlightPaintField.setAccessible(true);
        mHighlightPaintField.set(this, new Paint() {

            @Override
            public void setColor(int color) {
                if (getSelectionStart() == getSelectionEnd()) {
                    super.setColor(cursorColor);
                } else {
                    super.setColor(color);
                }
            }
        });
    } catch (Exception e) {
    }
    int underlineWidth = getResources().getDimensionPixelSize(R.dimen.carbon_1dip);
    Bitmap dashPathBitmap = Bitmap.createBitmap(underlineWidth * 4, underlineWidth, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(dashPathBitmap);
    paint.setColor(0xffffffff);
    paint.setAlpha(255);
    c.drawCircle(dashPathBitmap.getHeight() / 2.0f, dashPathBitmap.getHeight() / 2.0f, dashPathBitmap.getHeight() / 2.0f, paint);
    dashPathShader = new BitmapShader(dashPathBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
    initSelectionHandle();
    addTextChangedListener(new SimpleTextWatcher() {

        @Override
        public void afterTextChanged(Editable editable) {
            validateInternalEvent();
        }
    });
    validateInternalEvent();
    if (getElevation() > 0)
        AnimUtils.setupElevationAnimator(stateAnimator, this);
}
Also used : Typeface(android.graphics.Typeface) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint) Field(java.lang.reflect.Field) Bitmap(android.graphics.Bitmap) SimpleTextWatcher(carbon.internal.SimpleTextWatcher) TypedArray(android.content.res.TypedArray) Editable(android.text.Editable)

Example 83 with BitmapShader

use of android.graphics.BitmapShader in project JamsMusicPlayer by psaravan.

the class PicassoCircularTransformer method transform.

@Override
public Bitmap transform(Bitmap source) {
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
    if (squaredBitmap != source) {
        source.recycle();
    }
    Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
    paint.setShader(shader);
    paint.setAntiAlias(true);
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    squaredBitmap.recycle();
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint)

Example 84 with BitmapShader

use of android.graphics.BitmapShader in project JamsMusicPlayer by psaravan.

the class PicassoRoundedRectTransformer method transform.

@Override
public Bitmap transform(final Bitmap source) {
    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint);
    if (source != output) {
        source.recycle();
    }
    return output;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapShader(android.graphics.BitmapShader)

Example 85 with BitmapShader

use of android.graphics.BitmapShader in project plaid by nickbutcher.

the class CircleTransform method circleCrop.

private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null)
        return null;
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    // TODO this could be acquired from the pool too
    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG);
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint)

Aggregations

BitmapShader (android.graphics.BitmapShader)137 Bitmap (android.graphics.Bitmap)86 Paint (android.graphics.Paint)69 Canvas (android.graphics.Canvas)60 Matrix (android.graphics.Matrix)20 BitmapDrawable (android.graphics.drawable.BitmapDrawable)15 RectF (android.graphics.RectF)14 ShapeDrawable (android.graphics.drawable.ShapeDrawable)14 AnimationDrawable (android.graphics.drawable.AnimationDrawable)13 ClipDrawable (android.graphics.drawable.ClipDrawable)13 Drawable (android.graphics.drawable.Drawable)13 LayerDrawable (android.graphics.drawable.LayerDrawable)13 Rect (android.graphics.Rect)9 Shader (android.graphics.Shader)8 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)6 StateListDrawable (android.graphics.drawable.StateListDrawable)4 Point (android.graphics.Point)3 SuppressLint (android.annotation.SuppressLint)2 ColorMatrix (android.graphics.ColorMatrix)2 TypedArray (android.content.res.TypedArray)1