@@ -164,7 +164,7 @@ fun ColorPickerComponent(
164
164
modifier = Modifier .testTag(" text_label_alpha" )
165
165
)
166
166
Text (
167
- text = getAlphaChannel (currentColor),
167
+ text = getChannelValue (currentColor, " alpha " ),
168
168
textAlign = TextAlign .End ,
169
169
modifier = Modifier
170
170
.defaultMinSize(minWidth = argbValueMinWidth)
@@ -180,7 +180,7 @@ fun ColorPickerComponent(
180
180
modifier = Modifier .testTag(" text_label_Blue" )
181
181
)
182
182
Text (
183
- text = getBlueChannel (currentColor),
183
+ text = getChannelValue (currentColor, " blue " ),
184
184
textAlign = TextAlign .End ,
185
185
modifier = Modifier
186
186
.defaultMinSize(minWidth = argbValueMinWidth)
@@ -196,7 +196,7 @@ fun ColorPickerComponent(
196
196
modifier = Modifier .testTag(" text_label_red" )
197
197
)
198
198
Text (
199
- text = getRedChannel (currentColor),
199
+ text = getChannelValue (currentColor, " red " ),
200
200
textAlign = TextAlign .End ,
201
201
modifier = Modifier
202
202
.defaultMinSize(minWidth = argbValueMinWidth)
@@ -212,7 +212,7 @@ fun ColorPickerComponent(
212
212
modifier = Modifier .testTag(" text_label_green" )
213
213
)
214
214
Text (
215
- text = getGreenChannel (currentColor),
215
+ text = getChannelValue (currentColor, " green " ),
216
216
textAlign = TextAlign .End ,
217
217
modifier = Modifier
218
218
.defaultMinSize(minWidth = argbValueMinWidth)
@@ -493,37 +493,18 @@ fun toARGB(color: Int): String {
493
493
/* *
494
494
* Alpha channel in numeric notation 0-255.
495
495
* @param color the color value to convert.
496
+ * @param name the name of the channel.
496
497
* @return channel integer value as String.
497
498
*/
498
- fun getAlphaChannel (color : Int ): String {
499
- return String .format(" %s" , Color (color).alpha.times(255 ).toInt())
500
- }
501
-
502
- /* *
503
- * Red channel in numeric notation 0-255.
504
- * @param color the color value to convert.
505
- * @return channel integer value as String.
506
- */
507
- fun getRedChannel (color : Int ): String {
508
- return String .format(" %s" , Color (color).red.times(255 ).toInt())
509
- }
510
-
511
- /* *
512
- * Green channel in numeric notation 0-255.
513
- * @param color the color value to convert.
514
- * @return channel integer value as String.
515
- */
516
- fun getGreenChannel (color : Int ): String {
517
- return String .format(" %s" , Color (color).green.times(255 ).toInt())
518
- }
519
-
520
- /* *
521
- * Blue channel in numeric notation 0-255.
522
- * @param color the color value to convert.
523
- * @return channel integer value as String.
524
- */
525
- fun getBlueChannel (color : Int ): String {
526
- return String .format(" %s" , Color (color).blue.times(255 ).toInt())
499
+ fun getChannelValue (color : Int , name : String ): String {
500
+ val value: Float = when (name) {
501
+ " alpha" -> { Color (color).alpha }
502
+ " red" -> { Color (color).red }
503
+ " green" -> { Color (color).green }
504
+ " blue" -> { Color (color).blue }
505
+ else -> { return " " }
506
+ }
507
+ return String .format(" %s" , value.times(255 ).toInt())
527
508
}
528
509
529
510
/* *
0 commit comments