Repository: florisboard/florisboard
Issue: Flashing Keyboard

<!--
- Describe the bug in a short but concise way.
- If you have a screenshot or screen recording of the bug, link them at
  the end of this issue.
- Please search existing bug reports to avoid creating duplicates.
- Thank you for your help in making FlorisBoard better!
-->

#### Short description
When using custom themes, I have noticed the keyboard will be flashing in and out. By flashing here, I am referring to that it fades in and out between the keyboard's normal theme and near completely transparent. This has happened with multiple custom themes I have used. It does occur every time, but it does happen often. If this is a duplicate, I did not notice.

#### Steps to reproduce
1.) Create and set custom theme
2.) Bring up keyboard

#### Environment information
- FlorisBoard Version: 0.3.10-BETA06 
- Install Source: F-Droid
- Device: Samsung Galaxy S20 FE
- Android version, ROM: Android 11




Changed files:
app/src/main/java/dev/patrickgold/florisboard/ime/text/TextInputManager.kt

diff --git a/app/src/main/java/dev/patrickgold/florisboard/ime/text/TextInputManager.kt b/app/src/main/java/dev/patrickgold/florisboard/ime/text/TextInputManager.kt
index ccc0079e..36b91a98 100644
--- a/app/src/main/java/dev/patrickgold/florisboard/ime/text/TextInputManager.kt
+++ b/app/src/main/java/dev/patrickgold/florisboard/ime/text/TextInputManager.kt
@@ -71,7 +71,6 @@ class TextInputManager private constructor() : CoroutineScope by MainScope(), In
     lateinit var layoutManager: LayoutManager
         private set
     private var activeKeyboardMode: KeyboardMode? = null
-    private var animator: ObjectAnimator? = null
     private val keyboardViews = EnumMap<KeyboardMode, KeyboardView>(KeyboardMode::class.java)
     private var editingKeyboardView: EditingKeyboardView? = null
     private var loadingPlaceholderKeyboard: KeyboardView? = null
@@ -169,27 +168,29 @@ class TextInputManager private constructor() : CoroutineScope by MainScope(), In
         loadingPlaceholderKeyboard = inputView.findViewById(R.id.keyboard_preview)
 
         launch(Dispatchers.Main) {
-            textViewGroup?.let {
-                animator = ObjectAnimator.ofFloat(it, "alpha", 0.9f, 1.0f).apply {
+            val animator1 = textViewGroup?.let {
+                ObjectAnimator.ofFloat(it, "alpha", 0.9f, 1.0f).apply {
                     duration = 125
+                    repeatCount = 0
+                    start()
+                }
+            }
+            val animator2 = textViewGroup?.let {
+                ObjectAnimator.ofFloat(it, "alpha", 1.0f, 0.4f).apply {
+                    startDelay = 125
+                    duration = 500
                     repeatCount = ValueAnimator.INFINITE
                     repeatMode = ValueAnimator.REVERSE
                     start()
-                    launch {
-                        delay(duration)
-                        try {
-                            duration = 500
-                            setFloatValues(1.0f, 0.4f)
-                        } catch (_: Exception) {}
-                    }
                 }
             }
             val activeKeyboardMode = getActiveKeyboardMode()
             addKeyboardView(activeKeyboardMode)
             setActiveKeyboardMode(activeKeyboardMode)
-            animator?.cancel()
-            textViewGroup?.let {
-                animator = ObjectAnimator.ofFloat(it, "alpha", it.alpha, 1.0f).apply {
+            animator1?.cancel()
+            animator2?.cancel()
+            val animator3 = textViewGroup?.let {
+                ObjectAnimator.ofFloat(it, "alpha", it.alpha, 1.0f).apply {
                     duration = (((1.0f - it.alpha) / 0.6f) * 125f).roundToLong()
                     repeatCount = 0
                     start()
@@ -200,6 +201,8 @@ class TextInputManager private constructor() : CoroutineScope by MainScope(), In
                     addKeyboardView(mode)
                 }
             }
+            delay(animator3?.duration ?: 1)
+            animator3?.end()
         }
     }