Created
April 21, 2015 07:19
-
-
Save Hackforid/3b6792333299f47e70b6 to your computer and use it in GitHub Desktop.
Stetho Okhttp Picasso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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