Android_Q_Launcher调整为横向滑动

Android_Q_Launcher调整为横向滑动

以下内容为原创,其中有参考部分同行的blog。

 

需求说明:

1.Android Q Launcher去掉抽屉功能,屏蔽从下往上的滑动功能;

2.将系统中apk及新安装的apk全部显示在workspace中;

3.workspace中,不可卸载的应用长按滑动后,只能有cancel功能,可卸载应用,长按滑动后,有卸载功能;

4.Launcher横屏显示时,屏蔽从下往上的滑动功能;

 

需求分解:备注:以下相关代码注释请搜索“by lj”

1.将 AllAppsContainerView 中的图标加载到 Workspace,需要在LoaderTask中,将所有APP都Load并且通过addAndBindAddedWorkspaceItems,添加显示到workspace。packagesappsLauncher3srccomandroidlauncher3modelLoaderTask.java文件中,在run()方法中,

// second step

            TraceHelper.partitionSection(TAG, “step 2.1: loading all apps”);

            List allActivityList = loadAllApps();

            /*add start by lj on 20200530*/

            verifyApplications();

            /*add end by lj on 20200530*/

 

需要添加的方法如下:

/*add start by lj on 20200530*/

    private void verifyApplications() {

        final Context context = mApp.getContext();

        ArrayList> installQueue = new ArrayList();

        final List profiles = mUserManager.getUserProfiles();

        for (UserHandle user : profiles) {

            final List apps = mLauncherApps.getActivityList(null, user);

            ArrayList added =

new ArrayList();

            synchronized (this) {

                for (LauncherActivityInfo app : apps) {

                    InstallShortcutReceiver.PendingInstallShortcutInfo pendingInstallShortcutInfo =

                        new InstallShortcutReceiver.PendingInstallShortcutInfo(app, context);

added.add(pendingInstallShortcutInfo);

                    installQueue.add(pendingInstallShortcutInfo.getItemInfo());

                }

            }

            if (!added.isEmpty()) {

                mApp.getModel().addAndBindAddedWorkspaceItems(installQueue);

            }

        }

    }

/*add end by lj on 20200530*/

 

2.packagesappsLauncher3srccomandroidlauncher3InstallShortcutReceiver.java文件中,将PendingInstallShortcutInfo方法从private调整为public;

原先代码需要判定后,再决定是否需要重新load app列表,packagesappsLauncher3srccomandroidlauncher3modelBaseModelUpdateTask.java文件中,run()方法,将return语句屏蔽,保证每次都能执行execte方法,public final void run() {

        if (!mModel.isModelLoaded()) {

            if (DEBUG_TASKS) {

                Log.d(TAG, “Ignoring model task since loader is pending=” + this);

            }

            // Loader has not yet run.

            //return; /*delete by lj on 20200530*/

        }

        execute(mApp, mDataModel, mAllAppsList);

    }

 

3.新安装的 app 自动添加图标到 Workspace,packagesappsLauncher3srccomandroidlauncher3modelPackageUpdatedTask.java文件中,execute方法添加内容如下:

        final ArrayList addedOrModified = new ArrayList();

        addedOrModified.addAll(appsList.added);

        /*add start by lj on 20200530*/

        updateToWorkSpace(context, app, appsList);

        /*add end by lj on 20200530*/

        appsList.added.clear();

        addedOrModified.addAll(appsList.modified);

        appsList.modified.clear();

 

需要添加的方法如下:

/*add start by lj on 20200530*/

    public void updateToWorkSpace(Context context, LauncherAppState app , AllAppsList appsList) {

        ArrayList> installQueue = new ArrayList();

        final List profiles = UserManagerCompat.getInstance(context).getUserProfiles();

        ArrayList added =

            new ArrayList();

        for (UserHandle user : profiles) {

            final List apps = LauncherAppsCompat.getInstance(context).getActivityList(null, user);

            synchronized (this) {

                for (LauncherActivityInfo info : apps) {

                    for (AppInfo appInfo : appsList.added) {

                        if (info.getComponentName().equals(appInfo.componentName)) {

                            InstallShortcutReceiver.PendingInstallShortcutInfo mPendingInstallShortcutInfo =

                                new InstallShortcutReceiver.PendingInstallShortcutInfo(info,context);

                            added.add(mPendingInstallShortcutInfo);

                            installQueue.add(mPendingInstallShortcutInfo.getItemInfo());

                        }

                    }

                }

            }

        }

 

        if (!added.isEmpty()) {

            app.getModel().addAndBindAddedWorkspaceItems(installQueue);

        }

    }

    /*add end by lj on 20200530*/

 

4.Workspace 图标长按删除选项调整为取消,packagesappsLauncher3srccomandroidlauncher3DeleteDropTarget.java文件中,setTextBasedOnDragSource方法中mText,在非可卸载应用使用时,显示为取消,

/*add start by lj on 20200530*/

mText = getResources().getString(isCanDrop(item)

? R.string.remove_drop_target_label

: android.R.string.cancel);

            /*add end by lj on 20200530*/

 

需要添加的方法如下:

    /*add start by lj on 20200530*/

    private boolean isCanDrop(ItemInfo item) {

        return !(item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||

            item.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER);

    }

    /*add end by lj on 20200530*/

 

5.在workspace拖拽icon结束后,增加判断,是否取消当前拖拽操作,packagesappsLauncher3srccomandroidlauncher3dragndropDragController.java文件中,drop()方法,

        // Drop onto the target.

        boolean accepted = false;

        if (dropTarget != null) {

            dropTarget.onDragExit(mDragObject);

            if (dropTarget.acceptDrop(mDragObject)) {

                if (flingAnimation != null) {

                    flingAnimation.run();

                } else {

                    dropTarget.onDrop(mDragObject, mOptions);

                }

                accepted = true;

                /*add start by lj on 20200530*/

                if (dropTarget instanceof DeleteDropTarget && isNeedCancelDrag(mDragObject.dragInfo)) {

                    cancelDrag();

                }

                /*add end by lj on 20200530*/

            }

        }

 

需要添加的方法如下:

    /*add start by lj on 20200530*/

    private boolean isNeedCancelDrag(ItemInfo item) {

        return (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||

            item.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER);

    }

/*add end by lj on 20200530*/

 

6.屏蔽竖屏状态下,从下往上的抽屉滑动效果,packagesappsLauncher3quickstepsrccomandroidlauncher3uioverridestouchcontrollersPortraitStatesTouchController.java文件中,canInterceptTouch方法,

else if (mLauncher.isInState(OVERVIEW)) {

            if (!mOverviewPortraitStateTouchHelper.canInterceptTouch(ev)) {

                return false;

            }

          

            /*add start by lj on 20200530*/

            return false;

            /*add end by lj on 20200530*/

        } else {

            // If we are swiping to all apps instead of overview, allow it from anywhere.

            boolean interceptAnywhere = mLauncher.isInState(NORMAL) && !mAllowDragToOverview;

            // For all other states, only listen if the event originated below the hotseat height

            if (!interceptAnywhere && !isTouchOverHotseat(mLauncher, ev)) {

                return false;

            }

          

            /*add start by lj on 20200530*/

            return false;

            /*add end by lj on 20200530*/

        }

 

7.屏蔽横屏状态下,从下往上的抽屉滑动效果,packagesappslauncher3quicksteprecents_ui_overridessrccomandroidlauncher3uioverridestouchcontrollersOverviewToAllAppsTouchController.java文件中,canInterceptTouch方法,

if (mLauncher.isInState(ALL_APPS)) {

            /*add start by lj on 20200530*/

            if (true) {

                return false;

            }

            /*add end by lj on 20200530*/

            // In all-apps only listen if the container cannot scroll itself

            return mLauncher.getAppsView().shouldContainerScroll(ev);

        } else if (mLauncher.isInState(NORMAL)) {

            /*add start by lj on 20200530*/

            if (true) {

                return false;

            }

            /*add end by lj on 20200530*/

            return (ev.getEdgeFlags() & Utilities.EDGE_NAV_BAR) == 0;

        } else if (mLauncher.isInState(OVERVIEW)) {

            /*add start by lj on 20200530*/

            if (true) {

                return false;

            }

            /*add end by lj on 20200530*/

 

            RecentsView rv = mLauncher.getOverviewPanel();

            return ev.getY() > (rv.getBottom() – rv.getPaddingBottom());

        } else {

            return false;

        }

 

packagesappslauncher3srccomandroidlauncher3viewsScrimView.java文件中,updateDragHandleVisibility方法,       

//boolean visible = mLauncher.getDeviceProfile().isVerticalBarLayout() || mAM.isEnabled();/*delete by lj on 20200530*/

        /*add start by lj on 20200530*/

        boolean visible = false;

        /*add start by lj on 20200530*/

        boolean wasVisible = mDragHandle != null;

 

完成以上代码的修改后,即可达到上述期望的效果。

 

本文由 @陈奕天[Vip] 发布于 职涯宝 ,未经作者许可,禁止转载,欢迎您分享文章

发表评论

登录后才能评论
小程序
小程序
微信客服
微信客服
QQ客服 建站服务
分享本页
返回顶部