From b54c59b531a47500ba2634c4f92417a72fdff00c Mon Sep 17 00:00:00 2001 From: VincentKobz Date: Thu, 23 May 2024 11:04:08 +0200 Subject: [PATCH] feat: Add settings in demo-app to allow camera fallback when no scanner devices are available --- .../enioka/scanner/demo/SettingsActivity.java | 6 ++++ .../enioka/scanner/demo/WelcomeActivity.java | 2 ++ .../src/main/res/layout/activity_settings.xml | 33 ++++++++++++++++++- .../src/main/res/values-fr/strings.xml | 1 + .../src/main/res/values/strings.xml | 1 + 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/demoscannerapp/src/main/java/com/enioka/scanner/demo/SettingsActivity.java b/demoscannerapp/src/main/java/com/enioka/scanner/demo/SettingsActivity.java index 2b7af7c5..2d0afd6f 100644 --- a/demoscannerapp/src/main/java/com/enioka/scanner/demo/SettingsActivity.java +++ b/demoscannerapp/src/main/java/com/enioka/scanner/demo/SettingsActivity.java @@ -42,6 +42,10 @@ public class SettingsActivity extends AppCompatActivity { * Enable logging preferences key */ public static final String ENABLE_LOGGING_KEY = "enableLogging"; + /** + * Allow camera fallback preferences key + */ + public static final String ALLOW_CAMERA_FALLBACK_KEY = "allowCameraFallback"; /** * List of provider views ids @@ -106,6 +110,7 @@ protected void onCreate(Bundle savedInstanceState) { ((MaterialSwitch) findViewById(R.id.switchPairingFlow)).setChecked(preferences.getBoolean(ScannerServiceApi.EXTRA_SEARCH_ALLOW_PAIRING_FLOW_BOOLEAN, options.allowPairingFlow)); ((MaterialSwitch) findViewById(R.id.switchIntentDevices)).setChecked(preferences.getBoolean(ScannerServiceApi.EXTRA_SEARCH_ALLOW_INTENT_BOOLEAN, options.allowIntentDevices)); ((MaterialSwitch) findViewById(R.id.switchEnableLogging)).setChecked(preferences.getBoolean(ENABLE_LOGGING_KEY, false)); + ((MaterialSwitch) findViewById(R.id.switchAllowCameraFallback)).setChecked(preferences.getBoolean(ALLOW_CAMERA_FALLBACK_KEY, false)); final Set allowedProviderKeys = preferences.getStringSet(ScannerServiceApi.EXTRA_SEARCH_ALLOWED_PROVIDERS_STRING_ARRAY, Collections.emptySet()); @@ -239,6 +244,7 @@ public void onClickSave(View v) { editor.putBoolean(ScannerServiceApi.EXTRA_SEARCH_ALLOW_PAIRING_FLOW_BOOLEAN, ((MaterialSwitch) findViewById(R.id.switchPairingFlow)).isChecked()); editor.putBoolean(ScannerServiceApi.EXTRA_SEARCH_ALLOW_INTENT_BOOLEAN, ((MaterialSwitch) findViewById(R.id.switchIntentDevices)).isChecked()); editor.putBoolean(ENABLE_LOGGING_KEY, ((MaterialSwitch) findViewById(R.id.switchEnableLogging)).isChecked()); + editor.putBoolean(ALLOW_CAMERA_FALLBACK_KEY, ((MaterialSwitch) findViewById(R.id.switchAllowCameraFallback)).isChecked()); final Set allowedProviderKeys = new HashSet<>(); final Set excludedProviderKeys = new HashSet<>(); diff --git a/demoscannerapp/src/main/java/com/enioka/scanner/demo/WelcomeActivity.java b/demoscannerapp/src/main/java/com/enioka/scanner/demo/WelcomeActivity.java index 8436b7a1..1331d46f 100644 --- a/demoscannerapp/src/main/java/com/enioka/scanner/demo/WelcomeActivity.java +++ b/demoscannerapp/src/main/java/com/enioka/scanner/demo/WelcomeActivity.java @@ -89,6 +89,8 @@ public void onClickBt1(View v) { intent.putExtra(ScannerServiceApi.EXTRA_SYMBOLOGY_SELECTION, symbologies); // add logging intent extra intent.putExtra(SettingsActivity.ENABLE_LOGGING_KEY, preferences.getBoolean(SettingsActivity.ENABLE_LOGGING_KEY, false)); + // add allow camera fallback intent extra + intent.putExtra(SettingsActivity.ALLOW_CAMERA_FALLBACK_KEY, preferences.getBoolean(SettingsActivity.ALLOW_CAMERA_FALLBACK_KEY, false)); startActivity(intent); } diff --git a/demoscannerapp/src/main/res/layout/activity_settings.xml b/demoscannerapp/src/main/res/layout/activity_settings.xml index 187d0885..61cc90ec 100644 --- a/demoscannerapp/src/main/res/layout/activity_settings.xml +++ b/demoscannerapp/src/main/res/layout/activity_settings.xml @@ -303,6 +303,37 @@ android:layout_marginEnd="16dp"/> + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/linearLayoutAllowCameraFallback"/> diff --git a/demoscannerapp/src/main/res/values-fr/strings.xml b/demoscannerapp/src/main/res/values-fr/strings.xml index e9000b50..fe5f0858 100644 --- a/demoscannerapp/src/main/res/values-fr/strings.xml +++ b/demoscannerapp/src/main/res/values-fr/strings.xml @@ -18,6 +18,7 @@ Autoriser les séquences d\'appairage Autoriser les scanners fonctionnant par Intent Activation des logs + Activation par défaut de l\'appareil photo si aucun scanneur n\'est trouvé Providers autorisés Providers exclus Sélection de la symbologie diff --git a/demoscannerapp/src/main/res/values/strings.xml b/demoscannerapp/src/main/res/values/strings.xml index 0aee6827..24a082b2 100644 --- a/demoscannerapp/src/main/res/values/strings.xml +++ b/demoscannerapp/src/main/res/values/strings.xml @@ -17,6 +17,7 @@ Allow pairing flow Allow intent devices Enable logging + Default to camera if no scanner is found Allowed Providers Excluded Providers Allowed Symbology