Example usage for android.graphics Canvas restore

List of usage examples for android.graphics Canvas restore

Introduction

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

Prototype

public void restore() 

Source Link

Document

This call balances a previous call to save(), and is used to remove all modifications to the matrix/clip state since the last save call.

Usage

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

@Override
protected void onDraw(Canvas canvas) {
    // TS: jin.dongjin 2015-06-23 EMAIL BUGFIX_1015610 MOD_S
    if (mCoordinates == null) {
        LogUtils.e(LOG_TAG, "null coordinates in ConversationItemView#onDraw");
        return;/*from w w  w .  j  a v a2  s.  c om*/
    }
    // TS: jin.dongjin 2015-06-23 EMAIL BUGFIX_1015610 MOD_E

    Utils.traceBeginSection("CIVC.draw");

    // Contact photo
    if (mGadgetMode == ConversationItemViewCoordinates.GADGET_CONTACT_PHOTO) {
        canvas.save();
        Utils.traceBeginSection("draw senders image");
        drawSendersImage(canvas);
        Utils.traceEndSection();
        canvas.restore();
    }

    //TS: yanhua.chen 2015-9-2 EMAIL CR_ID MOD_S
    // Subject.
    boolean isUnread = mHeader.unread;
    // Old style subject; apply text colors/ sizes/ styling.
    canvas.save();
    if (mHeader.subjectDisplayLayout != null) {
        sPaint.setTextSize(mCoordinates.subjectFontSize);
        sPaint.setTypeface(Typeface.DEFAULT);
        // [FEATURE]-ADD-BEGIN by TSNJ,zhujian.shao,10/23/2014,FR-736411(porting from FR622697)
        canvas.translate(mSubjectWidth - mPriorityX,
                mCoordinates.subjectY + mHeader.subjectDisplayLayout.getTopPadding());
        // [FEATURE]-ADD-END by TSNJ,zhujian.shao,10/23/2014,FR-736411
        mHeader.subjectDisplayLayout.draw(canvas);
    } else {
        drawSubject(canvas);
    }
    canvas.restore();

    // Sender.
    sPaint.setTypeface(Typeface.DEFAULT);
    canvas.save();
    drawSenders(canvas);
    canvas.restore();
    //TS: yanhua.chen 2015-9-2 EMAIL CR_ID MOD_E

    canvas.save();
    drawSnippet(canvas);
    canvas.restore();

    // Folders.
    if (mConfig.areFoldersVisible()) {
        mHeader.folderDisplayer.drawFolders(canvas, mCoordinates, ViewUtils.isViewRtl(this));
    }

    // If this folder has a color (combined view/Email), show it here
    if (mConfig.isColorBlockVisible()) {
        sFoldersPaint.setColor(mHeader.conversation.color);
        sFoldersPaint.setStyle(Paint.Style.FILL);
        canvas.drawRect(mCoordinates.colorBlockX, mCoordinates.colorBlockY,
                mCoordinates.colorBlockX + mCoordinates.colorBlockWidth,
                mCoordinates.colorBlockY + mCoordinates.colorBlockHeight, sFoldersPaint);
    }

    // Draw the reply state. Draw nothing if neither replied nor forwarded.
    if (mConfig.isReplyStateVisible()) {
        if (mHeader.hasBeenRepliedTo && mHeader.hasBeenForwarded) {
            canvas.drawBitmap(STATE_REPLIED_AND_FORWARDED, mCoordinates.replyStateX, mCoordinates.replyStateY,
                    null);
        } else if (mHeader.hasBeenRepliedTo) {
            canvas.drawBitmap(STATE_REPLIED, mCoordinates.replyStateX, mCoordinates.replyStateY, null);
        } else if (mHeader.hasBeenForwarded) {
            canvas.drawBitmap(STATE_FORWARDED, mCoordinates.replyStateX, mCoordinates.replyStateY, null);
        } else if (mHeader.isInvite) {
            canvas.drawBitmap(STATE_CALENDAR_INVITE, mCoordinates.replyStateX, mCoordinates.replyStateY, null);
        }
    }

    if (mConfig.isPersonalIndicatorVisible()) {
        canvas.drawBitmap(mHeader.personalLevelBitmap, mCoordinates.personalIndicatorX,
                mCoordinates.personalIndicatorY, null);
    }

    // Info icon
    if (mHeader.infoIcon != null) {
        canvas.drawBitmap(mHeader.infoIcon, mInfoIconX, mCoordinates.infoIconY, sPaint);
    }

    // Date.
    sPaint.setTextSize(mCoordinates.dateFontSize);
    sPaint.setTypeface(isUnread ? Typeface.SANS_SERIF : SANS_SERIF_LIGHT);
    sPaint.setColor(isUnread ? sDateTextColorUnread : sDateTextColorRead);
    drawText(canvas, mHeader.dateText, mDateX, mCoordinates.dateYBaseline, sPaint);
    //TS: yanhua.chen 2015-6-19 EMAIL BUGFIX_305581 MOD_S
    //TS: wenggangjin 2015-01-27 EMAIL BUGFIX_-888881 MOD_S
    //TS: wenggangjin 2015-01-15 EMAIL BUGFIX_886241 MOD_S
    //        if (mHeader.conversation.hasAttachments && !mDisplayedFolder.isSearch()) {
    if (mHeader.conversation.hasAttachments) {
        mHeader.paperclip = ATTACHMENT;
    } else {
        mHeader.paperclip = null;
    }
    //TS: wenggangjin 2015-01-15 EMAIL BUGFIX_886241 MOD_E
    //TS: wenggangjin 2015-01-27 EMAIL BUGFIX_-888881 MOD_S
    //TS: yanhua.chen 2015-6-19 EMAIL BUGFIX_305581 MOD_E
    // Paper clip icon.
    if (mHeader.paperclip != null) {
        canvas.drawBitmap(mHeader.paperclip, mPaperclipX, mCoordinates.paperclipY, sPaint);
    }

    //[FEATURE]-Add-BEGIN by TSCD.chao zhang,04/17/2014,FR 631895(porting from FR514398)
    //priority icon
    Bitmap sPrio = sNormalPriorityIcon;
    mPriority = mHeader.conversation.flagPriority;
    if (mPriority == HIGH_PRIORITY) {
        sPrio = sHighPriorityIcon;
    } else if (mPriority == LOW_PRIORITY) {
        sPrio = sLowPriorityIcon;
    }
    // TS: zhaotianyong 2014-12-15 EMAIL BUGFIX_859814 ADD_S
    sPrio = resizeBitMap(sPrio, 0.6f, 0.6f);
    // TS: zhaotianyong 2014-12-15 EMAIL BUGFIX_859814 ADD_E
    canvas.drawBitmap(sPrio, mPriorityX, mCoordinates.paperclipY, null);

    //[FEATURE]-Add-END by TSCD.chao zhang

    if (mStarEnabled) {
        // Star.
        canvas.drawBitmap(getStarBitmap(), mCoordinates.starX, mCoordinates.starY, sPaint);
    }

    // right-side edge effect when in tablet conversation mode and the list is not collapsed
    if (Utils.getDisplayListRightEdgeEffect(mTabletDevice, mListCollapsible, mConfig.getViewMode())) {
        final boolean isRtl = ViewUtils.isViewRtl(this);
        RIGHT_EDGE_TABLET.setBounds((isRtl) ? 0 : getWidth() - RIGHT_EDGE_TABLET.getIntrinsicWidth(), 0,
                (isRtl) ? RIGHT_EDGE_TABLET.getIntrinsicWidth() : getWidth(), getHeight());
        RIGHT_EDGE_TABLET.draw(canvas);

        if (isActivated()) {
            final int w = VISIBLE_CONVERSATION_HIGHLIGHT.getIntrinsicWidth();
            VISIBLE_CONVERSATION_HIGHLIGHT.setBounds((isRtl) ? getWidth() - w : 0, 0, (isRtl) ? getWidth() : w,
                    getHeight());
            VISIBLE_CONVERSATION_HIGHLIGHT.draw(canvas);
        }
    }
    //TS: zheng.zou 2015-09-01 EMAIL BUGFIX_539892 MOD_S
    if (mWillDrawDivider) {
        // draw the inset divider
        sDividerPaint.setColor(sDividerColor);
        final int dividerBottomY = getHeight();
        final int dividerTopY = dividerBottomY - sDividerHeight;
        // AM: Kexue.Geng 2015-02-28 EMAIL BUGFIX_900927 MOD_S
        // canvas.drawRect(sDividerInset, dividerTopY, getWidth(), dividerBottomY, sDividerPaint);
        canvas.drawRect(mGadgetMode == ConversationItemViewCoordinates.GADGET_NONE ? 0 : sDividerInset,
                dividerTopY, getWidth(), dividerBottomY, sDividerPaint);
        // AM: Kexue.Geng 2015-02-28 EMAIL BUGFIX_900927 MOD_E
    }
    //TS: zheng.zou 2015-09-01 EMAIL BUGFIX_539892 MOD_E
    Utils.traceEndSection();
    // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_S
    //draw the status
    canvas.save();
    drawStatus(canvas);
    canvas.restore();
    // TS: chao.zhang 2015-09-14 EMAIL FEATURE-585337 ADD_E
}

From source file:org.connectbot.TerminalView.java

@Override
public void onDraw(Canvas canvas) {
    if (bridge.bitmap != null) {
        // draw the bitmap
        bridge.onDraw();/*from  www. ja v a 2  s  . c  o  m*/

        // draw the bridge bitmap if it exists
        canvas.drawBitmap(bridge.bitmap, 0, 0, paint);

        // also draw cursor if visible
        if (bridge.buffer.isCursorVisible()) {
            int cursorColumn = bridge.buffer.getCursorColumn();
            final int cursorRow = bridge.buffer.getCursorRow();

            final int columns = bridge.buffer.getColumns();

            if (cursorColumn == columns)
                cursorColumn = columns - 1;

            if (cursorColumn < 0 || cursorRow < 0)
                return;

            int currentAttribute = bridge.buffer.getAttributes(cursorColumn, cursorRow);
            boolean onWideCharacter = (currentAttribute & VDUBuffer.FULLWIDTH) != 0;

            int x = cursorColumn * bridge.charWidth;
            int y = (bridge.buffer.getCursorRow() + bridge.buffer.screenBase - bridge.buffer.windowBase)
                    * bridge.charHeight;

            // Save the current clip and translation
            canvas.save();

            canvas.translate(x, y);
            canvas.clipRect(0, 0, bridge.charWidth * (onWideCharacter ? 2 : 1), bridge.charHeight);
            canvas.drawPaint(cursorPaint);

            final int deadKey = bridge.getKeyHandler().getDeadKey();
            if (deadKey != 0) {
                canvas.drawText(new char[] { (char) deadKey }, 0, 1, 0, 0, cursorStrokePaint);
            }

            // Make sure we scale our decorations to the correct size.
            canvas.concat(scaleMatrix);

            int metaState = bridge.getKeyHandler().getMetaState();

            if ((metaState & TerminalKeyListener.OUR_SHIFT_ON) != 0)
                canvas.drawPath(shiftCursor, cursorStrokePaint);
            else if ((metaState & TerminalKeyListener.OUR_SHIFT_LOCK) != 0)
                canvas.drawPath(shiftCursor, cursorPaint);

            if ((metaState & TerminalKeyListener.OUR_ALT_ON) != 0)
                canvas.drawPath(altCursor, cursorStrokePaint);
            else if ((metaState & TerminalKeyListener.OUR_ALT_LOCK) != 0)
                canvas.drawPath(altCursor, cursorPaint);

            if ((metaState & TerminalKeyListener.OUR_CTRL_ON) != 0)
                canvas.drawPath(ctrlCursor, cursorStrokePaint);
            else if ((metaState & TerminalKeyListener.OUR_CTRL_LOCK) != 0)
                canvas.drawPath(ctrlCursor, cursorPaint);

            // Restore previous clip region
            canvas.restore();
        }

        // draw any highlighted area
        if (bridge.isSelectingForCopy()) {
            SelectionArea area = bridge.getSelectionArea();
            canvas.save(Canvas.CLIP_SAVE_FLAG);
            canvas.clipRect(area.getLeft() * bridge.charWidth, area.getTop() * bridge.charHeight,
                    (area.getRight() + 1) * bridge.charWidth, (area.getBottom() + 1) * bridge.charHeight);
            canvas.drawPaint(cursorPaint);
            canvas.restore();
        }
    }
}

From source file:com.marlonjones.voidlauncher.CellLayout.java

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

    for (int i = 0; i < mFolderBackgrounds.size(); i++) {
        FolderIcon.PreviewBackground bg = mFolderBackgrounds.get(i);
        if (bg.isClipping) {
            cellToPoint(bg.delegateCellX, bg.delegateCellY, mTempLocation);
            canvas.save();/* ww  w  . j a  v a  2  s  . c o  m*/
            canvas.translate(mTempLocation[0], mTempLocation[1]);
            bg.drawBackgroundStroke(canvas, mFolderBgPaint);
            canvas.restore();
        }
    }
}

From source file:kankan.wheel.widget.WheelView.java

/**
 * Draws items//w w  w. ja  v a 2  s . co m
 * @param canvas the canvas for drawing
 */
private void drawItems(Canvas canvas) {
    canvas.save();

    int top = (currentItem - firstItem) * getItemHeight() + (getItemHeight() - getHeight()) / 2;
    canvas.translate(PADDING, -top + scrollingOffset);

    //??
    AbstractWheelTextAdapter adapter = null;
    if (viewAdapter instanceof AbstractWheelTextAdapter) {
        adapter = (AbstractWheelTextAdapter) viewAdapter;
    }
    if (adapter != null && adapter.isEnableMultiTextColor()) {
        int targetIndex = -1;
        int minDis = Integer.MAX_VALUE;
        for (int i = 0; i < itemsLayout.getChildCount(); i++) {
            TextView child = (TextView) itemsLayout.getChildAt(i);
            int realTop = child.getTop() - top + scrollingOffset;
            int viewCenter = realTop + child.getHeight() / 2;
            Rect bounds = centerDrawable.getBounds();
            int dis = Math.abs(viewCenter - bounds.centerY());
            if (dis < minDis) {
                minDis = dis;
                targetIndex = i;
            }
        }

        for (int i = 0; i < itemsLayout.getChildCount(); i++) {
            TextView view = (TextView) itemsLayout.getChildAt(i);
            view.setAlpha(0.5f);
            view.setTextColor(adapter.getTextColor());
            view.setTextSize(adapter.getTextSize());
            adapter.setTextViewPadding(view, adapter.getTextPaddingTop(), adapter.getTextPaddingBottom());

        }

        if (targetIndex != -1) {
            TextView view = (TextView) itemsLayout.getChildAt(targetIndex);
            view.setAlpha(1);
            view.setTextColor(adapter.getTextSelectedColor());
            view.setTextSize(adapter.getTextSize() + 4);
            adapter.setTextViewPadding(view, adapter.getTextPaddingTop() - 2,
                    adapter.getTextPaddingBottom() - 2);
        }

        TextView view = (TextView) itemsLayout.getChildAt(targetIndex - 1);
        if (view != null)
            view.setAlpha(1);
        view = (TextView) itemsLayout.getChildAt(targetIndex + 1);
        if (view != null)
            view.setAlpha(1);
    }

    itemsLayout.draw(canvas);

    canvas.restore();
}

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

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    if (child == topView) {
        canvas.save();//  ww  w. j  a  v a 2s.c om
        canvas.clipRect(0, 0, getMeasuredWidth(), child.getLayoutParams().height + AndroidUtilities.dp(2));
    }
    boolean result = super.drawChild(canvas, child, drawingTime);
    if (child == topView) {
        canvas.restore();
    }
    return result;
}

From source file:android.support.v7.graphics.drawable.DrawerArrowDrawable.java

@Override
public void draw(Canvas canvas) {
    Rect bounds = getBounds();//ww  w.j  a  v a  2  s.  co  m

    final boolean flipToPointRight;
    switch (mDirection) {
    case ARROW_DIRECTION_LEFT:
        flipToPointRight = false;
        break;
    case ARROW_DIRECTION_RIGHT:
        flipToPointRight = true;
        break;
    case ARROW_DIRECTION_END:
        flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR;
        break;
    case ARROW_DIRECTION_START:
    default:
        flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
        break;
    }

    // Interpolated widths of arrow bars

    float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2);
    arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress);
    final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress);
    // Interpolated size of middle bar
    final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, mProgress));
    // The rotation of the top and bottom bars (that make the arrow head)
    final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress);

    // The whole canvas rotates as the transition happens
    final float canvasRotate = lerp(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress);

    final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation));
    final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation));

    mPath.rewind();
    final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress);

    final float arrowEdge = -arrowShaftLength / 2;
    // draw middle bar
    mPath.moveTo(arrowEdge + arrowShaftCut, 0);
    mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0);

    // bottom bar
    mPath.moveTo(arrowEdge, topBottomBarOffset);
    mPath.rLineTo(arrowWidth, arrowHeight);

    // top bar
    mPath.moveTo(arrowEdge, -topBottomBarOffset);
    mPath.rLineTo(arrowWidth, -arrowHeight);

    mPath.close();

    canvas.save();

    // Rotate the whole canvas if spinning, if not, rotate it 180 to get
    // the arrow pointing the other way for RTL.
    final float barThickness = mPaint.getStrokeWidth();
    final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2);
    float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2.
    yOffset += barThickness * 1.5 + mBarGap;

    canvas.translate(bounds.centerX(), yOffset);
    if (mSpin) {
        canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1));
    } else if (flipToPointRight) {
        canvas.rotate(180);
    }
    canvas.drawPath(mPath, mPaint);

    canvas.restore();
}

From source file:com.commonsware.cwac.crossport.v7.graphics.drawable.DrawerArrowDrawable.java

@Override
public void draw(Canvas canvas) {
    Rect bounds = getBounds();/*from   www  .  ja v  a2  s.c o  m*/

    final boolean flipToPointRight;
    switch (mDirection) {
    case ARROW_DIRECTION_LEFT:
        flipToPointRight = false;
        break;
    case ARROW_DIRECTION_RIGHT:
        flipToPointRight = true;
        break;
    case ARROW_DIRECTION_END:
        flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR;
        break;
    case ARROW_DIRECTION_START:
    default:
        flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
        break;
    }

    // Interpolated widths of arrow bars

    float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2);
    arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress);
    final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress);
    // Interpolated size of middle bar
    final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, mProgress));
    // The rotation of the top and bottom bars (that make the arrow head)
    final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress);

    // The whole canvas rotates as the transition happens
    final float canvasRotate = lerp(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress);

    final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation));
    final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation));

    mPath.rewind();
    final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress);

    final float arrowEdge = -arrowShaftLength / 2;
    // draw middle bar
    mPath.moveTo(arrowEdge + arrowShaftCut, 0);
    mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0);

    // bottom bar
    mPath.moveTo(arrowEdge, topBottomBarOffset);
    mPath.rLineTo(arrowWidth, arrowHeight);

    // top bar
    mPath.moveTo(arrowEdge, -topBottomBarOffset);
    mPath.rLineTo(arrowWidth, -arrowHeight);

    mPath.close();

    canvas.save();

    // Rotate the whole canvas if spinning, if not, rotate it 180 to get
    // the arrow pointing the other way for RTL.
    final float barThickness = mPaint.getStrokeWidth();
    final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2);
    float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2.
    yOffset += barThickness * 1.5f + mBarGap;

    canvas.translate(bounds.centerX(), yOffset);
    if (mSpin) {
        canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1));
    } else if (flipToPointRight) {
        canvas.rotate(180);
    }
    canvas.drawPath(mPath, mPaint);

    canvas.restore();
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mRemeasure) {
        remeasure(getWidth(), getHeight());
        mRemeasure = false;/*ww  w .j a va  2s .c  o m*/
    }
    canvas.save();

    float yTranslate = -mViewStartY + DAY_HEADER_HEIGHT;
    // offset canvas by the current drag and header position
    canvas.translate(-mViewStartX, yTranslate);
    // clip to everything below the allDay area
    Rect dest = mDestRect;
    dest.top = (int) (mFirstCell - yTranslate);
    dest.bottom = (int) (mViewHeight - yTranslate);
    dest.left = 0;
    dest.right = mViewWidth;
    canvas.save();
    canvas.clipRect(dest);
    // Draw the movable part of the view
    doDraw(canvas);
    // restore to having no clip
    canvas.restore();

    if ((mTouchMode & TOUCH_MODE_HSCROLL) != 0) {
        float xTranslate;
        if (mViewStartX > 0) {
            xTranslate = mViewWidth;
        } else {
            xTranslate = -mViewWidth;
        }
        // Move the canvas around to prep it for the next view
        // specifically, shift it by a screen and undo the
        // yTranslation which will be redone in the nextView's onDraw().
        canvas.translate(xTranslate, -yTranslate);
        DayView nextView = (DayView) mViewSwitcher.getNextView();

        // Prevent infinite recursive calls to onDraw().
        nextView.mTouchMode = TOUCH_MODE_INITIAL_STATE;

        nextView.onDraw(canvas);
        // Move it back for this view
        canvas.translate(-xTranslate, 0);
    } else {
        // If we drew another view we already translated it back
        // If we didn't draw another view we should be at the edge of the
        // screen
        canvas.translate(mViewStartX, -yTranslate);
    }

    // Draw the fixed areas (that don't scroll) directly to the canvas.
    drawAfterScroll(canvas);
    mComputeSelectedEvents = false;

    // Draw overscroll glow
    if (!mEdgeEffectTop.isFinished()) {
        if (DAY_HEADER_HEIGHT != 0) {
            canvas.translate(0, DAY_HEADER_HEIGHT);
        }
        if (mEdgeEffectTop.draw(canvas)) {
            invalidate();
        }
        if (DAY_HEADER_HEIGHT != 0) {
            canvas.translate(0, -DAY_HEADER_HEIGHT);
        }
    }
    if (!mEdgeEffectBottom.isFinished()) {
        canvas.rotate(180, mViewWidth / 2, mViewHeight / 2);
        if (mEdgeEffectBottom.draw(canvas)) {
            invalidate();
        }
    }
    canvas.restore();
}

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

private void renderSelection(Canvas canvas, boolean clearSelection) {
    if (mSelectedWord == null) {
        return;//from  www .  j  a v a2s .c o m
    }

    int startRow = mSelectedWord.getStartRow();
    int endRow = startRow;
    int startColumn = mSelectedWord.getStartColumn();
    int endColumn = startColumn;
    RectF cellRect = new RectF();

    canvas.save();
    canvas.scale(mRenderScale, mRenderScale);

    if (mSelectedWord.getDirection() == Crossword.Word.DIR_ACROSS) {
        endColumn += mSelectedWord.getLength() - 1;
    } else {
        endRow += mSelectedWord.getLength() - 1;
    }

    float top = mSelectedWord.getStartRow() * mCellSize;
    for (int row = startRow, index = 0; row <= endRow; row++, top += mCellSize) {
        float left = mSelectedWord.getStartColumn() * mCellSize;
        for (int column = startColumn; column <= endColumn; column++, left += mCellSize) {
            Cell cell = mPuzzleCells[row][column];
            if (cell != null) {
                // Draw the unselected cell
                Paint paint;
                if (clearSelection) {
                    paint = mCellFillPaint;
                } else {
                    if (index == mSelectedCell) {
                        paint = mSelectedCellFillPaint;
                    } else {
                        paint = mSelectedWordFillPaint;
                    }
                }

                cellRect.set(left, top, left + mCellSize, top + mCellSize);
                renderCell(canvas, cell, cellRect, paint);
            }

            index++;
        }
    }

    canvas.restore();
}

From source file:com.brian.common.view.DrawerArrowDrawable.java

@Override
public void draw(Canvas canvas) {
    if (mIsCirculate) {
        if (mProgress >= .995) {
            flipped = true;/*from  ww w.j  a  va  2 s . co  m*/
        } else if (mProgress <= .005) {
            flipped = false;
        }
        if (flipped) {
            canvas.save();
            canvas.scale(1f, -1f, getIntrinsicWidth() / 2, getIntrinsicHeight() / 2);
        }
    }

    Rect bounds = getBounds();

    final boolean flipToPointRight;
    switch (mDirection) {
    case ARROW_DIRECTION_LEFT:
        flipToPointRight = false;
        break;
    case ARROW_DIRECTION_RIGHT:
        flipToPointRight = true;
        break;
    default:
        flipToPointRight = false;
        break;
    }

    // Interpolated widths of arrow bars

    float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2);
    arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress);
    final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress);
    // Interpolated size of middle bar
    final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, mProgress));
    // The rotation of the top and bottom bars (that make the arrow head)
    final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress);

    // The whole canvas rotates as the transition happens
    final float canvasRotate = lerp(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress);

    final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation));
    final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation));

    mPath.rewind();
    final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress);

    final float arrowEdge = -arrowShaftLength / 2;
    // draw middle bar
    mPath.moveTo(arrowEdge + arrowShaftCut, 0);
    mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0);

    // bottom bar
    mPath.moveTo(arrowEdge, topBottomBarOffset);
    mPath.rLineTo(arrowWidth, arrowHeight);

    // top bar
    mPath.moveTo(arrowEdge, -topBottomBarOffset);
    mPath.rLineTo(arrowWidth, -arrowHeight);

    mPath.close();

    canvas.save();

    // Rotate the whole canvas if spinning, if not, rotate it 180 to get
    // the arrow pointing the other way for RTL.
    final float barThickness = mPaint.getStrokeWidth();
    final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2);
    float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2.
    yOffset += barThickness * 1.5 + mBarGap;

    canvas.translate(bounds.centerX(), yOffset);
    if (mSpin) {
        canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1));
    } else if (flipToPointRight) {
        canvas.rotate(180);
    }
    canvas.drawPath(mPath, mPaint);

    canvas.restore();
}