Skip to content

Commit

Permalink
Fix ScannerCompatActivity inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
DaSpood committed Dec 5, 2023
1 parent 0a79e9e commit 87faf55
Showing 1 changed file with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class ScannerCompatActivity extends AppCompatActivity implements ScannerC
protected boolean goToCamera = false;

/**
* Use bluetooth to look for scanners (if available).
* Check the app's bluetooth permissions. This variable does not affect scanner search options.
*/
protected boolean useBluetooth = true;

Expand All @@ -95,13 +95,18 @@ public class ScannerCompatActivity extends AppCompatActivity implements ScannerC
*/
protected int cameraViewId = R.id.camera_scan_view;

/**
* The ID of the ImageButton on which to press to manually switch to camera mode.
*/
protected int cameraToggleId = R.id.scanner_bt_camera;

/**
* The ID of the optional ImageButton on which to press to toggle the flashlight/illumination.
*/
protected int flashlightViewId = R.id.scanner_flashlight;

/**
* The ID of the optional ImageButton on which to press to toggle the flashlight/illumination.
* The ID of the optional ImageButton on which to press to toggle the zxing/zbar camera scan library.
*/
protected int scannerModeToggleViewId = R.id.scanner_switch_zxing;

Expand Down Expand Up @@ -168,9 +173,9 @@ protected void onStart() {
return;
}

if (useBluetooth && hasPermissionSet(this, PERMISSIONS_BT)) {
if (!useBluetooth || hasPermissionSet(this, PERMISSIONS_BT)) {
bindAndStartService();
} else {
} else if (useBluetooth && !hasPermissionSet(this, PERMISSIONS_BT)) {
requestPermissionSet(this, PERMISSIONS_BT, PERMISSION_REQUEST_ID_BT);
}
}
Expand Down Expand Up @@ -201,7 +206,7 @@ protected void onResume() {
}

// Immediately set some buttons (which do no need to wait for scanners).
resetCameraButton();
displayCameraButton();
displayManualInputButton();

// Register this activity on the scanner service (hooks onData) and ask it to hook possible scanners needing foreground control onto this activity.
Expand Down Expand Up @@ -397,7 +402,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}
case PERMISSION_REQUEST_ID_BT: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (useBluetooth && hasPermissionSet(this, PERMISSIONS_BT)) {
if (!useBluetooth || hasPermissionSet(this, PERMISSIONS_BT)) {
bindAndStartService();
}
} else {
Expand Down Expand Up @@ -472,7 +477,7 @@ public void onData(List<Barcode> data) {
/**
* Display the torch button "on" or "off" is the device has capability.
**/
protected void displayTorch() {
private void displayTorch() {
final ImageButton flashlight = findViewById(flashlightViewId);
if (findViewById(flashlightViewId) == null) {
return;
Expand Down Expand Up @@ -543,7 +548,7 @@ protected boolean anyScannerHasIlluminationOn() {
/**
* Display a manual input (keyboard) button for manual input.
*/
protected void displayManualInputButton() {
private void displayManualInputButton() {
final View bt = findViewById(keyboardOpenViewId);
if (bt == null) {
return;
Expand Down Expand Up @@ -577,13 +582,13 @@ public void dismiss() {
/**
* Display a "use camera" button to allow using camera input even when a laser is available.
*/
protected void resetCameraButton() {
if (findViewById(R.id.scanner_bt_camera) != null) {
findViewById(R.id.scanner_bt_camera).setOnClickListener(view -> initCamera());
private void displayCameraButton() {
if (findViewById(cameraToggleId) != null) {
findViewById(cameraToggleId).setOnClickListener(view -> initCamera());
}
}

protected void displayCameraReaderToggle() {
private void displayCameraReaderToggle() {
final Switch toggle = findViewById(scannerModeToggleViewId);
if (toggle == null) {
return;
Expand All @@ -596,7 +601,7 @@ protected void displayCameraReaderToggle() {
});
}

protected void displayCameraPauseToggle() {
private void displayCameraPauseToggle() {
final Switch toggle = findViewById(scannerModeTogglePauseId);
if (toggle == null) {
return;
Expand Down

0 comments on commit 87faf55

Please sign in to comment.