先屏蔽不显示搜索框 只显示删除 卸载 按钮
Launcher.java
protected boolean updateGlobalSearchIcon() {
final View searchButtonContainer = findViewById(R.id.search_button_container);
final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
final View voiceButtonContainer = findViewById(R.id.voice_button_container);
final View voiceButton = findViewById(R.id.voice_button);
/* wanchengguo 20180612 begin*/
searchButtonContainer.setVisibility(View.GONE);
voiceButtonContainer.setVisibility(View.GONE);
searchButton.setVisibility(View.GONE);
voiceButton.setVisibility(View.GONE);
return false;
/*final SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
ComponentName activityName = searchManager.getGlobalSearchActivity();
if (activityName != null) {
int coi = getCurrentOrientationIndexForGlobalIcons();
sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
TOOLBAR_SEARCH_ICON_METADATA_NAME);
if (sGlobalSearchIcon[coi] == null) {
sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity(
R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo,
TOOLBAR_ICON_METADATA_NAME);
}
if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE);
searchButton.setVisibility(View.VISIBLE);
invalidatePressedFocusedStates(searchButtonContainer, searchButton);
return true;
} else {
// We disable both search and voice search when there is no global search provider
if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE);
if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
if (searchButton != null) searchButton.setVisibility(View.GONE);
if (voiceButton != null) voiceButton.setVisibility(View.GONE);
updateVoiceButtonProxyVisible(false);
return false;
}
/* wanchengguo 20180612 end*/
}
原因是将安装的APP 进行删除流程的时候判断成了Weight,所以导致删不了,并且不能弹出删除对话框
修改Launcher的加载模式进行对安装的APP进行flag标记
LauncherModel.java
private boolean loadWorkspace(){
...while (!mStopped && c.moveToNext()) {
...
if (info != null) {
//add wanchengguo
if(intent.getAction() != null && intent.getAction().equals(Intent.ACTION_MAIN)){
try {
final String packageName = intent.getComponent().getPackageName();
//List
PackageInfo pi = manager.getPackageInfo(packageName, 0);
if (!pi.applicationInfo.enabled) {
// If we return null here, the corresponding item will be removed from the launcher
// db and will not appear in the workspace.
//return null;
}
final int appFlags = manager.getApplicationInfo(packageName, 0).flags;
if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) {
info.flags |= AppInfo.DOWNLOADED_FLAG;
if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
info.flags |= AppInfo.UPDATED_SYSTEM_APP_FLAG;
}
}
// info.firstInstallTime = manager.getPackageInfo(packageName, 0).firstInstallTime;
} catch (NameNotFoundException e) {
Log.d(TAG, "getPackInfo failed for componentName " + intent.getComponent());
//return null;
}
}
//add by wanchengguo 20180612 end
info.id = id;
info.intent = intent;
container = c.getInt(containerIndex);
info.container = container;
info.screenId = c.getInt(screenIndex);
info.cellX = c.getInt(cellXIndex);
info.cellY = c.getInt(cellYIndex);
info.spanX = 1;
info.spanY = 1;
info.intent.putExtra(ItemInfo.EXTRA_PROFILE, serialNumber);
info.isDisabled = isSafeMode
&& !Utilities.isSystemApp(context, intent);
''''
DeleteDropTarget.java
这里面是对删除的流程,在这里判断是否是安装的App,如果是安装的 就调用startApplicationUninstallActivity()进行删除
//LauncherAppState.isDisableAllApps() 判断条件由true改为false 由false 改为true
public static boolean willAcceptDrop(Object info) {
if (info instanceof ItemInfo) { @Override
public void onDragStart(DragSource source, Object info, int dragAction) {
boolean isVisible = true;
boolean useUninstallLabel = LauncherAppState.isDisableAllApps() ;/*&&
isAllAppsApplication(source, info);*/
....useUninstallLabel确保其为true 按钮显示卸载而非删除
private boolean isUninstallFromWorkspace(DragObject d) {
if (LauncherAppState.isDisableAllApps() && isWorkspaceOrFolderApplication(d)) {
ShortcutInfo shortcut = (ShortcutInfo) d.dragInfo;
// Only allow manifest shortcuts to initiate an un-install.
//return !InstallShortcutReceiver.isValidShortcutLaunchIntent(shortcut.intent);
return InstallShortcutReceiver.isValidShortcutLaunchIntent(shortcut.intent);
//确保满足从workspace 判断条件为true
}
private void completeDrop(DragObject d) {
ItemInfo item = (ItemInfo) d.dragInfo;
int myAppInfoFlags = 0; /*wanchengguo 20180612 end*/
boolean wasWaitingForUninstall = mWaitingForUninstall;
mWaitingForUninstall = false;
if (LauncherLog.DEBUG) {
LauncherLog.d(TAG, "completeDrop: item = " + item + ", d = " + d);
}
if (isAllAppsApplication(d.dragSource, item)) {
// Uninstall the application if it is being dragged from AppsCustomize
AppInfo appInfo = (AppInfo) item;
mLauncher.startApplicationUninstallActivity(appInfo.componentName, appInfo.flags,
appInfo.user);
} else if (isUninstallFromWorkspace(d)) {
ShortcutInfo shortcut = (ShortcutInfo) item;
if (shortcut.intent != null && shortcut.intent.getComponent() != null) {
final ComponentName componentName = shortcut.intent.getComponent();
final DragSource dragSource = d.dragSource;
final UserHandleCompat user = shortcut.user;
/*wanchengguo 20180612 begin*/
List
for (int i = 0; i < packages.size(); i++) {
PackageInfo packageInfo = packages.get(i);
if (packageInfo.packageName.equals(componentName.getPackageName())) {
if ((packageInfo.applicationInfo.flags &
ApplicationInfo.FLAG_SYSTEM)==0) {
Log.e(TAG, "This is user app ");
myAppInfoFlags = 1;
}
}
}
mWaitingForUninstall = mLauncher.startApplicationUninstallActivity(
componentName, myAppInfoFlags, user);
/*mWaitingForUninstall = mLauncher.startApplicationUninstallActivity(
componentName, shortcut.flags, user);*/
/*wanchengguo 20180612 end*/
if (mWaitingForUninstall) {
final Runnable checkIfUninstallWasSuccess = new Runnable() {
@Override
public void run() {
mWaitingForUninstall = false;
String packageName = componentName.getPackageName();
boolean uninstallSuccessful = !AllAppsList.packageHasActivities(
getContext(), packageName, user);
if (dragSource instanceof Folder) {
((Folder) dragSource).
onUninstallActivityReturned(uninstallSuccessful);
} else if (dragSource instanceof Workspace) {
((Workspace) dragSource).
onUninstallActivityReturned(uninstallSuccessful);
}
}
。。。。