Example usage for android.hardware Camera.Parameters getClass

List of usage examples for android.hardware Camera.Parameters getClass

Introduction

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

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

/** Returns a list of available camera preview sizes, or null if the Android API to get the sizes is not available.
 *///from w ww.ja v a2s.  c  o  m
@SuppressWarnings("unchecked")
public static List<Camera.Size> previewSizesForCameraParameters(Camera.Parameters params) {
    try {
        Method m = params.getClass().getMethod("getSupportedPreviewSizes");
        return (List<Camera.Size>) m.invoke(params);
    } catch (Exception ex) {
        return null;
    }
}

From source file:Main.java

/** Returns a list of available camera picture sizes, or null if the Android API to get the sizes is not available.
 *//*from w  w  w. j  a va 2  s  .  c  o  m*/
@SuppressWarnings("unchecked")
public static List<Camera.Size> pictureSizesForCameraParameters(Camera.Parameters params) {
    try {
        Method m = params.getClass().getMethod("getSupportedPictureSizes");
        return (List<Camera.Size>) m.invoke(params);
    } catch (Exception ex) {
        return null;
    }
}

From source file:Main.java

/** Returns a list of available camera preview sizes, or null if the Android API to get the sizes is not available.
 *//*from w w w  .ja  v a2  s. c o m*/
public static List<Camera.Size> previewSizesForCameraParameters(Camera.Parameters params) {
    try {
        Method m = params.getClass().getMethod("getSupportedPreviewSizes");
        return (List<Camera.Size>) m.invoke(params);
    } catch (Exception ex) {
        return null;
    }
}

From source file:Main.java

/** Returns true if the device's API and camera supports zooming. */
public static boolean cameraSupportsZoom(Camera camera) {
    if (!sdkSupportsCameraZoom())
        return false;
    try {//from ww  w .ja va  2s .c  o m
        Camera.Parameters params = camera.getParameters();
        Method zoomSupported = params.getClass().getMethod("isZoomSupported");
        return (Boolean) zoomSupported.invoke(params);
    } catch (Exception ex) {
        return false;
    }
}

From source file:Main.java

/** Returns a list of available camera picture sizes, or null if the Android API to get the sizes is not available.
 *//*from   w ww. j ava 2s  .  co  m*/
public static List<Camera.Size> pictureSizesForCameraParameters(Camera.Parameters params) {
    try {
        Method m = params.getClass().getMethod("getSupportedPictureSizes");
        return (List<Camera.Size>) m.invoke(params);
    } catch (Exception ex) {
        return null;
    }
}

From source file:Main.java

/** Attempts to set the camera's flash mode. Returns true if successful, false if the Android API doesn't support setting flash modes.
 *///from ww  w  .ja  v  a2 s.c  om
public static boolean setFlashMode(Camera camera, String mode) {
    Camera.Parameters params = camera.getParameters();
    try {
        Method flashModeMethod = params.getClass().getMethod("setFlashMode", String.class);
        flashModeMethod.invoke(params, mode);
        camera.setParameters(params);
        return true;
    } catch (Exception ignored) {
        return false;
    }
}

From source file:Main.java

public static String getCurrentFlashMode(Camera camera) {
    Camera.Parameters params = camera.getParameters();
    try {//w  w w . j  a  va 2s.c o m
        Method getModeMethod = params.getClass().getMethod("getFlashMode");
        return (String) getModeMethod.invoke(camera);
    } catch (Exception ex) {
        return null;
    }
}

From source file:Main.java

/** Returns a list of available camera flash modes. If the Android API doesn't support getting flash modes (requires 2.0 or later),
 * returns a list with a single element of "off", corresponding to Camera.Parameters.FLASH_MODE_OFF.
 *//*from w w w.  j  a va  2  s  .  c  om*/
public static List<String> getFlashModes(Camera camera) {
    Camera.Parameters params = camera.getParameters();
    try {
        Method flashModesMethod = params.getClass().getMethod("getSupportedFlashModes");
        @SuppressWarnings("unchecked")
        List<String> result = (List<String>) flashModesMethod.invoke(params);
        if (result != null)
            return result;
    } catch (Exception ignored) {
    }
    return Collections.singletonList("off");
}

From source file:Main.java

/** Returns a list of available camera flash modes. If the Android API doesn't support getting flash modes (requires 2.0 or later),
 * returns a list with a single element of "off", corresponding to Camera.Parameters.FLASH_MODE_OFF.
 *//*from  ww w . ja v a 2 s  .  co  m*/
public static List<String> getFlashModes(Camera camera) {
    Camera.Parameters params = camera.getParameters();
    try {
        Method flashModesMethod = params.getClass().getMethod("getSupportedFlashModes");
        List<String> result = (List<String>) flashModesMethod.invoke(params);
        if (result != null)
            return result;
    } catch (Exception ignored) {
    }
    return Collections.singletonList("off");
}

From source file:Main.java

/** Attempts to set the camera's zoom ratio as close as possible to the given value.
 * Like the Camera.Parameters.getZoomRatios method, values are in 1/100s so 100 is unzoomed.
 * Returns the actual ratio set, which will be 100 if the camera doesn't support zoom.
 *//*from  w w w  . j  a  va  2 s .c  o  m*/
public static int setCameraZoomRatio(Camera camera, int ratio) {
    if (!sdkSupportsCameraZoom())
        return DEFAULT_ZOOM_RATIO;
    try {
        Camera.Parameters params = camera.getParameters();
        Method getZoomRatios = params.getClass().getMethod("getZoomRatios");
        @SuppressWarnings("unchecked")
        List<Integer> zoomRatios = (List<Integer>) getZoomRatios.invoke(params);
        int index = zoomIndexForTargetRatio(zoomRatios, ratio);
        Method setZoom = params.getClass().getMethod("setZoom", int.class);
        setZoom.invoke(params, index);
        camera.setParameters(params);
        return zoomRatios.get(index);
    } catch (Exception ex) {
        return DEFAULT_ZOOM_RATIO;
    }
}