@Override public Drawable getCurrent() { return wrapped.getCurrent(); }
@Override public void setLoopCount(int loopCount) { wrapped.setLoopCount(loopCount); }
@Override public void onStart() { if (resource != null) { resource.start(); } }
/** * {@inheritDoc} * If no {@link GlideAnimation} is given or if the animation does not set the * {@link android.graphics.drawable.Drawable} on the view, the drawable is set using * {@link ImageView#setImageDrawable(android.graphics.drawable.Drawable)}. * * @param resource {@inheritDoc} * @param animation {@inheritDoc} */ @Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) { if (!resource.isAnimated()) { //TODO: Try to generalize this to other sizes/shapes. // This is a dirty hack that tries to make loading square thumbnails and then square full images less costly // by forcing both the smaller thumb and the larger version to have exactly the same intrinsic dimensions. // If a drawable is replaced in an ImageView by another drawable with different intrinsic dimensions, // the ImageView requests a layout. Scrolling rapidly while replacing thumbs with larger images triggers // lots of these calls and causes significant amounts of jank. float viewRatio = view.getWidth() / (float) view.getHeight(); float drawableRatio = resource.getIntrinsicWidth() / (float) resource.getIntrinsicHeight(); if (Math.abs(viewRatio - 1f) <= SQUARE_RATIO_MARGIN && Math.abs(drawableRatio - 1f) <= SQUARE_RATIO_MARGIN) { resource = new SquaringDrawable(resource, view.getWidth()); } } super.onResourceReady(resource, animation); this.resource = resource; resource.setLoopCount(maxLoopCount); resource.start(); }
@Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { this.mResource = resource; setDrawable(resource); resource.setLoopCount(GlideDrawable.LOOP_FOREVER); resource.start(); }
@Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) { super.onResourceReady(resource, animation); if (!autoplayGifs) { resource.stop(); } BadgedFourThreeImageView badgedImageView = (BadgedFourThreeImageView) getView(); if (resource instanceof GlideBitmapDrawable) { Palette.from(((GlideBitmapDrawable) resource).getBitmap()) .clearFilters() .generate(this); } else if (resource instanceof GifDrawable) { Bitmap image = ((GifDrawable) resource).getFirstFrame(); Palette.from(image).clearFilters().generate(this); // 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)); } }
@Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { listener.onResourceReady(resource.getIntrinsicWidth(), resource.getIntrinsicHeight()); return false; } }).into(imageView);
@Override public int getOpacity() { if (mDrawable != null) { return mDrawable.getOpacity(); } return 0; }
@Override public void draw(Canvas canvas) { if (mDrawable != null) { mDrawable.draw(canvas); } }
@Override public void setAlpha(int alpha) { if (mDrawable != null) { mDrawable.setAlpha(alpha); } }
@Override public boolean isAnimated() { return wrapped.isAnimated(); }
@Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { Rect rect; if (resource.getIntrinsicWidth() > 100) { float width; float height; Logger.i("Image width is " + resource.getIntrinsicWidth()); Logger.i("View width is " + view.getWidth()); if (resource.getIntrinsicWidth() >= getView().getWidth()) { float downScale = (float) resource.getIntrinsicWidth() / getView().getWidth(); width = (float) resource.getIntrinsicWidth() / (float) downScale; height = (float) resource.getIntrinsicHeight() / (float) downScale; } else { float multiplier = (float) getView().getWidth() / resource.getIntrinsicWidth(); width = (float) resource.getIntrinsicWidth() * (float) multiplier; height = (float) resource.getIntrinsicHeight() * (float) multiplier; rect = new Rect(0, 0, resource.getIntrinsicWidth() * 2, resource.getIntrinsicHeight() * 2); resource.setBounds(rect); if (resource.isAnimated()) { mDrawable.setCallback(get(getView())); resource.setLoopCount(GlideDrawable.LOOP_FOREVER); resource.start();
@Override public void onResourceReady(GlideDrawable glideDrawable, GlideAnimation glideAnimation) { // start GlideDrawable, even if it's not animated (these methods are No-op in that case) glideDrawable.setLoopCount(GlideDrawable.LOOP_FOREVER); glideDrawable.start(); setDrawable(glideDrawable); }
@Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) { super.onResourceReady(resource, animation); if (!autoplayGifs) { resource.stop(); } BadgedFourThreeImageView badgedImageView = (BadgedFourThreeImageView) getView(); if (resource instanceof GlideBitmapDrawable) { Palette.from(((GlideBitmapDrawable) resource).getBitmap()) .clearFilters() .generate(this); } else if (resource instanceof GifDrawable) { Bitmap image = ((GifDrawable) resource).getFirstFrame(); Palette.from(image).clearFilters().generate(this); // 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)); } }
@Override public int getOpacity() { return wrapped.getOpacity(); }
@Override public void draw(Canvas canvas) { wrapped.draw(canvas); }
@Override public void setAlpha(int i) { wrapped.setAlpha(i); }
@Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { Bitmap bitmap = ((GlideBitmapDrawable) resource.getCurrent()).getBitmap(); changeUIColors(bitmap); return false; } })
@Override public void start() { wrapped.start(); }
@Override public void onStop() { if (resource != null) { resource.stop(); } } }