Extracted Step
This commit is contained in:
parent
e0c5a72524
commit
8adab38d54
|
@ -26,8 +26,12 @@ open class ChipTanFlickerCodeStripeView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open fun showStripe(showStripe: Bit) {
|
open fun setStripeVisibility(stripe: Bit) {
|
||||||
if (showStripe == Bit.High) {
|
setStripeVisibility(stripe.isHigh)
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun setStripeVisibility(showStripe: Boolean) {
|
||||||
|
if (showStripe) {
|
||||||
drawWhite()
|
drawWhite()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -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.android.R
|
||||||
import net.dankito.banking.ui.model.tan.FlickerCode
|
import net.dankito.banking.ui.model.tan.FlickerCode
|
||||||
import net.dankito.banking.ui.util.FlickerCodeAnimator
|
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.ITanView
|
||||||
import net.dankito.banking.ui.model.settings.TanProcedureSettings
|
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(
|
open class ChipTanFlickerCodeView @JvmOverloads constructor(
|
||||||
|
@ -227,19 +226,17 @@ open class ChipTanFlickerCodeView @JvmOverloads constructor(
|
||||||
this.didTanProcedureSettingsChange = false
|
this.didTanProcedureSettingsChange = false
|
||||||
|
|
||||||
animator.animateFlickerCode(flickerCode) { step ->
|
animator.animateFlickerCode(flickerCode) { step ->
|
||||||
context.asActivity()?.runOnUiThread {
|
|
||||||
showStepOnUiThread(step)
|
showStepOnUiThread(step)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected open fun showStepOnUiThread(step: Array<Bit>) {
|
protected open fun showStepOnUiThread(step: Step) {
|
||||||
|
|
||||||
stripe1.showStripe(step[0])
|
stripe1.setStripeVisibility(step.bit1)
|
||||||
stripe2.showStripe(step[1])
|
stripe2.setStripeVisibility(step.bit2)
|
||||||
stripe3.showStripe(step[2])
|
stripe3.setStripeVisibility(step.bit3)
|
||||||
stripe4.showStripe(step[3])
|
stripe4.setStripeVisibility(step.bit4)
|
||||||
stripe5.showStripe(step[4])
|
stripe5.setStripeVisibility(step.bit5)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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.javafx.dialogs.tan.controls.TanGeneratorMarkerView
|
||||||
import net.dankito.banking.ui.model.settings.ITanView
|
import net.dankito.banking.ui.model.settings.ITanView
|
||||||
import net.dankito.banking.ui.model.settings.TanProcedureSettings
|
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.fixedHeight
|
||||||
import net.dankito.utils.javafx.ui.extensions.fixedWidth
|
import net.dankito.utils.javafx.ui.extensions.fixedWidth
|
||||||
import net.dankito.utils.javafx.ui.extensions.setBackgroundToColor
|
import net.dankito.utils.javafx.ui.extensions.setBackgroundToColor
|
||||||
|
@ -171,19 +172,17 @@ open class ChipTanFlickerCodeView(
|
||||||
updateMinAndMaxFrequencyReached()
|
updateMinAndMaxFrequencyReached()
|
||||||
|
|
||||||
animator.animateFlickerCode(flickerCode) { step ->
|
animator.animateFlickerCode(flickerCode) { step ->
|
||||||
runLater {
|
|
||||||
paintFlickerCode(step)
|
paintFlickerCode(step)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected open fun paintFlickerCode(step: Array<Bit>) {
|
protected open fun paintFlickerCode(step: Step) {
|
||||||
stripe1.set(step[0] == Bit.High)
|
stripe1.set(step.bit1.isHigh)
|
||||||
stripe2.set(step[1] == Bit.High)
|
stripe2.set(step.bit2.isHigh)
|
||||||
stripe3.set(step[2] == Bit.High)
|
stripe3.set(step.bit3.isHigh)
|
||||||
stripe4.set(step[3] == Bit.High)
|
stripe4.set(step.bit4.isHigh)
|
||||||
stripe5.set(step[4] == Bit.High)
|
stripe5.set(step.bit5.isHigh)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun setLeftMarkerPosition(component: UIComponent) {
|
protected open fun setLeftMarkerPosition(component: UIComponent) {
|
||||||
|
|
|
@ -8,6 +8,11 @@ enum class Bit(val value: Int) {
|
||||||
High(1);
|
High(1);
|
||||||
|
|
||||||
|
|
||||||
|
val isHigh: Boolean
|
||||||
|
get() = this == High
|
||||||
|
|
||||||
|
val isLow: Boolean = !!! this.isHigh
|
||||||
|
|
||||||
fun invert(): Bit {
|
fun invert(): Bit {
|
||||||
if (this == High) {
|
if (this == High) {
|
||||||
return Low
|
return Low
|
||||||
|
|
|
@ -27,11 +27,11 @@ open class FlickerCodeAnimator {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
open fun animateFlickerCode(flickerCode: FlickerCode, showStep: (Array<Bit>) -> Unit) {
|
open fun animateFlickerCode(flickerCode: FlickerCode, showStep: (Step) -> Unit) {
|
||||||
animateFlickerCode(flickerCode, DefaultFrequency, showStep)
|
animateFlickerCode(flickerCode, DefaultFrequency, showStep)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun animateFlickerCode(flickerCode: FlickerCode, frequency: Int, showStep: (Array<Bit>) -> Unit) {
|
open fun animateFlickerCode(flickerCode: FlickerCode, frequency: Int, showStep: (Step) -> Unit) {
|
||||||
stop() // stop may still running previous animation
|
stop() // stop may still running previous animation
|
||||||
|
|
||||||
currentFrequency = frequency
|
currentFrequency = frequency
|
||||||
|
@ -43,7 +43,7 @@ open class FlickerCodeAnimator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open suspend fun calculateAnimation(steps: List<Array<Bit>>, showStep: (Array<Bit>) -> Unit) {
|
protected open suspend fun calculateAnimation(steps: List<Step>, showStep: (Step) -> Unit) {
|
||||||
var currentStepIndex = 0
|
var currentStepIndex = 0
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
@ -7,36 +7,36 @@ open class FlickerCodeStepsCalculator {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
val bits = mutableMapOf<Char, List<Bit>>()
|
val bits = mutableMapOf<Char, Step>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
/* bitfield: clock, bits 2^1, 2^2, 2^3, 2^4 */
|
/* 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['0'] = Step(Bit.Low, Bit.Low, Bit.Low, Bit.Low, Bit.Low)
|
||||||
bits['1'] = listOf(Bit.Low, Bit.High, Bit.Low, Bit.Low, Bit.Low)
|
bits['1'] = Step(Bit.Low, Bit.High, Bit.Low, Bit.Low, Bit.Low)
|
||||||
bits['2'] = listOf(Bit.Low, Bit.Low, Bit.High, Bit.Low, Bit.Low)
|
bits['2'] = Step(Bit.Low, Bit.Low, Bit.High, Bit.Low, Bit.Low)
|
||||||
bits['3'] = listOf(Bit.Low, Bit.High, Bit.High, Bit.Low, Bit.Low)
|
bits['3'] = Step(Bit.Low, Bit.High, Bit.High, Bit.Low, Bit.Low)
|
||||||
bits['4'] = listOf(Bit.Low, Bit.Low, Bit.Low, Bit.High, Bit.Low)
|
bits['4'] = Step(Bit.Low, Bit.Low, Bit.Low, Bit.High, Bit.Low)
|
||||||
bits['5'] = listOf(Bit.Low, Bit.High, Bit.Low, Bit.High, Bit.Low)
|
bits['5'] = Step(Bit.Low, Bit.High, Bit.Low, Bit.High, Bit.Low)
|
||||||
bits['6'] = listOf(Bit.Low, Bit.Low, Bit.High, Bit.High, Bit.Low)
|
bits['6'] = Step(Bit.Low, Bit.Low, Bit.High, Bit.High, Bit.Low)
|
||||||
bits['7'] = listOf(Bit.Low, Bit.High, Bit.High, Bit.High, Bit.Low)
|
bits['7'] = Step(Bit.Low, Bit.High, Bit.High, Bit.High, Bit.Low)
|
||||||
bits['8'] = listOf(Bit.Low, Bit.Low, Bit.Low, Bit.Low, Bit.High)
|
bits['8'] = Step(Bit.Low, Bit.Low, Bit.Low, Bit.Low, Bit.High)
|
||||||
bits['9'] = listOf(Bit.Low, Bit.High, Bit.Low, Bit.Low, Bit.High)
|
bits['9'] = Step(Bit.Low, Bit.High, Bit.Low, Bit.Low, Bit.High)
|
||||||
bits['A'] = listOf(Bit.Low, Bit.Low, Bit.High, Bit.Low, Bit.High)
|
bits['A'] = Step(Bit.Low, Bit.Low, Bit.High, Bit.Low, Bit.High)
|
||||||
bits['B'] = listOf(Bit.Low, Bit.High, Bit.High, Bit.Low, Bit.High)
|
bits['B'] = Step(Bit.Low, Bit.High, Bit.High, Bit.Low, Bit.High)
|
||||||
bits['C'] = listOf(Bit.Low, Bit.Low, Bit.Low, Bit.High, Bit.High)
|
bits['C'] = Step(Bit.Low, Bit.Low, Bit.Low, Bit.High, Bit.High)
|
||||||
bits['D'] = listOf(Bit.Low, Bit.High, Bit.Low, Bit.High, Bit.High)
|
bits['D'] = Step(Bit.Low, Bit.High, Bit.Low, Bit.High, Bit.High)
|
||||||
bits['E'] = listOf(Bit.Low, Bit.Low, Bit.High, Bit.High, Bit.High)
|
bits['E'] = Step(Bit.Low, Bit.Low, Bit.High, Bit.High, Bit.High)
|
||||||
bits['F'] = listOf(Bit.Low, Bit.High, 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<Array<Bit>> {
|
open fun calculateSteps(flickerCode: String): List<Step> {
|
||||||
|
|
||||||
val halfbyteid = ObjectHolder(0)
|
val halfbyteid = ObjectHolder(0)
|
||||||
val clock = ObjectHolder(Bit.High)
|
val clock = ObjectHolder(Bit.High)
|
||||||
val bitarray = mutableListOf<MutableList<Bit>>()
|
val bitarray = mutableListOf<Step>()
|
||||||
|
|
||||||
|
|
||||||
/* prepend synchronization identifier */
|
/* prepend synchronization identifier */
|
||||||
|
@ -46,11 +46,11 @@ open class FlickerCodeStepsCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i in 0 until code.length step 2) {
|
for (i in 0 until code.length step 2) {
|
||||||
bits[code[i + 1]]?.let { bitarray.add(mutableListOf(*it.toTypedArray())) }
|
bits[code[i + 1]]?.let { bitarray.add(it) }
|
||||||
bits[code[i]]?.let { bitarray.add(mutableListOf(*it.toTypedArray())) }
|
bits[code[i]]?.let { bitarray.add(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val steps = mutableListOf<Array<Bit>>()
|
val steps = mutableListOf<Step>()
|
||||||
|
|
||||||
do {
|
do {
|
||||||
steps.add(calculateStep(halfbyteid, clock, bitarray))
|
steps.add(calculateStep(halfbyteid, clock, bitarray))
|
||||||
|
@ -59,10 +59,9 @@ open class FlickerCodeStepsCalculator {
|
||||||
return steps
|
return steps
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun calculateStep(halfbyteid: ObjectHolder<Int>, clock: ObjectHolder<Bit>, bitarray: MutableList<MutableList<Bit>>): Array<Bit> {
|
protected open fun calculateStep(halfbyteid: ObjectHolder<Int>, clock: ObjectHolder<Bit>, bitarray: List<Step>): Step {
|
||||||
bitarray[halfbyteid.value][0] = clock.value
|
val step = Step(clock.value, bitarray[halfbyteid.value])
|
||||||
|
|
||||||
val stepBits = Array(5) { index -> bitarray[halfbyteid.value][index] }
|
|
||||||
|
|
||||||
clock.value = clock.value.invert()
|
clock.value = clock.value.invert()
|
||||||
|
|
||||||
|
@ -75,7 +74,7 @@ open class FlickerCodeStepsCalculator {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stepBits
|
return step
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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)
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue