Skip to content

Commit 7a7997e

Browse files
shitlimeWhiredPlanck
authored andcommitted
feat: fixed key bar support round_corner , margin_x
1 parent d92686b commit 7a7997e

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

app/src/main/java/com/osfans/trime/ime/symbol/LiquidLayout.kt

+37-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package com.osfans.trime.ime.symbol
66

77
import android.annotation.SuppressLint
88
import android.content.Context
9+
import android.graphics.drawable.GradientDrawable
910
import androidx.constraintlayout.widget.ConstraintLayout
1011
import androidx.core.view.setPadding
1112
import com.osfans.trime.data.theme.ColorManager
@@ -14,7 +15,6 @@ import com.osfans.trime.data.theme.FontManager
1415
import com.osfans.trime.data.theme.Theme
1516
import com.osfans.trime.ime.core.TrimeInputMethodService
1617
import splitties.dimensions.dp
17-
import splitties.views.backgroundColor
1818
import splitties.views.dsl.constraintlayout.above
1919
import splitties.views.dsl.constraintlayout.after
2020
import splitties.views.dsl.constraintlayout.before
@@ -48,11 +48,11 @@ class LiquidLayout(context: Context, service: TrimeInputMethodService, theme: Th
4848
// TODO: 继承一个键盘视图嵌入到这里,而不是自定义一个视图
4949
private val fixedKeyBar =
5050
constraintLayout {
51-
val operations = theme.liquid.getMap("fixed_key_bar")?.get("keys")?.configList
52-
operations?.let {
51+
val fixedKeys = theme.liquid.getMap("fixed_key_bar")?.get("keys")?.configList
52+
fixedKeys?.let {
5353
val btns =
54-
Array(it.size) {
55-
val operation = operations.get(it)
54+
Array(it.size) { index ->
55+
val operation = fixedKeys[index]
5656
val text =
5757
textView {
5858
text =
@@ -65,15 +65,20 @@ class LiquidLayout(context: Context, service: TrimeInputMethodService, theme: Th
6565
}
6666
val root =
6767
frameLayout {
68+
background =
69+
GradientDrawable().apply {
70+
cornerRadius = theme.generalStyle.roundCorner.toFloat()
71+
ColorManager.getColor("key_back_color")?.let { bg ->
72+
setColor(bg)
73+
}
74+
}
6875
add(
6976
text,
7077
lParams(matchParent, wrapContent) {
7178
gravity = gravityCenter
7279
padding = dp(5)
7380
},
7481
)
75-
ColorManager.getColor("key_back_color")
76-
?.let { bg -> backgroundColor = bg }
7782
// todo 想办法实现退格键、空格键等 repeatable: true 长按连续触发
7883
setOnClickListener {
7984
val event = EventManager.getEvent(operation.toString())
@@ -85,6 +90,7 @@ class LiquidLayout(context: Context, service: TrimeInputMethodService, theme: Th
8590
}
8691
return@Array root
8792
}
93+
val marginX = theme.liquid.getFloat("margin_x")
8894
when (
8995
theme.liquid.getMap("fixed_key_bar")
9096
?.get("position")?.configValue.toString()
@@ -94,8 +100,18 @@ class LiquidLayout(context: Context, service: TrimeInputMethodService, theme: Th
94100
add(
95101
btn,
96102
lParams(wrapContent, matchConstraints) {
97-
if (i == 0) topOfParent() else below(btns[i - 1])
98-
if (i == btns.size - 1) bottomOfParent() else above(btns[i + 1])
103+
if (i == 0) {
104+
topOfParent()
105+
} else {
106+
topMargin = dp(marginX).toInt()
107+
below(btns[i - 1])
108+
}
109+
if (i == btns.size - 1) {
110+
bottomOfParent()
111+
} else {
112+
bottomMargin = dp(marginX).toInt()
113+
above(btns[i + 1])
114+
}
99115
},
100116
)
101117
}
@@ -106,8 +122,18 @@ class LiquidLayout(context: Context, service: TrimeInputMethodService, theme: Th
106122
add(
107123
btn,
108124
lParams(wrapContent, matchConstraints) {
109-
if (i == 0) startOfParent() else after(btns[i - 1])
110-
if (i == btns.size - 1) endOfParent() else before(btns[i + 1])
125+
if (i == 0) {
126+
startOfParent()
127+
} else {
128+
leftMargin = dp(marginX).toInt()
129+
after(btns[i - 1])
130+
}
131+
if (i == btns.size - 1) {
132+
endOfParent()
133+
} else {
134+
rightMargin = dp(marginX).toInt()
135+
before(btns[i + 1])
136+
}
111137
},
112138
)
113139
}

0 commit comments

Comments
 (0)