{"action":"created","issue":{"url":"https://api.github.com/repos/bumptech/glide/issues/840","labels_url":"https://api.github.com/repos/bumptech/glide/issues/840/labels{/name}","comments_url":"https://api.github.com/repos/bumptech/glide/issues/840/comments","events_url":"https://api.github.com/repos/bumptech/glide/issues/840/events","html_url":"https://github.com/bumptech/glide/issues/840","id":123885584,"number":840,"title":"Change format for specific loads and still get transition drawable","user":{"login":"eicm","id":4117330,"avatar_url":"https://avatars.githubusercontent.com/u/4117330?v=3","gravatar_id":"","url":"https://api.github.com/users/eicm","html_url":"https://github.com/eicm","followers_url":"https://api.github.com/users/eicm/followers","following_url":"https://api.github.com/users/eicm/following{/other_user}","gists_url":"https://api.github.com/users/eicm/gists{/gist_id}","starred_url":"https://api.github.com/users/eicm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eicm/subscriptions","organizations_url":"https://api.github.com/users/eicm/orgs","repos_url":"https://api.github.com/users/eicm/repos","events_url":"https://api.github.com/users/eicm/events{/privacy}","received_events_url":"https://api.github.com/users/eicm/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bumptech/glide/labels/enhancement","name":"enhancement","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-25T15:04:08Z","updated_at":"2015-12-26T13:53:07Z","closed_at":null,"body":"Is it possible to change the load format between ARGB and RGB_565 for specific loads and still load a drawable to get the transition effect between thumbnail and actual image?"},"comment":{"url":"https://api.github.com/repos/bumptech/glide/issues/comments/167326465","html_url":"https://github.com/bumptech/glide/issues/840#issuecomment-167326465","issue_url":"https://api.github.com/repos/bumptech/glide/issues/840","id":167326465,"user":{"login":"TWiStErRob","id":2906988,"avatar_url":"https://avatars.githubusercontent.com/u/2906988?v=3","gravatar_id":"","url":"https://api.github.com/users/TWiStErRob","html_url":"https://github.com/TWiStErRob","followers_url":"https://api.github.com/users/TWiStErRob/followers","following_url":"https://api.github.com/users/TWiStErRob/following{/other_user}","gists_url":"https://api.github.com/users/TWiStErRob/gists{/gist_id}","starred_url":"https://api.github.com/users/TWiStErRob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TWiStErRob/subscriptions","organizations_url":"https://api.github.com/users/TWiStErRob/orgs","repos_url":"https://api.github.com/users/TWiStErRob/repos","events_url":"https://api.github.com/users/TWiStErRob/events{/privacy}","received_events_url":"https://api.github.com/users/TWiStErRob/received_events","type":"User","site_admin":false},"created_at":"2015-12-26T13:53:07Z","updated_at":"2015-12-26T13:53:07Z","body":"The heart of all is a custom factory:\r\n```java\r\nprivate static final GlideAnimationFactory<Bitmap> CROSS_FADE_FACTORY = new GlideAnimationFactory<Bitmap>() {\r\n    private final GlideAnimationFactory<Drawable> realFactory = new DrawableCrossFadeFactory<>();\r\n    @Override public GlideAnimation<Bitmap> build(boolean isFromMemoryCache, boolean isFirstResource) {\r\n        @SuppressWarnings(\"unchecked\")\r\n        final GlideAnimation<Drawable> transition = realFactory.build(isFromMemoryCache, isFirstResource);\r\n        return new GlideAnimation<Bitmap>() {\r\n            @Override public boolean animate(Bitmap current, ViewAdapter adapter) {\r\n                Resources resources = adapter.getView().getResources();\r\n                Drawable currentBitmap = new BitmapDrawable(resources, current);\r\n                return transition.animate(currentBitmap, adapter);\r\n            }\r\n        };\r\n    }\r\n};\r\n```\r\nThis can be exploded into several classes and `realFactory` can be anything, most notably `DrawableCrossFadeFactory` has several constructor overloads.\r\n\r\nAssuming you have something like this (you'll see later why I extracted the local variable):\r\n```java\r\nBitmapRequestBuilder<String, Bitmap> request = Glide\r\n    .with(context)\r\n    .load(fullUrl)\r\n    .asBitmap()\r\n    .format(DecodeFormat.PREFER_ARGB_8888)\r\n    .thumbnail(Glide\r\n        .with(context)\r\n        .load(thumbUrl)\r\n        .asBitmap()\r\n    )\r\n;\r\n```\r\nyou have two options, both of them are weird because `GenericRequestBuilder.animate(GlideAnimationFactory)` is package private.\r\n@sjudd I think it could be made public in 3.7.0 if ever released since v4 already made it public. Also let's use this issue to track the addition of built-in crossFade for `asBitmap()`.\r\n\r\n### The proper\r\n... yet ugly: I don't like listeners to do stuff, though they were designed that way.\r\n\r\n```java\r\nrequest\r\n    .dontAnimate() // turn off defaults since we're handling it\r\n    .listener(new BitmapCrossfadeListener())\r\n    .into(imageView)\r\n;\r\n```\r\n```java\r\npublic class BitmapCrossfadeListener implements RequestListener<String, Bitmap> {\r\n    // CROSS_FADE_FACTORY here\r\n    @Override public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {\r\n        return false;\r\n    }\r\n    @Override public boolean onResourceReady(Bitmap resource, String model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {\r\n        return CROSS_FADE_FACTORY\r\n            .build(isFromMemoryCache, isFirstResource)\r\n            .animate(resource, (ViewAdapter)target)\r\n            ;\r\n    }\r\n}\r\n```\r\n\r\n### The hacky\r\nEquivalent to calling `request.animate(CROSS_FADE_FACTORY).into(imageView)` if it was public.\r\n```java\r\nGlideRequestBuilderAccessor.animate(request, CROSS_FADE_FACTORY);\r\nrequest.into(imageView);\r\n```\r\n```java\r\npackage com.bumptech.glide;\r\npublic class GlideRequestBuilderAccessor {\r\n    public static <T> void animate(GenericRequestBuilder<?, ?, ?, T> request, GlideAnimationFactory<T> factory) {\r\n        request.animate(factory);\r\n    }\r\n}\r\n```\r\nor, depending on your preferred style an alternative:\r\n\r\n```java\r\nGlideRequestBuilderAccessor.animate(request, CROSS_FADE_FACTORY).into(imageView);\r\n\r\npublic static <ModelType, DataType, ResourceType, TranscodeType>\r\nGenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeType> animate(\r\n        GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeType> request,\r\n        GlideAnimationFactory<TranscodeType> factory\r\n    ) {\r\n    return request.animate(factory);\r\n}\r\n```"}}