set Camera Barcode Scene Mode - Android Camera

Android examples for Camera:Camera Attribute

Description

set Camera Barcode Scene Mode

Demo Code

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

import android.hardware.Camera;
import android.util.Log;

public class Main {
  private static final String TAG = "";

  public static void setBarcodeSceneMode(Camera.Parameters parameters) {
    if (Camera.Parameters.SCENE_MODE_BARCODE.equals(parameters.getSceneMode())) {
      return;//from   w w w .j a  v a  2 s .  c om
    }
    String sceneMode = findSettableValue("scene mode", parameters.getSupportedSceneModes(),
        Camera.Parameters.SCENE_MODE_BARCODE);
    if (sceneMode != null) {
      parameters.setSceneMode(sceneMode);
    }
  }

  private static String findSettableValue(String name, Collection<String> supportedValues, String... desiredValues) {
    if (supportedValues != null) {
      for (String desiredValue : desiredValues) {
        if (supportedValues.contains(desiredValue)) {
          Log.i(TAG, "Podemos utilizar o seguinte valor de" + name + ": " + desiredValue);
          return desiredValue;
        }
      }
    }
    return null;
  }

  private static String toString(Collection<int[]> arrays) {
    if (arrays == null || arrays.isEmpty()) {
      return "[]";
    }
    StringBuilder buffer = new StringBuilder();
    buffer.append('[');
    Iterator<int[]> it = arrays.iterator();
    while (it.hasNext()) {
      buffer.append(Arrays.toString(it.next()));
      if (it.hasNext()) {
        buffer.append(", ");
      }
    }
    buffer.append(']');
    return buffer.toString();
  }

  private static String toString(Iterable<Camera.Area> areas) {
    if (areas == null) {
      return null;
    }
    StringBuilder result = new StringBuilder();
    for (Camera.Area area : areas) {
      result.append(area.rect).append(':').append(area.weight).append(' ');
    }
    return result.toString();
  }
}

Related Tutorials