All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bumptech.glide.manager.TargetTracker Maven / Gradle / Ivy

Go to download

A fast and efficient image loading library for Android focused on smooth scrolling.

There is a newer version: 5.0.0-rc01
Show newest version
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();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy