Back to project page u2020.
The source code is released under:
Apache License
If you think the Android project u2020 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.jakewharton.u2020.data; /*www .j a v a 2 s. c o m*/ import android.app.Application; import android.content.SharedPreferences; import android.net.Uri; import com.jakewharton.u2020.data.api.ApiModule; import com.squareup.okhttp.Cache; import com.squareup.okhttp.OkHttpClient; import com.squareup.picasso.OkHttpDownloader; import com.squareup.picasso.Picasso; import dagger.Module; import dagger.Provides; import java.io.File; import java.io.IOException; import javax.inject.Singleton; import timber.log.Timber; import static android.content.Context.MODE_PRIVATE; @Module( includes = ApiModule.class, complete = false, library = true ) public final class DataModule { static final int DISK_CACHE_SIZE = 50 * 1024 * 1024; // 50MB @Provides @Singleton SharedPreferences provideSharedPreferences(Application app) { return app.getSharedPreferences("u2020", MODE_PRIVATE); } @Provides @Singleton OkHttpClient provideOkHttpClient(Application app) { return createOkHttpClient(app); } @Provides @Singleton Picasso providePicasso(Application app, OkHttpClient client) { return new Picasso.Builder(app) .downloader(new OkHttpDownloader(client)) .listener(new Picasso.Listener() { @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) { Timber.e(e, "Failed to load image: %s", uri); } }) .build(); } static OkHttpClient createOkHttpClient(Application app) { OkHttpClient client = new OkHttpClient(); // Install an HTTP cache in the application cache directory. try { File cacheDir = new File(app.getCacheDir(), "http"); Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE); client.setCache(cache); } catch (IOException e) { Timber.e(e, "Unable to install disk cache."); } return client; } }