Example usage for android.hardware Camera getClass

List of usage examples for android.hardware Camera getClass

Introduction

In this page you can find the example usage for android.hardware Camera getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.TaxiDriver.jy.CameraPreview.java

protected void setDisplayOrientation(Camera camera, int angle) {
    Method downPolymorphic;//from  www  .  j av a2s.c  o m
    try {
        downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class });
        if (downPolymorphic != null)
            downPolymorphic.invoke(camera, new Object[] { angle });
    } catch (Exception e1) {
    }
}

From source file:com.googlecode.android_scripting.facade.CameraFacade.java

@Rpc(description = "Take a picture and save it to the specified path.", returns = "A map of Booleans autoFocus and takePicture where True "
        + "indicates success. cameraId also included.")
public Bundle cameraCapturePicture(@RpcParameter(name = "targetPath") final String targetPath,
        @RpcParameter(name = "useAutoFocus") @RpcDefault("true") Boolean useAutoFocus,
        @RpcParameter(name = "cameraId", description = "Id of camera to use. SDK 9") @RpcDefault("0") Integer cameraId)
        throws Exception {
    final BooleanResult autoFocusResult = new BooleanResult();
    final BooleanResult takePictureResult = new BooleanResult();
    Camera camera = openCamera(cameraId);
    if (camera == null) {
        String msg = String.format("can't initialize camera id %d, try to use another id", cameraId);
        Log.e(msg);/*from w w  w .  j  a v  a2s .co  m*/

        Bundle result = new Bundle();
        result.putInt("cameraId", cameraId);
        result.putBoolean("autoFocus", false);
        result.putBoolean("takePicture", false);
        result.putString("reason", msg + ", see logcat for details");
        return result;
    }
    Parameters prm = camera.getParameters();
    camera.setParameters(prm);

    try {
        Method method = camera.getClass().getMethod("setDisplayOrientation", int.class);
        method.invoke(camera, 90);
    } catch (Exception e) {
        Log.e(e);
    }

    try {
        FutureActivityTask<SurfaceHolder> previewTask = setPreviewDisplay(camera);
        camera.startPreview();
        if (useAutoFocus) {
            autoFocus(autoFocusResult, camera);
        }
        takePicture(new File(targetPath), takePictureResult, camera);
        previewTask.finish();
    } catch (Exception e) {
        Log.e(e);
    } finally {
        camera.release();
    }

    Bundle result = new Bundle();
    result.putBoolean("autoFocus", autoFocusResult.mmResult);
    result.putBoolean("takePicture", takePictureResult.mmResult);
    result.putInt("cameraId", cameraId);
    return result;
}