List of usage examples for android.graphics Canvas translate
public void translate(float dx, float dy)
From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java
/** * ??//from w w w . j a va 2s .c o m * * @param canvas * @param position ??? * @param itemWidth ? * @param itemHeight ? */ protected void drawItemGradient(Canvas canvas, int position, int itemWidth, int itemHeight) { if (mGradient == null || !mGradient.isStateful()) return; final int normalColor = mGradient.getDefaultColor(); final int selectedColor = mGradient.getColorForState(SELECTED_STATE_SET, normalColor); if (position == mNextPager) { mTextPaint.setColor(getColor(normalColor, selectedColor, mOffset)); } else if (position == mCurrentPager) { mTextPaint.setColor(getColor(normalColor, selectedColor, 1 - mOffset)); } else { mTextPaint.setColor(normalColor); } final float moveX = ViewCompat.getPaddingStart(this) + (itemWidth + getIntervalWidth()) * position; final float moveY = getPaddingTop(); final int restWidth = position == getItemCount() - 1 ? getLastItemWidth() : itemWidth; canvas.save(); canvas.translate(moveX, moveY); canvas.drawRect(0, 0, restWidth, itemHeight, mTextPaint); canvas.restore(); }
From source file:com.klinker.android.sliding.MultiShrinkScroller.java
/** * Draw all components on the screen.// w ww. j av a 2 s . c om * @param canvas the canvas to draw on. */ @Override public void draw(Canvas canvas) { super.draw(canvas); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); if (!edgeGlowBottom.isFinished()) { final int restoreCount = canvas.save(); // Draw the EdgeEffect on the bottom of the Window (Or a little bit below the bottom // of the Window if we start to scroll upwards while EdgeEffect is visible). This // does not need to consider the case where this MultiShrinkScroller doesn't fill // the Window, since the nested ScrollView should be set to fillViewport. canvas.translate(-width + getPaddingLeft(), height + getMaximumScrollUpwards() - getScroll()); canvas.rotate(180, width, 0); if (isTwoPanel) { // Only show the EdgeEffect on the bottom of the ScrollView. edgeGlowBottom.setSize(scrollView.getWidth(), height); } else { edgeGlowBottom.setSize(width, height); } if (edgeGlowBottom.draw(canvas)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { postInvalidateOnAnimation(); } else { postInvalidate(); } } canvas.restoreToCount(restoreCount); } if (!edgeGlowTop.isFinished()) { final int restoreCount = canvas.save(); if (isTwoPanel) { edgeGlowTop.setSize(scrollView.getWidth(), height); canvas.translate(photoViewContainer.getWidth(), 0); } else { edgeGlowTop.setSize(width, height); } if (edgeGlowTop.draw(canvas)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { postInvalidateOnAnimation(); } else { postInvalidate(); } } canvas.restoreToCount(restoreCount); } }
From source file:org.telegram.ui.Cells.ProfileSearchCell.java
@Override protected void onDraw(Canvas canvas) { if (user == null && chat == null && encryptedChat == null) { return;// www .ja v a 2 s . co m } if (useSeparator) { if (LocaleController.isRTL) { canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, linePaint); } else { canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, linePaint); } } if (drawAlpha != 1) { canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(), (int) (255 * drawAlpha), Canvas.HAS_ALPHA_LAYER_SAVE_FLAG); } if (drawNameLock) { setDrawableBounds(lockDrawable, nameLockLeft, nameLockTop); lockDrawable.draw(canvas); } else if (drawNameGroup) { setDrawableBounds(groupDrawable, nameLockLeft, nameLockTop); groupDrawable.draw(canvas); } else if (drawNameBroadcast) { setDrawableBounds(broadcastDrawable, nameLockLeft, nameLockTop); broadcastDrawable.draw(canvas); } else if (drawNameBot) { setDrawableBounds(botDrawable, nameLockLeft, nameLockTop); botDrawable.draw(canvas); } if (nameLayout != null) { canvas.save(); canvas.translate(nameLeft, nameTop); nameLayout.draw(canvas); canvas.restore(); if (drawCheck) { if (LocaleController.isRTL) { setDrawableBounds(checkDrawable, nameLeft - AndroidUtilities.dp(4) - checkDrawable.getIntrinsicWidth(), nameLockTop); } else { setDrawableBounds(checkDrawable, nameLeft + (int) nameLayout.getLineWidth(0) + AndroidUtilities.dp(4), nameLockTop); } checkDrawable.draw(canvas); } } if (onlineLayout != null) { canvas.save(); canvas.translate(onlineLeft, AndroidUtilities.dp(40)); onlineLayout.draw(canvas); canvas.restore(); } if (countLayout != null) { if (MessagesController.getInstance().isDialogMuted(dialog_id)) { setDrawableBounds(countDrawableGrey, countLeft - AndroidUtilities.dp(5.5f), countTop, countWidth + AndroidUtilities.dp(11), countDrawableGrey.getIntrinsicHeight()); countDrawableGrey.draw(canvas); } else { setDrawableBounds(countDrawable, countLeft - AndroidUtilities.dp(5.5f), countTop, countWidth + AndroidUtilities.dp(11), countDrawable.getIntrinsicHeight()); countDrawable.draw(canvas); } canvas.save(); canvas.translate(countLeft, countTop + AndroidUtilities.dp(4)); countLayout.draw(canvas); canvas.restore(); } avatarImage.draw(canvas); }
From source file:com.microhealthllc.Slide.MultiShrinkScroller.java
/** * Draw all components on the screen.//from w w w . jav a2 s .c o m * * @param canvas the canvas to draw on. */ @Override public void draw(Canvas canvas) { super.draw(canvas); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); if (!edgeGlowBottom.isFinished()) { final int restoreCount = canvas.save(); // Draw the EdgeEffect on the bottom of the Window (Or a little bit below the bottom // of the Window if we start to scroll upwards while EdgeEffect is visible). This // does not need to consider the case where this MultiShrinkScroller doesn't fill // the Window, since the nested ScrollView should be set to fillViewport. canvas.translate(-width + getPaddingLeft(), height + getMaximumScrollUpwards() - getScroll()); canvas.rotate(180, width, 0); if (isTwoPanel) { // Only show the EdgeEffect on the bottom of the ScrollView. edgeGlowBottom.setSize(scrollView.getWidth(), height); } else { edgeGlowBottom.setSize(width, height); } // todo: figure out what is wrong with the edge glow with padded layouts if (paddedLayout) { edgeGlowBottom.setSize(0, 0); } if (edgeGlowBottom.draw(canvas)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { postInvalidateOnAnimation(); } else { postInvalidate(); } } canvas.restoreToCount(restoreCount); } if (!edgeGlowTop.isFinished()) { final int restoreCount = canvas.save(); if (isTwoPanel) { edgeGlowTop.setSize(scrollView.getWidth(), height); canvas.translate(photoViewContainer.getWidth() * (1 / 6), 0); } else { edgeGlowTop.setSize(width, height); } // todo: figure out what is wrong with the edge glow with padded layouts if (paddedLayout) { edgeGlowTop.setSize(0, 0); } if (edgeGlowTop.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
/** * //from w w w . j av a 2 s. c om * * @param canvas */ protected void drawIndicator(Canvas canvas) { if (mIndicator == null) return; final int indicatorWidth = getIndicatorWidth(); final int indicatorHeight = getIndicatorHeight(); if (indicatorWidth <= 0 || indicatorHeight <= 0) return; mIndicator.setBounds(0, 0, indicatorWidth, indicatorHeight); final float widthWithInterval = getItemWidth() + getIntervalWidth(); final float currentCenter = ViewCompat.getPaddingStart(this) + mCurrentPager * widthWithInterval + widthWithInterval * 0.5f; final float nextCenter = ViewCompat.getPaddingStart(this) + mNextPager * widthWithInterval + widthWithInterval * 0.5f; final float moveCenter = currentCenter + (nextCenter - currentCenter) * mOffset; final float moveX = moveCenter - indicatorWidth * 0.5f; final float moveY = getHeight() - getPaddingBottom() - getDividerHeight() - indicatorHeight; canvas.save(); canvas.translate(moveX, moveY); mIndicator.draw(canvas); canvas.restore(); }
From source file:cnedu.ustcjd.widget.MultiSlider.java
@Override protected synchronized void onDraw(Canvas canvas) { super.onDraw(canvas); // --> draw track if (mTrack != null) { // Translate canvas so a indeterminate circular progress bar with padding // rotates properly in its animation canvas.save();// w w w. j a v a 2 s . co m if (isLayoutRtl() && mMirrorForRtl) { canvas.translate(getWidth() - getPaddingRight(), getPaddingTop()); canvas.scale(-1.0f, 1.0f); } else { canvas.translate(getPaddingLeft(), getPaddingTop()); } mTrack.draw(canvas); canvas.restore(); } // --> draw ranges for (Thumb thumb : mThumbs) { if (thumb.getRange() != null) { canvas.save(); if (isLayoutRtl() && mMirrorForRtl) { canvas.translate(getWidth() - getPaddingRight(), getPaddingTop()); canvas.scale(-1.0f, 1.0f); } else { canvas.translate(getPaddingLeft(), getPaddingTop()); } thumb.getRange().draw(canvas); canvas.restore(); } } // --> then draw thumbs for (Thumb thumb : mThumbs) { if (thumb.getThumb() != null && !thumb.isInvisibleThumb()) { canvas.save(); // Translate the padding. For the x, we need to allow the thumb to // draw in its extra space canvas.translate(getPaddingLeft() - thumb.getThumbOffset(), getPaddingTop()); // float scale = mScaleMax > 0 ? (float) thumb.getValue() / (float) mScaleMax : 0; thumb.getThumb().draw(canvas); canvas.restore(); } } }
From source file:net.simonvt.staggeredgridview.StaggeredGridView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); if (topEdge != null) { boolean needsInvalidate = false; if (!topEdge.isFinished()) { topEdge.draw(canvas);//from w w w . j a v a 2s .c om needsInvalidate = true; } if (!bottomEdge.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth(); canvas.translate(-width, getHeight()); canvas.rotate(180, width, 0); bottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); needsInvalidate = true; } if (needsInvalidate) { postInvalidateOnAnimation(); } } if (!selectorRect.isEmpty()) { selector.setBounds(selectorRect); selector.draw(canvas); } }
From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java
@Override public void draw(Canvas canvas) { super.draw(canvas); if (mEdgeGlowTop != null) { final int scrollY = getScrollY(); if (!mEdgeGlowTop.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.translate(getPaddingLeft(), Math.min(0, scrollY)); mEdgeGlowTop.setSize(width, getHeight()); if (mEdgeGlowTop.draw(canvas)) { ViewCompat.postInvalidateOnAnimation(this); }/*from w w w .j a va 2s . c om*/ canvas.restoreToCount(restoreCount); } if (!mEdgeGlowBottom.isFinished()) { final int restoreCount = canvas.save(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); canvas.translate(-width + getPaddingLeft(), Math.max(getScrollRange(), scrollY) + height); canvas.rotate(180, width, 0); mEdgeGlowBottom.setSize(width, height); if (mEdgeGlowBottom.draw(canvas)) { ViewCompat.postInvalidateOnAnimation(this); } canvas.restoreToCount(restoreCount); } } }
From source file:com.marshalchen.common.uimodule.freeflow.core.FreeFlowContainer.java
@Override public void draw(Canvas canvas) { super.draw(canvas); boolean needsInvalidate = false; final int height = getMeasuredHeight() - getPaddingTop() - getPaddingBottom(); final int width = getMeasuredWidth(); if (!mLeftEdge.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(270);/*from w ww . j a v a 2 s . com*/ canvas.translate(-height + getPaddingTop(), 0);// width); mLeftEdge.setSize(height, width); needsInvalidate = mLeftEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mTopEdge.isFinished()) { final int restoreCount = canvas.save(); mTopEdge.setSize(width, height); needsInvalidate = mTopEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mRightEdge.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(90); canvas.translate(0, -width);// width); mRightEdge.setSize(height, width); needsInvalidate = mRightEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mBottomEdge.isFinished()) { final int restoreCount = canvas.save(); canvas.rotate(180); canvas.translate(-width + getPaddingTop(), -height); mBottomEdge.setSize(width, height); needsInvalidate = mBottomEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (needsInvalidate) { ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.yek.keyboard.keyboards.views.AnyKeyboardView.java
@Override public void onDraw(Canvas canvas) { final boolean keyboardChanged = mKeyboardChanged; super.onDraw(canvas); // switching animation if (mAnimationLevel != AskPrefs.AnimationsLevel.None && keyboardChanged && (mInAnimation != null)) { startAnimation(mInAnimation);/*from ww w . java 2s . c om*/ mInAnimation = null; } // text pop out animation if (mPopOutText != null && mAnimationLevel != AskPrefs.AnimationsLevel.None) { final int maxVerticalTravel = getHeight() / 2; final long currentAnimationTime = SystemClock.elapsedRealtime() - mPopOutTime; if (currentAnimationTime > TEXT_POP_OUT_ANIMATION_DURATION) { mPopOutText = null; } else { final float popOutPositionProgress = ((float) currentAnimationTime) / ((float) TEXT_POP_OUT_ANIMATION_DURATION); final float animationProgress = mPopOutTextReverting ? 1f - popOutPositionProgress : popOutPositionProgress; final float animationInterpolatorPosition = getPopOutAnimationInterpolator(false, animationProgress); final int y = mPopOutStartPoint.y - (int) (maxVerticalTravel * animationInterpolatorPosition); final int x = mPopOutStartPoint.x; final int alpha = mPopOutTextReverting ? (int) (255 * animationProgress) : 255 - (int) (255 * animationProgress); // drawing setPaintToKeyText(mPaint); // will disappear over time mPaint.setAlpha(alpha); mPaint.setShadowLayer(5, 0, 0, Color.BLACK); // will grow over time mPaint.setTextSize(mPaint.getTextSize() * (1.0f + animationInterpolatorPosition)); canvas.translate(x, y); canvas.drawText(mPopOutText, 0, mPopOutText.length(), 0, 0, mPaint); canvas.translate(-x, -y); //we're doing reverting twice much faster if (mPopOutTextReverting) { mPopOutTime = mPopOutTime - (int) (60 * popOutPositionProgress); } // next frame postInvalidateDelayed(1000 / 60);// doing 60 frames per second; } } //showing alpha/beta icon if needed if (BuildConfig.TESTING_BUILD) { final float textSizeForBuildSign = mPaint.getTextSize() / 2f; final float x = getWidth() - (mBuildTypeSignText.length() * textSizeForBuildSign); final float y = getHeight() - textSizeForBuildSign - getPaddingBottom(); canvas.translate(x, y); canvas.drawText(mBuildTypeSignText, 0, mBuildTypeSignText.length(), 0, 0, mBuildTypeSignPaint); canvas.translate(-x, -y); } }