Loading res/layout/live_preview_widget_cell.xml 0 → 100644 +28 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2021 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <com.android.launcher3.dragndrop.LivePreviewWidgetCell xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" android:focusable="true" android:background="?android:attr/colorPrimaryDark" android:gravity="center_horizontal"> <include layout="@layout/widget_cell_content" /> </com.android.launcher3.dragndrop.LivePreviewWidgetCell> No newline at end of file src/com/android/launcher3/dragndrop/LivePreviewWidgetCell.java +23 −0 Original line number Diff line number Diff line Loading @@ -10,7 +10,9 @@ import android.widget.RemoteViews; import com.android.launcher3.BaseActivity; import com.android.launcher3.DeviceProfile; import com.android.launcher3.LauncherAppWidgetProviderInfo; import com.android.launcher3.WidgetPreviewLoader; import com.android.launcher3.icons.BitmapRenderer; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.widget.WidgetCell; /** Loading @@ -36,6 +38,15 @@ public class LivePreviewWidgetCell extends WidgetCell { mPreview = view; } public RemoteViews getPreview() { return mPreview; } /** Resets any resource. This should be called before recycling this view. */ public void reset() { mPreview = null; } @Override public void ensurePreview() { if (mPreview != null && mActiveRequest == null) { Loading @@ -49,6 +60,18 @@ public class LivePreviewWidgetCell extends WidgetCell { super.ensurePreview(); } @Override public void applyFromCellItem(WidgetItem item, WidgetPreviewLoader loader) { if (mPreview == null && item.widgetInfo != null && item.widgetInfo.previewLayout != View.NO_ID) { mPreview = new RemoteViews(item.widgetInfo.provider.getPackageName(), item.widgetInfo.previewLayout); } super.applyFromCellItem(item, loader); } /** * Generates a bitmap by inflating {@param views}. * @see com.android.launcher3.WidgetPreviewLoader#generateWidgetPreview Loading src/com/android/launcher3/widget/BaseWidgetSheet.java +8 −3 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import com.android.launcher3.DropTarget.DragObject; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.dragndrop.LivePreviewWidgetCell; import com.android.launcher3.popup.PopupDataProvider; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.TestProtocol; Loading Loading @@ -99,12 +100,16 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView return false; } PendingItemDragHelper dragHelper = new PendingItemDragHelper(v); if (v instanceof LivePreviewWidgetCell) { dragHelper.setPreview(((LivePreviewWidgetCell) v).getPreview()); } int[] loc = new int[2]; getPopupContainer().getLocationInDragLayer(image, loc); new PendingItemDragHelper(v).startDrag( image.getBitmapBounds(), image.getBitmap().getWidth(), image.getWidth(), new Point(loc[0], loc[1]), this, new DragOptions()); dragHelper.startDrag(image.getBitmapBounds(), image.getBitmap().getWidth(), image.getWidth(), new Point(loc[0], loc[1]), this, new DragOptions()); close(true); return true; } Loading src/com/android/launcher3/widget/PendingItemDragHelper.java +4 −2 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ import android.graphics.drawable.Drawable; import android.view.View; import android.widget.RemoteViews; import androidx.annotation.Nullable; import com.android.launcher3.DeviceProfile; import com.android.launcher3.DragSource; import com.android.launcher3.Launcher; Loading @@ -48,14 +50,14 @@ public class PendingItemDragHelper extends DragPreviewProvider { private final PendingAddItemInfo mAddInfo; private int[] mEstimatedCellSize; private RemoteViews mPreview; @Nullable private RemoteViews mPreview; public PendingItemDragHelper(View view) { super(view); mAddInfo = (PendingAddItemInfo) view.getTag(); } public void setPreview(RemoteViews preview) { public void setPreview(@Nullable RemoteViews preview) { mPreview = preview; } Loading src/com/android/launcher3/widget/WidgetsBottomSheet.java +3 −2 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.ResourceUtils; import com.android.launcher3.anim.PendingAnimation; import com.android.launcher3.dragndrop.LivePreviewWidgetCell; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.util.PackageUserKey; Loading Loading @@ -136,8 +137,8 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { } protected WidgetCell addItemCell(ViewGroup parent) { WidgetCell widget = (WidgetCell) LayoutInflater.from(getContext()).inflate( R.layout.widget_cell, parent, false); LivePreviewWidgetCell widget = (LivePreviewWidgetCell) LayoutInflater.from( getContext()).inflate(R.layout.live_preview_widget_cell, parent, false); widget.setOnClickListener(this); widget.setOnLongClickListener(this); Loading Loading
res/layout/live_preview_widget_cell.xml 0 → 100644 +28 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2021 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <com.android.launcher3.dragndrop.LivePreviewWidgetCell xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" android:focusable="true" android:background="?android:attr/colorPrimaryDark" android:gravity="center_horizontal"> <include layout="@layout/widget_cell_content" /> </com.android.launcher3.dragndrop.LivePreviewWidgetCell> No newline at end of file
src/com/android/launcher3/dragndrop/LivePreviewWidgetCell.java +23 −0 Original line number Diff line number Diff line Loading @@ -10,7 +10,9 @@ import android.widget.RemoteViews; import com.android.launcher3.BaseActivity; import com.android.launcher3.DeviceProfile; import com.android.launcher3.LauncherAppWidgetProviderInfo; import com.android.launcher3.WidgetPreviewLoader; import com.android.launcher3.icons.BitmapRenderer; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.widget.WidgetCell; /** Loading @@ -36,6 +38,15 @@ public class LivePreviewWidgetCell extends WidgetCell { mPreview = view; } public RemoteViews getPreview() { return mPreview; } /** Resets any resource. This should be called before recycling this view. */ public void reset() { mPreview = null; } @Override public void ensurePreview() { if (mPreview != null && mActiveRequest == null) { Loading @@ -49,6 +60,18 @@ public class LivePreviewWidgetCell extends WidgetCell { super.ensurePreview(); } @Override public void applyFromCellItem(WidgetItem item, WidgetPreviewLoader loader) { if (mPreview == null && item.widgetInfo != null && item.widgetInfo.previewLayout != View.NO_ID) { mPreview = new RemoteViews(item.widgetInfo.provider.getPackageName(), item.widgetInfo.previewLayout); } super.applyFromCellItem(item, loader); } /** * Generates a bitmap by inflating {@param views}. * @see com.android.launcher3.WidgetPreviewLoader#generateWidgetPreview Loading
src/com/android/launcher3/widget/BaseWidgetSheet.java +8 −3 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import com.android.launcher3.DropTarget.DragObject; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.dragndrop.LivePreviewWidgetCell; import com.android.launcher3.popup.PopupDataProvider; import com.android.launcher3.testing.TestLogging; import com.android.launcher3.testing.TestProtocol; Loading Loading @@ -99,12 +100,16 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView return false; } PendingItemDragHelper dragHelper = new PendingItemDragHelper(v); if (v instanceof LivePreviewWidgetCell) { dragHelper.setPreview(((LivePreviewWidgetCell) v).getPreview()); } int[] loc = new int[2]; getPopupContainer().getLocationInDragLayer(image, loc); new PendingItemDragHelper(v).startDrag( image.getBitmapBounds(), image.getBitmap().getWidth(), image.getWidth(), new Point(loc[0], loc[1]), this, new DragOptions()); dragHelper.startDrag(image.getBitmapBounds(), image.getBitmap().getWidth(), image.getWidth(), new Point(loc[0], loc[1]), this, new DragOptions()); close(true); return true; } Loading
src/com/android/launcher3/widget/PendingItemDragHelper.java +4 −2 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ import android.graphics.drawable.Drawable; import android.view.View; import android.widget.RemoteViews; import androidx.annotation.Nullable; import com.android.launcher3.DeviceProfile; import com.android.launcher3.DragSource; import com.android.launcher3.Launcher; Loading @@ -48,14 +50,14 @@ public class PendingItemDragHelper extends DragPreviewProvider { private final PendingAddItemInfo mAddInfo; private int[] mEstimatedCellSize; private RemoteViews mPreview; @Nullable private RemoteViews mPreview; public PendingItemDragHelper(View view) { super(view); mAddInfo = (PendingAddItemInfo) view.getTag(); } public void setPreview(RemoteViews preview) { public void setPreview(@Nullable RemoteViews preview) { mPreview = preview; } Loading
src/com/android/launcher3/widget/WidgetsBottomSheet.java +3 −2 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.ResourceUtils; import com.android.launcher3.anim.PendingAnimation; import com.android.launcher3.dragndrop.LivePreviewWidgetCell; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.util.PackageUserKey; Loading Loading @@ -136,8 +137,8 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { } protected WidgetCell addItemCell(ViewGroup parent) { WidgetCell widget = (WidgetCell) LayoutInflater.from(getContext()).inflate( R.layout.widget_cell, parent, false); LivePreviewWidgetCell widget = (LivePreviewWidgetCell) LayoutInflater.from( getContext()).inflate(R.layout.live_preview_widget_cell, parent, false); widget.setOnClickListener(this); widget.setOnLongClickListener(this); Loading