List of usage examples for android.view SurfaceHolder unlockCanvasAndPost
public void unlockCanvasAndPost(Canvas canvas);
From source file:Main.java
public static synchronized void cleansurfaceview(SurfaceHolder postureholder, SurfaceView posturesurface) { Canvas canvas = postureholder .lockCanvas(new Rect(0, 0, posturesurface.getWidth(), posturesurface.getHeight())); canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); postureholder.unlockCanvasAndPost(canvas); Canvas canvasa = postureholder .lockCanvas(new Rect(0, 0, posturesurface.getWidth(), posturesurface.getHeight())); canvasa.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); postureholder.unlockCanvasAndPost(canvasa); }
From source file:com.android.screenspeak.contextmenu.RadialMenuView.java
@Override public void invalidate() { super.invalidate(); final SurfaceHolder holder = mHolder; if (holder == null) { return;//from ww w .ja v a 2s . c om } final Canvas canvas = holder.lockCanvas(); if (canvas == null) { return; } // Clear the canvas. canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR); if (getVisibility() != View.VISIBLE) { holder.unlockCanvasAndPost(canvas); return; } final int width = getWidth(); final int height = getHeight(); if (!mDisplayWedges) { mCenter.x = (width / 2.0f); mCenter.y = (height / 2.0f); } // Draw the pretty gradient background. mGradientBackground.setGradientCenter((mCenter.x / width), (mCenter.y / height)); mGradientBackground.setBounds(0, 0, width, height); mGradientBackground.draw(canvas); final RadialMenu menu = (mSubMenu != null) ? mSubMenu : mRootMenu; final float center = mExtremeRadius; if (mDisplayWedges) { final int wedges = menu.size(); final float degrees = 360.0f / wedges; // Refresh cached wedge shapes if necessary. if (0 != menu.size()) { invalidateCachedWedgeShapes(); } // Draw the cancel dot. drawCancel(canvas); // Draw wedges. for (int i = 0; i < wedges; i++) { drawWedge(canvas, center, i, menu, degrees); } } else { // Draw the center dot. drawCenterDot(canvas, width, height); } // Draw corners. for (int i = 0; i < 4; i++) { drawCorner(canvas, width, height, center, i); } holder.unlockCanvasAndPost(canvas); }
From source file:com.googlecode.eyesfree.widget.RadialMenuView.java
@Override public void invalidate() { super.invalidate(); final SurfaceHolder holder = mHolder; if (holder == null) { return;/* w ww. ja v a 2 s . c om*/ } final Canvas canvas = holder.lockCanvas(); if (canvas == null) { return; } // Clear the canvas. canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR); if (getVisibility() != View.VISIBLE) { holder.unlockCanvasAndPost(canvas); return; } final int width = getWidth(); final int height = getHeight(); if (!mDisplayWedges) { mCenter.x = (width / 2.0f); mCenter.y = (height / 2.0f); } // Draw the pretty gradient background. mGradientBackground.setGradientCenter((mCenter.x / width), (mCenter.y / height)); mGradientBackground.setBounds(0, 0, width, height); mGradientBackground.draw(canvas); final RadialMenu menu = (mSubMenu != null) ? mSubMenu : mRootMenu; final float center = mExtremeRadius; if (mDisplayWedges) { final int wedges = menu.size(); final float degrees = 360.0f / wedges; // Refresh cached wedge shapes if necessary. if (mCachedMenuSize != menu.size()) { invalidateCachedWedgeShapes(); } // Draw the cancel dot. drawCancel(canvas, width, height, center); // Draw wedges. for (int i = 0; i < wedges; i++) { drawWedge(canvas, width, height, center, i, menu, degrees); } } else { // Draw the center dot. drawCenterDot(canvas, width, height); } // Draw corners. for (int i = 0; i < 4; i++) { drawCorner(canvas, width, height, center, i); } holder.unlockCanvasAndPost(canvas); }
From source file:org.medcare.Dicom.DicomActivity.java
public void delDicom(SurfaceHolder surfaceHolder) { Log.i(TAG, "debut traitement DEL"); curentImageController = dicomView.getCurrentImageController(); if (curentImageController == null) return;/* w w w .ja v a 2 s .c o m*/ dicomView.imageControllers.remove(curentImageController); int index = dicomView.imageControllers.size() - 1; Canvas c = null; try { if (index >= 0) { curentImageController = dicomView.imageControllers.get(dicomView.imageControllers.size() - 1); curentImageController.setChange(true); } else { curentImageController = null; c = surfaceHolder.lockCanvas(null); synchronized (surfaceHolder) { dicomView.clear(c); } } } finally { // do this in a finally so that if an exception is // thrown // during the above, we don't leave the Surface in an // inconsistent state if (c != null) { surfaceHolder.unlockCanvasAndPost(c); } } }
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;/*from w w w. j a v a 2 s . c o m*/ try { 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; }