Update SysColorsModule.kt
This commit is contained in:
parent
4599c2d96f
commit
d57081364b
1 changed files with 8 additions and 3 deletions
|
|
@ -4,7 +4,7 @@ import android.R.color
|
|||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.core.content.ContextCompat
|
||||
import de.robv.android.xposed.AndroidAppHelper
|
||||
import de.robv.android.xposed.XposedHelpers
|
||||
import GoonXposed.xposed.Module
|
||||
import kotlinx.serialization.json.*
|
||||
import java.lang.ref.WeakReference
|
||||
|
|
@ -15,7 +15,11 @@ object SysColorsModule : Module() {
|
|||
|
||||
@Deprecated("This method is deprecated in the parent class")
|
||||
override fun buildPayload(builder: JsonObjectBuilder) {
|
||||
context = WeakReference(AndroidAppHelper.currentApplication())
|
||||
context = WeakReference(runCatching {
|
||||
XposedHelpers.callStaticMethod(
|
||||
XposedHelpers.findClass("android.app.ActivityThread", null), "currentApplication"
|
||||
) as Context
|
||||
}.getOrNull())
|
||||
val accents = arrayOf("accent1", "accent2", "accent3", "neutral1", "neutral2")
|
||||
val shades = arrayOf(0, 10, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000)
|
||||
|
||||
|
|
@ -38,7 +42,8 @@ object SysColorsModule : Module() {
|
|||
}
|
||||
|
||||
private fun convertToColor(id: Int): String {
|
||||
val clr = if (isSupported()) ContextCompat.getColor(context.get()!!, id) else 0
|
||||
val ctx = context.get()
|
||||
val clr = if (isSupported() && ctx != null) ContextCompat.getColor(ctx, id) else 0
|
||||
return String.format("#%06X", 0xFFFFFF and clr)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue