类com.bumptech.glide.load.Options源码实例Demo

下面列出了怎么用com.bumptech.glide.load.Options的API类实例代码及写法,或者点击链接到github查看源代码。

@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;
  }
}
 
源代码2 项目: mollyim-android   文件: EncryptedCacheEncoder.java
@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);
  }
}
 
@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;
    }
}
 
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);
    }
}
 
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;
  }
}
 
@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;
  }
}
 
@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);
  }
}
 
@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;
  }
}
 
@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);
  }
}
 
@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;
  }
}
 
源代码11 项目: mollyim-android   文件: BlurHashModelLoader.java
@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));
}
 
源代码12 项目: mollyim-android   文件: BlurHashResourceDecoder.java
@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));
}
 
源代码13 项目: APNG4Android   文件: ByteBufferAnimationDecoder.java
@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();
        }
    };
}
 
源代码14 项目: APNG4Android   文件: StreamAnimationDecoder.java
@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);
}
 
源代码15 项目: GlideToVectorYou   文件: SvgDecoder.java
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);
  }
}
 
源代码16 项目: GlideToVectorYou   文件: SvgDrawableTranscoder.java
@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);
}
 
源代码17 项目: MusicPlayer   文件: BitmapPaletteTranscoder.java
@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);
}
 
源代码18 项目: MusicPlayer   文件: ArtistImageFetcher.java
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;
}
 
源代码19 项目: MusicPlayer   文件: ArtistImageLoader.java
@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));
    }
 
源代码20 项目: SvgGlidePlugins   文件: ByteBufferSvgDecoder.java
@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);
    }
}
 
源代码21 项目: SvgGlidePlugins   文件: SvgDecoder.java
@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);
    }
}
 
源代码22 项目: SvgGlidePlugins   文件: InputStreamSvgDecoder.java
@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);
    }
}
 
源代码23 项目: SvgGlidePlugins   文件: FileSvgDecoder.java
@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);
    }
}
 
源代码24 项目: SvgGlidePlugins   文件: RawResourceSvgDecoder.java
@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);
    }
}
 
源代码25 项目: SvgGlidePlugins   文件: StringSvgDecoder.java
@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);
    }
}
 
@Override
SVG loadSvg(
        @NonNull ParcelFileDescriptor source,
        int width,
        int height,
        @NonNull Options options
) throws SvgParseException {
    return mDecoder.loadSvg(source.getFileDescriptor(), width, height, options);
}
 
源代码27 项目: SvgGlidePlugins   文件: FileDescriptorSvgDecoder.java
@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);
    }
}
 
@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));
}
 
源代码29 项目: FirebaseUI-Android   文件: FirebaseImageLoader.java
@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));
}
 
源代码30 项目: mollyim-android   文件: StickerRemoteUriLoader.java
@Override
public @NonNull LoadData<InputStream> buildLoadData(@NonNull StickerRemoteUri sticker, int width, int height, @NonNull Options options) {
  return new LoadData<>(sticker, new StickerRemoteUriFetcher(receiver, sticker));
}
 
 类所在包
 类方法
 同包方法