com.bumptech.glide.load.Options Java Examples

The following examples show how to use com.bumptech.glide.load.Options. 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: SvgBitmapDrawableTranscoder.java    From SvgGlidePlugins with Apache License 2.0 6 votes vote down vote up
private void prepareSvg(@NonNull Resource<SVG> toTranscode, @Nullable Options options) {
    if (!(toTranscode instanceof SvgResource)) {
        return;
    }

    DownsampleStrategy strategy =
            options == null ? null : options.get(DownsampleStrategy.OPTION);
    if (strategy != null) {
        float scaleFactor = strategy.getScaleFactor(
                Math.round(toTranscode.get().getDocumentWidth()),
                Math.round(toTranscode.get().getDocumentHeight()),
                ((SvgResource) toTranscode).getWidth(),
                ((SvgResource) toTranscode).getHeight()
        );
        SvgUtils.scaleDocumentSize(toTranscode.get(), scaleFactor);
    }
}
 
Example #2
Source File: EncryptedBitmapResourceEncoder.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("EmptyCatchBlock")
@Override
public boolean encode(@NonNull Resource<Bitmap> data, @NonNull File file, @NonNull Options options) {
  Log.i(TAG, "Encrypted resource encoder running: " + file.toString());

  Bitmap                bitmap  = data.get();
  Bitmap.CompressFormat format  = getFormat(bitmap, options);
  int                   quality = options.get(BitmapEncoder.COMPRESSION_QUALITY);

  try (OutputStream os = createEncryptedOutputStream(secret, file)) {
    bitmap.compress(format, quality, os);
    os.close();
    return true;
  } catch (IOException e) {
    Log.w(TAG, e);
    return false;
  }
}
 
Example #3
Source File: EncryptedCacheEncoder.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("EmptyCatchBlock")
@Override
public boolean encode(@NonNull InputStream data, @NonNull File file, @NonNull Options options) {
  Log.i(TAG, "Encrypted cache encoder running: " + file.toString());

  byte[] buffer = byteArrayPool.get(ArrayPool.STANDARD_BUFFER_SIZE_BYTES, byte[].class);

  try (OutputStream outputStream = createEncryptedOutputStream(secret, file)) {
    int read;

    while ((read = data.read(buffer)) != -1) {
      outputStream.write(buffer, 0, read);
    }

    return true;
  } catch (IOException e) {
    if (e instanceof SocketException) {
      Log.d(TAG, "Socket exception. Likely a cancellation.");
    } else {
      Log.w(TAG, e);
    }
    return false;
  } finally {
    byteArrayPool.put(buffer);
  }
}
 
Example #4
Source File: SvgBitmapDrawableTranscoder.java    From SvgGlidePlugins with Apache License 2.0 6 votes vote down vote up
@NonNull
private Bitmap.Config getDecodeFormat(@Nullable Options options) {
    DecodeFormat decodeFormat = options == null ? null : options.get(GifOptions.DECODE_FORMAT);
    if (decodeFormat == null) {
        return Bitmap.Config.ARGB_8888;
    }

    switch (decodeFormat) {
        case PREFER_RGB_565:
            return Bitmap.Config.RGB_565;

        case PREFER_ARGB_8888:
        default:
            return Bitmap.Config.ARGB_8888;
    }
}
 
Example #5
Source File: EncryptedBitmapCacheDecoder.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Resource<Bitmap> decode(@NonNull File source, int width, int height, @NonNull Options options)
    throws IOException
{
  Log.i(TAG, "Encrypted Bitmap cache decoder running: " + source.toString());
  try (InputStream inputStream = createEncryptedInputStream(secret, source)) {
    return streamBitmapDecoder.decode(inputStream, width, height, options);
  }
}
 
Example #6
Source File: SvgDecoder.java    From GlideToVectorYou with Apache License 2.0 5 votes vote down vote up
public Resource<SVG> decode(@NonNull InputStream source, int width, int height,
                            @NonNull Options options)
    throws IOException {
  try {
    SVG svg = SVG.getFromInputStream(source);
    return new SimpleResource<>(svg);
  } catch (SVGParseException ex) {
    throw new IOException("Cannot load SVG from stream", ex);
  }
}
 
Example #7
Source File: RawResourceSvgDecoder.java    From SvgGlidePlugins with Apache License 2.0 5 votes vote down vote up
@Override
SVG loadSvg(@NonNull Uri source, int width, int height, @NonNull Options options) throws SvgParseException {
    try {
        return SVG.getFromResource(mResources, ResourceUtils.getRawResourceId(mResources, source));
    } catch (SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
Example #8
Source File: FileSvgDecoder.java    From SvgGlidePlugins with Apache License 2.0 5 votes vote down vote up
@Override
SVG loadSvg(@NonNull File source, int width, int height, @NonNull Options options) throws SvgParseException {
    try {
        return SvgUtils.getSvg(source);
    } catch (IOException | SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
Example #9
Source File: InputStreamSvgDecoder.java    From SvgGlidePlugins with Apache License 2.0 5 votes vote down vote up
@Override
SVG loadSvg(@NonNull InputStream source, int width, int height, @NonNull Options options) throws SvgParseException {
    try {
        return SVG.getFromInputStream(source);
    } catch (SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
Example #10
Source File: FirebaseImageLoader.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public LoadData<InputStream> buildLoadData(@NonNull StorageReference reference,
                                           int height,
                                           int width,
                                           @NonNull Options options) {
    return new LoadData<>(
            new FirebaseStorageKey(reference),
            new FirebaseStorageFetcher(reference));
}
 
Example #11
Source File: EncryptedBitmapResourceEncoder.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private Bitmap.CompressFormat getFormat(Bitmap bitmap, Options options) {
  Bitmap.CompressFormat format = options.get(BitmapEncoder.COMPRESSION_FORMAT);

  if (format != null) {
    return format;
  } else if (bitmap.hasAlpha()) {
    return Bitmap.CompressFormat.PNG;
  } else {
    return Bitmap.CompressFormat.JPEG;
  }
}
 
Example #12
Source File: EncryptedBitmapCacheDecoder.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean handles(@NonNull File source, @NonNull Options options)
    throws IOException
{
  Log.i(TAG, "Checking item for encrypted Bitmap cache decoder: " + source.toString());

  try (InputStream inputStream = createEncryptedInputStream(secret, source)) {
    return streamBitmapDecoder.handles(inputStream, options);
  } catch (IOException e) {
    Log.w(TAG, e);
    return false;
  }
}
 
Example #13
Source File: EncryptedGifCacheDecoder.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean handles(@NonNull File source, @NonNull Options options) {
  Log.i(TAG, "Checking item for encrypted GIF cache decoder: " + source.toString());

  try (InputStream inputStream = createEncryptedInputStream(secret, source)) {
    return gifDecoder.handles(inputStream, options);
  } catch (IOException e) {
    Log.w(TAG, e);
    return false;
  }
}
 
Example #14
Source File: EncryptedGifDrawableResourceEncoder.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean encode(@NonNull Resource<GifDrawable> data, @NonNull File file, @NonNull Options options) {
  GifDrawable drawable = data.get();

  try (OutputStream outputStream = createEncryptedOutputStream(secret, file)) {
    ByteBufferUtil.toStream(drawable.getBuffer(), outputStream);
    return true;
  } catch (IOException e) {
    Log.w(TAG, e);
    return false;
  }
}
 
Example #15
Source File: StringSvgDecoder.java    From SvgGlidePlugins with Apache License 2.0 5 votes vote down vote up
@Override
SVG loadSvg(@NonNull String source, int width, int height, @NonNull Options options) throws SvgParseException {
    try {
        return SVG.getFromString(source);
    } catch (SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
Example #16
Source File: BlurHashModelLoader.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public LoadData<BlurHash> buildLoadData(@NonNull BlurHash blurHash,
                                        int width,
                                        int height,
                                        @NonNull Options options)
{
  return new LoadData<>(new ObjectKey(blurHash.getHash()), new BlurDataFetcher(blurHash));
}
 
Example #17
Source File: EncryptedGifCacheDecoder.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Resource<GifDrawable> decode(@NonNull File source, int width, int height, @NonNull Options options) throws IOException {
  Log.i(TAG, "Encrypted GIF cache decoder running...");
  try (InputStream inputStream = createEncryptedInputStream(secret, source)) {
    return gifDecoder.decode(inputStream, width, height, options);
  }
}
 
Example #18
Source File: ParcelFileDescriptorSvgDecoder.java    From SvgGlidePlugins with Apache License 2.0 5 votes vote down vote up
@Override
SVG loadSvg(
        @NonNull ParcelFileDescriptor source,
        int width,
        int height,
        @NonNull Options options
) throws SvgParseException {
    return mDecoder.loadSvg(source.getFileDescriptor(), width, height, options);
}
 
Example #19
Source File: BlurHashResourceDecoder.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public @Nullable Resource<Bitmap> decode(@NonNull BlurHash source, int width, int height, @NonNull Options options) throws IOException {
  final int finalWidth;
  final int finalHeight;

  if (width > height) {
    finalWidth  = Math.min(width, MAX_DIMEN);
    finalHeight = (int) (finalWidth * height / (float) width);
  } else {
    finalHeight = Math.min(height, MAX_DIMEN);
    finalWidth  = (int) (finalHeight * width / (float) height);
  }

  return new SimpleResource<>(BlurHashDecoder.decode(source.getHash(), finalWidth, finalHeight));
}
 
Example #20
Source File: ByteBufferSvgDecoder.java    From SvgGlidePlugins with Apache License 2.0 5 votes vote down vote up
@Override
SVG loadSvg(@NonNull ByteBuffer source, int width, int height, @NonNull Options options) throws SvgParseException {
    try (InputStream is = ByteBufferUtil.toStream(source)) {
        return SVG.getFromInputStream(is);
    } catch (IOException | SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
Example #21
Source File: FileDescriptorSvgDecoder.java    From SvgGlidePlugins with Apache License 2.0 5 votes vote down vote up
@Override
SVG loadSvg(
        @NonNull FileDescriptor source,
        int width,
        int height,
        @NonNull Options options
) throws SvgParseException {
    try {
        return SvgUtils.getSvg(source);
    } catch (IOException | SVGParseException e) {
        throw new SvgParseException(e);
    }
}
 
Example #22
Source File: ArtistImageLoader.java    From MusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
    @Override
    public LoadData<InputStream> buildLoadData(@NonNull ArtistImage artistImage, int width, int height, @NonNull Options options) {
        return new LoadData<>( ArtistSignatureUtil.getInstance(App.getInstance()).getArtistSignature(artistImage.mArtistName, artistImage.mLoadOriginal,artistImage.mImageNumber),new ArtistImageFetcher(lastFMClient,artistImage,urlLoader,width,height,options));
//        return new LoadData<>(new ObjectKey(String.valueOf(artistImage.getArtistName())),new ArtistImageFetcher(lastFMClient,artistImage,urlLoader,width,height,options));
     //   return new LoadData<>( ArtistSignatureUtil.getInstance(App.getInstance()).getArtistSignature(artistImage.getArtistName()), new ArtistImageFetcher(lastFMClient,artistImage,urlLoader,width,height, options));
    }
 
Example #23
Source File: ArtistImageFetcher.java    From MusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
public ArtistImageFetcher(LastFMRestClient lastFMRestClient, ArtistImage model, ModelLoader<GlideUrl, InputStream> urlLoader, int width, int height, Options options) {
    this.lastFMRestClient = lastFMRestClient;
    this.model = model;
    this.urlLoader = urlLoader;
    this.width = width;
    this.height = height;
    mOption = options;
    mLoadOriginal = model.mLoadOriginal;
    mImageNumber = model.mImageNumber;
}
 
Example #24
Source File: SvgBitmapDrawableTranscoder.java    From SvgGlidePlugins with Apache License 2.0 5 votes vote down vote up
@Override
public Resource<BitmapDrawable> transcode(
        @NonNull Resource<SVG> toTranscode, @Nullable Options options) {
    prepareSvg(toTranscode, options);
    Bitmap bitmap = SvgUtils.toBitmap(toTranscode.get(), mBitmapProvider, getDecodeFormat(options));
    return LazyBitmapDrawableResource.obtain(mResources, new BitmapResource(bitmap, mBitmapPool));
}
 
Example #25
Source File: BitmapPaletteTranscoder.java    From MusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Resource<BitmapPaletteWrapper> transcode(@NonNull Resource<Bitmap> bitmapResource, @NonNull Options options) {
    Bitmap bitmap = bitmapResource.get();
    BitmapPaletteWrapper bitmapPaletteWrapper = new BitmapPaletteWrapper(bitmap,PhonographColorUtil.generatePalette(bitmap));
    return new BitmapPaletteResource(bitmapPaletteWrapper);
}
 
Example #26
Source File: ByteBufferAnimationDecoder.java    From APNG4Android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Resource<Drawable> decode(@NonNull final ByteBuffer source, int width, int height, @NonNull Options options) throws IOException {
    Loader loader = new ByteBufferLoader() {
        @Override
        public ByteBuffer getByteBuffer() {
            source.position(0);
            return source;
        }
    };
    FrameAnimationDrawable drawable;
    if (WebPParser.isAWebP(new ByteBufferReader(source))) {
        drawable = new WebPDrawable(loader);
    } else if (APNGParser.isAPNG(new ByteBufferReader(source))) {
        drawable = new APNGDrawable(loader);
    } else if (GifParser.isGif(new ByteBufferReader(source))) {
        drawable = new GifDrawable(loader);
    } else {
        return null;
    }
    return new DrawableResource<Drawable>(drawable) {
        @NonNull
        @Override
        public Class<Drawable> getResourceClass() {
            return Drawable.class;
        }

        @Override
        public int getSize() {
            return source.limit();
        }

        @Override
        public void recycle() {
            ((FrameAnimationDrawable) drawable).stop();
        }
    };
}
 
Example #27
Source File: StreamAnimationDecoder.java    From APNG4Android with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Resource<Drawable> decode(@NonNull final InputStream source, int width, int height, @NonNull Options options) throws IOException {
    byte[] data = inputStreamToBytes(source);
    if (data == null) {
        return null;
    }
    ByteBuffer byteBuffer = ByteBuffer.wrap(data);
    return byteBufferDecoder.decode(byteBuffer, width, height, options);
}
 
Example #28
Source File: SvgDrawableTranscoder.java    From GlideToVectorYou with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Resource<PictureDrawable> transcode(@NonNull Resource<SVG> toTranscode,
                                           @NonNull Options options) {
  SVG svg = toTranscode.get();
  Picture picture = svg.renderToPicture();
  PictureDrawable drawable = new PictureDrawable(picture);
  return new SimpleResource<>(drawable);
}
 
Example #29
Source File: SvgDecoder.java    From SvgGlidePlugins with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Resource<SVG> decode(@NonNull T source, int width, int height, @NonNull Options options)
        throws IOException {
    try {
        int sourceSize = getSize(source);
        SVG svg = loadSvg(source, width, height, options);
        SvgUtils.fix(svg);
        int[] sizes = getResourceSize(svg, width, height);
        return new SvgResource(svg, sizes[0], sizes[1], sourceSize);
    } catch (SvgParseException e) {
        throw new IOException("Cannot load SVG", e);
    }
}
 
Example #30
Source File: OkHttpUrlLoader.java    From MVVMArms with Apache License 2.0 4 votes vote down vote up
@Override
public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height,
                                           Options options) {
    return new LoadData<>(model, new OkHttpStreamFetcher(client, model));
}