diff --git a/CHANGELOG.md b/CHANGELOG.md index 485e0790fb..d999371508 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 quiet zone as background to the exit code and adjust the brightness if it is shown ### Removed ### Fixed 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..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 @@ -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 @@ -105,6 +107,7 @@ class PaymentStatusView @JvmOverloads constructor( init { clipChildren = false + exitTokenBarcode.removeQuietZone(true) if (!isInEditMode) { project = Snabble.checkedInProject.value @@ -139,6 +142,8 @@ class PaymentStatusView @JvmOverloads constructor( } else { checkout?.abort() } + + adjustBrightness(DEFAULT_BRIGHTNESS) } checkout?.state?.observeView(this) { @@ -335,8 +340,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 +351,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 +499,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/java/io/snabble/sdk/ui/scanner/BarcodeView.java b/ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java index b7d8756323..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 @@ -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,14 @@ 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; + } + @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); @@ -180,7 +189,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/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..a4fe6b4686 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:padding="16dp" + android:layout_gravity="center_horizontal" + android:background="@drawable/snabble_barcode_background"> + + + +