diff options
author | Brian Attwell <brianattwell@google.com> | 2014-07-21 23:39:35 -0700 |
---|---|---|
committer | Brian Attwell <brianattwell@google.com> | 2014-07-23 18:01:58 +0000 |
commit | c3f21a33fa554f683ddbe6d9553d1b3bd9a4fd29 (patch) | |
tree | d584051637f9a13e8543d0b81b2ab52c4f6a8df6 /src/com/android/contacts/common/ContactPhotoManager.java | |
parent | 4d0ec405721176fcbf4c70bade5d34da68d523c3 (diff) | |
download | android_packages_apps_ContactsCommon-c3f21a33fa554f683ddbe6d9553d1b3bd9a4fd29.tar.gz android_packages_apps_ContactsCommon-c3f21a33fa554f683ddbe6d9553d1b3bd9a4fd29.tar.bz2 android_packages_apps_ContactsCommon-c3f21a33fa554f683ddbe6d9553d1b3bd9a4fd29.zip |
Only kill image requests from the one fragment
In ContractEntryListAdapter#changeCursor(), don't kill all image loading
requests app wide. Instead, only kill the image loading requests that
were associated with the adapter's fragment.
Bug: 15522504
Change-Id: Ib4e0448217e8bbb8df55e74649a013e0f1688a22
Diffstat (limited to 'src/com/android/contacts/common/ContactPhotoManager.java')
-rw-r--r-- | src/com/android/contacts/common/ContactPhotoManager.java | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/com/android/contacts/common/ContactPhotoManager.java b/src/com/android/contacts/common/ContactPhotoManager.java index 213a7a22..24b96e29 100644 --- a/src/com/android/contacts/common/ContactPhotoManager.java +++ b/src/com/android/contacts/common/ContactPhotoManager.java @@ -49,6 +49,8 @@ import android.support.v4.graphics.drawable.RoundedBitmapDrawable; import android.text.TextUtils; import android.util.Log; import android.util.LruCache; +import android.view.View; +import android.view.ViewGroup; import android.widget.ImageView; import com.android.contacts.common.lettertiles.LetterTileDrawable; @@ -513,7 +515,7 @@ public abstract class ContactPhotoManager implements ComponentCallbacks2 { /** * Cancels all pending requests to load photos asynchronously. */ - public abstract void cancelPendingRequests(); + public abstract void cancelPendingRequests(View fragmentRootView); /** * Temporarily stops loading photos from the database. @@ -843,11 +845,30 @@ class ContactPhotoManagerImpl extends ContactPhotoManager implements Callback { /** - * Cancels all pending requests to load photos asynchronously. + * Cancels pending requests to load photos asynchronously for views inside + * {@param fragmentRootView}. If {@param fragmentRootView} is null, cancels all requests. */ @Override - public void cancelPendingRequests() { - mPendingRequests.clear(); + public void cancelPendingRequests(View fragmentRootView) { + if (fragmentRootView == null) { + mPendingRequests.clear(); + return; + } + ImageView[] requestSetCopy = mPendingRequests.keySet().toArray(new ImageView[ + mPendingRequests.size()]); + for (ImageView imageView : requestSetCopy) { + // If an ImageView is orphaned (currently scrap) or a child of fragmentRootView, then + // we can safely remove its request. + if (imageView.getParent() == null || isChildView(fragmentRootView, imageView)) { + mPendingRequests.remove(imageView); + } + } + } + + private static boolean isChildView(View parent, View potentialChild) { + return potentialChild.getParent() != null && (potentialChild.getParent() == parent || ( + potentialChild.getParent() instanceof ViewGroup && isChildView(parent, + (ViewGroup) potentialChild.getParent()))); } @Override |