material-components / material-components/material-components-android

[MaterialColors] Resolve attribute colors using Resources

オープン
#492 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature request Feature: Color Feature: 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)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。