@Override public void registerComponents(Context context, Glide glide) { Stetho.initializeWithDefaults(context); final Cache cache = new Cache(new File(context.getCacheDir(), "okhttp"), IMAGE_CACHE_SIZE); HttpLoggingInterceptor logger = new HttpLoggingInterceptor(); // logger.setLevel(Level.BASIC); OkHttpClient client = new OkHttpClient() .newBuilder() .cache(cache) .addNetworkInterceptor(new StethoInterceptor()) .addInterceptor(logger) .build(); glide.register(CachedGlideUrl.class, InputStream.class, superFactory(new OkHttpUrlLoader.Factory(client), CachedGlideUrl.class)); glide.register(ForceLoadGlideUrl.class, InputStream.class, superFactory(new OkHttpUrlLoader.Factory(client), ForceLoadGlideUrl.class)); }
@Override public void registerComponents(Context context, Glide glide) { final File cacheDir = new File(BaseApplication.get().getCacheDir(), "ToshiImageCache"); final Cache cache = new Cache(cacheDir, MAX_SIZE); final OkHttpClient client = new OkHttpClient().newBuilder() .cache(cache) .addInterceptor(new AppInfoUserAgentInterceptor()) .addInterceptor(new HttpLoggingInterceptor(new LoggingInterceptor()).setLevel(HttpLoggingInterceptor.Level.BODY)) .build(); glide.register(CachedGlideUrl.class, InputStream.class, superFactory(new OkHttpUrlLoader.Factory(client), CachedGlideUrl.class)); glide.register(ForceLoadGlideUrl.class, InputStream.class, superFactory(new OkHttpUrlLoader.Factory(client), ForceLoadGlideUrl.class)); }
@Override public void registerComponents(Context context, Glide glide) { //配置OkHttp OkHttpClient mOkHttpClient = new OkHttpClient() .newBuilder() .connectTimeout(15, TimeUnit.SECONDS) .readTimeout(15, TimeUnit.SECONDS) .build(); //设置Glide请求为Okhttp glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(mOkHttpClient)); //设置Glide的内存缓存和BitmapPool使用最多他们初始值的最大大小的一半 glide.setMemoryCategory(MemoryCategory.LOW); }
@Override public void onCreate() { super.onCreate(); // Flog是自定义Log if (BuildConfig.DEBUG) { Flog.DebugTree tree = new Flog.DebugTree(); tree.setShowLine(false); // 是否打印类名和行号 Flog.plant(tree); } OkHttpClient okHttpClient = new OkHttpClient(); //配置Fresco ImagePipelineConfig config = OkHttpImagePipelineConfigFactory .newBuilder(this, okHttpClient) .build(); Fresco.initialize(this, config); Glide.get(this).register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(okHttpClient)); }
public void getUserPhoto(Activity activity, String userID, ImageView view, int defaultResID, int maxSize, String lastModify) { if (userID == null || userID.isEmpty()) { return; } if (mFactory == null) { mFactory = new OkHttpUrlLoader.Factory(mUserDataProvider.getOkHttpClient()); Glide.get(mActivity).register(GlideUrl.class, InputStream.class, mFactory); } String url = mUserDataProvider.getUserPhotoUrl(userID); if (url != null) { if (view.getTag() == null) { new GlidePhotoData(activity, view, defaultResID, lastModify, maxSize, mSubDomain, url); } else { new GlidePhotoData(activity, view, lastModify, maxSize, mSubDomain, url); } } }
public Factory(Context context) { okHttpFactory = new OkHttpUrlLoader.Factory(new OkHttpClient.Builder() .connectTimeout(TIMEOUT, TimeUnit.MILLISECONDS) .readTimeout(TIMEOUT, TimeUnit.MILLISECONDS) .writeTimeout(TIMEOUT, TimeUnit.MILLISECONDS) .build()); lastFMClient = new LastFMRestClient(LastFMRestClient.createDefaultOkHttpClientBuilder(context) .connectTimeout(TIMEOUT, TimeUnit.MILLISECONDS) .readTimeout(TIMEOUT, TimeUnit.MILLISECONDS) .writeTimeout(TIMEOUT, TimeUnit.MILLISECONDS) .build()); }
public static void init(Glide glide, OkHttpClient okHttpClient) { OkHttpClient.Builder builder; if (okHttpClient != null) { builder = okHttpClient.newBuilder(); } else { builder = new OkHttpClient.Builder(); } builder.addNetworkInterceptor(createInterceptor(new DispatchingProgressListener())); glide.getRegistry().replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(builder.build())); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); OkHttpClient client = new OkHttpClient.Builder() .readTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS) .addInterceptor(loggingInterceptor) .build(); registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client)); }
@Override public void registerComponents(Context context, Glide glide) { OkHttpClient client = new OkHttpClient .Builder() .addInterceptor(createInterceptor(new DispatchingProgressListener())) .build(); glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client)); }
public static void init(Glide glide, OkHttpClient okHttpClient) { OkHttpClient.Builder builder; if (okHttpClient != null) { builder = okHttpClient.newBuilder(); } else { builder = new OkHttpClient.Builder(); } builder.addNetworkInterceptor(createInterceptor(new DispatchingProgressListener())); glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(builder.build())); }
@Singleton @Provides public RequestManager provideGlide() { OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(mOkHttpClient); Glide.get(app).register(GlideUrl.class, InputStream.class, factory); return Glide.with(app); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { registry.replace( GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory( request -> GlobalApplication.getOkHttpClient().newCall(request) ) ); }
@Override protected void load2(Context context, ImageView imageView) throws Exception { Glide .with(this) .using(new StreamModelLoaderWrapper<>(new OkHttpUrlLoader(longTimeoutClient))) .load(new GlideUrl("https://httpbin.org/delay/12")) // timeout increased: 15 > 10, so it'll pass .signature(new StringSignature("load2")) // distinguish from other load to make sure loader is picked up .placeholder(R.drawable.glide_placeholder) // since the test URL returns a JSON stream, the load will fail, // let's still add an error to see that the load fails slower than the other, // meaning the image was actually tried to be decoded .error(R.drawable.glide_error) .listener(new LoggingListener<GlideUrl, GlideDrawable>("load2")) .into(new LoggingTarget<>("load2", Log.VERBOSE, new GlideDrawableImageViewTarget(imageView))) ; }
@Singleton @Provides RequestManager provideGlide(OkHttpClient okHttpClient) { OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(okHttpClient); Glide.get(mView).register(GlideUrl.class, InputStream.class, factory); return Glide.with(mView); }
@Override public void onCreate() { super.onCreate(); Glide.get(this).register(GlideUrl.class , InputStream.class , new OkHttpUrlLoader.Factory(RetrofitClient.getOkHttpClient(this))); LocalDisplay.init(this); }
public PhotoUserAdapter(Activity context, ArrayList<ListUser> items, ListView listView, OnItemClickListener onItemClickListener, Popup popup, BaseListAdapter.OnItemsListener onUsersListener) { super(context, items, listView, onItemClickListener, popup, onUsersListener); mPermissionDataProvider = PermissionDataProvider.getInstance(context); mSubDomain = (String)ConfigDataProvider.getLocalStorage(LocalStorage.SUBDOMAIN); if (mFactory == null) { mFactory = new OkHttpUrlLoader.Factory(mUserDataProvider.getOkHttpClient()); Glide.get(mActivity).register(GlideUrl.class, InputStream.class, mFactory); } if (mPermissionDataProvider.getLoginUserInfo() == null) { return; } mLoginedUserID = mPermissionDataProvider.getLoginUserInfo().user_id; }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { BaseApplication application = (BaseApplication) context.getApplicationContext(); //Glide 底层默认使用 HttpConnection 进行网络请求,这里替换为 Okhttp 后才能使用本框架,进行 Glide 的加载进度监听 registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(application.getOkHttpClient())); }
@Override public void registerComponents(Context context, Glide glide) { OkHttpClient client = OkHttpClientFactory.getTrustedOkHttpClient("", ""); glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client)); }
@Override public void registerComponents(Context context, Glide glide) { glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(OkHttpFactory.INSTANCE.create(null, false))); }
@Override public void registerComponents(Context context, Glide glide) { OkHttpClient client = new OkHttpClient.Builder() .addNetworkInterceptor(createInterceptor(new DispatchingProgressListener())) .build(); glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client)); }
@Override public void registerComponents(Context context, Glide glide) { glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(sClient)); }
public static OkHttpUrlLoader getOkHttpUrlLoader() { return sOkHttpUrlLoader; }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory()); }
@Override public void registerComponents(Context context, Glide glide) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.networkInterceptors().add(createInterceptor(new DispatchingProgressListener())); glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(builder.build())); }
@Override public void registerComponents(Context context, Glide glide) { //glide.clearDiskCache(); glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory()); glide.setMemoryCategory(MemoryCategory.NORMAL); }
@Override public void registerComponents(Context context, Glide glide) { glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());//将底层网络框架替换为okhttp }
@Override public void registerComponents(Context context, Glide glide) { MainApplication app = (MainApplication) context.getApplicationContext(); OkHttpClient client = app.getGlideOkHttpClient(); glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client)); }
@Override public void registerComponents(Context context, Glide glide) { // 配置使用OKHttp3来请求网络 glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(new OkHttpClient())); }
@Override public void registerComponents(Context context, Glide glide, Registry registry) { super.registerComponents(context, glide, registry); registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(ProgressManager.getOkHttpClient())); }
@Override public void registerComponents(Context context, Glide glide) { glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(callFactory)); }