@@ -28,8 +28,6 @@ import android.os.Handler
28
28
import android.os.Looper
29
29
import android.os.Message
30
30
import android.text.InputType
31
- import android.text.TextUtils
32
- import android.view.Gravity
33
31
import android.view.KeyEvent
34
32
import android.view.LayoutInflater
35
33
import android.view.View
@@ -40,6 +38,7 @@ import android.view.inputmethod.CursorAnchorInfo
40
38
import android.view.inputmethod.EditorInfo
41
39
import android.view.inputmethod.ExtractedTextRequest
42
40
import android.widget.FrameLayout
41
+ import android.widget.LinearLayout
43
42
import androidx.annotation.Keep
44
43
import androidx.core.view.updateLayoutParams
45
44
import androidx.lifecycle.lifecycleScope
@@ -72,16 +71,15 @@ import com.osfans.trime.ime.text.ScrollView
72
71
import com.osfans.trime.ime.text.TextInputManager
73
72
import com.osfans.trime.util.ShortcutUtils
74
73
import com.osfans.trime.util.StringUtils
75
- import com.osfans.trime.util.ViewUtils
76
74
import com.osfans.trime.util.WeakHashSet
77
75
import com.osfans.trime.util.isNightMode
78
76
import kotlinx.coroutines.Dispatchers
79
77
import kotlinx.coroutines.launch
80
78
import splitties.bitflags.hasFlag
81
79
import splitties.dimensions.dp
82
80
import splitties.systemservices.inputMethodManager
81
+ import splitties.views.gravityBottom
83
82
import timber.log.Timber
84
- import java.util.Objects
85
83
86
84
/* * [輸入法][InputMethodService]主程序 */
87
85
@@ -109,7 +107,7 @@ open class Trime : LifecycleInputMethodService() {
109
107
private var minPopupSize = 0 // 上悬浮窗的候选词的最小词长
110
108
private var minPopupCheckSize = 0 // 第一屏候选词数量少于设定值,则候选词上悬浮窗。(也就是说,第一屏存在长词)此选项大于1时,min_length等参数失效
111
109
private var mCompositionPopupWindow: CompositionPopupWindow ? = null
112
- private var candidateExPage = false
110
+ var candidateExPage = false
113
111
114
112
@Keep
115
113
private val onThemeChangeListener =
@@ -119,14 +117,6 @@ open class Trime : LifecycleInputMethodService() {
119
117
}
120
118
}
121
119
122
- fun hasCandidateExPage (): Boolean {
123
- return candidateExPage
124
- }
125
-
126
- fun setCandidateExPage (value : Boolean ) {
127
- candidateExPage = value
128
- }
129
-
130
120
init {
131
121
try {
132
122
check(self == null ) { " Trime is already initialized" }
@@ -307,11 +297,11 @@ open class Trime : LifecycleInputMethodService() {
307
297
}
308
298
309
299
fun pasteByChar () {
310
- commitTextByChar(Objects .requireNonNull (ShortcutUtils .pasteFromClipboard(this )).toString())
300
+ commitTextByChar(checkNotNull (ShortcutUtils .pasteFromClipboard(this )).toString())
311
301
}
312
302
313
303
private fun showCompositionView (isCandidate : Boolean ) {
314
- if (TextUtils .isEmpty( Rime .compositionText) && isCandidate) {
304
+ if (Rime .compositionText.isEmpty( ) && isCandidate) {
315
305
mCompositionPopupWindow!! .hideCompositionView()
316
306
return
317
307
}
@@ -442,7 +432,7 @@ open class Trime : LifecycleInputMethodService() {
442
432
ic?.commitText(" \n " , 1 )
443
433
return
444
434
}
445
- if (! TextUtils .isEmpty( editorInfo!! .actionLabel) &&
435
+ if (! editorInfo!! .actionLabel.isNullOrEmpty( ) &&
446
436
editorInfo!! .actionId != EditorInfo .IME_ACTION_UNSPECIFIED
447
437
) {
448
438
val ic = currentInputConnection
@@ -1038,7 +1028,6 @@ open class Trime : LifecycleInputMethodService() {
1038
1028
} else {
1039
1029
mCandidate!! .setText(0 )
1040
1030
}
1041
- mCandidate!! .setExpectWidth(mainKeyboardView!! .width)
1042
1031
// 刷新候选词后,如果候选词超出屏幕宽度,滚动候选栏
1043
1032
mTabRoot!! .move(mCandidate!! .highlightLeft, mCandidate!! .highlightRight)
1044
1033
}
@@ -1113,22 +1102,18 @@ open class Trime : LifecycleInputMethodService() {
1113
1102
} else {
1114
1103
WindowManager .LayoutParams .MATCH_PARENT
1115
1104
}
1116
- val inputArea = w.findViewById<View >(android.R .id.inputArea)
1117
- // TODO: 需要获取到文本编辑框、完成按钮,设置其色彩和尺寸。
1118
- // if (isFullscreenMode()) {
1119
- // Timber.d("isFullscreenMode");
1120
- // /* In Fullscreen mode, when layout contains transparent color,
1121
- // * the background under input area will disturb users' typing,
1122
- // * so set the input area as light pink */
1123
- // inputArea.setBackgroundColor(parseColor("#ff660000"));
1124
- // } else {
1125
- // Timber.d("NotFullscreenMode");
1126
- // /* Otherwise, set it as light gray to avoid potential issue */
1127
- // inputArea.setBackgroundColor(parseColor("#dddddddd"));
1128
- // }
1129
- ViewUtils .updateLayoutHeightOf(inputArea, layoutHeight)
1130
- ViewUtils .updateLayoutGravityOf(inputArea, Gravity .BOTTOM )
1131
- ViewUtils .updateLayoutHeightOf(inputView!! , layoutHeight)
1105
+ val inputArea = w.decorView.findViewById<FrameLayout >(android.R .id.inputArea)
1106
+ inputArea.updateLayoutParams {
1107
+ height = layoutHeight
1108
+ if (this is FrameLayout .LayoutParams ) {
1109
+ this .gravity = inputArea.gravityBottom
1110
+ } else if (this is LinearLayout .LayoutParams ) {
1111
+ this .gravity = inputArea.gravityBottom
1112
+ }
1113
+ }
1114
+ inputView?.updateLayoutParams {
1115
+ height = layoutHeight
1116
+ }
1132
1117
}
1133
1118
}
1134
1119
0 commit comments