List of usage examples for android.graphics Canvas drawBitmap
public void drawBitmap(@NonNull Bitmap bitmap, @Nullable Rect src, @NonNull Rect dst, @Nullable Paint paint)
From source file:com.bannisha.yelian.customview.CirclePageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mViewPager == null) { return;// ww w . ja v a 2s. c o m } final int count = mViewPager.getAdapter().getCount(); if (count == 0) { return; } if (mCurrentPage >= count) { setCurrentItem(count - 1); return; } int imageLongSize = 0; int imageShortSize = 0; int longSize; int longPaddingBefore; int longPaddingAfter; int shortSize; int shortPaddingBefore; if (mOrientation == HORIZONTAL) { if (flag) { imageLongSize = imageBitmap.getWidth(); imageShortSize = imageBitmap.getHeight(); } longSize = getWidth(); shortSize = getHeight(); longPaddingBefore = getPaddingLeft(); longPaddingAfter = getPaddingRight(); shortPaddingBefore = getPaddingTop(); } else { if (flag) { imageShortSize = imageBitmap.getWidth(); imageLongSize = imageBitmap.getHeight(); } longSize = getHeight(); shortSize = getWidth(); longPaddingBefore = getPaddingTop(); longPaddingAfter = getPaddingBottom(); shortPaddingBefore = getPaddingLeft(); } float shortOffset = 0; if (flag) { shortOffset = (shortSize - imageShortSize) / 2; if (rd == 0) { mRadius = imageLongSize * 2; } else { mRadius = rd; } } else { shortOffset = shortPaddingBefore + mRadius; } float threeRadius = mRadius * 3; float longOffset = longPaddingBefore + mRadius; if (mCentered) { longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f); } float dX; float dY; float pageFillRadius = mRadius; if (mPaintStroke.getStrokeWidth() > 0) { pageFillRadius -= mPaintStroke.getStrokeWidth() / 2.0f; } // Draw stroked circles for (int iLoop = 0; iLoop < count; iLoop++) { float drawLong = longOffset + (iLoop * threeRadius); if (mOrientation == HORIZONTAL) { dX = drawLong; dY = shortOffset; } else { dX = shortOffset; dY = drawLong; } // Only paint fill if not completely transparent if (mPaintPageFill.getAlpha() > 0) { if (flag) { canvas.drawBitmap(imageBitmap, dX, dY, mPaintPageFill); } else { canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill); } } // Only paint stroke if a stroke width was non-zero if (pageFillRadius != mRadius) { if (flag) { canvas.drawBitmap(imageBitmap, dX, dY, mPaintStroke); } else { canvas.drawCircle(dX, dY, mRadius, mPaintStroke); } } } // Draw the filled circle according to the current scroll float cx = (mSnap ? mSnapPage : mCurrentPage) * threeRadius; if (!mSnap) { cx += mPageOffset * threeRadius; } if (mOrientation == HORIZONTAL) { dX = longOffset + cx; dY = shortOffset; } else { dX = shortOffset; dY = longOffset + cx; } if (flag) { canvas.drawBitmap(currentImageBitmap, dX, dY, mPaintFill); } else { canvas.drawCircle(dX, dY, mRadius, mPaintFill); } }
From source file:com.example.SmartBoard.DrawingView.java
public void onDrawLine(Canvas canvas) { Paint paint = drawPaint;//from w ww. j a va 2s. co m if (points[1] == null) //point4 null when user did not touch and move on screen. return; //draw stroke paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(5); if (finished) { JSONObject objectProperties = new JSONObject(); String key = UUID.randomUUID().toString(); try { objectProperties.put("id", key); objectProperties.put("clientId", client.getClientId()); objectProperties.put("type", "Line"); objectProperties.put("color", drawPaint.getColor()); objectProperties.put("size", 5); objectProperties.put("startx", linePath.startx()); objectProperties.put("starty", linePath.starty()); objectProperties.put("stopx", linePath.stopx()); objectProperties.put("stopy", linePath.stopy()); objectProperties.put("gradient", linePath.getGradient()); objectProperties.put("length", linePath.length()); } catch (JSONException e) { e.printStackTrace(); } objectDrawables.put(key, objectProperties); mqtt.publishLine(objectProperties); //reset to start drawing again points = new Point[4]; colorballs.clear(); return; } canvas.drawLine(linePath.startx(), linePath.starty(), linePath.stopx(), linePath.stopy(), paint); // draw the balls on the canvas paint.setTextSize(18); paint.setStrokeWidth(0); for (int i = 0; i < colorballs.size(); i++) { ColorBall ball = colorballs.get(i); canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), paint); canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint); } }
From source file:com.android.launcher2.AsyncTaskCallback.java
private Bitmap getShortcutPreview(ResolveInfo info, int maxWidth, int maxHeight) { Bitmap tempBitmap = mCachedShortcutPreviewBitmap.get(); final Canvas c = mCachedShortcutPreviewCanvas.get(); if (tempBitmap == null || tempBitmap.getWidth() != maxWidth || tempBitmap.getHeight() != maxHeight) { tempBitmap = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888); mCachedShortcutPreviewBitmap.set(tempBitmap); } else {/*from w w w.j av a 2s . co m*/ c.setBitmap(tempBitmap); c.drawColor(0, PorterDuff.Mode.CLEAR); c.setBitmap(null); } // Render the icon Drawable icon = mIconCache.getFullResIcon(info); int paddingTop = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top); int paddingLeft = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left); int paddingRight = getResources().getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right); int scaledIconWidth = (maxWidth - paddingLeft - paddingRight); renderDrawableToBitmap(icon, tempBitmap, paddingLeft, paddingTop, scaledIconWidth, scaledIconWidth); Bitmap preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888); c.setBitmap(preview); Paint p = mCachedShortcutPreviewPaint.get(); if (p == null) { p = new Paint(); ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.setSaturation(0); p.setColorFilter(new ColorMatrixColorFilter(colorMatrix)); p.setAlpha((int) (255 * 0.06f)); //float density = 1f; //p.setMaskFilter(new BlurMaskFilter(15*density, BlurMaskFilter.Blur.NORMAL)); mCachedShortcutPreviewPaint.set(p); } c.drawBitmap(tempBitmap, 0, 0, p); c.setBitmap(null); renderDrawableToBitmap(icon, preview, 0, 0, mAppIconSize, mAppIconSize); return preview; }
From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java
private void canvasDraw(Bitmap bitmap, int src_width, int src_height, int startLine, int endLine) { SurfaceHolder surfaceHolder = getHolder(); Surface surface = surfaceHolder.getSurface(); Canvas canvas = null; try {//from www . ja v a 2 s . co m synchronized (surfaceHolder) { boolean isDirty = false; if (mDirtyCount < 3) { mDirtyCount++; isDirty = true; startLine = 0; endLine = src_height; } if (mScale) { mDstRect.set(0, 0, mRenderer.width, mRenderer.height); mSrcRect.set(0, 0, src_width, src_height); mDstRect.offset(mRenderer.x, mRenderer.y); mDirtyRect.set(0, startLine * mRenderer.height / src_height, mRenderer.width, endLine * mRenderer.height / src_height + 1); //locnet, 2011-04-21, a strip on right side not updated mDirtyRect.offset(mRenderer.x, mRenderer.y); } else { //L,T,R,B mSrcRect.set(-mScroll_x, Math.max(-mScroll_y, startLine), mRenderer.mCropWorkspace[2], Math.min(Math.min(getHeight() - mScroll_y, src_height), endLine)); mDstRect.set(0, mSrcRect.top + mScroll_y, mSrcRect.width(), mSrcRect.top + mScroll_y + mSrcRect.height()); if (isLandscape) { mDstRect.offset((getWidth() - mSrcRect.width()) / 2, 0); } else { mDstRect.offset((getWidth() - mSrcRect.width()) / 2, mActionBarHeight); } mDirtyRect.set(mDstRect); } if (surface != null && surface.isValid()) { if (isDirty) { canvas = surfaceHolder.lockCanvas(null); canvas.drawColor(0xff000000); } else { canvas = surfaceHolder.lockCanvas(mDirtyRect); } if (mScale) { canvas.drawBitmap(bitmap, mSrcRect, mDstRect, (mParent.mPrefScaleFilterOn) ? mBitmapPaint : null); } else { canvas.drawBitmap(bitmap, mSrcRect, mDstRect, null); } } } } finally { if (canvas != null && surface != null && surface.isValid()) { surfaceHolder.unlockCanvasAndPost(canvas); } } surfaceHolder = null; }
From source file:com.android.leanlauncher.WidgetPreviewLoader.java
public Bitmap generateWidgetPreview(AppWidgetProviderInfo info, int cellHSpan, int cellVSpan, int maxPreviewWidth, int maxPreviewHeight, Bitmap preview, int[] preScaledWidthOut) { // Load the preview image if possible if (maxPreviewWidth < 0) maxPreviewWidth = Integer.MAX_VALUE; Drawable drawable = null;/*from w w w. j a v a 2 s. c o m*/ if (info.previewImage != 0) { drawable = mManager.loadPreview(info); if (drawable != null) { drawable = mutateOnMainThread(drawable); } else { Log.w(TAG, "Can't load widget preview drawable 0x" + Integer.toHexString(info.previewImage) + " for provider: " + info.provider); } } int previewWidth; int previewHeight; Bitmap defaultPreview = null; boolean widgetPreviewExists = (drawable != null); if (widgetPreviewExists) { previewWidth = drawable.getIntrinsicWidth(); previewHeight = drawable.getIntrinsicHeight(); } else { // Generate a preview image if we couldn't load one if (cellHSpan < 1) cellHSpan = 1; if (cellVSpan < 1) cellVSpan = 1; // This Drawable is not directly drawn, so there's no need to mutate it. BitmapDrawable previewDrawable = (BitmapDrawable) mContext.getResources() .getDrawable(R.drawable.widget_tile); final int previewDrawableWidth = previewDrawable.getIntrinsicWidth(); final int previewDrawableHeight = previewDrawable.getIntrinsicHeight(); previewWidth = previewDrawableWidth * cellHSpan; previewHeight = previewDrawableHeight * cellVSpan; defaultPreview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888); final Canvas c = mCachedAppWidgetPreviewCanvas.get(); c.setBitmap(defaultPreview); Paint p = mDefaultAppWidgetPreviewPaint.get(); if (p == null) { p = new Paint(); p.setShader(new BitmapShader(previewDrawable.getBitmap(), Shader.TileMode.REPEAT, Shader.TileMode.REPEAT)); mDefaultAppWidgetPreviewPaint.set(p); } final Rect dest = mCachedAppWidgetPreviewDestRect.get(); dest.set(0, 0, previewWidth, previewHeight); c.drawRect(dest, p); c.setBitmap(null); // Draw the icon in the top left corner int minOffset = (int) (mAppIconSize * WIDGET_PREVIEW_ICON_PADDING_PERCENTAGE); int smallestSide = Math.min(previewWidth, previewHeight); float iconScale = Math.min((float) smallestSide / (mAppIconSize + 2 * minOffset), 1f); try { Bitmap icon = mIconCache.getIconForComponent(info.configure, UserHandleCompat.myUserHandle()); if (icon != null) { int hoffset = (int) ((previewDrawableWidth - mAppIconSize * iconScale) / 2); int yoffset = (int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2); renderBitmapIconOnPreview(icon, defaultPreview, hoffset, yoffset, (int) (mAppIconSize * iconScale), (int) (mAppIconSize * iconScale)); } } catch (Resources.NotFoundException ignored) { } } // Scale to fit width only - let the widget preview be clipped in the // vertical dimension float scale = 1f; if (preScaledWidthOut != null) { preScaledWidthOut[0] = previewWidth; } if (previewWidth > maxPreviewWidth) { scale = maxPreviewWidth / (float) previewWidth; } if (scale != 1f) { previewWidth = (int) (scale * previewWidth); previewHeight = (int) (scale * previewHeight); } // If a bitmap is passed in, we use it; otherwise, we create a bitmap of the right size if (preview == null) { preview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888); } // Draw the scaled preview into the final bitmap int x = (preview.getWidth() - previewWidth) / 2; if (widgetPreviewExists) { renderDrawableToBitmap(drawable, preview, x, 0, previewWidth, previewHeight); } else { final Canvas c = mCachedAppWidgetPreviewCanvas.get(); final Rect src = mCachedAppWidgetPreviewSrcRect.get(); final Rect dest = mCachedAppWidgetPreviewDestRect.get(); c.setBitmap(preview); src.set(0, 0, defaultPreview.getWidth(), defaultPreview.getHeight()); dest.set(x, 0, x + previewWidth, previewHeight); Paint p = mCachedAppWidgetPreviewPaint.get(); if (p == null) { p = new Paint(); p.setFilterBitmap(true); mCachedAppWidgetPreviewPaint.set(p); } c.drawBitmap(defaultPreview, src, dest, p); c.setBitmap(null); } return preview; }
From source file:com.example.SmartBoard.DrawingView.java
public void onDrawCircle(Canvas canvas) { Paint paint = drawPaint;/*w w w.j a va2 s.c om*/ if (points[3] == null) //point4 null when user did not touch and move on screen. return; int left, top, right, bottom; left = points[0].x; top = points[0].y; right = points[0].x; bottom = points[0].y; for (int i = 1; i < points.length; i++) { left = left > points[i].x ? points[i].x : left; top = top > points[i].y ? points[i].y : top; right = right < points[i].x ? points[i].x : right; bottom = bottom < points[i].y ? points[i].y : bottom; } float cx = (left + right) / 2f; float cy = (top + bottom) / 2f; float radius = (float) Math.hypot(top - bottom, right - left) / 2f; //draw stroke paint.setStyle(Paint.Style.STROKE); // paint.setColor(Color.parseColor("#AADB1255")); paint.setStrokeWidth(5); if (finished) { JSONObject objectProperties = new JSONObject(); String key = UUID.randomUUID().toString(); try { objectProperties.put("id", key); objectProperties.put("type", "Circle"); objectProperties.put("color", drawPaint.getColor()); objectProperties.put("size", 5); objectProperties.put("clientId", client.getClientId()); objectProperties.put("radius", radius); objectProperties.put("x", cx); objectProperties.put("y", cy); } catch (JSONException e) { } objectDrawables.put(key, objectProperties); // drawCanvas.drawCircle(cx, cy, radius, paint); // drawCanvas.save(); // mqtt.publishRectangle(objectProperties); mqtt.publishCircle(objectProperties); //reset to start drawing again points = new Point[4]; colorballs.clear(); return; } canvas.drawCircle(cx, cy, radius, paint); // draw the balls on the canvas // paint.setColor(Color.BLUE); paint.setTextSize(18); paint.setStrokeWidth(0); // paint.setColor(Color.BLUE); for (int i = 0; i < colorballs.size(); i++) { ColorBall ball = colorballs.get(i); canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), paint); canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint); } }
From source file:com.codemx.launcher3.CellLayout.java
@Override protected void onDraw(Canvas canvas) { if (!mIsDragTarget) { return;//from w w w . j a v a 2 s.c om } // When we're large, we are either drawn in a "hover" state (ie when dragging an item to // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) // When we're small, we are either drawn normally or in the "accepts drops" state (during // a drag). However, we also drag the mini hover background *over* one of those two // backgrounds if (mBackgroundAlpha > 0.0f) { mBackground.draw(canvas); } final Paint paint = mDragOutlinePaint; for (int i = 0; i < mDragOutlines.length; i++) { final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Rect r = mDragOutlines[i]; mTempRect.set(r); Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale()); final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); paint.setAlpha((int) (alpha + .5f)); canvas.drawBitmap(b, null, mTempRect, paint); } } if (DEBUG_VISUALIZE_OCCUPIED) { int[] pt = new int[2]; ColorDrawable cd = new ColorDrawable(Color.RED); cd.setBounds(0, 0, mCellWidth, mCellHeight); for (int i = 0; i < mCountX; i++) { for (int j = 0; j < mCountY; j++) { if (mOccupied[i][j]) { cellToPoint(i, j, pt); canvas.save(); canvas.translate(pt[0], pt[1]); cd.draw(canvas); canvas.restore(); } } } } int previewOffset = FolderIcon.FolderRingAnimator.sPreviewSize; // The folder outer / inner ring image(s) DeviceProfile grid = mLauncher.getDeviceProfile(); for (int i = 0; i < mFolderOuterRings.size(); i++) { FolderIcon.FolderRingAnimator fra = mFolderOuterRings.get(i); Drawable d; int width, height; cellToPoint(fra.mCellX, fra.mCellY, mTempLocation); View child = getChildAt(fra.mCellX, fra.mCellY); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; // Draw outer ring, if it exists if (FolderIcon.HAS_OUTER_RING) { d = FolderIcon.FolderRingAnimator.sSharedOuterRingDrawable; width = (int) (fra.getOuterRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - height / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } // Draw inner ring d = FolderIcon.FolderRingAnimator.sSharedInnerRingDrawable; width = (int) (fra.getInnerRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) { Drawable d = FolderIcon.sSharedFolderLeaveBehind; int width = d.getIntrinsicWidth(); int height = d.getIntrinsicHeight(); cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation); View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } }
From source file:com.android.mail.browse.ConversationItemView.java
@Override protected void onDraw(Canvas canvas) { if (mCoordinates == null) { LogUtils.e(LOG_TAG, "null coordinates in ConversationItemView#onDraw"); return;/*from w ww . ja v a2 s . c om*/ } Utils.traceBeginSection("CIVC.draw"); // Contact photo if (mGadgetMode == ConversationItemViewCoordinates.GADGET_CONTACT_PHOTO) { canvas.save(); Utils.traceBeginSection("draw senders image"); drawSendersImage(canvas); Utils.traceEndSection(); canvas.restore(); } // Senders. boolean isUnread = mHeader.unread; // Old style senders; apply text colors/ sizes/ styling. canvas.save(); if (mHeader.sendersDisplayLayout != null) { sPaint.setTextSize(mCoordinates.sendersFontSize); sPaint.setTypeface(SendersView.getTypeface(isUnread)); sPaint.setColor(sSendersTextColor); canvas.translate(mSendersX, mCoordinates.sendersY + mHeader.sendersDisplayLayout.getTopPadding()); mHeader.sendersDisplayLayout.draw(canvas); } else { drawSenders(canvas); } canvas.restore(); // Subject. sPaint.setTypeface(Typeface.DEFAULT); canvas.save(); drawSubject(canvas); canvas.restore(); canvas.save(); drawSnippet(canvas); canvas.restore(); // Folders. if (mConfig.areFoldersVisible()) { mHeader.folderDisplayer.drawFolders(canvas, mCoordinates, ViewUtils.isViewRtl(this)); } // If this folder has a color (combined view/Email), show it here if (mConfig.isColorBlockVisible()) { sFoldersPaint.setColor(mHeader.conversation.color); sFoldersPaint.setStyle(Paint.Style.FILL); canvas.drawRect(mCoordinates.colorBlockX, mCoordinates.colorBlockY, mCoordinates.colorBlockX + mCoordinates.colorBlockWidth, mCoordinates.colorBlockY + mCoordinates.colorBlockHeight, sFoldersPaint); } // Draw the reply state. Draw nothing if neither replied nor forwarded. if (mConfig.isReplyStateVisible()) { if (mHeader.hasBeenRepliedTo && mHeader.hasBeenForwarded) { canvas.drawBitmap(STATE_REPLIED_AND_FORWARDED, mCoordinates.replyStateX, mCoordinates.replyStateY, null); } else if (mHeader.hasBeenRepliedTo) { canvas.drawBitmap(STATE_REPLIED, mCoordinates.replyStateX, mCoordinates.replyStateY, null); } else if (mHeader.hasBeenForwarded) { canvas.drawBitmap(STATE_FORWARDED, mCoordinates.replyStateX, mCoordinates.replyStateY, null); } else if (mHeader.isInvite) { canvas.drawBitmap(STATE_CALENDAR_INVITE, mCoordinates.replyStateX, mCoordinates.replyStateY, null); } } if (mConfig.isPersonalIndicatorVisible()) { canvas.drawBitmap(mHeader.personalLevelBitmap, mCoordinates.personalIndicatorX, mCoordinates.personalIndicatorY, null); } // Info icon if (mHeader.infoIcon != null) { canvas.drawBitmap(mHeader.infoIcon, mInfoIconX, mCoordinates.infoIconY, sPaint); } // Date. sPaint.setTextSize(mCoordinates.dateFontSize); sPaint.setTypeface(isUnread ? SANS_SERIF_BOLD : SANS_SERIF_LIGHT); sPaint.setColor(isUnread ? sDateTextColorUnread : sDateTextColorRead); drawText(canvas, mHeader.dateText, mDateX, mCoordinates.dateYBaseline, sPaint); // Paper clip icon. if (mHeader.paperclip != null) { canvas.drawBitmap(mHeader.paperclip, mPaperclipX, mCoordinates.paperclipY, sPaint); } // Star. if (mStarEnabled) { canvas.drawBitmap(getStarBitmap(), mCoordinates.starX, mCoordinates.starY, sPaint); } // Divider. if (mDividerEnabled) { final int dividerBottomY = getHeight(); final int dividerTopY = dividerBottomY - sDividerHeight; canvas.drawRect(0, dividerTopY, getWidth(), dividerBottomY, sDividerPaint); } // The focused bar final SwipeableListView listView = getListView(); if (listView != null && listView.isConversationSelected(getConversation())) { final int w = FOCUSED_CONVERSATION_HIGHLIGHT.getIntrinsicWidth(); final boolean isRtl = ViewUtils.isViewRtl(this); // This bar is on the right side of the conv list if it's RTL FOCUSED_CONVERSATION_HIGHLIGHT.setBounds((isRtl) ? getWidth() - w : 0, 0, (isRtl) ? getWidth() : w, getHeight()); FOCUSED_CONVERSATION_HIGHLIGHT.draw(canvas); } Utils.traceEndSection(); }
From source file:com.android.launcher3.CellLayout.java
@Override protected void onDraw(Canvas canvas) { if (!mIsDragTarget) { return;//w ww . j a v a 2s.com } // When we're large, we are either drawn in a "hover" state (ie when dragging an item to // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f) // When we're small, we are either drawn normally or in the "accepts drops" state (during // a drag). However, we also drag the mini hover background *over* one of those two // backgrounds if (mBackgroundAlpha > 0.0f) { mBackground.draw(canvas); } final Paint paint = mDragOutlinePaint; for (int i = 0; i < mDragOutlines.length; i++) { final float alpha = mDragOutlineAlphas[i]; if (alpha > 0) { final Rect r = mDragOutlines[i]; mTempRect.set(r); Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale()); final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag(); paint.setAlpha((int) (alpha + .5f)); canvas.drawBitmap(b, null, mTempRect, paint); } } if (DEBUG_VISUALIZE_OCCUPIED) { int[] pt = new int[2]; ColorDrawable cd = new ColorDrawable(Color.RED); cd.setBounds(0, 0, mCellWidth, mCellHeight); for (int i = 0; i < mCountX; i++) { for (int j = 0; j < mCountY; j++) { if (mOccupied[i][j]) { cellToPoint(i, j, pt); canvas.save(); canvas.translate(pt[0], pt[1]); cd.draw(canvas); canvas.restore(); } } } } int previewOffset = FolderRingAnimator.sPreviewSize; // The folder outer / inner ring image(s) DeviceProfile grid = mLauncher.getDeviceProfile(); for (int i = 0; i < mFolderOuterRings.size(); i++) { FolderRingAnimator fra = mFolderOuterRings.get(i); Drawable d; int width, height; cellToPoint(fra.mCellX, fra.mCellY, mTempLocation); View child = getChildAt(fra.mCellX, fra.mCellY); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; // Draw outer ring, if it exists if (FolderIcon.HAS_OUTER_RING) { d = FolderRingAnimator.sSharedOuterRingDrawable; width = (int) (fra.getOuterRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - height / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } // Draw inner ring d = FolderRingAnimator.sSharedInnerRingDrawable; width = (int) (fra.getInnerRingSize() * getChildrenScale()); height = width; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) { Drawable d = FolderIcon.sSharedFolderLeaveBehind; int width = d.getIntrinsicWidth(); int height = d.getIntrinsicHeight(); cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation); View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]); if (child != null) { int centerX = mTempLocation[0] + mCellWidth / 2; int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset; canvas.save(); canvas.translate(centerX - width / 2, centerY - width / 2); d.setBounds(0, 0, width, height); d.draw(canvas); canvas.restore(); } } }
From source file:com.example.SmartBoard.DrawingView.java
public void onDrawRectangle(Canvas canvas) { Paint paint = drawPaint;// w w w . java 2s . com if (points[3] == null) //point4 null when user did not touch and move on screen. return; int left, top, right, bottom; left = points[0].x; top = points[0].y; right = points[0].x; bottom = points[0].y; for (int i = 1; i < points.length; i++) { left = left > points[i].x ? points[i].x : left; top = top > points[i].y ? points[i].y : top; right = right < points[i].x ? points[i].x : right; bottom = bottom < points[i].y ? points[i].y : bottom; } //draw stroke paint.setStyle(Paint.Style.STROKE); // paint.setColor(Color.parseColor("#AADB1255")); paint.setStrokeWidth(5); if (finished) { Rect rect = new Rect(left + colorballs.get(0).getWidthOfBall() / 2, top + colorballs.get(0).getWidthOfBall() / 2, right + colorballs.get(2).getWidthOfBall() / 2, bottom + colorballs.get(2).getWidthOfBall() / 2); JSONObject objectProperties = new JSONObject(); String key = UUID.randomUUID().toString(); try { objectProperties.put("type", "Rectangle"); objectProperties.put("clientId", client.getClientId()); objectProperties.put("id", key); objectProperties.put("color", drawPaint.getColor()); objectProperties.put("size", 5); objectProperties.put("dimens", rect.flattenToString()); } catch (JSONException e) { } objectDrawables.put(key, objectProperties); mqtt.publishRectangle(objectProperties); //reset to start drawing again points = new Point[4]; colorballs.clear(); return; } //temporary canvas drawing on resize mode canvas.drawRect(left + colorballs.get(0).getWidthOfBall() / 2, top + colorballs.get(0).getWidthOfBall() / 2, right + colorballs.get(2).getWidthOfBall() / 2, bottom + colorballs.get(2).getWidthOfBall() / 2, paint); //draw the corners BitmapDrawable bitmap = new BitmapDrawable(); // draw the balls on the canvas paint.setTextSize(18); paint.setStrokeWidth(0); for (int i = 0; i < colorballs.size(); i++) { ColorBall ball = colorballs.get(i); canvas.drawBitmap(ball.getBitmap(), ball.getX(), ball.getY(), paint); // System.out.println("RectMode"); canvas.drawText("" + (i + 1), ball.getX(), ball.getY(), paint); } }