Register OnAttachStateChangeListener before attaching to container.

If we do the reverse, there is a change onAttach will occur before the
callback is registered and invokable (e.g. overlay window already exists
for EDU).

Test: Manual
Fix: 299335210
Flag: None
Change-Id: Ic4befe900c9582e1b01c2bc4699b431f95efa617
This commit is contained in:
Brian Isganitis
2023-09-06 20:40:54 +00:00
parent a0e0069cbd
commit 503f04f86d

View File

@@ -21,12 +21,16 @@ import android.animation.Animator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Interpolator;
import android.window.OnBackInvokedDispatcher;
import androidx.annotation.Nullable;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable;
import com.android.launcher3.R;
@@ -40,8 +44,11 @@ import com.android.launcher3.views.AbstractSlideInView;
/** Wrapper for taskbar all apps with slide-in behavior. */
public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverlayContext>
implements Insettable, DeviceProfile.OnDeviceProfileChangeListener {
private final Handler mHandler;
private TaskbarAllAppsContainerView mAppsView;
private float mShiftRange;
private @Nullable Runnable mShowOnFullyAttachedToWindowRunnable;
// Initialized in init.
private TaskbarAllAppsCallbacks mAllAppsCallbacks;
@@ -53,6 +60,7 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverla
public TaskbarAllAppsSlideInView(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
mHandler = new Handler(Looper.myLooper());
}
void init(TaskbarAllAppsCallbacks callbacks) {
@@ -65,14 +73,14 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverla
return;
}
mIsOpen = true;
attachToContainer();
addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View v) {
removeOnAttachStateChangeListener(this);
// Wait for view and its descendants to be fully attached before starting open.
post(() -> showOnFullyAttachedToWindow(animate));
mShowOnFullyAttachedToWindowRunnable = () -> showOnFullyAttachedToWindow(animate);
mHandler.post(mShowOnFullyAttachedToWindowRunnable);
}
@Override
@@ -80,6 +88,7 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverla
removeOnAttachStateChangeListener(this);
}
});
attachToContainer();
}
private void showOnFullyAttachedToWindow(boolean animate) {
@@ -114,6 +123,10 @@ public class TaskbarAllAppsSlideInView extends AbstractSlideInView<TaskbarOverla
@Override
protected void handleClose(boolean animate) {
if (mShowOnFullyAttachedToWindowRunnable != null) {
mHandler.removeCallbacks(mShowOnFullyAttachedToWindowRunnable);
mShowOnFullyAttachedToWindowRunnable = null;
}
if (mIsOpen) {
mAllAppsCallbacks.onAllAppsTransitionStart(false);
}