Merge "Fix LayoutParams cast exception in drag-n-drop" into sc-dev

This commit is contained in:
Steven Ng 2021-05-05 18:07:32 +00:00 committed by Android (Google) Code Review
commit f8af753b6a
1 changed files with 23 additions and 0 deletions

View File

@ -57,6 +57,22 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
private final View[] mDragHandles = new View[HANDLE_COUNT];
private final List<Rect> mSystemGestureExclusionRects = new ArrayList<>(HANDLE_COUNT);
private final OnAttachStateChangeListener mWidgetViewAttachStateChangeListener =
new OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View view) {
// Do nothing
}
@Override
public void onViewDetachedFromWindow(View view) {
// When the app widget view is detached, we should close the resize frame.
// An example is when the dragging starts, the widget view is detached from
// CellLayout and then reattached to DragLayout.
close(false);
}
};
private LauncherAppWidgetHostView mWidgetView;
private CellLayout mCellLayout;
@ -177,7 +193,11 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
private void setupForWidget(LauncherAppWidgetHostView widgetView, CellLayout cellLayout,
DragLayer dragLayer) {
mCellLayout = cellLayout;
if (mWidgetView != null) {
mWidgetView.removeOnAttachStateChangeListener(mWidgetViewAttachStateChangeListener);
}
mWidgetView = widgetView;
mWidgetView.addOnAttachStateChangeListener(mWidgetViewAttachStateChangeListener);
LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo)
widgetView.getAppWidgetInfo();
mResizeMode = info.resizeMode;
@ -628,6 +648,9 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
@Override
protected void handleClose(boolean animate) {
mDragLayer.removeView(this);
if (mWidgetView != null) {
mWidgetView.removeOnAttachStateChangeListener(mWidgetViewAttachStateChangeListener);
}
}
@Override