Merge "Moving mState from Workspace to StateManager" into ub-launcher3-master

This commit is contained in:
TreeHugger Robot
2017-10-26 23:30:54 +00:00
committed by Android (Google) Code Review
5 changed files with 57 additions and 54 deletions
+6 -6
View File
@@ -772,7 +772,7 @@ public class Launcher extends BaseActivity
if (!mAppLaunchSuccess) {
getUserEventDispatcher().logActionCommand(Action.Command.STOP,
mWorkspace.getState().containerType);
mStateManager.getState().containerType);
}
NotificationListener.removeNotificationsChangedListener();
}
@@ -1014,7 +1014,7 @@ public class Launcher extends BaseActivity
}
public boolean isInState(LauncherState state) {
return mWorkspace.getState() == state;
return mStateManager.getState() == state;
}
/**
@@ -1426,7 +1426,7 @@ public class Launcher extends BaseActivity
if (topOpenView != null) {
topOpenView.logActionCommand(Action.Command.HOME_INTENT);
} else if (alreadyOnHome) {
Target target = newContainerTarget(mWorkspace.getState().containerType);
Target target = newContainerTarget(mStateManager.getState().containerType);
target.pageIndex = mWorkspace.getCurrentPage();
ued.logActionCommand(Action.Command.HOME_INTENT, target);
}
@@ -1489,7 +1489,7 @@ public class Launcher extends BaseActivity
outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
}
outState.putInt(RUNTIME_STATE, mWorkspace.getState().ordinal);
outState.putInt(RUNTIME_STATE, mStateManager.getState().ordinal);
AbstractFloatingView widgets = AbstractFloatingView
@@ -1884,7 +1884,7 @@ public class Launcher extends BaseActivity
if (topView != null) {
topView.onBackPressed();
} else if (!isInState(NORMAL)) {
ued.logActionCommand(Action.Command.BACK, mWorkspace.getState().containerType);
ued.logActionCommand(Action.Command.BACK, mStateManager.getState().containerType);
mStateManager.goToState(NORMAL);
} else {
// Back button is a no-op here, but give at least some feedback for the button press
@@ -2440,7 +2440,7 @@ public class Launcher extends BaseActivity
// TODO: When can workspace be null?
text.add(mWorkspace == null
? getString(R.string.all_apps_home_button_label)
: mWorkspace.getState().getDescription(this));
: mStateManager.getState().getDescription(this));
return result;
}
@@ -16,6 +16,8 @@
package com.android.launcher3;
import static com.android.launcher3.LauncherState.NORMAL;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
@@ -77,6 +79,8 @@ public class LauncherStateManager {
private final Launcher mLauncher;
private final AllAppsTransitionController mAllAppsController;
private LauncherState mState = NORMAL;
public LauncherStateManager(
Launcher l, AllAppsTransitionController allAppsController) {
mUiHandler = new Handler(Looper.getMainLooper());
@@ -84,6 +88,10 @@ public class LauncherStateManager {
mAllAppsController = allAppsController;
}
public LauncherState getState() {
return mState;
}
/**
* @see #goToState(LauncherState, boolean, Runnable)
*/
@@ -139,6 +147,7 @@ public class LauncherStateManager {
mConfig.reset();
if (!animated) {
setState(state);
mAllAppsController.setFinalProgress(state.verticalProgress);
mLauncher.getWorkspace().setState(state);
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
@@ -161,9 +170,10 @@ public class LauncherStateManager {
}
}
protected AnimatorSet createAnimationToNewWorkspace(LauncherState state,
protected AnimatorSet createAnimationToNewWorkspace(final LauncherState state,
final Runnable onCompleteRunnable) {
mConfig.reset();
mConfig.duration = state == NORMAL ? mState.transitionDuration : state.transitionDuration;
final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
final AnimationLayerSet layerViews = new AnimationLayerSet();
@@ -175,6 +185,13 @@ public class LauncherStateManager {
animation.addListener(layerViews);
animation.addListener(new AnimationSuccessListener() {
@Override
public void onAnimationStart(Animator animation) {
// Change the internal state only when the transition actually starts
setState(state);
}
@Override
public void onAnimationSuccess(Animator animator) {
// Run any queued runnables
@@ -189,6 +206,12 @@ public class LauncherStateManager {
return mConfig.mCurrentAnimation;
}
private void setState(LauncherState state) {
mState.onStateDisabled(mLauncher);
mState = state;
mState.onStateEnabled(mLauncher);
}
/**
* Cancels the current animation.
*/
@@ -220,13 +243,13 @@ public class LauncherStateManager {
public static class AnimationConfig extends AnimatorListenerAdapter {
public boolean shouldPost;
public long duration;
private long mOverriddenDuration = -1;
private AnimatorSet mCurrentAnimation;
public void reset() {
shouldPost = false;
mOverriddenDuration = -1;
shouldPost = true;
duration = 0;
if (mCurrentAnimation != null) {
mCurrentAnimation.setDuration(0);
@@ -235,14 +258,6 @@ public class LauncherStateManager {
}
}
public void overrideDuration(long duration) {
mOverriddenDuration = duration;
}
public long getDuration(long defaultDuration) {
return mOverriddenDuration >= 0 ? mOverriddenDuration : defaultDuration;
}
@Override
public void onAnimationEnd(Animator animation) {
if (mCurrentAnimation == animation) {
+13 -23
View File
@@ -206,8 +206,6 @@ public class Workspace extends PagedView
*/
private final float[] mHotseatAlpha = new float[] {1, 1, 1};
@ViewDebug.ExportedProperty(category = "launcher")
private LauncherState mState = NORMAL;
private boolean mIsSwitchingState = false;
boolean mChildrenLayersEnabled = true;
@@ -576,7 +574,8 @@ public class Workspace extends PagedView
mWorkspaceScreens.put(screenId, newScreen);
mScreenOrder.add(insertIndex, screenId);
addView(newScreen, insertIndex);
mStateTransitionAnimation.applyChildState(mState, newScreen, insertIndex);
mStateTransitionAnimation.applyChildState(
mLauncher.getStateManager().getState(), newScreen, insertIndex);
if (mLauncher.getAccessibilityDelegate().isInAccessibleDrag()) {
newScreen.enableAccessibleDrag(true, CellLayout.WORKSPACE_ACCESSIBILITY_DRAG);
@@ -1411,13 +1410,13 @@ public class Workspace extends PagedView
return super.getDescendantFocusability();
}
public boolean workspaceInModalState() {
return mState != NORMAL;
private boolean workspaceInModalState() {
return !mLauncher.isInState(NORMAL);
}
/** Returns whether a drag should be allowed to be started from the current workspace state. */
public boolean workspaceIconsCanBeDragged() {
return mState == NORMAL || mState == SPRING_LOADED;
return mLauncher.isInState(NORMAL) || mLauncher.isInState(SPRING_LOADED);
}
private void updateChildrenLayersEnabled() {
@@ -1545,11 +1544,6 @@ public class Workspace extends PagedView
}
private void onStartStateTransition(LauncherState state) {
// Change the internal state only when the transition actually starts
mState.onStateDisabled(mLauncher);
mState = state;
mState.onStateEnabled(mLauncher);
mIsSwitchingState = true;
mTransitionProgress = 0;
@@ -1570,7 +1564,7 @@ public class Workspace extends PagedView
*/
public void setState(LauncherState toState) {
onStartStateTransition(toState);
mStateTransitionAnimation.setState(mState);
mStateTransitionAnimation.setState(toState);
onEndStateTransition();
}
@@ -1580,7 +1574,7 @@ public class Workspace extends PagedView
public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
AnimatorSet anim, AnimationConfig config) {
StateTransitionListener listener = new StateTransitionListener(toState);
mStateTransitionAnimation.setStateWithAnimation(mState, toState, anim, layerViews, config);
mStateTransitionAnimation.setStateWithAnimation(toState, anim, layerViews, config);
// Invalidate the pages now, so that we have the visible pages before the
// animation is started
@@ -1595,22 +1589,19 @@ public class Workspace extends PagedView
anim.addListener(listener);
}
public LauncherState getState() {
return mState;
}
public void updateAccessibilityFlags() {
// TODO: Update the accessibility flags appropriately when dragging.
int accessibilityFlag = mLauncher.getStateManager().getState().workspaceAccessibilityFlag;
if (!mLauncher.getAccessibilityDelegate().isInAccessibleDrag()) {
int total = getPageCount();
for (int i = 0; i < total; i++) {
updateAccessibilityFlags((CellLayout) getPageAt(i), i);
updateAccessibilityFlags(accessibilityFlag, (CellLayout) getPageAt(i), i);
}
setImportantForAccessibility(mState.workspaceAccessibilityFlag);
setImportantForAccessibility(accessibilityFlag);
}
}
private void updateAccessibilityFlags(CellLayout page, int pageNo) {
private void updateAccessibilityFlags(int accessibilityFlag, CellLayout page, int pageNo) {
if (isPageRearrangeEnabled()) {
page.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
page.getShortcutsAndWidgets().setImportantForAccessibility(
@@ -1626,8 +1617,7 @@ public class Workspace extends PagedView
}
} else {
page.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
page.getShortcutsAndWidgets()
.setImportantForAccessibility(mState.workspaceAccessibilityFlag);
page.getShortcutsAndWidgets().setImportantForAccessibility(accessibilityFlag);
page.setContentDescription(null);
page.setAccessibilityDelegate(null);
}
@@ -2687,7 +2677,7 @@ public class Workspace extends PagedView
final long screenId = getIdForScreen(cellLayout);
if (!mLauncher.isHotseatLayout(cellLayout)
&& screenId != getScreenIdForPageIndex(mCurrentPage)
&& mState != SPRING_LOADED) {
&& !mLauncher.isInState(SPRING_LOADED)) {
snapToPage(getPageIndexForScreenId(screenId));
}
@@ -161,12 +161,10 @@ public class WorkspaceStateTransitionAnimation {
setWorkspaceProperty(toState, NO_ANIM_PROPERTY_SETTER);
}
public void setStateWithAnimation(LauncherState fromState, LauncherState toState,
AnimatorSet anim, AnimationLayerSet layerViews, AnimationConfig config) {
long duration = config.getDuration(toState == LauncherState.NORMAL
? fromState.transitionDuration : toState.transitionDuration);
public void setStateWithAnimation(LauncherState toState, AnimatorSet anim,
AnimationLayerSet layerViews, AnimationConfig config) {
AnimatedPropertySetter propertySetter =
new AnimatedPropertySetter(duration, layerViews, anim);
new AnimatedPropertySetter(config.duration, layerViews, anim);
setWorkspaceProperty(toState, propertySetter);
}
@@ -133,9 +133,9 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
mNoIntercept = false;
mTouchEventStartedOnHotseat = mLauncher.getDragLayer().isEventOverHotseat(ev);
if (!mLauncher.isInState(LauncherState.ALL_APPS) && mLauncher.getWorkspace().workspaceInModalState()) {
if (!mLauncher.isInState(ALL_APPS) && !mLauncher.isInState(NORMAL)) {
mNoIntercept = true;
} else if (mLauncher.isInState(LauncherState.ALL_APPS) &&
} else if (mLauncher.isInState(ALL_APPS) &&
!mAppsView.shouldContainerScroll(ev)) {
mNoIntercept = true;
} else if (AbstractFloatingView.getTopOpenView(mLauncher) != null) {
@@ -147,7 +147,7 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect
boolean ignoreSlopWhenSettling = false;
if (mDetector.isIdleState()) {
if (mLauncher.isInState(LauncherState.ALL_APPS)) {
if (mLauncher.isInState(ALL_APPS)) {
directionsToDetectScroll |= SwipeDetector.DIRECTION_NEGATIVE;
} else {
directionsToDetectScroll |= SwipeDetector.DIRECTION_POSITIVE;
@@ -230,7 +230,7 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect
if (fling) {
if (velocity < 0) {
calculateDuration(velocity, mAppsView.getTranslationY());
if (!mLauncher.isInState(LauncherState.ALL_APPS)) {
if (!mLauncher.isInState(ALL_APPS)) {
logSwipeOnContainer(Touch.FLING, Direction.UP, containerType);
}
mLauncher.getStateManager().goToState(ALL_APPS);
@@ -241,7 +241,7 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect
}
} else {
calculateDuration(velocity, Math.abs(mShiftRange - mAppsView.getTranslationY()));
if (mLauncher.isInState(LauncherState.ALL_APPS)) {
if (mLauncher.isInState(ALL_APPS)) {
logSwipeOnContainer(Touch.FLING, Direction.DOWN, ContainerType.ALLAPPS);
}
mLauncher.getStateManager().goToState(NORMAL);
@@ -250,13 +250,13 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect
} else {
if (mAppsView.getTranslationY() > mShiftRange / 2) {
calculateDuration(velocity, Math.abs(mShiftRange - mAppsView.getTranslationY()));
if (mLauncher.isInState(LauncherState.ALL_APPS)) {
if (mLauncher.isInState(ALL_APPS)) {
logSwipeOnContainer(Touch.SWIPE, Direction.DOWN, ContainerType.ALLAPPS);
}
mLauncher.getStateManager().goToState(NORMAL);
} else {
calculateDuration(velocity, Math.abs(mAppsView.getTranslationY()));
if (!mLauncher.isInState(LauncherState.ALL_APPS)) {
if (!mLauncher.isInState(ALL_APPS)) {
logSwipeOnContainer(Touch.SWIPE, Direction.UP, containerType);
}
mLauncher.getStateManager().goToState(ALL_APPS);
@@ -403,7 +403,7 @@ public class AllAppsTransitionController implements TouchController, SwipeDetect
outConfig.shouldPost = false;
}
outConfig.overrideDuration(mAnimationDuration);
outConfig.duration = mAnimationDuration;
ObjectAnimator anim = ObjectAnimator.ofFloat(this, PROGRESS, mProgress, progress);
anim.setDuration(mAnimationDuration);
anim.setInterpolator(interpolator);