mirror of
https://github.com/SimpleMobileTools/Simple-Keyboard.git
synced 2025-04-18 04:07:25 +02:00
feature(language): add vi string + config Vn
Signed-off-by: Hung <>
This commit is contained in:
parent
b57a0461cf
commit
01aeabdf9a
@ -14,6 +14,7 @@ import com.simplemobiletools.keyboard.extensions.getKeyboardLanguages
|
|||||||
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_LARGE
|
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_LARGE
|
||||||
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM
|
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM
|
||||||
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_SMALL
|
import com.simplemobiletools.keyboard.helpers.KEYBOARD_HEIGHT_MULTIPLIER_SMALL
|
||||||
|
import com.simplemobiletools.keyboard.helpers.LANGUAGE_VIETNAMESE_TELEX
|
||||||
import kotlinx.android.synthetic.main.activity_settings.*
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
@ -51,3 +51,4 @@ const val KEYBOARD_HEIGHT_MULTIPLIER_MEDIUM = 2
|
|||||||
const val KEYBOARD_HEIGHT_MULTIPLIER_LARGE = 3
|
const val KEYBOARD_HEIGHT_MULTIPLIER_LARGE = 3
|
||||||
|
|
||||||
const val EMOJI_SPEC_FILE_PATH = "media/emoji_spec.txt"
|
const val EMOJI_SPEC_FILE_PATH = "media/emoji_spec.txt"
|
||||||
|
const val LANGUAGE_VN_TELEX = "language/extension.json"
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package com.simplemobiletools.keyboard.helpers
|
package com.simplemobiletools.keyboard.helpers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
private var cachedEmojiData: MutableList<String>? = null
|
private var cachedEmojiData: MutableList<String>? = null
|
||||||
|
val cachedVNTelexData: HashMap<String,String> = HashMap()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the emoji list at the given [path] and returns an parsed [MutableList]. If the
|
* Reads the emoji list at the given [path] and returns an parsed [MutableList]. If the
|
||||||
@ -59,3 +62,27 @@ fun parseRawEmojiSpecsFile(context: Context, path: String): MutableList<String>
|
|||||||
cachedEmojiData = emojis
|
cachedEmojiData = emojis
|
||||||
return emojis
|
return emojis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun parseRawJsonSpecsFile(context: Context, path: String): HashMap<String,String> {
|
||||||
|
if (cachedVNTelexData.isNotEmpty()) {
|
||||||
|
return cachedVNTelexData
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val inputStream: InputStream = context.assets.open(path)
|
||||||
|
val jsonString = inputStream.bufferedReader().use{it.readText()}
|
||||||
|
val jsonData = JSONObject(jsonString)
|
||||||
|
val rulesObj = jsonData.getJSONObject("rules")
|
||||||
|
val ruleKeys = rulesObj.keys()
|
||||||
|
while (ruleKeys.hasNext()){
|
||||||
|
val key = ruleKeys.next()
|
||||||
|
val value = rulesObj.getString(key)
|
||||||
|
cachedVNTelexData[key] = value
|
||||||
|
}
|
||||||
|
} catch (ex: Exception) {
|
||||||
|
ex.printStackTrace()
|
||||||
|
return HashMap()
|
||||||
|
}
|
||||||
|
return cachedVNTelexData
|
||||||
|
}
|
||||||
|
@ -178,10 +178,38 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
|||||||
switchToLetters = true
|
switchToLetters = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
inputConnection.commitText(codeChar.toString(), 1)
|
when {
|
||||||
if (originalText == null) {
|
originalText != null && originalText.isNotEmpty() && cachedVNTelexData.isNotEmpty() -> {
|
||||||
updateShiftKeyState()
|
val fullText = originalText.toString() + codeChar.toString()
|
||||||
|
val lastIndexEmpty = if (fullText.contains(" ")) {
|
||||||
|
fullText.lastIndexOf(" ")
|
||||||
|
} else 0
|
||||||
|
if (lastIndexEmpty >= 0) {
|
||||||
|
val word = fullText.subSequence(lastIndexEmpty, fullText.length).trim().toString()
|
||||||
|
val wordChars = word.toCharArray()
|
||||||
|
val predictWord = StringBuilder()
|
||||||
|
for (char in wordChars.size -1 downTo 0) {
|
||||||
|
predictWord.append(wordChars[char])
|
||||||
|
val shouldChangeText = predictWord.reverse().toString()
|
||||||
|
if (cachedVNTelexData.containsKey(shouldChangeText)) {
|
||||||
|
inputConnection.setComposingRegion(fullText.length - shouldChangeText.length, fullText.length)
|
||||||
|
inputConnection.setComposingText(cachedVNTelexData[shouldChangeText], fullText.length)
|
||||||
|
inputConnection.setComposingRegion(fullText.length, fullText.length)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inputConnection.commitText(codeChar.toString(), 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
inputConnection.commitText(codeChar.toString(), 1)
|
||||||
|
if (originalText == null) {
|
||||||
|
updateShiftKeyState()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -418,6 +418,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
}
|
}
|
||||||
|
|
||||||
setupEmojiPalette(toolbarColor = toolbarColor, backgroundColor = mBackgroundColor, textColor = mTextColor)
|
setupEmojiPalette(toolbarColor = toolbarColor, backgroundColor = mBackgroundColor, textColor = mTextColor)
|
||||||
|
if(context.config.keyboardLanguage == LANGUAGE_VIETNAMESE_TELEX){
|
||||||
|
setupLanguageTelex()
|
||||||
|
}else{
|
||||||
|
cachedVNTelexData.clear()
|
||||||
|
}
|
||||||
setupStoredClips()
|
setupStoredClips()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1506,6 +1511,13 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For Vietnamese - Telex
|
||||||
|
private fun setupLanguageTelex() {
|
||||||
|
ensureBackgroundThread {
|
||||||
|
parseRawJsonSpecsFile(context, LANGUAGE_VN_TELEX)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupEmojiAdapter(emojis: List<String>) {
|
private fun setupEmojiAdapter(emojis: List<String>) {
|
||||||
mEmojiPaletteHolder?.emojis_list?.apply {
|
mEmojiPaletteHolder?.emojis_list?.apply {
|
||||||
val emojiItemWidth = context.resources.getDimensionPixelSize(R.dimen.emoji_item_size)
|
val emojiItemWidth = context.resources.getDimensionPixelSize(R.dimen.emoji_item_size)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user