Skip to content

Commit

Permalink
Create a CustomViewTarget to replace ViewTarget.
Browse files Browse the repository at this point in the history
The two main differences are:
- It forces you to override the method where resources must be cleared. Not doing so results in recycled bitmaps being used and crashing apps. Not doing so was a common pattern among developers optimizing for lines of code instead of correctness.
- No more setTag(object) use. Glide now targets 14+ which can safely use the id tag variant and avoid another class of runtime bugs caused by developers optimizing for lines of code instead of correctness by calling setTag() and overwriting Glide's data.

Finally, we deprecate ViewTarget, SimpleTarget and BaseTarget. Apps should primarily be using Target, CustomViewTarget, ImageViewTarget and FutureTarget which either force the developer to implement all necessary methods, properly implement them themselves, or will not attempt to reclaim bitmaps. The deprecated classes continue to be used internally by some of the "correct" classes but can be merged down once the deprecated APIs are able to be removed.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=201729878
  • Loading branch information
AlexanderGH authored and sjudd committed Jul 30, 2018
1 parent b7c2b13 commit 3a70607
Show file tree
Hide file tree
Showing 9 changed files with 1,222 additions and 37 deletions.
5 changes: 3 additions & 2 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.bumptech.glide">

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bumptech.glide">
<uses-sdk android:minSdkVersion="14" />
<application/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@
* A base {@link Target} for loading {@link com.bumptech.glide.load.engine.Resource}s that provides
* basic or empty implementations for most methods.
*
* <p> For maximum efficiency, clear this target when you have finished using or displaying the
* {@link com.bumptech.glide.load.engine.Resource} loaded into it using
* {@link com.bumptech.glide.RequestManager#clear(Target)}.</p>
* <p>For maximum efficiency, clear this target when you have finished using or displaying the
* {@link com.bumptech.glide.load.engine.Resource} loaded into it using {@link
* com.bumptech.glide.RequestManager#clear(Target)}.
*
* <p> For loading {@link com.bumptech.glide.load.engine.Resource}s into {@link android.view.View}s,
* {@link com.bumptech.glide.request.target.ViewTarget} or
* {@link com.bumptech.glide.request.target.ImageViewTarget} are preferable.</p>
* <p>For loading {@link com.bumptech.glide.load.engine.Resource}s into {@link android.view.View}s,
* {@link com.bumptech.glide.request.target.ViewTarget} or {@link
* com.bumptech.glide.request.target.ImageViewTarget} are preferable.
*
* @param <Z> The type of resource that will be received by this target.
* @deprecated Use {@link CustomViewTarget} if loading the content into a view, the download API if
* in the background
* (http://bumptech.github.io/glide/doc/getting-started.html#background-threads), or a a fully
* implemented {@link Target} for any specialized use-cases. Using BaseView is unsafe if the
* user does not implement {@link #onLoadCleared}, resulting in recycled bitmaps being
* referenced from the UI and hard to root-cause crashes.
*/
@Deprecated
public abstract class BaseTarget<Z> implements Target<Z> {

private Request request;
Expand Down
Loading

0 comments on commit 3a70607

Please sign in to comment.