Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentStatusView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -105,6 +107,7 @@ class PaymentStatusView @JvmOverloads constructor(

init {
clipChildren = false
exitTokenBarcode.removeQuietZone(true)

if (!isInEditMode) {
project = Snabble.checkedInProject.value
Expand Down Expand Up @@ -139,6 +142,8 @@ class PaymentStatusView @JvmOverloads constructor(
} else {
checkout?.abort()
}

adjustBrightness(DEFAULT_BRIGHTNESS)
}

checkout?.state?.observeView(this) {
Expand Down Expand Up @@ -335,15 +340,24 @@ 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
}
}
}
}

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))
Expand Down Expand Up @@ -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
11 changes: 10 additions & 1 deletion ui/src/main/java/io/snabble/sdk/ui/scanner/BarcodeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -180,7 +189,7 @@ private void generate() {
Map<EncodeHintType, String> 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;
Expand Down
6 changes: 6 additions & 0 deletions ui/src/main/res/drawable/snabble_barcode_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white" />
<corners android:radius="16dp" />
</shape>
35 changes: 17 additions & 18 deletions ui/src/main/res/layout/snabble_view_payment_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,24 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<io.snabble.sdk.ui.scanner.BarcodeView
android:id="@+id/exit_token_barcode"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@android:color/transparent"
android:textAppearance="?attr/textAppearanceBodyLarge"
tools:visibility="visible" />

<TextView
android:layout_width="match_parent"
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingHorizontal="16dp"
android:paddingVertical="8dp"
android:text="@string/Snabble.PaymentStatus.ExitCode.openExitGateTimed"
android:textAppearance="?attr/textAppearanceBodyMedium" />
android:layout_marginVertical="16.dp"
android:padding="16dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/snabble_barcode_background">

<io.snabble.sdk.ui.scanner.BarcodeView
android:id="@+id/exit_token_barcode"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:textAppearance="?attr/textAppearanceBodyLarge"
tools:visibility="visible" />
</RelativeLayout>

</LinearLayout>

<io.snabble.sdk.ui.checkout.PaymentStatusItemView
Expand Down
Loading