Implemented pausing flicker code
This commit is contained in:
parent
87985469bf
commit
15d282a175
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.ImageButton
|
||||
import android.widget.LinearLayout
|
||||
import kotlinx.android.synthetic.main.view_flicker_code.view.*
|
||||
import kotlinx.android.synthetic.main.view_tan_image_size_controls.view.*
|
||||
|
@ -35,10 +36,12 @@ open class ChipTanFlickerCodeView @JvmOverloads constructor(
|
|||
protected lateinit var stripe4: ChipTanFlickerCodeStripeView
|
||||
protected lateinit var stripe5: ChipTanFlickerCodeStripeView
|
||||
|
||||
protected lateinit var allStripes: List<ChipTanFlickerCodeStripeView>
|
||||
|
||||
protected lateinit var tanGeneratorLeftMarker: View
|
||||
protected lateinit var tanGeneratorRightMarker: View
|
||||
|
||||
protected lateinit var allStripes: List<ChipTanFlickerCodeStripeView>
|
||||
protected lateinit var btnPauseFlickerCode: ImageButton
|
||||
|
||||
protected val animator = FlickerCodeAnimator()
|
||||
|
||||
|
@ -49,6 +52,8 @@ open class ChipTanFlickerCodeView @JvmOverloads constructor(
|
|||
|
||||
protected var currentFrequency = 30
|
||||
|
||||
protected var isFlickerCodePaused = false
|
||||
|
||||
|
||||
init {
|
||||
setupUi(context)
|
||||
|
@ -64,6 +69,9 @@ open class ChipTanFlickerCodeView @JvmOverloads constructor(
|
|||
rootView.btnIncreaseSpeed.setOnClickListener { increaseFrequency() }
|
||||
rootView.btnDecreaseSpeed.setOnClickListener { decreaseFrequency() }
|
||||
|
||||
btnPauseFlickerCode = rootView.btnPauseFlickerCode
|
||||
btnPauseFlickerCode.setOnClickListener { togglePauseFlickerCode() }
|
||||
|
||||
stripe1 = rootView.findViewById(R.id.flickerCodeStripe1)
|
||||
stripe2 = rootView.findViewById(R.id.flickerCodeStripe2)
|
||||
stripe3 = rootView.findViewById(R.id.flickerCodeStripe3)
|
||||
|
@ -83,7 +91,6 @@ open class ChipTanFlickerCodeView @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
animator.stop()
|
||||
|
||||
|
@ -160,6 +167,20 @@ open class ChipTanFlickerCodeView @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
|
||||
open fun togglePauseFlickerCode() {
|
||||
if (isFlickerCodePaused == false) {
|
||||
animator.pause()
|
||||
btnPauseFlickerCode.setImageResource(android.R.drawable.ic_media_play)
|
||||
}
|
||||
else {
|
||||
animator.resume()
|
||||
btnPauseFlickerCode.setImageResource(android.R.drawable.ic_media_pause)
|
||||
}
|
||||
|
||||
isFlickerCodePaused = !!! isFlickerCodePaused
|
||||
}
|
||||
|
||||
|
||||
open fun setCode(flickerCode: FlickerCode) {
|
||||
animator.stop()
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@ open class FlickerCodeAnimator { // TODO: move to fints4javaLib
|
|||
|
||||
protected var currentStepIndex = 0
|
||||
|
||||
@Volatile
|
||||
protected var isPaused = false
|
||||
|
||||
protected var calculateAnimationThread: Thread? = null
|
||||
|
||||
|
||||
|
@ -41,6 +44,7 @@ open class FlickerCodeAnimator { // TODO: move to fints4javaLib
|
|||
|
||||
protected open fun calculateAnimation(steps: List<Array<Bit>>, showStep: (Array<Bit>) -> Unit) {
|
||||
while (Thread.currentThread().isInterrupted == false) {
|
||||
if (isPaused == false) {
|
||||
val nextStep = steps[currentStepIndex]
|
||||
|
||||
showStep(nextStep)
|
||||
|
@ -49,6 +53,7 @@ open class FlickerCodeAnimator { // TODO: move to fints4javaLib
|
|||
if (currentStepIndex >= steps.size) {
|
||||
currentStepIndex = 0 // all steps shown, start again from beginning
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(1000L / currentFrequency)
|
||||
|
@ -58,6 +63,14 @@ open class FlickerCodeAnimator { // TODO: move to fints4javaLib
|
|||
}
|
||||
}
|
||||
|
||||
open fun pause() {
|
||||
this.isPaused = true
|
||||
}
|
||||
|
||||
open fun resume() {
|
||||
this.isPaused = false
|
||||
}
|
||||
|
||||
open fun stop() {
|
||||
try {
|
||||
if (calculateAnimationThread?.isInterrupted == false) {
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_marginRight="@dimen/view_flicker_code_controls_sections_space"
|
||||
android:layout_marginEnd="@dimen/view_flicker_code_controls_sections_space"/>
|
||||
android:layout_marginEnd="@dimen/view_flicker_code_controls_sections_space"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -42,6 +43,15 @@
|
|||
android:text="@string/view_flicker_code_decrease_frequency"
|
||||
/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btnPauseFlickerCode"
|
||||
android:layout_width="@dimen/view_tan_image_controls_buttons_width"
|
||||
android:layout_height="@dimen/view_tan_image_controls_buttons_height"
|
||||
android:layout_marginLeft="@dimen/view_flicker_code_controls_sections_space"
|
||||
android:layout_marginStart="@dimen/view_flicker_code_controls_sections_space"
|
||||
android:src="@android:drawable/ic_media_pause"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
Loading…
Reference in New Issue