Skip to content

Instantly share code, notes, and snippets.

View cbeyls's full-sized avatar

Christophe Beyls cbeyls

View GitHub Profile
@cbeyls
cbeyls / FragmentArgumentDelegate.kt
Last active October 16, 2018 13:17 — forked from yanngx/FragmentArgumentDelegate.kt
Fragment arguments without hassle !
package be.brol
import android.os.Binder
import android.os.Bundle
import android.os.Parcelable
import android.support.v4.app.BundleCompat
import android.support.v4.app.Fragment
import kotlin.reflect.KProperty
/**
@cbeyls
cbeyls / RefreshProgressBar.java
Last active January 1, 2019 14:37
A custom horizontal indeterminate progress bar which displays a smooth colored animation. (Google Now progress bar)
package android.support.v4.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Handler;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
@cbeyls
cbeyls / SafeLoadersFragmentActivity.java
Last active April 27, 2019 12:16
Activity to restore the safe Loaders behavior of support libraries < 24.0.0 in recent versions
package android.support.v4.app;
/**
* Inherit from this class to prevent Loaders from being forcefully retained during a configuration change.
* Forceful retain currently causes all stopped Loaders to briefly start, causing unexpected issues for detached fragments.
* This restores the Loaders behavior of support libraries < 24.0.0
*
* @author Christophe Beyls
* @see <a href="https://issuetracker.google.com/issues/37916599">Bug report</a>
*/
@cbeyls
cbeyls / LiveDataFactory.java
Created April 27, 2019 12:50
A Factory providing utility LiveData instances
package be.digitalia.common.livedata;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import java.util.concurrent.TimeUnit;
sealed class Animal {
// Cats are simple. A cat is a cat.
object Cat : Animal()
sealed class Dog : Animal() {
abstract val breed: String?
class DogWithBreed(override val breed: String) : Dog()
@cbeyls
cbeyls / BinaryTrees.kt
Created August 18, 2019 21:15
Kotlin implementation of the binary-trees benchmark from The Computer Language Benchmarks Game
/**
* The Computer Language Benchmarks Game
* https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
*
* based on Jarkko Miettinen's Java program
* contributed by Christophe Beyls
*/
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
@cbeyls
cbeyls / ParcelableUtils.kt
Last active October 28, 2019 21:30
Kotlin Parcelable utilities
package be.digitalia.sample
import android.os.Parcel
import android.os.Parcelable
import java.math.BigDecimal
import java.math.BigInteger
import java.util.*
interface KParcelable : Parcelable {
@cbeyls
cbeyls / RecyclerViewUtils.java
Last active January 3, 2020 16:12
Utility class to enforce a single scroll direction for a RecyclerView or a ViewPager2
package be.digitalia.samples.utils;
import android.view.MotionEvent;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;
public class RecyclerViewUtils {
@cbeyls
cbeyls / WindowInsetsFrameLayout.java
Last active February 5, 2020 10:58
A fragment container enabling the use of android:fitsSystemWindows in fragment layouts.
package be.digitalia.common.widgets;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.support.v4.util.ObjectsCompat;
import android.util.AttributeSet;
import android.view.View;
@cbeyls
cbeyls / AdapterLinearLayout.java
Last active May 11, 2020 08:57
Vertical LinearLayout populated by a special adapter. Can be used as a lightweight ListView.
package be.digitalia.common.widgets;
import android.content.Context;
import android.database.DataSetObservable;
import android.database.DataSetObserver;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;