com.google.zxing.client.android.camera.open.OpenCamera Java Examples

The following examples show how to use com.google.zxing.client.android.camera.open.OpenCamera. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CameraManager.java    From flutter_qr_reader with MIT License 6 votes vote down vote up
/**
 * @param enabled if {@code true}, light should be turned on if currently off. And vice versa.
 */
public synchronized void setTorchEnabled(boolean enabled) {
  OpenCamera theCamera = openCamera;
  if (theCamera != null && enabled != configManager.getTorchState(theCamera.getCamera())) {
    boolean wasAutoFocusManager = autoFocusManager != null;
    if (wasAutoFocusManager) {
      autoFocusManager.stop();
      autoFocusManager = null;
    }
    configManager.setTorchEnabled(theCamera.getCamera(), enabled);
    if (wasAutoFocusManager) {
      autoFocusManager = new AutoFocusManager(theCamera.getCamera());
      autoFocusManager.start();
    }
  }
}
 
Example #2
Source File: CameraManager.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method
 *
 * @param newSetting if {@code true}, light should be turned on if currently off. And vice versa.
 */
public synchronized void setTorch(boolean newSetting) {
    OpenCamera theCamera = camera;
    if (theCamera != null) {
        if (newSetting != configManager.getTorchState(theCamera.getCamera())) {
            boolean wasAutoFocusManager = autoFocusManager != null;
            if (wasAutoFocusManager) {
                autoFocusManager.stop();
                autoFocusManager = null;
            }
            configManager.setTorch(theCamera.getCamera(), newSetting);
            if (wasAutoFocusManager) {
                autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
                autoFocusManager.start();
            }
        }
    }
}
 
Example #3
Source File: CameraManager.java    From barcodescanner-lib-aar with MIT License 6 votes vote down vote up
/**
   * Convenience method for {@link com.google.zxing.client.android.CaptureActivity}
   *
   * @param newSetting if {@code true}, light should be turned on if currently off. And vice versa.
   */
public synchronized void setTorch(boolean newSetting) {
  OpenCamera theCamera = camera;
  if (theCamera != null) {
    if (newSetting != configManager.getTorchState(theCamera.getCamera())) {
      boolean wasAutoFocusManager = autoFocusManager != null;
      if (wasAutoFocusManager) {
        autoFocusManager.stop();
        autoFocusManager = null;
      }
      configManager.setTorch(theCamera.getCamera(), newSetting);
      if (wasAutoFocusManager) {
        autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
        autoFocusManager.start();
      }
    }
  }
}
 
Example #4
Source File: CameraManager.java    From ShareBox with Apache License 2.0 6 votes vote down vote up
/**
 * @param enabled if {@code true}, light should be turned on if currently off. And vice versa.
 */
public synchronized void setTorchEnabled(boolean enabled) {
    OpenCamera theCamera = openCamera;
    if (theCamera != null && enabled != configManager.getTorchState(theCamera.getCamera())) {
        boolean wasAutoFocusManager = autoFocusManager != null;
        if (wasAutoFocusManager) {
            autoFocusManager.stop();
            autoFocusManager = null;
        }
        configManager.setTorchEnabled(theCamera.getCamera(), enabled);
        if (wasAutoFocusManager) {
            autoFocusManager = new AutoFocusManager(theCamera.getCamera());
            autoFocusManager.start();
        }
    }
}
 
Example #5
Source File: CameraManager.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method for {@link com.google.zxing.client.android.CaptureActivity}
 *
 * @param newSetting if {@code true}, light should be turned on if currently off. And vice versa.
 */
public synchronized void setTorch(boolean newSetting) {
  OpenCamera theCamera = camera;
  if (theCamera != null) {
    if (newSetting != configManager.getTorchState(theCamera.getCamera())) {
      boolean wasAutoFocusManager = autoFocusManager != null;
      if (wasAutoFocusManager) {
        autoFocusManager.stop();
        autoFocusManager = null;
      }
      configManager.setTorch(theCamera.getCamera(), newSetting);
      if (wasAutoFocusManager) {
        autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
        autoFocusManager.start();
      }
    }
  }
}
 
Example #6
Source File: CameraManager.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method for {@link com.google.zxing.client.android.CaptureActivity}
 *
 * @param newSetting if {@code true}, light should be turned on if currently off. And vice versa.
 */
public synchronized void setTorch(boolean newSetting) {
  OpenCamera theCamera = camera;
  if (theCamera != null) {
    if (newSetting != configManager.getTorchState(theCamera.getCamera())) {
      boolean wasAutoFocusManager = autoFocusManager != null;
      if (wasAutoFocusManager) {
        autoFocusManager.stop();
        autoFocusManager = null;
      }
      configManager.setTorch(theCamera.getCamera(), newSetting);
      if (wasAutoFocusManager) {
        autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
        autoFocusManager.start();
      }
    }
  }
}
 
Example #7
Source File: CameraManager.java    From ZXing-Standalone-library with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method for {@link com.google.zxing.client.android.CaptureActivity}
 *
 * @param newSetting if {@code true}, light should be turned on if currently off. And vice versa.
 */
public synchronized void setTorch(boolean newSetting) {
  OpenCamera theCamera = camera;
  if (theCamera != null) {
    if (newSetting != configManager.getTorchState(theCamera.getCamera())) {
      boolean wasAutoFocusManager = autoFocusManager != null;
      if (wasAutoFocusManager) {
        autoFocusManager.stop();
        autoFocusManager = null;
      }
      configManager.setTorch(theCamera.getCamera(), newSetting);
      if (wasAutoFocusManager) {
        autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
        autoFocusManager.start();
      }
    }
  }
}
 
Example #8
Source File: CameraManager.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method for {@link com.google.zxing.client.android.CaptureActivity}
 *
 * @param newSetting if {@code true}, light should be turned on if currently off. And vice versa.
 */
public synchronized void setTorch(boolean newSetting) {
  OpenCamera theCamera = camera;
  if (theCamera != null) {
    if (newSetting != configManager.getTorchState(theCamera.getCamera())) {
      boolean wasAutoFocusManager = autoFocusManager != null;
      if (wasAutoFocusManager) {
        autoFocusManager.stop();
        autoFocusManager = null;
      }
      configManager.setTorch(theCamera.getCamera(), newSetting);
      if (wasAutoFocusManager) {
        autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
        autoFocusManager.start();
      }
    }
  }
}
 
Example #9
Source File: CameraManager.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Asks the camera hardware to begin drawing preview frames to the screen.
 */
public synchronized void startPreview() {
  OpenCamera theCamera = camera;
  if (theCamera != null && !previewing) {
    theCamera.getCamera().startPreview();
    previewing = true;
    autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
  }
}
 
Example #10
Source File: CameraManager.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
/**
 * Asks the camera hardware to begin drawing preview frames to the screen.
 */
public synchronized void startPreview() {
    OpenCamera theCamera = camera;
    if (theCamera != null && !previewing) {
        theCamera.getCamera().startPreview();
        previewing = true;
        autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
    }
}
 
Example #11
Source File: CameraManager.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
/**
 * Asks the camera hardware to begin drawing preview frames to the screen.
 */
public synchronized void startPreview() {
  OpenCamera theCamera = camera;
  if (theCamera != null && !previewing) {
    theCamera.getCamera().startPreview();
    previewing = true;
    autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
  }
}
 
Example #12
Source File: CameraManager.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * Asks the camera hardware to begin drawing preview frames to the screen.
 */
public synchronized void startPreview() {
  OpenCamera theCamera = camera;
  if (theCamera != null && !previewing) {
    theCamera.getCamera().startPreview();
    previewing = true;
    autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
  }
}
 
Example #13
Source File: CameraManager.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
/**
 * Asks the camera hardware to begin drawing preview frames to the screen.
 */
public synchronized void startPreview() {
  OpenCamera theCamera = camera;
  if (theCamera != null && !previewing) {
    theCamera.getCamera().startPreview();
    previewing = true;
    autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
  }
}
 
Example #14
Source File: CameraManager.java    From flutter_qr_reader with MIT License 5 votes vote down vote up
/**
 * Asks the google.zxing.client.android.android.com.google.zxing.client.android.camera hardware to begin drawing preview frames to the screen.
 */
public synchronized void startPreview() {
  OpenCamera theCamera = openCamera;
  if (theCamera != null && !previewing) {
    theCamera.getCamera().startPreview();
    previewing = true;
    autoFocusManager = new AutoFocusManager(theCamera.getCamera());
    autoFocusManager.setAutofocusInterval(autofocusIntervalInMs);
  }
}
 
Example #15
Source File: CameraManager.java    From ZXing-Standalone-library with Apache License 2.0 5 votes vote down vote up
/**
 * Asks the camera hardware to begin drawing preview frames to the screen.
 */
public synchronized void startPreview() {
  OpenCamera theCamera = camera;
  if (theCamera != null && !previewing) {
    theCamera.getCamera().startPreview();
    previewing = true;
    autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
  }
}
 
Example #16
Source File: CameraManager.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
/**
 * Asks the camera hardware to begin drawing preview frames to the screen.
 */
public synchronized void startPreview() {
    OpenCamera theCamera = openCamera;
    if (theCamera != null && !previewing) {
        theCamera.getCamera().startPreview();
        previewing = true;
        autoFocusManager = new AutoFocusManager(theCamera.getCamera());
        autoFocusManager.setAutofocusInterval(autofocusIntervalInMs);
    }
}
 
Example #17
Source File: CameraConfigurationManager.java    From ShareBox with Apache License 2.0 4 votes vote down vote up
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {

        Camera theCamera = camera.getCamera();
        Camera.Parameters parameters = theCamera.getParameters();

        if (parameters == null) {
            Log.w(TAG,
                    "Device error: no camera parameters are available. Proceeding without configuration.");
            return;
        }

        Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

        if (safeMode) {
            Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
        }

        // Maybe selected auto-focus but not available, so fall through here:
        String focusMode = null;
        if (!safeMode) {
            List<String> supportedFocusModes = parameters.getSupportedFocusModes();
            focusMode =
                    findSettableValue("focus mode", supportedFocusModes, Camera.Parameters.FOCUS_MODE_AUTO);
        }
        if (focusMode != null) {
            parameters.setFocusMode(focusMode);
        }

        parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y);

        theCamera.setParameters(parameters);

        theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera);

        Camera.Parameters afterParameters = theCamera.getParameters();
        Camera.Size afterSize = afterParameters.getPreviewSize();
        if (afterSize != null && (bestPreviewSize.x != afterSize.width
                || bestPreviewSize.y != afterSize.height)) {
            Log.w(TAG,
                    "Camera said it supported preview size "
                            + bestPreviewSize.x
                            + 'x'
                            + bestPreviewSize.y
                            + ", but after setting it, preview size is "
                            + afterSize.width
                            + 'x'
                            + afterSize.height);
            bestPreviewSize.x = afterSize.width;
            bestPreviewSize.y = afterSize.height;
        }
    }
 
Example #18
Source File: CameraConfigurationManager.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {

        Camera theCamera = camera.getCamera();
        Camera.Parameters parameters = theCamera.getParameters();

        if (parameters == null) {
            Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
            return;
        }

        Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

        if (safeMode) {
            Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
        }

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

        initializeTorch(parameters, prefs, safeMode);

        CameraConfigurationUtils.setFocus(
                parameters,
                prefs.getBoolean(CameraPreferences.KEY_AUTO_FOCUS, true),
                prefs.getBoolean(CameraPreferences.KEY_DISABLE_CONTINUOUS_FOCUS, true),
                safeMode);

        if (!safeMode) {
            if (prefs.getBoolean(CameraPreferences.KEY_INVERT_SCAN, false)) {
                CameraConfigurationUtils.setInvertColor(parameters);
            }

            if (!prefs.getBoolean(CameraPreferences.KEY_DISABLE_BARCODE_SCENE_MODE, true)) {
                CameraConfigurationUtils.setBarcodeSceneMode(parameters);
            }

            if (!prefs.getBoolean(CameraPreferences.KEY_DISABLE_METERING, true)) {
                CameraConfigurationUtils.setVideoStabilization(parameters);
                CameraConfigurationUtils.setFocusArea(parameters);
                CameraConfigurationUtils.setMetering(parameters);
            }

        }

        parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y);

        theCamera.setParameters(parameters);

        theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera);

        Camera.Parameters afterParameters = theCamera.getParameters();
        Camera.Size afterSize = afterParameters.getPreviewSize();
        if (afterSize != null && (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) {
            Log.w(TAG, "Camera said it supported preview size " + bestPreviewSize.x + 'x' + bestPreviewSize.y +
                    ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
            bestPreviewSize.x = afterSize.width;
            bestPreviewSize.y = afterSize.height;
        }
    }
 
Example #19
Source File: CameraConfigurationManager.java    From flutter_qr_reader with MIT License 4 votes vote down vote up
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {

    Camera theCamera = camera.getCamera();
    Camera.Parameters parameters = theCamera.getParameters();

    if (parameters == null) {
      SimpleLog.w(TAG,
          "Device error: no google.zxing.client.android.android.com.google.zxing.client.android.camera parameters are available. Proceeding without configuration.");
      return;
    }

    SimpleLog.i(TAG, "Initial google.zxing.client.android.android.com.google.zxing.client.android.camera parameters: " + parameters.flatten());

    if (safeMode) {
      SimpleLog.w(TAG, "In google.zxing.client.android.android.com.google.zxing.client.android.camera config safe mode -- most settings will not be honored");
    }

    // Maybe selected auto-focus but not available, so fall through here:
    String focusMode = null;
    if (!safeMode) {
      List<String> supportedFocusModes = parameters.getSupportedFocusModes();
      focusMode =
          findSettableValue("focus mode",
                  supportedFocusModes,
                  Camera.Parameters.FOCUS_MODE_AUTO);
    }
    if (focusMode != null) {
      parameters.setFocusMode(focusMode);
    }

    parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y);

    theCamera.setParameters(parameters);

    theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera);

    Camera.Parameters afterParameters = theCamera.getParameters();
    Camera.Size afterSize = afterParameters.getPreviewSize();
    if (afterSize != null && (bestPreviewSize.x != afterSize.width
        || bestPreviewSize.y != afterSize.height)) {
      SimpleLog.w(TAG,
          "Camera said it supported preview size "
              + bestPreviewSize.x
              + 'x'
              + bestPreviewSize.y
              + ", but after setting it, preview size is "
              + afterSize.width
              + 'x'
              + afterSize.height);
      bestPreviewSize.x = afterSize.width;
      bestPreviewSize.y = afterSize.height;
    }
  }
 
Example #20
Source File: CameraManager.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
    OpenCamera theCamera = camera;
    if (theCamera == null) {
        theCamera = OpenCameraInterface.open(requestedCameraId);
        if (theCamera == null) {
            throw new IOException("Camera.open() failed to return object from driver");
        }
        camera = theCamera;
    }

    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera);
        if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
            setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
            requestedFramingRectWidth = 0;
            requestedFramingRectHeight = 0;
        }
    }

    Camera cameraObject = theCamera.getCamera();
    Camera.Parameters parameters = cameraObject.getParameters();
    String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
    try {
        configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
        // Driver failed
        Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
        Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
        // Reset:
        if (parametersFlattened != null) {
            parameters = cameraObject.getParameters();
            parameters.unflatten(parametersFlattened);
            try {
                cameraObject.setParameters(parameters);
                configManager.setDesiredCameraParameters(theCamera, true);
            } catch (RuntimeException re2) {
                // Well, darn. Give up
                Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
            }
        }
    }
    cameraObject.setPreviewDisplay(holder);

}
 
Example #21
Source File: CameraConfigurationManager.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {
  Camera theCamera = camera.getCamera();

  int rotation = context.getApplicationContext().getResources().getConfiguration().orientation;

  WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  Display display = windowManager.getDefaultDisplay();
  int deviceSpecificRotation = display.getRotation();

  if (rotation == Configuration.ORIENTATION_PORTRAIT) {
    if (deviceSpecificRotation == Surface.ROTATION_0 || deviceSpecificRotation == Surface.ROTATION_90) {
      theCamera.setDisplayOrientation(90);
    } else {
      theCamera.setDisplayOrientation(270);
    }
  } else {
    // landscape
    if (deviceSpecificRotation == Surface.ROTATION_180 || deviceSpecificRotation == Surface.ROTATION_270) {
      theCamera.setDisplayOrientation(180);
    }
  }

  Camera.Parameters parameters = theCamera.getParameters();
  if (parameters == null) {
    Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
    return;
  }

  Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

  if (safeMode) {
    Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
  }

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

  initializeTorch(parameters, prefs, safeMode);

  CameraConfigurationUtils.setFocus(
      parameters,
      prefs.getBoolean(PreferencesActivity.KEY_AUTO_FOCUS, true),
      prefs.getBoolean(PreferencesActivity.KEY_DISABLE_CONTINUOUS_FOCUS, true),
      safeMode);

  if (!safeMode) {
    if (prefs.getBoolean(PreferencesActivity.KEY_INVERT_SCAN, false)) {
      CameraConfigurationUtils.setInvertColor(parameters);
    }

    if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_BARCODE_SCENE_MODE, true)) {
      CameraConfigurationUtils.setBarcodeSceneMode(parameters);
    }

    if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_METERING, true)) {
      CameraConfigurationUtils.setVideoStabilization(parameters);
      CameraConfigurationUtils.setFocusArea(parameters);
      CameraConfigurationUtils.setMetering(parameters);
    }

  }

  parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y);

  theCamera.setParameters(parameters);

  theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera);

  Camera.Parameters afterParameters = theCamera.getParameters();
  Camera.Size afterSize = afterParameters.getPreviewSize();
  if (afterSize != null && (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) {
    Log.w(TAG, "Camera said it supported preview size " + bestPreviewSize.x + 'x' + bestPreviewSize.y +
        ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
    bestPreviewSize.x = afterSize.width;
    bestPreviewSize.y = afterSize.height;
  }
}
 
Example #22
Source File: CameraManager.java    From ShareBox with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @param height @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder, int width, int height)
        throws IOException {
    OpenCamera theCamera = openCamera;
    if (!isOpen()) {
        theCamera = OpenCameraInterface.open(requestedCameraId);
        if (theCamera == null || theCamera.getCamera() == null) {
            throw new IOException("Camera.open() failed to return object from driver");
        }
        openCamera = theCamera;
    }
    theCamera.getCamera().setPreviewDisplay(holder);
    theCamera.getCamera().setPreviewCallback(previewCallback);
    theCamera.getCamera().setDisplayOrientation(displayOrientation);

    if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(theCamera, width, height);
    }

    Camera cameraObject = theCamera.getCamera();
    Camera.Parameters parameters = cameraObject.getParameters();
    String parametersFlattened =
            parameters == null ? null : parameters.flatten(); // Save these, temporarily
    try {
        configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
        // Driver failed
        Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
        Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
        // Reset:
        if (parametersFlattened != null) {
            parameters = cameraObject.getParameters();
            parameters.unflatten(parametersFlattened);
            try {
                cameraObject.setParameters(parameters);
                configManager.setDesiredCameraParameters(theCamera, true);
            } catch (RuntimeException re2) {
                // Well, darn. Give up
                Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
            }
        }
    }
    cameraObject.setPreviewDisplay(holder);
}
 
Example #23
Source File: CameraManager.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
  OpenCamera theCamera = camera;
  if (theCamera == null) {
    theCamera = OpenCameraInterface.open(requestedCameraId);
    if (theCamera == null) {
      throw new IOException("Camera.open() failed to return object from driver");
    }
    camera = theCamera;
  }

  if (!initialized) {
    initialized = true;
    configManager.initFromCameraParameters(theCamera);
    if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
      setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
      requestedFramingRectWidth = 0;
      requestedFramingRectHeight = 0;
    }
  }

  Camera cameraObject = theCamera.getCamera();
  Camera.Parameters parameters = cameraObject.getParameters();
  String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
  try {
    configManager.setDesiredCameraParameters(theCamera, false);
  } catch (RuntimeException re) {
    // Driver failed
    Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
    Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
    // Reset:
    if (parametersFlattened != null) {
      parameters = cameraObject.getParameters();
      parameters.unflatten(parametersFlattened);
      try {
        cameraObject.setParameters(parameters);
        configManager.setDesiredCameraParameters(theCamera, true);
      } catch (RuntimeException re2) {
        // Well, darn. Give up
        Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
      }
    }
  }
  cameraObject.setPreviewDisplay(holder);

  if (torchInitiallyOn) {
    setTorch(true);
  }
}
 
Example #24
Source File: CameraConfigurationManager.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {

    Camera theCamera = camera.getCamera();
    Camera.Parameters parameters = theCamera.getParameters();

    if (parameters == null) {
      Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
      return;
    }

    Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

    if (safeMode) {
      Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    initializeTorch(parameters, prefs, safeMode);

    CameraConfigurationUtils.setFocus(
        parameters,
        prefs.getBoolean(PreferencesActivity.KEY_AUTO_FOCUS, true),
        prefs.getBoolean(PreferencesActivity.KEY_DISABLE_CONTINUOUS_FOCUS, true),
        safeMode);

    if (!safeMode) {
      if (prefs.getBoolean(PreferencesActivity.KEY_INVERT_SCAN, false)) {
        CameraConfigurationUtils.setInvertColor(parameters);
      }

      if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_BARCODE_SCENE_MODE, true)) {
        CameraConfigurationUtils.setBarcodeSceneMode(parameters);
      }

      if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_METERING, true)) {
        CameraConfigurationUtils.setVideoStabilization(parameters);
        CameraConfigurationUtils.setFocusArea(parameters);
        CameraConfigurationUtils.setMetering(parameters);
      }

    }

    parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y);

    theCamera.setParameters(parameters);

    theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera);

    Camera.Parameters afterParameters = theCamera.getParameters();
    Camera.Size afterSize = afterParameters.getPreviewSize();
    if (afterSize != null && (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) {
      Log.w(TAG, "Camera said it supported preview size " + bestPreviewSize.x + 'x' + bestPreviewSize.y +
          ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
      bestPreviewSize.x = afterSize.width;
      bestPreviewSize.y = afterSize.height;
    }
  }
 
Example #25
Source File: CameraManager.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
  OpenCamera theCamera = camera;
  if (theCamera == null) {
    theCamera = OpenCameraInterface.open(requestedCameraId);
    if (theCamera == null) {
      throw new IOException("Camera.open() failed to return object from driver");
    }
    camera = theCamera;
  }

  if (!initialized) {
    initialized = true;
    configManager.initFromCameraParameters(theCamera);
    if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
      setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
      requestedFramingRectWidth = 0;
      requestedFramingRectHeight = 0;
    }
  }

  Camera cameraObject = theCamera.getCamera();
  Camera.Parameters parameters = cameraObject.getParameters();
  String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
  try {
    configManager.setDesiredCameraParameters(theCamera, false);
  } catch (RuntimeException re) {
    // Driver failed
    Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
    Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
    // Reset:
    if (parametersFlattened != null) {
      parameters = cameraObject.getParameters();
      parameters.unflatten(parametersFlattened);
      try {
        cameraObject.setParameters(parameters);
        configManager.setDesiredCameraParameters(theCamera, true);
      } catch (RuntimeException re2) {
        // Well, darn. Give up
        Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
      }
    }
  }
  cameraObject.setPreviewDisplay(holder);

}
 
Example #26
Source File: CameraManager.java    From ZXing-Standalone-library with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
  OpenCamera theCamera = camera;
  if (theCamera == null) {
    theCamera = OpenCameraInterface.open(requestedCameraId);
    if (theCamera == null) {
      throw new IOException("Camera.open() failed to return object from driver");
    }
    camera = theCamera;
  }

  if (!initialized) {
    initialized = true;
    configManager.initFromCameraParameters(theCamera);
    if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
      setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
      requestedFramingRectWidth = 0;
      requestedFramingRectHeight = 0;
    }
  }

  Camera cameraObject = theCamera.getCamera();
  Camera.Parameters parameters = cameraObject.getParameters();
  String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
  try {
    configManager.setDesiredCameraParameters(theCamera, false);
  } catch (RuntimeException re) {
    // Driver failed
    Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
    Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
    // Reset:
    if (parametersFlattened != null) {
      parameters = cameraObject.getParameters();
      parameters.unflatten(parametersFlattened);
      try {
        cameraObject.setParameters(parameters);
        configManager.setDesiredCameraParameters(theCamera, true);
      } catch (RuntimeException re2) {
        // Well, darn. Give up
        Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
      }
    }
  }
  cameraObject.setPreviewDisplay(holder);

}
 
Example #27
Source File: CameraManager.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
  OpenCamera theCamera = camera;
  if (theCamera == null) {
    theCamera = OpenCameraInterface.open(requestedCameraId);
    if (theCamera == null) {
      throw new IOException("Camera.open() failed to return object from driver");
    }
    camera = theCamera;
  }

  if (!initialized) {
    initialized = true;
    configManager.initFromCameraParameters(theCamera);
    if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
      setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
      requestedFramingRectWidth = 0;
      requestedFramingRectHeight = 0;
    }
  }

  Camera cameraObject = theCamera.getCamera();
  Camera.Parameters parameters = cameraObject.getParameters();
  String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
  try {
    configManager.setDesiredCameraParameters(theCamera, false);
  } catch (RuntimeException re) {
    // Driver failed
    Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
    Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
    // Reset:
    if (parametersFlattened != null) {
      parameters = cameraObject.getParameters();
      parameters.unflatten(parametersFlattened);
      try {
        cameraObject.setParameters(parameters);
        configManager.setDesiredCameraParameters(theCamera, true);
      } catch (RuntimeException re2) {
        // Well, darn. Give up
        Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
      }
    }
  }
  cameraObject.setPreviewDisplay(holder);

}
 
Example #28
Source File: CameraConfigurationManager.java    From weex with Apache License 2.0 4 votes vote down vote up
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {

    Camera theCamera = camera.getCamera();
    Camera.Parameters parameters = theCamera.getParameters();

    if (parameters == null) {
      Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
      return;
    }

    Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

    if (safeMode) {
      Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    initializeTorch(parameters, prefs, safeMode);

    CameraConfigurationUtils.setFocus(
        parameters,
        prefs.getBoolean(PreferencesActivity.KEY_AUTO_FOCUS, true),
        prefs.getBoolean(PreferencesActivity.KEY_DISABLE_CONTINUOUS_FOCUS, true),
        safeMode);

    if (!safeMode) {
      if (prefs.getBoolean(PreferencesActivity.KEY_INVERT_SCAN, false)) {
        CameraConfigurationUtils.setInvertColor(parameters);
      }

      if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_BARCODE_SCENE_MODE, true)) {
        CameraConfigurationUtils.setBarcodeSceneMode(parameters);
      }

      if (!prefs.getBoolean(PreferencesActivity.KEY_DISABLE_METERING, true)) {
        CameraConfigurationUtils.setVideoStabilization(parameters);
        CameraConfigurationUtils.setFocusArea(parameters);
        CameraConfigurationUtils.setMetering(parameters);
      }

    }

    parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y);

    theCamera.setDisplayOrientation(90);
    theCamera.setParameters(parameters);

    theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera);

    Camera.Parameters afterParameters = theCamera.getParameters();
    Camera.Size afterSize = afterParameters.getPreviewSize();
    if (afterSize != null && (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) {
      Log.w(TAG, "Camera said it supported preview size " + bestPreviewSize.x + 'x' + bestPreviewSize.y +
          ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
      bestPreviewSize.x = afterSize.width;
      bestPreviewSize.y = afterSize.height;
    }
  }
 
Example #29
Source File: CameraManager.java    From flutter_qr_reader with MIT License 4 votes vote down vote up
/**
 * Opens the google.zxing.client.android.android.com.google.zxing.client.android.camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the google.zxing.client.android.android.com.google.zxing.client.android.camera will draw preview frames into.
 * @param height @throws IOException Indicates the google.zxing.client.android.android.com.google.zxing.client.android.camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder, int width, int height)
    throws IOException {
  OpenCamera theCamera = openCamera;
  if (!isOpen()) {
    theCamera = OpenCameraInterface.open(requestedCameraId);
    if (theCamera == null || theCamera.getCamera() == null) {
      throw new IOException("Camera.open() failed to return object from driver");
    }
    openCamera = theCamera;
  }
  theCamera.getCamera().setPreviewDisplay(holder);
  theCamera.getCamera().setPreviewCallback(previewCallback);
  theCamera.getCamera().setDisplayOrientation(displayOrientation);

  if (!initialized) {
    initialized = true;
    configManager.initFromCameraParameters(theCamera, width, height);
  }

  Camera cameraObject = theCamera.getCamera();
  Camera.Parameters parameters = cameraObject.getParameters();
  String parametersFlattened =
      parameters == null ? null : parameters.flatten(); // Save these, temporarily
  try {
    configManager.setDesiredCameraParameters(theCamera, false);
  } catch (RuntimeException re) {
    // Driver failed
    SimpleLog.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
    SimpleLog.i(TAG, "Resetting to saved google.zxing.client.android.android.com.google.zxing.client.android.camera params: " + parametersFlattened);
    // Reset:
    if (parametersFlattened != null) {
      parameters = cameraObject.getParameters();
      parameters.unflatten(parametersFlattened);
      try {
        cameraObject.setParameters(parameters);
        configManager.setDesiredCameraParameters(theCamera, true);
      } catch (RuntimeException re2) {
        // Well, darn. Give up
        SimpleLog.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
      }
    }
  }
  cameraObject.setPreviewDisplay(holder);
}
 
Example #30
Source File: CameraManager.java    From weex with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
  OpenCamera theCamera = camera;
  if (theCamera == null) {
    theCamera = OpenCameraInterface.open(requestedCameraId);
    if (theCamera == null) {
      throw new IOException("Camera.open() failed to return object from driver");
    }
    camera = theCamera;
  }

  if (!initialized) {
    initialized = true;
    configManager.initFromCameraParameters(theCamera);
    if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
      setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
      requestedFramingRectWidth = 0;
      requestedFramingRectHeight = 0;
    }
  }

  Camera cameraObject = theCamera.getCamera();
  Camera.Parameters parameters = cameraObject.getParameters();
  String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
  try {
    configManager.setDesiredCameraParameters(theCamera, false);
  } catch (RuntimeException re) {
    // Driver failed
    Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
    Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
    // Reset:
    if (parametersFlattened != null) {
      parameters = cameraObject.getParameters();
      parameters.unflatten(parametersFlattened);
      try {
        cameraObject.setParameters(parameters);
        configManager.setDesiredCameraParameters(theCamera, true);
      } catch (RuntimeException re2) {
        // Well, darn. Give up
        Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
      }
    }
  }
  cameraObject.setPreviewDisplay(holder);

}