This commit is contained in:
pengxiaolong
2025-12-26 22:01:04 +08:00
parent 79b5bc0273
commit 7814a10815
108 changed files with 6538 additions and 1987 deletions

View File

@@ -21,27 +21,26 @@ object ThemeManager {
private var drawableCache: MutableMap<String, Drawable> = mutableMapOf()
// ==================== 外部目录相关 ====================
//通知主题更新
private val listeners = mutableSetOf<() -> Unit>()
fun addThemeChangeListener(listener: () -> Unit) {
listeners.add(listener)
}
fun removeThemeChangeListener(listener: () -> Unit) {
listeners.remove(listener)
}
/** 主题根目录:/Android/data/<package>/files/keyboard_themes */
private fun getThemeRootDir(context: Context): File =
File(context.getExternalFilesDir(null), "keyboard_themes")
File(context.filesDir, "keyboard_themes")
/** 某个具体主题目录:/Android/.../keyboard_themes/<themeName> */
private fun getThemeDir(context: Context, themeName: String): File =
File(getThemeRootDir(context), themeName)
// ==================== 内置主题拷贝assets -> 外部目录) ====================
/**
* 确保 APK 自带的主题(assets/keyboard_themes/...) 已经复制到
* /Android/data/.../files/keyboard_themes 目录下。
*
* 行为:
* - 如果主题目录不存在:整套拷贝过去。
* - 如果主题目录已经存在:只复制“新增文件”,不会覆盖已有文件。
*
* 建议在 IME 的 onCreate() 里调用一次。
*/
fun ensureBuiltInThemesInstalled(context: Context) {
val am = context.assets
val rootName = "keyboard_themes"
@@ -126,6 +125,8 @@ object ThemeManager {
.apply()
drawableCache = loadThemeDrawables(context, themeName)
listeners.forEach { it.invoke() }
}
fun getCurrentThemeName(): String? = currentThemeName