Skip to content

Instantly share code, notes, and snippets.

View FireZenk's full-sized avatar
🌍
Improving the world

Jorge Garrido FireZenk

🌍
Improving the world
View GitHub Profile
import androidx.compose.animation.core.*
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
@kafri8889
kafri8889 / DateTextField.kt
Last active July 15, 2024 13:55
Date format in TextField Jetpack Compose
@Composable
fun Screen() {
var date by remember {
mutableStateOf(
TextFieldValue(
text = "dd-MM-yyyy"
)
)
}
@hvisser
hvisser / KeepScreenOn.kt
Created January 21, 2022 09:16
LocalView.current can be useful if you need to tap into a view function like keepScreenOn or haptics from Compose
@Composable
fun KeepScreenOn() {
val currentView = LocalView.current
DisposableEffect(Unit) {
currentView.keepScreenOn = true
onDispose {
currentView.keepScreenOn = false
}
}
@cgruber
cgruber / constrain_desktop_window.kt
Last active April 21, 2024 11:30
Constrain Compose Desktop Window to a minimum size.
//
// Copyright (c) Christian Gruber, All Rights Reserved
//
// Licensed for use under any of simplified BSD 2-clause, BSD, MIT, or Apache licenses,
// at the licensee's discretion.
//
// I'd release it to the public domain, except that prevents its use in some commercial
// environments due to the US having a broken copyright system. So there it is. Liberally
// licensed as I can make it.
@pedrovgs
pedrovgs / ComposeViewModel.kt
Created April 28, 2021 16:58
Example of a base view model for Jetpack Compose
import androidx.lifecycle.*
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
abstract class ComposeViewModel<C, E> : ViewModel(), LifecycleObserver {
@handstandsam
handstandsam / MyLifecycleOwner.kt
Last active November 11, 2024 10:58
Jetpack Compose OverlayService. You have to have all the correct permissions granted and in your manifest, but if you do, this this will show a green box with "Hello" in it!
import android.os.Bundle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleRegistry
import androidx.savedstate.SavedStateRegistry
import androidx.savedstate.SavedStateRegistryController
import androidx.savedstate.SavedStateRegistryOwner
internal class MyLifecycleOwner : SavedStateRegistryOwner {
private var mLifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this)
private var mSavedStateRegistryController: SavedStateRegistryController = SavedStateRegistryController.create(this)
@motorro
motorro / prepopulate-MainActivityModel.kt
Created March 12, 2020 15:40
New database instance
val db = Room
.databaseBuilder(getApplication(), CitiesDb::class.java, "cities.db")
.createFromAsset("databases/cities.db")
.fallbackToDestructiveMigration() // On version update - just copy over
.build()
@pablisco
pablisco / Coroutine_scope_functions.kt
Last active January 11, 2024 16:42
Simple way to jump into a separate context
suspend fun <T, R> T.letOn(
context: CoroutineContext,
block: suspend CoroutineScope.(T) -> R
): R = withContext(context) { block(this@letOn) }
suspend fun <T> T.alsoOn(
context: CoroutineContext,
block: suspend CoroutineScope.(T) -> Unit
): T = also { withContext(context) { block(this@alsoOn) } }
@sergiocasero
sergiocasero / DaoGenerator.kt
Created April 25, 2019 09:39
DaoGenerator code template for IntelliJ/AS
package ${PACKAGE_NAME}
#parse("File Header.java")
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Update
import androidx.room.Query
@Dao
package com.geekorum.geekdroid.navigation
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import androidx.core.content.res.use
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager