Example #1
0
  @SuppressWarnings("deprecation")
  public Preview(Context context, Camera camera) {
    super(context);
    mCamera = camera;

    // Install a SurfaceHolder.Callback so we get notified when the
    // underlying surface is created and destroyed.
    mHolder = getHolder();
    mHolder.addCallback(this);
    // deprecated setting, but required on Android versions prior to 3.0
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  }
Example #2
0
  public FlxGameView(FlxGame game, Context context, AttributeSet attrs) {
    super(context, attrs);

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);

    this.activity = (Activity) context;

    this.game = game;

    this.setFocusable(true);
    this.setFocusableInTouchMode(true);
  }
Example #3
0
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    // If your preview can change or rotate, take care of those events here.
    // Make sure to stop the preview before resizing or reformatting it.

    if (mHolder.getSurface() == null) {
      // preview surface does not exist
      return;
    }

    // stop preview before making changes
    try {
      mCamera.stopPreview();

      Log.v(TAG, "stopPreview");

      googleGlassXE10WorkAround(mCamera);

    } catch (Exception e) {
      // ignore: tried to stop a non-existent preview
      Log.d(TAG, "Tried to stop a non-existent preview: " + e.getMessage());
    }

    // start preview with new settings
    try {
      mCamera.setPreviewDisplay(mHolder);
      mCamera.startPreview();
      Log.v(TAG, "startPreview");

    } catch (Exception e) {
      Log.d(TAG, "Error starting camera preview: " + e.getMessage());
    }
  }
Example #4
0
 @Override
 public void run() {
   while (running) {
     Canvas c = null;
     try {
       c = surfaceHolder.lockCanvas(null);
       synchronized (surfaceHolder) {
         if (!game.onEnterFrame(c)) {
           running = false;
           game.shutdown(true);
           view.shutdown();
         }
       }
     } 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);
       }
     }
   }
 }