Skip to content

Instantly share code, notes, and snippets.

View decodeandroid's full-sized avatar
🏠
Working from home

Decode Android decodeandroid

🏠
Working from home
View GitHub Profile
@decodeandroid
decodeandroid / SlidingNumberPuzzle.kt
Last active November 6, 2024 20:55
Sliding Numbers Puzzle Game using Jetpack Compose & Canvas
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
@decodeandroid
decodeandroid / SpeedoMeter.kt
Last active October 14, 2024 23:29
Speedometer Using Jetpack Compose Canvas
import androidx.annotation.FloatRange
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animate
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.runtime.Composable
@decodeandroid
decodeandroid / AnalogClock.kt
Last active September 5, 2024 16:11
Analog clock Jetpack Compose
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@decodeandroid
decodeandroid / CustomProgressBar.kt
Created August 25, 2024 06:29
Custom Progress Bar in Jetpack Compose
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@decodeandroid
decodeandroid / PatternView.kt
Created August 18, 2024 17:18
Pattern View Jetpack Compose
import android.view.MotionEvent
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Text
@decodeandroid
decodeandroid / GameScreen.kt
Last active August 9, 2024 04:20
Word Game Jetpack Compose Canvas
import androidx.compose.foundation.gestures.detectDragGesturesAfterLongPress
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.boundsInWindow
@decodeandroid
decodeandroid / PieChart.kt
Last active July 20, 2024 17:41
PieChartCompose
data class PieChartData(
val color: Color= getRandomColor(),
val value: Int,
val description: String,
val isTapped: Boolean = false
)
internal fun getRandomColor(): Color {
return Color(
red = (0..255).random(),
@decodeandroid
decodeandroid / BarChart.kt
Created May 30, 2024 12:00
Bar Chart Jetpack Compose Canvas
@Composable
fun BarChart() {
val chartData = listOf(
Pair("I", 90),
Pair("II", 110),
Pair("III", 70),
Pair("IV", 205),
Pair("V", 150),
Pair("VI", 175)
@decodeandroid
decodeandroid / LineChartCompose.kt
Created May 23, 2024 06:41
Line Chart Jetpack Compose Canvas
@Preview(showBackground = true, showSystemUi = true)
@Composable
fun ShowLineChartPreview() {
val chartData = listOf(
Pair(1, 1.5),
Pair(2, 1.75),
Pair(3, 3.45),
Pair(4, 2.25),
Pair(5, 6.45),
Pair(6, 3.35),
@decodeandroid
decodeandroid / Create Canvas
Last active May 17, 2024 17:30
Learn Android Canvas in Jetpack Compose
@Composable
fun NewAndroidBot() {
//import Canvas
androidx.compose.foundation.Canvas(
modifier = Modifier
.background(Color.White) //set background color of canvas
.fillMaxSize() //canvas will take full screen size
) {
//draw the head