Removing animation when stripping empty pages, as the animation is
run by LayoutAnimation already Bug: 151978739 Change-Id: I75b9055c3e862a6813164cce6c1ba7b2fe1f870a
This commit is contained in:
1 parent
7a9f1628f2
commit
6e379fc784
2 files changed
+37
-93
No files matched your search
@@ -29,7 +29,6 @@ import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.LayoutTransition;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.animation.ValueAnimator.AnimatorUpdateListener;
|
||||
import android.annotation.SuppressLint;
|
||||
@@ -125,9 +124,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
|
||||
private static final boolean ENFORCE_DRAG_EVENT_ORDER = false;
|
||||
|
||||
private static final int SNAP_OFF_EMPTY_SCREEN_DURATION = 400;
|
||||
private static final int FADE_EMPTY_SCREEN_DURATION = 150;
|
||||
|
||||
private static final int ADJACENT_SCREEN_DROP_DURATION = 300;
|
||||
|
||||
private static final int DEFAULT_PAGE = 0;
|
||||
@@ -140,7 +136,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
@Thunk final IntSparseArrayMap<CellLayout> mWorkspaceScreens = new IntSparseArrayMap<>();
|
||||
@Thunk final IntArray mScreenOrder = new IntArray();
|
||||
|
||||
@Thunk Runnable mRemoveEmptyScreenRunnable;
|
||||
@Thunk boolean mDeferRemoveExtraEmptyScreen = false;
|
||||
|
||||
/**
|
||||
@@ -428,7 +423,7 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
}
|
||||
|
||||
if (!mDeferRemoveExtraEmptyScreen) {
|
||||
removeExtraEmptyScreen(true, mDragSourceInternal != null);
|
||||
removeExtraEmptyScreen(mDragSourceInternal != null);
|
||||
}
|
||||
|
||||
updateChildrenLayersEnabled();
|
||||
@@ -453,8 +448,16 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
private void setupLayoutTransition() {
|
||||
// We want to show layout transitions when pages are deleted, to close the gap.
|
||||
mLayoutTransition = new LayoutTransition();
|
||||
|
||||
mLayoutTransition.enableTransitionType(LayoutTransition.DISAPPEARING);
|
||||
mLayoutTransition.enableTransitionType(LayoutTransition.CHANGE_DISAPPEARING);
|
||||
// Change the interpolators such that the fade animation plays before the move animation.
|
||||
// This prevents empty adjacent pages to overlay during animation
|
||||
mLayoutTransition.setInterpolator(LayoutTransition.DISAPPEARING,
|
||||
Interpolators.clampToProgress(Interpolators.ACCEL_DEACCEL, 0, 0.5f));
|
||||
mLayoutTransition.setInterpolator(LayoutTransition.CHANGE_DISAPPEARING,
|
||||
Interpolators.clampToProgress(Interpolators.ACCEL_DEACCEL, 0.5f, 1));
|
||||
|
||||
mLayoutTransition.disableTransitionType(LayoutTransition.APPEARING);
|
||||
mLayoutTransition.disableTransitionType(LayoutTransition.CHANGE_APPEARING);
|
||||
setLayoutTransition(mLayoutTransition);
|
||||
@@ -571,9 +574,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
boolean lastChildOnScreen = false;
|
||||
boolean childOnFinalScreen = false;
|
||||
|
||||
// Cancel any pending removal of empty screen
|
||||
mRemoveEmptyScreenRunnable = null;
|
||||
|
||||
if (mDragSourceInternal != null) {
|
||||
if (mDragSourceInternal.getChildCount() == 1) {
|
||||
lastChildOnScreen = true;
|
||||
@@ -624,43 +624,34 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
}
|
||||
}
|
||||
|
||||
public void removeExtraEmptyScreen(final boolean animate, boolean stripEmptyScreens) {
|
||||
removeExtraEmptyScreenDelayed(animate, null, 0, stripEmptyScreens);
|
||||
public void removeExtraEmptyScreen(boolean stripEmptyScreens) {
|
||||
removeExtraEmptyScreenDelayed(0, stripEmptyScreens, null);
|
||||
}
|
||||
|
||||
public void removeExtraEmptyScreenDelayed(final boolean animate, final Runnable onComplete,
|
||||
final int delay, final boolean stripEmptyScreens) {
|
||||
public void removeExtraEmptyScreenDelayed(
|
||||
int delay, boolean stripEmptyScreens, Runnable onComplete) {
|
||||
if (mLauncher.isWorkspaceLoading()) {
|
||||
// Don't strip empty screens if the workspace is still loading
|
||||
return;
|
||||
}
|
||||
|
||||
if (delay > 0) {
|
||||
postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
removeExtraEmptyScreenDelayed(animate, onComplete, 0, stripEmptyScreens);
|
||||
}
|
||||
}, delay);
|
||||
postDelayed(
|
||||
() -> removeExtraEmptyScreenDelayed(0, stripEmptyScreens, onComplete), delay);
|
||||
return;
|
||||
}
|
||||
|
||||
convertFinalScreenToEmptyScreenIfNecessary();
|
||||
if (hasExtraEmptyScreen()) {
|
||||
int emptyIndex = mScreenOrder.indexOf(EXTRA_EMPTY_SCREEN_ID);
|
||||
if (getNextPage() == emptyIndex) {
|
||||
snapToPage(getNextPage() - 1, SNAP_OFF_EMPTY_SCREEN_DURATION);
|
||||
fadeAndRemoveEmptyScreen(SNAP_OFF_EMPTY_SCREEN_DURATION, FADE_EMPTY_SCREEN_DURATION,
|
||||
onComplete, stripEmptyScreens);
|
||||
} else {
|
||||
snapToPage(getNextPage(), 0);
|
||||
fadeAndRemoveEmptyScreen(0, FADE_EMPTY_SCREEN_DURATION,
|
||||
onComplete, stripEmptyScreens);
|
||||
}
|
||||
return;
|
||||
} else if (stripEmptyScreens) {
|
||||
// If we're not going to strip the empty screens after removing
|
||||
// the extra empty screen, do it right away.
|
||||
removeView(mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID));
|
||||
mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID);
|
||||
mScreenOrder.removeValue(EXTRA_EMPTY_SCREEN_ID);
|
||||
|
||||
// Update the page indicator to reflect the removed page.
|
||||
showPageIndicatorAtCurrentScroll();
|
||||
}
|
||||
|
||||
if (stripEmptyScreens) {
|
||||
stripEmptyScreens();
|
||||
}
|
||||
|
||||
@@ -669,44 +660,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
}
|
||||
}
|
||||
|
||||
private void fadeAndRemoveEmptyScreen(int delay, int duration, final Runnable onComplete,
|
||||
final boolean stripEmptyScreens) {
|
||||
// XXX: Do we need to update LM workspace screens below?
|
||||
final CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID);
|
||||
|
||||
mRemoveEmptyScreenRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (hasExtraEmptyScreen()) {
|
||||
mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID);
|
||||
mScreenOrder.removeValue(EXTRA_EMPTY_SCREEN_ID);
|
||||
removeView(cl);
|
||||
if (stripEmptyScreens) {
|
||||
stripEmptyScreens();
|
||||
}
|
||||
// Update the page indicator to reflect the removed page.
|
||||
showPageIndicatorAtCurrentScroll();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ObjectAnimator oa = ObjectAnimator.ofFloat(cl, ALPHA, 0f);
|
||||
oa.setDuration(duration);
|
||||
oa.setStartDelay(delay);
|
||||
oa.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (mRemoveEmptyScreenRunnable != null) {
|
||||
mRemoveEmptyScreenRunnable.run();
|
||||
}
|
||||
if (onComplete != null) {
|
||||
onComplete.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
oa.start();
|
||||
}
|
||||
|
||||
public boolean hasExtraEmptyScreen() {
|
||||
return mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) && getChildCount() > 1;
|
||||
}
|
||||
@@ -793,8 +746,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
}
|
||||
}
|
||||
|
||||
boolean isInAccessibleDrag = mLauncher.getAccessibilityDelegate().isInAccessibleDrag();
|
||||
|
||||
// We enforce at least one page to add new items to. In the case that we remove the last
|
||||
// such screen, we convert the last screen to the empty screen
|
||||
int minScreens = 1;
|
||||
@@ -813,7 +764,6 @@ public class Workspace extends PagedView<WorkspacePageIndicator>
|
||||
removeView(cl);
|
||||
} else {
|
||||
// if this is the last screen, convert it to the empty screen
|
||||
mRemoveEmptyScreenRunnable = null;
|
||||
mWorkspaceScreens.put(EXTRA_EMPTY_SCREEN_ID, cl);
|
||||
mScreenOrder.add(EXTRA_EMPTY_SCREEN_ID);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user