Skip to content

Instantly share code, notes, and snippets.

@LouisCAD
LouisCAD / ModalBottomSheet.kt
Last active November 20, 2023 09:16
Put this in its own Gradle module to have ModalBottomSheet in Material3 (or even without Material Design at all).
package com.louiscad.splitties.eap.bottomsheet
import android.app.Activity
import android.view.ViewGroup
import androidx.activity.compose.BackHandler
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetLayout
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
@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
@objcode
objcode / ConcurrencyHelpers.kt
Last active January 15, 2024 05:17
Helpers to control concurrency for one shot requests using Kotlin coroutines.
/* Copyright 2019 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import androidx.annotation.ColorInt
import java.lang.Math.pow
import kotlin.math.cos
@nightwolf738
nightwolf738 / BitmapExtension.kt
Created March 20, 2019 12:32
Masking bitmap with given destinationImage. Useful for masking ImageViews
fun Bitmap.maskWith(destinationImage: Bitmap, mode: PorterDuff.Mode): Bitmap {
val result = this.copy(Bitmap.Config.ARGB_8888, true)
val canvas = Canvas(result)
val paint = Paint()
canvas.drawBitmap(destinationImage, 0f, 0f, paint)
paint.xfermode = PorterDuffXfermode(mode)
canvas.drawBitmap(this, 0f, 0f, paint)
@alexjlockwood
alexjlockwood / WaveSquare.kt
Created March 11, 2019 02:30
Kotlin implementation of a wave square animation, inspired by https://twitter.com/beesandbombs/status/1101169015299420163
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.View
import kotlin.math.atan2
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt
@florina-muntenescu
florina-muntenescu / BaseDao.kt
Last active September 28, 2023 15:01
Use Dao inheritance to reduce the amount of boilerplate code - https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1
/*
* Copyright (C) 2017 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
@yanngx
yanngx / FragmentArgumentDelegate.kt
Last active January 19, 2023 09:26
Fragment arguments without hassle !
package be.brol
import android.os.Binder
import android.os.Bundle
import android.support.v4.app.BundleCompat
import android.support.v4.app.Fragment
/**
* Eases the Fragment.newInstance ceremony by marking the fragment's args with this delegate
* Just write the property in newInstance and read it like any other property after the fragment has been created
@muratcanbur
muratcanbur / DolapSubscriber.java
Last active July 24, 2017 06:42
DolapSubscriber is a base Rx Subscriber class that handles all API requests.
public abstract class DolapSubscriber<T> extends Subscriber<T> {
private MVPView mvpView;
public DolapSubscriber(MVPView mvpView) {
this.mvpView = mvpView;
}
@Override
public void onCompleted() {
@burgalon
burgalon / AccountAuthenticator.java
Last active July 15, 2023 08:29
Implementing OAuth2 with AccountManager, Retrofit and Dagger
public class AccountAuthenticator extends AbstractAccountAuthenticator {
private final Context context;
@Inject @ClientId String clientId;
@Inject @ClientSecret String clientSecret;
@Inject ApiService apiService;
public AccountAuthenticator(Context context) {
super(context);