commit 8caf2b6d90a746ade4ea6ad73f542a70184565e2
parent 2fdb51dff67d995ea307f76621451100ed094c5f
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Fri,  9 Jun 2023 23:07:28 +0200

feat: amoled dark mode (#58)


Diffstat:
Mapp/src/main/assets/lang/en_US.json | 3++-
Mapp/src/main/kotlin/me/rhunk/snapenhance/config/ConfigProperty.kt | 6++++++
Aapp/src/main/kotlin/me/rhunk/snapenhance/features/impl/experiments/AmoledDarkMode.kt | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mapp/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/ViewAppearanceHelper.kt | 20+++++++++-----------
Mapp/src/main/kotlin/me/rhunk/snapenhance/manager/impl/FeatureManager.kt | 2++
5 files changed, 69 insertions(+), 12 deletions(-)

diff --git a/app/src/main/assets/lang/en_US.json b/app/src/main/assets/lang/en_US.json @@ -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": { diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/config/ConfigProperty.kt b/app/src/main/kotlin/me/rhunk/snapenhance/config/ConfigProperty.kt @@ -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 { diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/experiments/AmoledDarkMode.kt b/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/experiments/AmoledDarkMode.kt @@ -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())) + } + } + } + } +}+ \ No newline at end of file diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/ViewAppearanceHelper.kt b/app/src/main/kotlin/me/rhunk/snapenhance/features/impl/ui/menus/ViewAppearanceHelper.kt @@ -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 diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/manager/impl/FeatureManager.kt b/app/src/main/kotlin/me/rhunk/snapenhance/manager/impl/FeatureManager.kt @@ -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() }