11package org.piepmeyer.gauguin.ui.grid
22
3+ import android.content.Context
34import android.graphics.Paint
45import androidx.core.graphics.ColorUtils
56import com.google.android.material.color.MaterialColors
@@ -9,6 +10,7 @@ import org.piepmeyer.gauguin.grid.GridCell
910
1011class GridPaintHolder (
1112 gridUI : GridUI ,
13+ context : Context ,
1214) {
1315 private val backgroundPaint: Paint = Paint ()
1416
@@ -46,20 +48,20 @@ class GridPaintHolder(
4648 private val previewTextPaint: Paint = Paint ()
4749
4850 init {
49- val fontHolder = GridFontHolder (gridUI. context)
51+ val fontHolder = GridFontHolder (context)
5052
51- backgroundPaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorSurface)
53+ backgroundPaint.color = getColor(context , com.google.android.material.R .attr.colorSurface)
5254 backgroundPaint.style = Paint .Style .FILL
5355
5456 borderPaint.strokeWidth = 2f
5557 borderPaint.style = Paint .Style .STROKE
56- borderPaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorSecondary)
58+ borderPaint.color = getColor(context , com.google.android.material.R .attr.colorSecondary)
5759
5860 gridPaint.flags = Paint .ANTI_ALIAS_FLAG
5961 gridPaint.color =
6062 ColorUtils .blendARGB(
61- gridUI.resources. getColor(R .color.gridCage, null ),
62- MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorSurface),
63+ getColor(context, R .attr.colorGridCage ),
64+ getColor(context , com.google.android.material.R .attr.colorSurface),
6365 if (gridUI.isInEditMode) {
6466 0.0f
6567 } else {
@@ -72,24 +74,24 @@ class GridPaintHolder(
7274 selectedGridPaint = Paint (gridPaint)
7375 selectedGridPaint.color =
7476 ColorUtils .blendARGB(
75- MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorSecondary),
76- MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorSurface),
77+ getColor(context , com.google.android.material.R .attr.colorSecondary),
78+ getColor(context , com.google.android.material.R .attr.colorSurface),
7779 0.1f ,
7880 )
7981
8082 warningGridPaint = Paint (gridPaint)
81- warningGridPaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorError)
83+ warningGridPaint.color = getColor(context , com.google.android.material.R .attr.colorError)
8284
8385 innerGridPaint.flags = Paint .ANTI_ALIAS_FLAG
8486 innerGridPaint.color = gridPaint.color
8587
8688 cageSelectedPaint.flags = Paint .ANTI_ALIAS_FLAG
8789 cageSelectedPaint.style = Paint .Style .STROKE
88- cageSelectedPaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorOnBackground)
90+ cageSelectedPaint.color = getColor(context , com.google.android.material.R .attr.colorOnBackground)
8991 cageSelectedPaint.typeface = fontHolder.fontValue
9092
9193 cageTextPaint.flags = Paint .ANTI_ALIAS_FLAG
92- cageTextPaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorPrimary)
94+ cageTextPaint.color = getColor(context , com.google.android.material.R .attr.colorPrimary)
9395 cageTextPaint.typeface = fontHolder.fontCageText
9496
9597 val hsl = FloatArray (3 )
@@ -100,66 +102,66 @@ class GridPaintHolder(
100102 cageTextPreviewModePaint.typeface = fontHolder.fontCageText
101103
102104 cageTextSelectedPaint.flags = Paint .ANTI_ALIAS_FLAG
103- cageTextSelectedPaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorPrimary)
105+ cageTextSelectedPaint.color = getColor(context , com.google.android.material.R .attr.colorPrimary)
104106 cageTextSelectedPaint.typeface = fontHolder.fontCageText
105107 cageTextSelectedFastFinishModePaint.flags = Paint .ANTI_ALIAS_FLAG
106- cageTextSelectedFastFinishModePaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorSurface)
108+ cageTextSelectedFastFinishModePaint.color = getColor(context , com.google.android.material.R .attr.colorSurface)
107109 cageTextSelectedFastFinishModePaint.typeface = fontHolder.fontCageText
108110
109111 valuePaint.flags = Paint .ANTI_ALIAS_FLAG
110- valuePaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorOnBackground)
112+ valuePaint.color = getColor(context , com.google.android.material.R .attr.colorOnBackground)
111113 valuePaint.typeface = fontHolder.fontValue
112114
113115 valueSelectedPaint.flags = Paint .ANTI_ALIAS_FLAG
114- valueSelectedPaint.color = gridUI.resources. getColor(R .color.gridSelected, null )
116+ valueSelectedPaint.color = getColor(context, R .attr.colorGridSelected )
115117 valueSelectedPaint.typeface = fontHolder.fontValue
116118 valueSelectedFastFinishModePaint.flags = Paint .ANTI_ALIAS_FLAG
117- valueSelectedFastFinishModePaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorSurface)
119+ valueSelectedFastFinishModePaint.color = getColor(context , com.google.android.material.R .attr.colorSurface)
118120 valueSelectedFastFinishModePaint.typeface = fontHolder.fontValue
119121
120122 possiblesPaint.flags = Paint .ANTI_ALIAS_FLAG
121- possiblesPaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorOnBackground)
123+ possiblesPaint.color = getColor(context , com.google.android.material.R .attr.colorOnBackground)
122124 possiblesPaint.typeface = fontHolder.fontPossibles
123125
124126 possiblesSelectedPaint.flags = Paint .ANTI_ALIAS_FLAG
125127 possiblesSelectedPaint.textSize = 6f
126- possiblesSelectedPaint.color = gridUI.resources. getColor(R .color.gridSelected, null )
128+ possiblesSelectedPaint.color = getColor(context, R .attr.colorGridSelected )
127129 possiblesSelectedPaint.typeface = fontHolder.fontPossibles
128130 possiblesSelectedFastFinishModePaint.flags = Paint .ANTI_ALIAS_FLAG
129131 possiblesSelectedFastFinishModePaint.textSize = 6f
130- possiblesSelectedFastFinishModePaint.color = gridUI.resources. getColor(R .color.gridSelectedText, null )
132+ possiblesSelectedFastFinishModePaint.color = getColor(context, R .attr.colorGridSelectedText )
131133 possiblesSelectedFastFinishModePaint.typeface = fontHolder.fontPossibles
132134
133135 previewTextPaint.flags = Paint .ANTI_ALIAS_FLAG
134136 previewTextPaint.textSize = 6f
135- previewTextPaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorOnTertiaryContainer)
137+ previewTextPaint.color = getColor(context , com.google.android.material.R .attr.colorOnTertiaryContainer)
136138 previewTextPaint.typeface = fontHolder.fontPossibles
137139
138- previewPaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorTertiaryContainer)
140+ previewPaint.color = getColor(context , com.google.android.material.R .attr.colorTertiaryContainer)
139141
140142 selectedPaint.flags = Paint .ANTI_ALIAS_FLAG
141- selectedPaint.color = gridUI.resources. getColor(R .color.gridSelected, null )
143+ selectedPaint.color = getColor(context, R .attr.colorGridSelected )
142144 selectedPaint.style = Paint .Style .STROKE
143145
144146 selectedFastFinishModePaint.flags = Paint .ANTI_ALIAS_FLAG
145- selectedFastFinishModePaint.color = gridUI.resources. getColor(R .color.gridSelected, null )
147+ selectedFastFinishModePaint.color = getColor(context, R .attr.colorGridSelected )
146148 selectedFastFinishModePaint.style = Paint .Style .FILL_AND_STROKE
147149 textOnSelectedFastFinishModePaint.flags = Paint .ANTI_ALIAS_FLAG
148- textOnSelectedFastFinishModePaint.color = gridUI.resources. getColor(R .color.gridSelectedText, null )
150+ textOnSelectedFastFinishModePaint.color = getColor(context, R .attr.colorGridSelectedText )
149151
150152 lastModifiedPaint.color =
151153 ColorUtils .blendARGB(
152- gridUI.resources. getColor(R .color.gridSelected, null ),
153- MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorSurface),
154+ getColor(context, R .attr.colorGridSelected ),
155+ getColor(context , com.google.android.material.R .attr.colorSurface),
154156 0.5f ,
155157 )
156158 lastModifiedPaint.style = Paint .Style .STROKE
157159 lastModifiedPaint.flags = Paint .ANTI_ALIAS_FLAG
158160
159- warningTextPaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorError)
161+ warningTextPaint.color = getColor(context , com.google.android.material.R .attr.colorError)
160162 warningTextPaint.typeface = fontHolder.fontValue
161163
162- cheatedPaint.color = MaterialColors . getColor(gridUI , com.google.android.material.R .attr.colorSurfaceVariant)
164+ cheatedPaint.color = getColor(context , com.google.android.material.R .attr.colorSurfaceVariant)
163165
164166 errorBackgroundPaint.color =
165167 MaterialColors .compositeARGBWithAlpha(
@@ -232,4 +234,11 @@ class GridPaintHolder(
232234 fun gridPaint (): Paint = gridPaint
233235
234236 fun selectedGridPaint (): Paint = selectedGridPaint
237+
238+ companion object {
239+ fun getColor (
240+ context : Context ,
241+ colorId : Int ,
242+ ): Int = MaterialColors .getColor(context, colorId, " ups" )
243+ }
235244}
0 commit comments