Skip to content

Instantly share code, notes, and snippets.

View imminent's full-sized avatar

imminent imminent

  • Life360
  • San Francisco
View GitHub Profile
@imminent
imminent / ExampleActivity.java
Last active October 23, 2017 07:39
Gist for a modified approach to integrating Palette with Picasso proposed by Jake Wharton for the interim while Picasso doesn't have a supported way to pass meta data along the pipeline. http://jakewharton.com/coercing-picasso-to-play-with-palette/
package your.package;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.graphics.Palette;
import com.squareup.picasso.Picasso;
import your.package.PaletteTransformation;
import static your.package.PaletteTransformation.PaletteCallback;
@imminent
imminent / CursorSubject.java
Last active August 11, 2016 17:21
CursorSubject is a Reactive Extension version of Android's CursorLoader. Handles retrieving the Cursor in a background thread, sending the result Cursor on the main thread, and resending a Cursor whenever the content changed notification is triggered.
package com.example.models;
import android.database.ContentObserver;
import android.database.Cursor;
import android.os.Handler;
import android.os.Looper;
import java.io.Closeable;
import java.util.concurrent.atomic.AtomicReference;
@imminent
imminent / MyApplication.java
Created November 22, 2013 16:09
Example of setup that registers/unregisters non-singleton POJOs with an Event Bus.
package com.example;
import android.annotation.TargetApi;
import android.app.Application;
import android.app.ActivityLifecycleCallbacks;
import com.squareup.otto.Bus;
import javax.inject.Inject;
import javax.inject.Provider;
import dagger.ObjectGraph;
import java.util.Map;
@imminent
imminent / AndroidCookieStore.java
Created July 5, 2013 16:00
Example of a persistent cookie store that only keeps one cookie around.
package com.example.android.utilities;
import android.content.SharedPreferences;
import android.os.PatternMatcher;
import android.util.Log;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.URI;
import java.util.List;
@imminent
imminent / DoneDiscardCallbacks.java
Last active December 15, 2015 10:49
Snippet for binding Done/Discard Bar pattern via ActivityLifecycleCallbacks.
/*
* Copyright 2012 Dandre Allison
* 2012 Roman Nurik
*
* 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
*
@imminent
imminent / GateKeeper.java
Created March 22, 2013 21:48
Android version gate keeper utility.
import javax.annotation.Nonnull;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
/**
* <p>Keeper of the {@linkplain Build#VERSION_CODES Android version gates}, used to guarantee non shall pass,
* unless they are worthy.</p>
* @author Dandre Allison
@imminent
imminent / ObjectGraph.java
Last active October 23, 2017 07:39
Dagger `ObjectGraph` utility to hide the mess of injecting the different Android classes. Note this is inspired by https://github.com/pyricau/CleanAndroidCode/blob/master/cleanandroidcode/src/main/java/info/piwai/cleanandroidcode/base/GraphRetriever.java
import javax.annotation.Nonnull;
import android.app.Activity;
import android.app.Service;
import android.support.v4.app.Fragment;
import android.content.Context;
/**
* <p>Retrieves the {@link dagger.ObjectGraph} and injects dependencies.</p>
* @author Dandré Allison
@imminent
imminent / AndroidCookieStore.java
Last active December 14, 2015 06:38
Collection of code to use the Client interface of Retrofit to use HttpUrlConnection with SharedPreferences persistent cookies.
import android.annotation.TargetApi;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.PatternMatcher;
import com.keepandshare.android.utils.CryptographyUtil;
import com.keepandshare.android.utils.Ln;
import javax.inject.Singleton;
import java.net.CookieStore;
import java.net.HttpCookie;
@imminent
imminent / QuickReturnListFragment.java
Last active March 14, 2016 14:13
Quick return bar for ListView
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ListView;
import android.support.v4.app.ListFragment;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.ObjectAnimator;
@imminent
imminent / banner_image_view.xml
Created December 17, 2012 18:07
set height ImageView stetches image to fit width while maintaining aspect ratio. Centers the stretched image in the window of the ImageView.
<ImageView
android:id="@+id/header_background"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignBottom="@+id/avatar"
android:paddingTop="8dp"
android:scaleType="centerCrop"
android:cropToPadding="true"
android:adjustViewBounds="true"
android:src="@drawable/anonymous_image_2"