Java Code Examples for android.graphics.Canvas#scale()

The following examples show how to use android.graphics.Canvas#scale() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlurUtils.java    From letv with Apache License 2.0 6 votes vote down vote up
@SuppressLint({"NewApi"})
public static void blur_3(Context context, Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    Display d = ((Activity) context).getWindowManager().getDefaultDisplay();
    Bitmap overlay = Bitmap.createBitmap((int) (((float) d.getWidth()) / 1.0f), (int) (((float) d.getHeight()) / 1.0f), Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.scale(1.0f / 1.0f, 1.0f / 1.0f);
    Paint paint = new Paint();
    paint.setFlags(2);
    canvas.drawBitmap(bkg, 0.0f, 0.0f, paint);
    overlay = FastBlur.doBlur(overlay, (int) 100.0f, true);
    if (LetvUtils.getSDKVersion() >= 16) {
        view.setBackground(new BitmapDrawable(context.getResources(), overlay));
    } else {
        view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
    }
}
 
Example 2
Source File: ActionBarDrawerToggle.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    copyBounds(mTmpRect);
    canvas.save();

    // Layout direction must be obtained from the activity.
    final boolean isLayoutRTL = ViewCompat.getLayoutDirection(
            mActivity.getWindow().getDecorView()) == ViewCompat.LAYOUT_DIRECTION_RTL;
    final int flipRtl = isLayoutRTL ? -1 : 1;
    final int width = mTmpRect.width();
    canvas.translate(-mOffset * width * mPosition * flipRtl, 0);

    // Force auto-mirroring if it's not supported by the platform.
    if (isLayoutRTL && !mHasMirroring) {
        canvas.translate(width, 0);
        canvas.scale(-1, 1);
    }

    super.draw(canvas);
    canvas.restore();
}
 
Example 3
Source File: Hasher.java    From crystal-preloaders with Apache License 2.0 6 votes vote down vote up
@Override
public void onDraw(Canvas canvas, Paint fgPaint, Paint bgPaint, float width, float height, float cx, float cy) {
    //canvas.drawColor(Color.YELLOW);

    fgPaint.setStyle(Paint.Style.FILL);
    fgPaint.setStrokeWidth(3f);
    fgPaint.setAntiAlias(true);

    canvas.save();
    canvas.scale(0.75f, 0.75f, cx, cy);
    canvas.rotate(degree, cx, cy);

    canvas.drawPath(path, fgPaint);
    canvas.restore();

    canvas.drawCircle(cx, cx, factor + factor - factor / 8, bgPaint);
    canvas.drawCircle(cx, cx, factor + factor - factor / 8 - 4, fgPaint);
    canvas.drawCircle(cx, cx, factor / 3, bgPaint);

}
 
Example 4
Source File: GeoGebraLogoBox.java    From FlexibleRichTextView with Apache License 2.0 6 votes vote down vote up
public void draw(Canvas g2, float x, float y) {
	g2.save();
	Paint st = AjLatexMath.getPaint();
	int c = st.getColor();
	Style s = st.getStyle();
	float w = st.getStrokeWidth();

	g2.translate(x + 0.25f * height / 2.15f, y - 1.75f / 2.15f * height);
	st.setColor(gray);
	st.setStrokeWidth(3.79999995f);
	g2.scale(0.05f * height / 2.15f, 0.05f * height / 2.15f);
	g2.rotate((float) Math.toDegrees((-26 * Math.PI / 180)), 20.5f, 17.5f);
	g2.drawArc(new RectF(0f, 0f, 43f, 32f), 0f, 360f, false, st);
	g2.rotate((float) Math.toDegrees((26 * Math.PI / 180)), 20.5f, 17.5f);
	st.setStyle(Style.STROKE);
	drawCircle(st, g2, 16f, -5f);
	drawCircle(st, g2, -1f, 7f);
	drawCircle(st, g2, 5f, 28f);
	drawCircle(st, g2, 27f, 24f);
	drawCircle(st, g2, 36f, 3f);

	st.setColor(c);
	st.setStyle(s);
	st.setStrokeWidth(w);
	g2.restore();
}
 
Example 5
Source File: FastScroller.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void drawVerticalScrollbar(Canvas canvas) {
    int viewWidth = mRecyclerViewWidth;

    int left = viewWidth - mVerticalThumbWidth;
    int top = mVerticalThumbCenterY - mVerticalThumbHeight / 2;
    mVerticalThumbDrawable.setBounds(0, 0, mVerticalThumbWidth, mVerticalThumbHeight);
    mVerticalTrackDrawable
        .setBounds(0, 0, mVerticalTrackWidth, mRecyclerViewHeight);

    if (isLayoutRTL()) {
        mVerticalTrackDrawable.draw(canvas);
        canvas.translate(mVerticalThumbWidth, top);
        canvas.scale(-1, 1);
        mVerticalThumbDrawable.draw(canvas);
        canvas.scale(1, 1);
        canvas.translate(-mVerticalThumbWidth, -top);
    } else {
        canvas.translate(left, 0);
        mVerticalTrackDrawable.draw(canvas);
        canvas.translate(0, top);
        mVerticalThumbDrawable.draw(canvas);
        canvas.translate(-left, -top);
    }
}
 
Example 6
Source File: BallScaleIndicator.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas, Paint paint) {
    float circleSpacing=4;
    paint.setAlpha(alpha);
    canvas.scale(scale,scale,getWidth()/2,getHeight()/2);
    paint.setAlpha(alpha);
    canvas.drawCircle(getWidth()/2,getHeight()/2,getWidth()/2-circleSpacing,paint);
}
 
Example 7
Source File: RearrangeableLayout.java    From RearrangeableLayout with MIT License 5 votes vote down vote up
@Override
protected void dispatchDraw(Canvas canvas) {
    if (mSelectedChild != null) {
        mSelectedChild.setVisibility(View.INVISIBLE);
    }
    super.dispatchDraw(canvas);

    if (mSelectedChild != null) {
        Rect rect = new Rect();
        mSelectedChild.getHitRect(rect);

        int restorePoint = canvas.save();
        canvas.scale(mSelectionZoom, mSelectionZoom, rect.centerX(), rect.centerY());
        canvas.drawRect(rect, mOutlinePaint);

        mSelectedChild.setDrawingCacheEnabled(true);
        Bitmap child = mSelectedChild.getDrawingCache();
        if (child != null) {
            LayoutParams lp = (LayoutParams) mSelectedChild.getLayoutParams();
            canvas.drawBitmap(child, lp.left, lp.top, mSelectionPaint);
        } else {
            Log.d(TAG, "drawingCache not found! Maybe because of hardware acceleration");
            mSelectedChild.draw(canvas);
        }
        canvas.restoreToCount(restorePoint);
    }
}
 
Example 8
Source File: SmoothProgressDrawable.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas) {
  mBounds = getBounds();
  canvas.clipRect(mBounds);

  int boundsWidth = mBounds.width();

  if (mReversed) {
    canvas.translate(boundsWidth, 0);
    canvas.scale(-1, 1);
  }

  drawStrokes(canvas);
}
 
Example 9
Source File: DragView.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    @SuppressWarnings("all") // suppress dead code warning
    final boolean debug = false;
    if (debug) {
        Paint p = new Paint();
        p.setStyle(Paint.Style.FILL);
        p.setColor(0x66ffffff);
        canvas.drawRect(0, 0, getWidth(), getHeight(), p);
    }

    mHasDrawn = true;
    boolean crossFade = mCrossFadeProgress > 0 && mCrossFadeBitmap != null;
    if (crossFade) {
        int alpha = crossFade ? (int) (255 * (1 - mCrossFadeProgress)) : 255;
        mPaint.setAlpha(alpha);
    }
    canvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint);
    if (crossFade) {
        mPaint.setAlpha((int) (255 * mCrossFadeProgress));
        canvas.save();
        float sX = (mBitmap.getWidth() * 1.0f) / mCrossFadeBitmap.getWidth();
        float sY = (mBitmap.getHeight() * 1.0f) / mCrossFadeBitmap.getHeight();
        canvas.scale(sX, sY);
        canvas.drawBitmap(mCrossFadeBitmap, 0.0f, 0.0f, mPaint);
        canvas.restore();
    }
}
 
Example 10
Source File: BlurTransformation.java    From TestChat with Apache License 2.0 5 votes vote down vote up
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
        Bitmap source = resource.get();

        int width = source.getWidth();
        int height = source.getHeight();
        int scaledWidth = width / mSampling;
        int scaledHeight = height / mSampling;

        Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
        if (bitmap == null) {
                bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
        }

        Canvas canvas = new Canvas(bitmap);
        canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
        Paint paint = new Paint();
        paint.setFlags(Paint.FILTER_BITMAP_FLAG);
        canvas.drawBitmap(source, 0, 0, paint);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                try {
                        bitmap = RSBlur.blur(mContext, bitmap, mRadius);
                } catch (RSRuntimeException e) {
                        bitmap = FastBlur.blur(bitmap, mRadius, true);
                }
        } else {
                bitmap = FastBlur.blur(bitmap, mRadius, true);
        }

        return BitmapResource.obtain(bitmap, mBitmapPool);
}
 
Example 11
Source File: Glide4Loader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
public static Bitmap blur(Bitmap source,int mRadius,boolean recycleOriginal){
    int mSampling = 1;
    int width = source.getWidth();
    int height = source.getHeight();
    int scaledWidth = width / mSampling;
    int scaledHeight = height / mSampling;
    Bitmap bitmap
     = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
        Paint paint = new Paint();
        paint.setFlags(Paint.FILTER_BITMAP_FLAG);
        canvas.drawBitmap(source, 0, 0, paint);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        try {
            bitmap = RSBlur.blur(ImageLoader.context, bitmap, mRadius);
        } catch (RSRuntimeException e) {
            bitmap = FastBlur.blur(bitmap, mRadius, true);
        }
    } else {
        bitmap = FastBlur.blur(bitmap, mRadius, true);
    }
    if(recycleOriginal){
        source.recycle();
    }

    return bitmap;
}
 
Example 12
Source File: ImageViewWithZoom.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	// Set the image bounderies
	canvas.save();
	canvas.scale(scaleFactor, scaleFactor);
	image.draw(canvas);
	canvas.restore();
}
 
Example 13
Source File: GifMovieView.java    From AnimeTaste with MIT License 5 votes vote down vote up
/**
 * Draw current GIF frame
 */
private void drawMovieFrame(Canvas canvas) {

	mMovie.setTime(mCurrentAnimationTime);

	canvas.save(Canvas.MATRIX_SAVE_FLAG);
	canvas.scale(mScale, mScale);
	mMovie.draw(canvas, mLeft / mScale, mTop / mScale);
	canvas.restore();
}
 
Example 14
Source File: LottieDrawable.java    From lottie-android with Apache License 2.0 4 votes vote down vote up
private void drawWithOriginalAspectRatio(Canvas canvas) {
  if (compositionLayer == null) {
    return;
  }

  float scale = this.scale;
  float extraScale = 1f;
  float maxScale = getMaxScale(canvas);
  if (scale > maxScale) {
    scale = maxScale;
    extraScale = this.scale / scale;
  }

  int saveCount = -1;
  if (extraScale > 1) {
    // This is a bit tricky...
    // We can't draw on a canvas larger than ViewConfiguration.get(context).getScaledMaximumDrawingCacheSize()
    // which works out to be roughly the size of the screen because Android can't generate a
    // bitmap large enough to render to.
    // As a result, we cap the scale such that it will never be wider/taller than the screen
    // and then only render in the top left corner of the canvas. We then use extraScale
    // to scale up the rest of the scale. However, since we rendered the animation to the top
    // left corner, we need to scale up and translate the canvas to zoom in on the top left
    // corner.
    saveCount = canvas.save();
    float halfWidth = composition.getBounds().width() / 2f;
    float halfHeight = composition.getBounds().height() / 2f;
    float scaledHalfWidth = halfWidth * scale;
    float scaledHalfHeight = halfHeight * scale;

    canvas.translate(
        getScale() * halfWidth - scaledHalfWidth,
        getScale() * halfHeight - scaledHalfHeight);
    canvas.scale(extraScale, extraScale, scaledHalfWidth, scaledHalfHeight);
  }

  matrix.reset();
  matrix.preScale(scale, scale);
  compositionLayer.draw(canvas, matrix, alpha);

  if (saveCount > 0) {
    canvas.restoreToCount(saveCount);
  }
}
 
Example 15
Source File: BaseKChartView.java    From kAndroid with Apache License 2.0 4 votes vote down vote up
/**
 * 画k线图
 *
 * @param canvas
 */
private void drawK(Canvas canvas) {
    //保存之前的平移,缩放
    canvas.save();
    canvas.translate(mTranslateX * mScaleX, 0);
    canvas.scale(mScaleX, 1);

    mMaxValue = ((ICandle) getItem(mStartIndex)).getHighPrice();
    mMinValue = ((ICandle) getItem(mStartIndex)).getLowPrice();

    for (int i = mStartIndex; i <= mStopIndex; i++) {
        Object currentPoint = getItem(i);
        float currentPointX = getX(i);
        Object lastPoint = i == 0 ? currentPoint : getItem(i - 1);
        float lastX = i == 0 ? currentPointX : getX(i - 1);
        if (mMainDraw != null) {
            if (mMaxValue < ((ICandle) getItem(i)).getHighPrice()) {
                mMaxValue = ((ICandle) getItem(i)).getHighPrice();
                mMaxPoint = (ICandle) getItem(i);
                mMaxX = currentPointX;
            } else if (mMinValue > ((ICandle) getItem(i)).getLowPrice()) {
                mMinValue = ((ICandle) getItem(i)).getLowPrice();
                mMinPoint = (ICandle) getItem(i);
                mMinX = currentPointX;
            }
            mMainDraw.drawTranslated(lastPoint, currentPoint, lastX, currentPointX, canvas, this, i);
        }
        if (mChildDraw != null) {
            mChildDraw.drawTranslated(lastPoint, currentPoint, lastX, currentPointX, canvas, this, i);
        }

    }
    if (mMainDraw != null && mMinPoint != null && mMaxPoint != null) {
        mMainDraw.drawMaxAndMin(this, canvas, mMaxX, mMinX, mMaxPoint, mMinPoint);
    }

    //画选择线
    if (isLongPress || !isClosePress) {
        IKLine point = (IKLine) getItem(mSelectedIndex);
        if (point == null) {
            return;
        }
        float x = getX(mSelectedIndex);
        float y = getMainY(point.getClosePrice());

        mSelectedLinePaint.setColor(ContextCompat.getColor(getContext(), R.color.chart_press_xian));//长按时线条显示文字的颜色
        canvas.drawLine(x, mMainRect.top, x, mChildRect.bottom, mSelectedLinePaint);
        canvas.drawLine(-mTranslateX, y, -mTranslateX + mWidth / mScaleX, y, mSelectedLinePaint);//隐藏横线
    }
    //还原 平移缩放
    canvas.restore();
}
 
Example 16
Source File: CameraBridgeViewBase.java    From FaceRecognitionApp with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This method shall be called by the subclasses when they have valid
 * object and want it to be delivered to external client (via callback) and
 * then displayed on the screen.
 * @param frame - the current frame to be delivered
 */
protected void deliverAndDrawFrame(CvCameraViewFrame frame) {
    Mat modified;

    if (mListener != null) {
        modified = mListener.onCameraFrame(frame);
    } else {
        modified = frame.rgba();
    }

    boolean bmpValid = true;
    if (modified != null) {
        try {
            Utils.matToBitmap(modified, mCacheBitmap);
        } catch(Exception e) {
            Log.e(TAG, "Mat type: " + modified);
            Log.e(TAG, "Bitmap type: " + mCacheBitmap.getWidth() + "*" + mCacheBitmap.getHeight());
            Log.e(TAG, "Utils.matToBitmap() throws an exception: " + e.getMessage());
            bmpValid = false;
        }
    }

    if (bmpValid && mCacheBitmap != null) {
        Canvas canvas = getHolder().lockCanvas();
        if (canvas != null) {
            canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR);
            int degrees = 0;

            if (!isEmulator()) { // Rotation is always reported as portrait on the emulator for some reason
                int orientation = getScreenOrientation();
                switch (orientation) {
                    case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
                        degrees = -90;
                        break;
                    case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
                        break;
                    case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
                        degrees = 90;
                        break;
                    case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
                        degrees = 180;
                        break;
                }
            }

            Matrix matrix = new Matrix();
            matrix.postRotate(degrees);
            Bitmap outputBitmap = Bitmap.createBitmap(mCacheBitmap, 0, 0, mCacheBitmap.getWidth(), mCacheBitmap.getHeight(), matrix, true);

            if (outputBitmap.getWidth() <= canvas.getWidth()) {
                mScale = getRatio(outputBitmap.getWidth(), outputBitmap.getHeight(), canvas.getWidth(), canvas.getHeight());
            } else {
                mScale = getRatio(canvas.getWidth(), canvas.getHeight(), outputBitmap.getWidth(), outputBitmap.getHeight());
            }

            if (mScale != 0) {
                canvas.scale(mScale, mScale, 0, 0);
            }

            if (BuildConfig.DEBUG)
                Log.v(TAG, "mStretch value: " + mScale);

            canvas.drawBitmap(outputBitmap, 0, 0, null);

            if (mFpsMeter != null) {
                mFpsMeter.measure();
                mFpsMeter.draw(canvas, 20, 30);
            }
            getHolder().unlockCanvasAndPost(canvas);
        }
    }
}
 
Example 17
Source File: FlatClockView.java    From FlatTimeCollection with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    initDraw();

    if(withBackground)
        canvas.drawCircle(getWidth()/2f, getHeight()/2f, getWidth()/2f, backgroundPaint);

    canvas.save();
    canvas.scale(.88f, .88f, getWidth()/2f, getHeight()/2f);

    canvas.save();
    for(float i=30f; i<=360f; i+=30f){
        canvas.rotate(30f, getWidth()/2f, getHeight()/2f);
        if(i%90f == 0f){
            canvas.drawPath(bigMark, bigMarkPaint);
            continue;
        }
        canvas.drawPath(smallMark, smallMarkPaint);
    }
    // restore from rotate
    canvas.restore();

    canvas.save();
    canvas.rotate(mCalendar.get(Calendar.MINUTE) * 6f, getWidth()/2f, getHeight()/2f);
    indicatorPaint.setColor(minIndicatorColor);
    canvas.drawPath(minIndicator, indicatorPaint);
    canvas.restore();

    canvas.save();
    canvas.rotate((mCalendar.get(Calendar.HOUR) + (Calendar.MINUTE/60f)) * 30f, getWidth()/2f, getHeight()/2f);
    indicatorPaint.setColor(hourIndicatorColor);
    canvas.drawPath(hourIndicator, indicatorPaint);
    canvas.restore();

    canvas.save();
    canvas.rotate(mCalendar.get(Calendar.SECOND) * 6f, getWidth()/2f, getHeight()/2f);
    indicatorPaint.setColor(secIndicatorColor);
    canvas.drawPath(secIndicator, indicatorPaint);
    canvas.restore();

    // restore from scale
    canvas.restore();
}
 
Example 18
Source File: GaugeRotationHolo.java    From AccelerationAlert with Apache License 2.0 4 votes vote down vote up
/**
 * Draw the gauge face.
 * 
 * @param canvas
 */
private void drawFace(Canvas canvas)
{
	// free the old bitmap
	if (face != null)
	{
		face.recycle();
	}

	face = Bitmap.createBitmap(getWidth(), getHeight(),
			Bitmap.Config.ARGB_8888);
	Canvas faceCanvas = new Canvas(face);
	float scale = (float) getWidth();
	faceCanvas.scale(scale, scale);

	float rimSize = 0.02f;

	float radius = ((rimRect.left + rimSize) + (rimRect.right - rimSize)) / 2;

	float aPos = -rotation[1];

	if (aPos < 0)
	{
		aPos = 0;
	}

	float aNeg = -rotation[1];

	if (aNeg > 0)
	{
		aNeg = 0;
	}

	float radiusSquaredNeg = (float) Math.pow(radius, 2);

	float aSquaredNeg = (float) Math.pow(aNeg, 2);

	float bNeg = (float) Math.sqrt(radiusSquaredNeg - aSquaredNeg);

	float radiusSquaredPos = (float) Math.pow(radius, 2);

	float aSquaredPos = (float) Math.pow(aPos, 2);

	float bPos = (float) Math.sqrt(radiusSquaredPos - aSquaredPos);

	skyBackgroundRect.set(rimRect.left + rimSize, rimRect.top + rimSize,
			rimRect.right - rimSize, rimRect.bottom - rimSize);

	if (aPos == 0)
	{
		faceCanvas.drawArc(skyBackgroundRect,
				(float) (0 + (-rotation[0] * (180 / Math.PI))), 360, true,
				skyPaint);
	}
	if (aNeg== 0)
	{
		faceCanvas.drawArc(skyBackgroundRect,
				(float) (0 + (-rotation[0] * (180 / Math.PI))), 360, true,
				earthPaint);
	}

	skyRect.set((rimRect.left + rimSize) + (radius - bPos) / 2, rimRect.top
			+ rimSize, (rimRect.right - rimSize) - (radius - bPos) / 2,
			(rimRect.bottom - rimSize) - (aPos));

	faceCanvas.drawArc(skyRect,
			(float) (0 + (-rotation[0] * (180 / Math.PI))), -180, true,
			skyPaint);

	earthRect.set((rimRect.left + rimSize) + (radius - bNeg) / 2,
			(rimRect.top + rimSize) - (aNeg), (rimRect.right - rimSize)
					- (radius - bNeg) / 2, rimRect.bottom - rimSize);

	// canvas.drawOval(faceRect, facePaint);
	faceCanvas.drawArc(earthRect,
			(float) (0 + (-rotation[0] * (180 / Math.PI))), 180, true,
			earthPaint);

	canvas.drawBitmap(face, 0, 0, backgroundPaint);
}
 
Example 19
Source File: GIFView.java    From RedReader with GNU General Public License v3.0 4 votes vote down vote up
protected void onDraw(final Canvas canvas) {
	canvas.drawColor(Color.TRANSPARENT);
	super.onDraw(canvas);
	long now = SystemClock.uptimeMillis();

	final float scale = Math.min((float)getWidth() / mMovie.width(), (float)getHeight() / mMovie.height());

	canvas.scale(scale, scale);
	canvas.translate(((float)getWidth() / scale - (float)mMovie.width())/2f,
			((float)getHeight() / scale - (float)mMovie.height())/2f);


	if(movieStart == 0) movieStart = (int)now;

	mMovie.setTime((int)((now - movieStart) % mMovie.duration()));
	mMovie.draw(canvas, 0, 0, paint);

	this.invalidate();
}
 
Example 20
Source File: ProtractorView.java    From ProtractorView with MIT License 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    canvas.save();
    canvas.scale(1, -1, mArcRect.centerX(), mArcRect.centerY());
    canvas.drawArc(mArcRect, 0, MAX, false, mArcPaint);
    canvas.drawArc(mArcRect, 0, mAngle, false, mArcProgressPaint);

    canvas.restore();
    double slope, startTickX, startTickY, endTickX, endTickY, midTickX, midTickY, thetaInRadians;
    double radiusOffset = mArcRadius + mTickOffset;

    //TicksBetweenLabel
    /**
     * Mechanism to draw the tick and text.
     * Tan(theta) gives the slope.
     * Formula for a straight line is y = mx + c. y is calculated for varying values of x and the ticks are drawn.
     */

    int count = mTicksBetweenLabel.ordinal();
    for (int i = 360; i >= 180; i -= mTickIntervals) {
        canvas.save();
        if (count == mTicksBetweenLabel.ordinal()) {
            //for text
            canvas.translate(mArcRect.centerX(), mArcRect.centerY());
            thetaInRadians = Math.toRadians(i);
            slope = Math.tan(thetaInRadians);
            startTickX = (radiusOffset * Math.cos(thetaInRadians));
            midTickX = startTickX + (((mTickLength / 2)) * Math.cos(thetaInRadians));
            midTickY = slope * midTickX;
            canvas.drawText("" + (360 - i), (float) midTickX, (float) midTickY, (mAngle <= 359 - i) ? mTickTextPaint : mTickTextColoredPaint);
            count = 0;
        } else {
            //for tick
            canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
            canvas.translate(mArcRect.centerX(), mArcRect.centerY());
            canvas.rotate(180);
            thetaInRadians = Math.toRadians(360 - i);
            slope = Math.tan(thetaInRadians);
            startTickX = (radiusOffset * Math.cos(thetaInRadians));
            startTickY = slope * startTickX;
            endTickX = startTickX + ((mTickLength) * Math.cos(thetaInRadians));
            endTickY = slope * endTickX;
            canvas.drawLine((float) startTickX, (float) startTickY, (float) endTickX, (float) endTickY, (mAngle <= 359 - i) ? mTickPaint : mTickProgressPaint);
            count++;
        }
        canvas.restore();
    }


    if (mEnabled) {
        // Draw the thumb nail
        canvas.save();
        canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY());
        canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos);
        mThumb.draw(canvas);
        canvas.restore();
    }
}