本文整理汇总了Java中com.bumptech.glide.load.resource.gif.GifDrawable类的典型用法代码示例。如果您正苦于以下问题:Java GifDrawable类的具体用法?Java GifDrawable怎么用?Java GifDrawable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GifDrawable类属于com.bumptech.glide.load.resource.gif包,在下文中一共展示了GifDrawable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transform
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
private RequestOptions transform(
@NonNull Transformation<Bitmap> transformation, boolean isRequired) {
if (isAutoCloneEnabled) {
return clone().transform(transformation, isRequired);
}
DrawableTransformation drawableTransformation =
new DrawableTransformation(transformation, isRequired);
transform(Bitmap.class, transformation, isRequired);
transform(Drawable.class, drawableTransformation, isRequired);
// TODO: remove BitmapDrawable decoder and this transformation.
// Registering as BitmapDrawable is simply an optimization to avoid some iteration and
// isAssignableFrom checks when obtaining the transformation later on. It can be removed without
// affecting the functionality.
transform(BitmapDrawable.class, drawableTransformation.asBitmapDrawable(), isRequired);
transform(GifDrawable.class, new GifDrawableTransformation(transformation), isRequired);
return selfOrThrowIfLocked();
}
示例2: onResourceReady
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@Override
public void onResourceReady(Drawable resource, @Nullable Transition<? super Drawable> transition) {
super.onResourceReady(resource, transition);
BadgedFourThreeImageView badgedImageView = (BadgedFourThreeImageView) getView();
if (resource instanceof GifDrawable) {
Bitmap image = ((GifDrawable) resource).getFirstFrame();
if (image != null) {
// look at the corner to determine the gif badge color
int cornerSize = (int) (56 * getView().getContext().getResources().getDisplayMetrics
().scaledDensity);
Bitmap corner = Bitmap.createBitmap(image,
image.getWidth() - cornerSize,
image.getHeight() - cornerSize,
cornerSize, cornerSize);
boolean isDark = ColorUtils.isDark(corner);
corner.recycle();
badgedImageView.setBadgeColor(ContextCompat.getColor(getView().getContext(),
isDark ? R.color.gif_badge_dark_image : R.color.gif_badge_light_image));
} else {
badgedImageView.setBadgeColor(ContextCompat.getColor(getView().getContext(),
R.color.gif_badge_light_image));
}
}
}
示例3: getData
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@Override
public void getData() {
swipeRefreshLayout.setRefreshing(true);
if (url.contains("gif") && !url.contains("large")) {
url = Parse.parseImageUrl(url, 0);
}
list.clear();
list.add(getString(R.string.save));
if (!url.contains("large")) {
list.add(getString(R.string.view_original_image));
}
alertDialog = new AlertDialog.Builder(this)
.setTitle(R.string.option)
.setItems(list.toArray(new String[list.size()]), this).create();
LogUtils.d("Load image: " + url);
if (url.contains("gif")) {
Glide.with(this).asGif().load(url).into(new ImageViewTarget<GifDrawable>());
} else {
Glide.with(this).load(url).into(new ImageViewTarget<>());
}
}
示例4: getShareIntentForImage
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@Nullable
private Intent getShareIntentForImage(String sharingText) {
File cachedImage = null;
if (mImageResource instanceof GlideBitmapDrawable) {
cachedImage = getCachedBitmap(((GlideBitmapDrawable) mImageResource).getBitmap());
} else if (mImageResource instanceof GifDrawable) {
cachedImage = getCachedGif((GifDrawable) mImageResource);
}
if (cachedImage != null) {
Uri sharedUri = StreamProvider.getUriForFile("derpibooru.derpy.ui.ImageActivity", cachedImage);
if (sharedUri != null) {
return new Intent()
.setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_SUBJECT, sharingText)
.putExtra(Intent.EXTRA_STREAM, sharedUri)
.setDataAndType(sharedUri, mContext.getContentResolver().getType(sharedUri))
.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
return null;
}
示例5: getCachedGif
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@Nullable
private File getCachedGif(GifDrawable gifDrawable) {
try {
File cacheDir = getImageCacheDir();
if (cacheDir == null) {
throw new IOException("cache directory does not exist.");
}
if (gifDrawable.getData().length >= GIF_FILE_SIZE_LIMIT_BYTES) {
return getCachedBitmap(gifDrawable.getFirstFrame());
} else {
FileOutputStream stream = new FileOutputStream(cacheDir + SLASH_TEMP_GIF_FILE_NAME);
stream.write(gifDrawable.getData());
stream.close();
return new File(cacheDir + SLASH_TEMP_GIF_FILE_NAME);
}
} catch (IOException e) {
Log.e("ImageShare", "getCachedGif", e);
}
return null;
}
示例6: onResourceReady
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@Override public boolean onResourceReady(TranscodeType resource, Object model, Target<TranscodeType> target, DataSource dataSource, boolean isFirstResource) {
boolean callbackResult = this.callback != null && this.callback.onResourceReady(resource, model, target, dataSource, isFirstResource);
Bitmap b = null;
if (resource instanceof BitmapDrawable) {
b = ((BitmapDrawable) resource).getBitmap();
} else if (resource instanceof GifDrawable) {
b = ((GifDrawable) resource).getFirstFrame();
} else if (target instanceof BitmapHolder) {
b = ((BitmapHolder) target).getBitmap();
}
if (b != null) {
start(b);
}
return callbackResult;
}
示例7: encode
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@Override
public boolean encode(Resource<GifDrawable> resource, File file, Options options) {
GifDrawable drawable = resource.get();
Transformation<Bitmap> transformation = drawable.getFrameTransformation();
boolean isTransformed = !(transformation instanceof UnitTransformation);
if (isTransformed && options.get(ENCODE_TRANSFORMATION)) {
return encodeTransformedToFile(drawable, file);
} else {
return writeDataDirect(drawable.getBuffer(), file);
}
}
示例8: encodeTransformedToStream
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
private boolean encodeTransformedToStream(GifDrawable drawable, OutputStream os) {
Transformation<Bitmap> transformation = drawable.getFrameTransformation();
GifDecoder decoder = decodeHeaders(drawable.getBuffer());
AnimatedGifEncoder encoder = factory.buildEncoder();
if (!encoder.start(os)) {
return false;
}
for (int i = 0; i < decoder.getFrameCount(); i++) {
Bitmap currentFrame = decoder.getNextFrame();
Resource<Bitmap> transformedResource =
getTransformedFrame(currentFrame, transformation, drawable);
try {
if (!encoder.addFrame(transformedResource.get())) {
return false;
}
int currentFrameIndex = decoder.getCurrentFrameIndex();
int delay = decoder.getDelay(currentFrameIndex);
encoder.setDelay(delay);
decoder.advance();
} finally {
transformedResource.recycle();
}
}
return encoder.finish();
}
示例9: getTransformedFrame
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
private Resource<Bitmap> getTransformedFrame(Bitmap currentFrame,
Transformation<Bitmap> transformation, GifDrawable drawable) {
// TODO: what if current frame is null?
Resource<Bitmap> bitmapResource = factory.buildFrameResource(currentFrame, bitmapPool);
Resource<Bitmap> transformedResource =
transformation.transform(
context, bitmapResource, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
if (!bitmapResource.equals(transformedResource)) {
bitmapResource.recycle();
}
return transformedResource;
}
示例10: initialize
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@Override
public void initialize() {
if (drawable instanceof BitmapDrawable) {
((BitmapDrawable) drawable).getBitmap().prepareToDraw();
} else if (drawable instanceof GifDrawable) {
((GifDrawable) drawable).getFirstFrame().prepareToDraw();
}
}
示例11: testReceivesGif
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@Test
public void testReceivesGif() throws IOException {
String fakeUri = "content://fake";
InputStream testGifData = openResource("test.gif");
mockUri(Uri.parse(fakeUri), testGifData);
requestManager.asGif().load(fakeUri).into(target);
verify(target).onResourceReady(isA(GifDrawable.class), isA(Transition.class));
}
示例12: testReceivesGifBytes
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@Test
public void testReceivesGifBytes() throws IOException {
String fakeUri = "content://fake";
InputStream testGifData = openResource("test.gif");
mockUri(Uri.parse(fakeUri), testGifData);
requestManager.as(byte[].class).apply(decodeTypeOf(GifDrawable.class)).load(fakeUri)
.into(target);
verify(target).onResourceReady(isA(byte[].class), isA(Transition.class));
}
示例13: testReturnsNewDrawableOnGet
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@Test
public void testReturnsNewDrawableOnGet() {
GifDrawable expected = mock(GifDrawable.class);
Drawable.ConstantState constantState = mock(Drawable.ConstantState.class);
when(constantState.newDrawable()).thenReturn(expected);
when(drawable.getConstantState()).thenReturn(constantState);
assertEquals(expected, resource.get());
verify(drawable).getConstantState();
verify(constantState).newDrawable();
}
示例14: setUp
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@Before
public void setUp() {
gifDrawable = mock(GifDrawable.class);
resource = mockResource();
when(resource.get()).thenReturn(gifDrawable);
transcoder = new GifDrawableBytesTranscoder();
}
示例15: getPreloadRequestBuilder
import com.bumptech.glide.load.resource.gif.GifDrawable; //导入依赖的package包/类
@NonNull
@Override
public RequestBuilder<GifDrawable> getPreloadRequestBuilder(MediaStoreData item) {
MediaStoreSignature signature =
new MediaStoreSignature(item.mimeType, item.dateModified, item.orientation);
return requestBuilder
.clone()
.signature(signature)
.load(item.uri);
}