Android examples for Camera:Camera Focus
set Camera Focus
import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; import android.hardware.Camera; public class Main { private static final String TAG = ""; public static void setFocus(Camera.Parameters parameters, boolean autoFocus, boolean disableContinuous, boolean safeMode) { List<String> supportedFocusModes = parameters.getSupportedFocusModes(); String focusMode = null;//from w w w . j a va2s . c o m if (autoFocus) { if (safeMode || disableContinuous) { focusMode = findSettableValue("focus mode", supportedFocusModes, Camera.Parameters.FOCUS_MODE_AUTO); } else { focusMode = findSettableValue("focus mode", supportedFocusModes, Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE, Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO, Camera.Parameters.FOCUS_MODE_AUTO); } } // Maybe selected auto-focus but not available, so fall through here: if (!safeMode && focusMode == null) { focusMode = findSettableValue("focus mode", supportedFocusModes, Camera.Parameters.FOCUS_MODE_MACRO, Camera.Parameters.FOCUS_MODE_EDOF); } if (focusMode != null) { if (focusMode.equals(parameters.getFocusMode())) { } else { parameters.setFocusMode(focusMode); } } } private static String findSettableValue(String name, Collection<String> supportedValues, String... desiredValues) { if (supportedValues != null) { for (String desiredValue : desiredValues) { if (supportedValues.contains(desiredValue)) { return desiredValue; } } } return null; } }