From 2763be3150d429d338b9848286e9365b4052c100 Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Thu, 24 Feb 2011 11:19:57 -0800 Subject: Improving performance of All Apps transition - increased perf ~8fps using hardware layers Change-Id: Ic6a2c23e9182fdb1ee362cbd72f7813f4e9accf0 --- src/com/android/launcher2/AllAppsTabbed.java | 30 +++++++++++++++- .../android/launcher2/CustomizeTrayTabHost.java | 41 ++++++++++++++++++++++ src/com/android/launcher2/Launcher.java | 27 +++++++++----- src/com/android/launcher2/Workspace.java | 7 ++-- 4 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 src/com/android/launcher2/CustomizeTrayTabHost.java (limited to 'src/com/android') diff --git a/src/com/android/launcher2/AllAppsTabbed.java b/src/com/android/launcher2/AllAppsTabbed.java index 47a5bf7fc..36594dd34 100644 --- a/src/com/android/launcher2/AllAppsTabbed.java +++ b/src/com/android/launcher2/AllAppsTabbed.java @@ -29,16 +29,19 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; +import android.view.ViewGroup; import android.widget.TabHost; import android.widget.TabWidget; import android.widget.TextView; +import android.widget.TabHost.OnTabChangeListener; +import android.widget.TabHost.TabContentFactory; import java.util.ArrayList; /** * Implements a tabbed version of AllApps2D. */ -public class AllAppsTabbed extends TabHost implements AllAppsView { +public class AllAppsTabbed extends TabHost implements AllAppsView, LauncherAnimatable { private static final String TAG = "Launcher.AllAppsTabbed"; @@ -46,6 +49,7 @@ public class AllAppsTabbed extends TabHost implements AllAppsView { private static final String TAG_DOWNLOADED = "DOWNLOADED"; private AllAppsPagedView mAllApps; + private View mTabBar; private Context mContext; private final LayoutInflater mInflater; private boolean mFirstLayout = true; @@ -64,6 +68,8 @@ public class AllAppsTabbed extends TabHost implements AllAppsView { try { mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view); if (mAllApps == null) throw new Resources.NotFoundException(); + mTabBar = findViewById(R.id.all_apps_tab_bar); + if (mTabBar == null) throw new Resources.NotFoundException(); } catch (Resources.NotFoundException e) { Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed"); } @@ -163,6 +169,28 @@ public class AllAppsTabbed extends TabHost implements AllAppsView { return (getAnimation() != null); } + @Override + public void setFastAlpha(float alpha) { + final ViewGroup allAppsParent = (ViewGroup) mAllApps.getParent(); + final ViewGroup tabBarParent = (ViewGroup) mAllApps.getParent(); + mAllApps.setFastAlpha(alpha); + allAppsParent.fastInvalidate(); + mTabBar.setFastAlpha(alpha); + tabBarParent.fastInvalidate(); + } + + @Override + public void onLauncherAnimationStart() { + mTabBar.setLayerType(LAYER_TYPE_HARDWARE, null); + mAllApps.setLayerType(LAYER_TYPE_HARDWARE, null); + } + + @Override + public void onLauncherAnimationEnd() { + mTabBar.setLayerType(LAYER_TYPE_NONE, null); + mAllApps.setLayerType(LAYER_TYPE_NONE, null); + } + @Override public void setApps(ArrayList list) { mAllApps.setApps(list); diff --git a/src/com/android/launcher2/CustomizeTrayTabHost.java b/src/com/android/launcher2/CustomizeTrayTabHost.java new file mode 100644 index 000000000..502917211 --- /dev/null +++ b/src/com/android/launcher2/CustomizeTrayTabHost.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2011 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.launcher2; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.TabHost; + +public class CustomizeTrayTabHost extends TabHost implements LauncherAnimatable { + public CustomizeTrayTabHost(Context context) { + super(context); + } + + public CustomizeTrayTabHost(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public void onLauncherAnimationStart() { + setLayerType(LAYER_TYPE_HARDWARE, null); + } + + @Override + public void onLauncherAnimationEnd() { + setLayerType(LAYER_TYPE_NONE, null); + } +} diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 039e76bae..63982ba30 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -2767,7 +2767,7 @@ public final class Launcher extends Activity }); if (toAllApps) { - toView.setAlpha(0f); + toView.setFastAlpha(0f); ValueAnimator alphaAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration); alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f)); alphaAnim.addUpdateListener(new AnimatorUpdateListener() { @@ -2781,9 +2781,8 @@ public final class Launcher extends Activity alphaAnim.start(); } - // Only use hardware layers in portrait mode, they don't give any gains in landscape - if (mWorkspace.getWidth() < mWorkspace.getHeight()) { - toView.setLayerType(View.LAYER_TYPE_HARDWARE, null); + if (toView instanceof LauncherAnimatable) { + ((LauncherAnimatable) toView).onLauncherAnimationStart(); } scaleAnim.addListener(new AnimatorListenerAdapter() { @Override @@ -2793,7 +2792,7 @@ public final class Launcher extends Activity toView.setTranslationY(0.0f); toView.setVisibility(View.VISIBLE); if (!toAllApps) { - toView.setAlpha(1.0f); + toView.setFastAlpha(1.0f); } } @Override @@ -2801,9 +2800,11 @@ public final class Launcher extends Activity // If we don't set the final scale values here, if this animation is cancelled // it will have the wrong scale value and subsequent cameraPan animations will // not fix that - toView.setLayerType(View.LAYER_TYPE_NONE, null); toView.setScaleX(1.0f); toView.setScaleY(1.0f); + if (toView instanceof LauncherAnimatable) { + ((LauncherAnimatable) toView).onLauncherAnimationEnd(); + } } }); @@ -2895,13 +2896,16 @@ public final class Launcher extends Activity fromView.setFastAlpha(a * 1f + b * 0f); } }); - - fromView.setLayerType(View.LAYER_TYPE_HARDWARE, null); + if (fromView instanceof LauncherAnimatable) { + ((LauncherAnimatable) fromView).onLauncherAnimationStart(); + } alphaAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { fromView.setVisibility(View.GONE); - fromView.setLayerType(View.LAYER_TYPE_NONE, null); + if (fromView instanceof LauncherAnimatable) { + ((LauncherAnimatable) fromView).onLauncherAnimationEnd(); + } } }); @@ -3714,3 +3718,8 @@ public final class Launcher extends Activity Log.d(TAG, "END launcher2 dump state"); } } + +interface LauncherAnimatable { + void onLauncherAnimationStart(); + void onLauncherAnimationEnd(); +} diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 40dc98dc4..b1dd08807 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -792,7 +792,7 @@ public class Workspace extends SmoothPagedView } } if (keepUpdating) { - invalidate(); + fastInvalidate(); } } @@ -1167,8 +1167,9 @@ public class Workspace extends SmoothPagedView final long drawingTime = getDrawingTime(); for (int i = 0; i < pageCount; i++) { final View page = (View) getChildAt(i); - - drawChild(canvas, page, drawingTime); + if (page.getVisibility() == VISIBLE && page.getAlpha() != 0f) { + drawChild(canvas, page, drawingTime); + } } } else { super.dispatchDraw(canvas); -- cgit v1.2.3