beautiful

This commit is contained in:
polwex 2024-11-24 20:08:21 +07:00
parent c06aff7133
commit 8aac0ac2f5
78 changed files with 122 additions and 15 deletions

View File

@ -13,6 +13,7 @@ import android.widget.Button
import android.widget.HorizontalScrollView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.res.ResourcesCompat
import kotlin.properties.Delegates
@ -25,6 +26,7 @@ class MyKeyboardService : InputMethodService() {
private lateinit var keyboardContainer: LinearLayout
private lateinit var suggestionsContainer: LinearLayout
private lateinit var currentInputDisplay: TextView
private lateinit var currentTitle: TextView
private var isShiftActive = false
private fun updateCurrentInputDisplay(text: String) {
@ -40,10 +42,13 @@ class MyKeyboardService : InputMethodService() {
"ASDFGHJKL".toList(),
"ZXCVBNM".toList()
)
data class FontInfo(val resourceId: Int, val name: String)
private val fonts = listOf(
Typeface.NORMAL,
// Typeface.createFromAsset(assets, "fonts/round.ttf")
FontInfo(R.font.charm_regular,"charm"),
FontInfo(R.font.ibmplexsansthai_regular,"ibm"),
FontInfo(R.font.chonburi_regular,"chonburi"),
FontInfo(R.font.judson_regular,"judson"),
FontInfo(R.font.kanit_regular, "kanit")
)
private var currentFontIndex = 0
@ -53,6 +58,7 @@ class MyKeyboardService : InputMethodService() {
val inputView = layoutInflater.inflate(R.layout.keyboard_layout, null)
// Initialize views using findViewById
currentTitle = inputView.findViewById(R.id.keyboard_title)
currentInputDisplay = inputView.findViewById(R.id.current_input_display)
suggestionsContainer = inputView.findViewById(R.id.suggestions_container)
keyboardContainer = inputView.findViewById(R.id.keyboard_container)
@ -211,7 +217,6 @@ class MyKeyboardService : InputMethodService() {
val button = Button(this).apply{
text = option
textSize = 20f
// typeface = fonts[currentFontIndex] // Set the current font
setOnClickListener { onSuggestionClicked(option) }
layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
@ -243,22 +248,17 @@ class MyKeyboardService : InputMethodService() {
}
private fun changeFont(_thing: String){
currentFontIndex = (currentFontIndex + 1) % fonts.size
Log.d("THAI_IME", "🔤 Changed font to index: $currentFontIndex")
// Refresh suggestions with new font
redrawCurrentSuggestions()
}
private fun redrawCurrentSuggestions() {
val currentButtons = mutableListOf<String>()
val currentFont = fonts[currentFontIndex]
currentTitle.text = currentFont.name
val typeface = ResourcesCompat.getFont(this, currentFont.resourceId)
for (i in 0 until suggestionsContainer.childCount) {
val button = suggestionsContainer.getChildAt(i) as? Button
button?.text?.toString()?.let { currentButtons.add(it) }
button?.let{
it.typeface = typeface
}
}
displaySuggestions(currentButtons)
}
// TODO: Add methods for handling shift and number toggle
}
object ViewDebugUtils {
fun getViewHierarchy(view: View?, level: Int = 0): String {

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/charm_regular" />
<font
android:fontStyle="normal"
android:fontWeight="700"
android:font="@font/charm_bold" />
</font-family>

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/chonburi_regular" />
</font-family>

Binary file not shown.

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/ibmplexsansthai_regular" />
<font
android:fontStyle="normal"
android:fontWeight="700"
android:font="@font/ibmplexsansthai_bold" />
<font
android:fontStyle="normal"
android:fontWeight="250"
android:font="@font/ibmplexsansthai_light" />
<font
android:fontStyle="normal"
android:fontWeight="100"
android:font="@font/ibmplexsansthai_extralight" />
<font
android:fontStyle="normal"
android:fontWeight="550"
android:font="@font/ibmplexsansthai_semibold" />
<font
android:fontStyle="normal"
android:fontWeight="300"
android:font="@font/ibmplexsansthai_medium" />
<font
android:fontStyle="normal"
android:fontWeight="200"
android:font="@font/ibmplexsansthai_thin" />
</font-family>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/judson_regular" />
<font
android:fontStyle="normal"
android:fontWeight="700"
android:font="@font/judson_bold" />
<font
android:fontStyle="italic"
android:fontWeight="700"
android:font="@font/judson_italic" />
</font-family>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/kanit_regular" />
<font
android:fontStyle="normal"
android:fontWeight="700"
android:font="@font/kanit_bold" />
<font
android:fontStyle="normal"
android:fontWeight="900"
android:font="@font/kanit_extrabold" />
<font
android:fontStyle="normal"
android:fontWeight="250"
android:font="@font/kanit_light" />
<font
android:fontStyle="normal"
android:fontWeight="100"
android:font="@font/kanit_extralight" />
<font
android:fontStyle="normal"
android:fontWeight="550"
android:font="@font/kanit_semibold" />
<font
android:fontStyle="normal"
android:fontWeight="300"
android:font="@font/kanit_medium" />
<font
android:fontStyle="normal"
android:fontWeight="200"
android:font="@font/kanit_thin" />
<font
android:fontStyle="italic"
android:fontWeight="250"
android:font="@font/kanit_thinitalic" />
<font
android:fontStyle="italic"
android:fontWeight="700"
android:font="@font/kanit_bolditalic" />
</font-family>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.