Skip to content

Commit

Permalink
feat: Add settings in demo-app to allow camera fallback when no scann…
Browse files Browse the repository at this point in the history
…er devices are available
  • Loading branch information
VincentKobz committed May 23, 2024
1 parent 7fad72f commit b54c59b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> allowedProviderKeys = preferences.getStringSet(ScannerServiceApi.EXTRA_SEARCH_ALLOWED_PROVIDERS_STRING_ARRAY, Collections.emptySet());

Expand Down Expand Up @@ -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<String> allowedProviderKeys = new HashSet<>();
final Set<String> excludedProviderKeys = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
33 changes: 32 additions & 1 deletion demoscannerapp/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,37 @@
android:layout_marginEnd="16dp"/>
</LinearLayout>

<LinearLayout
android:id="@+id/linearLayoutAllowCameraFallback"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayoutEnableLogging">

<TextView
android:id="@+id/textViewAllowCameraFallback"
android:layout_width="0dp"
android:layout_weight="9"
android:layout_height="wrap_content"
android:text="@string/allow_camera_fallback"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="@color/defaultTextColor"
android:layout_marginStart="16dp"/>

<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/switchAllowCameraFallback"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"/>
</LinearLayout>

<com.google.android.material.divider.MaterialDivider
android:id="@+id/dividerSettingsAllowedProvider"
android:layout_width="0dp"
Expand All @@ -311,7 +342,7 @@
app:layout_constraintWidth_percent="0.90"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayoutEnableLogging"/>
app:layout_constraintTop_toBottomOf="@+id/linearLayoutAllowCameraFallback"/>

<!-- ALLOWED PROVIDERS -->

Expand Down
1 change: 1 addition & 0 deletions demoscannerapp/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<string name="allow_pairing_flow">Autoriser les séquences d\'appairage</string>
<string name="allow_intent_devices">Autoriser les scanners fonctionnant par Intent</string>
<string name="enable_log">Activation des logs</string>
<string name="allow_camera_fallback">Activation par défaut de l\'appareil photo si aucun scanneur n\'est trouvé</string>
<string name="allowed_providers">Providers autorisés</string>
<string name="excluded_providers">Providers exclus</string>
<string name="symbology_selection">Sélection de la symbologie</string>
Expand Down
1 change: 1 addition & 0 deletions demoscannerapp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="allow_pairing_flow">Allow pairing flow</string>
<string name="allow_intent_devices">Allow intent devices</string>
<string name="enable_log">Enable logging</string>
<string name="allow_camera_fallback">Default to camera if no scanner is found</string>
<string name="allowed_providers">Allowed Providers</string>
<string name="excluded_providers">Excluded Providers</string>
<string name="symbology_selection">Allowed Symbology</string>
Expand Down

0 comments on commit b54c59b

Please sign in to comment.