Skip to content

Commit

Permalink
feat: Remove unused button on main activity when there is no intent s…
Browse files Browse the repository at this point in the history
…canner detected
  • Loading branch information
VincentKobz committed Apr 18, 2024
1 parent 97997b3 commit b877d14
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,13 @@ public void onScannerInitEnded(int scannerCount) {
startCameraActivity();
}

displayTorch();
displayToggleLedButton();
displayEnableScanButton();
displayDisableScanButton();
displayBellButton();
if (scannerCount > 0) {
displayTorch();
displayToggleLedButton();
displayEnableScanButton();
displayDisableScanButton();
displayBellButton();
}
}

@Override
Expand Down Expand Up @@ -400,6 +402,7 @@ private void displayTorch() {
return;
}

flashlight.setVisibility(View.VISIBLE);
toggleTorch();

flashlight.setOnClickListener(v -> {
Expand Down Expand Up @@ -464,6 +467,8 @@ private void displayManualInputButton() {
return;
}

bt.setVisibility(View.VISIBLE);

bt.setOnClickListener(view -> {
// Pause camera or laser scanner during manual input.
scannerService.pause();
Expand Down Expand Up @@ -497,7 +502,9 @@ private void displayCameraButton() {
if (cameraButtonView != null) {

// Display the camera button if the camera scanner SDK is available.
if (!hasCameraScannerSdk) {
if (hasCameraScannerSdk) {
cameraButtonView.setVisibility(View.VISIBLE);
} else {
cameraButtonView.setVisibility(View.GONE);
return;
}
Expand All @@ -515,6 +522,8 @@ private void displayToggleLedButton() {
}
View v = findViewById(R.id.scanner_red_led);

v.setVisibility(View.VISIBLE);

// Check if we should display the button
boolean anySupport = false;
for (final Scanner s : ScannerCompatActivity.this.scannerService.getConnectedScanners()) {
Expand Down Expand Up @@ -547,8 +556,11 @@ private void displayToggleLedButton() {
}

private void displayDisableScanButton() {
if (findViewById(R.id.scanner_trigger_off) != null) {
findViewById(R.id.scanner_trigger_off).setOnClickListener(view -> {
View scannerTriggerOff = findViewById(R.id.scanner_trigger_off);

if (scannerTriggerOff != null) {
scannerTriggerOff.setVisibility(View.VISIBLE);
scannerTriggerOff.setOnClickListener(view -> {
for (final Scanner s : scannerService.getConnectedScanners()) {
if (s.getTriggerSupport() != null)
s.getTriggerSupport().releaseScanTrigger();
Expand All @@ -558,8 +570,11 @@ private void displayDisableScanButton() {
}

private void displayEnableScanButton() {
if (findViewById(R.id.scanner_trigger_on) != null) {
findViewById(R.id.scanner_trigger_on).setOnClickListener(view -> {
View scannerTriggerOnView = findViewById(R.id.scanner_trigger_on);

if (scannerTriggerOnView!= null) {
scannerTriggerOnView.setVisibility(View.VISIBLE);
scannerTriggerOnView.setOnClickListener(view -> {
for (final Scanner s : scannerService.getConnectedScanners()) {
if (s.getTriggerSupport() != null)
s.getTriggerSupport().pressScanTrigger();
Expand All @@ -569,8 +584,11 @@ private void displayEnableScanButton() {
}

private void displayBellButton() {
if (findViewById(R.id.scanner_bell) != null) {
findViewById(R.id.scanner_bell).setOnClickListener(view -> {
View scannerBellView = findViewById(R.id.scanner_bell);

if (scannerBellView != null) {
scannerBellView.setVisibility(View.VISIBLE);
scannerBellView.setOnClickListener(view -> {
for (final Scanner s : scannerService.getConnectedScanners()) {
if (s.getBeepSupport() != null)
s.getBeepSupport().beepScanSuccessful();
Expand Down
20 changes: 14 additions & 6 deletions enioka_scan/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
tools:context=".activities.ScannerCompatActivity">

<TextView
Expand Down Expand Up @@ -37,14 +38,16 @@
android:background="@null"
android:src="@drawable/ic_photo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
app:layout_constraintLeft_toLeftOf="parent"
android:visibility="gone" />

<ImageButton
android:id="@+id/scanner_bt_keyboard"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:background="@null"
android:src="@drawable/icn_keyboard"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />

Expand All @@ -54,10 +57,11 @@
android:layout_height="45dp"
android:background="@null"
android:src="@drawable/icn_flash_off_on"
app:tint="@color/colorRed"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/scanner_flashlight" />
app:layout_constraintRight_toLeftOf="@id/scanner_flashlight"
app:tint="@color/colorRed"
android:visibility="gone" />

<ImageButton
android:id="@+id/scanner_flashlight"
Expand All @@ -67,7 +71,8 @@
android:src="@drawable/icn_flash_off"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/scanner_red_led"
app:layout_constraintRight_toRightOf="parent" />
app:layout_constraintRight_toRightOf="parent"
android:visibility="gone" />

<ImageButton
android:id="@+id/scanner_trigger_on"
Expand All @@ -76,6 +81,7 @@
android:background="@null"
android:scaleType="fitCenter"
android:src="@drawable/scan_active"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/scanner_trigger_off"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -87,6 +93,7 @@
android:background="@null"
android:scaleType="fitCenter"
android:src="@drawable/scan_inactive"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/scanner_bell"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/scanner_trigger_on" />
Expand All @@ -98,10 +105,11 @@
android:background="@null"
android:scaleType="fitCenter"
android:src="@drawable/ic_bell"
app:tint="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/scanner_trigger_off" />
app:layout_constraintTop_toBottomOf="@id/scanner_trigger_off"
app:tint="@android:color/black"
android:visibility="gone" />


</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit b877d14

Please sign in to comment.