@@ -6,6 +6,7 @@ package com.osfans.trime.ime.symbol
6
6
7
7
import android.annotation.SuppressLint
8
8
import android.content.Context
9
+ import android.graphics.drawable.GradientDrawable
9
10
import androidx.constraintlayout.widget.ConstraintLayout
10
11
import androidx.core.view.setPadding
11
12
import com.osfans.trime.data.theme.ColorManager
@@ -14,7 +15,6 @@ import com.osfans.trime.data.theme.FontManager
14
15
import com.osfans.trime.data.theme.Theme
15
16
import com.osfans.trime.ime.core.TrimeInputMethodService
16
17
import splitties.dimensions.dp
17
- import splitties.views.backgroundColor
18
18
import splitties.views.dsl.constraintlayout.above
19
19
import splitties.views.dsl.constraintlayout.after
20
20
import splitties.views.dsl.constraintlayout.before
@@ -48,11 +48,11 @@ class LiquidLayout(context: Context, service: TrimeInputMethodService, theme: Th
48
48
// TODO: 继承一个键盘视图嵌入到这里,而不是自定义一个视图
49
49
private val fixedKeyBar =
50
50
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 {
53
53
val btns =
54
- Array (it.size) {
55
- val operation = operations.get(it)
54
+ Array (it.size) { index ->
55
+ val operation = fixedKeys[index]
56
56
val text =
57
57
textView {
58
58
text =
@@ -65,15 +65,20 @@ class LiquidLayout(context: Context, service: TrimeInputMethodService, theme: Th
65
65
}
66
66
val root =
67
67
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
+ }
68
75
add(
69
76
text,
70
77
lParams(matchParent, wrapContent) {
71
78
gravity = gravityCenter
72
79
padding = dp(5 )
73
80
},
74
81
)
75
- ColorManager .getColor(" key_back_color" )
76
- ?.let { bg -> backgroundColor = bg }
77
82
// todo 想办法实现退格键、空格键等 repeatable: true 长按连续触发
78
83
setOnClickListener {
79
84
val event = EventManager .getEvent(operation.toString())
@@ -85,6 +90,7 @@ class LiquidLayout(context: Context, service: TrimeInputMethodService, theme: Th
85
90
}
86
91
return @Array root
87
92
}
93
+ val marginX = theme.liquid.getFloat(" margin_x" )
88
94
when (
89
95
theme.liquid.getMap(" fixed_key_bar" )
90
96
?.get(" position" )?.configValue.toString()
@@ -94,8 +100,18 @@ class LiquidLayout(context: Context, service: TrimeInputMethodService, theme: Th
94
100
add(
95
101
btn,
96
102
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
+ }
99
115
},
100
116
)
101
117
}
@@ -106,8 +122,18 @@ class LiquidLayout(context: Context, service: TrimeInputMethodService, theme: Th
106
122
add(
107
123
btn,
108
124
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
+ }
111
137
},
112
138
)
113
139
}
0 commit comments