This commit is contained in:
Nehemiah of Zebulun 2023-08-28 16:26:17 +02:00
parent 84f3178783
commit d1bc4a0061
16 changed files with 209 additions and 51 deletions

View File

@ -10,6 +10,7 @@ import android.view.KeyEvent
import android.view.View
import android.view.ViewConfiguration
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
@ -112,6 +113,10 @@ class WKT9: InputMethodService() {
inputMode = null
cursorPosition = 0
sentenceStart = false
}
override fun onFinishInputView(finishingInput: Boolean) {
super.onFinishInputView(finishingInput)
clearCandidates()
}
@ -175,7 +180,7 @@ class WKT9: InputMethodService() {
else -> Log.d(tag, "Mode without input...")
}
showStatusIcon(R.drawable.word_en_cap)
showStatusIcon(0)
super.onStartInput(attribute, restarting)
}
@ -200,6 +205,17 @@ class WKT9: InputMethodService() {
)
}
override fun showStatusIcon(iconResId: Int) {
if (iconResId != 0) super.showStatusIcon(iconResId)
when (inputMode) {
is WordInputMode -> super.showStatusIcon(R.drawable.word)
is AlphaInputMode -> super.showStatusIcon(R.drawable.alpha)
is NumericInputMode -> super.showStatusIcon(R.drawable.numeric)
else -> super.showStatusIcon(R.drawable.wkt9)
}
}
private fun clearCandidates() {
clearCandidateUI()
@ -272,6 +288,7 @@ class WKT9: InputMethodService() {
if (res.record) onRecord()
if (res.transcribe) onTranscribe()
if (res.updateStatus) onUpdateStatus()
if (res.focus) onFocus()
return res.consumed
}
@ -293,9 +310,10 @@ class WKT9: InputMethodService() {
candidates.forEachIndexed { index, candidate ->
val layout = if (index == highLight) R.layout.current_suggestion else R.layout.suggestion
val candidateView = layoutInflater.inflate(layout, null) as TextView
val candidateView = layoutInflater.inflate(layout, null)
val textView = candidateView.findViewById<TextView>(R.id.suggestion_text)
candidateView.text = candidate
textView.text = candidate
candidatesView.addView(candidateView)
}
@ -342,6 +360,10 @@ class WKT9: InputMethodService() {
deleteText(beforeCursor, afterCursor)
}
private fun onFocus() {
requestShowSelf(InputMethodManager.SHOW_IMPLICIT)
}
private fun onLeft() {
if (candidates.isEmpty()) return
@ -356,10 +378,11 @@ class WKT9: InputMethodService() {
private fun onRecord() {
// The recorder must be busy...
if (recorder !== null) return
if (recorder !== null || !isInputViewShown) return
clearCandidates()
// Delete possible existing recording
recording?.delete()
// Toast settings

View File

@ -32,6 +32,7 @@ class WordInputMode: InputMode {
Command.SPACE -> finalizeWordOrSentence()
Command.LEFT -> navigateLeft()
Command.RIGHT -> navigateRight()
Command.SELECT -> focus()
else -> KeyEventResult()
}
}
@ -80,9 +81,7 @@ class WordInputMode: InputMode {
}
private fun deleteCharacter(repeat: Int = 0): KeyEventResult {
if (repeat % 2 != 0) return KeyEventResult()
codeWord.clear()
if (repeat == 0) codeWord.clear()
return KeyEventResult(
finishComposing = true,
@ -104,6 +103,13 @@ class WordInputMode: InputMode {
)
}
private fun focus(): KeyEventResult {
return KeyEventResult(
consumed = true,
focus = true
)
}
private fun goBack(): KeyEventResult {
reset()

View File

@ -16,5 +16,6 @@ data class KeyEventResult(
val record: Boolean = false,
val transcribe: Boolean = false,
val updateStatus: Boolean = false,
val sentenceStart: Boolean? = null
val sentenceStart: Boolean? = null,
val focus: Boolean = false
)

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp"/>
<solid android:color="@color/suggestion"/>
<padding
android:bottom="5dp"
android:left="10dp"
android:right="10dp"
android:top="5dp"/>
</shape>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp"/>
<solid android:color="@color/button"/>
<padding
android:bottom="5dp"
android:left="10dp"
android:right="10dp"
android:top="5dp"/>
</shape>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:fillColor="#FF000000"
android:pathData="m1.48,14.288q1.632,-0.64 3.168,-1.6 1.536,-0.992 2.848,-2.496h1.856V27.76H13.096V30H2.44v-2.24h4.288V13.872q-0.352,0.32 -0.864,0.672 -0.48,0.32 -1.088,0.64 -0.576,0.32 -1.216,0.608 -0.64,0.288 -1.248,0.48zM29.72,15.248q0,1.024 -0.416,1.984 -0.384,0.96 -1.056,1.888 -0.64,0.928 -1.472,1.824 -0.832,0.896 -1.696,1.76 -0.48,0.48 -1.12,1.152 -0.64,0.672 -1.216,1.376 -0.576,0.704 -0.96,1.376Q21.4,27.28 21.4,27.76h9.12V30h-12q-0.032,-0.16 -0.032,-0.32 0,-0.192 0,-0.352 0,-1.344 0.448,-2.496 0.448,-1.152 1.152,-2.176 0.704,-1.024 1.568,-1.92 0.896,-0.928 1.76,-1.792 0.704,-0.704 1.344,-1.376 0.672,-0.672 1.152,-1.344 0.512,-0.672 0.8,-1.376 0.32,-0.736 0.32,-1.504 0,-0.864 -0.288,-1.472Q26.488,13.264 26.008,12.88 25.56,12.464 24.952,12.272 24.344,12.08 23.64,12.08q-0.832,0 -1.536,0.224 -0.672,0.224 -1.216,0.544 -0.512,0.32 -0.896,0.64 -0.384,0.288 -0.576,0.48l-1.312,-1.856q0.256,-0.288 0.768,-0.704 0.512,-0.416 1.216,-0.768 0.736,-0.384 1.632,-0.64 0.896,-0.256 1.92,-0.256 3.104,0 4.576,1.44 1.504,1.408 1.504,4.064z"/>
</vector>

View File

@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="0.96"
android:viewportHeight="0.96">
<path
android:pathData="m0.18075,0.8793c0.19619,-0.02192 0.39089,-0.02758 0.5985,0 -0.19521,0.01799 -0.39496,0.01693 -0.5985,0zM0.651,0.51845c-0.05353,0.08123 -0.04917,0.13923 0,0.20047H0.309c0.04484,-0.06042 0.06139,-0.13157 0,-0.20047H0.09525C0.23696,0.41241 0.38726,0.31548 0.48,0.15761 0.58714,0.30213 0.72501,0.41137 0.86475,0.51845Z"
android:strokeLineJoin="miter"
android:strokeWidth="0.0624"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="square"/>
</vector>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dip"
android:color="@color/suggestion" />
</shape>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dip"
android:color="@color/current_suggestion" />
</shape>

View File

@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:fillColor="#FF000000"
android:pathData="M6.728,15.126 L4.496,15.344Q4.002,14.054 3.521,12.499 3.064,10.919 2.585,9.21 2.135,7.498 1.699,5.696 1.262,3.895 0.858,2.113L3.177,1.886 5.469,13.01 7.001,6.669 9.088,6.465 12.831,12.289 11.177,1.102 13.496,0.874q0.234,1.821 0.409,3.648 0.205,1.824 0.336,3.567 0.128,1.722 0.203,3.317 0.076,1.595 0.08,2.956L12.322,14.577 8.335,8.207ZM28.171,0.869q-1.142,1.714 -2.577,3.436 -1.406,1.718 -3.103,3.465 1.031,0.492 2.211,1.166 1.181,0.675 2.33,1.506 1.175,0.807 2.227,1.757 1.082,0.948 1.881,1.967l-2.696,0.264Q27.546,13.508 26.537,12.641 25.529,11.774 24.427,11.048 23.355,10.319 22.222,9.749 21.115,9.156 20.012,8.759l1.129,6.387 -2.377,0.233 -2.362,-13.357 2.377,-0.233 1.053,5.955Q21.461,6.114 22.893,4.371 24.353,2.626 25.417,1.139Z"
android:strokeWidth="0.996"/>
<path
android:fillColor="#FF000000"
android:pathData="M14.253,17.249 L14.543,18.724 9.183,19.195 11.462,30.764 8.877,30.991 6.598,19.423 1.238,19.894 0.948,18.419ZM30.741,22.513q0.768,3.898 -1.679,6.129 -2.452,2.209 -8.154,2.733l-0.385,-1.467q3.531,-0.311 5.492,-1.427 1.989,-1.14 2.23,-3.498 -0.711,0.298 -1.596,0.526 -0.889,0.207 -1.898,0.296 -1.671,0.147 -2.868,-0.069 -1.201,-0.237 -2.003,-0.724 -0.806,-0.508 -1.262,-1.197 -0.456,-0.689 -0.614,-1.489 -0.141,-0.716 0.06,-1.485 0.197,-0.789 0.802,-1.464 0.605,-0.675 1.661,-1.175 1.056,-0.5 2.633,-0.639 3.216,-0.283 5.146,1.048 1.93,1.331 2.436,3.902zM24.751,24.348q1.009,-0.089 1.835,-0.29 0.858,-0.204 1.632,-0.508 -0.01,-0.213 -0.047,-0.403 -0.037,-0.19 -0.079,-0.4 -0.162,-0.822 -0.496,-1.543 -0.303,-0.724 -0.852,-1.233 -0.518,-0.512 -1.337,-0.761 -0.792,-0.273 -1.927,-0.173 -0.946,0.083 -1.522,0.413 -0.581,0.308 -0.912,0.745 -0.335,0.415 -0.429,0.917 -0.062,0.499 0.025,0.941 0.253,1.285 1.237,1.885 1.011,0.576 2.872,0.412z"
android:strokeWidth="1.026"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:fillColor="#FF000000"
android:pathData="M14.376,1.445L14.376,4.802L8.936,4.802L8.936,31.13h-2.624L6.312,4.802h-5.44L0.872,1.445ZM31.128,13.338q0,8.872 -2.88,13.38Q25.368,31.178 19.576,31.226L19.48,27.869q3.584,0 5.76,-2.11 2.208,-2.158 2.912,-7.385 -0.768,0.528 -1.696,0.863 -0.928,0.288 -1.952,0.288 -1.696,0 -2.848,-0.719 -1.152,-0.767 -1.856,-2.014 -0.704,-1.295 -1.024,-2.925 -0.32,-1.631 -0.32,-3.453 0,-1.631 0.352,-3.309 0.352,-1.726 1.088,-3.117 0.736,-1.391 1.888,-2.302 1.152,-0.911 2.752,-0.911 3.264,0 4.928,3.357 1.664,3.357 1.664,9.208zM24.792,16.264q1.024,0 1.888,-0.288 0.896,-0.288 1.728,-0.815 0.032,-0.48 0.032,-0.911 0,-0.432 0,-0.911 0,-1.87 -0.192,-3.549Q28.088,8.111 27.64,6.864 27.224,5.617 26.456,4.898 25.72,4.131 24.568,4.131q-0.96,0 -1.6,0.623 -0.64,0.575 -1.056,1.487 -0.416,0.863 -0.608,1.966 -0.16,1.103 -0.16,2.11 0,2.925 0.864,4.46 0.896,1.487 2.784,1.487z"
android:strokeWidth="1.22419"/>
</vector>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp"/>
<solid android:color="@color/current_suggestion"/>
<padding
android:bottom="5dp"
android:left="10dp"
android:right="10dp"
android:top="5dp"/>
</shape>

View File

@ -1,13 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/suggestion"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:background="@drawable/suggestion_current_border"
android:textFontWeight="600"
android:textSize="20sp"
android:minWidth="40dp"
android:textAlignment="center"
android:textColor="@color/current_suggestion" />
android:id="@+id/current_suggestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp">
<TextView
android:id="@+id/suggestion_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/yellow_radius"
android:textColor="@color/suggestion_text"
android:paddingVertical="5dp"
android:paddingHorizontal="8dp"
android:textSize="20sp"
android:textFontWeight="600" />
</LinearLayout>

View File

@ -1,13 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/suggestion"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:background="@drawable/suggestion_border"
android:textFontWeight="600"
android:textSize="20sp"
android:minWidth="40dp"
android:textAlignment="center"
android:textColor="@color/suggestion" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp">
<TextView
android:id="@+id/suggestion_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/blue_radius"
android:textColor="@color/suggestion_text"
android:paddingVertical="5dp"
android:paddingHorizontal="8dp"
android:textSize="20sp"
android:textFontWeight="600" />
</LinearLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<HorizontalScrollView
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -7,13 +7,55 @@
android:layout_gravity="bottom"
android:theme="@style/Theme.AppCompat.DayNight"
android:gravity="bottom"
android:orientation="vertical">
android:background="@color/black"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/suggestions"
android:background="@color/black"
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
<LinearLayout
android:background="@color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="3dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingVertical="2dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_radius"
android:textColor="@color/button_text"
android:layout_marginEnd="2dp"
android:paddingVertical="5dp"
android:paddingHorizontal="8dp"
android:textSize="20sp"
android:textFontWeight="600"
android:text="En" />
<View
android:layout_marginHorizontal="4dp"
android:layout_marginVertical="4dp"
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="@color/suggestion_text"/>
</LinearLayout>
<LinearLayout
android:id="@+id/suggestions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>

View File

@ -7,6 +7,9 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="button">#637783</color>
<color name="button_text">#FFFCF0</color>
<color name="suggestion">#C1E8FF</color>
<color name="current_suggestion">#FFC1F0</color>
<color name="current_suggestion">#FFE3C1</color>
<color name="suggestion_text">#424242</color>
</resources>