summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Miranda <jonmiranda@google.com>2017-02-06 15:45:53 -0800
committerJon Miranda <jonmiranda@google.com>2017-02-06 17:31:58 -0800
commit12b616c7d446d3274d16938d8bc37f5dc4bdc211 (patch)
tree4a14c8c2b19d45093b7cc767cbcb63cf92160507
parentdb7b82960a54b85510aaeba2f543b37b4dc59fc8 (diff)
downloadandroid_packages_apps_Trebuchet-12b616c7d446d3274d16938d8bc37f5dc4bdc211.tar.gz
android_packages_apps_Trebuchet-12b616c7d446d3274d16938d8bc37f5dc4bdc211.tar.bz2
android_packages_apps_Trebuchet-12b616c7d446d3274d16938d8bc37f5dc4bdc211.zip
Update PreviewLayoutRule API to prepare for new folder animation.
Also created a new FeatureFlag to start building behind. Bug: 35064148 Change-Id: I4a7d30bf1e1f49f1012eb963695d44d67096a5bc
-rw-r--r--src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java40
-rw-r--r--src/com/android/launcher3/folder/FolderIcon.java17
-rw-r--r--src/com/android/launcher3/folder/StackFolderIconLayoutRule.java22
-rw-r--r--src_config/com/android/launcher3/config/FeatureFlags.java1
4 files changed, 60 insertions, 20 deletions
diff --git a/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java b/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java
index 6ee02f9d7..840fcf5fe 100644
--- a/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java
+++ b/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java
@@ -1,16 +1,17 @@
package com.android.launcher3.folder;
-import android.graphics.Path;
-import android.graphics.Point;
+import android.view.View;
-import com.android.launcher3.DeviceProfile;
-import com.android.launcher3.LauncherAppState;
-import com.android.launcher3.Utilities;
+import com.android.launcher3.config.FeatureFlags;
+
+import java.util.ArrayList;
+import java.util.List;
public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule {
static final int MAX_NUM_ITEMS_IN_PREVIEW = 4;
private static final int MIN_NUM_ITEMS_IN_PREVIEW = 2;
+ private static final int MAX_NUM_ITEMS_PER_ROW = 2;
final float MIN_SCALE = 0.48f;
final float MAX_SCALE = 0.58f;
@@ -38,7 +39,7 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule
public FolderIcon.PreviewItemDrawingParams computePreviewItemDrawingParams(int index,
int curNumItems, FolderIcon.PreviewItemDrawingParams params) {
- float totalScale = scaleForNumItems(curNumItems);
+ float totalScale = scaleForItem(index, curNumItems);
float transX;
float transY;
float overlayAlpha = 0;
@@ -94,7 +95,7 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule
MIN_NUM_ITEMS_IN_PREVIEW) / (MAX_NUM_ITEMS_IN_PREVIEW - MIN_NUM_ITEMS_IN_PREVIEW));
double theta = theta0 + index * (2 * Math.PI / curNumItems) * direction;
- float halfIconSize = (mIconSize * scaleForNumItems(curNumItems)) / 2;
+ float halfIconSize = (mIconSize * scaleForItem(index, curNumItems)) / 2;
// Map the location along the circle, and offset the coordinates to represent the center
// of the icon, and to be based from the top / left of the preview area. The y component
@@ -104,7 +105,9 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule
}
- private float scaleForNumItems(int numItems) {
+ @Override
+ public float scaleForItem(int index, int numItems) {
+ // Scale is determined by the number of items in the preview.
float scale = 1f;
if (numItems <= 2) {
scale = MAX_SCALE;
@@ -118,7 +121,7 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule
}
@Override
- public int numItems() {
+ public int maxNumItems() {
return MAX_NUM_ITEMS_IN_PREVIEW;
}
@@ -127,4 +130,23 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule
return true;
}
+ @Override
+ public List<View> getItemsToDisplay(Folder folder) {
+ List<View> items = new ArrayList<>(folder.getItemsInReadingOrder());
+ int numItems = items.size();
+ if (FeatureFlags.LAUNCHER3_NEW_FOLDER_ANIMATION && numItems > MAX_NUM_ITEMS_IN_PREVIEW) {
+ // We match the icons in the preview with the layout of the opened folder (b/27944225),
+ // but we still need to figure out how we want to handle updating the preview when the
+ // upper left quadrant changes.
+ int appsPerRow = folder.mContent.getPageAt(0).getCountX();
+ int appsToDelete = appsPerRow - MAX_NUM_ITEMS_PER_ROW;
+
+ // We only display the upper left quadrant.
+ while (appsToDelete > 0) {
+ items.remove(MAX_NUM_ITEMS_PER_ROW);
+ appsToDelete--;
+ }
+ }
+ return items.subList(0, Math.min(numItems, MAX_NUM_ITEMS_IN_PREVIEW));
+ }
}
diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java
index 7f5569cb9..3653711d6 100644
--- a/src/com/android/launcher3/folder/FolderIcon.java
+++ b/src/com/android/launcher3/folder/FolderIcon.java
@@ -70,6 +70,7 @@ import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.util.Thunk;
import java.util.ArrayList;
+import java.util.List;
/**
* An icon that can appear on in the workspace representing an {@link Folder}.
@@ -320,7 +321,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
to.offset(center[0] - animateView.getMeasuredWidth() / 2,
center[1] - animateView.getMeasuredHeight() / 2);
- float finalAlpha = index < mPreviewLayoutRule.numItems() ? 0.5f : 0f;
+ float finalAlpha = index < mPreviewLayoutRule.maxNumItems() ? 0.5f : 0f;
float finalScale = scale * scaleRelativeToDragLayer;
dragLayer.animateView(animateView, from, to, finalAlpha,
@@ -413,8 +414,8 @@ public class FolderIcon extends FrameLayout implements FolderListener {
}
private float getLocalCenterForIndex(int index, int curNumItems, int[] center) {
- mTmpParams = computePreviewItemDrawingParams(Math.min(mPreviewLayoutRule.numItems(), index),
- curNumItems, mTmpParams);
+ mTmpParams = computePreviewItemDrawingParams(
+ Math.min(mPreviewLayoutRule.maxNumItems(), index), curNumItems, mTmpParams);
mTmpParams.transX += mBackground.basePreviewOffsetX;
mTmpParams.transY += mBackground.basePreviewOffsetY;
@@ -870,8 +871,8 @@ public class FolderIcon extends FrameLayout implements FolderListener {
}
private void updateItemDrawingParams(boolean animate) {
- ArrayList<View> items = mFolder.getItemsInReadingOrder();
- int nItemsInPreview = Math.min(items.size(), mPreviewLayoutRule.numItems());
+ List<View> items = mPreviewLayoutRule.getItemsToDisplay(mFolder);
+ int nItemsInPreview = items.size();
int prevNumItems = mDrawingParams.size();
@@ -1037,10 +1038,10 @@ public class FolderIcon extends FrameLayout implements FolderListener {
public interface PreviewLayoutRule {
PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems,
PreviewItemDrawingParams params);
-
void init(int availableSpace, int intrinsicIconSize, boolean rtl);
-
- int numItems();
+ float scaleForItem(int index, int totalNumItems);
+ int maxNumItems();
boolean clipToBackground();
+ List<View> getItemsToDisplay(Folder folder);
}
}
diff --git a/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java b/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java
index 7fb02e313..297203ae2 100644
--- a/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java
+++ b/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java
@@ -16,10 +16,12 @@
package com.android.launcher3.folder;
-import android.graphics.Path;
+import android.view.View;
import com.android.launcher3.folder.FolderIcon.PreviewItemDrawingParams;
+import java.util.List;
+
public class StackFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule {
static final int MAX_NUM_ITEMS_IN_PREVIEW = 3;
@@ -54,10 +56,10 @@ public class StackFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule {
@Override
public PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems,
PreviewItemDrawingParams params) {
+ float scale = scaleForItem(index, curNumItems);
index = MAX_NUM_ITEMS_IN_PREVIEW - index - 1;
float r = (index * 1.0f) / (MAX_NUM_ITEMS_IN_PREVIEW - 1);
- float scale = (1 - PERSPECTIVE_SCALE_FACTOR * (1 - r));
float offset = (1 - r) * mMaxPerspectiveShift;
float scaledSize = scale * mBaselineIconSize;
@@ -80,12 +82,26 @@ public class StackFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule {
}
@Override
- public int numItems() {
+ public int maxNumItems() {
return MAX_NUM_ITEMS_IN_PREVIEW;
}
@Override
+ public float scaleForItem(int index, int numItems) {
+ // Scale is determined by the position of the icon in the preview.
+ index = MAX_NUM_ITEMS_IN_PREVIEW - index - 1;
+ float r = (index * 1.0f) / (MAX_NUM_ITEMS_IN_PREVIEW - 1);
+ return (1 - PERSPECTIVE_SCALE_FACTOR * (1 - r));
+ }
+
+ @Override
public boolean clipToBackground() {
return false;
}
+
+ @Override
+ public List<View> getItemsToDisplay(Folder folder) {
+ List<View> items = folder.getItemsInReadingOrder();
+ return items.subList(0, Math.min(items.size(), MAX_NUM_ITEMS_IN_PREVIEW));
+ }
}
diff --git a/src_config/com/android/launcher3/config/FeatureFlags.java b/src_config/com/android/launcher3/config/FeatureFlags.java
index ffb86e4cb..5c29366b9 100644
--- a/src_config/com/android/launcher3/config/FeatureFlags.java
+++ b/src_config/com/android/launcher3/config/FeatureFlags.java
@@ -28,6 +28,7 @@ public final class FeatureFlags {
public static boolean LAUNCHER3_USE_SYSTEM_DRAG_DRIVER = true;
public static boolean LAUNCHER3_DISABLE_PINCH_TO_OVERVIEW = false;
public static boolean LAUNCHER3_ALL_APPS_PULL_UP = true;
+ public static boolean LAUNCHER3_NEW_FOLDER_ANIMATION = false;
// Feature flag to enable moving the QSB on the 0th screen of the workspace.
public static final boolean QSB_ON_FIRST_SCREEN = true;