material-components / material-components/material-components-android
[MaterialColors] Resolve attribute colors using Resources
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 17.4k
- フォーク
- 3.2k
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
MaterialAttributes.java の 71 行目から始め、MaterialAttributes.resolveOrThrow を通る MaterialColors.getColor のパスを追跡します。typedValue.data の直接参照と、issue にある ContextCompat.getColor の提案を比較し、その後、Material ウィジェットの色がオーバーライドされた Resources メソッドを通り、期待どおりに彩度を下げられることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- mobile-dev
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100