Skip to content

Instantly share code, notes, and snippets.

View tmxdyf's full-sized avatar
💭
I may be slow to respond.

tmxdyf tmxdyf

💭
I may be slow to respond.
View GitHub Profile
@oianmol
oianmol / QrScannerScreen.android.kt
Last active June 13, 2024 12:23
QR Code Scanner with Jetbrains Jetpack compose multiplatform!
import android.Manifest
import android.content.pm.PackageManager
import android.util.Log
import android.view.ViewGroup
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.camera.core.CameraSelector
import androidx.camera.core.ImageAnalysis
import androidx.camera.core.Preview
import androidx.camera.lifecycle.ProcessCameraProvider
@SylpheM
SylpheM / TooltipShape.kt
Last active March 30, 2024 06:15
A tooltip shape (a rounded rectangle with an arrow or a tick), that can be used with a shadow. Preview included
enum class TickOrientation {
TOP, START, END, BOTTOM
}
class TooltipShape(
private val cornerRadiusDp: Dp,
private val tickHeight: Dp,
private val tickOrientation: TickOrientation
) : Shape {
@Marlinski
Marlinski / BottomSheetScaffold.kt
Created October 23, 2022 21:48
port of BottomSheetScaffold for Material3
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@dino-su
dino-su / ClockText.kt
Created September 29, 2022 03:40
Compose TextClock
@Composable
fun ClockText() {
val currentTimeMillis = remember {
mutableStateOf(System.currentTimeMillis())
}
LaunchedEffect(key1 = currentTimeMillis) {
while (true) {
delay(250)
currentTimeMillis.value = System.currentTimeMillis()
@alexzaitsev
alexzaitsev / DefaultLinkMovementMethod.java
Last active January 17, 2024 08:45
How to display HTML using Android Compose
/**
* Set this on a textview and then you can potentially open links locally if applicable
*/
public class DefaultLinkMovementMethod extends LinkMovementMethod {
private OnLinkClickedListener mOnLinkClickedListener;
public DefaultLinkMovementMethod(OnLinkClickedListener onLinkClickedListener) {
mOnLinkClickedListener = onLinkClickedListener;
}
@denis-ismailaj
denis-ismailaj / SwipeToDelete.kt
Last active May 20, 2024 01:01
SwipeToDelete is a boilerplate-free simple implementation of SwipeToDismiss for bidirectional delete gestures in Jetpack Compose.
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
@dovahkiin98
dovahkiin98 / AutoSizeText.kt
Created October 4, 2021 09:03
AutoSize text implementation in Jetpack Compose
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.BoxWithConstraintsScope
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.InternalFoundationTextApi
import androidx.compose.foundation.text.TextDelegate
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@flymrc
flymrc / aes-cbc-padding.kts
Last active October 30, 2023 13:24
Kotlin AES Encryption and Decryption
// ref: https://www.baeldung.com/java-aes-encryption-decryption
import java.util.*
import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec
fun decrypt(algorithm: String, cipherText: String, key: SecretKeySpec, iv: IvParameterSpec): String {
val cipher = Cipher.getInstance(algorithm)
@Gowsky
Gowsky / Border.kt
Last active June 1, 2023 06:35
Corrected Modifier.border for Jetpack Compose. It adjusts inner rounded corner rectangle instead of using the same radius as outer rounded corner rectangle.
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.*
@DavidIbrahim
DavidIbrahim / DashedBorder.kt
Last active May 14, 2024 15:13
dashedBorder modifier for android compose
import androidx.compose.foundation.BorderStroke
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0