Fix app widget preview layout drag-n-drop & rendering

1. Before this CL, preview layouts are not rendered in both the
   BottomWidgetSheet and SearchPopupSheet because the preview
   width & height are not set correctly.
2. Also applies the right padding to preview layouts.

Bug: 185374336
Test: Drag-n-drop preview layout from the full widgets picker,
      the bottom widgets picker and the search widgets picker.

Change-Id: I2b6303bfe4eb86a4935a5569f6107e9d46448902
This commit is contained in:
Steven Ng committed 2021-04-16 10:41:33 +01:00
1 parent 0a19747cae
commit f089f741ad
3 files changed
+49 -24

No files matched your search

@@ -20,6 +20,8 @@ import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
/**
* View group managing the widget preview: either using a {@link WidgetImageView} or an actual
* {@link LauncherAppWidgetHostView}.
@@ -43,4 +45,27 @@ public class WidgetCellPreview extends FrameLayout {
return true;
}
/** Returns {@code true} if this container has a preview layout. */
public boolean hasPreviewLayout() {
for (int i = 0; i < getChildCount(); i++) {
if (getChildAt(i) instanceof LauncherAppWidgetHostView) {
return true;
}
}
return false;
}
/**
* Returns {@link LauncherAppWidgetHostView} if this container has a preview layout. Otherwise,
* returns null.
*/
@Nullable
public LauncherAppWidgetHostView getPreviewLayout() {
for (int i = 0; i < getChildCount(); i++) {
if (getChildAt(i) instanceof LauncherAppWidgetHostView) {
return (LauncherAppWidgetHostView) getChildAt(i);
}
}
return null;
}
}