Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View czyrux's full-sized avatar

Antonio Gutierrez Martinez czyrux

  • Facebook
  • London
View GitHub Profile
@czyrux
czyrux / RxBus.java
Created November 2, 2016 18:55
Event bus using RxJava
import com.jakewharton.rxrelay.PublishRelay;
import com.jakewharton.rxrelay.Relay;
import rx.Observable;
public class RxBus {
private static final RxBus INSTANCE = new RxBus();
private final Relay<Object, Object> busSubject = PublishRelay.create().toSerialized();
@czyrux
czyrux / Store.java
Last active October 30, 2016 19:11
Store concept using RxJava subject
import com.jakewharton.rxrelay.BehaviorRelay;
import com.jakewharton.rxrelay.Relay;
import rx.Observable;
public class Store<T> {
private final Relay<T, T> storeSubject;
public Store() {
@czyrux
czyrux / UncheckedPool.java
Created July 23, 2016 11:27
Leaner version of a Simple (non-synchronized) pool of objects. This Pool does not do any check whether an object to be released is already or not in the pool, unlike android.support.v4.util.Pools.SimplePool
import android.support.v4.util.Pools;
/**
* Simple (non-synchronized) pool of objects. This Pool does not do any check whether an object to be released is
* already in the pool, unlike {@link android.support.v4.util.Pools.SimplePool}
*
* @param <T> The pooled type.
*/
public class UncheckedPool<T> implements Pools.Pool<T> {
@czyrux
czyrux / PresenterLoader.java
Last active July 26, 2021 05:43
PresenterLoader
import android.content.Context;
import android.support.v4.content.Loader;
public final class PresenterLoader<T extends Presenter> extends Loader<T>{
private final PresenterFactory<T> factory;
private T presenter;
public PresenterLoader(Context context, PresenterFactory<T> factory) {
super(context);
@czyrux
czyrux / ShareHelper.java
Last active August 29, 2015 14:16
Example on how to share content with specific requirements in Android
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import android.annotation.TargetApi;
import android.app.Activity;
@czyrux
czyrux / AsyncLoader.java
Last active August 29, 2015 14:15
Utility Loader class implementation which extends AsyncTaskLoader and handles caveats regarding loader lifecycle. It also provides error handling and a helper class to decouple the loader job task.
import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;
/**
* Loader which extends AsyncTaskLoader and handles caveats as pointed out in
* http://code.google.com/p/android/issues/detail?id=14944.
* <p/>
*
* @param <T> data type
* @author Antonio Gutierrez <agutierrez88s@gmail.com>
@czyrux
czyrux / ParcelUtils.java
Created February 15, 2015 12:20
Utility class for parceling objects in Android
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Utility class for parceling objects
*/
@czyrux
czyrux / LocaleUtils.java
Created February 15, 2015 12:07
Utility class to change update locale settings within an Android Application. Changes will be reflected only within the app
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import java.util.Locale;
/**
* Utility class to change app locale settings.
@czyrux
czyrux / Pools.java
Last active August 29, 2015 14:05
Tiny helper class for creating pools of objects in Java. Specially suitable for Android Projects
/**
* Helper class for creating pools of objects.
*
* An example use looks like this:
*
* <pre>
* public class MyPooledClass implements {@link PoolObject}{
*
* private static final SynchronizedPool<MyPooledClass> sPool = new SynchronizedPool<MyPooledClass>(new MyPooledFactoryClass(), 10);
*