diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/ChipTanFlickerCodeStripeView.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/ChipTanFlickerCodeStripeView.kt index 4d5d18f3..a84b3fe1 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/ChipTanFlickerCodeStripeView.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/ChipTanFlickerCodeStripeView.kt @@ -26,8 +26,12 @@ open class ChipTanFlickerCodeStripeView @JvmOverloads constructor( } - open fun showStripe(showStripe: Bit) { - if (showStripe == Bit.High) { + open fun setStripeVisibility(stripe: Bit) { + setStripeVisibility(stripe.isHigh) + } + + open fun setStripeVisibility(showStripe: Boolean) { + if (showStripe) { drawWhite() } else { diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/ChipTanFlickerCodeView.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/ChipTanFlickerCodeView.kt index 40062eeb..f3f6b489 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/ChipTanFlickerCodeView.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/views/ChipTanFlickerCodeView.kt @@ -11,10 +11,9 @@ import kotlinx.android.synthetic.main.view_tan_image_size_controls.view.* import net.dankito.banking.ui.android.R import net.dankito.banking.ui.model.tan.FlickerCode import net.dankito.banking.ui.util.FlickerCodeAnimator -import net.dankito.banking.ui.util.Bit import net.dankito.banking.ui.model.settings.ITanView import net.dankito.banking.ui.model.settings.TanProcedureSettings -import net.dankito.utils.android.extensions.asActivity +import net.dankito.banking.ui.util.Step open class ChipTanFlickerCodeView @JvmOverloads constructor( @@ -227,19 +226,17 @@ open class ChipTanFlickerCodeView @JvmOverloads constructor( this.didTanProcedureSettingsChange = false animator.animateFlickerCode(flickerCode) { step -> - context.asActivity()?.runOnUiThread { - showStepOnUiThread(step) - } + showStepOnUiThread(step) } } - protected open fun showStepOnUiThread(step: Array) { + protected open fun showStepOnUiThread(step: Step) { - stripe1.showStripe(step[0]) - stripe2.showStripe(step[1]) - stripe3.showStripe(step[2]) - stripe4.showStripe(step[3]) - stripe5.showStripe(step[4]) + stripe1.setStripeVisibility(step.bit1) + stripe2.setStripeVisibility(step.bit2) + stripe3.setStripeVisibility(step.bit3) + stripe4.setStripeVisibility(step.bit4) + stripe5.setStripeVisibility(step.bit5) } } \ No newline at end of file diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/ChipTanFlickerCodeView.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/ChipTanFlickerCodeView.kt index 8b9b8d55..c6368fd9 100644 --- a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/ChipTanFlickerCodeView.kt +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/tan/controls/ChipTanFlickerCodeView.kt @@ -11,6 +11,7 @@ import net.dankito.banking.javafx.dialogs.tan.controls.ChipTanFlickerCodeStripeV import net.dankito.banking.javafx.dialogs.tan.controls.TanGeneratorMarkerView import net.dankito.banking.ui.model.settings.ITanView import net.dankito.banking.ui.model.settings.TanProcedureSettings +import net.dankito.banking.ui.util.Step import net.dankito.utils.javafx.ui.extensions.fixedHeight import net.dankito.utils.javafx.ui.extensions.fixedWidth import net.dankito.utils.javafx.ui.extensions.setBackgroundToColor @@ -171,19 +172,17 @@ open class ChipTanFlickerCodeView( updateMinAndMaxFrequencyReached() animator.animateFlickerCode(flickerCode) { step -> - runLater { - paintFlickerCode(step) - } + paintFlickerCode(step) } } - protected open fun paintFlickerCode(step: Array) { - stripe1.set(step[0] == Bit.High) - stripe2.set(step[1] == Bit.High) - stripe3.set(step[2] == Bit.High) - stripe4.set(step[3] == Bit.High) - stripe5.set(step[4] == Bit.High) + protected open fun paintFlickerCode(step: Step) { + stripe1.set(step.bit1.isHigh) + stripe2.set(step.bit2.isHigh) + stripe3.set(step.bit3.isHigh) + stripe4.set(step.bit4.isHigh) + stripe5.set(step.bit5.isHigh) } protected open fun setLeftMarkerPosition(component: UIComponent) { diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/Bit.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/Bit.kt index f43aca5e..5b772a1f 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/Bit.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/Bit.kt @@ -8,6 +8,11 @@ enum class Bit(val value: Int) { High(1); + val isHigh: Boolean + get() = this == High + + val isLow: Boolean = !!! this.isHigh + fun invert(): Bit { if (this == High) { return Low diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/FlickerCodeAnimator.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/FlickerCodeAnimator.kt index 75be6aba..b91a9eb6 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/FlickerCodeAnimator.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/FlickerCodeAnimator.kt @@ -27,11 +27,11 @@ open class FlickerCodeAnimator { - open fun animateFlickerCode(flickerCode: FlickerCode, showStep: (Array) -> Unit) { + open fun animateFlickerCode(flickerCode: FlickerCode, showStep: (Step) -> Unit) { animateFlickerCode(flickerCode, DefaultFrequency, showStep) } - open fun animateFlickerCode(flickerCode: FlickerCode, frequency: Int, showStep: (Array) -> Unit) { + open fun animateFlickerCode(flickerCode: FlickerCode, frequency: Int, showStep: (Step) -> Unit) { stop() // stop may still running previous animation currentFrequency = frequency @@ -43,7 +43,7 @@ open class FlickerCodeAnimator { } } - protected open suspend fun calculateAnimation(steps: List>, showStep: (Array) -> Unit) { + protected open suspend fun calculateAnimation(steps: List, showStep: (Step) -> Unit) { var currentStepIndex = 0 while (true) { diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/FlickerCodeStepsCalculator.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/FlickerCodeStepsCalculator.kt index e8b5b495..7515a0d0 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/FlickerCodeStepsCalculator.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/FlickerCodeStepsCalculator.kt @@ -7,36 +7,36 @@ open class FlickerCodeStepsCalculator { companion object { - val bits = mutableMapOf>() + val bits = mutableMapOf() init { /* bitfield: clock, bits 2^1, 2^2, 2^3, 2^4 */ - bits['0'] = listOf(Bit.Low, Bit.Low, Bit.Low, Bit.Low, Bit.Low) - bits['1'] = listOf(Bit.Low, Bit.High, Bit.Low, Bit.Low, Bit.Low) - bits['2'] = listOf(Bit.Low, Bit.Low, Bit.High, Bit.Low, Bit.Low) - bits['3'] = listOf(Bit.Low, Bit.High, Bit.High, Bit.Low, Bit.Low) - bits['4'] = listOf(Bit.Low, Bit.Low, Bit.Low, Bit.High, Bit.Low) - bits['5'] = listOf(Bit.Low, Bit.High, Bit.Low, Bit.High, Bit.Low) - bits['6'] = listOf(Bit.Low, Bit.Low, Bit.High, Bit.High, Bit.Low) - bits['7'] = listOf(Bit.Low, Bit.High, Bit.High, Bit.High, Bit.Low) - bits['8'] = listOf(Bit.Low, Bit.Low, Bit.Low, Bit.Low, Bit.High) - bits['9'] = listOf(Bit.Low, Bit.High, Bit.Low, Bit.Low, Bit.High) - bits['A'] = listOf(Bit.Low, Bit.Low, Bit.High, Bit.Low, Bit.High) - bits['B'] = listOf(Bit.Low, Bit.High, Bit.High, Bit.Low, Bit.High) - bits['C'] = listOf(Bit.Low, Bit.Low, Bit.Low, Bit.High, Bit.High) - bits['D'] = listOf(Bit.Low, Bit.High, Bit.Low, Bit.High, Bit.High) - bits['E'] = listOf(Bit.Low, Bit.Low, Bit.High, Bit.High, Bit.High) - bits['F'] = listOf(Bit.Low, Bit.High, Bit.High, Bit.High, Bit.High) + bits['0'] = Step(Bit.Low, Bit.Low, Bit.Low, Bit.Low, Bit.Low) + bits['1'] = Step(Bit.Low, Bit.High, Bit.Low, Bit.Low, Bit.Low) + bits['2'] = Step(Bit.Low, Bit.Low, Bit.High, Bit.Low, Bit.Low) + bits['3'] = Step(Bit.Low, Bit.High, Bit.High, Bit.Low, Bit.Low) + bits['4'] = Step(Bit.Low, Bit.Low, Bit.Low, Bit.High, Bit.Low) + bits['5'] = Step(Bit.Low, Bit.High, Bit.Low, Bit.High, Bit.Low) + bits['6'] = Step(Bit.Low, Bit.Low, Bit.High, Bit.High, Bit.Low) + bits['7'] = Step(Bit.Low, Bit.High, Bit.High, Bit.High, Bit.Low) + bits['8'] = Step(Bit.Low, Bit.Low, Bit.Low, Bit.Low, Bit.High) + bits['9'] = Step(Bit.Low, Bit.High, Bit.Low, Bit.Low, Bit.High) + bits['A'] = Step(Bit.Low, Bit.Low, Bit.High, Bit.Low, Bit.High) + bits['B'] = Step(Bit.Low, Bit.High, Bit.High, Bit.Low, Bit.High) + bits['C'] = Step(Bit.Low, Bit.Low, Bit.Low, Bit.High, Bit.High) + bits['D'] = Step(Bit.Low, Bit.High, Bit.Low, Bit.High, Bit.High) + bits['E'] = Step(Bit.Low, Bit.Low, Bit.High, Bit.High, Bit.High) + bits['F'] = Step(Bit.Low, Bit.High, Bit.High, Bit.High, Bit.High) } } - open fun calculateSteps(flickerCode: String): List> { + open fun calculateSteps(flickerCode: String): List { val halfbyteid = ObjectHolder(0) val clock = ObjectHolder(Bit.High) - val bitarray = mutableListOf>() + val bitarray = mutableListOf() /* prepend synchronization identifier */ @@ -46,11 +46,11 @@ open class FlickerCodeStepsCalculator { } for (i in 0 until code.length step 2) { - bits[code[i + 1]]?.let { bitarray.add(mutableListOf(*it.toTypedArray())) } - bits[code[i]]?.let { bitarray.add(mutableListOf(*it.toTypedArray())) } + bits[code[i + 1]]?.let { bitarray.add(it) } + bits[code[i]]?.let { bitarray.add(it) } } - val steps = mutableListOf>() + val steps = mutableListOf() do { steps.add(calculateStep(halfbyteid, clock, bitarray)) @@ -59,10 +59,9 @@ open class FlickerCodeStepsCalculator { return steps } - protected open fun calculateStep(halfbyteid: ObjectHolder, clock: ObjectHolder, bitarray: MutableList>): Array { - bitarray[halfbyteid.value][0] = clock.value + protected open fun calculateStep(halfbyteid: ObjectHolder, clock: ObjectHolder, bitarray: List): Step { + val step = Step(clock.value, bitarray[halfbyteid.value]) - val stepBits = Array(5) { index -> bitarray[halfbyteid.value][index] } clock.value = clock.value.invert() @@ -75,7 +74,7 @@ open class FlickerCodeStepsCalculator { } - return stepBits + return step } } \ No newline at end of file diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/Step.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/Step.kt new file mode 100644 index 00000000..727ab246 --- /dev/null +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/util/Step.kt @@ -0,0 +1,14 @@ +package net.dankito.banking.ui.util + + +open class Step( + val bit1: Bit, + val bit2: Bit, + val bit3: Bit, + val bit4: Bit, + val bit5: Bit +) { + + constructor(clockBit: Bit, step: Step) : this(clockBit, step.bit2, step.bit3, step.bit4, step.bit5) + +} \ No newline at end of file