Example usage for android.widget ImageView draw

List of usage examples for android.widget ImageView draw

Introduction

In this page you can find the example usage for android.widget ImageView draw.

Prototype

@CallSuper
public void draw(Canvas canvas) 

Source Link

Document

Manually render this view (and all of its children) to the given Canvas.

Usage

From source file:com.acceleratedio.pac_n_zoom.DrawSVG.java

public ArrayList<ImageView> DrawSVG(Context context, ImageView orgnlImageView, RelativeLayout rel_anm_lo) {

    paint.setColor(Color.WHITE);/* www  .ja  v  a  2  s  .  co m*/
    paint.setStyle(Paint.Style.FILL);
    LoadSVG.SVGData data = AnimActivity.svg_data;
    ArrayList<ImageView> imgViews = new ArrayList<ImageView>();
    imgViews.add(orgnlImageView);

    if (data.symbl != null) {

        ArrayList<String> sprt_ordr = data.svg.ordr;
        int sym_mbr = 0;
        Bitmap bitmap;
        Canvas canvas;

        // - Loop through the sprites 
        int sprt_nmbr = sprt_ordr.size();
        data.svg.initScl = new float[sprt_nmbr];
        float[] initScl = data.svg.initScl;

        for (int sprt_mbr = 1; sprt_mbr < sprt_nmbr; sprt_mbr += 1) {

            String sprt_id = sprt_ordr.get(sprt_mbr); // e.g., id="g2_0"

            if (Integer.parseInt(sprt_id.substring(sprt_id.indexOf('_') + 1)) > 0) {
                // The symbol is already drawn; replicate the view   
                String init_sprt = sprt_id.substring(0, sprt_id.indexOf('_') + 1) + '0';
                String svg_ordr = data.svg.svg_ordr;
                String cnt_str = svg_ordr.substring(0, svg_ordr.indexOf(init_sprt));
                ImageView init_vw = imgViews.get(StringUtils.countMatches(cnt_str, ","));
                Bitmap initBmp = ((BitmapDrawable) init_vw.getDrawable()).getBitmap();

                bitmap = Bitmap.createBitmap(initBmp.getWidth(), initBmp.getHeight(), initBmp.getConfig());

                canvas = new Canvas(bitmap);
                canvas.save(Canvas.MATRIX_SAVE_FLAG);
                xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id);
                canvas.scale(crt_sprt.scl, crt_sprt.scl);
                initScl[sprt_mbr] = crt_sprt.scl;
                canvas.translate(0, 0);
            } else {
                // The symbol needs to be drawn; a new view   is used
                bitmap = getCreatBmp(rel_anm_lo);
                canvas = new Canvas(bitmap);
                canvas.save(Canvas.MATRIX_SAVE_FLAG);

                // - Set the init values
                xfrmInit crt_sprt = getInitSpriteAttrib(sprt_id);
                canvas.scale(crt_sprt.scl, crt_sprt.scl);
                initScl[sprt_mbr] = crt_sprt.scl;
                canvas.translate(0, 0);

                // - Draw the bitmap
                LoadSVG.symbol crt_sym = data.symbl.get(sym_mbr);
                ArrayList<LoadSVG.path> pths = crt_sym.pths;
                int pth_nmbr = pths.size();

                // Loop through the paths
                for (int pth_mbr = 0; pth_mbr < pth_nmbr; pth_mbr += 1) {

                    LoadSVG.path crt_pth = pths.get(pth_mbr);
                    final Path path = new Path();
                    final Paint paint = new Paint();
                    /* Debug
                    if (pth_mbr + 1 == pth_nmbr) {
                            
                       String log_str = "Paths: pth_mbr = " +
                          String.valueOf(pth_mbr) + "; color = " + crt_pth.clr;
                            
                       Log.d("DrawSVG", log_str);
                    }
                    */
                    paint.setColor(Color.parseColor(crt_pth.clr));
                    paint.setAntiAlias(true);
                    paint.setStyle(Paint.Style.FILL_AND_STROKE);
                    ld_pth_pnts(crt_pth.pth, path);
                    path.close();
                    path.setFillType(Path.FillType.EVEN_ODD);
                    canvas.drawPath(path, paint);
                }

                canvas.restore();
                sym_mbr += 1;
            }

            ImageView iv = new ImageView(context);
            iv.setImageBitmap(bitmap);

            RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);

            iv.draw(canvas);
            iv.setLayoutParams(rlp);
            iv.setBackgroundColor(Color.TRANSPARENT);
            imgViews.add(iv);
        } // sprites
    } // if symbol

    return imgViews;
}