Skip to content

Instantly share code, notes, and snippets.

@dkunzler
dkunzler / Activity.java
Created May 23, 2013 14:30
To use square's Picasso image loading library (http://square.github.io/picasso/) with http Basic auth the implementation of a custom loader is necessary. OkHttp (http://square.github.io/okhttp/) is also needed. Additionally on the server side cache control for such responses has to be enabled explicitly.
// inside Application or Activity, make sure Picasso gets only initalized once
Picasso picasso;
Builder builder = new Picasso.Builder(this);
picasso = builder.loader(new BasicAuthOkHttpLoader(this)).build();
@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.
*/
package your.awesome.app;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.toolbox.ImageLoader.ImageCache;
public class LruBitmapCache extends LruCache<String, Bitmap> implements ImageCache {
public LruBitmapCache(int maxSize) {
super(maxSize);
@dustin-graham
dustin-graham / gist:5571520
Created May 13, 2013 21:04
Simple activity to pull data from whoismyrepresentative.org. This code throws a runtime error: java.lang.ExceptionInInitializerError caused by java.util.regex.PatternSyntaxException: Syntax error U_REGEX_RULE_SYNTAX near index 21: 05-13 14:55:03.464: E/AndroidRuntime(1568): \{([a-z][a-z0-9_-]*)} of RestMethodInfo line 46
package com.rain.example.retrofit.sanitycheck;
import java.util.List;
import retrofit.RestAdapter;
import retrofit.http.GET;
import retrofit.http.Query;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
@skyisle
skyisle / MyActivity.java
Created May 10, 2013 08:43
crash reproduce with okhttp
package com.alanjeon.okhttptest;
import com.squareup.okhttp.OkHttpClient;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ficusk
ficusk / GsonRequest.java
Last active January 6, 2025 22:43
A Volley adapter for JSON requests that will be parsed into Java objects by Gson.
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
@emil10001
emil10001 / OkDownload.java
Created April 24, 2013 16:41
Playing around with Square's OkHttp library.
OkHttpClient client = new OkHttpClient();
// Ignore invalid SSL endpoints.
client.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
@johnkil
johnkil / DbUtils.java
Last active December 16, 2015 13:48
Utilities to work with SQLite database (based on http://udinic.wordpress.com/2012/05/09/sqlite-drop-column-support).
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;
/**
@eLindemann
eLindemann / dabblet.css
Created April 1, 2013 20:41
"Google Now" Card
/**
* "Google Now" Card
*/
body {
background: #e1e1e1;
min-height: 100%;
margin: auto;
}
ul.gNow {
width: 450px;
@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;