Created
July 31, 2014 23:23
-
-
Save simpleton/d6ba5b084552a2b36c47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private List<WeakReference<IFileDownloader.IFileDownloadCallBack> > callbackList | |
= Collections.synchronizedList(new ArrayList<WeakReference<IFileDownloader.IFileDownloadCallBack>>()); | |
public void addCallback(IFileDownloader.IFileDownloadCallBack cb) { | |
if (cb != null) { | |
for (int i=0; i < callbackList.size(); ++i) { | |
IFileDownloader.IFileDownloadCallBack callback = callbackList.get(i).get(); | |
if (callback == cb) { | |
return; | |
} | |
} | |
callbackList.add(new WeakReference<IFileDownloader.IFileDownloadCallBack>(cb)); | |
} | |
} | |
public void removeCallback(IFileDownloader.IFileDownloadCallBack cb) { | |
if (cb != null) { | |
for (int i=0; i < callbackList.size(); ++i) { | |
IFileDownloader.IFileDownloadCallBack callback = callbackList.get(i).get(); | |
if (callback == null) { | |
callbackList.remove(i--); | |
} else if (callback == cb) { | |
callbackList.remove(i); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment