From 394f84d6cec9aa560d6121bea283d575b496c86e Mon Sep 17 00:00:00 2001 From: Fabian Bender Date: Wed, 11 Dec 2024 15:04:38 +0100 Subject: [PATCH 1/6] adjust the PaymentStatusView: * adjust brightness if the exit code is shown * make the exit code bigger and add a background for better scanning experience * move the hint to be the sub title --- .../sdk/ui/checkout/PaymentStatusView.kt | 16 +++++++++ .../drawable/snabble_barcode_background.xml | 6 ++++ .../layout/snabble_view_payment_status.xml | 35 +++++++++---------- 3 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 ui/src/main/res/drawable/snabble_barcode_background.xml diff --git a/ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentStatusView.kt b/ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentStatusView.kt index d2524b2b98..56273546b9 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentStatusView.kt +++ b/ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentStatusView.kt @@ -8,6 +8,7 @@ import android.os.Bundle import android.util.AttributeSet import android.view.View import android.view.ViewGroup +import android.view.WindowManager import android.view.inputmethod.InputMethodManager import android.webkit.URLUtil import android.widget.Button @@ -44,6 +45,7 @@ import io.snabble.sdk.ui.payment.SEPACardInputActivity import io.snabble.sdk.ui.payment.payone.sepa.form.PayoneSepaActivity import io.snabble.sdk.ui.scanner.BarcodeView import io.snabble.sdk.ui.telemetry.Telemetry +import io.snabble.sdk.ui.utils.UIUtils import io.snabble.sdk.ui.utils.executeUiAction import io.snabble.sdk.ui.utils.getFragmentActivity import io.snabble.sdk.ui.utils.observeView @@ -139,6 +141,8 @@ class PaymentStatusView @JvmOverloads constructor( } else { checkout?.abort() } + + adjustBrightness(DEFAULT_BRIGHTNESS) } checkout?.state?.observeView(this) { @@ -335,8 +339,10 @@ class PaymentStatusView @JvmOverloads constructor( exitTokenContainer.isVisible = true exitToken.state = PaymentStatusItemView.State.SUCCESS exitToken.setTitle(resources.getString(R.string.Snabble_PaymentStatus_ExitCode_title)) + exitToken.setText(resources.getString(R.string.Snabble_PaymentStatus_ExitCode_openExitGateTimed)) exitTokenBarcode.setFormat(format) exitTokenBarcode.setText(it.value) + adjustBrightness(MAX_BRIGHTNESS) } else { exitTokenContainer.isVisible = false } @@ -344,6 +350,13 @@ class PaymentStatusView @JvmOverloads constructor( } } + private fun adjustBrightness(value: Float) { + val activity = UIUtils.getHostActivity(context) + val localLayoutParams: WindowManager.LayoutParams = activity.window.attributes + localLayoutParams.screenBrightness = value + activity.window.setAttributes(localLayoutParams) + } + private fun handlePaymentAborted() { payment.state = PaymentStatusItemView.State.FAILED payment.setText(resources.getString(R.string.Snabble_PaymentStatus_Payment_error)) @@ -485,3 +498,6 @@ class PaymentStatusView @JvmOverloads constructor( } } } + +private const val MAX_BRIGHTNESS = 0.99f // value of 1.0 is not accepted +private const val DEFAULT_BRIGHTNESS = -1f diff --git a/ui/src/main/res/drawable/snabble_barcode_background.xml b/ui/src/main/res/drawable/snabble_barcode_background.xml new file mode 100644 index 0000000000..5fa45277ae --- /dev/null +++ b/ui/src/main/res/drawable/snabble_barcode_background.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/ui/src/main/res/layout/snabble_view_payment_status.xml b/ui/src/main/res/layout/snabble_view_payment_status.xml index c03ea7b828..85dd1acc16 100644 --- a/ui/src/main/res/layout/snabble_view_payment_status.xml +++ b/ui/src/main/res/layout/snabble_view_payment_status.xml @@ -120,25 +120,24 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> - - - + android:layout_marginVertical="16.dp" + android:layout_gravity="center_horizontal" + android:background="@drawable/snabble_barcode_background"> + + + + Date: Wed, 11 Dec 2024 15:19:24 +0100 Subject: [PATCH 2/6] add missing CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 485e0790fb..c2736c4024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## UNRELEASED ### Added ### Changed +*ui: add safe area as background to the exit code and adjust the brightness if it is shown ### Removed ### Fixed From a7a1ebc61e9a4359a059c83c08e7a106990b7cce Mon Sep 17 00:00:00 2001 From: Fabian Bender Date: Wed, 11 Dec 2024 21:59:53 +0100 Subject: [PATCH 3/6] add workaround to remove the quiet zone on dark mode if wanted --- .../java/io/snabble/sdk/ui/checkout/PaymentStatusView.kt | 1 + .../main/java/io/snabble/sdk/ui/scanner/BarcodeView.java | 7 ++++++- ui/src/main/res/layout/snabble_view_payment_status.xml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentStatusView.kt b/ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentStatusView.kt index 56273546b9..a33374a925 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentStatusView.kt +++ b/ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentStatusView.kt @@ -107,6 +107,7 @@ class PaymentStatusView @JvmOverloads constructor( init { clipChildren = false + exitTokenBarcode.removeQuietZone(true) if (!isInEditMode) { project = Snabble.checkedInProject.value diff --git a/ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java b/ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java index b7d8756323..f9b380eb8f 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java +++ b/ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java @@ -51,6 +51,7 @@ public class BarcodeView extends AppCompatImageView { private boolean isNumberDisplayEnabled = true; private boolean adjustBrightness = true; private boolean animateBarcode = true; + private boolean removeQuietZone = false; private Handler uiHandler; private int backgroundColor; @@ -143,6 +144,10 @@ public void setAnimateBarcode(boolean animate) { animateBarcode = animate; } + public void removeQuietZone(boolean adjust) { + removeQuietZone = adjust; + } + @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); @@ -180,7 +185,7 @@ private void generate() { Map hints = null; // Remove the quite zone of the QR code we have enough space in the light mode - if (format == BarcodeFormat.QR_CODE && !isDarkMode) { + if ((format == BarcodeFormat.QR_CODE && !isDarkMode) || removeQuietZone) { hints = new HashMap<>(); hints.put(EncodeHintType.MARGIN, "0"); border = 0; diff --git a/ui/src/main/res/layout/snabble_view_payment_status.xml b/ui/src/main/res/layout/snabble_view_payment_status.xml index 85dd1acc16..a4fe6b4686 100644 --- a/ui/src/main/res/layout/snabble_view_payment_status.xml +++ b/ui/src/main/res/layout/snabble_view_payment_status.xml @@ -124,6 +124,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginVertical="16.dp" + android:padding="16dp" android:layout_gravity="center_horizontal" android:background="@drawable/snabble_barcode_background"> @@ -132,7 +133,6 @@ android:layout_width="160dp" android:layout_height="160dp" android:layout_gravity="center" - android:layout_margin="16.dp" android:background="@android:color/transparent" android:textAppearance="?attr/textAppearanceBodyLarge" tools:visibility="visible" /> From 9125f4b7f3c21df2a5fa6853e086a3842946a6f0 Mon Sep 17 00:00:00 2001 From: Fabian Bender Date: Wed, 11 Dec 2024 22:00:28 +0100 Subject: [PATCH 4/6] adjust CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2736c4024..55919ae1a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. ## UNRELEASED ### Added ### Changed -*ui: add safe area as background to the exit code and adjust the brightness if it is shown +*ui: add quiet zone as background to the exit code and adjust the brightness if it is shown ### Removed ### Fixed From 3db528a51b3c7338205872de2af91bf7a3fb9c8e Mon Sep 17 00:00:00 2001 From: Christian Maier Date: Thu, 12 Dec 2024 06:30:53 +0100 Subject: [PATCH 5/6] Fix typo in CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55919ae1a9..d999371508 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. ## UNRELEASED ### Added ### Changed -*ui: add quiet zone as background to the exit code and adjust the brightness if it is shown +* ui: add quiet zone as background to the exit code and adjust the brightness if it is shown ### Removed ### Fixed From 64d0617d7671cdad6ea2a01002f977e8a50385e0 Mon Sep 17 00:00:00 2001 From: Fabian Bender Date: Thu, 12 Dec 2024 07:14:35 +0100 Subject: [PATCH 6/6] add documentation --- ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java b/ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java index f9b380eb8f..4295ee1cd4 100644 --- a/ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java +++ b/ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java @@ -144,6 +144,10 @@ public void setAnimateBarcode(boolean animate) { animateBarcode = animate; } + /** + * If set the quiet zone, e.g. the white space around the qr code will be removed. + * @param adjust : true for removing the quiet zone false (default) to keep it as it is. + */ public void removeQuietZone(boolean adjust) { removeQuietZone = adjust; }