use of com.android.launcher3.widget.PendingAddWidgetInfo in project android_packages_apps_Launcher3 by crdroidandroid.
the class Workspace method acceptDrop.
/**
* {@inheritDoc}
*/
@Override
public boolean acceptDrop(DragObject d) {
// If it's an external drop (e.g. from All Apps), check if it should be accepted
CellLayout dropTargetLayout = mDropToLayout;
if (d.dragSource != this) {
// Don't accept the drop if we're not over a screen at time of drop
if (dropTargetLayout == null) {
return false;
}
if (!transitionStateShouldAllowDrop())
return false;
mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
// We want the point to be mapped to the dragTarget.
mapPointFromDropLayout(dropTargetLayout, mDragViewVisualCenter);
int spanX;
int spanY;
if (mDragInfo != null) {
final CellLayout.CellInfo dragCellInfo = mDragInfo;
spanX = dragCellInfo.spanX;
spanY = dragCellInfo.spanY;
} else {
spanX = d.dragInfo.spanX;
spanY = d.dragInfo.spanY;
}
int minSpanX = spanX;
int minSpanY = spanY;
if (d.dragInfo instanceof PendingAddWidgetInfo) {
minSpanX = ((PendingAddWidgetInfo) d.dragInfo).minSpanX;
minSpanY = ((PendingAddWidgetInfo) d.dragInfo).minSpanY;
}
mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, dropTargetLayout, mTargetCell);
float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell);
if (mCreateUserFolderOnDrop && willCreateUserFolder(d.dragInfo, dropTargetLayout, mTargetCell, distance, true)) {
return true;
}
if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder(d.dragInfo, dropTargetLayout, mTargetCell, distance)) {
return true;
}
int[] resultSpan = new int[2];
mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, null, mTargetCell, resultSpan, CellLayout.MODE_ACCEPT_DROP);
boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0;
// Don't accept the drop if there's no room for the item
if (!foundCell) {
onNoCellFound(dropTargetLayout);
return false;
}
}
int screenId = getIdForScreen(dropTargetLayout);
if (screenId == EXTRA_EMPTY_SCREEN_ID) {
commitExtraEmptyScreen();
}
return true;
}
use of com.android.launcher3.widget.PendingAddWidgetInfo in project android_packages_apps_Launcher3 by crdroidandroid.
the class Launcher method completeAddAppWidget.
/**
* Add a widget to the workspace.
*
* @param appWidgetId The app widget id
*/
@Thunk
void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo, AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) {
if (appWidgetInfo == null) {
appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId);
}
if (hostView == null) {
// Perform actual inflation because we're live
hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
}
LauncherAppWidgetInfo launcherInfo;
launcherInfo = new LauncherAppWidgetInfo(appWidgetId, appWidgetInfo.provider, appWidgetInfo, hostView);
launcherInfo.spanX = itemInfo.spanX;
launcherInfo.spanY = itemInfo.spanY;
launcherInfo.minSpanX = itemInfo.minSpanX;
launcherInfo.minSpanY = itemInfo.minSpanY;
launcherInfo.user = appWidgetInfo.getProfile();
if (itemInfo instanceof PendingAddWidgetInfo) {
launcherInfo.sourceContainer = ((PendingAddWidgetInfo) itemInfo).sourceContainer;
} else if (itemInfo instanceof PendingRequestArgs) {
launcherInfo.sourceContainer = ((PendingRequestArgs) itemInfo).getWidgetSourceContainer();
}
getModelWriter().addItemToDatabase(launcherInfo, itemInfo.container, itemInfo.screenId, itemInfo.cellX, itemInfo.cellY);
hostView.setVisibility(View.VISIBLE);
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);
}
}
});
}
}
}
use of com.android.launcher3.widget.PendingAddWidgetInfo in project android_packages_apps_Launcher3 by crdroidandroid.
the class WidgetUtils method createWidgetInfo.
/**
* Creates a LauncherAppWidgetInfo corresponding to {@param info}
*
* @param bindWidget if true the info is bound and a valid widgetId is assigned to
* the LauncherAppWidgetInfo
*/
public static LauncherAppWidgetInfo createWidgetInfo(LauncherAppWidgetProviderInfo info, Context targetContext, boolean bindWidget) {
LauncherAppWidgetInfo item = new LauncherAppWidgetInfo(LauncherAppWidgetInfo.NO_ID, info.provider);
item.spanX = info.minSpanX;
item.spanY = info.minSpanY;
item.minSpanX = info.minSpanX;
item.minSpanY = info.minSpanY;
item.user = info.getProfile();
item.cellX = 0;
item.cellY = 1;
item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
if (bindWidget) {
PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(info, LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY);
pendingInfo.spanX = item.spanX;
pendingInfo.spanY = item.spanY;
pendingInfo.minSpanX = item.minSpanX;
pendingInfo.minSpanY = item.minSpanY;
Bundle options = pendingInfo.getDefaultSizeOptions(targetContext);
AppWidgetHost host = new LauncherAppWidgetHost(targetContext);
int widgetId = host.allocateAppWidgetId();
if (!new WidgetManagerHelper(targetContext).bindAppWidgetIdIfAllowed(widgetId, info, options)) {
host.deleteAppWidgetId(widgetId);
throw new IllegalArgumentException("Unable to bind widget id");
}
item.appWidgetId = widgetId;
}
return item;
}
Aggregations