Search in sources :

Example 1 with OkHttp3Downloader

use of com.squareup.picasso.OkHttp3Downloader in project Manhua by ag2s20150909.

the class APP method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mContext = this;
    fixdeThreadPool = Executors.newFixedThreadPool(1);
    CrashHandler.getInstance().init(this).setOnCrashListener(new CrashHandler.OnCrashListener() {

        @Override
        public void onCrash(Context context, String errorMsg) {
            Toast.makeText(context, errorMsg, Toast.LENGTH_LONG).show();
        }
    }).setCrashSave().setCrashSaveTargetFolder(this.getExternalFilesDir("crash").getPath());
    File file = new File(mContext.getExternalCacheDir(), "okhttpcache");
    if (!file.exists()) {
        file.mkdirs();
    }
    okhttp3.Cache cache = new okhttp3.Cache(file, 1024 * 1024 * 500);
    okhttp3.OkHttpClient client = new OkHttpClient.Builder().cache(cache).build();
    OkHttp3Downloader okHttp3Downloader = new OkHttp3Downloader(client);
    Picasso.Builder picassoBuilder = new Picasso.Builder(mContext);
    picassoBuilder.downloader(okHttp3Downloader).build();
    Picasso picasso = picassoBuilder.build();
    Picasso.setSingletonInstance(picasso);
}
Also used : Context(android.content.Context) CrashHandler(cn.liuyin.manhua.tool.CrashHandler) OkHttpClient(okhttp3.OkHttpClient) OkHttp3Downloader(com.squareup.picasso.OkHttp3Downloader) Picasso(com.squareup.picasso.Picasso) File(java.io.File)

Aggregations

Context (android.content.Context)1 CrashHandler (cn.liuyin.manhua.tool.CrashHandler)1 OkHttp3Downloader (com.squareup.picasso.OkHttp3Downloader)1 Picasso (com.squareup.picasso.Picasso)1 File (java.io.File)1 OkHttpClient (okhttp3.OkHttpClient)1