Java Code Examples for com.jess.arms.utils.DataHelper

The following examples show how to use com.jess.arms.utils.DataHelper. These examples are extracted from open source projects. 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 Project: MVPArms   Source File: GlideConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
    final AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    builder.setDiskCache(() -> {
        // Careful: the external cache directory doesn't enforce permissions
        return DiskLruCacheWrapper.create(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE);
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    //将配置 Glide 的机会转交给 GlideImageLoaderStrategy,如你觉得框架提供的 GlideImageLoaderStrategy
    //并不能满足自己的需求,想自定义 BaseImageLoaderStrategy,那请你最好实现 GlideAppliesOptions
    //因为只有成为 GlideAppliesOptions 的实现类,这里才能调用 applyGlideOptions(),让你具有配置 Glide 的权利
    BaseImageLoaderStrategy loadImgStrategy = appComponent.imageLoader().getLoadImgStrategy();
    if (loadImgStrategy instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) loadImgStrategy).applyGlideOptions(context, builder);
    }
}
 
Example 2
Source Project: Aurora   Source File: ClientModule.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 需要单独给 {@link RxCache} 提供缓存路径
 *
 * @param cacheDir
 * @return
 */
@Singleton
@Provides
@Named("RxCacheDirectory")
File provideRxCacheDirectory(File cacheDir) {
    File cacheDirectory = new File(cacheDir, "RxCache");
    return DataHelper.makeDirs(cacheDirectory);
}
 
Example 3
Source Project: Aurora   Source File: GlideConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    //将配置 Glide 的机会转交给 GlideImageLoaderStrategy,如你觉得框架提供的 GlideImageLoaderStrategy
    //并不能满足自己的需求,想自定义 BaseImageLoaderStrategy,那请你最好实现 GlideAppliesOptions
    //因为只有成为 GlideAppliesOptions 的实现类,这里才能调用 applyGlideOptions(),让你具有配置 Glide 的权利
    BaseImageLoaderStrategy loadImgStrategy = appComponent.imageLoader().getLoadImgStrategy();
    if (loadImgStrategy instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) loadImgStrategy).applyGlideOptions(context, builder);
    }
}
 
Example 4
Source Project: LQRBiliBlili   Source File: GlobalConfiguration.java    License: MIT License 5 votes vote down vote up
@Override
    public void applyOptions(Context context, GlobalConfigModule.Builder builder) {
        //使用builder可以为框架配置一些配置信息
        builder
                //.baseurl(Api.APP_DOMAIN)
                .retrofitConfiguration(new MyRetrofitConfiguration())
                // 使用统一UserAgent
//                .addInterceptor(new UserAgentInterceptor())
                .rxCacheConfiguration(new MyRxCacheConfiguration())
                .globalHttpHandler(new MyGlobalHttpHandler())
                .responseErrorListener(new MyResponseErrorListener())
                .cacheFile(new File(DataHelper.getCacheFile(context), "rxCache"))
                .gsonConfiguration(new MyGsonConfiguration());
    }
 
Example 5
Source Project: MVPArms   Source File: ClientModule.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 需要单独给 {@link RxCache} 提供子缓存文件
 *
 * @param cacheDir 框架缓存文件
 * @return {@link File}
 */
@Singleton
@Provides
@Named("RxCacheDirectory")
static File provideRxCacheDirectory(File cacheDir) {
    File cacheDirectory = new File(cacheDir, "RxCache");
    return DataHelper.makeDirs(cacheDirectory);
}
 
Example 6
Source Project: Aurora   Source File: GlobalConfigModule.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 提供缓存文件
 */
@Singleton
@Provides
File provideCacheFile(Application application) {
    return mCacheFile == null ? DataHelper.getCacheFile(application) : mCacheFile;
}
 
Example 7
Source Project: MVPArms   Source File: GlobalConfigModule.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 提供缓存文件
 */
@Singleton
@Provides
File provideCacheFile(Application application) {
    return mCacheFile == null ? DataHelper.getCacheFile(application) : mCacheFile;
}