Move inner classes out of FolderIcon.
The goal is to eventually move all of the PreviewBackground and
Preview Item drawing out of the FolderIcon class.
Bug: 36022592
Change-Id: Ie0552bb4ca8a7e232c1c454a23558940e9394a14
diff --git a/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java b/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java
index 33bf275..ff357c0 100644
--- a/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java
+++ b/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java
@@ -29,8 +29,8 @@
}
@Override
- public FolderIcon.PreviewItemDrawingParams computePreviewItemDrawingParams(int index,
- int curNumItems, FolderIcon.PreviewItemDrawingParams params) {
+ public PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems,
+ PreviewItemDrawingParams params) {
float totalScale = scaleForItem(index, curNumItems);
float transX;
@@ -47,7 +47,7 @@
}
if (params == null) {
- params = new FolderIcon.PreviewItemDrawingParams(transX, transY, totalScale, overlayAlpha);
+ params = new PreviewItemDrawingParams(transX, transY, totalScale, overlayAlpha);
} else {
params.update(transX, transY, totalScale);
params.overlayAlpha = overlayAlpha;
diff --git a/src/com/android/launcher3/folder/FolderAnimationManager.java b/src/com/android/launcher3/folder/FolderAnimationManager.java
index 7e6205a..7adda19 100644
--- a/src/com/android/launcher3/folder/FolderAnimationManager.java
+++ b/src/com/android/launcher3/folder/FolderAnimationManager.java
@@ -71,8 +71,7 @@
private final TimeInterpolator mFolderInterpolator;
private final TimeInterpolator mLargeFolderPreviewItemInterpolator;
- private final FolderIcon.PreviewItemDrawingParams mTmpParams =
- new FolderIcon.PreviewItemDrawingParams(0, 0, 0, 0);
+ private final PreviewItemDrawingParams mTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0);
private static final Property<View, Float> SCALE_PROPERTY =
new Property<View, Float>(Float.class, "scale") {
@@ -344,12 +343,6 @@
: ObjectAnimator.ofFloat(view, property, v2, v1);
}
- private Animator getAnimator(List<BubbleTextView> items, Property property, int v1, int v2) {
- return mIsOpening
- ? ObjectAnimator.ofArgb(items, property, v1, v2)
- : ObjectAnimator.ofArgb(items, property, v2, v1);
- }
-
private Animator getAnimator(GradientDrawable drawable, String property, int v1, int v2) {
return mIsOpening
? ObjectAnimator.ofArgb(drawable, property, v1, v2)
diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java
index 215a31c..1cc285e 100644
--- a/src/com/android/launcher3/folder/FolderIcon.java
+++ b/src/com/android/launcher3/folder/FolderIcon.java
@@ -19,8 +19,6 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
-import android.animation.ValueAnimator;
-import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;
@@ -227,8 +225,7 @@
}
public boolean acceptDrop(ItemInfo dragInfo) {
- final ItemInfo item = dragInfo;
- return !mFolder.isDestroyed() && willAcceptItem(item);
+ return !mFolder.isDestroyed() && willAcceptItem(dragInfo);
}
public void addItem(ShortcutInfo item) {
@@ -423,39 +420,6 @@
return mBadgeInfo != null && mBadgeInfo.hasBadge();
}
- static class PreviewItemDrawingParams {
- PreviewItemDrawingParams(float transX, float transY, float scale, float overlayAlpha) {
- this.transX = transX;
- this.transY = transY;
- this.scale = scale;
- this.overlayAlpha = overlayAlpha;
- }
-
- public void update(float transX, float transY, float scale) {
- // We ensure the update will not interfere with an animation on the layout params
- // If the final values differ, we cancel the animation.
- if (anim != null) {
- if (anim.finalTransX == transX || anim.finalTransY == transY
- || anim.finalScale == scale) {
- return;
- }
- anim.cancel();
- }
-
- this.transX = transX;
- this.transY = transY;
- this.scale = scale;
- }
-
- float transX;
- float transY;
- float scale;
- public float overlayAlpha;
- boolean hidden;
- FolderPreviewItemAnim anim;
- Drawable drawable;
- }
-
private float getLocalCenterForIndex(int index, int curNumItems, int[] center) {
mTmpParams = computePreviewItemDrawingParams(
Math.min(mPreviewLayoutRule.maxNumItems(), index), curNumItems, mTmpParams);
@@ -465,12 +429,12 @@
float offsetX = mTmpParams.transX + (mTmpParams.scale * mIntrinsicIconSize) / 2;
float offsetY = mTmpParams.transY + (mTmpParams.scale * mIntrinsicIconSize) / 2;
- center[0] = (int) Math.round(offsetX);
- center[1] = (int) Math.round(offsetY);
+ center[0] = Math.round(offsetX);
+ center[1] = Math.round(offsetY);
return mTmpParams.scale;
}
- private PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems,
+ PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems,
PreviewItemDrawingParams params) {
// We use an index of -1 to represent an icon on the workspace for the destroy and
// create animations
@@ -582,89 +546,14 @@
}
}
- class FolderPreviewItemAnim {
- ValueAnimator mValueAnimator;
- float finalScale;
- float finalTransX;
- float finalTransY;
-
- /**
- *
- * @param params layout params to animate
- * @param index0 original index of the item to be animated
- * @param nItems0 original number of items in the preview
- * @param index1 new index of the item to be animated
- * @param nItems1 new number of items in the preview
- * @param duration duration in ms of the animation
- * @param onCompleteRunnable runnable to execute upon animation completion
- */
- public FolderPreviewItemAnim(final PreviewItemDrawingParams params, int index0, int nItems0,
- int index1, int nItems1, int duration, final Runnable onCompleteRunnable) {
-
- computePreviewItemDrawingParams(index1, nItems1, mTmpParams);
-
- finalScale = mTmpParams.scale;
- finalTransX = mTmpParams.transX;
- finalTransY = mTmpParams.transY;
-
- computePreviewItemDrawingParams(index0, nItems0, mTmpParams);
-
- final float scale0 = mTmpParams.scale;
- final float transX0 = mTmpParams.transX;
- final float transY0 = mTmpParams.transY;
-
- mValueAnimator = LauncherAnimUtils.ofFloat(0f, 1.0f);
- mValueAnimator.addUpdateListener(new AnimatorUpdateListener(){
- public void onAnimationUpdate(ValueAnimator animation) {
- float progress = animation.getAnimatedFraction();
-
- params.transX = transX0 + progress * (finalTransX - transX0);
- params.transY = transY0 + progress * (finalTransY - transY0);
- params.scale = scale0 + progress * (finalScale - scale0);
- invalidate();
- }
- });
-
- mValueAnimator.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationStart(Animator animation) {
- }
-
- @Override
- public void onAnimationEnd(Animator animation) {
- if (onCompleteRunnable != null) {
- onCompleteRunnable.run();
- }
- params.anim = null;
- }
- });
- mValueAnimator.setDuration(duration);
- }
-
- public void start() {
- mValueAnimator.start();
- }
-
- public void cancel() {
- mValueAnimator.cancel();
- }
-
- public boolean hasEqualFinalState(FolderPreviewItemAnim anim) {
- return finalTransY == anim.finalTransY && finalTransX == anim.finalTransX &&
- finalScale == anim.finalScale;
-
- }
- }
-
private void animateFirstItem(final Drawable d, int duration, final boolean reverse,
final Runnable onCompleteRunnable) {
-
FolderPreviewItemAnim anim;
if (!reverse) {
- anim = new FolderPreviewItemAnim(mDrawingParams.get(0), -1, -1, 0, 2, duration,
+ anim = new FolderPreviewItemAnim(this, mDrawingParams.get(0), -1, -1, 0, 2, duration,
onCompleteRunnable);
} else {
- anim = new FolderPreviewItemAnim(mDrawingParams.get(0), 0, 2, -1, -1, duration,
+ anim = new FolderPreviewItemAnim(this, mDrawingParams.get(0), 0, 2, -1, -1, duration,
onCompleteRunnable);
}
anim.start();
@@ -740,7 +629,7 @@
mReferenceDrawable = p.drawable;
}
} else {
- FolderPreviewItemAnim anim = new FolderPreviewItemAnim(p, i, prevNumItems, i,
+ FolderPreviewItemAnim anim = new FolderPreviewItemAnim(this, p, i, prevNumItems, i,
nItemsInPreview, DROP_IN_ANIMATION_DURATION, null);
if (p.anim != null) {
@@ -901,7 +790,7 @@
}
}
- public interface PreviewLayoutRule {
+ interface PreviewLayoutRule {
PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems,
PreviewItemDrawingParams params);
void init(int availableSpace, float intrinsicIconSize, boolean rtl);
diff --git a/src/com/android/launcher3/folder/FolderPreviewItemAnim.java b/src/com/android/launcher3/folder/FolderPreviewItemAnim.java
new file mode 100644
index 0000000..0da7c5c
--- /dev/null
+++ b/src/com/android/launcher3/folder/FolderPreviewItemAnim.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.folder;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ValueAnimator;
+
+import com.android.launcher3.LauncherAnimUtils;
+
+/**
+ * Animates a Folder preview item.
+ */
+class FolderPreviewItemAnim {
+ private ValueAnimator mValueAnimator;
+
+ float finalScale;
+ float finalTransX;
+ float finalTransY;
+
+ private PreviewItemDrawingParams mTmpParams = new PreviewItemDrawingParams(0, 0, 0, 0);
+
+ /**
+ * @param folderIcon The FolderIcon this preview will be drawn in.
+ * @param params layout params to animate
+ * @param index0 original index of the item to be animated
+ * @param items0 original number of items in the preview
+ * @param index1 new index of the item to be animated
+ * @param items1 new number of items in the preview
+ * @param duration duration in ms of the animation
+ * @param onCompleteRunnable runnable to execute upon animation completion
+ */
+ FolderPreviewItemAnim(final FolderIcon folderIcon, final PreviewItemDrawingParams params,
+ int index0, int items0, int index1, int items1, int duration,
+ final Runnable onCompleteRunnable) {
+ folderIcon.computePreviewItemDrawingParams(index1, items1, mTmpParams);
+
+ finalScale = mTmpParams.scale;
+ finalTransX = mTmpParams.transX;
+ finalTransY = mTmpParams.transY;
+
+ folderIcon.computePreviewItemDrawingParams(index0, items0, mTmpParams);
+
+ final float scale0 = mTmpParams.scale;
+ final float transX0 = mTmpParams.transX;
+ final float transY0 = mTmpParams.transY;
+
+ mValueAnimator = LauncherAnimUtils.ofFloat(0f, 1.0f);
+ mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener(){
+ public void onAnimationUpdate(ValueAnimator animation) {
+ float progress = animation.getAnimatedFraction();
+
+ params.transX = transX0 + progress * (finalTransX - transX0);
+ params.transY = transY0 + progress * (finalTransY - transY0);
+ params.scale = scale0 + progress * (finalScale - scale0);
+ folderIcon.invalidate();
+ }
+ });
+ mValueAnimator.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ if (onCompleteRunnable != null) {
+ onCompleteRunnable.run();
+ }
+ params.anim = null;
+ }
+ });
+ mValueAnimator.setDuration(duration);
+ }
+
+ public void start() {
+ mValueAnimator.start();
+ }
+
+ public void cancel() {
+ mValueAnimator.cancel();
+ }
+
+ public boolean hasEqualFinalState(FolderPreviewItemAnim anim) {
+ return finalTransY == anim.finalTransY && finalTransX == anim.finalTransX &&
+ finalScale == anim.finalScale;
+
+ }
+}
diff --git a/src/com/android/launcher3/folder/PreviewItemDrawingParams.java b/src/com/android/launcher3/folder/PreviewItemDrawingParams.java
new file mode 100644
index 0000000..607b7ca
--- /dev/null
+++ b/src/com/android/launcher3/folder/PreviewItemDrawingParams.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.folder;
+
+import android.graphics.drawable.Drawable;
+
+/**
+ * Manages the parameters used to draw a Folder preview item.
+ */
+class PreviewItemDrawingParams {
+ float transX;
+ float transY;
+ float scale;
+ float overlayAlpha;
+ FolderPreviewItemAnim anim;
+ public boolean hidden;
+ Drawable drawable;
+
+ PreviewItemDrawingParams(float transX, float transY, float scale, float overlayAlpha) {
+ this.transX = transX;
+ this.transY = transY;
+ this.scale = scale;
+ this.overlayAlpha = overlayAlpha;
+ }
+
+ public void update(float transX, float transY, float scale) {
+ // We ensure the update will not interfere with an animation on the layout params
+ // If the final values differ, we cancel the animation.
+ if (anim != null) {
+ if (anim.finalTransX == transX || anim.finalTransY == transY
+ || anim.finalScale == scale) {
+ return;
+ }
+ anim.cancel();
+ }
+
+ this.transX = transX;
+ this.transY = transY;
+ this.scale = scale;
+ }
+}
diff --git a/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java b/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java
index 1ece278..138dc1c 100644
--- a/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java
+++ b/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java
@@ -16,8 +16,6 @@
package com.android.launcher3.folder;
-import com.android.launcher3.folder.FolderIcon.PreviewItemDrawingParams;
-
public class StackFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule {
static final int MAX_NUM_ITEMS_IN_PREVIEW = 3;