Merge "Render preview layout in full widgets sheet and bottom widgets sheet" into sc-dev
This commit is contained in:
commit
36322d8621
6 files changed
+71
-10
No files matched your search
@@ -0,0 +1,28 @@
|
||||
<?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>
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
@@ -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) {
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.view.ViewGroup;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.WidgetPreviewLoader;
|
||||
import com.android.launcher3.dragndrop.LivePreviewWidgetCell;
|
||||
import com.android.launcher3.model.WidgetItem;
|
||||
import com.android.launcher3.recyclerview.ViewHolderBinder;
|
||||
import com.android.launcher3.widget.WidgetCell;
|
||||
@@ -107,8 +108,8 @@ public class WidgetsListRowViewHolderBinder
|
||||
mLayoutInflater.inflate(R.layout.widget_list_divider, row);
|
||||
} else {
|
||||
// Add cell for even index
|
||||
WidgetCell widget = (WidgetCell) mLayoutInflater.inflate(
|
||||
R.layout.widget_cell, row, false);
|
||||
LivePreviewWidgetCell widget = (LivePreviewWidgetCell) mLayoutInflater.inflate(
|
||||
R.layout.live_preview_widget_cell, row, false);
|
||||
|
||||
// set up touch.
|
||||
widget.setOnClickListener(mIconClickListener);
|
||||
@@ -124,7 +125,8 @@ public class WidgetsListRowViewHolderBinder
|
||||
|
||||
// Bind the view in the widget horizontal tray region.
|
||||
for (int i = 0; i < infoList.size(); i++) {
|
||||
WidgetCell widget = (WidgetCell) row.getChildAt(2 * i);
|
||||
LivePreviewWidgetCell widget = (LivePreviewWidgetCell) row.getChildAt(2 * i);
|
||||
widget.reset();
|
||||
widget.applyFromCellItem(infoList.get(i), mWidgetPreviewLoader);
|
||||
widget.setApplyBitmapDeferred(mApplyBitmapDeferred);
|
||||
widget.ensurePreview();
|
||||
|
||||
Reference in new issue
Block a user