3

GitHub - msasikanth/material-color-utilities-kmm: KMM port of Material Color Uti...

 11 months ago
source link: https://github.com/msasikanth/material-color-utilities-kmm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Material Color Utilities

KMM port of Material Color Utilities Java package

Dependency

implementation("dev.sasikanth:material-color-utilities:<version>")

Usage

import dev.sasikanth.material.color.utilities.dynamiccolor.MaterialDynamicColors
import dev.sasikanth.material.color.utilities.hct.Hct
import dev.sasikanth.material.color.utilities.quantize.QuantizerCelebi
import dev.sasikanth.material.color.utilities.scheme.SchemeContent
import dev.sasikanth.material.color.utilities.score.Score

val seedColor = Score.score(
  QuantizerCelebi.quantize(bitmapPixels, 128)
)[0] // or specific AARRGGBB color int

val scheme = SchemeContent(
  sourceColorHct = Hct.fromInt(seedColor),
  isDark = true,
  contrastLevel = 0.0
)

val dynamicColors = MaterialDynamicColors()
// Create list of Material tokens you want to use/update
// based on the scheme
val tokens = mapOf(
  "primary" to dynamicColors.primary(),
  "secondary" to dynamicColors.secondary()
)

val colorsOutput = mutableMapOf<String, Int>()
for (token in tokens) {
  colorsOutput[token.key] = token.value.getArgb(scheme)
}

// Use/Update theme colors

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK