Skip to content

Instantly share code, notes, and snippets.

@JakeWharton
JakeWharton / SquareViewAnimator.java
Created June 13, 2012 17:59
ViewAnimator helper which allows setting the selected child by ID rather than index
package com.squareup.widgets;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ViewAnimator;
/** ViewAnimator helper which allows setting the selected child by ID rather than index. */
public class SquareViewAnimator extends ViewAnimator {
public SquareViewAnimator(Context context) {
/**
* Execute an {@link AsyncTask} on a thread pool.
*
* @param task Task to execute.
* @param args Optional arguments to pass to {@link AsyncTask#execute(Object[])}.
* @param <T> Task argument type.
*/
public static <T> void execute(AsyncTask<T, ?, ?> task, T... args) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) {
throw new UnsupportedOperationException("This class can only be used on API 4 and newer.");
@JakeWharton
JakeWharton / BaseActivity.java
Created July 6, 2012 01:17
Scoped event bus which automatically registers and unregisters with the lifecycle.
package com.squareup.example;
public abstract BaseActivity extends SherlockActivity {
private final ScopedBus scopedBus = new ScopedBus();
protected ScopedBus getBus() {
return scopedBus;
}
@Override public void onPause() {
@JakeWharton
JakeWharton / authorpurge.py
Created August 15, 2012 19:29
Purge all @author tags!
#!/usr/bin/env python
import os
import re
os.system('git reset --hard HEAD')
os.system('git clean -fdx')
REs = [
r'''\s+\*\n\s+\* @author[^\n]*''',
@JakeWharton
JakeWharton / ActionBarSherlockRobolectric.java
Created September 29, 2012 05:42
Making Robolectric suck less... (barely)
// Copyright 2012 Square, Inc.
package com.squareup.test;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import com.actionbarsherlock.ActionBarSherlock;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.internal.ActionBarSherlockCompat;
$ hermione.py test-3.0
Deploying artifacts to hermetic repository...
Rictusempra com.aaa:bbb:1.0-test-3.0...
Prior Incantato com.ccc:ddd:1.0.0-test-3.0...
Point Me com.eee:fff:2.2-test-3.0...
Rictusempra com.ggg:hhh:0.8-test-3.0...
Engorgio com.iii:jjj:1.0-test-3.0...
Rictusempra com.kkk:lll:0.8.0-test-3.0...
@JakeWharton
JakeWharton / README.md
Last active October 13, 2015 14:38
Maven pom for Google Play services
@JakeWharton
JakeWharton / BindingAdapter.java
Last active July 25, 2023 05:49
An adapter base class that uses a new/bind pattern for its views.
// Apache 2.0 licensed.
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
/** An implementation of {@link BaseAdapter} which uses the new/bind pattern for its views. */
public abstract class BindableAdapter<T> extends BaseAdapter {
@JakeWharton
JakeWharton / OkHttpStack.java
Created May 21, 2013 01:14
A `HttpStack` implementation for Volley that uses OkHttp as its transport.
import com.android.volley.toolbox.HurlStack;
import com.squareup.okhttp.OkHttpClient;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* An {@link com.android.volley.toolbox.HttpStack HttpStack} implementation which
* uses OkHttp as its transport.
*/
@JakeWharton
JakeWharton / OkConnectionFactory.java
Created June 17, 2013 15:04
A connection factory for using OkHttp with Kevin Sawicki's HttpRequest library.
/**
* A {@link HttpRequest.ConnectionFactory connection factory} which uses OkHttp.
* <p/>
* Call {@link HttpRequest#setConnectionFactory(HttpRequest.ConnectionFactory)} with an instance of
* this class to enable.
*/
public class OkConnectionFactory implements HttpRequest.ConnectionFactory {
private final OkHttpClient client;
public OkConnectionFactory() {