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
2 changes: 1 addition & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@
<string name="indent_small_adjustment">2段目の余白の微調整</string>
<string name="side_margin_edge_keys">3段目の両端の余白</string>
<string name="qwerty_key_letter_size">キーの文字サイズ</string>
<string name="qwerty_symbol_keymap_text_size">記号キーマップの文字サイズ</string>
<string name="qwerty_symbol_keymap_text_size">記号キーマップ・数字フリック文字のサイズ</string>
<string name="qwerty_special_key_text_size">特殊キーの文字サイズ</string>
<string name="qwerty_special_key_icon_size">特殊キーのアイコンサイズ</string>
<string name="reset_to_default">初期値に戻す</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@
<string name="indent_small_adjustment">Indent Small (Adjustment)</string>
<string name="side_margin_edge_keys">Side Margin (Edge keys)</string>
<string name="qwerty_key_letter_size">Key Letter Size</string>
<string name="qwerty_symbol_keymap_text_size">Symbol Keymap Text Size</string>
<string name="qwerty_symbol_keymap_text_size">Symbol Map / Number Flick Text Size</string>
<string name="qwerty_special_key_text_size">Special Key Text Size</string>
<string name="qwerty_special_key_icon_size">Special Key Icon Size</string>
<string name="reset_to_default">Reset to Default</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.kazumaproject.qwerty_keyboard.ui

import android.content.Context
import android.view.ContextThemeWrapper
import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.kazumaproject.qwerty_keyboard.R
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class QwertyGuideTextSizeInstrumentedTest {

@Test
fun guideTextSizeAppliesToLetterAndNumberKeyGuides() {
runOnMain {
val keyboard = createKeyboard()

keyboard.setKeyMargins(symbolKeymapTextSizeSp = 15f)

assertEquals(15f, keyboard.findViewById<QWERTYButton>(R.id.key_a).guideTextSizeSp)
assertEquals(15f, keyboard.findViewById<QWERTYButton>(R.id.key_1).guideTextSizeSp)
assertEquals(15f, keyboard.findViewById<QWERTYButton>(R.id.key_0).guideTextSizeSp)
}
}

@Test
fun guideTextSizeUsesQwertyButtonBounds() {
runOnMain {
val keyboard = createKeyboard()
val numberKey = keyboard.findViewById<QWERTYButton>(R.id.key_1)

keyboard.setKeyMargins(symbolKeymapTextSizeSp = 100f)
assertEquals(24f, numberKey.guideTextSizeSp)

keyboard.setKeyMargins(symbolKeymapTextSizeSp = 1f)
assertEquals(4f, numberKey.guideTextSizeSp)
}
}

private fun createKeyboard(): QWERTYKeyboardView {
val targetContext = InstrumentationRegistry.getInstrumentation().targetContext
val themedContext: Context = ContextThemeWrapper(
targetContext,
com.google.android.material.R.style.Theme_Material3_DayNight_NoActionBar
)
return QWERTYKeyboardView(themedContext).apply {
val widthSpec = View.MeasureSpec.makeMeasureSpec(1080, View.MeasureSpec.EXACTLY)
val heightSpec = View.MeasureSpec.makeMeasureSpec(500, View.MeasureSpec.EXACTLY)
measure(widthSpec, heightSpec)
layout(0, 0, 1080, 500)
}
}

private fun runOnMain(block: () -> Unit) {
InstrumentationRegistry.getInstrumentation().runOnMainSync(block)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ class QWERTYKeyboardView @JvmOverloads constructor(
applyLayoutForMode(qwertyMode.value)

updateAllKeyTextSizes()
updateSymbolKeymapTextSizes()
updateGuideTextSizes()
updateSpecialKeyTextSizes()
refreshSpecialKeyIconSizesWhenLaidOut()
}
Expand Down Expand Up @@ -805,8 +805,9 @@ class QWERTYKeyboardView @JvmOverloads constructor(
}
}

private fun updateSymbolKeymapTextSizes() {
defaultQWERTYButtonsRoman.distinct().forEach { view ->
private fun updateGuideTextSizes() {
val guideButtons = defaultQWERTYButtonsRoman.asList() + numberRowButtons.asList()
guideButtons.distinct().forEach { view ->
view.guideTextSizeSp = symbolKeymapTextSizeSp
}
}
Expand Down Expand Up @@ -1314,6 +1315,13 @@ class QWERTYKeyboardView @JvmOverloads constructor(
)
}

private val numberRowButtons: Array<QWERTYButton> by lazy {
arrayOf(
binding.key1, binding.key2, binding.key3, binding.key4, binding.key5,
binding.key6, binding.key7, binding.key8, binding.key9, binding.key0
)
}

private fun attachDefaultKeyLabels() {
val chars =
if (romajiModeState.value) QWERTYKeys.DEFAULT_KEYS_JP else QWERTYKeys.DEFAULT_KEYS
Expand Down
Loading