android 9 修改 Launcher3

客户有要求直接显示app列表页面,不显示桌面,网上查了基本都是处理的桌面(workspace),后被我找到方法,独辟蹊径!

add 2020.1.13

发现右键居然还能操作,回到上层界面,再改:

路径:

packages\apps\Launcher3\src\com\android\launcher3\allapps\AllAppsContainerView.java

 

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
    	Log.e(TAG, "into dispatchKeyEvent...");
        mSearchUiManager.preDispatchKeyEvent(event);
		+return true;
        -//return super.dispatchKeyEvent(event);
    }

 

1、路径:  函数:setupViews 最后

packages\apps\Launcher3\src\com\android\launcher3\Launcher.java

 添加:

       .... 
        // Setup Apps
        mAppsView = findViewById(R.id.apps_view);

        // Setup the drag controller (drop targets have to be added in reverse order in priority)
        mDragController.setMoveTarget(mWorkspace);
        mDropTargetBar.setup(mDragController);

        mAllAppsController.setupViews(mAppsView);

	+goAppsView();
    }


private void goAppsView(){
		Launcher mLauncher = Launcher.getLauncher(this);
		if (!mLauncher.isInState(ALL_APPS)) {
            mLauncher.getUserEventDispatcher().logActionOnControl(Action.Touch.TAP,
                    ControlType.ALL_APPS_BUTTON);
            mLauncher.getStateManager().goToState(ALL_APPS);
        }
	}

2、禁止上下滑动的地方和网上的一样,可以在下面找打。

//========================================================= 

以下为网上查到的方法:

1、直接在桌面上显示 app

路径1、

packages\apps\Launcher3\src\com\android\launcher3\config\BaseFlags.java

添加:

 

添加变量:

abstract class BaseFlags {

    BaseFlags() {}

+   public static final boolean REMOVE_DRAWER = true;

    public static final boolean IS_DOGFOOD_BUILD = false;
    public static final String AUTHORITY = "com.android.launcher3.settings".intern();

    ...

路径2、

packages\apps\Launcher3\src\com\android\launcher3\model\BaseModelUpdateTask.java

修改:

    @Override
    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;
	    +if(!FeatureFlags.REMOVE_DRAWER){
            +   return;
            +}
        }
        execute(mApp, mDataModel, mAllAppsList);
    }

 路径3、

packages\apps\Launcher3\src\com\android\launcher3\model\LoaderTask.java

修改:

            // second step
            TraceHelper.partitionSection(TAG, "step 2.1: loading all apps");
            loadAllApps();

			+if (FeatureFlags.REMOVE_DRAWER) 
			+{                 
			+	verifyApplications();             
			+} 

            TraceHelper.partitionSection(TAG, "step 2.2: Binding all apps");
            verifyNotStopped();
            mResults.bindAllApps();
    //add by yy
    private void verifyApplications() {
        final Context context = mApp.getContext();
        ArrayList<Pair<ItemInfo, Object>> installQueue = new ArrayList<>();
        final List<UserHandle> profiles = mUserManager.getUserProfiles();
        for (UserHandle user : profiles) {
            final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null, user);
            ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo> added = new ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo>();
            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);
            }
        }
    }
    //end add by yy

 2、禁止上滑,显示app

路径:

packages\apps\Launcher3\quickstep\src\com\android\launcher3\uioverrides\OverviewToAllAppsTouchController.java

修改:

    @Override
    protected boolean canInterceptTouch(MotionEvent ev) {
    	+if(FeatureFlags.REMOVE_DRAWER){
        +    return false;
        +}

        if (mCurrentAnimation != null) {
            // If we are already animating from a previous state, we can intercept.
            return true;
        }

        ...

3、禁止桌面左右滑动

路径:

packages\apps\Launcher3\src\com\android\launcher3\PagedView.java

修改:

                +    if(FeatureFlags.REMOVE_DRAWER){
				+		Log.e(TAG, "into MotionEvent.ACTION_UP ==>>"+action);
				+		//returnToOriginalPage = true;
				+		snapToPageWithVelocity(mCurrentPage, velocityX);
		        +	}

				+	/*
                    int finalPage;
                    // We give flings precedence over large moves, which is why we short-circuit our
                    // test for a large move if a fling has been registered. That is, a large
                    // move to the left and fling to the right will register as a fling to the right.
                    boolean isDeltaXLeft = mIsRtl ? deltaX > 0 : deltaX < 0;
                    boolean isVelocityXLeft = mIsRtl ? velocityX > 0 : velocityX < 0;
                    if (((isSignificantMove && !isDeltaXLeft && !isFling) ||
                            (isFling && !isVelocityXLeft)) && mCurrentPage > 0) {
                        finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1;
						Log.e(TAG, "into snapToPageWithVelocity1 ==>>"+finalPage);
                        snapToPageWithVelocity(finalPage, velocityX);
                    } else if (((isSignificantMove && isDeltaXLeft && !isFling) ||
                            (isFling && isVelocityXLeft)) &&
                            mCurrentPage < getChildCount() - 1) {
                        finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1;
						Log.e(TAG, "into snapToPageWithVelocity2 ==>>"+finalPage);
                        snapToPageWithVelocity(finalPage, velocityX);
                    } else {
                        snapToDestination();
                    }
                   + */

4、禁止 桌面应用图标长按事件

路径:

packages\apps\Launcher3\src\com\android\launcher3\allapps\AllAppsGridAdapter.java

 

@Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case VIEW_TYPE_ICON:
                BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(
                        R.layout.all_apps_icon, parent, false);
                icon.setOnClickListener(ItemClickHandler.INSTANCE);
               + //icon.setOnLongClickListener(ItemLongClickListener.INSTANCE_ALL_APPS);
                icon.setLongPressTimeout(ViewConfiguration.getLongPressTimeout());
                icon.setOnFocusChangeListener(mIconFocusListener);
                ...

路径:

packages\apps\Launcher3\src\com\android\launcher3\Workspace.java

修改:

        ...
        child.setHapticFeedbackEnabled(false);
       + //child.setOnLongClickListener(ItemLongClickListener.INSTANCE_WORKSPACE);
        if (child instanceof DropTarget) {
            mDragController.addDropTarget((DropTarget) child);
        }
    }

 

 

 

参考:

https://www.jb51.net/article/173839.htm

https://blog.csdn.net/yxdspirit/article/details/84634454

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值