material-components / material-components/material-components-android
[MaterialColors] Resolve attribute colors using Resources
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 17.4k
- Fork
- 3.2k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I'm building a library that desaturates colors when Dark theme is enabled (as described in [Material Docs](https://material.io/design/color/dark-theme.html#ui-application))
Basically, I'm overriding `getColor` and `getColorStateList` in `android.content.res.Resources`, and them returning the requested color desaturated. But when it comes to material widgets, it doesn't work.
So, diving into material widgets, I noticed that the colors are retrieved calling `MaterialColors.getColor` that calls `MaterialAttributes.resolveOrThrow`, and after resolving the attributeId, the color is directly available in `typedValue.data` (line 71). But in this way, the call to`Resources` is skipped and my desaturation methods will never be called.
My solution is to call `ContextCompat.getColor(context, typedValue.resourceId)` instead of `typeValue.data` at line 71 of `MaterialAttributes.java`.
I understand that this can cause some performance impact by retrieving the color another time, but I'm writing this library because a lot of application has dynamic primary and accent colors, and it's a pain to calculate manually the desaturated colors by hand and then add to `night-values`.
Or please let me know if the problem can be resolved in another way.
[Here the desaturation code](https://github.com/ologe/color-desaturation/blob/master/lib/src/main/java/dev/olog/lib/DarkDesaturatedResources.java)
Here's the screenshot
[not desaturated](https://github.com/ologe/color-desaturation/blob/master/img/light_mode.png)
[desaturated](https://github.com/ologe/color-desaturation/blob/master/img/dark_mode.png)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in MaterialAttributes.java alla riga 71 e segui il percorso di MaterialColors.getColor attraverso MaterialAttributes.resolveOrThrow. Confronta la ricerca diretta di typedValue.data con la proposta dell'issue relativa a ContextCompat.getColor, quindi verifica che i colori dei widget Material passino attraverso i metodi Resources sovrascritti e vengano desaturati come previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- mobile-dev
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100