Feature: Automatically change at a Glance text color based on wallpaper (#5944)

This commit is contained in:
Varun Bansal
2025-10-12 11:01:06 +05:30
committed by GitHub
parent 07668702d5
commit 1912177c58
2 changed files with 21 additions and 1 deletions

View File

@@ -1,12 +1,14 @@
package app.lawnchair.smartspace
import android.content.Context
import android.graphics.Color
import android.util.SparseArray
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import app.lawnchair.smartspace.model.SmartspaceTarget
import app.lawnchair.util.isWallpaperDark
import com.android.launcher3.R
import com.android.launcher3.util.Themes
@@ -71,7 +73,9 @@ class CardPagerAdapter(context: Context) : PagerAdapter() {
val target = smartspaceTargets[viewHolder.position]
val card = viewHolder.card
card.setSmartspaceTarget(target, smartspaceTargets.size > 1)
card.setPrimaryTextColor(currentTextColor)
val isDark = isWallpaperDark(card.context)
val dynamicColors = if (isDark) Color.WHITE else Color.BLACK
card.setPrimaryTextColor(dynamicColors)
}
override fun getCount() = smartspaceTargets.size

View File

@@ -0,0 +1,16 @@
package app.lawnchair.util
import android.content.Context
import android.graphics.Color
import app.lawnchair.wallpaper.WallpaperColorsCompat
import app.lawnchair.wallpaper.WallpaperManagerCompat
fun isWallpaperDark(context: Context): Boolean {
val wallpaperManager = WallpaperManagerCompat.INSTANCE.get(context)
val colors: WallpaperColorsCompat? = wallpaperManager.wallpaperColors
return colors?.primaryColor?.let { argb ->
val darkness =
1 - (0.299 * Color.red(argb) + 0.587 * Color.green(argb) + 0.114 * Color.blue(argb)) / 255
darkness >= 0.5
} ?: false
}