Merge "Show resize frame when widget is added." into sc-dev
This commit is contained in:
commit
419ee4599e
|
@ -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
|
// 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
|
// cells (same if not resized, or different) will be marked as occupied when the resize
|
||||||
// frame is dismissed.
|
// frame is dismissed.
|
||||||
|
@ -270,7 +278,7 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
|
||||||
mLauncher.getStatsLogManager()
|
mLauncher.getStatsLogManager()
|
||||||
.logger()
|
.logger()
|
||||||
.withInstanceId(logInstanceId)
|
.withInstanceId(logInstanceId)
|
||||||
.withItemInfo((ItemInfo) mWidgetView.getTag())
|
.withItemInfo(widgetInfo)
|
||||||
.log(LAUNCHER_WIDGET_RESIZE_STARTED);
|
.log(LAUNCHER_WIDGET_RESIZE_STARTED);
|
||||||
|
|
||||||
setOnKeyListener(this);
|
setOnKeyListener(this);
|
||||||
|
|
|
@ -1347,6 +1347,40 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
|
||||||
prepareAppWidget(hostView, launcherInfo);
|
prepareAppWidget(hostView, launcherInfo);
|
||||||
mWorkspace.addInScreen(hostView, launcherInfo);
|
mWorkspace.addInScreen(hostView, launcherInfo);
|
||||||
announceForAccessibility(R.string.item_added_to_workspace);
|
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) {
|
private void prepareAppWidget(AppWidgetHostView hostView, LauncherAppWidgetInfo item) {
|
||||||
|
|
|
@ -102,6 +102,8 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest {
|
||||||
|
|
||||||
setResult(acceptConfig);
|
setResult(acceptConfig);
|
||||||
if (acceptConfig) {
|
if (acceptConfig) {
|
||||||
|
// Dismiss widget resize frame.
|
||||||
|
mDevice.pressHome();
|
||||||
Wait.atMost("", new WidgetSearchCondition(), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
|
Wait.atMost("", new WidgetSearchCondition(), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
|
||||||
assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
|
assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -58,6 +58,8 @@ public class AddWidgetTest extends AbstractLauncherUiTest {
|
||||||
openAllWidgets().
|
openAllWidgets().
|
||||||
getWidget(widgetInfo.getLabel(mTargetContext.getPackageManager())).
|
getWidget(widgetInfo.getLabel(mTargetContext.getPackageManager())).
|
||||||
dragToWorkspace(false, false);
|
dragToWorkspace(false, false);
|
||||||
|
// Dismiss widget resize frame.
|
||||||
|
mDevice.pressHome();
|
||||||
|
|
||||||
assertTrue(mActivityMonitor.itemExists(
|
assertTrue(mActivityMonitor.itemExists(
|
||||||
(info, view) -> info instanceof LauncherAppWidgetInfo &&
|
(info, view) -> info instanceof LauncherAppWidgetInfo &&
|
||||||
|
|
Loading…
Reference in New Issue