mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
fix: the Android keyboard opens on the first tap after the system dismissed it (#665)
This commit is contained in:
1 parent
6de6ec821c
commit
fc9d4d0646
2 files changed
+61
-1
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.os.Looper
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.FrameLayout
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(manifest = Config.NONE)
|
||||
class KeyboardHostTest {
|
||||
private lateinit var imm: InputMethodManager
|
||||
private lateinit var host: KeyboardHost
|
||||
|
||||
@Before fun setUp() {
|
||||
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
|
||||
imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
host = KeyboardHost(activity)
|
||||
activity.setContentView(FrameLayout(activity).apply { addView(host) })
|
||||
idle()
|
||||
}
|
||||
|
||||
@Config(sdk = [33])
|
||||
@Test fun toggleShowsAKeyboardTheSystemDismissed() {
|
||||
host.show()
|
||||
idle()
|
||||
imm.hideSoftInputFromWindow(host.windowToken, 0)
|
||||
idle()
|
||||
host.toggle()
|
||||
idle()
|
||||
assertTrue(shadowOf(imm).isSoftInputVisible)
|
||||
assertTrue(host.shown)
|
||||
}
|
||||
|
||||
@Config(sdk = [28])
|
||||
@Test fun toggleHidesAKeyboardThatIsShowing() {
|
||||
host.show()
|
||||
idle()
|
||||
host.toggle()
|
||||
idle()
|
||||
assertFalse(shadowOf(imm).isSoftInputVisible)
|
||||
assertFalse(host.shown)
|
||||
}
|
||||
|
||||
private fun idle() = shadowOf(Looper.getMainLooper()).idle()
|
||||
}
|
||||
Reference in new issue
Block a user