This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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, | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
val infiniteTransition = rememberInfiniteTransition() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drawCircle( | |
radius = 10.dp.toPx(), | |
color = Color.Blue, | |
center = Offset(pos[0], pos[1]) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder