Skip to content

Commit

Permalink
Update spotless and reformat codes
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Jul 5, 2023
1 parent 4af0044 commit 9d27bed
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fun MainScreen() {
onColorChanged = { colorEnvelope: ColorEnvelope ->
hexCode = colorEnvelope.hexCode
textColor = colorEnvelope.color
}
},
)

Spacer(modifier = Modifier.height(50.dp))
Expand All @@ -81,7 +81,7 @@ fun MainScreen() {
.padding(10.dp)
.height(35.dp)
.align(Alignment.CenterHorizontally),
controller = controller
controller = controller,
)

BrightnessSlider(
Expand All @@ -90,7 +90,7 @@ fun MainScreen() {
.padding(10.dp)
.height(35.dp)
.align(Alignment.CenterHorizontally),
controller = controller
controller = controller,
)

Spacer(modifier = Modifier.height(30.dp))
Expand All @@ -100,15 +100,15 @@ fun MainScreen() {
color = textColor,
fontSize = 16.sp,
fontWeight = FontWeight.Bold,
modifier = Modifier.align(Alignment.CenterHorizontally)
modifier = Modifier.align(Alignment.CenterHorizontally),
)

AlphaTile(
modifier = Modifier
.size(80.dp)
.clip(RoundedCornerShape(6.dp))
.align(Alignment.CenterHorizontally),
controller = controller
controller = controller,
)
}
}
Expand All @@ -118,7 +118,7 @@ fun MainToolBar() {
TopAppBar(
elevation = 6.dp,
backgroundColor = Color(0xFF6200EE),
modifier = Modifier.height(58.dp)
modifier = Modifier.height(58.dp),
) {
Text(
modifier = Modifier
Expand All @@ -127,7 +127,7 @@ fun MainToolBar() {
text = stringResource(R.string.app_name),
color = Color.White,
fontSize = 18.sp,
fontWeight = FontWeight.Bold
fontWeight = FontWeight.Bold,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import com.google.modernstorage.photopicker.PhotoPicker
@Composable
@SuppressLint("UnsafeOptInUsageError")
fun ColumnScope.PhotoPickerIcon(
controller: ColorPickerController
controller: ColorPickerController,
) {
val context = LocalContext.current
val photoPicker =
Expand All @@ -60,7 +60,7 @@ fun ColumnScope.PhotoPickerIcon(
Box(
modifier = Modifier
.padding(horizontal = 16.dp)
.align(Alignment.End)
.align(Alignment.End),
) {
Image(
modifier = Modifier
Expand All @@ -70,7 +70,7 @@ fun ColumnScope.PhotoPickerIcon(
photoPicker.launch(PhotoPicker.Args(PhotoPicker.Type.IMAGES_ONLY, 1))
},
imageVector = ImageVector.vectorResource(R.drawable.ic_gallery),
contentDescription = null
contentDescription = null,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.github.skydoves.colorpicker.compose

object Versions {
internal const val ANDROID_GRADLE_PLUGIN = "7.4.2"
internal const val ANDROID_GRADLE_SPOTLESS = "6.7.0"
internal const val ANDROID_GRADLE_SPOTLESS = "6.19.0"
internal const val GRADLE_NEXUS_PUBLISH_PLUGIN = "1.3.0"
internal const val KOTLIN = "1.8.22"
internal const val KOTLIN_GRADLE_DOKKA = "1.8.20"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public fun AlphaSlider(
},
tileOddColor: Color = defaultTileOddColor,
tileEvenColor: Color = defaultTileEvenColor,
tileSize: Dp = 12.dp
tileSize: Dp = 12.dp,
) {
val density = LocalDensity.current
var backgroundBitmap: ImageBitmap? = null
Expand Down Expand Up @@ -106,7 +106,7 @@ public fun AlphaSlider(
val drawable = AlphaTileDrawable(
with(density) { tileSize.toPx() },
tileOddColor,
tileEvenColor
tileEvenColor,
)
backgroundBitmap
?.asAndroidBitmap()
Expand All @@ -118,7 +118,7 @@ public fun AlphaSlider(
0,
0,
backgroundCanvas.nativeCanvas.width,
backgroundCanvas.nativeCanvas.height
backgroundCanvas.nativeCanvas.height,
)
drawable.draw(backgroundCanvas.nativeCanvas)
backgroundCanvas.drawRoundRect(
Expand All @@ -128,7 +128,7 @@ public fun AlphaSlider(
bottom = size.height.toFloat(),
radiusX = borderRadius.value,
radiusY = borderRadius.value,
paint = borderPaint
paint = borderPaint,
)
}
bitmapSize = size
Expand All @@ -139,13 +139,13 @@ public fun AlphaSlider(
val position: Float = if (wheelImageBitmap == null) {
val point = wheelPoint.coerceIn(
minimumValue = 0f,
maximumValue = bitmapSize.width.toFloat()
maximumValue = bitmapSize.width.toFloat(),
)
point / bitmapSize.width
} else {
val point = wheelPoint.coerceIn(
minimumValue = 0f,
maximumValue = bitmapSize.width.toFloat()
maximumValue = bitmapSize.width.toFloat(),
)
point / bitmapSize.width
}
Expand All @@ -158,19 +158,19 @@ public fun AlphaSlider(
val position: Float = if (wheelImageBitmap == null) {
val point = wheelPoint.coerceIn(
minimumValue = 0f,
maximumValue = bitmapSize.width.toFloat()
maximumValue = bitmapSize.width.toFloat(),
)
point / bitmapSize.width
} else {
val point = wheelPoint.coerceIn(
minimumValue = 0f,
maximumValue = bitmapSize.width.toFloat()
maximumValue = bitmapSize.width.toFloat(),
)
point / bitmapSize.width
}
controller.setAlpha(position.coerceIn(0f, 1f), fromUser = true)
}
}
},
) {
drawIntoCanvas { canvas ->
backgroundBitmap?.let {
Expand All @@ -184,7 +184,7 @@ public fun AlphaSlider(
colors = listOf(startColor, endColor),
from = Offset.Zero,
to = Offset(bitmapSize.width.toFloat(), bitmapSize.height.toFloat()),
tileMode = TileMode.Clamp
tileMode = TileMode.Clamp,
)
colorPaint.shader = shader
canvas.drawRoundRect(
Expand All @@ -194,34 +194,34 @@ public fun AlphaSlider(
bottom = bitmapSize.height.toFloat(),
radiusX = borderRadius.value,
radiusY = borderRadius.value,
paint = colorPaint
paint = colorPaint,
)

// draw wheel bitmap on the canvas.
if (wheelImageBitmap == null) {
val position = controller.alpha.value
val point = (bitmapSize.width * position).coerceIn(
minimumValue = 0f,
maximumValue = bitmapSize.width.toFloat()
maximumValue = bitmapSize.width.toFloat(),
)
canvas.drawCircle(
Offset(x = point, y = bitmapSize.height / 2f),
wheelRadius.toPx(),
wheelPaint
wheelPaint,
)
} else {
val position = controller.alpha.value
val point = (bitmapSize.width * position).coerceIn(
minimumValue = 0f,
maximumValue = bitmapSize.width.toFloat()
maximumValue = bitmapSize.width.toFloat(),
)
canvas.drawImage(
wheelImageBitmap,
Offset(
x = point - (wheelImageBitmap.width / 2),
y = bitmapSize.height / 2f - wheelImageBitmap.height / 2
y = bitmapSize.height / 2f - wheelImageBitmap.height / 2,
),
Paint()
Paint(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public fun AlphaTile(
selectedColor: Color = Color.Transparent,
tileOddColor: Color = defaultTileOddColor,
tileEvenColor: Color = defaultTileEvenColor,
tileSize: Dp = 12.dp
tileSize: Dp = 12.dp,
) {
val density = LocalDensity.current
var backgroundBitmap: ImageBitmap? = null
Expand All @@ -68,7 +68,11 @@ public fun AlphaTile(
val size =
newSize.takeIf { it.width != 0 && it.height != 0 } ?: return@onSizeChanged
val drawable =
AlphaTileDrawable(with(density) { tileSize.toPx() }, tileOddColor, tileEvenColor)
AlphaTileDrawable(
with(density) { tileSize.toPx() },
tileOddColor,
tileEvenColor,
)
backgroundBitmap
?.asAndroidBitmap()
?.recycle()
Expand All @@ -79,12 +83,12 @@ public fun AlphaTile(
0,
0,
backgroundCanvas.nativeCanvas.width,
backgroundCanvas.nativeCanvas.height
backgroundCanvas.nativeCanvas.height,
)
drawable.draw(backgroundCanvas.nativeCanvas)
}
bitmapSize = size
}
},
) {
drawIntoCanvas { canvas ->
backgroundBitmap?.let {
Expand All @@ -94,7 +98,7 @@ public fun AlphaTile(
0f,
bitmapSize.width.toFloat(),
bitmapSize.height.toFloat(),
colorPaint
colorPaint,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ import androidx.compose.ui.graphics.asAndroidBitmap
public class AlphaTileDrawable constructor(
tileSize: Float,
tileOddColor: Color,
tileEvenColor: Color
tileEvenColor: Color,
) : Drawable() {

private val androidPaint: android.graphics.Paint = android.graphics.Paint(
android.graphics.Paint.ANTI_ALIAS_FLAG
android.graphics.Paint.ANTI_ALIAS_FLAG,
)

init {
Expand All @@ -69,7 +69,7 @@ public class AlphaTileDrawable constructor(
androidPaint.shader = BitmapShader(
imageBitmap.asAndroidBitmap(),
Shader.TileMode.REPEAT,
Shader.TileMode.REPEAT
Shader.TileMode.REPEAT,
)
}

Expand All @@ -92,7 +92,7 @@ public class AlphaTileDrawable constructor(

@Deprecated(
message = "This method will be deprecated on the future Android SDK",
replaceWith = ReplaceWith(expression = "getOpacity")
replaceWith = ReplaceWith(expression = "getOpacity"),
)
override fun getOpacity(): Int = PixelFormat.OPAQUE
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal object BitmapCalculator {
bitmap,
targetSize.width,
targetSize.height,
false
false,
)
}

Expand Down
Loading

0 comments on commit 9d27bed

Please sign in to comment.