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

Commit 037a5362 authored by Yogisha Dixit's avatar Yogisha Dixit
Browse files

Show resize frame when widget is added.

I referenced the code in Workspace.java that updates the widget view's
layout params before showing the resize frame.

Test: manual, AddWidgetTest and AddConfigWidgetTest tapl tests
Bug: 183437963
Change-Id: I6655917878fa22d6084b4bf39fc0661e7278d6f9
parent 9b8932f5
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -262,6 +262,14 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
            }
        }

        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) mWidgetView.getLayoutParams();
        ItemInfo widgetInfo = (ItemInfo) mWidgetView.getTag();
        lp.cellX = lp.tmpCellX = widgetInfo.cellX;
        lp.cellY = lp.tmpCellY = widgetInfo.cellY;
        lp.cellHSpan = widgetInfo.spanX;
        lp.cellVSpan = widgetInfo.spanY;
        lp.isLockedToGrid = true;

        // When we create the resize frame, we first mark all cells as unoccupied. The appropriate
        // cells (same if not resized, or different) will be marked as occupied when the resize
        // frame is dismissed.
@@ -270,7 +278,7 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
        mLauncher.getStatsLogManager()
                .logger()
                .withInstanceId(logInstanceId)
                .withItemInfo((ItemInfo) mWidgetView.getTag())
                .withItemInfo(widgetInfo)
                .log(LAUNCHER_WIDGET_RESIZE_STARTED);

        setOnKeyListener(this);
+34 −0
Original line number Diff line number Diff line
@@ -1347,6 +1347,40 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
        prepareAppWidget(hostView, launcherInfo);
        mWorkspace.addInScreen(hostView, launcherInfo);
        announceForAccessibility(R.string.item_added_to_workspace);

        // Show the widget resize frame.
        if (hostView instanceof LauncherAppWidgetHostView) {
            final LauncherAppWidgetHostView launcherHostView = (LauncherAppWidgetHostView) hostView;
            CellLayout cellLayout = getCellLayout(launcherInfo.container, launcherInfo.screenId);
            if (mStateManager.getState() == NORMAL) {
                // Show resize frame once the widget layout is drawn.
                View.OnLayoutChangeListener onLayoutChangeListener =
                        new View.OnLayoutChangeListener() {
                            @Override
                            public void onLayoutChange(View view, int left, int top, int right,
                                    int bottom, int oldLeft, int oldTop, int oldRight,
                                    int oldBottom) {
                                AppWidgetResizeFrame.showForWidget(launcherHostView, cellLayout);
                                launcherHostView.removeOnLayoutChangeListener(this);
                            }
                        };
                launcherHostView.addOnLayoutChangeListener(onLayoutChangeListener);
                // There is a small chance that the layout was already drawn before the layout
                // change listener was registered, which means that the resize frame wouldn't be
                // shown. Directly call requestLayout to force a layout change.
                launcherHostView.requestLayout();
            } else {
                mStateManager.addStateListener(new StateManager.StateListener<LauncherState>() {
                    @Override
                    public void onStateTransitionComplete(LauncherState finalState) {
                        if (mPrevLauncherState == SPRING_LOADED && finalState == NORMAL) {
                            AppWidgetResizeFrame.showForWidget(launcherHostView, cellLayout);
                            mStateManager.removeStateListener(this);
                        }
                    }
                });
            }
        }
    }

    private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
+2 −0
Original line number Diff line number Diff line
@@ -102,6 +102,8 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest {

        setResult(acceptConfig);
        if (acceptConfig) {
            // Dismiss widget resize frame.
            mDevice.pressHome();
            Wait.atMost("", new WidgetSearchCondition(), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
            assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
        } else {
+2 −0
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ public class AddWidgetTest extends AbstractLauncherUiTest {
                openAllWidgets().
                getWidget(widgetInfo.getLabel(mTargetContext.getPackageManager())).
                dragToWorkspace(false, false);
        // Dismiss widget resize frame.
        mDevice.pressHome();

        assertTrue(mActivityMonitor.itemExists(
                (info, view) -> info instanceof LauncherAppWidgetInfo &&