Skip to content

Commit

Permalink
feat: Replace manual input button by dialog that show available provi…
Browse files Browse the repository at this point in the history
…ders logs
  • Loading branch information
VincentKobz committed May 23, 2024
1 parent fd14d01 commit 6599b5e
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 45 deletions.
4 changes: 2 additions & 2 deletions docs/api/scanner_activity.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ the scanner :::{cpp:var}R.id.scanner_switch_pause:::.
:::{cpp:var}R.id.constraint_layout_main_activity:::.
- scanner_flashlight_id: The ID of the optional ImageButton on which to press to toggle the
flashlight/illumination :::{cpp:var}R.id.scanner_flashlight:::.
- scanner_bt_keyboard_id: The ID of the optional ImageButton on which to press to manually switch to
keyboard mode :::{cpp:var}R.id.scanner_bt_keyboard:::.
- scanner_bt_provider_logs: The ID of the optional ImageButton on which to press to manually access
available providers logs :::{cpp:var}R.id.scanner_bt_provider_logs:::.
:::

:::{cpp:var} int cameraToggleId = R.id.scanner_bt_camera
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.enioka.scanner.activities;

import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;

import androidx.core.content.ContextCompat;

import com.enioka.scanner.R;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

public class ManualLogDialog {
void launchDialog(Context context, String title, String logs, String textButton) {
Drawable icon = ContextCompat.getDrawable(context, R.drawable.info);

if (icon != null) {
// set color of icon to black api 18
icon.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(context, com.google.android.material.R.color.design_default_color_primary), PorterDuff.Mode.SRC_IN));
}

new MaterialAlertDialogBuilder(context)
.setTitle(title)
.setIcon(icon)
.setMessage(logs)
.setNegativeButton(textButton, (dialog, which) -> dialog.dismiss())
.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -137,7 +136,7 @@ public class ScannerCompatActivity extends AppCompatActivity implements ScannerC
*/
protected int flashlightViewId = R.id.scanner_flashlight;

protected int keyboardOpenViewId = R.id.scanner_bt_keyboard;
protected int providerLogOpenViewId = R.id.scanner_bt_provider_logs;

/**
* An optional fragment allowing to input a value with the soft keyboard (for cases when scanners do not work).
Expand Down Expand Up @@ -205,6 +204,11 @@ public class ScannerCompatActivity extends AppCompatActivity implements ScannerC
*/
private String openLinkUrl = null;

/**
* Logs and status of all detected providers
*/
private String providerLogs = "";

////////////////////////////////////////////////////////////////////////////////////////////////
// Activity lifecycle callbacks
////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -306,7 +310,7 @@ protected void onResume() {

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

// Register this activity on the scanner service (hooks onData) and ask it to hook possible scanners needing foreground control onto this activity.
// If no scanners are available at all, this will still call onForegroundScannerInitEnded with 0 scanners, and the activity will launch the camera.
Expand Down Expand Up @@ -526,7 +530,7 @@ private void initCameraScanner() {
}

displayTorch();
displayManualInputButton();
displayManualProviderLogButton();
displayCameraReaderToggle();
displayCameraPauseToggle();
}
Expand Down Expand Up @@ -587,6 +591,10 @@ public void onStatusChanged(final Scanner scanner, final ScannerStatusCallback.S
// Update visibility of the scanner status card
findViewById(R.id.scanner_provider_status_card).setVisibility(View.VISIBLE);
}

if (scanner != null && newStatus != null) {
providerLogs += scanner.getProviderKey() + " " + newStatus + "\n";
}
}

@Override
Expand Down Expand Up @@ -815,39 +823,19 @@ protected boolean anyScannerHasIlluminationOn() {
}

/**
* Display a manual input (keyboard) button for manual input.
* Display a manual input button to launch an alert dialog that contains provider logs.
*/
private void displayManualInputButton() {
final View bt = findViewById(keyboardOpenViewId);
private void displayManualProviderLogButton() {
final View bt = findViewById(providerLogOpenViewId);
if (bt == null) {
return;
}

bt.setVisibility(View.VISIBLE);

bt.setOnClickListener(view -> {
// Pause camera or laser scanner during manual input.
scannerService.pause();

manualInputFragment = ManualInputFragment.newInstance();
manualInputFragment.setAutocompletionItems(autocompletionItems, threshold);
manualInputFragment.setDialogInterface(new DialogInterface() {
@Override
public void cancel() {
if (serviceBound) {
scannerService.resume();
}
}

@Override
public void dismiss() {
if (serviceBound) {
scannerService.resume();
}
}
});
manualInputFragment.show(getSupportFragmentManager(), "manual");
});
String providerLogTitle = getResources().getString(R.string.provider_log_dialog_title);
String textButton = getResources().getString(R.string.provider_log_dialog_close);
bt.setOnClickListener(view -> new ManualLogDialog().launchDialog(this, providerLogTitle, providerLogs, textButton));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface CameraScannerProvider {
* - card_last_scan_id: ID of the card view that displays the last scan.
* - constraint_layout_id: The ID of the constraint layout inside the camera layout.
* - scanner_flashlight_id: The ID of the optional ImageButton on which to press to toggle the flashlight/illumination.
* - scanner_bt_keyboard_id: The ID of the optional ImageButton on which to press to manually switch to keyboard mode.
* - scanner_bt_provider_logs: The ID of the optional ImageButton on which to press to manually access available providers logs
*/
public HashMap<String, Integer> getIdResources();

Expand Down
9 changes: 9 additions & 0 deletions enioka_scan/src/main/res/drawable/done.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:pathData="M12.736,3.97a0.733,0.733 0,0 1,1.047 0c0.286,0.289 0.29,0.756 0.01,1.05L7.88,12.01a0.733,0.733 0,0 1,-1.065 0.02L3.217,8.384a0.757,0.757 0,0 1,0 -1.06,0.733 0.733,0 0,1 1.047,0l3.052,3.093 5.4,-6.425z"
android:fillColor="@android:color/white"/>
</vector>
9 changes: 9 additions & 0 deletions enioka_scan/src/main/res/drawable/info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:pathData="M8,16A8,8 0,1 0,8 0a8,8 0,0 0,0 16m0.93,-9.412 l-1,4.705c-0.07,0.34 0.029,0.533 0.304,0.533 0.194,0 0.487,-0.07 0.686,-0.246l-0.088,0.416c-0.287,0.346 -0.92,0.598 -1.465,0.598 -0.703,0 -1.002,-0.422 -0.808,-1.319l0.738,-3.468c0.064,-0.293 0.006,-0.399 -0.287,-0.47l-0.451,-0.081 0.082,-0.381 2.29,-0.287zM8,5.5a1,1 0,1 1,0 -2,1 1,0 0,1 0,2"
android:fillColor="@android:color/white"/>
</vector>
8 changes: 4 additions & 4 deletions enioka_scan/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@
android:layout_marginEnd="12dp"
app:icon="@drawable/camera_fill"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/scanner_bt_keyboard"/>
app:layout_constraintEnd_toStartOf="@+id/scanner_bt_provider_logs"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/scanner_bt_keyboard"
android:id="@+id/scanner_bt_provider_logs"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_marginEnd="12dp"
android:text="@string/keyboard_input"
android:text="@string/provider_log"
style="@style/Widget.Material3.Button.OutlinedButton"
app:icon="@drawable/keyboard_fill" />
app:icon="@drawable/info" />
</LinearLayout>

<com.google.android.material.button.MaterialButton
Expand Down
6 changes: 4 additions & 2 deletions enioka_scan/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@
<string name="activity_scan_use_zxing">ZXing</string>
<string name="activity_scan_pause_camera">Pause</string>
<string name="camera_mode_button">Camera</string>
<string name="keyboard_input">Entrée</string>
<string name="provider_log">Logs</string>
<string name="provider_log_dialog_title">Logs des scanneurs</string>
<string name="provider_log_dialog_close">Fermer</string>
<string name="switch_enable_scan_text">Activer le scan</string>
<string name="open_link">Ouvrir le lien</string>
<string name="last_scan_clipboard">Dernier scan copié avec succès dans le presse-papiers !</string>
<string name="bug_report">Signaler un bug</string>

<!-- Content description -->
<string name="fab_flashlight">lumiere flash</string>
<string name="fab_keyboard">saisie manuelle du clavier</string>
<string name="fab_provider_logs">logs des scanneurs disponibles</string>
<string name="fab_scanner_flashlight">activation de la lumiere du scanneur</string>
<string name="fab_scanner_bell">activation de la cloche</string>
<string name="fab_scanner_red_light">activation de la lumiere rouge du scanneur</string>
Expand Down
6 changes: 4 additions & 2 deletions enioka_scan/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@
<string name="fragment_scan_manual_invite">Please enter the barcode value, then select one item among the results</string>
<string name="fragment_scan_manual_hint">0000000000</string>
<string name="fragment_scan_manual_ok">Send</string>
<string name="keyboard_input">Input</string>
<string name="provider_log">Logs</string>
<string name="provider_log_dialog_title">Provider logs</string>
<string name="provider_log_dialog_close">Close</string>
<string name="switch_enable_scan_text">enable scan</string>
<string name="open_link">Open link</string>
<string name="bug_report">Report bug</string>

<!-- Content description -->
<string name="fab_flashlight">flash light</string>
<string name="fab_keyboard">manual input keyboard</string>
<string name="fab_provider_logs">available provider logs</string>
<string name="fab_scanner_flashlight">scanner flashlight activation</string>
<string name="fab_scanner_bell">scanner bell activation</string>
<string name="fab_scanner_red_light">scanner red light activation</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public HashMap<String, Integer> getIdResources() {
idResources.put("card_last_scan_id", R.id.card_camera_last_scan);
idResources.put("constraint_layout_id", R.id.constraint_layout_main_activity);
idResources.put("scanner_flashlight_id", R.id.scanner_flashlight);
idResources.put("scanner_bt_keyboard_id", R.id.scanner_bt_keyboard);
idResources.put("scanner_bt_provider_logs", R.id.scanner_bt_provider_logs);

return idResources;
}
Expand Down
6 changes: 3 additions & 3 deletions enioka_scan_camera/src/main/res/layout/activity_main_alt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@
android:contentDescription="@string/fab_flashlight" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/scanner_bt_keyboard"
android:id="@+id/scanner_bt_provider_logs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:src="@drawable/keyboard_fill"
android:src="@drawable/info"
app:fabCustomSize="48dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/scanner_flashlight"
android:contentDescription="@string/fab_keyboard" />
android:contentDescription="@string/fab_provider_logs" />

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/scanner_switch_zxing"
Expand Down

0 comments on commit 6599b5e

Please sign in to comment.