Refactor InsettableFrameLayout/DragLayer and add StateListener interface.
Bug: 65387919 Change-Id: I5eb94c0f3962d44f63af3efc92d852e019bba711
This commit is contained in:
@@ -9,8 +9,7 @@ import android.view.ViewDebug;
|
||||
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 class InsettableFrameLayout extends FrameLayout implements
|
||||
|
||||
public InsettableFrameLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setOnHierarchyChangeListener(this);
|
||||
}
|
||||
|
||||
public void setFrameLayoutChildInsets(View child, Rect newInsets, Rect oldInsets) {
|
||||
@@ -95,12 +93,8 @@ public class InsettableFrameLayout extends FrameLayout implements
|
||||
}
|
||||
|
||||
@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) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.os.Handler;
|
||||
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 @@ public class LauncherStateManager {
|
||||
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 @@ public class LauncherStateManager {
|
||||
return mStateHandlers;
|
||||
}
|
||||
|
||||
public void setStateListener(StateListener stateListener) {
|
||||
mStateListener = stateListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #goToState(LauncherState, boolean, Runnable)
|
||||
*/
|
||||
@@ -157,6 +162,9 @@ public class LauncherStateManager {
|
||||
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 class LauncherStateManager {
|
||||
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 @@ public class LauncherStateManager {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -703,13 +703,14 @@ public class DragLayer extends InsettableFrameLayout {
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user