Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Jan Rabe kibotu

🎯
Focusing
View GitHub Profile
@kibotu
kibotu / build-json-generator.gradle
Last active Jul 18, 2022
Generating build time variables into app/asset folder. Newly support for configuration caching.
View build-json-generator.gradle
/**
* Task to generate build.json and puts it into assets/meta folder within the app.
*/
preBuild.dependsOn tasks.register("generateBuildJson") {
// note: file can't be named 'build.json' otherwise it will not be bundled into the app.
outputs.file(project.rootProject.file('app/src/main/assets/meta.json'))
// need to remember configuration variables for later task execution
@kibotu
kibotu / LruBitmapCache.kt
Last active Jun 3, 2022
LruBitmapCache
View LruBitmapCache.kt
import android.graphics.Bitmap
import androidx.collection.LruCache
val runtimeMemoryChunkInBytes: Int
get() = (Runtime.getRuntime().maxMemory() / 8).toInt()
/**
* https://developer.android.com/topic/performance/graphics/cache-bitmap
*/
class LruBitmapCache : LruCache<String, Bitmap>(runtimeMemoryChunkInBytes) {
@kibotu
kibotu / ParallaxScreen.kt
Created Jun 1, 2022 — forked from surajsau/ParallaxScreen.kt
Parallax effect with Jetpack Compose
View ParallaxScreen.kt
@Composable
fun ParallaxScreen(modifier: Modifier = Modifier) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var data by remember { mutableStateOf<SensorData?>(null) }
DisposableEffect(Unit) {
val dataManager = SensorDataManager(context)
dataManager.init()
@kibotu
kibotu / gource_me.sh
Last active May 25, 2022
gource & ffmpeg
View gource_me.sh
#!/bin/bash
# https://github.com/acaudwell/Gource
# brew install gource
# brew install ffmpeg
cd "/Users/user/Documents/repositories/my-favorite-project"
gource \
View WeakReferenceDelegate.kt
import java.lang.ref.WeakReference
import kotlin.reflect.KProperty
inline fun <reified T> weak() = WeakReferenceDelegate<T>()
inline fun <reified T> weak(value: T) = WeakReferenceDelegate(value)
/**
* e.g. var x by weak<Context?>(activity)
@kibotu
kibotu / Context+Extensions.kt
Last active Mar 21, 2022
Jetpack Compose get activity in Composable from LocalContext.
View Context+Extensions.kt
// val activity = LocalContext.current.findActivity()
tailrec fun Context.findActivity(): AppCompatActivity? = when (this) {
is AppCompatActivity -> this
is ContextWrapper -> baseContext.findActivity()
else -> null
}
@kibotu
kibotu / build.gradle
Last active Mar 29, 2022
Deploy aab to Huawei AppGallery.
View build.gradle
// based on https://github.com/ferPrieto/steps-app-gallery-deploy/blob/main/step.sh
import groovy.json.JsonSlurper
ext {
def properties = project.gradle.startParameter.projectProperties
println(properties)
// https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agcapi-getstarted-0000001111845114
// IMPORTANT: when creating api key: 'N/A' as Project
@kibotu
kibotu / generate_dependencies.gradle
Last active Jul 18, 2022
Generating Dependencies for different build variants.
View generate_dependencies.gradle
/**
* Generates a text file containing dependencies for different build variants
* and saves them into the respective variant asset folder.
* Also deletes files on clean.
*
* Can be safely used with <code>org.gradle.unsafe.configuration-cache=true</code>
*/
android.applicationVariants.all { variant ->
def name = variant.name
View android_material_design_colours.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- google's material design colours from
http://www.google.com/design/spec/style/color.html#color-ui-color-palette -->
<!--reds-->
<color name="md_red_50">#FFEBEE</color>
<color name="md_red_100">#FFCDD2</color>
<color name="md_red_200">#EF9A9A</color>
View WoobleAll.kt
// implementation "com.github.kibotu:AndroidAnimationsActions:2.0.1"
// maven { url 'https://jitpack.io' }
fun ViewGroup.woobleEVERYTHING() = children.forEach { it.startWobbling() }
fun View.startWobbling() {
val minDuration = 1f
val maxDuration = 1.5f
val duration: Float = randomRange(minDuration, maxDuration)
play(