diff options
author | Linus Lee <llee@cyngn.com> | 2015-05-28 15:51:33 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2015-06-01 00:53:49 +0000 |
commit | d482eb729911a3d85a3edc685c70da0804f51cfc (patch) | |
tree | 4016b66df2e802be389e034f6c789194f92df174 /src/com/android/launcher3/Folder.java | |
parent | 20bf4bd9539e7e1038b7a3f53b3593b37fb184be (diff) | |
download | android_packages_apps_Trebuchet-d482eb729911a3d85a3edc685c70da0804f51cfc.tar.gz android_packages_apps_Trebuchet-d482eb729911a3d85a3edc685c70da0804f51cfc.tar.bz2 android_packages_apps_Trebuchet-d482eb729911a3d85a3edc685c70da0804f51cfc.zip |
Fix power save mode broken ui/animations
Change-Id: I7dc0123300ff2e9aa64713c1091d13ecc93001f3
Diffstat (limited to 'src/com/android/launcher3/Folder.java')
-rw-r--r-- | src/com/android/launcher3/Folder.java | 86 |
1 files changed, 60 insertions, 26 deletions
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java index 070eb3722..ccc90d229 100644 --- a/src/com/android/launcher3/Folder.java +++ b/src/com/android/launcher3/Folder.java @@ -30,7 +30,9 @@ import android.graphics.PointF; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; +import android.os.PowerManager; import android.os.SystemClock; +import android.provider.Settings; import android.support.v4.widget.AutoScrollHelper; import android.text.InputType; import android.text.Selection; @@ -92,6 +94,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList private static final int CLOSE_FOLDER_DELAY_MS = 150; + private final PowerManager mPowerManager; + private int mExpandDuration; private int mMaterialExpandDuration; private int mMaterialExpandStagger; @@ -169,6 +173,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList public Folder(Context context, AttributeSet attrs) { super(context, attrs); + mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); setAlwaysDrawnWithCacheEnabled(false); @@ -596,6 +602,24 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList fakeFolderIconView.setVisibility(View.INVISIBLE); } + private static Animator setupAlphaAnimator(final View v, final float startAlpha, + final float endAlpha, final long duration, final long startDelay) { + v.setAlpha(startAlpha); + Animator animator = LauncherAnimUtils.ofFloat(v, "alpha", startAlpha, endAlpha); + animator.setDuration(duration); + animator.setStartDelay(startDelay); + animator.setInterpolator(new LogDecelerateInterpolator(60, 0)); + animator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + // in low power mode the animation doesn't play, so set the end value here + v.setAlpha(endAlpha); + } + }); + + return animator; + } + public void animateOpen(Workspace workspace) { if (!(getParent() instanceof DragLayer)) return; @@ -625,35 +649,37 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList float transX = 0; float transY = getResources().getInteger(R.integer.folder_translate_y_dist); + final float endTransX = 0; + final float endTransY = 0; setTranslationX(transX); setTranslationY(transY); - PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, 0); - PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, 0); + PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, + endTransX); + PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, + endTransY); AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); - mFolderLock.setAlpha(0f); - Animator lockAlpha = LauncherAnimUtils.ofFloat(mFolderLock, "alpha", 0f, 1f); - lockAlpha.setDuration(mMaterialExpandDuration); - lockAlpha.setStartDelay(mMaterialExpandStagger); - lockAlpha.setInterpolator(new LogDecelerateInterpolator(60, 0)); + View[] alphaViewSet = new View[] { mFolderLock, mContent, mFolderName }; + for (View view : alphaViewSet) { + Animator alphaAnimator = setupAlphaAnimator(view, 0f, 1f, + mMaterialExpandDuration, mMaterialExpandStagger); - mContent.setAlpha(0f); - Animator iconsAlpha = LauncherAnimUtils.ofFloat(mContent, "alpha", 0f, 1f); - iconsAlpha.setDuration(mMaterialExpandDuration); - iconsAlpha.setStartDelay(mMaterialExpandStagger); - iconsAlpha.setInterpolator(new LogDecelerateInterpolator(60, 0)); - - mFolderName.setAlpha(0f); - Animator textAlpha = LauncherAnimUtils.ofFloat(mFolderName, "alpha", 0f, 1f); - textAlpha.setDuration(mMaterialExpandDuration); - textAlpha.setStartDelay(mMaterialExpandStagger); - textAlpha.setInterpolator(new LogDecelerateInterpolator(60, 0)); + anim.play(alphaAnimator); + } Animator drift = LauncherAnimUtils.ofPropertyValuesHolder(this, tx, ty); drift.setDuration(mMaterialExpandDuration); drift.setStartDelay(mMaterialExpandStagger); drift.setInterpolator(new LogDecelerateInterpolator(60, 0)); + drift.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + // in low power mode the animation doesn't play, so set the end value here + Folder.this.setTranslationX(endTransX); + Folder.this.setTranslationY(endTransY); + } + }); final ArrayList<View> layerViews = new ArrayList<View>(); @@ -719,9 +745,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList } anim.play(fakeFolderIcon); anim.play(drift); - anim.play(iconsAlpha); - anim.play(lockAlpha); - anim.play(textAlpha); if (workspaceAnim != null) { anim.play(workspaceAnim); } @@ -839,12 +862,24 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList if (!(getParent() instanceof DragLayer)) return; AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); - PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); + PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f); float transY = getResources().getInteger(R.integer.folder_translate_y_dist); PropertyValuesHolder translationY = PropertyValuesHolder.ofFloat("translationY", 0f, transY); - final ObjectAnimator oa = - LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, translationY); + + setLayerType(LAYER_TYPE_HARDWARE, null); + + float animatorDurationScale = Settings.Global.getFloat(getContext().getContentResolver(), + Settings.Global.ANIMATOR_DURATION_SCALE, 1); + ObjectAnimator oa; + if (mPowerManager.isPowerSaveMode() || animatorDurationScale < 0.01f) { + // power save mode is no fun - skip alpha animation and just set it to 0 + // otherwise the icons will stay around until the duration of the animation + oa = LauncherAnimUtils.ofPropertyValuesHolder(this, translationY); + setAlpha(0f); + } else { + oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, translationY); + } oa.addListener(new AnimatorListenerAdapter() { @Override @@ -856,7 +891,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList }); oa.setDuration(mMaterialExpandDuration); oa.setInterpolator(new LogDecelerateInterpolator(60, 0)); - setLayerType(LAYER_TYPE_HARDWARE, null); + anim.play(oa); Animator workspaceAnim = mLauncher.getWorkspace().getChangeStateAnimation( Workspace.State.NORMAL, animate, new ArrayList<View>()); @@ -939,7 +974,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList mFolderIcon.setPreviewBackground(R.drawable.folder_bg); } - anim.play(oa); if (workspaceAnim != null) { anim.play(workspaceAnim); } |