Java Code Examples for com.bumptech.glide.load.DecodeFormat#PREFER_RGB_565

The following examples show how to use com.bumptech.glide.load.DecodeFormat#PREFER_RGB_565 . 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: ImageLoader.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("CheckResult") @NonNull private RequestOptions getRequestOptions() {
  RequestOptions requestOptions = new RequestOptions();
  DecodeFormat decodeFormat;
  if (Build.VERSION.SDK_INT >= 26) {
    decodeFormat = DecodeFormat.PREFER_ARGB_8888;
    requestOptions.disallowHardwareConfig();
  } else {
    decodeFormat = DecodeFormat.PREFER_RGB_565;
  }
  return requestOptions.format(decodeFormat)
      .diskCacheStrategy(DiskCacheStrategy.RESOURCE);
}
 
Example 2
Source File: HHGlideModel.java    From HHComicViewer with Apache License 2.0 4 votes vote down vote up
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    SharedPreferencesManager manager = new SharedPreferencesManager(context);
    final String cacheSize = manager.getString(DISK_CACHE_KEY, DISK_CACHE_160MB);
    String decodeFormat = manager.getString(DECODE_FORMAT_KEY, DECODE_FORMAT_ARGB_8888);
    final String cacheName = manager.getString(DISK_CACHE_NAME_KEY, DEFAULT_CACHE_NAME);

    DecodeFormat format = null;
    switch (decodeFormat) {
        case DECODE_FORMAT_RGB_565:
            format = DecodeFormat.PREFER_RGB_565;
            break;
        default:
        case DECODE_FORMAT_ARGB_8888:
            format = DecodeFormat.PREFER_ARGB_8888;
            break;
    }
    // 高版本配置,没有禁用Hardware Bitmaps,仅Android O以上版本的新特性
    // 参阅https://muyangmin.github.io/glide-docs-cn/doc/hardwarebitmaps.html了解不能使用Hardware Bitmaps的情况
    // 不禁用可能会导致错误,但是有着节省内存和避免内存抖动的优点
    builder.setDefaultRequestOptions(new RequestOptions()
    .format(format)
    );

    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            int sizeInMB = 160;
            switch (cacheSize) {
                case DISK_CACHE_40MB:
                    sizeInMB = 40;
                    break;
                case DISK_CACHE_80MB:
                    sizeInMB = 80;
                    break;
                case DISK_CACHE_160MB:
                    sizeInMB = 160;
                    break;
                case DISK_CACHE_320MB:
                    sizeInMB = 320;
                    break;
                default:
                case DISK_CACHE_640MB:
                    sizeInMB = 640;
                    break;
            }

            File path = null;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
                path = context.getExternalCacheDirs()[(context.getExternalCacheDirs().length - 1)];
            } else {
                path = context.getExternalCacheDir();
            }
            File cacheLocation = new File(path, cacheName);
            cacheLocation.mkdirs();
            return DiskLruCacheWrapper.create(cacheLocation, sizeInMB * 1024 * 1024);
        }
    });
}