Skip to content

Instantly share code, notes, and snippets.

@sebokopter
sebokopter / build.gradle.kts
Last active June 20, 2023 12:14
Kts Gradle Configuration for renaming Bundle/AAB files
import com.android.build.gradle.internal.tasks.FinalizeBundleTask
android.applicationVariants.all variant@{
tasks.named<FinalizeBundleTask>("sign${name.capitalizeAsciiOnly()}Bundle") {
val file = finalBundleFile.asFile.get()
val finalFile = File(file.parentFile, "myapp-${this@variant.name}-${this@variant.versionCode}-${this@variant.versionName}.aab")
finalBundleFile.set(finalFile)
}
}
@surajsau
surajsau / ParallaxScreen.kt
Last active May 18, 2024 08:16
Parallax effect with Jetpack Compose
@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()
@okmanideep
okmanideep / EventQueue.kt
Last active January 5, 2023 15:27
Event abstraction for Jetpack Compose
import androidx.compose.runtime.*
import kotlinx.coroutines.CoroutineScope
@Stable
internal class Event<T>(val value: T)
class MutableEventQueue<T>
internal constructor(): EventQueue<T>() {
private val events = mutableListOf<Event<T>>()
private val nextEventAsState = mutableStateOf<Event<T>?>(null)
@Composable
fun CalendarView(
modifier: Modifier = Modifier,
selectedDay: CalendarDay = CalendarDay.create(),
onSelectedDayChange: (CalendarDay) -> Unit = {},
visibleMonth: CalendarDay = CalendarDay.create(),
onVisibleMonthChange: (CalendarDay) -> Unit = {},
today: CalendarDay = CalendarDay.create(),
events: Set<CalendarDay> = emptySet()
) {
@Aidanvii7
Aidanvii7 / BundleExtensions.kt
Last active October 1, 2021 09:56
A Kotlin way to use Android Bundles. Offers type safety unlike android ktx's version of bundleOf
import android.os.Bundle
import android.os.Parcelable
import android.util.Size
import java.io.Serializable
typealias BundleContext = Bundle.() -> Unit
/**
* ```
* fun example(someParcelable: Parcelable, someOtherBundle: Bundle) {
@passsy
passsy / KIntent.kt
Last active March 28, 2023 06:51
Kotlin extension functions to start a generic Activity
package com.pascalwelsch.extensions
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
/**
* Extensions for simpler launching of Activities
@mttkay
mttkay / Pager.java
Created November 4, 2015 15:46
A simple Rx based pager
public class Pager<I, O> {
private static final Observable FINISH_SEQUENCE = Observable.never();
private PublishSubject<Observable<I>> pages;
private Observable<I> nextPage = finish();
private Subscription subscription = Subscriptions.empty();
private final PagingFunction<I> pagingFunction;
private final Func1<I, O> pageTransformer;
@gunhansancar
gunhansancar / LocaleHelper.java
Last active April 8, 2021 12:34
While developing your awesome application, sometimes you are required to add a language change feature to your app on the fly. However, Android OS does not directly support this behaviour. And therefore, you need to solve this situation in some other ways. For more details see http://gunhansancar.com/change-language-programmatically-in-android/
package com.gunhansancar.changelanguageexample.helper;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.preference.PreferenceManager;
@dwursteisen
dwursteisen / MongoExample.java
Created April 2, 2015 12:56
This code snippet show how MongoDB Async driver can be used with RxJava
import java.util.concurrent.CountDownLatch;
import com.mongodb.CursorType;
import com.mongodb.async.client.MongoClients;
import com.mongodb.async.client.MongoCollection;
import com.mongodb.async.client.MongoDatabase;
import org.bson.Document;
import rx.Observable;
@jaredrummler
jaredrummler / MenuTint.java
Last active April 13, 2022 03:58
Helper class to set the color and transparency for menu icons in an ActionBar or Toolbar.
/*
* Copyright (C) 2015. Jared Rummler <jared.rummler@gmail.com>
*
* 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