diff options
author | Chris Wren <cwren@android.com> | 2013-08-13 11:34:30 -0400 |
---|---|---|
committer | Chris Wren <cwren@android.com> | 2013-08-14 09:51:29 -0400 |
commit | c37df74e6a50b5458c360839a75104e4e603a3ca (patch) | |
tree | b1bcde741af4e81ed45cfb5ca35164610c99c0f6 /src | |
parent | 7170112b066301a1fc302a159aa8857a70f83883 (diff) | |
download | android_packages_screensavers_PhotoTable-c37df74e6a50b5458c360839a75104e4e603a3ca.tar.gz android_packages_screensavers_PhotoTable-c37df74e6a50b5458c360839a75104e4e603a3ca.tar.bz2 android_packages_screensavers_PhotoTable-c37df74e6a50b5458c360839a75104e4e603a3ca.zip |
resove some edge cases in background optimization.
don't try to guess where the view is, just remove it from where ever it is.
don't try to track if things are animating, just add them to the background at the next convenient time.
Bug: 10048162
Change-Id: Icad3dfe8de95ab57790d201a637f1938af3aa79a
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dreams/phototable/PhotoTable.java | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/src/com/android/dreams/phototable/PhotoTable.java b/src/com/android/dreams/phototable/PhotoTable.java index 2837309..1ba95b9 100644 --- a/src/com/android/dreams/phototable/PhotoTable.java +++ b/src/com/android/dreams/phototable/PhotoTable.java @@ -34,6 +34,7 @@ import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; import android.view.ViewPropertyAnimator; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; @@ -44,7 +45,6 @@ import java.util.ArrayList; import java.util.Formatter; import java.util.HashSet; import java.util.LinkedList; -import java.util.List; import java.util.Random; import java.util.Set; @@ -109,8 +109,6 @@ public class PhotoTable extends FrameLayout { private final long mPickUpDuration; private final int mMaxSelectionTime; private final int mMaxFocusTime; - private final List<View> mAnimating; - private DreamService mDream; private PhotoLaunchTask mPhotoLaunchTask; private LoadNaturalSiblingTask mLoadOnDeckTasks[]; @@ -127,6 +125,7 @@ public class PhotoTable extends FrameLayout { private ViewGroup mBackground; private ViewGroup mStageLeft; private View mScrim; + private final Set<View> mWaitingToJoinBackground; public PhotoTable(Context context, AttributeSet as) { super(context, as); @@ -157,7 +156,7 @@ public class PhotoTable extends FrameLayout { mOnTable = new LinkedList<View>(); mPhotoSource = new PhotoSourcePlexor(getContext(), getContext().getSharedPreferences(PhotoTableDreamSettings.PREFS_NAME, 0)); - mAnimating = new ArrayList<View>(); + mWaitingToJoinBackground = new HashSet<View>(); mLauncher = new Launcher(); mFocusReaper = new FocusReaper(); mSelectionReaper = new SelectionReaper(); @@ -607,6 +606,7 @@ public class PhotoTable extends FrameLayout { /** De-emphasize the other photos on the table. */ public void fadeOutBackground(final View photo) { + resolveBackgroundQueue(); if (mBackgroudOptimization) { mBackground.animate() .withLayer() @@ -628,7 +628,7 @@ public class PhotoTable extends FrameLayout { /** Return the other photos to foreground status. */ public void fadeInBackground(final View photo) { if (mBackgroudOptimization) { - mAnimating.add(photo); + mWaitingToJoinBackground.add(photo); mBackground.animate() .withLayer() .setDuration(mPickUpDuration) @@ -636,10 +636,7 @@ public class PhotoTable extends FrameLayout { .withEndAction(new Runnable() { @Override public void run() { - mAnimating.remove(photo); - if (!mAnimating.contains(photo)) { - moveToBackground(photo); - } + resolveBackgroundQueue(); } }); } else { @@ -658,6 +655,13 @@ public class PhotoTable extends FrameLayout { } } + private void resolveBackgroundQueue() { + for(View photo: mWaitingToJoinBackground) { + moveToBackground(photo); + } + mWaitingToJoinBackground.clear(); + } + /** Dispose of the photo gracefully, in case we can see some of it. */ public void fadeAway(final View photo, final boolean replace) { // fade out of view @@ -854,7 +858,7 @@ public class PhotoTable extends FrameLayout { log("animate it"); // toss onto table - mAnimating.add(photo); + resolveBackgroundQueue(); photo.animate() .withLayer() .scaleX(mTableRatio / mImageRatio) @@ -867,32 +871,32 @@ public class PhotoTable extends FrameLayout { .withEndAction(new Runnable() { @Override public void run() { - mAnimating.remove(photo); - if (!mAnimating.contains(photo)) { - moveToBackground(photo); - } + mWaitingToJoinBackground.add(photo); } }); } private void moveToBackground(View photo) { if (mBackgroudOptimization && !isInBackground(photo)) { - removeView(photo); + removeViewFromParent(photo); mBackground.addView(photo, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); } } private void exitStageLeft(View photo) { - if (isInBackground(photo)) { - mBackground.removeView(photo); - } else { - removeView(photo); - } + removeViewFromParent(photo); mStageLeft.addView(photo, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); } + private void removeViewFromParent(View photo) { + ViewParent parent = photo.getParent(); + if (parent != null) { // should never be null, just being paranoid + ((ViewGroup) parent).removeView(photo); + } + } + private void moveToForeground(View photo) { if (mBackgroudOptimization && isInBackground(photo)) { mBackground.removeView(photo); @@ -929,6 +933,7 @@ public class PhotoTable extends FrameLayout { log("animate it"); // lift up to the glass for a good look + mWaitingToJoinBackground.remove(photo); moveToForeground(photo); photo.animate() .withLayer() @@ -967,7 +972,7 @@ public class PhotoTable extends FrameLayout { private void recycle(View photo) { if (photo != null) { - removeView(photo); + removeViewFromParent(photo); mPhotoSource.recycle(getBitmap(photo)); } } |