Android5.1 Launcher3修改成单层 无法卸载非系统应用

先屏蔽不显示搜索框 只显示删除 卸载 按钮

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<LauncherActivityInfoCompat> app = mLauncherApps.getActivityList(packageName, user);
                                   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) {
            ItemInfo item = (ItemInfo) info;
            if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET ||
                    item.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
                return true;
            }


            if (LauncherAppState.isDisableAllApps() &&
                    item.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
                return true;
            }


            if (LauncherAppState.isDisableAllApps() &&
                    item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION &&
                    item instanceof AppInfo) {
                AppInfo appInfo = (AppInfo) info;
                return (appInfo.flags & AppInfo.DOWNLOADED_FLAG) != 0;
            }


            if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION &&
                item instanceof ShortcutInfo) {
                if (!LauncherAppState.isDisableAllApps()) {
                    ShortcutInfo shortcutInfo = (ShortcutInfo) info;
                    return (shortcutInfo.flags & AppInfo.DOWNLOADED_FLAG) != 0;
                } else {
                    return true;
                }
            }
        }
        return false;
    }

  @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

        }
        return false;

    }

 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<PackageInfo> packages = getContext().getPackageManager().getInstalledPackages(0);


                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);
                            }

                        }

。。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值