Merge "Refactor InsettableFrameLayout/DragLayer and add StateListener interface." into ub-launcher3-master
diff --git a/src/com/android/launcher3/InsettableFrameLayout.java b/src/com/android/launcher3/InsettableFrameLayout.java
index be76490..60f5ca2 100644
--- a/src/com/android/launcher3/InsettableFrameLayout.java
+++ b/src/com/android/launcher3/InsettableFrameLayout.java
@@ -9,8 +9,7 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;
-public class InsettableFrameLayout extends FrameLayout implements
- ViewGroup.OnHierarchyChangeListener, Insettable {
+public class InsettableFrameLayout extends FrameLayout implements Insettable {
@ViewDebug.ExportedProperty(category = "launcher")
protected Rect mInsets = new Rect();
@@ -21,7 +20,6 @@
public InsettableFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
- setOnHierarchyChangeListener(this);
}
public void setFrameLayoutChildInsets(View child, Rect newInsets, Rect oldInsets) {
@@ -95,12 +93,8 @@
}
@Override
- public void onChildViewAdded(View parent, View child) {
+ public void onViewAdded(View child) {
+ super.onViewAdded(child);
setFrameLayoutChildInsets(child, mInsets, new Rect());
}
-
- @Override
- public void onChildViewRemoved(View parent, View child) {
- }
-
}
diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java
index f016e8d..3b58ed8 100644
--- a/src/com/android/launcher3/LauncherStateManager.java
+++ b/src/com/android/launcher3/LauncherStateManager.java
@@ -25,7 +25,6 @@
import android.os.Looper;
import android.view.View;
-import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
@@ -83,6 +82,8 @@
private StateHandler[] mStateHandlers;
private LauncherState mState = NORMAL;
+ private StateListener mStateListener;
+
public LauncherStateManager(Launcher l) {
mUiHandler = new Handler(Looper.getMainLooper());
mLauncher = l;
@@ -99,6 +100,10 @@
return mStateHandlers;
}
+ public void setStateListener(StateListener stateListener) {
+ mStateListener = stateListener;
+ }
+
/**
* @see #goToState(LauncherState, boolean, Runnable)
*/
@@ -157,6 +162,9 @@
for (StateHandler handler : getStateHandlers()) {
handler.setState(state);
}
+ if (mStateListener != null) {
+ mStateListener.onStateSetImmediately(state);
+ }
mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
// Run any queued runnable
@@ -210,6 +218,17 @@
public void onAnimationStart(Animator animation) {
// Change the internal state only when the transition actually starts
setState(state);
+ if (mStateListener != null) {
+ mStateListener.onStateTransitionStart(state);
+ }
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ if (mStateListener != null) {
+ mStateListener.onStateTransitionComplete(mState);
+ }
}
@Override
@@ -304,4 +323,15 @@
void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
AnimatorSet anim, AnimationConfig config);
}
+
+ public interface StateListener {
+
+ /**
+ * Called when the state is set without an animation.
+ */
+ void onStateSetImmediately(LauncherState state);
+
+ void onStateTransitionStart(LauncherState toState);
+ void onStateTransitionComplete(LauncherState finalState);
+ }
}
diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java
index 8189b23..9f9822c 100644
--- a/src/com/android/launcher3/dragndrop/DragLayer.java
+++ b/src/com/android/launcher3/dragndrop/DragLayer.java
@@ -703,13 +703,14 @@
}
@Override
- public void onChildViewAdded(View parent, View child) {
- super.onChildViewAdded(parent, child);
+ public void onViewAdded(View child) {
+ super.onViewAdded(child);
updateChildIndices();
}
@Override
- public void onChildViewRemoved(View parent, View child) {
+ public void onViewRemoved(View child) {
+ super.onViewRemoved(child);
updateChildIndices();
}