Example usage for android.graphics Canvas scale

List of usage examples for android.graphics Canvas scale

Introduction

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

Prototype

public final void scale(float sx, float sy, float px, float py) 

Source Link

Document

Preconcat the current matrix with the specified scale.

Usage

From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java

private void drawSun(Canvas canvas, float pct) {

    // Draw the dots
    canvas.drawCircle(mBezier1x, mBezier1y, mDotRadius, mDotPaint);
    canvas.drawCircle(mBezier4x, mBezier4y, mDotRadius, mDotPaint);

    // calculate the center point of the sun image
    float x = bezierInterpolation(pct, mBezier1x, mBezier2x, mBezier3x, mBezier4x);
    float y = bezierInterpolation(pct, mBezier1y, mBezier2y, mBezier3y, mBezier4y);

    Rect sunBounds = mSunImage.getBounds();

    x -= sunBounds.width() / 2;/*from  w  w  w. ja va2  s.c om*/
    y -= sunBounds.height() / 2;

    // if we are in rtl, we still want to show the image normally
    // so flip it back
    canvas.translate(x, y);
    if (mIsRtl) {
        canvas.save();
        canvas.scale(-1, 1, sunBounds.centerX(), sunBounds.centerY());
    }
    // draw the sun image
    mSunImage.draw(canvas);
    // restore the flip again
    if (mIsRtl) {
        canvas.restore();
    }
    canvas.translate(-x, -y);

}

From source file:com.skumar.flexibleciruclarseekbar.CircularSeekBar.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mClockwise) {
        canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
    }//from   ww w.j a  va2s . c  om

    // Set for the gradient color
    if (hasGradientColor)
        setShader();

    // Draw the arcs
    final int arcStart = mStartAngle + mAngleOffset + mRotation;
    final int arcSweep = mSweepAngle;
    canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint);

    // Draw the needle scale
    if (drawMarkings) {
        drawNeedleMarkings(canvas);

        // Draw dot markers
        if (hasDotMarkers)
            drawDotMarker(canvas);
    }

    if (mEnabled) {
        // Draw the thumb nail
        canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos);
        mThumb.draw(canvas);
        if (hasPopupIn) {
            // Draw the popup
            canvas.translate(-mThumb.getIntrinsicWidth() / 2, -mThumb.getIntrinsicHeight() - mHeightForPopup);
            mPopup.draw(canvas);
        }
    }
}

From source file:com.lamcreations.scaffold.common.utils.CollapsingTextHelper.java

public void draw(Canvas canvas) {
    int saveCount = canvas.save();
    if (this.mTextToDraw != null) {
        boolean isRtl = this.mIsRtl;
        float x = isRtl ? this.mCurrentRight : this.mCurrentLeft;
        float y = this.mCurrentTop;
        boolean drawTexture = this.mUseTexture && this.mExpandedTitleTexture != null;
        this.mTextPaint.setTextSize(this.mCurrentTextSize);
        float ascent;
        if (drawTexture) {
            ascent = this.mTextureAscent * this.mScale;
        } else {//  ww w. jav a2 s .c om
            ascent = this.mTextPaint.ascent() * this.mScale;
        }

        if (drawTexture) {
            y += ascent;
        }

        if (this.mScale != 1.0F) {
            canvas.scale(this.mScale, this.mScale, x, y);
        }

        if (isRtl) {
            x -= this.mTextWidth;
        }

        if (drawTexture) {
            canvas.drawBitmap(this.mExpandedTitleTexture, x, y, this.mTexturePaint);
        } else {
            canvas.drawText(this.mTextToDraw, 0, this.mTextToDraw.length(), x, y, this.mTextPaint);
        }
    }

    canvas.restoreToCount(saveCount);
}

From source file:com.cocosw.accessory.views.layout.CollapsingTitleLayout.java

@Override
public void draw(Canvas canvas) {
    final int saveCount = canvas.save();

    final int toolbarHeight = mToolbar.getHeight();
    canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, mScrollOffset));

    // Now call super and let it draw the background, etc
    super.draw(canvas);

    if (mTitleToDraw != null) {
        float x = mTextLeft;
        float y = mTextTop;

        if (!mUseTexture) {
            // If we're not drawing a texture, we need to properly offset the text
            x -= mDrawnTextBounds.left;/*from ww w.j a  v  a2 s . com*/
            y -= mDrawnTextBounds.top;
        }

        if (DEBUG_DRAW) {
            // Just a debug tool, which drawn a Magneta rect in the text bounds
            canvas.drawRect(mTextLeft, mTextTop, mTextRight, mTextTop + mDrawnTextBounds.height(),
                    DEBUG_DRAW_PAINT);
        }

        if (mScale != 1f) {
            canvas.scale(mScale, mScale, x, y);
        }

        if (mUseTexture && mExpandedTitleTexture != null) {
            // If we should use a texture, draw it instead of text
            canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint);
        } else {
            canvas.drawText(mTitleToDraw, x, y, mTextPaint);
        }
    }

    canvas.restoreToCount(saveCount);
}

From source file:com.ameron32.apps.tapnotes._trial.ui.CollapsingTitleLayout.java

@Override
public void draw(Canvas canvas) {
    final int saveCount = canvas.save();

    final int toolbarHeight = mToolbar.getHeight();
    canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, mScrollOffset));

    // Now call super and let it draw the background, etc
    super.draw(canvas);

    if (mTitleToDraw != null) {
        float x = mTextLeft;
        float y = mTextTop;

        final float ascent = mTextPaint.ascent() * mScale;
        final float descent = mTextPaint.descent() * mScale;
        final float h = descent - ascent;

        if (DEBUG_DRAW) {
            // Just a debug tool, which drawn a Magneta rect in the text bounds
            canvas.drawRect(mTextLeft, y - h + descent, mTextRight, y + descent, DEBUG_DRAW_PAINT);
        }/* w  ww.  j a  va  2s.c om*/

        if (mUseTexture) {
            y = y - h + descent;
        }

        if (mScale != 1f) {
            canvas.scale(mScale, mScale, x, y);
        }

        if (mUseTexture && mExpandedTitleTexture != null) {
            // If we should use a texture, draw it instead of text
            canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint);
        } else {
            canvas.drawText(mTitleToDraw, x, y, mTextPaint);
        }
    }

    canvas.restoreToCount(saveCount);
}

From source file:au.com.zacher.popularmovies.activity.layout.CollapsingTitleLayout.java

@Override
public void draw(@NonNull Canvas canvas) {
    final int saveCount = canvas.save();

    final int toolbarHeight = this.mToolbar.getHeight();
    canvas.clipRect(0, 0, canvas.getWidth(),
            interpolate(canvas.getHeight(), toolbarHeight, this.mScrollOffset));

    // Now call super and let it draw the background, etc
    super.draw(canvas);

    if (this.mTitleToDraw != null) {
        float x = this.mTextLeft;
        float y = this.mTextTop;

        final float ascent = this.mTextPaint.ascent() * this.mScale;
        final float descent = this.mTextPaint.descent() * this.mScale;
        final float h = descent - ascent;

        if (DEBUG_DRAW) {
            // Just a debug tool, which drawn a Magneta rect in the text bounds
            canvas.drawRect(this.mTextLeft, y - h + descent, this.mTextRight, y + descent, DEBUG_DRAW_PAINT);
        }/*  ww w. jav a 2s  . c o  m*/

        if (this.mUseTexture) {
            y = y - h + descent;
        }

        if (this.mScale != 1f) {
            canvas.scale(this.mScale, this.mScale, x, y);
        }

        if (this.mUseTexture && this.mExpandedTitleTexture != null) {
            // If we should use a texture, draw it instead of text
            canvas.drawBitmap(this.mExpandedTitleTexture, x, y, this.mTexturePaint);
        } else {
            canvas.drawText(this.mTitleToDraw, x, y, this.mTextPaint);
        }
    }

    canvas.restoreToCount(saveCount);
}

From source file:com.aigo.kt03airdemo.ui.view.ResideLayout.java

@Override
protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.ALL_SAVE_FLAG);

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately be covered.
        canvas.scale(1.2f - 0.2f * mSlideOffset, 1.2f - 0.2f * mSlideOffset, child.getRight(), getHeight() / 2);
    } else {/* w  w w  .jav  a 2s .co  m*/
        assert mSlideableView != null;
        canvas.scale(1 - mSlideOffset / 3, 1 - mSlideOffset / 3, mSlideableView.getLeft(), getHeight() / 2);
        ViewCompat.setRotationY(child, -10 * mSlideOffset);
    }

    if (!lp.slideable && mSlideOffset == 0) {
        result = true;
    } else {
        if (Build.VERSION.SDK_INT >= 11) { // HC
            result = super.drawChild(canvas, child, drawingTime);
        } else {
            if (lp.dimWhenOffset && mSlideOffset > 0) {
                if (!child.isDrawingCacheEnabled()) {
                    child.setDrawingCacheEnabled(true);
                }
                final Bitmap cache = child.getDrawingCache();
                if (cache != null) {
                    canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                    result = false;
                } else {
                    Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache");
                    result = super.drawChild(canvas, child, drawingTime);
                }
            } else {
                if (child.isDrawingCacheEnabled()) {
                    child.setDrawingCacheEnabled(false);
                }
                result = super.drawChild(canvas, child, drawingTime);
            }
        }
    }

    canvas.restoreToCount(save);

    return result;
}

From source file:com.shouhuan.view.ResideLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.ALL_SAVE_FLAG);

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately
        // be covered.
        canvas.scale(1.2f - 0.2f * mSlideOffset, 1.2f - 0.2f * mSlideOffset, child.getRight(), getHeight() / 2);
    } else {//from   www . j a v a2  s.com
        assert mSlideableView != null;
        canvas.scale(1 - mSlideOffset / 3, 1 - mSlideOffset / 3, mSlideableView.getLeft(), getHeight() / 2);
        // ViewCompat.setRotationY(child, -10 * mSlideOffset);
    }

    if (!lp.slideable && mSlideOffset == 0) {
        result = true;
    } else {
        if (Build.VERSION.SDK_INT >= 11) { // HC
            result = super.drawChild(canvas, child, drawingTime);
        } else {
            if (lp.dimWhenOffset && mSlideOffset > 0) {
                if (!child.isDrawingCacheEnabled()) {
                    child.setDrawingCacheEnabled(true);
                }
                final Bitmap cache = child.getDrawingCache();
                if (cache != null) {
                    canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                    result = false;
                } else {
                    Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache");
                    result = super.drawChild(canvas, child, drawingTime);
                }
            } else {
                if (child.isDrawingCacheEnabled()) {
                    child.setDrawingCacheEnabled(false);
                }
                result = super.drawChild(canvas, child, drawingTime);
            }
        }
    }

    canvas.restoreToCount(save);

    return result;
}

From source file:com.bright.cloudutils.view.ResideLayout.java

@Override
protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    boolean result;
    final int save = canvas.save(Canvas.ALL_SAVE_FLAG);

    if (mCanSlide && !lp.slideable && mSlideableView != null) {
        // Clip against the slider; no sense drawing what will immediately
        // be covered.
        canvas.scale(1.2f - 0.2f * mSlideOffset, 1.2f - 0.2f * mSlideOffset, child.getRight(), getHeight() / 2);
    } else {/*from   w ww . j a va  2 s . c  o  m*/
        assert mSlideableView != null;
        canvas.scale(1 - mSlideOffset / 3, 1 - mSlideOffset / 3, mSlideableView.getLeft(), getHeight() / 2);
        ViewCompat.setRotationY(child, -10 * mSlideOffset);
    }

    if (!lp.slideable && mSlideOffset == 0) {
        result = true;
    } else {
        if (Build.VERSION.SDK_INT >= 11) { // HC
            result = super.drawChild(canvas, child, drawingTime);
        } else {
            if (lp.dimWhenOffset && mSlideOffset > 0) {
                if (!child.isDrawingCacheEnabled()) {
                    child.setDrawingCacheEnabled(true);
                }
                final Bitmap cache = child.getDrawingCache();
                if (cache != null) {
                    canvas.drawBitmap(cache, child.getLeft(), child.getTop(), lp.dimPaint);
                    result = false;
                } else {
                    Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache");
                    result = super.drawChild(canvas, child, drawingTime);
                }
            } else {
                if (child.isDrawingCacheEnabled()) {
                    child.setDrawingCacheEnabled(false);
                }
                result = super.drawChild(canvas, child, drawingTime);
            }
        }
    }

    canvas.restoreToCount(save);

    return result;
}

From source file:org.buffer.android.buffertextinputlayout.util.CollapsingTextHelper.java

public void draw(Canvas canvas) {
    final int saveCount = canvas.save();
    if (mTextToDraw != null && mDrawTitle) {
        float x = mCurrentDrawX;
        float y = mCurrentDrawY;
        final boolean drawTexture = mUseTexture && mExpandedTitleTexture != null;
        final float ascent;
        final float descent;
        if (drawTexture) {
            ascent = mTextureAscent * mScale;
            descent = mTextureDescent * mScale;
        } else {/* w  w w .  j  a  v a  2 s  .c o m*/
            ascent = mTextPaint.ascent() * mScale;
            descent = mTextPaint.descent() * mScale;
        }
        if (DEBUG_DRAW) {
            // Just a debug tool, which drawn a magenta rect in the text bounds
            canvas.drawRect(mCurrentBounds.left, y + ascent, mCurrentBounds.right, y + descent,
                    DEBUG_DRAW_PAINT);
        }
        if (drawTexture) {
            y += ascent;
        }
        if (mScale != 1f) {
            canvas.scale(mScale, mScale, x, y);
        }
        if (drawTexture) {
            // If we should use a texture, draw it instead of text
            canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint);
        } else {
            canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint);
        }
    }
    canvas.restoreToCount(saveCount);
}