mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-04 09:45:19 +08:00
Modify add isUseNewConfig in YukiHookFactory and ModuleContextThemeWrapper
This commit is contained in:
@@ -340,7 +340,7 @@ context.startActivity(context, HostTestActivity::class.java)
|
||||
### Context.applyTheme *- ext-method*
|
||||
|
||||
```kotlin
|
||||
fun Context.applyTheme(theme: Int): ModuleContextThemeWrapper
|
||||
fun Context.applyTheme(theme: Int, isUseNewConfig: Boolean): ModuleContextThemeWrapper
|
||||
```
|
||||
|
||||
**变更记录**
|
||||
@@ -353,6 +353,8 @@ fun Context.applyTheme(theme: Int): ModuleContextThemeWrapper
|
||||
|
||||
在 Hook APP (宿主) 中使用此方法会自动调用 `injectModuleAppResources` 注入当前 Xposed 模块的资源。
|
||||
|
||||
如果在 Hook APP (宿主) 中使用此方法发生 `ClassCastException`,请设置 `isUseNewConfig` 为 `true`。
|
||||
|
||||
为防止资源 ID 互相冲突,你需要在当前 Xposed 模块项目的 `build.gradle` 中修改资源 ID。
|
||||
|
||||
- Kotlin Gradle DSL
|
||||
|
@@ -32,6 +32,7 @@ package com.highcapable.yukihookapi.hook.factory
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
@@ -153,11 +154,15 @@ fun Context.registerModuleAppActivities(proxy: Any? = null) = AppParasitics.regi
|
||||
*
|
||||
* 在 Hook APP (宿主) 中使用此方法会自动调用 [injectModuleAppResources] 注入当前 Xposed 模块的资源
|
||||
*
|
||||
* - 如果在 Hook APP (宿主) 中使用此方法发生 [ClassCastException] - 请设置 [isUseNewConfig] 为 true
|
||||
*
|
||||
* 详情请参考 [API 文档 - Context.applyTheme](https://fankes.github.io/YukiHookAPI/#/api/document?id=contextapplytheme-ext-method)
|
||||
* @param theme 主题资源 ID
|
||||
* @param isUseNewConfig 是否使用新的 [Configuration] - 默认否
|
||||
* @return [ModuleContextThemeWrapper]
|
||||
*/
|
||||
fun Context.applyTheme(@StyleRes theme: Int) = ModuleContextThemeWrapper.wrapper(baseContext = this, theme)
|
||||
fun Context.applyTheme(@StyleRes theme: Int, isUseNewConfig: Boolean = false) =
|
||||
ModuleContextThemeWrapper.wrapper(baseContext = this, theme, isUseNewConfig)
|
||||
|
||||
/**
|
||||
* 仅判断模块是否在太极、无极中激活
|
||||
|
@@ -29,6 +29,7 @@
|
||||
package com.highcapable.yukihookapi.hook.xposed.parasitic.context.wrapper
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.view.ContextThemeWrapper
|
||||
import com.highcapable.yukihookapi.hook.factory.injectModuleAppResources
|
||||
@@ -41,8 +42,10 @@ import com.highcapable.yukihookapi.hook.xposed.parasitic.reference.ModuleClassLo
|
||||
* 通过包装 - 你可以轻松在 (Xposed) 宿主环境使用来自模块的主题资源
|
||||
* @param baseContext 原始 [Context]
|
||||
* @param theme 使用的主题
|
||||
* @param isUseNewConfig 是否使用新的 [Configuration]
|
||||
*/
|
||||
class ModuleContextThemeWrapper private constructor(baseContext: Context, theme: Int) : ContextThemeWrapper(baseContext, theme) {
|
||||
class ModuleContextThemeWrapper private constructor(baseContext: Context, theme: Int, isUseNewConfig: Boolean) :
|
||||
ContextThemeWrapper(baseContext, theme) {
|
||||
|
||||
internal companion object {
|
||||
|
||||
@@ -50,12 +53,13 @@ class ModuleContextThemeWrapper private constructor(baseContext: Context, theme:
|
||||
* 从 [Context] 创建 [ModuleContextThemeWrapper]
|
||||
* @param baseContext 对接的 [Context]
|
||||
* @param theme 需要使用的主题
|
||||
* @param isUseNewConfig 是否使用新的 [Configuration]
|
||||
* @return [ModuleContextThemeWrapper]
|
||||
* @throws IllegalStateException 如果重复装载
|
||||
*/
|
||||
internal fun wrapper(baseContext: Context, theme: Int) =
|
||||
internal fun wrapper(baseContext: Context, theme: Int, isUseNewConfig: Boolean) =
|
||||
if (baseContext !is ModuleContextThemeWrapper)
|
||||
ModuleContextThemeWrapper(baseContext, theme)
|
||||
ModuleContextThemeWrapper(baseContext, theme, isUseNewConfig)
|
||||
else error("ModuleContextThemeWrapper already loaded")
|
||||
}
|
||||
|
||||
@@ -63,8 +67,8 @@ class ModuleContextThemeWrapper private constructor(baseContext: Context, theme:
|
||||
private var baseResources: Resources? = null
|
||||
|
||||
init {
|
||||
if (baseContext.resources?.configuration != null)
|
||||
baseResources = baseContext.createConfigurationContext(baseContext.resources.configuration).resources
|
||||
if (isUseNewConfig && baseContext.resources?.configuration != null)
|
||||
baseResources = baseContext.createConfigurationContext(baseContext.resources.configuration)?.resources
|
||||
if (YukiHookBridge.hasXposedBridge) resources?.injectModuleAppResources()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user