android: qr scanner: allow tap to focus
Allow tap to focus in the android qr scanner as some devices don't support autofocus. This should allow them to focus on some qr code.
This commit is contained in:
@@ -95,7 +95,10 @@ public class SimpleScannerActivity extends Activity {
|
|||||||
private void startCamera() {
|
private void startCamera() {
|
||||||
if (mScannerView == null) {
|
if (mScannerView == null) {
|
||||||
mScannerView = new BarcodeScannerView(this);
|
mScannerView = new BarcodeScannerView(this);
|
||||||
mScannerView.setCropRatio(0.75f); // Set crop ratio to 75% (this defines the square area shown in the scanner view)
|
// Set crop ratio to 75% (this defines the square area shown in the scanner view)
|
||||||
|
mScannerView.setCropRatio(0.75f);
|
||||||
|
// allow tap to focus (note: some devices don't support autofocus which is enabled by default)
|
||||||
|
mScannerView.setTapToFocus();
|
||||||
// by default only Format.QR_CODE is set
|
// by default only Format.QR_CODE is set
|
||||||
ViewGroup contentFrame = (ViewGroup) findViewById(R.id.content_frame);
|
ViewGroup contentFrame = (ViewGroup) findViewById(R.id.content_frame);
|
||||||
contentFrame.addView(mScannerView);
|
contentFrame.addView(mScannerView);
|
||||||
@@ -172,7 +175,7 @@ public class SimpleScannerActivity extends Activity {
|
|||||||
// Get the root view and set up insets listener
|
// Get the root view and set up insets listener
|
||||||
getWindow().getDecorView().setOnApplyWindowInsetsListener((v, insets) -> {
|
getWindow().getDecorView().setOnApplyWindowInsetsListener((v, insets) -> {
|
||||||
android.graphics.Insets systemBars = insets.getInsets(WindowInsets.Type.systemBars());
|
android.graphics.Insets systemBars = insets.getInsets(WindowInsets.Type.systemBars());
|
||||||
|
|
||||||
// Apply padding to content frame to keep scanner focus area centered
|
// Apply padding to content frame to keep scanner focus area centered
|
||||||
ViewGroup contentFrame = findViewById(R.id.content_frame);
|
ViewGroup contentFrame = findViewById(R.id.content_frame);
|
||||||
if (contentFrame != null) {
|
if (contentFrame != null) {
|
||||||
@@ -195,7 +198,7 @@ public class SimpleScannerActivity extends Activity {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply bottom margin to paste button for navigation bar
|
// Apply bottom margin to paste button for navigation bar
|
||||||
Button pasteButton = findViewById(R.id.paste_btn);
|
Button pasteButton = findViewById(R.id.paste_btn);
|
||||||
if (pasteButton != null) {
|
if (pasteButton != null) {
|
||||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) pasteButton.getLayoutParams();
|
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) pasteButton.getLayoutParams();
|
||||||
|
|||||||
Reference in New Issue
Block a user