summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorMichael Jurka <mikejurka@google.com>2011-03-04 12:06:57 -0800
committerMichael Jurka <mikejurka@google.com>2011-03-07 15:20:51 -0800
commitabded66084680bb31cc7ea403c88f44f79a3c884 (patch)
treee1a64c9a31caf280e011ed12b9b8ade54a080c47 /src/com
parent320b2fb5eff8750d07dc9b4874c2ec0b92a601b8 (diff)
downloadandroid_packages_apps_Trebuchet-abded66084680bb31cc7ea403c88f44f79a3c884.tar.gz
android_packages_apps_Trebuchet-abded66084680bb31cc7ea403c88f44f79a3c884.tar.bz2
android_packages_apps_Trebuchet-abded66084680bb31cc7ea403c88f44f79a3c884.zip
improving performance of first AllApps/Customize animation
Change-Id: I71e5cc634f7e1346617d101efd6945c00484cab3
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/launcher2/AllAppsPagedView.java26
-rw-r--r--src/com/android/launcher2/AllAppsTabbed.java33
-rw-r--r--src/com/android/launcher2/CellLayout.java4
-rw-r--r--src/com/android/launcher2/CustomizeTrayTabHost.java29
-rw-r--r--src/com/android/launcher2/Launcher.java34
-rw-r--r--src/com/android/launcher2/PagedViewCellLayout.java27
-rw-r--r--src/com/android/launcher2/PagedViewCellLayoutChildren.java4
-rw-r--r--src/com/android/launcher2/Workspace.java5
8 files changed, 123 insertions, 39 deletions
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java
index 4158b4ad2..b9b38c3d6 100644
--- a/src/com/android/launcher2/AllAppsPagedView.java
+++ b/src/com/android/launcher2/AllAppsPagedView.java
@@ -63,6 +63,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
private int mAppFilter = ALL_APPS_FLAG;
private final LayoutInflater mInflater;
+ private boolean mAllowHardwareLayerCreation;
public AllAppsPagedView(Context context) {
@@ -95,6 +96,22 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
mCenterPagesVertically = false;
}
+ void allowHardwareLayerCreation() {
+ // This is called after the first time we launch into All Apps. Before that point,
+ // there's no need for hardware layers here since there's a hardware layer set on the
+ // parent, AllAppsTabbed, during the AllApps transition -- creating hardware layers here
+ // before the animation is done slows down the animation
+ if (mAllowHardwareLayerCreation) {
+ return;
+ }
+ mAllowHardwareLayerCreation = true;
+ int childCount = getChildCount();
+ for (int i = 0; i < childCount; i++) {
+ PagedViewCellLayout page = (PagedViewCellLayout) getChildAt(i);
+ page.allowHardwareLayerCreation();
+ }
+ }
+
@Override
public void setLauncher(Launcher launcher) {
mLauncher = launcher;
@@ -121,8 +138,6 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
cancelLongPress();
if (isVisible()) {
- getParent().bringChildToFront(this);
- setVisibility(View.VISIBLE);
if (animate) {
startAnimation(AnimationUtils.loadAnimation(getContext(),
R.anim.all_apps_2d_fade_in));
@@ -141,7 +156,6 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
protected void onAnimationEnd() {
if (!isVisible()) {
- setVisibility(View.GONE);
mZoom = 0.0f;
endChoiceMode();
@@ -388,6 +402,7 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
}
mFilteredApps = rebuildFilteredApps(mApps);
}
+
@Override
public void removeApps(ArrayList<ApplicationInfo> list) {
removeAppsWithoutInvalidate(list);
@@ -434,12 +449,15 @@ public class AllAppsPagedView extends PagedViewWithDraggableItems implements All
// remove any extra pages after the "last" page
int extraPageDiff = curNumPages - numPages;
for (int i = 0; i < extraPageDiff; ++i) {
+ PagedViewCellLayout page = (PagedViewCellLayout) getChildAt(numPages);
removeViewAt(numPages);
}
// add any necessary pages
for (int i = curNumPages; i < numPages; ++i) {
PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
- layout.enableHardwareLayers();
+ if (mAllowHardwareLayerCreation) {
+ layout.allowHardwareLayerCreation();
+ }
layout.setCellCount(mCellCountX, mCellCountY);
layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
diff --git a/src/com/android/launcher2/AllAppsTabbed.java b/src/com/android/launcher2/AllAppsTabbed.java
index 66191503c..aa828b049 100644
--- a/src/com/android/launcher2/AllAppsTabbed.java
+++ b/src/com/android/launcher2/AllAppsTabbed.java
@@ -41,7 +41,7 @@ import java.util.ArrayList;
/**
* Implements a tabbed version of AllApps2D.
*/
-public class AllAppsTabbed extends TabHost implements AllAppsView, LauncherAnimatable {
+public class AllAppsTabbed extends TabHost implements AllAppsView, LauncherTransitionable {
private static final String TAG = "Launcher.AllAppsTabbed";
@@ -172,21 +172,36 @@ public class AllAppsTabbed extends TabHost implements AllAppsView, LauncherAnima
}
@Override
- public void onLauncherAnimationStart() {
- // Turn on hardware layers for performance
- setLayerType(LAYER_TYPE_HARDWARE, null);
- // Re-enable the rendering of the dimmed background in All Apps for performance reasons
- mLauncher.getWorkspace().disableBackground();
- mBackground.setVisibility(VISIBLE);
+ public void onLauncherTransitionStart(Animator animation) {
+ if (animation != null) {
+ // Turn on hardware layers for performance
+ setLayerType(LAYER_TYPE_HARDWARE, null);
+ // Re-enable the rendering of the dimmed background in All Apps for performance reasons
+ mLauncher.getWorkspace().disableBackground();
+ mBackground.setVisibility(VISIBLE);
+ // just a sanity check that we don't build a layer before a call to onLayout
+ if (!mFirstLayout) {
+ // force building the layer at the beginning of the animation, so you don't get a
+ // blip early in the animation
+ buildLayer();
+ }
+ }
}
@Override
- public void onLauncherAnimationEnd() {
- setLayerType(LAYER_TYPE_NONE, null);
+ public void onLauncherTransitionEnd(Animator animation) {
+ if (animation != null) {
+ setLayerType(LAYER_TYPE_NONE, null);
+ // To improve the performance of the first time All Apps is run, we initially keep
+ // hardware layers in AllAppsPagedView disabled since AllAppsTabbed itself is drawn in a
+ // hardware layer, and creating additional hardware layers slows down the animation. We
+ // create them here, after the animation is over.
+ }
// Move the rendering of the dimmed background to workspace after the all apps animation
// is done, so that the background is not rendered *above* the mini workspace screens
mLauncher.getWorkspace().enableBackground();
mBackground.setVisibility(GONE);
+ mAllApps.allowHardwareLayerCreation();
}
@Override
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 0fb87bacc..c1c12b5ed 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -571,6 +571,10 @@ public class CellLayout extends ViewGroup {
mChildren.draw(canvas);
}
+ void buildChildrenLayer() {
+ mChildren.buildLayer();
+ }
+
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
diff --git a/src/com/android/launcher2/CustomizeTrayTabHost.java b/src/com/android/launcher2/CustomizeTrayTabHost.java
index 502917211..76cfc84e8 100644
--- a/src/com/android/launcher2/CustomizeTrayTabHost.java
+++ b/src/com/android/launcher2/CustomizeTrayTabHost.java
@@ -16,11 +16,14 @@
package com.android.launcher2;
+import android.animation.Animator;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TabHost;
-public class CustomizeTrayTabHost extends TabHost implements LauncherAnimatable {
+public class CustomizeTrayTabHost extends TabHost implements LauncherTransitionable {
+ private boolean mFirstLayout = true;
+
public CustomizeTrayTabHost(Context context) {
super(context);
}
@@ -30,12 +33,28 @@ public class CustomizeTrayTabHost extends TabHost implements LauncherAnimatable
}
@Override
- public void onLauncherAnimationStart() {
- setLayerType(LAYER_TYPE_HARDWARE, null);
+ public void onLauncherTransitionStart(Animator animation) {
+ if (animation != null) {
+ setLayerType(LAYER_TYPE_HARDWARE, null);
+ // just a sanity check that we don't build a layer before a call to onLayout
+ if (!mFirstLayout) {
+ // force building the layer at the beginning of the animation, so you don't get a
+ // blip early in the animation
+ buildLayer();
+ }
+ }
+ }
+
+ @Override
+ public void onLauncherTransitionEnd(Animator animation) {
+ if (animation != null) {
+ setLayerType(LAYER_TYPE_NONE, null);
+ }
}
@Override
- public void onLauncherAnimationEnd() {
- setLayerType(LAYER_TYPE_NONE, null);
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
+ mFirstLayout = false;
+ super.onLayout(changed, l, t, r, b);
}
}
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 994c3b825..81569cd3c 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -2781,7 +2781,7 @@ public final class Launcher extends Activity
}
if (animated) {
- ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
+ final ValueAnimator scaleAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
scaleAnim.setInterpolator(new Workspace.ZoomOutInterpolator());
scaleAnim.addUpdateListener(new AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
@@ -2808,8 +2808,8 @@ public final class Launcher extends Activity
alphaAnim.start();
}
- if (toView instanceof LauncherAnimatable) {
- ((LauncherAnimatable) toView).onLauncherAnimationStart();
+ if (toView instanceof LauncherTransitionable) {
+ ((LauncherTransitionable) toView).onLauncherTransitionStart(scaleAnim);
}
scaleAnim.addListener(new AnimatorListenerAdapter() {
@Override
@@ -2829,8 +2829,8 @@ public final class Launcher extends Activity
// not fix that
toView.setScaleX(1.0f);
toView.setScaleY(1.0f);
- if (toView instanceof LauncherAnimatable) {
- ((LauncherAnimatable) toView).onLauncherAnimationEnd();
+ if (toView instanceof LauncherTransitionable) {
+ ((LauncherTransitionable) toView).onLauncherTransitionEnd(scaleAnim);
}
}
});
@@ -2857,6 +2857,10 @@ public final class Launcher extends Activity
toView.setScaleX(1.0f);
toView.setScaleY(1.0f);
toView.setVisibility(View.VISIBLE);
+ if (toView instanceof LauncherTransitionable) {
+ ((LauncherTransitionable) toView).onLauncherTransitionStart(null);
+ ((LauncherTransitionable) toView).onLauncherTransitionEnd(null);
+ }
hideAndShowToolbarButtons(toState, null, null);
}
}
@@ -2912,7 +2916,7 @@ public final class Launcher extends Activity
fromView.setFastScaleY(a * oldScaleY + b * scaleFactor);
}
});
- ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
+ final ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f);
alphaAnim.setDuration(res.getInteger(R.integer.config_allAppsFadeOutTime));
alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f));
alphaAnim.addUpdateListener(new AnimatorUpdateListener() {
@@ -2923,15 +2927,15 @@ public final class Launcher extends Activity
fromView.setFastAlpha(a * 1f + b * 0f);
}
});
- if (fromView instanceof LauncherAnimatable) {
- ((LauncherAnimatable) fromView).onLauncherAnimationStart();
+ if (fromView instanceof LauncherTransitionable) {
+ ((LauncherTransitionable) fromView).onLauncherTransitionStart(alphaAnim);
}
alphaAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
fromView.setVisibility(View.GONE);
- if (fromView instanceof LauncherAnimatable) {
- ((LauncherAnimatable) fromView).onLauncherAnimationEnd();
+ if (fromView instanceof LauncherTransitionable) {
+ ((LauncherTransitionable) fromView).onLauncherTransitionEnd(alphaAnim);
}
}
});
@@ -2951,6 +2955,10 @@ public final class Launcher extends Activity
mStateAnimation.start();
} else {
fromView.setVisibility(View.GONE);
+ if (fromView instanceof LauncherTransitionable) {
+ ((LauncherTransitionable) fromView).onLauncherTransitionStart(null);
+ ((LauncherTransitionable) fromView).onLauncherTransitionEnd(null);
+ }
if (!springLoaded) {
hideAndShowToolbarButtons(State.WORKSPACE, null, null);
}
@@ -3753,7 +3761,7 @@ public final class Launcher extends Activity
}
}
-interface LauncherAnimatable {
- void onLauncherAnimationStart();
- void onLauncherAnimationEnd();
+interface LauncherTransitionable {
+ void onLauncherTransitionStart(Animator animation);
+ void onLauncherTransitionEnd(Animator animation);
}
diff --git a/src/com/android/launcher2/PagedViewCellLayout.java b/src/com/android/launcher2/PagedViewCellLayout.java
index 57d41faff..28bb78b9a 100644
--- a/src/com/android/launcher2/PagedViewCellLayout.java
+++ b/src/com/android/launcher2/PagedViewCellLayout.java
@@ -40,7 +40,8 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
private static int sDefaultCellDimensions = 96;
protected PagedViewCellLayoutChildren mChildren;
private PagedViewCellLayoutChildren mHolographicChildren;
- private boolean mUseHardwareLayers = false;
+ private boolean mAllowHardwareLayerCreation = false;
+ private boolean mCreateHardwareLayersIfAllowed = false;
public PagedViewCellLayout(Context context) {
this(context, null);
@@ -74,8 +75,17 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
addView(mHolographicChildren);
}
- public void enableHardwareLayers() {
- mUseHardwareLayers = true;
+ public void allowHardwareLayerCreation() {
+ // This is called after the first time we launch into All Apps. Before that point,
+ // there's no need for hardware layers here since there's a hardware layer set on the
+ // parent, AllAppsTabbed, during the AllApps transition -- creating hardware layers here
+ // before the animation is done slows down the animation
+ if (!mAllowHardwareLayerCreation) {
+ mAllowHardwareLayerCreation = true;
+ if (mCreateHardwareLayersIfAllowed) {
+ createHardwareLayers();
+ }
+ }
}
@Override
@@ -85,13 +95,18 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
}
void destroyHardwareLayers() {
- if (mUseHardwareLayers) {
+ // called when a page is no longer visible (triggered by loadAssociatedPages ->
+ // removeAllViewsOnPage)
+ mCreateHardwareLayersIfAllowed = false;
+ if (mAllowHardwareLayerCreation) {
mChildren.destroyHardwareLayer();
mHolographicChildren.destroyHardwareLayer();
}
}
void createHardwareLayers() {
- if (mUseHardwareLayers) {
+ // called when a page is visible (triggered by loadAssociatedPages -> syncPageItems)
+ mCreateHardwareLayersIfAllowed = true;
+ if (mAllowHardwareLayerCreation) {
mChildren.createHardwareLayer();
mHolographicChildren.createHardwareLayer();
}
@@ -127,7 +142,7 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
if (child instanceof PagedViewIcon) {
PagedViewIcon pagedViewIcon = (PagedViewIcon) child;
- if (mUseHardwareLayers) {
+ if (mAllowHardwareLayerCreation) {
pagedViewIcon.disableCache();
}
mHolographicChildren.addView(pagedViewIcon.getHolographicOutlineView(), index, lp);
diff --git a/src/com/android/launcher2/PagedViewCellLayoutChildren.java b/src/com/android/launcher2/PagedViewCellLayoutChildren.java
index 27da02af5..92ff46184 100644
--- a/src/com/android/launcher2/PagedViewCellLayoutChildren.java
+++ b/src/com/android/launcher2/PagedViewCellLayoutChildren.java
@@ -139,12 +139,12 @@ public class PagedViewCellLayoutChildren extends ViewGroup {
}
void destroyHardwareLayer() {
- if (getLayerType() == LAYER_TYPE_HARDWARE) {
+ if (getLayerType() != LAYER_TYPE_NONE) {
setLayerType(LAYER_TYPE_NONE, null);
}
}
void createHardwareLayer() {
- if (getLayerType() == LAYER_TYPE_NONE) {
+ if (getLayerType() != LAYER_TYPE_HARDWARE) {
setLayerType(LAYER_TYPE_HARDWARE, null);
}
}
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 123ab1e41..fe40fc1e1 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -1513,6 +1513,11 @@ public class Workspace extends SmoothPagedView
oldAlphas[i] = cl.getAlpha();
newAlphas[i] = finalAlpha;
+ if (animated && (oldAlphas[i] != 0f || newAlphas[i] != 0f)) {
+ // if the CellLayout will be visible during the animation, force building its
+ // hardware layer immediately so we don't see a blip later in the animation
+ cl.buildChildrenLayer();
+ }
if (animated) {
oldXs[i] = cl.getX();
oldYs[i] = cl.getY();