Adding support for workspace state change listener
Change-Id: Id0a4bcf345ce928544f5d406f37252a00d1dc7af
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index bf8e314..b981b55 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -18,6 +18,7 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
+import android.animation.AnimatorSet;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
@@ -181,7 +182,7 @@
// State variable that indicates whether the pages are small (ie when you're
// in all apps or customize mode)
- enum State {
+ public enum State {
NORMAL (false, false),
NORMAL_HIDDEN (false, false),
SPRING_LOADED (false, true),
@@ -280,6 +281,7 @@
private WorkspaceStateTransitionAnimation mStateTransitionAnimation;
private AccessibilityDelegate mPagesAccessibilityDelegate;
+ private OnStateChangeListener mOnStateChangeListener;
/**
* Used to inflate the Workspace from XML.
@@ -337,6 +339,10 @@
}
}
+ public void setOnStateChangeListener(OnStateChangeListener listener) {
+ mOnStateChangeListener = listener;
+ }
+
// estimate the size of a widget with spans hSpan, vSpan. return MAX_VALUE for each
// dimension if unsuccessful
public int[] estimateItemSize(ItemInfo itemInfo, boolean springLoaded) {
@@ -1982,7 +1988,7 @@
public Animator setStateWithAnimation(State toState, boolean animated,
HashMap<View, Integer> layerViews) {
// Create the animation to the new state
- Animator workspaceAnim = mStateTransitionAnimation.getAnimationToState(mState,
+ AnimatorSet workspaceAnim = mStateTransitionAnimation.getAnimationToState(mState,
toState, animated, layerViews);
boolean shouldNotifyWidgetChange = !mState.shouldUpdateWidget
@@ -1995,6 +2001,10 @@
mLauncher.notifyWidgetProvidersChanged();
}
+ if (mOnStateChangeListener != null) {
+ mOnStateChangeListener.prepareStateChange(toState, animated ? workspaceAnim : null);
+ }
+
return workspaceAnim;
}
@@ -4408,4 +4418,14 @@
});
}
}
+
+ public interface OnStateChangeListener {
+
+ /**
+ * Called when the workspace state is changing.
+ * @param toState final state
+ * @param targetAnim animation which will be played during the transition or null.
+ */
+ void prepareStateChange(State toState, AnimatorSet targetAnim);
+ }
}