List of usage examples for android.view SurfaceHolder lockCanvas
public Canvas lockCanvas();
From source file:com.android.screenspeak.contextmenu.RadialMenuView.java
@Override public void invalidate() { super.invalidate(); final SurfaceHolder holder = mHolder; if (holder == null) { return;//w w w .ja v a2 s.c o m } 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;/*from ww w . ja va 2 s .c o m*/ } 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); }