去掉 顶部移除和卸载
Launcher.java
protected void setupViews() {
mDragLayer = findViewById(R.id.drag_layer);
mFocusHandler = mDragLayer.getFocusIndicatorHelper();
mWorkspace = mDragLayer.findViewById(R.id.workspace);
mWorkspace.initParentViews(mDragLayer);
mOverviewPanel = findViewById(R.id.overview_panel);
mHotseat = findViewById(R.id.hotseat);
mHotseat.setWorkspace(mWorkspace);
// Setup the drag layer
mDragLayer.setup(mDragController, mWorkspace);
mWorkspace.setup(mDragController);
// Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
// default state, otherwise we will update to the wrong offsets in RTL
mWorkspace.lockWallpaperToDefaultPage();
mWorkspace.bindAndInitFirstWorkspaceScreen(null /* recycled qsb */);
if(FeatureFlags.getGmsVersion() != null && !FeatureFlags.getGmsVersion().equals("")){
if(!FeatureFlags.getGmsVersion().contains("go")){
mWorkspace.bindAndInitFirstWorkspaceScreenQsb(null /* recycled qsb */);
}
}
mDragController.addDragListener(mWorkspace);
// Get the search/delete/uninstall bar
mDropTargetBar = mDragLayer.findViewById(R.id.drop_target_bar);
// Setup Apps
mAppsView = findViewById(R.id.apps_view);
// Setup Scrim
mScrimView = findViewById(R.id.scrim_view);
//去掉移除和删除按钮
// Setup the drag controller (drop targets have to be added in reverse order in priority)
// mDropTargetBar.setup(mDragController);
mAllAppsController.setupViews(mAppsView, mScrimView);
}
Workspace.java
@Override
public void onDragStart(DragObject dragObject, DragOptions options) {
if (ENFORCE_DRAG_EVENT_ORDER) {
enforceDragParity("onDragStart", 0, 0);
}
if (mDragInfo != null && mDragInfo.cell != null) {
CellLayout layout = (CellLayout) mDragInfo.cell.getParent().getParent();
layout.markCellsAsUnoccupiedForView(mDragInfo.cell);
}
if (mOutlineProvider != null) {
if (dragObject.dragView != null) {
Bitmap preview = dragObject.dragView.getPreviewBitmap();
// The outline is used to visualize where the item will land if dropped
mOutlineProvider.generateDragOutline(preview);
}
}
updateChildrenLayersEnabled();
// Do not add a new page if it is a accessible drag which was not started by the workspace.
// We do not support accessibility drag from other sources and instead provide a direct
// action for move/add to homescreen.
// When a accessible drag is started by the folder, we only allow rearranging withing the
// folder.
boolean addNewPage = !(options.isAccessibleDrag && dragObject.dragSource != this);
if (addNewPage) {
mDeferRemoveExtraEmptyScreen = false;
addExtraEmptyScreenOnDrag();
if (dragObject.dragInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET
&& dragObject.dragSource != this) {
// When dragging a widget from different source, move to a page which has
// enough space to place this widget (after rearranging/resizing). We special case
// widgets as they cannot be placed inside a folder.
// Start at the current page and search right (on LTR) until finding a page with
// enough space. Since an empty screen is the furthest right, a page must be found.
int currentPage = getPageNearestToCenterOfScreen();
for (int pageIndex = currentPage; pageIndex < getPageCount(); pageIndex++) {
CellLayout page = (CellLayout) getPageAt(pageIndex);
if (page.hasReorderSolution(dragObject.dragInfo)) {
setCurrentPage(pageIndex);
break;
}
}
}
}
// Always enter the spring loaded mode
//移除长按移除状态
// mLauncher.getStateManager().goToState(SPRING_LOADED);
mStatsLogManager.logger().withItemInfo(dragObject.dragInfo)
.withInstanceId(dragObject.logInstanceId)
.log(LauncherEvent.LAUNCHER_ITEM_DRAG_STARTED);
}
微件新增卸载 SystemShortcut.java
` public static final Factory APP_INFO = AppInfo::new;
public static class AppInfo extends SystemShortcut {
// ... //
}
//====修改start==== 创建UNINSTALL内部对象 public static final Factory UNINSTALL = UnInstall::new;
public static class UnInstall extends SystemShortcut {
public UnInstall(BaseDraggingActivity target, ItemInfo itemInfo) {
super(R.drawable.ic_uninstall_no_shadow, R.string.app_info_drop_uninstall_label, target,
itemInfo);
}
@Override
public void onClick(View view) {
dismissTaskMenuView(mTarget);
ComponentName cn = getUninstallTarget(mItemInfo);
if (cn == null) {
// System applications cannot be installed. For now, show a toast explaining that.
// We may give them the option of disabling apps this way.
Toast.makeText(mTarget, R.string.uninstall_system_app_text, Toast.LENGTH_SHORT).show();
return;
}
try {
Intent i = Intent.parseUri(mTarget.getString(R.string.delete_package_intent), 0)
.setData(Uri.fromParts("package", cn.getPackageName(), cn.getClassName()))
.putExtra(Intent.EXTRA_USER, mItemInfo.user);
mTarget.startActivity(i);
FileLog.d("Uninstall", "start uninstall activity " + cn.getPackageName());
return;
} catch (URISyntaxException e) {
Log.e("Uninstall", "Failed to parse intent to start uninstall activity for item=" + mItemInfo);
return;
}
}
}
/**
* @return the component name that should be uninstalled or null.
*/
ComponentName getUninstallTarget(ItemInfo item) {
Intent intent = null;
UserHandle user = null;
if (item != null &&
item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
intent = item.getIntent();
user = item.user;
}
if (intent != null) {
LauncherActivityInfo info = mTarget.getSystemService(LauncherApps.class)
.resolveActivity(intent, user);
if (info != null
&& (info.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
return info.getComponentName();
}
}
return null;
}
//====修改end====
public static final Factory<BaseDraggingActivity> INSTALL = (activity, itemInfo) -> {
// ... //
};
`