Skip to content

Instantly share code, notes, and snippets.

@Hackforid
Created April 21, 2015 07:19
Show Gist options
  • Save Hackforid/3b6792333299f47e70b6 to your computer and use it in GitHub Desktop.
Save Hackforid/3b6792333299f47e70b6 to your computer and use it in GitHub Desktop.
Stetho Okhttp Picasso
public class App extends Application {
private static final String PICASSO_CACHE = "picasso-cache";
private static final long PICASSO_CACHE_SIZE = 100 * 1024 * 1024;
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) {
Stetho.initialize(
Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build());
setPicasso();
}
}
public void setPicasso() {
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
File cache = new File(this.getCacheDir(), PICASSO_CACHE);
if (!cache.exists()) {
//noinspection ResultOfMethodCallIgnored
cache.mkdirs();
}
try {
client.setCache(new Cache(cache, PICASSO_CACHE_SIZE));
} catch (IOException e) {
e.printStackTrace();
}
Picasso picasso = new Picasso.Builder(this)
.downloader(new OkHttpDownloader(client))
.build();
Picasso.setSingletonInstance(picasso);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment