Skip to content

Commit

Permalink
refactor: remove alias of the input method service
Browse files Browse the repository at this point in the history
It may be useless now.
  • Loading branch information
WhiredPlanck committed Feb 26, 2024
1 parent 48801ee commit dab946c
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 58 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
android:theme="@style/Theme.TrimeAppTheme">

<service
android:name=".TrimeImeService"
android:name=".ime.core.TrimeInputMethodService"
android:exported="true"
android:label="@string/trime_app_name"
android:permission="android.permission.BIND_INPUT_METHOD">
Expand Down
14 changes: 0 additions & 14 deletions app/src/main/java/com/osfans/trime/TrimeImeService.kt

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/data/db/DraftHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.osfans.trime.data.db
import android.content.Context
import androidx.room.Room
import com.osfans.trime.data.AppPrefs
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.util.StringUtils.matches
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -70,7 +70,7 @@ object DraftHelper : CoroutineScope by CoroutineScope(SupervisorJob() + Dispatch
fun onInputEventChanged() {
if (!(limit != 0 && this::dftDao.isInitialized)) return

Trime.getService()
TrimeInputMethodService.getService()
.currentInputConnection
?.let { DatabaseBean.fromInputConnection(it) }
?.takeIf {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/ime/bar/QuickBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.osfans.trime.core.Rime
import com.osfans.trime.data.theme.ColorManager
import com.osfans.trime.databinding.CandidateBarBinding
import com.osfans.trime.databinding.TabBarBinding
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.ime.enums.SymbolKeyboardType
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
Expand All @@ -19,7 +19,7 @@ import splitties.views.dsl.core.matchParent

class QuickBar : KoinComponent {
private val context: Context by inject()
private val service: Trime by inject()
private val service: TrimeInputMethodService by inject()

val oldCandidateBar by lazy {
CandidateBarBinding.inflate(LayoutInflater.from(context)).apply {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/ime/core/EditorInstance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EditorInstance(private val ims: InputMethodService) {
}
}
val textInputManager: TextInputManager
get() = (ims as Trime).textInputManager ?: error("TextInputManager is null")
get() = (ims as TrimeInputMethodService).textInputManager ?: error("TextInputManager is null")

var lastCommittedText: CharSequence = ""

Expand Down Expand Up @@ -60,7 +60,7 @@ class EditorInstance(private val ims: InputMethodService) {
val commit = Rime.getRimeCommit()
commit?.let { commitText(it.commitText) }
Timber.i("\t<TrimeInput>\tcommitRimeText()\tupdateComposing")
(ims as Trime).updateComposing()
(ims as TrimeInputMethodService).updateComposing()
return commit != null
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/ime/core/InputView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import splitties.views.imageDrawable
*/
@SuppressLint("ViewConstructor")
class InputView(
val service: Trime,
val service: TrimeInputMethodService,
val rime: Rime,
) : ConstraintLayout(service), KoinComponent {
private val theme get() = ThemeManager.activeTheme
Expand Down Expand Up @@ -102,7 +102,7 @@ class InputView(
single<InputView> { this@InputView }
single<Theme> { theme }
single<ContextThemeWrapper> { themedContext }
single<Trime> { service }
single<TrimeInputMethodService> { service }
// the components need to be injected
// Note: these components can be injected into other components,
// but you must construct them there, otherwise Koin cannot
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/osfans/trime/ime/core/Speech.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Speech(context: Context) : RecognitionListener {
speechRecognizer.destroy()
}
Timber.i("onResults")
val trime = Trime.getServiceOrNull()
val trime = TrimeInputMethodService.getServiceOrNull()
if (trime != null) {
val matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
val openccConfig = ThemeManager.activeTheme.style.getString("speech_opencc_config")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import timber.log.Timber
/** [輸入法][InputMethodService]主程序 */

@Suppress("ktlint:standard:property-naming")
open class Trime : LifecycleInputMethodService() {
open class TrimeInputMethodService : LifecycleInputMethodService() {
private var normalTextEditor = false
private val prefs: AppPrefs
get() = AppPrefs.defaultInstance()
Expand Down Expand Up @@ -1015,14 +1015,14 @@ open class Trime : LifecycleInputMethodService() {
}

companion object {
var self: Trime? = null
var self: TrimeInputMethodService? = null

@JvmStatic
fun getService(): Trime {
fun getService(): TrimeInputMethodService {
return self ?: throw IllegalStateException("Trime not initialized")
}

fun getServiceOrNull(): Trime? {
fun getServiceOrNull(): TrimeInputMethodService? {
return self
}

Expand All @@ -1031,9 +1031,9 @@ open class Trime : LifecycleInputMethodService() {
Looper.getMainLooper(),
) { msg: Message ->
// 若当前没有输入面板,则后台同步。防止面板关闭后5秒内再次打开
if (!(msg.obj as Trime).isShowInputRequested) {
if (!(msg.obj as TrimeInputMethodService).isShowInputRequested) {
ShortcutUtils.syncInBackground()
(msg.obj as Trime).loadConfig()
(msg.obj as TrimeInputMethodService).loadConfig()
}
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.widget.ViewAnimator
import com.osfans.trime.core.Rime
import com.osfans.trime.databinding.MainInputLayoutBinding
import com.osfans.trime.databinding.SymbolInputLayoutBinding
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import splitties.views.dsl.core.add
Expand All @@ -15,7 +15,7 @@ import splitties.views.dsl.core.matchParent

class KeyboardWindow : KoinComponent {
private val context: Context by inject()
private val service: Trime by inject()
private val service: TrimeInputMethodService by inject()

val oldMainInputView by lazy {
MainInputLayoutBinding.inflate(LayoutInflater.from(context)).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.osfans.trime.data.theme.ColorManager
import com.osfans.trime.data.theme.FontManager
import com.osfans.trime.data.theme.Theme
import com.osfans.trime.databinding.SimpleKeyItemBinding
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.util.appContext
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -203,7 +203,7 @@ class FlexibleAdapter(theme: Theme) : RecyclerView.Adapter<FlexibleAdapter.ViewH
}

private fun askToDeleteAll() {
val service = Trime.getService()
val service = TrimeInputMethodService.getService()
val askDialog =
AlertDialog.Builder(
appContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.osfans.trime.data.db.CollectionHelper
import com.osfans.trime.data.db.DatabaseBean
import com.osfans.trime.data.db.DraftHelper
import com.osfans.trime.data.theme.Theme
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.ime.enums.KeyCommandType
import com.osfans.trime.ime.enums.SymbolKeyboardType
import com.osfans.trime.ime.text.TextInputManager
Expand All @@ -35,7 +35,7 @@ import timber.log.Timber

class LiquidKeyboard : KoinComponent, ClipboardHelper.OnClipboardUpdateListener {
private val context: Context by inject()
private val service: Trime by inject()
private val service: TrimeInputMethodService by inject()
private val theme: Theme by inject()

private lateinit var keyboardView: RecyclerView
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/osfans/trime/ime/symbol/TabView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import androidx.core.view.updateLayoutParams
import com.osfans.trime.data.theme.ColorManager
import com.osfans.trime.data.theme.FontManager
import com.osfans.trime.data.theme.ThemeManager
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.ime.enums.KeyCommandType
import com.osfans.trime.ime.enums.SymbolKeyboardType
import com.osfans.trime.util.GraphicUtils.drawText
Expand Down Expand Up @@ -201,14 +201,14 @@ class TabView(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
val tag = TabManager.tabTags[i]
if (tag.type == SymbolKeyboardType.NO_KEY) {
when (tag.command) {
KeyCommandType.EXIT -> Trime.getService().selectLiquidKeyboard(-1)
KeyCommandType.EXIT -> TrimeInputMethodService.getService().selectLiquidKeyboard(-1)
KeyCommandType.DEL_LEFT, KeyCommandType.DEL_RIGHT, KeyCommandType.REDO, KeyCommandType.UNDO -> {}
else -> {}
}
} else if (System.currentTimeMillis() - time0 < 500) {
highlightIndex = i
invalidate()
Trime.getService().selectLiquidKeyboard(i)
TrimeInputMethodService.getService().selectLiquidKeyboard(i)
}
Timber.d("index=" + i + " length=" + tabTags!!.size)
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/osfans/trime/ime/text/Composition.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import com.osfans.trime.data.theme.ColorManager
import com.osfans.trime.data.theme.EventManager
import com.osfans.trime.data.theme.FontManager
import com.osfans.trime.data.theme.ThemeManager
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.ime.keyboard.Event
import com.osfans.trime.ime.keyboard.KeyboardSwitcher
import com.osfans.trime.util.CollectionUtils
Expand Down Expand Up @@ -205,7 +205,7 @@ class Composition(context: Context, attrs: AttributeSet?) : TextView(context, at
.replace("", "")
n = Rime.getRimeRawInput()!!.length - s.length // 從右側定位
Rime.setCaretPos(n)
Trime.getService().updateComposing()
TrimeInputMethodService.getService().updateComposing()
return true
}
} else if (movable != Movable.NEVER &&
Expand All @@ -223,7 +223,7 @@ class Composition(context: Context, attrs: AttributeSet?) : TextView(context, at
} else { // MotionEvent.ACTION_MOVE
mCurrentX = (event.rawX + mDx).toInt()
mCurrentY = (event.rawY + mDy).toInt()
Trime.getService().updatePopupWindow(mCurrentX, mCurrentY)
TrimeInputMethodService.getService().updatePopupWindow(mCurrentX, mCurrentY)
}
return true
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/ime/text/ScrollView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import android.view.View
import android.view.animation.TranslateAnimation
import android.widget.HorizontalScrollView
import com.osfans.trime.core.Rime
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import timber.log.Timber
import kotlin.math.min

Expand Down Expand Up @@ -107,7 +107,7 @@ class ScrollView(context: Context?, attrs: AttributeSet?) : HorizontalScrollView
swipeStartX = ev.x
}
} else if (swipeStartX - ev.x > swipeActionLimit) {
if (Trime.getService().candidateExPage) {
if (TrimeInputMethodService.getService().candidateExPage) {
pageExAction?.run()
return
} else if (Rime.hasRight()) {
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.osfans.trime.data.theme.ThemeManager
import com.osfans.trime.ime.broadcast.IntentReceiver
import com.osfans.trime.ime.core.EditorInstance
import com.osfans.trime.ime.core.Speech
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.ime.enums.Keycode
import com.osfans.trime.ime.enums.Keycode.Companion.toStdKeyEvent
import com.osfans.trime.ime.enums.SymbolKeyboardType
Expand Down Expand Up @@ -46,17 +46,17 @@ import java.util.Locale
* the following count as text input: character, numeric (+advanced), phone and symbol layouts.
*
* All of the UI for the different keyboard layouts are kept under the same container element and
* are separated from media-related UI. The core [Trime] will pass any event defined in
* [Trime.EventListener] through to this class.
* are separated from media-related UI. The core [TrimeInputMethodService] will pass any event defined in
* [TrimeInputMethodService.EventListener] through to this class.
*
* TextInputManager is also the hub in the communication between the system, the active editor
* instance and the CandidateView.
*/
class TextInputManager private constructor() :
Trime.EventListener,
TrimeInputMethodService.EventListener,
KeyboardView.OnKeyboardActionListener,
Candidate.EventListener {
private val trime get() = Trime.getService()
private val trime get() = TrimeInputMethodService.getService()
private val prefs get() = AppPrefs.defaultInstance()
private val activeEditorInstance: EditorInstance
get() = trime.activeEditorInstance as EditorInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.osfans.trime.R
import com.osfans.trime.core.Rime
import com.osfans.trime.data.AppPrefs
import com.osfans.trime.data.DataManager
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.ui.components.PaddingPreferenceFragment
import com.osfans.trime.ui.main.MainViewModel
import com.osfans.trime.ui.main.soundPicker
Expand Down Expand Up @@ -46,7 +46,7 @@ class KeyboardFragment :
"keyboard__show_window",
"keyboard__inline_preedit", "keyboard__soft_cursor",
-> {
Trime.getServiceOrNull()?.recreateInputView()
TrimeInputMethodService.getServiceOrNull()?.recreateInputView()
}
"keyboard__candidate_page_size" -> {
val pageSize = AppPrefs.defaultInstance().keyboard.candidatePageSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import com.osfans.trime.data.db.ClipboardHelper
import com.osfans.trime.data.db.CollectionHelper
import com.osfans.trime.data.db.DraftHelper
import com.osfans.trime.databinding.ActivityLiquidKeyboardEditBinding
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.ime.enums.SymbolKeyboardType
import kotlinx.coroutines.launch
import timber.log.Timber

class LiquidKeyboardEditActivity : AppCompatActivity() {
private val service: Trime = Trime.getService()
private val service: TrimeInputMethodService = TrimeInputMethodService.getService()
private var id: Int? = null
private lateinit var editText: EditText
private var type: SymbolKeyboardType? = null
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/osfans/trime/util/InputMethodUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.provider.Settings
import com.osfans.trime.TrimeImeService
import com.osfans.trime.ime.core.TrimeInputMethodService
import splitties.systemservices.inputMethodManager
import timber.log.Timber

object InputMethodUtils {
private val serviceName =
ComponentName(appContext, TrimeImeService::class.java).flattenToShortString()
ComponentName(appContext, TrimeInputMethodService::class.java).flattenToShortString()

private fun getSecureSettings(name: String) = Settings.Secure.getString(appContext.contentResolver, name)

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/osfans/trime/util/ShortcutUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.blankj.utilcode.util.IntentUtils
import com.osfans.trime.core.Rime
import com.osfans.trime.data.AppPrefs
import com.osfans.trime.ime.core.RimeWrapper
import com.osfans.trime.ime.core.Trime
import com.osfans.trime.ime.core.TrimeInputMethodService
import com.osfans.trime.ui.main.LogActivity
import com.osfans.trime.ui.main.PrefMainActivity
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -45,8 +45,8 @@ object ShortcutUtils {
"date" -> return getDate(option)
"commit" -> return option
"run" -> startIntent(option)
"share_text" -> Trime.getService().shareText()
"liquid_keyboard" -> Trime.getService().selectLiquidKeyboard(option)
"share_text" -> TrimeInputMethodService.getService().shareText()
"liquid_keyboard" -> TrimeInputMethodService.getService().selectLiquidKeyboard(option)
else -> startIntent(command, option)
}
return null
Expand Down

0 comments on commit dab946c

Please sign in to comment.