com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader Java Examples

The following examples show how to use com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlideModule.java    From glide-support with The Unlicense 6 votes vote down vote up
@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));
	}
 
Example #2
Source File: GlideModelConfig.java    From ImageLoader with Apache License 2.0 6 votes vote down vote up
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide,
                               @NonNull Registry registry)  {
    /**
     * 不带拦截功能,只是单纯替换通讯组件
     */

    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    setIgnoreAll(builder);
    OkHttpClient client=builder
            .addNetworkInterceptor(new ProgressInterceptor())
            .connectTimeout(30, TimeUnit.SECONDS)
            .readTimeout(30, TimeUnit.SECONDS)
            .writeTimeout(30, TimeUnit.SECONDS)
            .build();
    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
    Log.i("glide","registerComponents---");

}
 
Example #3
Source File: GlideModuleSetting.java    From LeisureRead with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: GlideModelConfig.java    From ImageLoader with Apache License 2.0 6 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide) {
    /**
     * 不带拦截功能,只是单纯替换通讯组件
     */

    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    setIgnoreAll(builder);
    OkHttpClient client=builder
            .addNetworkInterceptor(new ProgressInterceptor())
            .connectTimeout(30, TimeUnit.SECONDS)
            .readTimeout(30, TimeUnit.SECONDS)
            .writeTimeout(30, TimeUnit.SECONDS)
            .build();

    glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
    Log.i("glide","registerComponents---");

}
 
Example #5
Source File: GlideModule.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public void registerComponents(
		@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
	// just to see the headers actually went through, Stetho or proxy can also be used for this
	registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(new OkHttpClient.Builder()
			.addNetworkInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.HEADERS))
			.build()));
	// override default loader with one that attaches headers
	registry.replace(String.class, InputStream.class, new HeaderedLoader.Factory());
}
 
Example #6
Source File: TestFragment.java    From glide-support with The Unlicense 5 votes vote down vote up
@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)))
	;
}
 
Example #7
Source File: GlideModule.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public void registerComponents(Context context, Glide glide) {
	// just to see the headers actually went through, Stetho or proxy can also be used for this
	glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(new OkHttpClient.Builder()
			.addNetworkInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.HEADERS))
			.build()));
	// override default loader with one that attaches headers
	glide.register(String.class, InputStream.class, new HeaderedLoader.Factory());
}
 
Example #8
Source File: ArtistImageLoader.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
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());
}
 
Example #9
Source File: AbstractGlideModule.java    From DMusic with Apache License 2.0 5 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder()
            .connectTimeout(10, TimeUnit.SECONDS)
            .readTimeout(10, TimeUnit.SECONDS)
            .writeTimeout(10, TimeUnit.SECONDS);
    SSLSocketFactory sslSocketFactory = getSSLSocketFactory();
    if (sslSocketFactory != null) {
        builder.sslSocketFactory(sslSocketFactory);
    }
    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(builder.build()));
}
 
Example #10
Source File: ArtistImageLoader.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
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());
}
 
Example #11
Source File: BaseNet.java    From AFBaseLibrary with Apache License 2.0 5 votes vote down vote up
protected void makeGlideSupportHttps() {
    if (!isHttpsRequest()) {
        return;
    }
    Glide.get(getApplicationContext()).register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(httpClient));

}
 
Example #12
Source File: ArtistImageLoader.java    From MusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
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());
}
 
Example #13
Source File: MyGlideModule.java    From MusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
    super.registerComponents(context, glide, registry);
    registry.append(AudioFileCover.class,InputStream.class,new AudioFileCoverLoader.Factory());
    registry.append(ArtistImage.class,InputStream.class, new ArtistImageLoader.Factory(context));
    registry.register(Bitmap.class, BitmapPaletteWrapper.class, new BitmapPaletteTranscoder());
    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
 
Example #14
Source File: HomeAssistAppGlideModule.java    From homeassist with Apache License 2.0 5 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
    OkHttpClient client = ServiceProvider.getGlideOkHttpClientInstance();
    OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client);

    glide.getRegistry().replace(GlideUrl.class, InputStream.class, factory);
}
 
Example #15
Source File: CustomGlideModule.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 5 votes vote down vote up
@Override
public void registerComponents(final Context context, final Glide glide, final Registry registry) {
    final OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
    builder.connectTimeout(15, TimeUnit.SECONDS);
    builder.readTimeout(30, TimeUnit.SECONDS);

    // Uncomment to use Stetho network debugging
    // if (BuildConfig.DEBUG) {
    //     builder.addNetworkInterceptor(new com.facebook.stetho.okhttp3.StethoInterceptor()).build();
    // }

    final OkHttpClient client = builder.build();
    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
 
Example #16
Source File: AbstractGlideModule.java    From Common with Apache License 2.0 5 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder()
            .connectTimeout(10, TimeUnit.SECONDS)
            .readTimeout(10, TimeUnit.SECONDS)
            .writeTimeout(10, TimeUnit.SECONDS);
    SSLSocketFactory sslSocketFactory = getSSLSocketFactory();
    if (sslSocketFactory != null) {
        builder.sslSocketFactory(sslSocketFactory);
    }
    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(builder.build()));
}
 
Example #17
Source File: TyGlide.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void registerComponents(@NonNull Context context,
                               @NonNull Glide glide,
                               @NonNull Registry registry) {
    OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(OkHttpHelper.getOkHttpInstance());

    registry.replace(GlideUrl.class, InputStream.class, factory);
}
 
Example #18
Source File: VideoListGlideModule.java    From VideoListPlayer with MIT License 4 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide) {
    glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(sClient));
}
 
Example #19
Source File: VideoListGlideModule.java    From VideoListPlayer with MIT License 4 votes vote down vote up
public static OkHttpUrlLoader getOkHttpUrlLoader() {
    return sOkHttpUrlLoader;
}
 
Example #20
Source File: BaseGlide.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
@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()));
}
 
Example #21
Source File: GlideConfiguration.java    From GankGirl with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide) {
    // 配置使用OKHttp3来请求网络
    glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(new OkHttpClient()));
}
 
Example #22
Source File: MainApplication.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes the request manager, image cache,
 * all third party integrations and shared components.
 */
private void init() {
    application = this;
    // FIXME: Disable RoboBlender to avoid annotation processor issues for now, as we already have plans to move to some other DI framework. See LEARNER-1687.
    // ref: https://github.com/roboguice/roboguice/wiki/RoboBlender-wiki#disabling-roboblender
    // ref: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration
    RoboGuice.setUseAnnotationDatabases(false);
    injector = RoboGuice.getOrCreateBaseApplicationInjector((Application) this, RoboGuice.DEFAULT_STAGE,
            (Module) RoboGuice.newDefaultRoboModule(this), (Module) new EdxDefaultModule(this));

    injector.injectMembers(this);

    EventBus.getDefault().register(new CrashlyticsCrashReportObserver());

    if (config.getNewRelicConfig().isEnabled()) {
        EventBus.getDefault().register(new NewRelicObserver());
    }

    // initialize NewRelic with crash reporting disabled
    if (config.getNewRelicConfig().isEnabled()) {
        //Crash reporting for new relic has been disabled
        NewRelic.withApplicationToken(config.getNewRelicConfig().getNewRelicKey())
                .withCrashReportingEnabled(false)
                .start(this);
    }

    // Add Segment as an analytics provider if enabled in the config
    if (config.getSegmentConfig().isEnabled()) {
        analyticsRegistry.addAnalyticsProvider(injector.getInstance(SegmentAnalytics.class));
    }
    if (config.getFirebaseConfig().isAnalyticsSourceFirebase()) {
        // Only add Firebase as an analytics provider if enabled in the config and Segment is disabled
        // because if Segment is enabled, we'll be using Segment's implementation for Firebase
        analyticsRegistry.addAnalyticsProvider(injector.getInstance(FirebaseAnalytics.class));
    }

    if (config.getFirebaseConfig().isEnabled()) {
        // Firebase notification needs to initialize the FirebaseApp before
        // subscribe/unsubscribe to/from the topics
        FirebaseApp.initializeApp(this);
        if (config.areFirebasePushNotificationsEnabled()) {
            NotificationUtil.subscribeToTopics(config);
        } else if (!config.areFirebasePushNotificationsEnabled()) {
            NotificationUtil.unsubscribeFromTopics(config);
        }
    }

    registerReceiver(new NetworkConnectivityReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    registerReceiver(new NetworkConnectivityReceiver(), new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));

    checkIfAppVersionUpgraded(this);

    // Register Font Awesome module in android-iconify library
    Iconify.with(new FontAwesomeModule());

    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
            .setDefaultFontPath("fonts/OpenSans-Regular.ttf")
            .setFontAttrId(R.attr.fontPath)
            .build()
    );

    // Init Branch
    if (config.getBranchConfig().isEnabled()) {
        Branch.getAutoInstance(this);
    }

    // Force Glide to use our version of OkHttp which now supports TLS 1.2 out-of-the-box for
    // Pre-Lollipop devices
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Glide.get(this).getRegistry().replace(GlideUrl.class, InputStream.class,
                new OkHttpUrlLoader.Factory(injector.getInstance(OkHttpClientProvider.class).get()));
    }

    // Initialize Facebook SDK
    boolean isOnZeroRatedNetwork = NetworkUtil.isOnZeroRatedNetwork(getApplicationContext(), config);
    if (!isOnZeroRatedNetwork && config.getFacebookConfig().isEnabled()) {
        // Facebook sdk should be initialized through AndroidManifest meta data declaration but
        // we are generating the meta data through gradle script due to which it is necessary
        // to manually initialize the sdk here.
        FacebookSdk.setApplicationId(config.getFacebookConfig().getFacebookAppId());
        FacebookSdk.sdkInitialize(getApplicationContext());
    }

    if (PermissionsUtil.checkPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, this)) {
        deleteExtraDownloadedFiles();
    }
}
 
Example #23
Source File: OkHttpProgressGlideModule.java    From glide-support with The Unlicense 4 votes vote down vote up
@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));
}
 
Example #24
Source File: OKHttpLibraryGlideModule.java    From Protein with Apache License 2.0 4 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
    registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
 
Example #25
Source File: OkHttpProgressGlideModule.java    From StatusStories with Apache License 2.0 4 votes vote down vote up
@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));
}
 
Example #26
Source File: GlideConfig.java    From MVVM-JueJin with MIT License 4 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide) {
    glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(OkHttpFactory.INSTANCE.create(null, false)));
}
 
Example #27
Source File: GlideConfiguration.java    From ProgressManager with Apache License 2.0 4 votes vote down vote up
@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()));
}
 
Example #28
Source File: GlideConfiguration.java    From AcgClub with MIT License 4 votes vote down vote up
@Override
public void registerComponents(Context context, Glide glide, Registry registry) {
  //Glide默认使用HttpURLConnection做网络请求,在这切换成okhttp请求
  registry.replace(GlideUrl.class, InputStream.class,
      new OkHttpUrlLoader.Factory(Utils.getAppComponent().okHttpClient()));
}