Search in sources :

Example 1 with CornerView

use of carbon.widget.CornerView in project Carbon by ZieIony.

the class ShadowGenerator method generateShadow.

public static Shadow generateShadow(View view, float elevation) {
    if (!software && renderScript == null) {
        try {
            renderScript = RenderScript.create(view.getContext());
            blurShader = ScriptIntrinsicBlur.create((RenderScript) renderScript, Element.U8_4((RenderScript) renderScript));
        } catch (Error ignore) {
            software = true;
        }
    }
    CornerView cornerView = (CornerView) view;
    int e = (int) Math.ceil(elevation);
    int c = (int) Math.max(e, cornerView.getCornerRadius());
    for (Object o : shadowSet) {
        Shadow s = (Shadow) o;
        if (s != null && s.elevation == elevation && s.c == c)
            return s;
    }
    Bitmap bitmap;
    int bitmapSize = e * 2 + 2 * c + 1;
    bitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888);
    Canvas shadowCanvas = new Canvas(bitmap);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(0xffffffff);
    roundRect.set(e, e, bitmapSize - e, bitmapSize - e);
    shadowCanvas.drawRoundRect(roundRect, c, c, paint);
    blur(bitmap, elevation);
    Shadow shadow = new Shadow(bitmap, elevation, c);
    shadowSet.add(shadow);
    return shadow;
}
Also used : RenderScript(android.support.v8.renderscript.RenderScript) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) CornerView(carbon.widget.CornerView) Paint(android.graphics.Paint)

Aggregations

Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 RenderScript (android.support.v8.renderscript.RenderScript)1 CornerView (carbon.widget.CornerView)1