Example usage for android.graphics Canvas translate

List of usage examples for android.graphics Canvas translate

Introduction

In this page you can find the example usage for android.graphics Canvas translate.

Prototype

public void translate(float dx, float dy) 

Source Link

Document

Preconcat the current matrix with the specified translation

Usage

From source file:org.telegram.ui.GroupCreateActivity.java

public Emoji.XImageSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) parentActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
    text.setText(Utilities.formatName(user.first_name, user.last_name));

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);/*from  w  w  w .  java 2s .  co  m*/
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    Emoji.XImageSpan span = new Emoji.XImageSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.id, span);
    for (ImageSpan sp : allSpans) {
        ssb.append("<<");
        ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    userSelectEditText.setText(ssb);
    userSelectEditText.setSelection(ssb.length());
    return span;
}

From source file:com.amitupadhyay.aboutexample.ui.widget.CollapsingTitleLayout.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (lineCount == 1) {
        collapsingText.draw(canvas);/*from   w  w w  .  j a v  a 2  s.c  o  m*/
    } else {
        float x = titleInsetStart;
        float y = Math.max(textTop - scrollOffset, titleInsetTop);
        canvas.translate(x, y);
        canvas.clipRect(0, 0, getWidth() - titleInsetStart - titleInsetEnd,
                Math.max(getHeight() - scrollOffset, collapsedHeight) - y);
        layout.draw(canvas);
    }
}

From source file:com.fada21.android.hydralist.expandable.ExpandingListViewDelegate.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.
 *//* w  w  w  .  ja v  a  2s. co m*/
public void dispatchDraw(Canvas 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:org.telegram.ui.Cells.SharedLinkCell.java

@Override
protected void onDraw(Canvas canvas) {
    if (titleLayout != null) {
        canvas.save();//  w  w w.jav a2  s  .  co  m
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline),
                titleY);
        titleLayout.draw(canvas);
        canvas.restore();
    }

    if (descriptionLayout != null) {
        descriptionTextPaint.setColor(TEXT_COLOR);
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline),
                descriptionY);
        descriptionLayout.draw(canvas);
        canvas.restore();
    }

    if (descriptionLayout2 != null) {
        descriptionTextPaint.setColor(TEXT_COLOR);
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline),
                description2Y);
        descriptionLayout2.draw(canvas);
        canvas.restore();
    }

    if (!linkLayout.isEmpty()) {
        descriptionTextPaint.setColor(Theme.MSG_LINK_TEXT_COLOR);
        int offset = 0;
        for (int a = 0; a < linkLayout.size(); a++) {
            StaticLayout layout = linkLayout.get(a);
            if (layout.getLineCount() > 0) {
                canvas.save();
                canvas.translate(
                        AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline),
                        linkY + offset);
                if (pressedLink == a) {
                    canvas.drawPath(urlPath, urlPaint);
                }
                layout.draw(canvas);
                canvas.restore();
                offset += layout.getLineBottom(layout.getLineCount() - 1);
            }
        }
    }

    letterDrawable.draw(canvas);
    if (drawLinkImageView) {
        linkImageView.draw(canvas);
    }

    if (needDivider) {
        if (LocaleController.isRTL) {
            canvas.drawLine(0, getMeasuredHeight() - 1,
                    getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline),
                    getMeasuredHeight() - 1, paint);
        } else {
            canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1,
                    getMeasuredWidth(), getMeasuredHeight() - 1, paint);
        }
    }
}

From source file:com.yahala.ui.GroupCreateActivity.java

public XImageSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf = (LayoutInflater) parentActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
    String name = Utilities.formatName(user.first_name, user.last_name);
    if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
        name = PhoneFormat.getInstance().format("+" + user.phone);
    }/* w w w.j a  v a  2s.  co  m*/
    text.setText(name + ", ");

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    XImageSpan span = new XImageSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.jid, span);
    for (ImageSpan sp : allSpans) {
        ssb.append("<<");
        ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    userSelectEditText.setText(ssb);
    userSelectEditText.setSelection(ssb.length());
    return span;
}

From source file:io.plaidapp.core.ui.widget.CollapsingTitleLayout.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (lineCount == 1) {
        collapsingText.draw(canvas);//from  w  w w.j ava  2 s. c om
    } else {
        int savePoint = canvas.save();
        float x = titleInsetStart;
        float y = Math.max(textTop - scrollOffset, titleInsetTop);
        canvas.translate(x, y);
        canvas.clipRect(0, 0, getWidth() - titleInsetStart - titleInsetEnd,
                Math.max(getHeight() - scrollOffset, collapsedHeight) - y);
        layout.draw(canvas);
        canvas.restoreToCount(savePoint);
    }
}

From source file:com.gj.administrator.gjerp.view.CircleIndicator.java

@Override
protected void onDraw(Canvas canvas) {
    Log.e("CircleIndicator", "onDraw()");
    super.onDraw(canvas);
    int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), null,
            Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
                    | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG);
    for (ShapeHolder item : tabItems) {
        canvas.save();/*w w  w  .ja  v a  2 s  . com*/
        canvas.translate(item.getX(), item.getY());
        item.getShape().draw(canvas);
        canvas.restore();
    }

    if (movingItem != null) {
        canvas.save();
        canvas.translate(movingItem.getX(), movingItem.getY());
        movingItem.getShape().draw(canvas);
        canvas.restore();
    }
    canvas.restoreToCount(sc);
}

From source file:android.support.v7.widget.AppCompatSeekBarHelper.java

/**
 * Draw the tick marks.//from  w  w w . java2  s  .co  m
 */
void drawTickMarks(Canvas canvas) {
    if (mTickMark != null) {
        final int count = mView.getMax();
        if (count > 1) {
            final int w = mTickMark.getIntrinsicWidth();
            final int h = mTickMark.getIntrinsicHeight();
            final int halfW = w >= 0 ? w / 2 : 1;
            final int halfH = h >= 0 ? h / 2 : 1;
            mTickMark.setBounds(-halfW, -halfH, halfW, halfH);

            final float spacing = (mView.getWidth() - mView.getPaddingLeft() - mView.getPaddingRight())
                    / (float) count;
            final int saveCount = canvas.save();
            canvas.translate(mView.getPaddingLeft(), mView.getHeight() / 2);
            for (int i = 0; i <= count; i++) {
                mTickMark.draw(canvas);
                canvas.translate(spacing, 0);
            }
            canvas.restoreToCount(saveCount);
        }
    }
}

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.
 *//*from   w w  w  .ja v a2 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:android.support.wear.widget.drawer.PageIndicatorView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mNumberOfPositions > 1) {
        float dotCenterLeft = getPaddingLeft() + (mDotSpacing / 2f);
        float dotCenterTop = getHeight() / 2f;
        canvas.save();//from   ww  w. j a  va 2 s .c  om
        canvas.translate(dotCenterLeft, dotCenterTop);
        for (int i = 0; i < mNumberOfPositions; i++) {
            if (i == mSelectedPosition) {
                float radius = mDotRadiusSelected + mDotShadowRadius;
                canvas.drawCircle(mDotShadowDx, mDotShadowDy, radius, mDotPaintShadowSelected);
                canvas.drawCircle(0, 0, mDotRadiusSelected, mDotPaintSelected);
            } else {
                float radius = mDotRadius + mDotShadowRadius;
                canvas.drawCircle(mDotShadowDx, mDotShadowDy, radius, mDotPaintShadow);
                canvas.drawCircle(0, 0, mDotRadius, mDotPaint);
            }
            canvas.translate(mDotSpacing, 0);
        }
        canvas.restore();
    }
}