use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.
the class Launcher method getFirstMatchForAppClose.
/**
* Similar to {@link #getFirstMatch} but optimized to finding a suitable view for the app close
* animation.
*
* @param preferredItemId The id of the preferred item to match to if it exists.
* @param packageName The package name of the app to match.
* @param user The user of the app to match.
*/
public View getFirstMatchForAppClose(int preferredItemId, String packageName, UserHandle user) {
final ItemInfoMatcher preferredItem = (info, cn) -> info != null && info.id == preferredItemId;
final ItemInfoMatcher packageAndUserAndApp = (info, cn) -> info != null && info.itemType == ITEM_TYPE_APPLICATION && info.user.equals(user) && info.getTargetComponent() != null && TextUtils.equals(info.getTargetComponent().getPackageName(), packageName);
if (isInState(LauncherState.ALL_APPS)) {
return getFirstMatch(Collections.singletonList(mAppsView.getActiveRecyclerView()), preferredItem, packageAndUserAndApp);
} else {
List<ViewGroup> containers = new ArrayList<>(mWorkspace.getPanelCount() + 1);
containers.add(mWorkspace.getHotseat().getShortcutsAndWidgets());
mWorkspace.forEachVisiblePage(page -> containers.add(((CellLayout) page).getShortcutsAndWidgets()));
// Order: Preferred item by itself or in folder, then by matching package/user
if (ADAPTIVE_ICON_WINDOW_ANIM.get()) {
return getFirstMatch(containers, preferredItem, forFolderMatch(preferredItem), packageAndUserAndApp, forFolderMatch(packageAndUserAndApp));
} else {
// FolderAdaptiveIcon as the background.
return getFirstMatch(containers, preferredItem, packageAndUserAndApp);
}
}
}
use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.
the class Workspace method onDropCompleted.
/**
* Called at the end of a drag which originated on the workspace.
*/
public void onDropCompleted(final View target, final DragObject d, final boolean success) {
if (success) {
if (target != this && mDragInfo != null) {
removeWorkspaceItem(mDragInfo.cell);
}
} else if (mDragInfo != null) {
// When drag is cancelled, reattach content view back to its original parent.
if (mDragInfo.cell instanceof LauncherAppWidgetHostView && d.dragView != null) {
d.dragView.detachContentView(/* reattachToPreviousParent= */
true);
}
final CellLayout cellLayout = mLauncher.getCellLayout(mDragInfo.container, mDragInfo.screenId);
if (cellLayout != null) {
cellLayout.onDropChild(mDragInfo.cell);
} else if (FeatureFlags.IS_STUDIO_BUILD) {
throw new RuntimeException("Invalid state: cellLayout == null in " + "Workspace#onDropCompleted. Please file a bug. ");
}
}
View cell = getHomescreenIconByItemId(d.originalDragInfo.id);
if (d.cancelled && cell != null) {
cell.setVisibility(VISIBLE);
}
mDragInfo = null;
}
use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.
the class Workspace method addToExistingFolderIfNecessary.
boolean addToExistingFolderIfNecessary(View newView, CellLayout target, int[] targetCell, float distance, DragObject d, boolean external) {
if (distance > target.getFolderCreationRadius(targetCell))
return false;
View dropOverView = target.getChildAt(targetCell[0], targetCell[1]);
if (!mAddToExistingFolderOnDrop)
return false;
mAddToExistingFolderOnDrop = false;
if (dropOverView instanceof FolderIcon) {
FolderIcon fi = (FolderIcon) dropOverView;
if (fi.acceptDrop(d.dragInfo)) {
mStatsLogManager.logger().withItemInfo(fi.mInfo).withInstanceId(d.logInstanceId).log(LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED_ON_FOLDER_ICON);
fi.onDrop(d, false);
// if the drag started here, we need to remove it from the workspace
if (!external) {
getParentCellLayoutForView(mDragInfo.cell).removeView(mDragInfo.cell);
}
return true;
}
}
return false;
}
use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.
the class AppWidgetResizeFrame method setupForWidget.
private void setupForWidget(LauncherAppWidgetHostView widgetView, CellLayout cellLayout, DragLayer dragLayer) {
mCellLayout = cellLayout;
if (mWidgetView != null) {
mWidgetView.removeOnAttachStateChangeListener(mWidgetViewAttachStateChangeListener);
}
mWidgetView = widgetView;
mWidgetView.addOnAttachStateChangeListener(mWidgetViewAttachStateChangeListener);
LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) widgetView.getAppWidgetInfo();
mDragLayer = dragLayer;
mMinHSpan = info.minSpanX;
mMinVSpan = info.minSpanY;
mMaxHSpan = info.maxSpanX;
mMaxVSpan = info.maxSpanY;
mWidgetPadding = getDefaultPaddingForWidget(getContext(), widgetView.getAppWidgetInfo().provider, null);
mReconfigureButton = (ImageButton) findViewById(R.id.widget_reconfigure_button);
if (info.isReconfigurable()) {
mReconfigureButton.setVisibility(VISIBLE);
mReconfigureButton.setOnClickListener(view -> {
mLauncher.setWaitingForResult(PendingRequestArgs.forWidgetInfo(mWidgetView.getAppWidgetId(), /* widgetHandler= */
null, (ItemInfo) mWidgetView.getTag()));
mLauncher.getAppWidgetHost().startConfigActivity(mLauncher, mWidgetView.getAppWidgetId(), Launcher.REQUEST_RECONFIGURE_APPWIDGET);
});
if (!hasSeenReconfigurableWidgetEducationTip()) {
post(() -> {
if (showReconfigurableWidgetEducationTip() != null) {
mLauncher.getSharedPrefs().edit().putBoolean(KEY_RECONFIGURABLE_WIDGET_EDUCATION_TIP_SEEN, true).apply();
}
});
}
}
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.
mCellLayout.markCellsAsUnoccupiedForView(mWidgetView);
mLauncher.getStatsLogManager().logger().withInstanceId(logInstanceId).withItemInfo(widgetInfo).log(LAUNCHER_WIDGET_RESIZE_STARTED);
setOnKeyListener(this);
}
use of com.android.launcher3.CellLayout in project android_packages_apps_Launcher3 by AOSPA.
the class AppWidgetResizeFrame method updateInvalidResizeEffect.
private void updateInvalidResizeEffect(CellLayout cellLayout, CellLayout pairedCellLayout, float alpha, float springLoadedProgress, @Nullable AnimatorSet animatorSet) {
int childCount = pairedCellLayout.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = pairedCellLayout.getChildAt(i);
if (animatorSet != null) {
animatorSet.play(mFirstFrameAnimatorHelper.addTo(ObjectAnimator.ofFloat(child, ALPHA, alpha)));
} else {
child.setAlpha(alpha);
}
}
if (animatorSet != null) {
animatorSet.play(mFirstFrameAnimatorHelper.addTo(ObjectAnimator.ofFloat(cellLayout, SPRING_LOADED_PROGRESS, springLoadedProgress)));
animatorSet.play(mFirstFrameAnimatorHelper.addTo(ObjectAnimator.ofFloat(pairedCellLayout, SPRING_LOADED_PROGRESS, springLoadedProgress)));
} else {
cellLayout.setSpringLoadedProgress(springLoadedProgress);
pairedCellLayout.setSpringLoadedProgress(springLoadedProgress);
}
boolean shouldShowCellLayoutBorder = springLoadedProgress > 0f;
if (animatorSet != null) {
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
cellLayout.setIsDragOverlapping(shouldShowCellLayoutBorder);
pairedCellLayout.setIsDragOverlapping(shouldShowCellLayoutBorder);
}
});
} else {
cellLayout.setIsDragOverlapping(shouldShowCellLayoutBorder);
pairedCellLayout.setIsDragOverlapping(shouldShowCellLayoutBorder);
}
}
Aggregations