List of usage examples for android.graphics Canvas translate
public void translate(float dx, float dy)
From source file:aksha.upcomingdemo.HorizontalListView.java
/** Draws the overscroll edge glow effect on the left and right sides of the horizontal list */ private void drawEdgeGlow(Canvas canvas) { if (mEdgeGlowLeft != null && !mEdgeGlowLeft.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so rotate it to draw on the left side. final int restoreCount = canvas.save(); final int height = getHeight(); canvas.rotate(-90, 0, 0);/* w w w . ja v a 2s .co m*/ canvas.translate(-height + getPaddingBottom(), 0); mEdgeGlowLeft.setSize(getRenderHeight(), getRenderWidth()); if (mEdgeGlowLeft.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } else if (mEdgeGlowRight != null && !mEdgeGlowRight.isFinished() && isEdgeGlowEnabled()) { // The Edge glow is meant to come from the top of the screen, so rotate it to draw on the right side. final int restoreCount = canvas.save(); final int width = getWidth(); canvas.rotate(90, 0, 0); canvas.translate(getPaddingTop(), -width); mEdgeGlowRight.setSize(getRenderHeight(), getRenderWidth()); if (mEdgeGlowRight.draw(canvas)) { invalidate(); } canvas.restoreToCount(restoreCount); } }
From source file:com.android.mail.browse.ConversationItemView.java
private void drawSubject(Canvas canvas) { canvas.translate(mCoordinates.subjectX, mCoordinates.subjectY); mSubjectTextView.draw(canvas); }
From source file:com.android.mail.browse.ConversationItemView.java
private void drawSenders(Canvas canvas) { canvas.translate(mSendersX, mCoordinates.sendersY); mSendersTextView.draw(canvas); }
From source file:com.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int viewWidth = this.getWidth(); int viewHeight = this.getHeight(); int viewHalfWidth = viewWidth / 2; this.sectionHeight = viewHeight / MAX_SECTION_COUNT; boolean isPreviousImage = false; boolean isPreviousLetter = false; float allSectionHeight; if (this.sections.size() > 0) { allSectionHeight = this.sectionHeight * this.sections.size(); this.drawBeginY = (viewHeight - allSectionHeight) / 2; this.drawEndY = this.drawBeginY + allSectionHeight; float top = viewHeight / 2 - allSectionHeight / 2 + this.sectionHeight / 2 - this.sectionFontSize / 2; for (int i = 0; i < this.sections.size(); i++) { EasySection section = this.sections.get(i); if (section instanceof EasyImageSection) { EasyImageSection imageSection = (EasyImageSection) section; this.setPaintShader(imageSection); if (isPreviousLetter) { top -= this.letterSize - (Math.max(this.letterHeight, this.sectionHeight) - Math.min(this.letterHeight, this.sectionHeight)); }/*from w w w . j a va 2 s . c o m*/ canvas.save(); canvas.translate(viewHalfWidth - this.letterSize / 2, top + this.sectionHeight * i); Paint imagePaint = this.imagePaints.get(imageSection.hashCode()); switch (imageSection.imageType) { case EasyImageSection.ROUND: { canvas.drawRoundRect(this.imageSectionRect, this.imageSectionBorderRadius, this.imageSectionBorderRadius, imagePaint); break; } case EasyImageSection.CIRCLE: { canvas.drawRoundRect(this.imageSectionRect, this.imageSectionCircleBorderRadius, this.imageSectionCircleBorderRadius, imagePaint); break; } } canvas.restore(); isPreviousImage = true; isPreviousLetter = false; } else { if (isPreviousImage) { top = top + this.letterSize; } canvas.drawText(section.letter, viewHalfWidth, top + this.sectionHeight * i, this.letterPaint); isPreviousImage = false; isPreviousLetter = true; } } } else { this.sectionHeight = 0; } }
From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java
/** * //from w w w . ja v a2s .com * * @param canvas */ private void drawText(Canvas canvas) { float x = getPaddingLeft() + itemWidth / 2; int y = getHeight() - getPaddingBottom() - indicatorHeight - underLineHeight; int position = 0; for (String text : tabs) { canvas.save(); mTextPaint.setColor(textColorNormal); mTextPaint.setTextAlign(Align.LEFT); mTextPaint.setTextSize(textSize); if (showTextGradient) { if (position == nextPager) { mTextPaint.setColor(getColor(textColorNormal, textColorSelected, textSizeOffset)); } else if (position == currectPager) { mTextPaint.setColor(getColor(textColorNormal, textColorSelected, 1 - textSizeOffset)); } else { mTextPaint.setColor(textColorNormal); } } if (showTextScale) { if (position == nextPager) { canvas.translate(x - mTextPaint.measureText(text) * (1 + textSizeOffset * magnification) / 2, y - textTop); canvas.scale(1 + textSizeOffset * magnification, 1 + textSizeOffset * magnification); } else if (position == currectPager) { canvas.translate( x - mTextPaint.measureText(text) * (1 + (1 - textSizeOffset) * magnification) / 2, y - textTop); canvas.scale(1 + (1 - textSizeOffset) * magnification, 1 + (1 - textSizeOffset) * magnification); } else { canvas.translate(x - mTextPaint.measureText(text) / 2, y - textTop); canvas.scale(1, 1); } } else { canvas.translate(x - mTextPaint.measureText(text) / 2, y - textTop); } canvas.drawText(text, 0, 0, mTextPaint); x += itemWidth + intervalWidth; position++; canvas.restore(); } }
From source file:com.bitflake.counter.HorizontalPicker.java
private void drawEdgeEffect(Canvas canvas, EdgeEffect edgeEffect, int degrees) { if (canvas == null || edgeEffect == null || (degrees != 90 && degrees != 270)) { return;//from w w w. j a va2 s .co m } if (!edgeEffect.isFinished()) { final int restoreCount = canvas.getSaveCount(); final int width = getWidth(); final int height = getHeight(); canvas.rotate(degrees); if (degrees == 270) { canvas.translate(-height, Math.max(0, getScrollX())); } else { // 90 canvas.translate(0, -(Math.max(getScrollRange(), getScaleX()) + width)); } edgeEffect.setSize(height, width); if (edgeEffect.draw(canvas)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { postInvalidateOnAnimation(); } else { postInvalidate(); } } canvas.restoreToCount(restoreCount); } }
From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java
/** * Divider/*from w ww .j a v a2 s . co m*/ * * @param canvas */ protected void drawDivider(Canvas canvas) { if (mDivider == null || mDivider.getIntrinsicHeight() <= 0) return; final int dividerWidth = mDivider.getIntrinsicWidth() > 0 ? mDivider.getIntrinsicWidth() : getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this); final int dividerHeight = mDivider.getIntrinsicHeight(); mDivider.setBounds(0, 0, dividerWidth, dividerHeight); final float moveX = ViewCompat.getPaddingStart(this); final float moveY = getItemHeight() + getPaddingTop(); canvas.save(); canvas.translate(moveX, moveY); mDivider.draw(canvas); canvas.restore(); }
From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java
/** * /* ww w. ja v a 2s .c o m*/ * * @param canvas * @param position ??? * @param itemWidth ? * @param itemHeight ? */ protected void drawInterval(Canvas canvas, int position, int itemWidth, int itemHeight) { if (mInterval == null || mInterval.getIntrinsicWidth() <= 0 || position == getItemCount() - 1) return; final int intervalHeight = mInterval.getIntrinsicHeight() <= 0 ? itemHeight : mInterval.getIntrinsicHeight(); mInterval.setBounds(0, 0, getIntervalWidth(), intervalHeight); final int moveX = ViewCompat.getPaddingStart(this) + itemWidth * position; final float moveY = getPaddingTop() + (itemHeight - intervalHeight) * 0.5f; canvas.save(); canvas.translate(moveX, moveY); mInterval.draw(canvas); canvas.restore(); }
From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java
/** * /* w ww. j a va 2 s .c o m*/ * * @param canvas * @param position ??? * @param itemWidth ? * @param itemHeight ? */ protected void drawItemBackground(Canvas canvas, int position, int itemWidth, int itemHeight) { if (!hasItemBackgrounds()) return; Drawable tag = getItemBackground(position); if (position == getItemCount() - 1) { int restWidth = getLastItemWidth(); tag.setBounds(0, 0, restWidth, itemHeight); } else { tag.setBounds(0, 0, itemWidth, itemHeight); } final float moveX = ViewCompat.getPaddingStart(this) + (itemWidth + getIntervalWidth()) * position; final float moveY = getPaddingTop(); canvas.save(); canvas.translate(moveX, moveY); tag.draw(canvas); canvas.restore(); }
From source file:com.tbse.mywearapplication.WatchFaceDrawer.java
void onDraw(Context context, IWatchFaceConfig config, Canvas canvas, Rect bounds) { final Calendar calendar = config.getCalendar(); final boolean isAmbient = config.isAmbient(); final boolean isRound = config.isRound(); final boolean useLightTheme = !isAmbient && config.isLightTheme(); mBackgroundPaint.setColor(ContextCompat.getColor(context, useLightTheme ? R.color.watchface_background_light : R.color.watchface_background)); ///////////////////////////////////////////////////////////////////// // Draw your watch face here, using the provided canvas and bounds // ///////////////////////////////////////////////////////////////////// final int width = bounds.width(); final int height = bounds.height(); // Find the center. Ignore the window insets so that, on round // watches with a "chin", the watch face is centered on the entire // screen, not just the usable portion. final float centerX = width / 2f; final float centerY = height / 2f; // Draw the background. if (mIsMobilePreview) { if (isRound) { canvas.drawCircle(centerX, centerY, centerX, mPreviewBorderPaint); } else {//from w ww . j a va 2s. com final float radius = mPreviewSquareRadius; final RectF rectF = new RectF(0, 0, canvas.getWidth(), canvas.getHeight()); canvas.drawRoundRect(rectF, radius, radius, mPreviewBorderPaint); } final float translateXY = width * 0.05f; canvas.translate(translateXY, translateXY); canvas.scale(0.9f, 0.9f); if (isRound) { canvas.drawCircle(centerX, centerY, centerX, mBackgroundPaint); } else { canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint); } } else { canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), mBackgroundPaint); } // Draw weather icon if (image != null) { Matrix matrix = new Matrix(); matrix.setTranslate(50, 90); matrix.preScale(0.2f, 0.2f); canvas.drawBitmap(image, matrix, null); } final float secRot = calendar.get(Calendar.SECOND) / 30f * (float) Math.PI; final int minutes = calendar.get(Calendar.MINUTE); final float minRot = minutes / 30f * (float) Math.PI; final float hrRot = ((calendar.get(Calendar.HOUR) + (minutes / 60f)) / 6f) * (float) Math.PI; final float secLength = centerX - mSecondOuterOffset; final float minLength = centerX - mMinuteOuterOffset; final float hrLength = centerX - mHourOuterOffset; if (!isAmbient) { final float secX = (float) Math.sin(secRot) * secLength; final float secY = (float) -Math.cos(secRot) * secLength; canvas.drawLine(centerX, centerY, centerX + secX, centerY + secY, mSecondHandPaint); } final float minX = (float) Math.sin(minRot) * minLength; final float minY = (float) -Math.cos(minRot) * minLength; canvas.drawLine(centerX, centerY, centerX + minX, centerY + minY, mMinuteHandPaint); final float hrX = (float) Math.sin(hrRot) * hrLength; final float hrY = (float) -Math.cos(hrRot) * hrLength; canvas.drawLine(centerX, centerY, centerX + hrX, centerY + hrY, mHourHandPaint); // Draw weather text canvas.drawText(day, 50, 50, isAmbient ? ambientTextPaint : textPaint); canvas.drawText(low, 50, 65, isAmbient ? ambientTextPaint : textPaint); canvas.drawText(high, 80, 65, isAmbient ? ambientTextPaint : textPaint); canvas.drawText(weatherDescription, 50, 80, isAmbient ? ambientTextPaint : textPaint); }