Skip to content

Instantly share code, notes, and snippets.

@androidx.compose.runtime.Composable
fun TestScreen() {
var dragOffset by remember { mutableStateOf(Offset.Zero) }
val density = LocalDensity.current
val angle by remember {
derivedStateOf {
if (dragOffset.y == 0f || dragOffset.y == 0f) return@derivedStateOf 0f
val angleInRadian = atan(dragOffset.x / -dragOffset.y)
@nikhil-mandlik-dev
nikhil-mandlik-dev / Clock.kt
Created June 25, 2023 10:06
Drawing Minute Second Overlay
//drawing minute-second overlay
val minuteHandOverlayPath = Path().apply {
val startOffset = Offset(
x = center.x + (outerRadius * cos(8f * Math.PI / 180f)).toFloat(),
y = center.y - (outerRadius * sin(8f * Math.PI / 180f)).toFloat(),
)
val endOffset = Offset(
x = center.x + (outerRadius * cos(-8f * Math.PI / 180f)).toFloat(),
y = center.y - (outerRadius * sin(-8f * Math.PI / 180f)).toFloat(),
@nikhil-mandlik-dev
nikhil-mandlik-dev / Clock.kt
Created June 25, 2023 10:03
Drawing Hour Label
//draw hour
val hourString = String.format("%02d", hour)
val hourTextMeasureOutput = textMeasurer.measure(
text = buildAnnotatedString { append(hourString) },
style = clockStyle.hourLabelStyle
)
val hourTopLeft = Offset(
x = this.center.x - (hourTextMeasureOutput.size.width / 2),
@nikhil-mandlik-dev
nikhil-mandlik-dev / Clock.kt
Last active June 26, 2023 07:11
Drawing Steps along the circle
//data class for wrapping dial customization
data class DialStyle(
val stepsWidth: Dp = 1.2.dp,
val stepsColor: Color = Color.Black,
val normalStepsLineHeight: Dp = 8.dp,
val fiveStepsLineHeight: Dp = 16.dp,
val stepsTextStyle: TextStyle = TextStyle(),
val stepsLabelTopPadding: Dp = 12.dp,
)
@nikhil-mandlik-dev
nikhil-mandlik-dev / TranslatingObject.kt
Created January 21, 2023 13:57
Translating Object from PathAnimation
package com.nikhil.here.pathanimation.ui.common
import android.graphics.PathMeasure
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.offset
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
@nikhil-mandlik-dev
nikhil-mandlik-dev / ic_ticket.xml
Created October 25, 2022 13:34
Ticket Vector
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="64"
android:viewportHeight="64">
<path
android:name="ticket_path"
android:pathData="
M8,16
H56
@nikhil-mandlik-dev
nikhil-mandlik-dev / MainActivity.kt
Created September 29, 2022 12:23
Translating Objects along a path
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val infiniteTransition = rememberInfiniteTransition()
@nikhil-mandlik-dev
nikhil-mandlik-dev / MainActivity.kt
Created September 29, 2022 12:20
Drawing Circle on Path
drawCircle(
radius = 10.dp.toPx(),
color = Color.Blue,
center = Offset(pos[0], pos[1])
)
@nikhil-mandlik-dev
nikhil-mandlik-dev / MainActivity.kt
Created September 29, 2022 12:18
Animating Progress
// Defining infiniteTransition to calculate progress value
val infiniteTransition = rememberInfiniteTransition()
val progress by infiniteTransition.animateFloat(
initialValue = 0f,
animationSpec = infiniteRepeatable(
animation = tween(2000),
repeatMode = RepeatMode.Restart
),
targetValue = 1f
)
@nikhil-mandlik-dev
nikhil-mandlik-dev / MainActivity.kt
Last active September 29, 2022 13:31
Finding the position of each coordinate along a path 🔍
val pos = FloatArray(2)
val tan = FloatArray(2)
PathMeasure().apply {
// set infinity path for which we want to do the calculation
setPath(infinityPath.asAndroidPath(), false)
// get the position and tangent of co-ordinate on the path
getPosTan(distance, pos, tan)