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.tct.mail.browse.ConversationItemView.java

private void drawSubject(Canvas canvas) {
    canvas.translate(mSubjectX, mCoordinates.subjectY);
    mSubjectTextView.draw(canvas);
}

From source file:com.tct.mail.browse.ConversationItemView.java

private void drawStatus(Canvas canvas) {
    canvas.translate(mStatusX, mCoordinates.statusY);
    mStatusTextView.draw(canvas);
}

From source file:com.tct.mail.browse.ConversationItemView.java

private void drawSenders(Canvas canvas) {
    canvas.translate(mCoordinates.sendersX, mCoordinates.sendersY);
    mSendersTextView.draw(canvas);
}

From source file:org.chromium.chrome.browser.toolbar.ToolbarPhone.java

/**
 * When entering and exiting the TabSwitcher mode, we fade out or fade in the browsing
 * mode of the toolbar on top of the TabSwitcher mode version of it.  We do this by
 * drawing all of the browsing mode views on top of the android view.
 *///from   www .j av  a 2  s .c o  m
private void drawTabSwitcherAnimationOverlay(Canvas canvas, float animationProgress) {
    if (!isNativeLibraryReady())
        return;

    float floatAlpha = 1 - animationProgress;
    int rgbAlpha = (int) (255 * floatAlpha);
    canvas.save();
    canvas.translate(0, -animationProgress * mBackgroundOverlayBounds.height());
    canvas.clipRect(mBackgroundOverlayBounds);

    float previousAlpha = 0.f;
    if (mHomeButton.getVisibility() != View.GONE) {
        // Draw the New Tab button used in the URL view.
        previousAlpha = mHomeButton.getAlpha();
        mHomeButton.setAlpha(previousAlpha * floatAlpha);
        drawChild(canvas, mHomeButton, SystemClock.uptimeMillis());
        mHomeButton.setAlpha(previousAlpha);
    }

    // Draw the location/URL bar.
    previousAlpha = mLocationBar.getAlpha();
    mLocationBar.setAlpha(previousAlpha * floatAlpha);
    // If the location bar is now fully transparent, do not bother drawing it.
    if (mLocationBar.getAlpha() != 0) {
        drawChild(canvas, mLocationBar, SystemClock.uptimeMillis());
    }
    mLocationBar.setAlpha(previousAlpha);

    // Draw the tab stack button and associated text.
    translateCanvasToView(this, mToolbarButtonsContainer, canvas);

    if (mTabSwitcherAnimationTabStackDrawable != null && mToggleTabStackButton != null
            && mUrlExpansionPercent != 1f) {
        // Draw the tab stack button image.
        canvas.save();
        translateCanvasToView(mToolbarButtonsContainer, mToggleTabStackButton, canvas);

        int backgroundWidth = mToggleTabStackButton.getDrawable().getIntrinsicWidth();
        int backgroundHeight = mToggleTabStackButton.getDrawable().getIntrinsicHeight();
        int backgroundLeft = (mToggleTabStackButton.getWidth() - mToggleTabStackButton.getPaddingLeft()
                - mToggleTabStackButton.getPaddingRight() - backgroundWidth) / 2;
        backgroundLeft += mToggleTabStackButton.getPaddingLeft();
        int backgroundTop = (mToggleTabStackButton.getHeight() - mToggleTabStackButton.getPaddingTop()
                - mToggleTabStackButton.getPaddingBottom() - backgroundHeight) / 2;
        backgroundTop += mToggleTabStackButton.getPaddingTop();
        canvas.translate(backgroundLeft, backgroundTop);

        mTabSwitcherAnimationTabStackDrawable.setAlpha(rgbAlpha);
        mTabSwitcherAnimationTabStackDrawable.draw(canvas);
        canvas.restore();
    }

    // Draw the menu button if necessary.
    if (!mShowMenuBadge && mTabSwitcherAnimationMenuDrawable != null && mUrlExpansionPercent != 1f) {
        mTabSwitcherAnimationMenuDrawable.setBounds(mMenuButton.getPaddingLeft(), mMenuButton.getPaddingTop(),
                mMenuButton.getWidth() - mMenuButton.getPaddingRight(),
                mMenuButton.getHeight() - mMenuButton.getPaddingBottom());
        translateCanvasToView(mToolbarButtonsContainer, mMenuButton, canvas);
        mTabSwitcherAnimationMenuDrawable.setAlpha(rgbAlpha);
        int color = mUseLightDrawablesForTextureCapture ? mLightModeDefaultColor : mDarkModeDefaultColor;
        mTabSwitcherAnimationMenuDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        mTabSwitcherAnimationMenuDrawable.draw(canvas);
    }

    // Draw the menu badge if necessary.
    Drawable badgeDrawable = mUseLightDrawablesForTextureCapture ? mTabSwitcherAnimationMenuBadgeLightDrawable
            : mTabSwitcherAnimationMenuBadgeDarkDrawable;
    if (mShowMenuBadge && badgeDrawable != null && mUrlExpansionPercent != 1f) {
        badgeDrawable.setBounds(mMenuBadge.getPaddingLeft(), mMenuBadge.getPaddingTop(),
                mMenuBadge.getWidth() - mMenuBadge.getPaddingRight(),
                mMenuBadge.getHeight() - mMenuBadge.getPaddingBottom());
        translateCanvasToView(mToolbarButtonsContainer, mMenuBadge, canvas);
        badgeDrawable.setAlpha(rgbAlpha);
        badgeDrawable.draw(canvas);
    }

    mLightDrawablesUsedForLastTextureCapture = mUseLightDrawablesForTextureCapture;

    canvas.restore();
}

From source file:com.appunite.list.FastScroller.java

public void draw(Canvas canvas) {

    if (mState == STATE_NONE) {
        // No need to draw anything
        return;/*  w ww  .j  ava  2  s.  co  m*/
    }

    final int y = mThumbY;
    final int viewWidth = mList.getWidth();
    final FastScroller.ScrollFade scrollFade = mScrollFade;

    int alpha = -1;
    if (mState == STATE_EXIT) {
        alpha = scrollFade.getAlpha();
        if (alpha < ScrollFade.ALPHA_MAX / 2) {
            mThumbDrawable.setAlpha(alpha * 2);
        }
        int left = 0;
        switch (mPosition) {
        case View.SCROLLBAR_POSITION_RIGHT:
            left = viewWidth - (mThumbW * alpha) / ScrollFade.ALPHA_MAX;
            break;
        case View.SCROLLBAR_POSITION_LEFT:
            left = -mThumbW + (mThumbW * alpha) / ScrollFade.ALPHA_MAX;
            break;
        }
        mThumbDrawable.setBounds(left, 0, left + mThumbW, mThumbH);
        mChangedBounds = true;
    }

    if (mTrackDrawable != null) {
        final Rect thumbBounds = mThumbDrawable.getBounds();
        final int left = thumbBounds.left;
        final int halfThumbHeight = (thumbBounds.bottom - thumbBounds.top) / 2;
        final int trackWidth = mTrackDrawable.getIntrinsicWidth();
        final int trackLeft = (left + mThumbW / 2) - trackWidth / 2;
        mTrackDrawable.setBounds(trackLeft, halfThumbHeight, trackLeft + trackWidth,
                mList.getHeight() - halfThumbHeight);
        mTrackDrawable.draw(canvas);
    }

    canvas.translate(0, y);
    mThumbDrawable.draw(canvas);
    canvas.translate(0, -y);

    // If user is dragging the scroll bar, draw the alphabet overlay
    if (mState == STATE_DRAGGING && mDrawOverlay) {
        if (mOverlayPosition == OVERLAY_AT_THUMB) {
            int left = 0;
            switch (mPosition) {
            default:
            case View.SCROLLBAR_POSITION_RIGHT:
                left = Math.max(0, mThumbDrawable.getBounds().left - mThumbW - mOverlaySize);
                break;
            case View.SCROLLBAR_POSITION_LEFT:
                left = Math.min(mThumbDrawable.getBounds().right + mThumbW, mList.getWidth() - mOverlaySize);
                break;
            }

            int top = Math.max(0, Math.min(y + (mThumbH - mOverlaySize) / 2, mList.getHeight() - mOverlaySize));

            final RectF pos = mOverlayPos;
            pos.left = left;
            pos.right = pos.left + mOverlaySize;
            pos.top = top;
            pos.bottom = pos.top + mOverlaySize;
            if (mOverlayDrawable != null) {
                mOverlayDrawable.setBounds((int) pos.left, (int) pos.top, (int) pos.right, (int) pos.bottom);
            }
        }
        mOverlayDrawable.draw(canvas);
        final Paint paint = mPaint;
        float descent = paint.descent();
        final RectF rectF = mOverlayPos;
        final Rect tmpRect = mTmpRect;
        mOverlayDrawable.getPadding(tmpRect);
        final int hOff = (tmpRect.right - tmpRect.left) / 2;
        final int vOff = (tmpRect.bottom - tmpRect.top) / 2;
        canvas.drawText(mSectionText, (int) (rectF.left + rectF.right) / 2 - hOff,
                (int) (rectF.bottom + rectF.top) / 2 + mOverlaySize / 4 - descent - vOff, paint);
    } else if (mState == STATE_EXIT) {
        if (alpha == 0) { // Done with exit
            setState(STATE_NONE);
        } else if (mTrackDrawable != null) {
            mList.invalidate(viewWidth - mThumbW, 0, viewWidth, mList.getHeight());
        } else {
            mList.invalidate(viewWidth - mThumbW, y, viewWidth, y + mThumbH);
        }
    }
}

From source file:org.akop.ararat.view.CrosswordView.java

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

    constrainTranslation();//w w w .ja va 2  s .  com

    canvas.save();
    canvas.clipRect(mContentRect);
    canvas.translate(mBitmapOffset.x, mBitmapOffset.y);
    canvas.scale(mBitmapScale, mBitmapScale);

    if (mPuzzleBitmap != null) {
        canvas.drawBitmap(mPuzzleBitmap, 0, 0, mBitmapPaint);
    } else {
        // Perform a fast, barebones render so that the screen doesn't
        // look completely empty

        mInPlaceRenderer.renderPuzzle(canvas, mRenderScale, true);
    }

    canvas.restore();
}

From source file:com.ruesga.timelinechart.TimelineChartView.java

private void drawEdgeEffects(Canvas c) {
    boolean needsInvalidate = false;

    if (mEdgeEffectLeft != null && !mEdgeEffectLeft.isFinished()) {
        final int restoreCount = c.save();
        c.rotate(270);//from  w w  w .  j  a  v a  2s.c om
        c.translate(-mGraphArea.height() - mGraphArea.top, mGraphArea.left);
        mEdgeEffectLeft.setSize((int) mGraphArea.height(), (int) mGraphArea.width());
        needsInvalidate = mEdgeEffectLeft.draw(c);
        c.restoreToCount(restoreCount);
    }

    if (mEdgeEffectRight != null && !mEdgeEffectRight.isFinished()) {
        final int restoreCount = c.save();
        c.rotate(90);
        c.translate(mGraphArea.top, -getWidth() + (getWidth() - mGraphArea.right));
        mEdgeEffectRight.setSize((int) mGraphArea.height(), (int) mGraphArea.width());
        needsInvalidate |= mEdgeEffectRight.draw(c);
        c.restoreToCount(restoreCount);
    }

    if (needsInvalidate) {
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

From source file:com.iangclifton.auid.horizontaliconview.HorizontalIconView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mDrawables == null || mDrawables.isEmpty()) {
        return;/*from w ww .  j  a va2s .  com*/
    }

    final int width = getWidth();
    final int paddingBottom = getPaddingBottom();
    final int paddingLeft = getPaddingLeft();
    final int paddingTop = getPaddingTop();

    // Determine edges of visible content
    final int leftEdge = getScrollX();
    final int rightEdge = leftEdge + width;

    int left = paddingLeft;
    int top = paddingTop;
    mSkippedIconCount = 0;

    final int iconCount = mDrawables.size();
    for (int i = 0; i < iconCount; i++) {
        if (left + mIconSize < leftEdge) {
            // Icon is too far left to be seen
            left = left + mIconSize + mIconSpacing;
            mSkippedIconCount++;
            continue;
        }

        if (left > rightEdge) {
            // All remaining icons are right of the view
            break;
        }

        // Get a reference to the icon to be drawn
        final Drawable icon = mDrawables.get(i);
        icon.setBounds(left, top, left + mIconSize, top + mIconSize);
        icon.draw(canvas);

        // Icon was drawn, so track position
        final int drawnPosition = i - mSkippedIconCount;
        if (drawnPosition + 1 > mIconPositions.size()) {
            final Rect rect = icon.copyBounds();
            mIconPositions.add(rect);
        } else {
            final Rect rect = mIconPositions.get(drawnPosition);
            icon.copyBounds(rect);
        }

        // Update left position
        left = left + mIconSize + mIconSpacing;
    }

    if (mEdgeEffectLeft != null) {
        if (!mEdgeEffectLeft.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight() - paddingTop - paddingBottom;

            canvas.rotate(270);
            canvas.translate(-height + paddingTop, Math.min(0, leftEdge));
            mEdgeEffectLeft.setSize(height, getWidth());
            if (mEdgeEffectLeft.draw(canvas)) {
                postInvalidateOnAnimation();
            }
            canvas.restoreToCount(restoreCount);
        }
        if (!mEdgeEffectRight.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight() - paddingTop - paddingBottom;

            canvas.rotate(90);
            canvas.translate(-paddingTop, -(Math.max(mScrollRange, leftEdge) + width));
            mEdgeEffectRight.setSize(height, width);
            if (mEdgeEffectRight.draw(canvas)) {
                postInvalidateOnAnimation();
            }
            canvas.restoreToCount(restoreCount);
        }
    }
}

From source file:com.hippo.widget.BothScrollView.java

@SuppressWarnings("SuspiciousNameCombination")
@Override/*from ww w .j a va 2 s  .c  om*/
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (mEdgeGlowLeft != null) {
        final int scrollX = getScrollX();
        final int scrollY = getScrollY();
        final int width = getWidth();
        final int height = getHeight();
        if (!mEdgeGlowLeft.isFinished()) {
            final int restoreCount = canvas.save();
            canvas.rotate(270);
            canvas.translate(-height - scrollY, Math.min(0, scrollX));
            mEdgeGlowLeft.setSize(height, width);
            if (mEdgeGlowLeft.draw(canvas)) {
                ViewCompat.postInvalidateOnAnimation(this);
            }
            canvas.restoreToCount(restoreCount);
        }
        if (!mEdgeGlowRight.isFinished()) {
            final int restoreCount = canvas.save();
            canvas.rotate(90);
            canvas.translate(scrollY, -(Math.max(getHorizontalScrollRange(), scrollX) + width));
            mEdgeGlowRight.setSize(height, width);
            if (mEdgeGlowRight.draw(canvas)) {
                ViewCompat.postInvalidateOnAnimation(this);
            }
            canvas.restoreToCount(restoreCount);
        }
        if (!mEdgeGlowTop.isFinished()) {
            final int restoreCount = canvas.save();
            canvas.translate(scrollX, Math.min(0, scrollY));
            mEdgeGlowTop.setSize(width, height);
            if (mEdgeGlowTop.draw(canvas)) {
                ViewCompat.postInvalidateOnAnimation(this);
            }
            canvas.restoreToCount(restoreCount);
        }
        if (!mEdgeGlowBottom.isFinished()) {
            final int restoreCount = canvas.save();
            canvas.translate(-width + scrollX, Math.max(getVerticalScrollRange(), scrollY) + height);
            canvas.rotate(180, width, 0);
            mEdgeGlowBottom.setSize(width, height);
            if (mEdgeGlowBottom.draw(canvas)) {
                ViewCompat.postInvalidateOnAnimation(this);
            }
            canvas.restoreToCount(restoreCount);
        }
    }
}

From source file:com.tct.mail.browse.ConversationItemView.java

private void drawSendersImage(final Canvas canvas) {
    if (!mSendersImageView.isFlipping()) {
        final boolean showSenders = !isSelected();
        mSendersImageView.reset(showSenders);
    }/*from  w w  w  . j  a v  a2 s. c  om*/
    canvas.translate(mCoordinates.contactImagesX, mCoordinates.contactImagesY);
    if (mPhotoBitmap == null) {
        mSendersImageView.draw(canvas);
    } else {
        canvas.drawBitmap(mPhotoBitmap, null, mPhotoRect, sPaint);
    }
}