com.bumptech.glide.manager.TargetTracker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of glide Show documentation
Show all versions of glide Show documentation
A fast and efficient image loading library for Android focused on smooth scrolling.
package com.bumptech.glide.manager;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.util.Util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.WeakHashMap;
/**
* Holds the set of {@link Target}s currently active for a
* {@link com.bumptech.glide.RequestManager} and forwards on lifecycle events.
*/
public final class TargetTracker implements LifecycleListener {
private final Set> targets =
Collections.newSetFromMap(new WeakHashMap, Boolean>());
public void track(Target> target) {
targets.add(target);
}
public void untrack(Target> target) {
targets.remove(target);
}
@Override
public void onStart() {
for (Target> target : Util.getSnapshot(targets)) {
target.onStart();
}
}
@Override
public void onStop() {
for (Target> target : Util.getSnapshot(targets)) {
target.onStop();
}
}
@Override
public void onDestroy() {
for (Target> target : Util.getSnapshot(targets)) {
target.onDestroy();
}
}
public List> getAll() {
return new ArrayList<>(targets);
}
public void clear() {
targets.clear();
}
}