Skip to content

Commit

Permalink
Add a property to launch with the torch switched on #6
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Dec 22, 2016
1 parent 4fc064b commit 33a9eae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ protected void onResume() {
cameraManager.setManualCameraId(cameraId);
}
}


if (intent.getBooleanExtra(Intents.Scan.TORCH_ON, false)) {
cameraManager.setTorchInitiallyOn(true);
}

String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
if (customPromptMessage != null) {
statusView.setText(customPromptMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public static final class Scan {
/**
* Optional parameters to specify the width and height of the scanning rectangle in pixels.
* The app will try to honor these, but will clamp them to the size of the preview frame.
* The app will try to honor these, but will clamp them to the size of the preview frame.
* You should specify both or neither, and pass the size as an int.
*/
public static final String WIDTH = "SCAN_WIDTH";
Expand Down Expand Up @@ -183,6 +184,11 @@ public static final class Scan {
*/
public static final String SHOW_TORCH_BUTTON = "SHOW_TORCH_BUTTON";

/**
* Set to true if we want to show the launch with the torch toggled on
*/
public static final String TORCH_ON = "TORCH_ON";

/**
* Set to true if you want to enable bulk scan mode
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public final class CameraManager {
private Rect framingRectInPreview;
private boolean initialized;
private boolean previewing;
private boolean torchInitiallyOn;
private int requestedCameraId = OpenCameraInterface.NO_REQUESTED_CAMERA;
private int requestedFramingRectWidth;
private int requestedFramingRectHeight;
Expand Down Expand Up @@ -124,6 +125,9 @@ public synchronized void openDriver(SurfaceHolder holder) throws IOException {
}
cameraObject.setPreviewDisplay(holder);

if (torchInitiallyOn) {
setTorch(true);
}
}

public synchronized boolean isOpen() {
Expand Down Expand Up @@ -307,6 +311,10 @@ public synchronized void setManualCameraId(int cameraId) {
requestedCameraId = cameraId;
}

public synchronized void setTorchInitiallyOn(boolean on) {
torchInitiallyOn = on;
}

/**
* Allows third party apps to specify the scanning rectangle dimensions, rather than determine
* them automatically based on screen resolution.
Expand Down

0 comments on commit 33a9eae

Please sign in to comment.