/** * Specify the the thread factory for loading images in the background. * <p> * Note: Calling {@link #executor(ExecutorService)} overwrites this value. */ @NonNull public Builder threadFactory(@NonNull ThreadFactory threadFactory) { checkNotNull(threadFactory, "threadFactory == null"); service = new PicassoExecutorService(threadFactory); return this; }
/** Create the {@link Picasso} instance. */ @NonNull public Picasso build() { Context context = this.context; okhttp3.Cache unsharedCache = null; if (callFactory == null) { File cacheDir = createDefaultCacheDir(context); long maxSize = calculateDiskCacheSize(cacheDir); unsharedCache = new okhttp3.Cache(cacheDir, maxSize); callFactory = new OkHttpClient.Builder() .cache(unsharedCache) .build(); } if (cache == null) { cache = new PlatformLruCache(Utils.calculateMemoryCacheSize(context)); } if (service == null) { service = new PicassoExecutorService(new PicassoThreadFactory()); } Stats stats = new Stats(cache); Dispatcher dispatcher = new Dispatcher(context, service, HANDLER, cache, stats); return new Picasso(context, dispatcher, callFactory, unsharedCache, cache, listener, requestTransformers, requestHandlers, stats, defaultBitmapConfig, indicatorsEnabled, loggingEnabled); } }
static Picasso defaultPicasso(Context context, boolean hasRequestHandlers, boolean hasTransformers) { Picasso.Builder builder = new Picasso.Builder(context); if (hasRequestHandlers) { builder.addRequestHandler(NOOP_REQUEST_HANDLER); } if (hasTransformers) { builder.addRequestTransformer(NOOP_TRANSFORMER); } return builder .callFactory(UNUSED_CALL_FACTORY) .defaultBitmapConfig(DEFAULT_CONFIG) .executor(new PicassoExecutorService(new PicassoThreadFactory())) .indicatorsEnabled(true) .listener(NOOP_LISTENER) .loggingEnabled(true) .withCacheSize(DEFAULT_CACHE_SIZE) .build(); }