Java Code Examples for android.view.SurfaceHolder.unlockCanvasAndPost()

The following are Jave code examples for showing how to use unlockCanvasAndPost() of the android.view.SurfaceHolder class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: fingerblox   File: MainActivity.java   Source Code and License Vote up 12 votes
private void processFrame(Mat frame) {

        Canvas canvas = null;
        SurfaceHolder holder = mCameraProcessPreview.getHolder();

        try {
            canvas = holder.lockCanvas(null);
            if (canvas != null) {
                Bitmap result = ImageProcessing.preprocess(frame, mOpenCvCameraView.getWidth(), mOpenCvCameraView.getHeight());
                canvas.drawBitmap(result, 0, 0, new Paint());
            }
        } finally {
            if (canvas != null) {
                holder.unlockCanvasAndPost(canvas);
            }
        }
    }
 
Example 2
Project: homescreenarcade   File: BlockDropWallpaper.java   Source Code and License Vote up 6 votes
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    super.onSurfaceChanged(holder, format, width, height);
    if (DOLOG)
        Log.d(TAG, "onSurfaceChanged: width = [" + width + "], height = [" + height + "]");

    display = new Display(BlockDropWallpaper.this);

    if (height > width) {
        scale = (float) width / (float) height;
        yCenter = height / 2f;
    } else {
        scale = 0.8f;
        yCenter = (height / scale) / (2f * scale);
    }
    xCenter = width / 2f;

    if (getState() != STATE_PAUSED) {
        // Manually redraw with the new dimensions (it won't redraw automatically when paused)
        Canvas canvas = holder.lockCanvas();
        draw(canvas);
        holder.unlockCanvasAndPost(canvas);
    }
}
 
Example 3
Project: pixelwallpaper   File: PixelWallpaperService.java   Source Code and License Vote up 6 votes
@Override
public void onTouchEvent(MotionEvent event) {

	if (touchmode != 0) {

		double x = event.getX();
		double y = event.getY();

		pa.touch(x, y);
		SurfaceHolder holder = getSurfaceHolder();
		Canvas canvas = null;
		try {
			canvas = holder.lockCanvas();
			if (canvas != null) {
				pa.draw(canvas);
			}
		} finally {
			if (canvas != null)
				holder.unlockCanvasAndPost(canvas);
		}

		super.onTouchEvent(event);
	}
}
 
Example 4
Project: pixelwallpaper   File: PixelWallpaperService.java   Source Code and License Vote up 6 votes
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
	if((this.width != width || this.height != height)) {
		this.width = width;
		this.height = height;
		pa.reinitialize(width, height);

		Canvas canvas = null;

		try {
			canvas = holder.lockCanvas();

			if (canvas != null) {

				pa.draw(canvas);
			}
		} finally {
			if (canvas != null)
				holder.unlockCanvasAndPost(canvas);
		}

	}

}
 
Example 5
Project: pixelwallpaper   File: PixelWallpaperService.java   Source Code and License Vote up 6 votes
private void draw() {

			SurfaceHolder holder = getSurfaceHolder();
			Canvas canvas = null;

			pa.update();

			try {
				canvas = holder.lockCanvas();

				if (canvas != null) {

					pa.draw(canvas);
				}
			} finally {
				if (canvas != null)
					holder.unlockCanvasAndPost(canvas);
			}
			handler.removeCallbacks(drawRunner);
			if (isVisible()) {
				handler.postDelayed(drawRunner, framerate);
			}

		}
 
Example 6
Project: AndroidUvcCameras   File: CameraPreviewV4L.java   Source Code and License Vote up 6 votes
@Override
  public void surfaceCreated(SurfaceHolder holder) {
      Canvas canvas = holder.lockCanvas();
      if (canvas != null) {
          canvas.drawRGB(0, 0, 0);
          holder.unlockCanvasAndPost(canvas);
      }
if (cameraHandle == 0) {
	V4lJni.setRotate(mCameraId, 2); // 0��ʱ��90�ȣ� 1˳ʱ��90�ȣ� 2����ת, 3��ת180��
	cameraHandle = V4lJni.openCameraExt(mCameraId, 1280, 960, 0);
}
      // ������Ƶ�߳̿�ʼ
      this.shouldStop = false;
      this.mainLoop = new Thread(this);
      this.mainLoop.start();
  }
 
Example 7
Project: buildAPKsSamples   File: CubeWallpaper2.java   Source Code and License Vote up 6 votes
void drawFrame() {
    final SurfaceHolder holder = getSurfaceHolder();
    final Rect frame = holder.getSurfaceFrame();
    final int width = frame.width();
    final int height = frame.height();

    Canvas c = null;
    try {
        c = holder.lockCanvas();
        if (c != null) {
            // draw something
            drawCube(c);
            drawTouchPoint(c);
        }
    } finally {
        if (c != null) holder.unlockCanvasAndPost(c);
    }

    mHandler.removeCallbacks(mDrawCube);
    if (mVisible) {
        mHandler.postDelayed(mDrawCube, 1000 / 25);
    }
}
 
Example 8
Project: buildAPKsSamples   File: CubeWallpaper1.java   Source Code and License Vote up 6 votes
void drawFrame() {
    final SurfaceHolder holder = getSurfaceHolder();

    Canvas c = null;
    try {
        c = holder.lockCanvas();
        if (c != null) {
            // draw something
            drawCube(c);
            drawTouchPoint(c);
        }
    } finally {
        if (c != null) holder.unlockCanvasAndPost(c);
    }

    // Reschedule the next redraw
    mHandler.removeCallbacks(mDrawCube);
    if (mVisible) {
        mHandler.postDelayed(mDrawCube, 1000 / 25);
    }
}
 
Example 9
Project: chameleon-live-wallpaper   File: ChameleonWallpaperService.java   Source Code and License Vote up 6 votes
private void draw() {
    final SurfaceHolder holder = getSurfaceHolder();
    Canvas canvas = null;
    try {
        canvas = holder.lockCanvas();
        if (canvas != null) {
            // Draw the frame here.
            drawFrame(canvas);
        }
    } finally {
        if (canvas != null) {
            holder.unlockCanvasAndPost(canvas);
        }
    }
    handler.removeCallbacks(drawRunnable);
    if (visible) {
        handler.postDelayed(drawRunnable, 5000);
    }
}
 
Example 10
Project: LivingBurger   File: JumpingBurger.java   Source Code and License Vote up 5 votes
/**
 * Draw
 */
private void draw() {
    long t = System.currentTimeMillis();
    SurfaceHolder holder = getSurfaceHolder();
    Canvas canvas = null;
    try {
        canvas = holder.lockCanvas();
        canvas.drawColor(backgroundColor);
        if (useBackgroundImage) {
            tilingAndDraw(backgroundImage, canvas);
        }
        for (ToDraw actual : objects) {
            doubles.clear();
            moveObject(actual, t - time);
            //draw the doubles before the reel objects, to keep the screen from flashing!
            for (ToDraw td : doubles) {
                drawOnCanvas(td, canvas);
            }
            drawOnCanvas(actual, canvas);
        }
    } finally {
        if (canvas != null) {
            holder.unlockCanvasAndPost(canvas);
        }
    }
    time = t;
    handler.removeCallbacks(drawRunner);
    if (visibility) {
        handler.postDelayed(drawRunner, sleepBetweenRedraws);
    }
}
 
Example 11
Project: AndroidUvcCameras   File: CameraPreviewUVC.java   Source Code and License Vote up 5 votes
@Override
public void surfaceCreated(SurfaceHolder holder) {
    mUsbMonitor.register();
    mUsbMonitor.requestPermission(getCamDev(mCameraId));

    Canvas canvas = holder.lockCanvas();
    if (canvas != null) {
        canvas.drawRGB(0, 0, 0);
        holder.unlockCanvasAndPost(canvas);
    }
    
    this.shouldStop = false;
    this.mainLoop = new Thread(this);
    this.mainLoop.start();
}
 
Example 12
Project: letv   File: DanmakuSurfaceView.java   Source Code and License Vote up 5 votes
public void surfaceCreated(SurfaceHolder surfaceHolder) {
    this.isSurfaceCreated = true;
    Canvas canvas = surfaceHolder.lockCanvas();
    if (canvas != null) {
        DrawHelper.clearCanvas(canvas);
        surfaceHolder.unlockCanvasAndPost(canvas);
    }
}
 
Example 13
Project: HexColorTime   File: Wallpaper.java   Source Code and License Vote up 5 votes
private void draw() {
    SurfaceHolder surfaceHolder = getSurfaceHolder();
    Canvas canvas = null;
    Calendar ca = Calendar.getInstance();
    try {
        canvas = surfaceHolder.lockCanvas();

        if (canvas != null) {

            paint.setTypeface(getTypeface());
            paint.setAntiAlias(true);
            paint.setTextAlign(Paint.Align.CENTER);
            paint.setTextSize(TextSizePreference.getValue());

            int xPos = (canvas.getWidth() / 2);
            int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)) ;

            canvas.drawColor(Color.parseColor(getTimeColor(ca)));

            canvas.drawText(getTimeText(ca), xPos, yPos, paint);
        }
    }
    finally {
        if(canvas != null) {
            surfaceHolder.unlockCanvasAndPost(canvas);
        }
    }
    handler.removeCallbacks(runnable);

    if(visible) {
        handler.postDelayed(runnable, 100);
    }
}
 
Example 14
Project: LiveWallpaper   File: LiveWallpaperView.java   Source Code and License Vote up 5 votes
private void drawSurfaceView(SurfaceHolder holder) {
    if (this.mNextBitmap != null && !this.mNextBitmap.isRecycled()) {
        Canvas localCanvas = holder.lockCanvas();
        if (localCanvas != null) {
            Rect rect = new Rect();
            rect.left = rect.top = 0;
            rect.bottom = localCanvas.getHeight();
            rect.right = localCanvas.getWidth();
            localCanvas.drawBitmap(this.mNextBitmap, null, rect, this.mPaint);
            holder.unlockCanvasAndPost(localCanvas);
        }
    }
}
 
Example 15
Project: live_master   File: DanmakuSurfaceView.java   Source Code and License Vote up 5 votes
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
    isSurfaceCreated = true;
    Canvas canvas = surfaceHolder.lockCanvas();
    if (canvas != null) {
        DrawHelper.clearCanvas(canvas);
        surfaceHolder.unlockCanvasAndPost(canvas);
    }
}
 
Example 16
Project: Asteroid   File: BackgroundService.java   Source Code and License Vote up 4 votes
private void draw(SurfaceHolder holder) {
    if (holder == null || !holder.getSurface().isValid())
        return;

    Canvas canvas;
    try {
        canvas = holder.lockCanvas();
        if (canvas == null) return;
    } catch (Exception e) {
        return;
    }

    canvas.drawColor(Color.BLACK);

    for (ParticleData particle : new ArrayList<>(particles)) {
        Rect rect = particle.next(particleSpeed, canvas.getWidth(), canvas.getHeight());
        if (rect != null)
            canvas.drawRect(rect, particle.isAccent ? accentPaint : paint);
        else particles.remove(particle);
    }

    particles.add(new ParticleData());

    if (isAsteroids) {
        for (AsteroidData asteroid : new ArrayList<>(asteroids)) {
            Matrix matrix = asteroid.next(asteroidSpeed, canvas.getWidth(), canvas.getHeight());
            if (matrix != null) {
                canvas.drawBitmap(asteroid.asteroidBitmap, matrix, paint);
            } else asteroids.remove(asteroid);
        }

        if (System.currentTimeMillis() - asteroidTime > asteroidInterval) {
            asteroidTime = System.currentTimeMillis();
            asteroids.add(new AsteroidData(Math.round(Math.random()) == 0 ? asteroidBitmap : asteroidBitmap2));
        }
    }

    holder.unlockCanvasAndPost(canvas);

    handler.removeCallbacks(runnable);
    handler.postDelayed(runnable, 10);
}