Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save torch state #136

Merged
merged 1 commit into from
Feb 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sample/src/main/java/example/zxing/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void scanToolbar(View view) {
}

public void scanCustomScanner(View view) {
new IntentIntegrator(this).setCaptureActivity(CustomScannerActivity.class).initiateScan();
new IntentIntegrator(this).setOrientationLocked(false).setCaptureActivity(CustomScannerActivity.class).initiateScan();
}

public void scanMarginScanner(View view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
Expand Down Expand Up @@ -122,6 +124,8 @@ public interface StateListener {
// must be smaller than 0.5;
private double marginFraction = 0.1d;

private boolean torchOn = false;

@TargetApi(14)
private TextureView.SurfaceTextureListener surfaceTextureListener() {
// Cannot initialize automatically, since we may be API < 14
Expand Down Expand Up @@ -363,6 +367,7 @@ private void calculateFrames() {
* @param on true to turn on the torch
*/
public void setTorch(boolean on) {
torchOn = on;
if (cameraInstance != null) {
cameraInstance.setTorch(on);
}
Expand All @@ -375,6 +380,9 @@ private void containerSized(Size containerSize) {
displayConfiguration = new DisplayConfiguration(getDisplayRotation(), containerSize);
cameraInstance.setDisplayConfiguration(displayConfiguration);
cameraInstance.configureCamera();
if(torchOn) {
cameraInstance.setTorch(torchOn);
}
}
}
}
Expand Down Expand Up @@ -718,4 +726,27 @@ protected Rect calculateFramingRect(Rect container, Rect surface) {
}
return intersection;
}

@Override
protected Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();

Bundle myState = new Bundle();
myState.putParcelable("super", superState);
myState.putBoolean("torch", torchOn);
return myState;
}

@Override
protected void onRestoreInstanceState(Parcelable state) {
if(!(state instanceof Bundle)) {
super.onRestoreInstanceState(state);
return;
}
Bundle myState = (Bundle)state;
Parcelable superState = myState.getParcelable("super");
super.onRestoreInstanceState(superState);
boolean torch = myState.getBoolean("torch");
setTorch(torch);
}
}