Example usage for android.graphics Canvas save

List of usage examples for android.graphics Canvas save

Introduction

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

Prototype

public int save() 

Source Link

Document

Saves the current matrix and clip onto a private stack.

Usage

From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    if (mEdgeGlowTop != null) {
        final int scrollX = getScrollX();
        final int scrollY = getScrollY();
        if (scrollDirection == DIRECTION_HORIZONTAL) {
            //            if (!mEdgeGlowLeft.isFinished()) {
            //               Log.i("NestedScrollView", "draw  ");
            //               final int restoreCount = canvas.save();
            //               final int height = getHeight() - getPaddingTop()
            //                     - getPaddingBottom();
            //               
            //               canvas.translate(getPaddingLeft(), height);
            //               canvas.rotate(-90);
            //               mEdgeGlowLeft.setSize(getWidth(), height);
            //               if (mEdgeGlowLeft.draw(canvas)) {
            //                  ViewCompat.postInvalidateOnAnimation(this);
            //               }
            //               canvas.restoreToCount(restoreCount);
            //            }
            //            if (!mEdgeGlowRight.isFinished()) {
            //               Log.i("NestedScrollView", "draw  ?");
            //               final int restoreCount = canvas.save();
            //               final int height = getHeight() - getPaddingTop()
            //                     - getPaddingBottom();
            ///*from  ww w  . j a  va  2  s  .com*/
            //               canvas.translate(getPaddingLeft() + getWidth(),height);
            //               canvas.rotate(90);
            //               mEdgeGlowRight.setSize(getWidth(), height);
            //               if (mEdgeGlowRight.draw(canvas)) {
            //                  ViewCompat.postInvalidateOnAnimation(this);
            //               }
            //               canvas.restoreToCount(restoreCount);
            //            }

            if (!mEdgeGlowLeft.isFinished()) {
                final int restoreCount = canvas.save();
                final int height = getHeight() - getPaddingTop() - getPaddingBottom();

                canvas.rotate(270);
                canvas.translate(-height + getPaddingTop() - scrollY, Math.min(0, scrollX));
                mEdgeGlowLeft.setSize(height, getWidth());
                if (mEdgeGlowLeft.draw(canvas)) {
                    invalidate();
                }
                canvas.restoreToCount(restoreCount);
            }
            if (!mEdgeGlowRight.isFinished()) {
                final int restoreCount = canvas.save();
                final int width = getWidth();
                final int height = getHeight() - getPaddingTop() - getPaddingBottom();

                canvas.rotate(90);
                canvas.translate(-getPaddingTop() + scrollY,
                        -(Math.max(getHorizontalScrollRange(), scrollX) + width));
                mEdgeGlowRight.setSize(height, width);
                if (mEdgeGlowRight.draw(canvas)) {
                    invalidate();
                }
                canvas.restoreToCount(restoreCount);
            }
        } else if (scrollDirection == DIRECTION_VERTICAL) {
            if (!mEdgeGlowTop.isFinished()) {
                final int restoreCount = canvas.save();
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();

                canvas.translate(scrollX + getPaddingLeft(), Math.min(0, scrollY));
                mEdgeGlowTop.setSize(width, getHeight());
                if (mEdgeGlowTop.draw(canvas)) {
                    ViewCompat.postInvalidateOnAnimation(this);
                }
                canvas.restoreToCount(restoreCount);
            }
            if (!mEdgeGlowBottom.isFinished()) {
                final int restoreCount = canvas.save();
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();
                final int height = getHeight();

                canvas.translate(scrollX - width + getPaddingLeft(),
                        Math.max(getVerticalScrollRange(), scrollY) + height);
                canvas.rotate(180, width, 0);
                mEdgeGlowBottom.setSize(width, height);
                if (mEdgeGlowBottom.draw(canvas)) {
                    ViewCompat.postInvalidateOnAnimation(this);
                }
                canvas.restoreToCount(restoreCount);
            }
        } else {
            //do nothing
        }

    }
}

From source file:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java

@Override
public void draw(Canvas canvas) {
    super.draw(canvas);
    boolean needsInvalidate = false;

    final int overScrollMode = ViewCompat.getOverScrollMode(this);
    if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
            || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null
                    && mAdapter.getCount() > 1)) {
        // BrantApps Change: Various, including the rotation and translation of the edges, padding applied to width not height
        // BrantApps Change: Was:
        /*/*from ww  w  . j  a  v a 2s.  c  o m*/
        if (!mLeftEdge.isFinished()) {
        final int restoreCount = canvas.save();
        final int height = getHeight() - getPaddingTop() - getPaddingBottom();
        final int width = getWidth();
                
        canvas.rotate(270);
        canvas.translate(-height + getPaddingTop(), mFirstOffset * width);
        mLeftEdge.setSize(height, width);
        needsInvalidate |= mLeftEdge.draw(canvas);
        canvas.restoreToCount(restoreCount);
        }
        if (!mRightEdge.isFinished()) {
        final int restoreCount = canvas.save();
        final int width = getWidth();
        final int height = getHeight() - getPaddingTop() - getPaddingBottom();
                
        canvas.rotate(90);
        canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width);
        mRightEdge.setSize(height, width);
        needsInvalidate |= mRightEdge.draw(canvas);
        canvas.restoreToCount(restoreCount);
        }
         */
        if (!mTopEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();
            final int height = getHeight();

            canvas.translate(-getPaddingLeft(), mFirstOffset * height);
            mTopEdge.setSize(width, height);
            needsInvalidate |= mTopEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
        if (!mBottomEdge.isFinished()) {
            final int restoreCount = canvas.save();
            final int width = getWidth() - getPaddingLeft() - getPaddingRight();
            final int height = getHeight();

            canvas.rotate(180);
            canvas.translate(-width + getPaddingLeft(), -(mLastOffset + 1) * height);
            mBottomEdge.setSize(width, height);
            needsInvalidate |= mBottomEdge.draw(canvas);
            canvas.restoreToCount(restoreCount);
        }
    } else {
        mTopEdge.finish();
        mBottomEdge.finish();
    }

    if (needsInvalidate) {
        // Keep animating
        ViewCompat.postInvalidateOnAnimation(this);
    }
}

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

private void drawTickLabels(Canvas c, LongSparseArray<Pair<double[], int[]>> data) {
    final float alphaVariation = MAX_ZOOM_OUT - MIN_ZOOM_OUT;
    final float alpha = MAX_ZOOM_OUT - mCurrentZoom;
    mTickLabelFgPaint.setAlpha((int) ((alpha * 255) / alphaVariation));

    final int size = data.size() - 1;
    final float cx = mGraphArea.left + (mGraphArea.width() / 2);
    for (int i = mItemsOnScreen[1]; i >= mItemsOnScreen[0]; i--) {
        // Update the dynamic layout
        long timestamp = data.keyAt(i);
        final int tickFormat = getTickLabelFormat(timestamp);
        mTickDate.setTime(timestamp);/*from www  .  ja  v a  2  s .  co  m*/
        final String text = mTickFormatter[tickFormat].format(mTickDate).replace(".", "")
                .toUpperCase(Locale.getDefault());
        DynamicSpannableString spannable = mTickTextSpannables[tickFormat].get(text.length());
        if (spannable == null) {
            // If we don't have an spannable for the text length, create a new one
            // that allow to use it now and in the future. Doing this here (on draw)
            // is not the best, but it supposed to only be performed one time per
            // different tick text length
            spannable = createSpannableTick(tickFormat, text);
            mTickTextSpannables[tickFormat].put(text.length(), spannable);
        }
        spannable.update(text);

        DynamicLayout layout = mTickTextLayouts[tickFormat].get(text.length());
        if (layout == null) {
            // Update the layout as well
            layout = new DynamicLayout(spannable, mTickLabelFgPaint, (int) mBarItemWidth,
                    Layout.Alignment.ALIGN_CENTER, 1.0f, 1.0f, false);
            mTickTextLayouts[tickFormat].put(text.length(), layout);
        }

        // Calculate the x position and draw the layout
        final float x = cx + mCurrentOffset - (mBarWidth * (size - i)) - (layout.getWidth() / 2);
        final int restoreCount = c.save();
        c.translate(x, mFooterArea.top + (mFooterArea.height() / 2 - mTickLabelMinHeight / 2));
        layout.draw(c);
        c.restoreToCount(restoreCount);
    }
}

From source file:com.codemx.launcher3.CellLayout.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mIsDragTarget) {
        return;//  w  w  w  .  j  av  a 2s  .  co m
    }

    // When we're large, we are either drawn in a "hover" state (ie when dragging an item to
    // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f)
    // When we're small, we are either drawn normally or in the "accepts drops" state (during
    // a drag). However, we also drag the mini hover background *over* one of those two
    // backgrounds
    if (mBackgroundAlpha > 0.0f) {
        mBackground.draw(canvas);
    }

    final Paint paint = mDragOutlinePaint;
    for (int i = 0; i < mDragOutlines.length; i++) {
        final float alpha = mDragOutlineAlphas[i];
        if (alpha > 0) {
            final Rect r = mDragOutlines[i];
            mTempRect.set(r);
            Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale());
            final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
            paint.setAlpha((int) (alpha + .5f));
            canvas.drawBitmap(b, null, mTempRect, paint);
        }
    }

    if (DEBUG_VISUALIZE_OCCUPIED) {
        int[] pt = new int[2];
        ColorDrawable cd = new ColorDrawable(Color.RED);
        cd.setBounds(0, 0, mCellWidth, mCellHeight);
        for (int i = 0; i < mCountX; i++) {
            for (int j = 0; j < mCountY; j++) {
                if (mOccupied[i][j]) {
                    cellToPoint(i, j, pt);
                    canvas.save();
                    canvas.translate(pt[0], pt[1]);
                    cd.draw(canvas);
                    canvas.restore();
                }
            }
        }
    }

    int previewOffset = FolderIcon.FolderRingAnimator.sPreviewSize;

    // The folder outer / inner ring image(s)
    DeviceProfile grid = mLauncher.getDeviceProfile();
    for (int i = 0; i < mFolderOuterRings.size(); i++) {
        FolderIcon.FolderRingAnimator fra = mFolderOuterRings.get(i);

        Drawable d;
        int width, height;
        cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
        View child = getChildAt(fra.mCellX, fra.mCellY);

        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            // Draw outer ring, if it exists
            if (FolderIcon.HAS_OUTER_RING) {
                d = FolderIcon.FolderRingAnimator.sSharedOuterRingDrawable;
                width = (int) (fra.getOuterRingSize() * getChildrenScale());
                height = width;
                canvas.save();
                canvas.translate(centerX - width / 2, centerY - height / 2);
                d.setBounds(0, 0, width, height);
                d.draw(canvas);
                canvas.restore();
            }

            // Draw inner ring
            d = FolderIcon.FolderRingAnimator.sSharedInnerRingDrawable;
            width = (int) (fra.getInnerRingSize() * getChildrenScale());
            height = width;
            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }

    if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) {
        Drawable d = FolderIcon.sSharedFolderLeaveBehind;
        int width = d.getIntrinsicWidth();
        int height = d.getIntrinsicHeight();

        cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation);
        View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]);
        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }
}

From source file:com.lite.android.launcher3.CellLayout.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mIsDragTarget) {
        return;// w  w w  . ja  v a 2 s.  c o  m
    }

    // When we're large, we are either drawn in a "hover" state (ie when dragging an item to
    // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f)
    // When we're small, we are either drawn normally or in the "accepts drops" state (during
    // a drag). However, we also drag the mini hover background *over* one of those two
    // backgrounds
    if (mBackgroundAlpha > 0.0f) {
        mBackground.draw(canvas);
    }

    final Paint paint = mDragOutlinePaint;
    for (int i = 0; i < mDragOutlines.length; i++) {
        final float alpha = mDragOutlineAlphas[i];
        if (alpha > 0) {
            final Rect r = mDragOutlines[i];
            mTempRect.set(r);
            Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale());
            final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
            paint.setAlpha((int) (alpha + .5f));
            canvas.drawBitmap(b, null, mTempRect, paint);
        }
    }

    if (DEBUG_VISUALIZE_OCCUPIED) {
        int[] pt = new int[2];
        ColorDrawable cd = new ColorDrawable(Color.RED);
        cd.setBounds(0, 0, mCellWidth, mCellHeight);
        for (int i = 0; i < mCountX; i++) {
            for (int j = 0; j < mCountY; j++) {
                if (mOccupied[i][j]) {
                    cellToPoint(i, j, pt);
                    canvas.save();
                    canvas.translate(pt[0], pt[1]);
                    cd.draw(canvas);
                    canvas.restore();
                }
            }
        }
    }

    int previewOffset = FolderRingAnimator.sPreviewSize;

    // The folder outer / inner ring image(s)
    DeviceProfile grid = mLauncher.getDeviceProfile();
    for (int i = 0; i < mFolderOuterRings.size(); i++) {
        FolderRingAnimator fra = mFolderOuterRings.get(i);

        Drawable d;
        int width, height;
        cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
        View child = getChildAt(fra.mCellX, fra.mCellY);

        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            // Draw outer ring, if it exists
            if (FolderIcon.HAS_OUTER_RING) {
                d = FolderRingAnimator.sSharedOuterRingDrawable;
                width = (int) (fra.getOuterRingSize() * getChildrenScale());
                height = width;
                canvas.save();
                canvas.translate(centerX - width / 2, centerY - height / 2);
                d.setBounds(0, 0, width, height);
                d.draw(canvas);
                canvas.restore();
            }

            // Draw inner ring
            d = FolderRingAnimator.sSharedInnerRingDrawable;
            if (d != null) {
                width = (int) (fra.getInnerRingSize() * getChildrenScale());
                height = width;
                canvas.save();
                canvas.translate(centerX - width / 2, centerY - width / 2);
                d.setBounds(0, 0, width, height);
                d.draw(canvas);
                canvas.restore();
            }
        }
    }

    if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) {
        Drawable d = FolderIcon.sSharedFolderLeaveBehind;
        int width = d.getIntrinsicWidth();
        int height = d.getIntrinsicHeight();

        cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation);
        View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]);
        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }
}

From source file:com.android.launcher3.CellLayout.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mIsDragTarget) {
        return;/*from  w  ww .  j  a  v  a 2  s .co m*/
    }

    // When we're large, we are either drawn in a "hover" state (ie when dragging an item to
    // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f)
    // When we're small, we are either drawn normally or in the "accepts drops" state (during
    // a drag). However, we also drag the mini hover background *over* one of those two
    // backgrounds
    if (mBackgroundAlpha > 0.0f) {
        mBackground.draw(canvas);
    }

    final Paint paint = mDragOutlinePaint;
    for (int i = 0; i < mDragOutlines.length; i++) {
        final float alpha = mDragOutlineAlphas[i];
        if (alpha > 0) {
            final Rect r = mDragOutlines[i];
            mTempRect.set(r);
            Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale());
            final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
            paint.setAlpha((int) (alpha + .5f));
            canvas.drawBitmap(b, null, mTempRect, paint);
        }
    }

    if (DEBUG_VISUALIZE_OCCUPIED) {
        int[] pt = new int[2];
        ColorDrawable cd = new ColorDrawable(Color.RED);
        cd.setBounds(0, 0, mCellWidth, mCellHeight);
        for (int i = 0; i < mCountX; i++) {
            for (int j = 0; j < mCountY; j++) {
                if (mOccupied[i][j]) {
                    cellToPoint(i, j, pt);
                    canvas.save();
                    canvas.translate(pt[0], pt[1]);
                    cd.draw(canvas);
                    canvas.restore();
                }
            }
        }
    }

    int previewOffset = FolderRingAnimator.sPreviewSize;

    // The folder outer / inner ring image(s)
    DeviceProfile grid = mLauncher.getDeviceProfile();
    for (int i = 0; i < mFolderOuterRings.size(); i++) {
        FolderRingAnimator fra = mFolderOuterRings.get(i);

        Drawable d;
        int width, height;
        cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
        View child = getChildAt(fra.mCellX, fra.mCellY);

        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            // Draw outer ring, if it exists
            if (FolderIcon.HAS_OUTER_RING) {
                d = FolderRingAnimator.sSharedOuterRingDrawable;
                width = (int) (fra.getOuterRingSize() * getChildrenScale());
                height = width;
                canvas.save();
                canvas.translate(centerX - width / 2, centerY - height / 2);
                d.setBounds(0, 0, width, height);
                d.draw(canvas);
                canvas.restore();
            }

            // Draw inner ring
            d = FolderRingAnimator.sSharedInnerRingDrawable;
            width = (int) (fra.getInnerRingSize() * getChildrenScale());
            height = width;
            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }

    if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) {
        Drawable d = FolderIcon.sSharedFolderLeaveBehind;
        int width = d.getIntrinsicWidth();
        int height = d.getIntrinsicHeight();

        cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation);
        View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]);
        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }
}

From source file:cc.flydev.launcher.Workspace.java

/**
 * Draw the View v into the given Canvas.
 *
 * @param v the view to draw//from   ww  w.  j  a  v  a 2  s.  c  o m
 * @param destCanvas the canvas to draw on
 * @param padding the horizontal and vertical padding to use when drawing
 */
private void drawDragView(View v, Canvas destCanvas, int padding, boolean pruneToDrawable) {
    final Rect clipRect = mTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView && pruneToDrawable) {
        Drawable d = ((TextView) v).getCompoundDrawables()[1];
        clipRect.set(0, 0, d.getIntrinsicWidth() + padding, d.getIntrinsicHeight() + padding);
        destCanvas.translate(padding / 2, padding / 2);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so we need to
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        } else if (v instanceof BubbleTextView) {
            final BubbleTextView tv = (BubbleTextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V
                    + tv.getLayout().getLineTop(0);
        } else if (v instanceof TextView) {
            final TextView tv = (TextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - tv.getCompoundDrawablePadding()
                    + tv.getLayout().getLineTop(0);
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}

From source file:com.jjoe64.graphview.GridLabelRenderer.java

/**
 * draws the horizontal steps/*from   ww w  .j  a va2  s .c om*/
 * vertical lines and horizontal labels
 *
 * @param canvas canvas
 */
protected void drawHorizontalSteps(Canvas canvas) {
    // draw horizontal steps (vertical lines and horizontal labels)
    mPaintLabel.setColor(getHorizontalLabelsColor());
    int i = 0;
    for (Map.Entry<Integer, Double> e : mStepsHorizontal.entrySet()) {
        // draw line
        if (mStyles.highlightZeroLines) {
            if (e.getValue() == 0d) {
                mPaintLine.setStrokeWidth(5);
            } else {
                mPaintLine.setStrokeWidth(0);
            }
        }
        if (mStyles.gridStyle.drawVertical()) {
            canvas.drawLine(mGraphView.getGraphContentLeft() + e.getKey(), mGraphView.getGraphContentTop(),
                    mGraphView.getGraphContentLeft() + e.getKey(),
                    mGraphView.getGraphContentTop() + mGraphView.getGraphContentHeight(), mPaintLine);
        }

        // draw label
        if (isHorizontalLabelsVisible()) {
            if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
                if (mStyles.horizontalLabelsAngle < 90f) {
                    mPaintLabel.setTextAlign((Paint.Align.RIGHT));
                } else if (mStyles.horizontalLabelsAngle <= 180f) {
                    mPaintLabel.setTextAlign((Paint.Align.LEFT));
                }
            } else {
                mPaintLabel.setTextAlign(Paint.Align.CENTER);
                if (i == mStepsHorizontal.size() - 1)
                    mPaintLabel.setTextAlign(Paint.Align.RIGHT);
                if (i == 0)
                    mPaintLabel.setTextAlign(Paint.Align.LEFT);
            }

            // multiline labels
            String label = mLabelFormatter.formatLabel(e.getValue(), true);
            if (label == null) {
                label = "";
            }
            String[] lines = label.split("\n");

            // If labels are angled, calculate adjustment to line them up with the grid
            int labelWidthAdj = 0;
            if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
                Rect textBounds = new Rect();
                mPaintLabel.getTextBounds(lines[0], 0, lines[0].length(), textBounds);
                labelWidthAdj = (int) Math
                        .abs(textBounds.width() * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle)));
            }
            for (int li = 0; li < lines.length; li++) {
                // for the last line y = height
                float y = (canvas.getHeight() - mStyles.padding - getHorizontalAxisTitleHeight())
                        - (lines.length - li - 1) * getTextSize() * 1.1f + mStyles.labelsSpace;
                float x = mGraphView.getGraphContentLeft() + e.getKey();
                if (mStyles.horizontalLabelsAngle > 0 && mStyles.horizontalLabelsAngle < 90f) {
                    canvas.save();
                    canvas.rotate(mStyles.horizontalLabelsAngle, x + labelWidthAdj, y);
                    canvas.drawText(lines[li], x + labelWidthAdj, y, mPaintLabel);
                    canvas.restore();
                } else if (mStyles.horizontalLabelsAngle > 0 && mStyles.horizontalLabelsAngle <= 180f) {
                    canvas.save();
                    canvas.rotate(mStyles.horizontalLabelsAngle - 180f, x - labelWidthAdj, y);
                    canvas.drawText(lines[li], x - labelWidthAdj, y, mPaintLabel);
                    canvas.restore();
                } else {
                    canvas.drawText(lines[li], x, y, mPaintLabel);
                }
            }
        }
        i++;
    }
}

From source file:com.aidy.launcher3.ui.workspace.Workspace.java

/**
 * Draw the View v into the given Canvas.
 * //  www  . j a v a2s  .  co  m
 * @param v
 *            the view to draw
 * @param destCanvas
 *            the canvas to draw on
 * @param padding
 *            the horizontal and vertical padding to use when drawing
 */
private void drawDragView(View v, Canvas destCanvas, int padding, boolean pruneToDrawable) {
    final Rect clipRect = mTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView && pruneToDrawable) {
        Drawable d = ((TextView) v).getCompoundDrawables()[1];
        clipRect.set(0, 0, d.getIntrinsicWidth() + padding, d.getIntrinsicHeight() + padding);
        destCanvas.translate(padding / 2, padding / 2);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so
            // we need to
            // hide the text completely (which can't be achieved by
            // clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        } else if (v instanceof BubbleTextView) {
            final BubbleTextView tv = (BubbleTextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V
                    + tv.getLayout().getLineTop(0);
        } else if (v instanceof TextView) {
            final TextView tv = (TextView) v;
            clipRect.bottom = tv.getExtendedPaddingTop() - tv.getCompoundDrawablePadding()
                    + tv.getLayout().getLineTop(0);
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}

From source file:com.lovely3x.eavlibrary.EasyAdapterView.java

/**
 * overscroll/* w w w  .j a v a  2  s  . co  m*/
 *
 * @param canvas
 */
protected void drawOverScrollEffect(Canvas canvas) {
    final int scrollY = getScrollY();
    final int scrollX = getScrollX();

    final int width;
    final int height;
    final int translateX;
    final int translateY;

    width = getWidth();
    height = getHeight();

    translateX = 0;
    translateY = 0;

    if (mTopEdgeEffect != null) {//
        if (!mTopEdgeEffect.isFinished()) {
            final int restoreCount = canvas.save();
            canvas.clipRect(translateX, translateY, translateX + width,
                    translateY + mTopEdgeEffect.getMaxHeight());
            final int edgeY = Math.min(0, scrollY) + translateY;
            canvas.translate(translateX, edgeY);
            mTopEdgeEffect.setSize(width, height);
            if (mTopEdgeEffect.draw(canvas)) {
                invalidateTopGlow();
            }
            canvas.restoreToCount(restoreCount);
        }
    }

    if (mBottomEdgeEffect != null) {//
        if (!mBottomEdgeEffect.isFinished()) {
            final int restoreCount = canvas.save();
            canvas.clipRect(translateX, translateY + height - mBottomEdgeEffect.getMaxHeight(),
                    translateX + width, translateY + height);
            final int edgeX = -width + translateX;
            final int edgeY = Math.max(getHeight(), scrollY);
            canvas.translate(edgeX, edgeY);
            canvas.rotate(180, width, 0);
            mBottomEdgeEffect.setSize(width, height);
            if (mBottomEdgeEffect.draw(canvas)) {
                invalidateBottomGlow();
            }
            canvas.restoreToCount(restoreCount);
        }
    }

    if (mLeftEdgeEffect != null) {//
        if (!mLeftEdgeEffect.isFinished()) {
            canvas.clipRect(translateX, translateY, translateX + mLeftEdgeEffect.getMaxHeight(),
                    translateY + height);
            final int restoreCount = canvas.save();
            canvas.translate(-width, getHeight() - getWidth());//?
            canvas.rotate(270, width, 0);//
            mLeftEdgeEffect.setSize(height, width);//?
            if (mLeftEdgeEffect.draw(canvas)) {
                invalidateLeftGlow();
            }
            canvas.restoreToCount(restoreCount);
        }
    }

    if (mRightEdgeEffect != null) {//?
        if (!mRightEdgeEffect.isFinished()) {
            //     canvas.clipRect(translateX, width - mRightEdgeEffect.getMaxHeight(), width, translateY + height);
            final int restoreCount = canvas.save();
            canvas.translate(0, getWidth());//?
            canvas.rotate(-270, width, 0);//
            mRightEdgeEffect.setSize(height, width);//?
            if (mRightEdgeEffect.draw(canvas)) {
                invalidateRightGlow();
            }
            canvas.restoreToCount(restoreCount);
        }
    }
}