feat: amoled dark mode (#58)

This commit is contained in:
rhunk 2023-06-09 23:07:28 +02:00 committed by GitHub
parent 2fdb51dff6
commit 8caf2b6d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 12 deletions

View File

@ -67,7 +67,8 @@
"preview_resolution": "Override Preview Resolution",
"picture_resolution": "Override Picture Resolution",
"force_highest_frame_rate": "Force Highest Frame Rate",
"force_camera_source_encoding": "Force Camera Source Encoding"
"force_camera_source_encoding": "Force Camera Source Encoding",
"amoled_dark_mode": "AMOLED Dark Mode"
},
"option": {

View File

@ -346,6 +346,12 @@ enum class ConfigProperty(
"description.meo_passcode_bypass",
ConfigCategory.EXPERIMENTAL_DEBUGGING,
ConfigStateValue(false)
),
AMOLED_DARK_MODE(
"property.amoled_dark_mode",
"description.amoled_dark_mode",
ConfigCategory.EXPERIMENTAL_DEBUGGING,
ConfigStateValue(false)
);
companion object {

View File

@ -0,0 +1,49 @@
package me.rhunk.snapenhance.features.impl.experiments
import android.annotation.SuppressLint
import android.content.res.TypedArray
import android.graphics.drawable.ColorDrawable
import me.rhunk.snapenhance.Constants
import me.rhunk.snapenhance.config.ConfigProperty
import me.rhunk.snapenhance.features.Feature
import me.rhunk.snapenhance.features.FeatureLoadParams
import me.rhunk.snapenhance.hook.HookStage
import me.rhunk.snapenhance.hook.Hooker
import me.rhunk.snapenhance.hook.hook
class AmoledDarkMode : Feature("Amoled Dark Mode", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
@SuppressLint("DiscouragedApi")
override fun onActivityCreate() {
if (!context.config.bool(ConfigProperty.AMOLED_DARK_MODE)) return
val attributeCache = mutableMapOf<String, Int>()
fun getAttribute(name: String): Int {
if (attributeCache.containsKey(name)) return attributeCache[name]!!
return context.resources.getIdentifier(name, "attr", Constants.SNAPCHAT_PACKAGE_NAME).also { attributeCache[name] = it }
}
context.androidContext.theme.javaClass.getMethod("obtainStyledAttributes", IntArray::class.java).hook(HookStage.AFTER) { param ->
val array = param.arg<IntArray>(0)
val result = param.getResult() as TypedArray
fun ephemeralHook(methodName: String, content: Any) {
Hooker.ephemeralHookObjectMethod(result::class.java, result, methodName, HookStage.BEFORE) {
it.setResult(content)
}
}
when (array[0]) {
getAttribute("sigColorTextPrimary") -> {
ephemeralHook("getColor", 0xFFFFFFFF.toInt())
}
getAttribute("sigColorBackgroundMain") -> {
ephemeralHook("getColor", 0xFF000000.toInt())
}
getAttribute("actionSheetBackgroundDrawable"),
getAttribute("actionSheetRoundedBackgroundDrawable") -> {
ephemeralHook("getDrawable", ColorDrawable(0xFF000000.toInt()))
}
}
}
}
}

View File

@ -16,19 +16,17 @@ object ViewAppearanceHelper {
)
fun applyTheme(viewModel: View, view: TextView) {
val sigColorTextPrimary = viewModel.context.theme.obtainStyledAttributes(
intArrayOf(
viewModel.resources.getIdentifier(
"sigColorTextPrimary",
"attr",
Constants.SNAPCHAT_PACKAGE_NAME
)
)
)
intArrayOf(viewModel.resources.getIdentifier("sigColorTextPrimary", "attr", Constants.SNAPCHAT_PACKAGE_NAME))
).getColor(0, 0)
val sigColorBackgroundMain = viewModel.context.theme.obtainStyledAttributes(
intArrayOf(viewModel.resources.getIdentifier("sigColorBackgroundMain", "attr", Constants.SNAPCHAT_PACKAGE_NAME))
).getColor(0, 0)
val snapchatFontResId = view.context.resources.getIdentifier("avenir_next_medium", "font", "com.snapchat.android")
//remove the shadow
view.setBackgroundColor(0x00000000)
view.setTextColor(sigColorTextPrimary.getColor(0, 0))
view.setBackgroundColor(sigColorBackgroundMain)
view.setTextColor(sigColorTextPrimary)
view.setShadowLayer(0F, 0F, 0F, 0)
view.outlineProvider = null
view.gravity = Gravity.LEFT or Gravity.CENTER_VERTICAL
@ -49,7 +47,7 @@ object ViewAppearanceHelper {
view.setBackgroundColor(0x5395026)
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
view.setBackgroundColor(0x00000000)
view.setBackgroundColor(sigColorBackgroundMain)
}
}
false

View File

@ -9,6 +9,7 @@ import me.rhunk.snapenhance.features.impl.ConfigEnumKeys
import me.rhunk.snapenhance.features.impl.Messaging
import me.rhunk.snapenhance.features.impl.downloader.AntiAutoDownload
import me.rhunk.snapenhance.features.impl.downloader.MediaDownloader
import me.rhunk.snapenhance.features.impl.experiments.AmoledDarkMode
import me.rhunk.snapenhance.features.impl.experiments.AppPasscode
import me.rhunk.snapenhance.features.impl.experiments.InfiniteStoryBoost
import me.rhunk.snapenhance.features.impl.experiments.MeoPasscodeBypass
@ -81,6 +82,7 @@ class FeatureManager(private val context: ModContext) : Manager {
register(AutoUpdater::class)
register(CameraTweaks::class)
register(InfiniteStoryBoost::class)
register(AmoledDarkMode::class)
initializeFeatures()
}