Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 828154a2 authored by Sunny Goyal's avatar Sunny Goyal Committed by Brian Isganitis
Browse files

Fixing widget not laid-out properly in preview

Bug: 185306338
Test: Manual
Change-Id: Ib1ec8a53e4701f6813813b86bf481b837127a909
Merged-In: Ib1ec8a53e4701f6813813b86bf481b837127a909
parent d1d67137
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import android.view.ViewGroup;
import com.android.launcher3.CellLayout.ContainerType;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.widget.LauncherAppWidgetHostView;
import com.android.launcher3.widget.NavigableAppWidgetHostView;

public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.FolderIconParent {
    static final String TAG = "ShortcutAndWidgetContainer";
@@ -104,9 +104,9 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.

    public void setupLp(View child) {
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
        if (child instanceof LauncherAppWidgetHostView) {
        if (child instanceof NavigableAppWidgetHostView) {
            DeviceProfile profile = mActivity.getDeviceProfile();
            ((LauncherAppWidgetHostView) child).getWidgetInset(profile, mTempRect);
            ((NavigableAppWidgetHostView) child).getWidgetInset(profile, mTempRect);
            lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
                    profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing, mTempRect);
        } else {
@@ -129,8 +129,8 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
        final DeviceProfile dp = mActivity.getDeviceProfile();

        if (child instanceof LauncherAppWidgetHostView) {
            ((LauncherAppWidgetHostView) child).getWidgetInset(dp, mTempRect);
        if (child instanceof NavigableAppWidgetHostView) {
            ((NavigableAppWidgetHostView) child).getWidgetInset(dp, mTempRect);
            lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
                    dp.appWidgetScale.x, dp.appWidgetScale.y, mBorderSpacing, mTempRect);
        } else {
@@ -178,16 +178,16 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
     */
    public void layoutChild(View child) {
        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
        if (child instanceof LauncherAppWidgetHostView) {
            LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) child;
        if (child instanceof NavigableAppWidgetHostView) {
            NavigableAppWidgetHostView nahv = (NavigableAppWidgetHostView) child;

            // Scale and center the widget to fit within its cells.
            DeviceProfile profile = mActivity.getDeviceProfile();
            float scaleX = profile.appWidgetScale.x;
            float scaleY = profile.appWidgetScale.y;

            lahv.setScaleToFit(Math.min(scaleX, scaleY));
            lahv.setTranslationForCentering(-(lp.width - (lp.width * scaleX)) / 2.0f,
            nahv.setScaleToFit(Math.min(scaleX, scaleY));
            nahv.setTranslationForCentering(-(lp.width - (lp.width * scaleX)) / 2.0f,
                    -(lp.height - (lp.height * scaleY)) / 2.0f);
        }

+7 −1
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.BaseDragLayer;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
import com.android.launcher3.widget.LocalColorExtractor;
import com.android.launcher3.widget.NavigableAppWidgetHostView;
import com.android.launcher3.widget.custom.CustomWidgetManager;

import java.util.ArrayList;
@@ -372,7 +373,12 @@ public class LauncherPreviewRenderer extends ContextWrapper

    private void inflateAndAddWidgets(
            LauncherAppWidgetInfo info, LauncherAppWidgetProviderInfo providerInfo) {
        AppWidgetHostView view = new AppWidgetHostView(mContext);
        AppWidgetHostView view = new NavigableAppWidgetHostView(this) {
            @Override
            protected boolean shouldAllowDirectClick() {
                return false;
            }
        };
        view.setAppWidget(-1, providerInfo);
        view.updateAppWidget(null);
        view.setTag(info);
+1 −2
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.view.View;
import android.view.ViewDebug;
import android.view.ViewGroup;

import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Reorderable;
import com.android.launcher3.dragndrop.DraggableView;
@@ -59,7 +58,7 @@ public abstract class NavigableAppWidgetHostView extends AppWidgetHostView
    @ViewDebug.ExportedProperty(category = "launcher")
    private boolean mChildrenFocused;

    protected final BaseActivity mActivity;
    protected final ActivityContext mActivity;

    public NavigableAppWidgetHostView(Context context) {
        super(context);