List of usage examples for android.graphics Canvas concat
public void concat(@Nullable Matrix matrix)
From source file:com.android.volley.ui.PhotoView.java
/** * Gets a bitmap of the cropped region. If cropping is not enabled, returns {@code null}. */// ww w . j a v a 2 s .c o m public Bitmap getCroppedPhoto() { if (!mAllowCrop) { return null; } final Bitmap croppedBitmap = Bitmap.createBitmap((int) CROPPED_SIZE, (int) CROPPED_SIZE, Bitmap.Config.ARGB_8888); final Canvas croppedCanvas = new Canvas(croppedBitmap); // scale for the final dimensions final int cropWidth = mCropRect.right - mCropRect.left; final float scaleWidth = CROPPED_SIZE / cropWidth; final float scaleHeight = CROPPED_SIZE / cropWidth; // translate to the origin & scale final Matrix matrix = new Matrix(mDrawMatrix); matrix.postTranslate(-mCropRect.left, -mCropRect.top); matrix.postScale(scaleWidth, scaleHeight); // draw the photo if (mDrawable != null) { croppedCanvas.concat(matrix); mDrawable.draw(croppedCanvas); } return croppedBitmap; }
From source file:org.connectbot.TerminalView.java
@Override public void onDraw(Canvas canvas) { if (bridge.bitmap != null) { // draw the bitmap bridge.onDraw();//w ww . j a v a 2 s . c o m // draw the bridge bitmap if it exists canvas.drawBitmap(bridge.bitmap, 0, 0, paint); // also draw cursor if visible if (bridge.buffer.isCursorVisible()) { int cursorColumn = bridge.buffer.getCursorColumn(); final int cursorRow = bridge.buffer.getCursorRow(); final int columns = bridge.buffer.getColumns(); if (cursorColumn == columns) cursorColumn = columns - 1; if (cursorColumn < 0 || cursorRow < 0) return; int currentAttribute = bridge.buffer.getAttributes(cursorColumn, cursorRow); boolean onWideCharacter = (currentAttribute & VDUBuffer.FULLWIDTH) != 0; int x = cursorColumn * bridge.charWidth; int y = (bridge.buffer.getCursorRow() + bridge.buffer.screenBase - bridge.buffer.windowBase) * bridge.charHeight; // Save the current clip and translation canvas.save(); canvas.translate(x, y); canvas.clipRect(0, 0, bridge.charWidth * (onWideCharacter ? 2 : 1), bridge.charHeight); canvas.drawPaint(cursorPaint); final int deadKey = bridge.getKeyHandler().getDeadKey(); if (deadKey != 0) { canvas.drawText(new char[] { (char) deadKey }, 0, 1, 0, 0, cursorStrokePaint); } // Make sure we scale our decorations to the correct size. canvas.concat(scaleMatrix); int metaState = bridge.getKeyHandler().getMetaState(); if ((metaState & TerminalKeyListener.OUR_SHIFT_ON) != 0) canvas.drawPath(shiftCursor, cursorStrokePaint); else if ((metaState & TerminalKeyListener.OUR_SHIFT_LOCK) != 0) canvas.drawPath(shiftCursor, cursorPaint); if ((metaState & TerminalKeyListener.OUR_ALT_ON) != 0) canvas.drawPath(altCursor, cursorStrokePaint); else if ((metaState & TerminalKeyListener.OUR_ALT_LOCK) != 0) canvas.drawPath(altCursor, cursorPaint); if ((metaState & TerminalKeyListener.OUR_CTRL_ON) != 0) canvas.drawPath(ctrlCursor, cursorStrokePaint); else if ((metaState & TerminalKeyListener.OUR_CTRL_LOCK) != 0) canvas.drawPath(ctrlCursor, cursorPaint); // Restore previous clip region canvas.restore(); } // draw any highlighted area if (bridge.isSelectingForCopy()) { SelectionArea area = bridge.getSelectionArea(); canvas.save(Canvas.CLIP_SAVE_FLAG); canvas.clipRect(area.getLeft() * bridge.charWidth, area.getTop() * bridge.charHeight, (area.getRight() + 1) * bridge.charWidth, (area.getBottom() + 1) * bridge.charHeight); canvas.drawPaint(cursorPaint); canvas.restore(); } } }
From source file:com.guodong.sun.guodong.widget.ZoomImageView.java
@Override protected void onDraw(Canvas canvas) { if (getDrawable() == null) { return; // couldn't resolve the URI }/* ww w. j a v a 2s. c om*/ if (mState == STATE_TRANSFORM_IN || mState == STATE_TRANSFORM_OUT) { if (mTransformStart) { initTransform(); } if (mTransfrom == null) { super.onDraw(canvas); return; } if (mTransformStart) { if (mState == STATE_TRANSFORM_IN) { mTransfrom.initStartIn(); } else { mTransfrom.initStartOut(); } } if (mTransformStart) { Log.d("Dean", "mTransfrom.startScale:" + mTransfrom.startScale); Log.d("Dean", "mTransfrom.startScale:" + mTransfrom.endScale); Log.d("Dean", "mTransfrom.scale:" + mTransfrom.scale); Log.d("Dean", "mTransfrom.startRect:" + mTransfrom.startRect.toString()); Log.d("Dean", "mTransfrom.endRect:" + mTransfrom.endRect.toString()); Log.d("Dean", "mTransfrom.rect:" + mTransfrom.rect.toString()); } mPaint.setAlpha(mBgAlpha); canvas.drawPaint(mPaint); int saveCount = canvas.getSaveCount(); canvas.save(); // ?Matrix getBmpMatrix(); canvas.translate(mTransfrom.rect.left, mTransfrom.rect.top); canvas.clipRect(0, 0, mTransfrom.rect.width, mTransfrom.rect.height); canvas.concat(mSmoothMatrix); getDrawable().draw(canvas); canvas.restoreToCount(saveCount); if (mTransformStart) { mTransformStart = false; startTransform(mState); } } else { //Transform In???Activity?? mPaint.setAlpha(255); canvas.drawPaint(mPaint); super.onDraw(canvas); } }
From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java
/** * MARK: Overrides/*from www . j av a 2s.c om*/ */ @Override protected void onDraw(Canvas canvas) { if (mPathWhite != null && mPathBlack != null) { float textX = Math.max(getPaddingLeft() - (int) (mBubbleWidth / 4.0f), mProgress * mWidth / 100 - (int) (mBubbleWidth / 4.0f)); float textY = mHeight / 2 - mBubbleHeight / 2 + calculateDeltaY(); switch (mState) { case STATE_WORKING: // Save and restore prevent the rest of the canvas to not be rotated canvas.save(); float speed = (getProgress() - mTarget) / 20; mBubbleAngle += speed * 10; if (mBubbleAngle > 20) { mBubbleAngle = 20; } if (mBubbleAngle < -20) { mBubbleAngle = -20; } if (Math.abs(speed) < 1) { mSpeedAngle -= mBubbleAngle / 20; mSpeedAngle *= .9f; } mBubbleAngle += mSpeedAngle; canvas.rotate(mBubbleAngle, bubbleAnchorX, bubbleAnchorY); canvas.drawPath(mPathBubble, mPaintBubble); canvas.drawText(String.valueOf((int) mProgress) + " %", textX, textY, mPaintText); canvas.restore(); break; case STATE_FAILED: canvas.save(); canvas.rotate(mFailAngle, bubbleAnchorX, bubbleAnchorY); canvas.drawPath(mPathBubble, mPaintBubble); canvas.rotate(mFailAngle, bubbleAnchorX, textY - mBubbleHeight / 7); // mPaintText.setColor(getResources().getColor(R.color.red_wine)); textX = Math.max(getPaddingLeft() - (int) (mBubbleWidth / 3.2f), mProgress * mWidth / 100 - (int) (mBubbleWidth / 3.2f)); canvas.drawText(getResources().getString(R.string.failed), textX, textY, mPaintText); canvas.restore(); break; case STATE_SUCCESS: canvas.save(); // mPaintText.setColor(getResources().getColor(R.color.green_grass)); textX = Math.max(getPaddingLeft() - (int) (mBubbleWidth / 3.2f), mProgress * mWidth / 100 - (int) (mBubbleWidth / 3.2f)); Matrix flipMatrix = new Matrix(); flipMatrix.setScale(mFlipFactor, 1, bubbleAnchorX, bubbleAnchorY); canvas.concat(flipMatrix); canvas.drawPath(mPathBubble, mPaintBubble); canvas.concat(flipMatrix); canvas.drawText(getResources().getString(R.string.done), textX, textY, mPaintText); canvas.restore(); break; } canvas.drawPath(mPathBlack, mPaintBlack); canvas.drawPath(mPathWhite, mPaintWhite); } }
From source file:com.tjych.swip.vertical.DirectionalViewPager.java
@Override public void draw(Canvas canvas) { super.draw(canvas); boolean needsInvalidate = false; final int overScrollMode = ViewCompat.getOverScrollMode(this); if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null && mAdapter.getCount() > 1)) { if (!mStartEdge.isFinished()) { final int restoreCount = canvas.save(); if (mOrientation == HORIZONTAL) { final int height = getHeight() - getPaddingTop() - getPaddingBottom(); final int width = getWidth(); canvas.rotate(270);/*from ww w . j ava 2 s . c o m*/ canvas.translate(-height + getPaddingTop(), mFirstOffset * width); mStartEdge.setSize(height, width); } else { final int height = getHeight(); final int width = getWidth() - getPaddingLeft() - getPaddingRight(); canvas.translate(getPaddingLeft(), mFirstOffset * height); mStartEdge.setSize(width, height); } needsInvalidate |= mStartEdge.draw(canvas); canvas.restoreToCount(restoreCount); } if (!mEndEdge.isFinished()) { final int restoreCount = canvas.save(); if (mOrientation == HORIZONTAL) { final int width = getWidth(); final int height = getHeight() - getPaddingTop() - getPaddingBottom(); canvas.rotate(90); canvas.translate(-getPaddingTop(), -(mLastOffset + 1) * width); mEndEdge.setSize(height, width); } else { final int width = getWidth() - getPaddingLeft() - getPaddingRight(); final int height = getHeight(); if (mEndEdgeMatrix == null) { mEndEdgeMatrix = new Matrix(); mEndEdgeMatrix.setScale(1f, -1f); mEndEdgeMatrix.postTranslate(0f, (mLastOffset + 1) * height); } canvas.concat(mEndEdgeMatrix); mEndEdge.setSize(width, height); } needsInvalidate |= mEndEdge.draw(canvas); canvas.restoreToCount(restoreCount); } } else { mStartEdge.finish(); mEndEdge.finish(); } if (needsInvalidate) { // Keep animating ViewCompat.postInvalidateOnAnimation(this); } }
From source file:com.wb.launcher3.Page.java
@Override protected void dispatchDraw(Canvas canvas) { int halfScreenSize = getViewportWidth() / 2; // mOverScrollX is equal to getScrollX() when we're within the normal scroll range. // Otherwise it is equal to the scaled overscroll position. int screenCenter = mOverScrollX + halfScreenSize; if (screenCenter != mLastScreenCenter || mForceScreenScrolled) { // set mForceScreenScrolled before calling screenScrolled so that screenScrolled can // set it for the next frame mForceScreenScrolled = false;// www . j av a 2 s. c o m screenScrolled(screenCenter); mLastScreenCenter = screenCenter; } // Find out which screens are visible; as an optimization we only call draw on them final int pageCount = getChildCount(); if (pageCount > 0) { //*/Modified by tyd Greg 2014-03-20,for transition effect boolean allowed = true; Workspace workspace = null; if (this instanceof Workspace) { workspace = (Workspace) this; allowed = !workspace.isSmall(); } if (TydtechConfig.TYDTECH_DEBUG_FLAG) { Log.d("Greg", "allowed: " + allowed); } /*/ if(!allowed || !TydtechConfig.TRANSITION_EFFECT_ENABLED){ getVisiblePages(mTempVisiblePagesRange); }else{ getVisiblePagesExt(mTempVisiblePagesRange); } //*/ getVisiblePages(mTempVisiblePagesRange); //*/ final int leftScreen = mTempVisiblePagesRange[0]; final int rightScreen = mTempVisiblePagesRange[1]; if (leftScreen != -1 && rightScreen != -1) { final long drawingTime = getDrawingTime(); // Clip to the bounds canvas.save(); canvas.clipRect(getScrollX(), getScrollY(), getScrollX() + getRight() - getLeft(), getScrollY() + getBottom() - getTop()); // Draw all the children, leaving the drag view for last for (int i = pageCount - 1; i >= 0; i--) { final View v = getPageAt(i); if (v == mDragView) continue; if (mForceDrawAllChildrenNextFrame || (leftScreen <= i && i <= rightScreen && shouldDrawChild(v))) { drawChild(canvas, v, drawingTime); } } // Draw the drag view on top (if there is one) if (mDragView != null) { drawChild(canvas, mDragView, drawingTime); } mForceDrawAllChildrenNextFrame = false; canvas.restore(); } //*/Added by TYD Theobald_Wu on 20130223 [begin] for cycle rolling pages if (TydtechConfig.CYCLE_ROLL_PAGES_ENABLED && allowed) { canvas.save(); int width = 0; final int pageW = getViewportWidth(); View v = null; int scrollOffset = (pageW - getChildWidth(0)) / 2; if (mOverScrollX < 0) { int index = pageCount - 1; v = getPageAt(index); width = getViewportOffsetX() - scrollOffset - v.getWidth(); } else if (mOverScrollX > mMaxScrollX) { v = getPageAt(0); width = getViewportOffsetX() + pageW * pageCount + scrollOffset; } if (TydtechConfig.TYDTECH_DEBUG_FLAG) { Log.d("Greg", "width: " + width); Log.d("Greg", "mOverScrollX: " + mOverScrollX); } if (v != null) { canvas.translate(width, v.getY()); canvas.concat(v.getMatrix()); final int w = v.getWidth(); final int h = v.getHeight(); final int sx = v.getScrollX(); final int sy = v.getScrollY(); Rect rect = new Rect(sx, sy, sx + w, sy + h); ///* zhangwuba mark this, user verison lead to screen flash 2014-5-12 //canvas.saveLayerAlpha(sx, sy, sx + w, sy + h, (int) (v.getAlpha() * 255), // Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); //*/ v.draw(canvas); } canvas.restore(); } //*/ } }