Example usage for android.view View draw

List of usage examples for android.view View draw

Introduction

In this page you can find the example usage for android.view View 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.youth.xframe.adapter.decoration.StickyHeaderDecoration.java

/**
 * {@inheritDoc}//from w w  w  .  java 2s. c  o m
 */
@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    if (parent.getAdapter() == null) {
        return;
    }

    final int count = parent.getChildCount();
    long previousHeaderId = -1;

    for (int layoutPos = 0; layoutPos < count; layoutPos++) {
        final View child = parent.getChildAt(layoutPos);
        int adapterPos = parent.getChildAdapterPosition(child);

        if (!mIncludeHeader) {
            if (parent.getAdapter() instanceof XRecyclerViewAdapter) {
                int headerCount = ((XRecyclerViewAdapter) parent.getAdapter()).getHeaderCount();
                int footerCount = ((XRecyclerViewAdapter) parent.getAdapter()).getFooterCount();
                int dataCount = ((XRecyclerViewAdapter) parent.getAdapter()).getDataCount();
                if (adapterPos < headerCount) {
                    continue;
                }
                if (adapterPos >= headerCount + dataCount) {
                    continue;
                }
                if (adapterPos >= headerCount) {
                    adapterPos -= headerCount;
                }

            }
        }

        if (adapterPos != RecyclerView.NO_POSITION && hasHeader(adapterPos)) {
            long headerId = mAdapter.getHeaderId(adapterPos);

            if (headerId != previousHeaderId) {
                previousHeaderId = headerId;
                View header = getHeader(parent, adapterPos).itemView;
                canvas.save();

                final int left = child.getLeft();
                final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos);
                canvas.translate(left, top);

                header.setTranslationX(left);
                header.setTranslationY(top);
                header.draw(canvas);
                canvas.restore();
            }
        }
    }
}

From source file:ca.barrenechea.widget.recyclerview.decoration.DoubleHeaderDecoration.java

/**
 * {@inheritDoc}/* w w  w  .ja  v a2 s . c  om*/
 */
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final int count = parent.getChildCount();

    boolean headerDrawn = false;
    for (int layoutPos = 0; layoutPos < count; layoutPos++) {
        final View child = parent.getChildAt(layoutPos);
        boolean visible = getAnimatedTop(child) > -child.getHeight()/* && child.getTop() < parent.getHeight()*/;
        final int adapterPos = parent.getChildAdapterPosition(child);
        if (visible && adapterPos != RecyclerView.NO_POSITION && (!headerDrawn || hasSubHeader(adapterPos))) {
            int left, top;
            final View header = getHeader(parent, adapterPos).itemView;
            final View subHeader = getSubHeader(parent, adapterPos).itemView;

            c.save();
            left = child.getLeft();
            top = getSubHeaderTop(parent, child, header, subHeader, adapterPos, layoutPos);
            c.translate(left, top);
            subHeader.setTranslationX(left);
            subHeader.setTranslationY(top);
            subHeader.draw(c);
            c.restore();

            if (!headerDrawn || hasHeader(adapterPos)) {
                c.save();
                left = child.getLeft();
                top = getHeaderTop(parent, child, header, subHeader, adapterPos, layoutPos);
                c.translate(left, top);
                header.setTranslationX(left);
                header.setTranslationY(top);
                header.draw(c);
                c.restore();
            }

            headerDrawn = true;
        }
    }
}

From source file:com.dgnt.dominionCardPicker.view.DynamicListView.java

/** Returns a bitmap showing a screenshot of the view passed in. */
private Bitmap getBitmapFromView(View v) {
    Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);
    return bitmap;
}

From source file:com.example.android.expandingcells.ExpandingListView.java

/**
 * By overriding dispatchDraw, we can draw the cells that disappear during the
 * expansion process. When the cell expands, some items below or above the expanding
 * cell may be moved off screen and are thus no longer children of the ListView's
 * layout. By storing a reference to these views prior to the layout, and
 * guaranteeing that these cells do not get recycled, the cells can be drawn
 * directly onto the canvas during the animation process. After the animation
 * completes, the references to the extra views can then be discarded.
 *//* ww w  . ja  va  2 s .c  o  m*/
@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);

    if (mViewsToDraw.size() == 0) {
        return;
    }

    for (View v : mViewsToDraw) {
        canvas.translate(0, v.getTop());
        v.draw(canvas);
        canvas.translate(0, -v.getTop());
    }
}

From source file:io.bunnyblue.noticedog.app.lockscreen.ui.LockScreenWidget.java

View duplicateView(View view) {
    Bitmap b = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888);
    view.draw(new Canvas(b));
    ImageView imageView = new ImageView(this.context);
    imageView.setImageBitmap(b);//from w  w w.ja v  a2 s.  co  m
    return imageView;
}

From source file:ucsc.hci.rankit.DynamicListView.java

/** Returns a bitmap showing a screenshot of the view passed in. */
private Bitmap getBitmapFromView(View v) {

    Bitmap bitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
    try {/*from w w w  . j  ava 2 s. c om*/
        bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        v.draw(canvas);
    } catch (Exception e) {
        e.printStackTrace();
        //intent.putExtra(USERS_CALL_STRING,UsersCallString);

        //Intent intentnow = new Intent(RankItApp.getAppContext(), MenuPageActivity.class);

        //startActivity(MenuPageActivity.intent_global);
    }
    return bitmap;
}

From source file:net.osmand.plus.views.controls.DynamicListView.java

/**
 * Returns a bitmap showing a screenshot of the view passed in.
 *///from  ww w  .  ja  v a  2 s.  co m
private Bitmap getBitmapFromView(View v) {
    Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);

    Bitmap bitmapOut = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvasOut = new Canvas(bitmapOut);
    canvasOut.drawColor(Color.TRANSPARENT);
    Paint p = new Paint();
    p.setAlpha(200);
    canvasOut.drawBitmap(bitmap, 0, 0, p);

    return bitmapOut;
}

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

public Bitmap getWrtBmp(String bmp_id, View view, int qlty) {

    int bmp_wdth = view.getWidth();
    int bmp_hght = view.getHeight();
    Bitmap bmpCaptured = Bitmap.createBitmap(bmp_wdth, bmp_hght, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmpCaptured);
    view.draw(canvas);
    File sdCard = Environment.getExternalStorageDirectory();
    File dir = new File(sdCard.getAbsolutePath() + "/acceleratedio/pacnzoom");
    dir.mkdirs();/*from ww w.  java  2  s  .c o  m*/

    try {
        File file = new File(dir, "/" + bmp_id + ".jpg");
        FileOutputStream fStrm = new FileOutputStream(file);
        bmpCaptured.compress(Bitmap.CompressFormat.JPEG, qlty, fStrm);
        fStrm.close();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return bmpCaptured;
}

From source file:org.cnc.mombot.utils.ContactsEditText.java

private Object convertViewToDrawable(View view) {
    BitmapDrawable bd = null;// w w  w . java 2  s  .c o m
    try {
        int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        view.measure(spec, spec);
        view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
        Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.translate(-view.getScrollX(), -view.getScrollY());
        view.draw(canvas);
        bd = new BitmapDrawable(getContext().getResources(), bitmap);
        bd.setBounds(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    } catch (Exception ex) {
    }
    return bd;
}

From source file:com.nextgis.maplibui.fragment.ReorderedLayerView.java

/**
 * Returns a bitmap showing a screenshot of the view passed in.
 *///from  w w w.  j a v  a 2 s.  c o  m
protected Bitmap getBitmapFromView(View v) {
    Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(getResources().getColor(R.color.background_floating_material_light));
    Rect rect = new Rect(0, 0, v.getWidth(), v.getHeight());
    canvas.drawRect(rect, paint);

    v.draw(canvas);
    return bitmap;
}