本文整理匯總了Java中android.graphics.Canvas.getClipBounds方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.getClipBounds方法的具體用法?Java Canvas.getClipBounds怎麽用?Java Canvas.getClipBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.getClipBounds方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.getClipBounds(mRect);
int top = mRect.top;
int left = mRect.left;
int width = mRect.width();
int height = mRect.height();
if (mRenderer.isInScroll()) {
top = 0;
left = 0;
width = getMeasuredWidth();
height = getMeasuredHeight();
}
mChart.draw(canvas, left, top, width, height, mPaint);
if (mRenderer != null && mRenderer.isZoomEnabled() && mRenderer.isZoomButtonsVisible()) {
mPaint.setColor(ZOOM_BUTTONS_COLOR);
zoomSize = Math.max(zoomSize, Math.min(width, height) / 7);
mZoomR.set(left + width - zoomSize * 3, top + height - zoomSize * 0.775f, left + width, top
+ height);
canvas.drawRoundRect(mZoomR, zoomSize / 3, zoomSize / 3, mPaint);
float buttonY = top + height - zoomSize * 0.625f;
canvas.drawBitmap(zoomInImage, left + width - zoomSize * 2.75f, buttonY, null);
canvas.drawBitmap(zoomOutImage, left + width - zoomSize * 1.75f, buttonY, null);
canvas.drawBitmap(fitZoomImage, left + width - zoomSize * 0.75f, buttonY, null);
}
mDrawn = true;
}
示例2: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas canvas) {
if (mClipRegion == 0) {
super.onDraw(canvas);
} else {
canvas.getClipBounds(tempRect);
final float clipWidth = tempRect.width() * mClipRegion;
final int saveCount = canvas.save();
if (mIsRtl) {
canvas.clipRect(tempRect.left, tempRect.top, tempRect.right - clipWidth, tempRect.bottom);
} else {
canvas.clipRect(tempRect.left + clipWidth, tempRect.top, tempRect.right, tempRect.bottom);
}
super.onDraw(canvas);
canvas.restoreToCount(saveCount);
}
}
示例3: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.getClipBounds(mCanvasClipBounds);
int linesCount = mCanvasClipBounds.width() / (mProgressLineWidth + mProgressLineMargin);
float deltaX = (mTotalScrollDistance) % (float) (mProgressLineMargin + mProgressLineWidth);
mProgressLinePaint.setColor(getResources().getColor(R.color.ucrop_color_progress_wheel_line));
for (int i = 0; i < linesCount; i++) {
if (i < (linesCount / 4)) {
mProgressLinePaint.setAlpha((int) (255 * (i / (float) (linesCount / 4))));
} else if (i > (linesCount * 3 / 4)) {
mProgressLinePaint.setAlpha((int) (255 * ((linesCount - i) / (float) (linesCount / 4))));
} else {
mProgressLinePaint.setAlpha(255);
}
canvas.drawLine(
-deltaX + mCanvasClipBounds.left + i * (mProgressLineWidth + mProgressLineMargin),
mCanvasClipBounds.centerY() - mProgressLineHeight / 4.0f,
-deltaX + mCanvasClipBounds.left + i * (mProgressLineWidth + mProgressLineMargin),
mCanvasClipBounds.centerY() + mProgressLineHeight / 4.0f, mProgressLinePaint);
}
mProgressLinePaint.setColor(mMiddleLineColor);
canvas.drawLine(mCanvasClipBounds.centerX(), mCanvasClipBounds.centerY() - mProgressLineHeight / 2.0f, mCanvasClipBounds.centerX(), mCanvasClipBounds.centerY() + mProgressLineHeight / 2.0f, mProgressLinePaint);
}
示例4: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
paint.setColor(dotColor);
canvas.save();
canvas.getClipBounds(clipRect);
clipRect.inset(-targetLeft, 0);
canvas.translate(-targetLeft, 0);
canvas.drawCircle(centerX, targetTop + centerY, radius * radiusScale, paint);
canvas.restore();
}
示例5: drawShadow
import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawShadow(Canvas canvas) {
if (shadowDrawable != null) {
Rect newRect = canvas.getClipBounds();
Log.d(TAG,"ShadowParentView has blur! " + newRect);
newRect.inset(-shadowPadding, -shadowPadding);
canvas.clipRect (newRect, Region.Op.REPLACE);
shadowDrawable.draw(canvas);
}
}
示例6: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isSelected()) {
canvas.getClipBounds(mCanvasClipBounds);
canvas.drawCircle((mCanvasClipBounds.right - mCanvasClipBounds.left) / 2.0f, mCanvasClipBounds.bottom - mDotSize,
mDotSize / 2, mDotPaint);
}
}
示例7: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isSelected()) {
canvas.getClipBounds(this.mCanvasClipBounds);
canvas.drawCircle(((float) (this.mCanvasClipBounds.right - this.mCanvasClipBounds
.left)) / 2.0f, (float) (this.mCanvasClipBounds.bottom - this.mDotSize),
(float) (this.mDotSize / 2), this.mDotPaint);
}
}
示例8: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Shape shape, Canvas canvas, Paint paint) {
canvas.save();
Rect bounds = canvas.getClipBounds();
// bottom etched line.
if (mBottomEtchedPaint != null) shape.draw(canvas, mBottomEtchedPaint);
canvas.restore();
canvas.save();
// separator.
canvas.concat(getSeparatorPaintMatrix(bounds));
shape.draw(canvas, mSeparatorPaint);
canvas.restore();
canvas.save();
// top etched line.
canvas.concat(getTopEtchedPaintMatrix(bounds));
if (mTopEtchedPaint != null) shape.draw(canvas, mTopEtchedPaint);
canvas.restore();
canvas.save();
// background.
canvas.concat(getBackgroundPaintMatrix(bounds));
shape.draw(canvas, mBackgroundPaint);
canvas.restore();
canvas.save();
// selected.
canvas.concat(getSelectedPaintMatrix(bounds));
if (mSelectedPaint != null) {
// we'll set the selected color on onDraw event since we don't know drawable height up to here.
Shader shader = new LinearGradient(0, 0, 0, mRowHeight, mStartColor, mEndColor, Shader.TileMode.MIRROR);
mSelectedPaint.setShader(shader);
shape.draw(canvas, mSelectedPaint);
}
}
示例9: configureBounds
import android.graphics.Canvas; //導入方法依賴的package包/類
private void configureBounds(Canvas canvas) {
// I have discovered a truly marvelous explanation of this,
// which this comment space is too narrow to contain. :)
// If you want to understand what's going on here,
// See http://www.joooooooooonhokim.com/?p=289
Rect clipBounds = canvas.getClipBounds();
Matrix canvasMatrix = canvas.getMatrix();
if (ScaleType.CENTER == mScaleType) {
mBounds.set(clipBounds);
} else if (ScaleType.CENTER_CROP == mScaleType) {
applyScaleToRadii(canvasMatrix);
mBounds.set(clipBounds);
} else if (ScaleType.FIT_XY == mScaleType) {
Matrix m = new Matrix();
m.setRectToRect(mBitmapRect, new RectF(clipBounds), Matrix.ScaleToFit.FILL);
mBitmapShader.setLocalMatrix(m);
mBounds.set(clipBounds);
} else if (ScaleType.FIT_START == mScaleType || ScaleType.FIT_END == mScaleType
|| ScaleType.FIT_CENTER == mScaleType || ScaleType.CENTER_INSIDE == mScaleType) {
applyScaleToRadii(canvasMatrix);
mBounds.set(mBitmapRect);
} else if (ScaleType.MATRIX == mScaleType) {
applyScaleToRadii(canvasMatrix);
mBounds.set(mBitmapRect);
}
}
示例10: addFrame
import android.graphics.Canvas; //導入方法依賴的package包/類
/**
* 圖片增加邊框
*
* @author 2013-10-12 下午3:58:28
* @param bitmap
* @param color
* @return Bitmap
*/
public static Bitmap addFrame(Bitmap bitmap, int color)
{
Bitmap bitmap2 = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap2);
Rect rect = canvas.getClipBounds();
rect.bottom--;
rect.right--;
Paint recPaint = new Paint();
recPaint.setColor(color);
recPaint.setStyle(Paint.Style.STROKE);
canvas.drawRect(rect, recPaint);
canvas.drawBitmap(bitmap, 0, 0, null);
return bitmap2;
}
示例11: drawChild
import android.graphics.Canvas; //導入方法依賴的package包/類
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result;
LayoutParams lp = (LayoutParams) child.getLayoutParams();
int save = canvas.save(2);
if (!(!this.mCanSlide || lp.slideable || this.mSlideableView == null)) {
canvas.getClipBounds(this.mTmpRect);
if (isLayoutRtlSupport()) {
this.mTmpRect.left = Math.max(this.mTmpRect.left, this.mSlideableView.getRight());
} else {
this.mTmpRect.right = Math.min(this.mTmpRect.right, this.mSlideableView.getLeft());
}
canvas.clipRect(this.mTmpRect);
}
if (VERSION.SDK_INT >= 11) {
result = super.drawChild(canvas, child, drawingTime);
} else if (!lp.dimWhenOffset || this.mSlideOffset <= 0.0f) {
if (child.isDrawingCacheEnabled()) {
child.setDrawingCacheEnabled(false);
}
result = super.drawChild(canvas, child, drawingTime);
} else {
if (!child.isDrawingCacheEnabled()) {
child.setDrawingCacheEnabled(true);
}
Bitmap cache = child.getDrawingCache();
if (cache != null) {
canvas.drawBitmap(cache, (float) child.getLeft(), (float) child.getTop(), lp.dimPaint);
result = false;
} else {
Log.e(TAG, "drawChild: child view " + child + " returned null drawing cache");
result = super.drawChild(canvas, child, drawingTime);
}
}
canvas.restoreToCount(save);
return result;
}
示例12: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (mGalaxy == null) {
return;
}
if (mAnimated) {
mAnimationTime = Math.abs(System.currentTimeMillis() - mAnimationStartTime) % ANIMATION_DURATION;
}
canvas.save();
// Translate top-left point of current view (canvas coordinates) towards left and up (right and down if negative)
canvas.translate(-mCanvasScrollX, -mCanvasScrollY);
// Scale around a pivot center
canvas.scale(mCanvasScale, mCanvasScale, mCanvasPivotX, mCanvasPivotY);
// Get bounds of current showed view (canvas coordinates)
canvas.getClipBounds(mBoundsView);
// Clips the drawing operations to the window
//canvas.clipRect(mBoundsView);
// [...] stuff drawn with matrix transformations
drawGrid(canvas);
drawPlanets(canvas);
drawFleets(canvas);
drawDragShips(canvas);
drawPointer(canvas);
canvas.restore();
// [...] stuff drawn without matrix transformations, as an overlay
if (mAnimated) {
postInvalidateDelayed(1000 / ANIMATION_FPS);
}
}
示例13: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
final Rect r = new Rect(getBounds());
if (canvas.getClipBounds(sTempRect) && !Rect.intersects(sTempRect, r)) {
// The draw region has been clipped.
return;
}
if (mIndicatorRectDirty) {
initIndicatorRect();
}
final float iconScale;
if ((mAnimationProgress >= ANIMATION_PROGRESS_STARTED)
&& (mAnimationProgress < ANIMATION_PROGRESS_COMPLETED)) {
mPaint.setAlpha((int) ((1 - mAnimationProgress) * 255));
mBgDrawable.setAlpha(mPaint.getAlpha());
mBgDrawable.draw(canvas);
canvas.drawOval(mIndicatorRect, mPaint);
iconScale = ICON_SCALE_FACTOR + (1 - ICON_SCALE_FACTOR) * mAnimationProgress;
} else if (mAnimationProgress == ANIMATION_PROGRESS_STOPPED) {
mPaint.setAlpha(255);
iconScale = ICON_SCALE_FACTOR;
mBgDrawable.setAlpha(255);
mBgDrawable.draw(canvas);
if (mProgress >= 100) {
canvas.drawOval(mIndicatorRect, mPaint);
} else if (mProgress > 0) {
canvas.drawArc(mIndicatorRect, -90, mProgress * 3.6f, false, mPaint);
}
} else {
iconScale = 1;
}
canvas.save();
canvas.scale(iconScale, iconScale, r.exactCenterX(), r.exactCenterY());
mIcon.draw(canvas);
canvas.restore();
}
示例14: drawChild
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result;
final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);
if (mSlideableView != child) { // if main view
// Clip against the slider; no sense drawing what will immediately be covered,
// Unless the panel is set to overlay content
canvas.getClipBounds(mTmpRect);
if (!mOverlayContent) {
if (mIsSlidingUp) {
mTmpRect.bottom = Math.min(mTmpRect.bottom, mSlideableView.getTop());
} else {
mTmpRect.top = Math.max(mTmpRect.top, mSlideableView.getBottom());
}
}
if (mClipPanel) {
canvas.clipRect(mTmpRect);
}
result = super.drawChild(canvas, child, drawingTime);
if (mCoveredFadeColor != 0 && mSlideOffset > 0) {
final int baseAlpha = (mCoveredFadeColor & 0xff000000) >>> 24;
final int imag = (int) (baseAlpha * mSlideOffset);
final int color = imag << 24 | (mCoveredFadeColor & 0xffffff);
mCoveredFadePaint.setColor(color);
canvas.drawRect(mTmpRect, mCoveredFadePaint);
}
} else {
result = super.drawChild(canvas, child, drawingTime);
}
canvas.restoreToCount(save);
return result;
}
示例15: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
// if (isInEditMode()) {
// canvas.drawColor(Color.BLACK);
// return;
// }
//繪製軌道背景
canvas.save();
mPaint.setColor(mTrackBgColor);
int trackLeft = getPaddingLeft();
int trackTop = (getMeasuredHeight() - mTrackHeight) / 2;
int trackRight = getMeasuredWidth() - getPaddingRight();
int trackBottom = getMeasuredHeight() / 2 + mTrackHeight / 2;
mTrackRectF.set(trackLeft, trackTop, trackRight, trackBottom);
canvas.drawRoundRect(mTrackRectF, mTrackRadius, mTrackRadius, mPaint);
canvas.restore();
//第二進度
if (secondProgress > 0) {
canvas.save();
mPaint.setColor(secondProgressColor);
if (thumbType == THUMB_DEFAULT) {
mTrackRectF.set(trackLeft, trackTop, trackLeft + secondProgress / getMaxProgress() * getMaxProgressLength(), trackBottom);
} else if (thumbType == THUMB_CIRCLE) {
mTrackRectF.set(trackLeft, trackTop, trackLeft + secondProgress / getMaxProgress() * getMaxProgressLength(), trackBottom);
}
canvas.drawRoundRect(mTrackRectF, mTrackRadius, mTrackRadius, mPaint);
canvas.restore();
}
//繪製軌道
canvas.save();
mPaint.setColor(mTrackColor);
if (thumbType == THUMB_DEFAULT) {
mTrackRectF.set(trackLeft, trackTop, trackLeft + curProgress / getMaxProgress() * getMaxLength() + mThumbWidth / 2, trackBottom);
} else if (thumbType == THUMB_CIRCLE) {
mTrackRectF.set(trackLeft, trackTop, trackLeft + curProgress / getMaxProgress() * getMaxLength() + mThumbRadius / 2, trackBottom);
}
canvas.drawRoundRect(mTrackRectF, mTrackRadius, mTrackRadius, mPaint);
canvas.restore();
//繪製浮子
updateProgress();
//浮子外圈, 在touch狀態下繪製
if (isTouchDown && thumbType == THUMB_CIRCLE) {
canvas.save();
canvas.getClipBounds(clipBounds);
clipBounds.inset(-mThumbRoundSize * 2, -mThumbRoundSize * 2);
canvas.clipRect(clipBounds, Region.Op.REPLACE);
mPaint.setColor(secondProgressColor);
canvas.drawCircle(mProgressRectF.centerX(), mProgressRectF.centerY(),
mThumbRoundSize + mThumbRoundSize / 2, mPaint);
canvas.restore();
}
//浮子
canvas.save();
mPaint.setColor(mThumbColor);
if (thumbType == THUMB_DEFAULT) {
canvas.drawRoundRect(mProgressRectF, mThumbRoundSize, mThumbRoundSize, mPaint);
} else if (thumbType == THUMB_CIRCLE) {
canvas.drawCircle(mProgressRectF.centerX(), mProgressRectF.centerY(), mThumbHeight / 2, mPaint);
}
canvas.restore();
}