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:com.klinker.android.launcher.info_page.widgets.swipe_refresh_layout.OffsetSwipeRefreshLayout.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);

    canvas.translate(0, mOffset);

    mProgressBar.draw(canvas);
}

From source file:com.android.mail.browse.SubjectAndFolderView.java

public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) {
    mVisibleFolders = true;//from   w w w  .  j a v  a2 s  . co m
    final BidiFormatter bidiFormatter = getBidiFormatter();
    final String wrappedSubject = mSubject == null ? "" : bidiFormatter.unicodeWrap(mSubject);
    final SpannableStringBuilder sb = new SpannableStringBuilder(wrappedSubject);
    sb.append('\u0020');
    final Settings settings = account.settings;
    final int start = sb.length();
    if (settings.importanceMarkersEnabled && conv.isImportant()) {
        sb.append(".\u0020");
        sb.setSpan(new ReplacementSpan() {
            @Override
            public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
                return mImportanceMarkerDrawable.getIntrinsicWidth();
            }

            @Override
            public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top,
                    int baseline, int bottom, Paint paint) {
                canvas.save();
                final int transY = baseline + mChipVerticalOffset
                        - mImportanceMarkerDrawable.getIntrinsicHeight();
                canvas.translate(x, transY);
                mImportanceMarkerDrawable.draw(canvas);
                canvas.restore();
            }
        }, start, start + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    }

    mFolderDisplayer.loadConversationFolders(conv, null /* ignoreFolder */, -1 /* ignoreFolderType */);
    mFolderDisplayer.constructFolderChips(sb);

    final int end = sb.length();
    sb.setSpan(new ChangeLabelsSpan(callbacks), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    setText(sb);
    setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:org.telegram.ui.Components.AvatarDrawable.java

@Override
public void draw(Canvas canvas) {
    Rect bounds = getBounds();/*from   ww w.  j av  a  2  s.co  m*/
    if (bounds == null) {
        return;
    }
    int size = bounds.width();
    paint.setColor(color);
    canvas.save();
    canvas.translate(bounds.left, bounds.top);
    canvas.drawCircle(size / 2, size / 2, size / 2, paint);

    if (drawBrodcast && broadcastDrawable != null) {
        int x = (size - broadcastDrawable.getIntrinsicWidth()) / 2;
        int y = (size - broadcastDrawable.getIntrinsicHeight()) / 2;
        broadcastDrawable.setBounds(x, y, x + broadcastDrawable.getIntrinsicWidth(),
                y + broadcastDrawable.getIntrinsicHeight());
        broadcastDrawable.draw(canvas);
    } else {
        if (textLayout != null) {
            canvas.translate((size - textWidth) / 2 - textLeft, (size - textHeight) / 2);
            textLayout.draw(canvas);
        } else if (drawPhoto && photoDrawable != null) {
            int x = (size - photoDrawable.getIntrinsicWidth()) / 2;
            int y = (size - photoDrawable.getIntrinsicHeight()) / 2;
            photoDrawable.setBounds(x, y, x + photoDrawable.getIntrinsicWidth(),
                    y + photoDrawable.getIntrinsicHeight());
            photoDrawable.draw(canvas);
        }
    }
    canvas.restore();
}

From source file:de.mrapp.android.util.view.ScrimInsetsLayout.java

@Override
public final void draw(final Canvas canvas) {
    super.draw(canvas);
    int width = getWidth();
    int height = getHeight();

    if (insets != null && insetDrawable != null) {
        int saveCount = canvas.save();
        canvas.translate(getScrollX(), getScrollY());
        insetDrawable.setBounds(0, 0, width, insets.top);
        insetDrawable.draw(canvas);/* ww w .  j  a  va2 s. c om*/
        insetDrawable.setBounds(0, height - insets.bottom, width, height);
        insetDrawable.draw(canvas);
        insetDrawable.setBounds(0, insets.top, insets.left, height - insets.bottom);
        insetDrawable.draw(canvas);
        insetDrawable.setBounds(width - insets.right, insets.top, width, height - insets.bottom);
        insetDrawable.draw(canvas);
        canvas.restoreToCount(saveCount);
    }
}

From source file:com.anl.wxb.jieqi.view.VerticalSeekBar.java

@Override
protected synchronized void onDraw(Canvas canvas) {
    if (!useViewRotation()) {
        switch (mRotationAngle) {
        case ROTATION_ANGLE_CW_90:
            canvas.rotate(90);//from   ww w.  j  a  v  a  2  s. co m
            canvas.translate(0, -super.getWidth());
            break;
        case ROTATION_ANGLE_CW_270:
            canvas.rotate(-90);
            canvas.translate(-super.getHeight(), 0);
            break;
        }
    }

    super.onDraw(canvas);
}

From source file:org.wikipedia.page.shareafact.SnippetImage.java

private static void drawWordmarkFromText(@NonNull Context context, @NonNull Canvas canvas,
        boolean isArticleRTL) {
    final int maxWidth = WIDTH - DESCRIPTION_WIDTH - 2 * HORIZONTAL_PADDING;
    final float fontSize = 20.0f;
    final float scaleX = 1.06f;

    TextPaint textPaint = new TextPaint();
    textPaint.setAntiAlias(true);//  w  w  w .  j  a  va2 s .co m
    textPaint.setColor(Color.LTGRAY);
    textPaint.setTextSize(fontSize);
    textPaint.setTypeface(SERIF);
    textPaint.setTextScaleX(scaleX);

    Spanned wikipedia = StringUtil.fromHtml(context.getString(R.string.wp_stylized));
    Layout.Alignment align = L10nUtil.isDeviceRTL() ? ALIGN_OPPOSITE : ALIGN_NORMAL;
    StaticLayout wordmarkLayout = buildLayout(
            new TextLayoutParams(wikipedia, textPaint, maxWidth, 1.0f, align));
    final int width = (int) wordmarkLayout.getLineWidth(0);
    final int height = wordmarkLayout.getHeight();

    final int bottom = HEIGHT - BOTTOM_PADDING;
    final int top = bottom - height;

    int left = WIDTH - HORIZONTAL_PADDING - width;
    if (isArticleRTL) {
        left = HORIZONTAL_PADDING;
    }

    canvas.save(); // --
    canvas.translate(left, top);
    wordmarkLayout.draw(canvas);
    canvas.restore(); // --
}

From source file:com.bobomee.android.gank.io.widget.CompactTabLayout.java

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (tabCount == 0) {
        return;/*from  ww  w . j  a  v a 2s . com*/
    }
    if (lastTabCount != tabCount) {
        measureTabWidths();
        lastTabCount = tabCount;
    }
    int offset = 0;
    for (int i = 0; i < selectedPosition; i++) {
        offset += tabWidths[i];
    }
    int tabWidth = tabWidths[selectedPosition];
    int indicatorWidth = tabWidth / 5;
    canvas.translate(offset, 0); //  N  tab 
    canvas.translate(indicatorLeftOffset * tabWidth, 0); //  N  tab ????
    canvas.save();
    canvas.translate(0, height - INDICATOR_HEIGHT); // ?
    int halfHoverWidth = tabWidth / 2 - indicatorWidth / 2;
    canvas.drawRect(-2, 0, halfHoverWidth, INDICATOR_HEIGHT + 9, hoverPaint);
    canvas.translate((tabWidth / 2 + indicatorWidth / 2), 0);
    canvas.drawRect(0, 0, halfHoverWidth * 2, INDICATOR_HEIGHT + 9, hoverPaint);
    canvas.restore();
}

From source file:com.justwayward.reader.view.RVPIndicator.java

/**
 * (?view)//from www  . j a v  a 2 s .com
 */
@Override
protected void dispatchDraw(Canvas canvas) {
    // ?
    canvas.save();

    switch (mIndicatorStyle) {

    case STYLE_BITMAP:

        canvas.translate(mTranslationX, 0);
        canvas.drawBitmap(mBitmap, null, mRectF, mPaint);

        break;
    case STYLE_LINE:

        canvas.translate(mTranslationX, getHeight() - mIndicatorHeight);
        canvas.drawRect(mRectF, mPaint);

        break;
    case STYLE_SQUARE:

        canvas.translate(mTranslationX, 0);
        canvas.drawRect(mRectF, mPaint);

        break;
    case STYLE_TRIANGLE:

        canvas.translate(mTranslationX, 0);
        // 
        // mPaint.setPathEffect(new CornerPathEffect(10));
        mPath = new Path();
        int midOfTab = getWidth() / mTabVisibleCount / 2;
        mPath.moveTo(midOfTab, getHeight() - mIndicatorHeight);
        mPath.lineTo(midOfTab - mIndicatorWidth / 2, getHeight());
        mPath.lineTo(midOfTab + mIndicatorWidth / 2, getHeight());
        mPath.close();
        canvas.drawPath(mPath, mPaint);

        break;
    }

    // ??
    canvas.restore();
    super.dispatchDraw(canvas);
}

From source file:com.daiv.android.twitter.manipulations.widgets.swipe_refresh_layout.FullScreenSwipeRefreshLayout.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);

    if (fullScreen) {
        if (mImmersive) {
            canvas.translate(0, actionBarTranslation);
        } else {//from   ww  w.  j  av  a2  s. co m
            canvas.translate(0, translation);
        }
    } else if (onlyStatus) {
        if (!mImmersive) {
            canvas.translate(0, statusTranslation);
        }
    }
    mProgressBar.draw(canvas);
}

From source file:me.lizheng.deckview.helpers.FakeShadowDrawable.java

private void drawShadow(Canvas canvas) {
    final float edgeShadowTop = -mCornerRadius - mShadowSize;
    final float inset = mCornerRadius + mInsetShadow + mRawShadowSize / 2;
    final boolean drawHorizontalEdges = mCardBounds.width() - 2 * inset > 0;
    final boolean drawVerticalEdges = mCardBounds.height() - 2 * inset > 0;
    // LT/*  ww w  . java  2s.c  om*/
    int saved = canvas.save();
    canvas.translate(mCardBounds.left + inset, mCardBounds.top + inset);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawHorizontalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.width() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // RB
    saved = canvas.save();
    canvas.translate(mCardBounds.right - inset, mCardBounds.bottom - inset);
    canvas.rotate(180f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawHorizontalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.width() - 2 * inset, -mCornerRadius + mShadowSize,
                mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // LB
    saved = canvas.save();
    canvas.translate(mCardBounds.left + inset, mCardBounds.bottom - inset);
    canvas.rotate(270f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawVerticalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
    // RT
    saved = canvas.save();
    canvas.translate(mCardBounds.right - inset, mCardBounds.top + inset);
    canvas.rotate(90f);
    canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
    if (drawVerticalEdges) {
        canvas.drawRect(0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
    }
    canvas.restoreToCount(saved);
}