FPS30で10px広がっていきます。 FPSManagerクラスはこちらより利用させていただきました。
ありがたや、ありがたや。
public class WipeView extends SurfaceView implements SurfaceHolder.Callback{ private int viewWidth; private int viewHeight; private Paint paint; private int radius = 0; private Thread wipeAnimation; private FPSManager manage = new FPSManager(30); public WipeView(Context context) { super(context); init(); } public WipeView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public WipeView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } public void init(){ //背景を透過するため getHolder().setFormat(PixelFormat.TRANSLUCENT); getHolder().addCallback(this); setZOrderOnTop(true); } @Override public void surfaceCreated(SurfaceHolder holder) { wipeAnimation = new Thread(wipeZoomIn); wipeAnimation.start(); } @Override protected void onDraw(Canvas canvas){ super.onDraw(canvas); this.viewHeight = canvas.getHeight(); this.viewWidth = canvas.getWidth(); //前フレームの描画をクリア canvas.drawColor(0, PorterDuff.Mode.CLEAR); //くり抜く円のパス Path clip = new Path(); clip.addCircle(viewWidth/2, viewHeight/2, radius, Path.Direction.CW); canvas.clipPath(clip, Op.DIFFERENCE); paint = new Paint(); paint.setColor(Color.BLACK); canvas.drawPaint(paint); Log.d("debug", "radius = " + radius); } Runnable wipeZoomIn = new Runnable(){ @Override public void run() { SurfaceHolder holder = getHolder(); try{ while(wipeAnimation != null){ TimeUnit.NANOSECONDS.sleep(manage.state()); Canvas canvas = holder.lockCanvas(); if(canvas != null){ radius += 10; onDraw(canvas); holder.unlockCanvasAndPost(canvas); if(radius >= viewWidth){ break; } } } }catch(Exception e){ } return; } }; @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } @Override public void surfaceDestroyed(SurfaceHolder holder) { wipeAnimation = null; } }
0 件のコメント:
コメントを投稿