Skip to content

Instantly share code, notes, and snippets.

View LouisCAD's full-sized avatar

Louis CAD LouisCAD

View GitHub Profile
/* Copyright 2023 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.MarqueeSpacing
import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
@riggaroo
riggaroo / CompositingStrategyOffscreenExample.kt
Last active May 27, 2024 16:20
GraphicsLayer CompositingStrategy Example demonstrating offscreen compositing strategy in Jetpack Compose, leveraging BlendMode.Clear to mask some of the image away.
/* Copyright 2022 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Composable
fun GraphicsLayerCompositingStrategyExample() {
Image(painter = painterResource(id = R.drawable.dog),
contentDescription = "Dog",
contentScale = ContentScale.Crop,
modifier = Modifier
.size(120.dp)
.aspectRatio(1f)
package de.apuri.boing
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.gestures.awaitFirstDown
import org.json.JSONObject
import java.io.File
const val tinyPngApiKey = "<YOUR-API-KEY-GOES-HERE>"
val projectDir = File("<PATH-TOPROJECT-ROOT>")
val supportedExtensions = listOf("png", "jpg")
fun main() {
projectDir.walk().forEach { srcFile ->
if (supportedExtensions.contains(srcFile.extension)) {
@zivkesten
zivkesten / BottomSheetUtils.kt
Last active June 3, 2024 14:36
Extension functions to display a Jetpack Compose bottom sheet over Android view
// Extension for Activity
fun Activity.showAsBottomSheet(content: @Composable (() -> Unit) -> Unit) {
val viewGroup = this.findViewById(android.R.id.content) as ViewGroup
addContentToView(viewGroup, content)
}
// Extension for Fragment
fun Fragment.showAsBottomSheet(content: @Composable (() -> Unit) -> Unit) {
val viewGroup = requireActivity().findViewById(android.R.id.content) as ViewGroup
addContentToView(viewGroup, content)
@marianeum
marianeum / get-compose-root-view
Created May 27, 2022 14:51
Access compose root view in test
// Sometimes you may need access to the root view in a test when working with compose.
// This is particularly useful for screenshot tests with popups/dialog where the root view
// will be in a separate window, rather than the activity
// This snippet shows how this can be used
val view = composeTestRule.onNode(isDialog()).fetchRootView()
private fun SemanticsNodeInteraction.fetchRootView(): View {
val node = fetchSemanticsNode()
return (node.root as ViewRootForTest).view
@phhusson
phhusson / gist:662af3573ad4fc91bb62e5fe7cde7250
Created March 14, 2022 13:12
Add rickroll Dialer option. Add rick.webm in assets
From f07ca2a26dcb0cc797dcc6fc0d2d4f16b89c481e Mon Sep 17 00:00:00 2001
From: Pierre-Hugues Husson <[email protected]>
Date: Mon, 14 Mar 2022 09:09:28 -0400
Subject: [PATCH] Add a rickroll button in heads-up notification to rickroll
caller
Change-Id: Ibe72535fb3e93f69a531723dc96ede05663ee251
---
assets/rick.webm | Bin 0 -> 1232413 bytes
.../NotificationBroadcastReceiver.java | 145 ++++++++++++++++++
@westonal
westonal / JsonDsl.kt
Created January 5, 2022 04:59
Kotlin Json Dsl idea
package com.example
import kotlinx.serialization.json.*
import org.junit.Assert.assertEquals
import org.junit.Test
class JsonDslTest {
@Test
fun `declare complex object`() {
@chris-hatton
chris-hatton / DataSizeFormatter.kt
Last active May 11, 2025 15:09
Human Readable Data Size Formatter for Kotlin Multiplatform (uses Common API only)
package datasizeformatter
import kotlin.math.abs
import kotlin.math.pow
import kotlin.math.roundToLong
/**
* Format a human-readable representation of data size, in binary base form.
* e.g. 1024 -> 1 KiB
* @param byteCount The number of bytes to represent in human-readable form. `Long.MIN_VALUE` is unsupported.
@zach-klippenstein
zach-klippenstein / Blockify.kt
Last active March 22, 2024 21:47
A Compose modifier to turn your apps into blocks (no, this has nothing to do with NFTs)
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.integration.demos.BlockFilter.Companion.Lighting