Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions openless-all/app/android/kotlin/OpenLessImeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ class OpenLessImeService : InputMethodService(), OpenLessOverlayBridge.OverlaySt
// (see buildKeyboardView()'s spaceButton); the panel/View tree itself
// is never rebuilt into a second layout for PINYIN — see
// docs/pinyin-lite/phase-0-audit.md section 7.
internal enum class LatinInputMode { ENGLISH, PINYIN }
internal enum class LatinInputMode {
ENGLISH,
PINYIN;

fun toggled(): LatinInputMode = if (this == ENGLISH) PINYIN else ENGLISH
}

private var lastCancelledImeRequest = 0L
private var imeRequestId = 0L
Expand Down Expand Up @@ -552,7 +557,7 @@ class OpenLessImeService : InputMethodService(), OpenLessOverlayBridge.OverlaySt
englishComposingWord.clear()
englishCandidateQueryEpoch++
litePinyinController.clear()
latinInputMode = if (latinInputMode == LatinInputMode.ENGLISH) LatinInputMode.PINYIN else LatinInputMode.ENGLISH
latinInputMode = latinInputMode.toggled()
saveLatinInputMode(latinInputMode)
refreshLatinCandidateBar()
performKeyHaptic()
Expand Down Expand Up @@ -1583,16 +1588,12 @@ class OpenLessImeService : InputMethodService(), OpenLessOverlayBridge.OverlaySt
textSize = 12f
gravity = android.view.Gravity.CENTER
setTypeface(typeface, android.graphics.Typeface.BOLD)
isClickable = false
// The actual bug behind every earlier "text is just missing"
// attempt at a FrameLayout overlay on a keyboardKey(): that key
// has its own non-zero elevation+translationZ (dp(5)+dp(1), see
// keyboardKey()'s own body) for its raised-surface look, and on
// API 21+ ViewGroup draws children in Z order — not insertion
// order — whenever their Z values differ. spaceButton's Z was
// silently winning and painting straight over this View despite
// being added to the FrameLayout first. A higher Z here forces
// this View to actually draw on top.
isClickable = true
isFocusable = true
contentDescription = ui("切换拼音和英文", "Switch between Pinyin and English")
setOnClickListener { toggleLatinInputMode() }
// Keep the hint above the raised space key so its tap target is
// the visible mode label rather than the key underneath it.
translationZ = dp(10).toFloat()
}
val spaceWrapper = FrameLayout(this).apply {
Expand Down
18 changes: 18 additions & 0 deletions openless-all/app/android/kotlin/test/LatinInputModeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.openless.app

import org.junit.Assert.assertEquals
import org.junit.Test

class LatinInputModeTest {
@Test
fun toggledModeAlternatesBetweenEnglishAndPinyin() {
assertEquals(
OpenLessImeService.LatinInputMode.PINYIN,
OpenLessImeService.LatinInputMode.ENGLISH.toggled(),
)
assertEquals(
OpenLessImeService.LatinInputMode.ENGLISH,
OpenLessImeService.LatinInputMode.PINYIN.toggled(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ async fn auto_sync_local_retry_releases_runtime_and_respects_pause() {
})
.await;
tokio::time::timeout(
std::time::Duration::from_millis(200),
std::time::Duration::from_secs(2),
fixture.service.set_enabled(false),
)
.await
Expand Down
1 change: 1 addition & 0 deletions openless-all/app/scripts/copy-android-scaffolding.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const KOTLIN_FILES = [
const KOTLIN_TEST_FILES = [
'ImeLearningPolicyTest.kt',
'ImePrivacyPolicyTest.kt',
'LatinInputModeTest.kt',
'OpenLessContentReaderTest.kt',
'OpenLessCredentialCipherTest.kt',
'OpenLessShizukuBridgeTest.kt',
Expand Down
Loading