Skip to content

Instantly share code, notes, and snippets.

Avatar

Christophe Beyls cbeyls

View GitHub Profile
@cbeyls
cbeyls / GenericAlphabetIndexer.java
Last active Aug 29, 2015
An optimized version of the Android framework's AlphabetIndexer which is compatible with any Adapter returning non-null items with a meaningful toString() representation. Section indexes will be updated automatically when the Adapter's data set changes.
View GenericAlphabetIndexer.java
package be.digitalia.common.adapters;
import android.database.DataSetObserver;
import android.util.SparseIntArray;
import android.widget.Adapter;
import android.widget.SectionIndexer;
/**
* An optimized version of the framework's AlphabetIndexer which is compatible with any Adapter
* returning non-null items with a meaningful toString() representation. Section indexes will be
@cbeyls
cbeyls / VolleyImageLoader.java
Created Aug 10, 2014
ImageLoader implementation for my own fork of the Cast Companion Library using the Volley library. See: https://github.com/cbeyls/CastCompanionLibrary-android
View VolleyImageLoader.java
package com.google.sample.castcompanionlibrary.cast.imageloader;
import android.content.Context;
import android.util.DisplayMetrics;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader.ImageContainer;
import com.android.volley.toolbox.ImageLoader.ImageListener;
/**
@cbeyls
cbeyls / PicassoImageLoader.java
Created Mar 30, 2015
ImageLoader implementation for my own fork of the Cast Companion Library using the Picasso library. See: https://github.com/cbeyls/CastCompanionLibrary-android
View PicassoImageLoader.java
package com.google.sample.castcompanionlibrary.cast.imageloader;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
@cbeyls
cbeyls / textpattern.rb
Created Apr 21, 2015
TextPattern import plugin for Jekyll that uses a YAML dump file of the "Textpattern" table from PHPMyAdmin instead of a local database. It also imports categories in addition to tags.
View textpattern.rb
module JekyllImport
module Importers
class TextPattern < Importer
def self.require_deps
JekyllImport.require_with_fallback(%w[
rubygems
fileutils
safe_yaml
])
end
@cbeyls
cbeyls / SafeCoordinatorLayout.java
Last active Feb 22, 2017
CoordinatorLayout properly restoring the Behavior states on API < 13 by avoiding null ClassLoaders
View SafeCoordinatorLayout.java
package be.digitalia.common.widgets;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.os.ParcelableCompat;
import android.support.v4.os.ParcelableCompatCreatorCallbacks;
import android.util.AttributeSet;
@cbeyls
cbeyls / LifecycleLoader.java
Last active May 19, 2017
Lifecycle-aware Loader delivering results from a LiveData source
View LifecycleLoader.java
package be.digitalia.common.loaders;
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@cbeyls
cbeyls / SuspendIntentService.kt
Created Aug 6, 2017
An Intent Service processing work in order from a Kotlin coroutine running on the main thread.
View SuspendIntentService.kt
package be.digitalia.common.services
import android.app.Service
import android.content.Intent
import android.os.Message
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.LinkedListChannel
import kotlinx.coroutines.experimental.launch
@cbeyls
cbeyls / SimpleCursorLoader.java
Last active Jan 26, 2018
A CursorLoader to implement simple monitorable database queries without a ContentProvider.
View SimpleCursorLoader.java
package be.digitalia.fosdem.loaders;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.content.AsyncTaskLoader;
/**
* A CursorLoader that doesn't need a ContentProvider.
*
* @author Christophe Beyls
@cbeyls
cbeyls / RecyclerViewCursorAdapter.java
Last active Apr 19, 2018
Simplified CursorAdapter designed for RecyclerView
View RecyclerViewCursorAdapter.java
package be.digitalia.common.adapters;
import android.database.Cursor;
import android.support.v7.widget.RecyclerView;
/**
* Simplified CursorAdapter designed for RecyclerView.
*
* @author Christophe Beyls
*/
@cbeyls
cbeyls / ParallaxScrollView.java
Last active Sep 15, 2018
Simplest implementation of a parallax header effect for Android.
View ParallaxScrollView.java
package be.digitalia.common.widgets;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;