欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android8.1 MTK 平台 Launcher3 修改定制

程序员文章站 2022-06-30 14:25:31
...

一、去掉默认 Google 搜索栏

Android8.1 MTK 平台 Launcher3 修改定制

修改位置

vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\Workspace.java

注释 bindAndInitFirstWorkspaceScreen() 中 if (qsb == null) 开始到结尾

public void bindAndInitFirstWorkspaceScreen(View qsb) {
        if (!FeatureFlags.QSB_ON_FIRST_SCREEN) {
            return;
        }
        // Add the first page
        CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, 0);
        if (FeatureFlags.PULLDOWN_SEARCH) {
            .....
        }
        //add don't show google quick search box[qsb]
        // Always add a QSB on the first screen.
        /*if (qsb == null) {
            // In transposed layout, we add the QSB in the Grid. As workspace does not touch the
            // edges, we do not need a full width QSB.
            qsb = LayoutInflater.from(getContext())
                    .inflate(R.layout.search_container_workspace,firstPage, false);
        }

        
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(), 1);
        lp.canReorder = false;
        if (!firstPage.addViewToCellLayout(qsb, 0, R.id.search_container_workspace, lp, true)) {
            Log.e(TAG, "Failed to add to item at (0, 0) to CellLayout");
        }*/
        //add don't show google quick search box[qsb]
    }

二、去掉所有 app 界面搜索应用栏

Android8.1 MTK 平台 Launcher3 修改定制

修改位置

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

在 onFinishInflate() 中添加一行 mSearchContainer.setVisibility(View.GONE);

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    ....

    mSearchContainer = findViewById(R.id.search_container_all_apps);
    mSearchUiManager = (SearchUiManager) mSearchContainer;
    mSearchUiManager.initialize(mApps, mAppsRecyclerView);

    /// add this code don't show all app quick search box
    mSearchContainer.setVisibility(View.GONE);

    ......
}

三、hotseat 中添加老版本的所有应用图标,并去除上滑箭头和屏蔽 Drag 动画

Android8.1 MTK 平台 Launcher3 修改定制

修改位置

  • 1、 添加所有 app 按钮

vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\Hotseat.java

在 resetLayout() 中将 FeatureFlags.NO_ALL_APPS_ICON 写成 true 则默认加载六个点按钮

void resetLayout() {
        mContent.removeAllViewsInLayout();
        //change true    default add all app button
        if (/*!FeatureFlags.NO_ALL_APPS_ICON*/true) {
            // Add the Apps button
            Context context = getContext();
            DeviceProfile grid = mLauncher.getDeviceProfile();
            int allAppsButtonRank = grid.inv.getAllAppsButtonRank();

            LayoutInflater inflater = LayoutInflater.from(context);
            TextView allAppsButton = (TextView)
                    inflater.inflate(R.layout.all_apps_button, mContent, false);
            Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);
            d.setBounds(0, 0, grid.iconSizePx, grid.iconSizePx);

            ...
        }
    }

  • 2、去除上滑箭头

vendor\mediatek\proprietary\packages\apps\Launcher3\res\layout-land\launcher.xml

给 PageIndicatorCaretLandscape 控件添加 gone 属性,注意我此处修改的是横屏的版本,若你是竖屏则修改

layout 文件夹下 launcher.xml

<com.android.launcher3.pageindicators.PageIndicatorCaretLandscape
            android:id="@+id/page_indicator"
            android:theme="@style/HomeScreenElementTheme"
            android:layout_width="@dimen/dynamic_grid_min_page_indicator_size"
            android:layout_height="@dimen/dynamic_grid_min_page_indicator_size"
            android:layout_gravity="bottom|left"
            android:visibility="gone"/>

此处添加完成后小箭头确实不显示了,但是当你在 workspace 长按时,小箭头又出现了,坑爹的找了半天,最终终

于搞定了。

vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\pageindicators\PageIndicatorCaretLandscape.java

@Override
protected void onDraw(Canvas canvas) {
    //annotaion for longclick don't show up arrow
    /*Rect drawableBounds = getCaretDrawable().getBounds();
    int count = canvas.save();
    canvas.translate((getWidth() - drawableBounds.width()) / 2,
            getHeight() - drawableBounds.height());
    getCaretDrawable().draw(canvas);
    canvas.restoreToCount(count);*/
}

注释 onDraw() 的方法体就好了,因为当你长按 workSpace 时,触发长按事件,最终调用了 Launcher

中的 showOverviewMode(),通过 mWorkspace.setVisibility(View.VISIBLE);

PageIndicatorCaretLandscape 和 Workspace 是绑定的,导致 onDraw 执行,重新绘制。

  • 3、屏蔽 Drag 动画

vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\allapps\AllAppsTransitionController.java

 @Override
    public boolean onDrag(float displacement, float velocity) {
        Log.e("Launcher3", "onDrag()");
        if (true)  return true;
        //add for forbidden workspace drag change GradientView alph

        if (mAppsView == null) {
            return false;   // early termination.
        }

        mContainerVelocity = velocity;

        float shift = Math.min(Math.max(0, mShiftStart + displacement), mShiftRange);
        setProgress(shift / mShiftRange);

        return true;
    }

    @Override
    public void onDragEnd(float velocity, boolean fling) {
        Log.e("Launcher3", "onDragEnd()");
        //add for forbidden workspace drag change GradientView alph
        if (true){
            if (velocity < 0) {
                mLauncher.showWorkspace(true);
            }
            return;
        }  
        //add for forbidden workspace drag change GradientView alph

        if (mAppsView == null) {
            return; // early termination.
        }

        final int containerType = mTouchEventStartedOnHotseat
                ? ContainerType.HOTSEAT : ContainerType.WORKSPACE;

        if (fling) {
            if (velocity < 0) {
                calculateDuration(velocity, mAppsView.getTranslationY());

                if (!mLauncher.isAllAppsVisible()) {
                    mLauncher.getUserEventDispatcher().logActionOnContainer(
                            Action.Touch.FLING,
                            Action.Direction.UP,
                            containerType);
                }
                mLauncher.showAppsView(true /* animated */, false /* updatePredictedApps */);
                if (hasSpringAnimationHandler()) {
                    mSpringAnimationHandler.add(mSearchSpring, true /* setDefaultValues */);
                    // The icons are moving upwards, so we go to 0 from 1. (y-axis 1 is below 0.)
                    mSpringAnimationHandler.animateToFinalPosition(0 /* pos */, 1 /* startValue */);
                }
            } else {
                calculateDuration(velocity, Math.abs(mShiftRange - mAppsView.getTranslationY()));
                mLauncher.showWorkspace(true);
            }
            // snap to top or bottom using the release velocity
        }

	.....

}

分别在 onDrag() 和 onDragEnd() 回调方法中直接 return,需要注意的是在 onDragEnd 中需要将

workSpace 的状态复原,不然下一次点击所有APP 按钮时,会出现白屏现象。

四、图标长按拖拽至最左侧删除卸载区域不对 bug

alps\vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\DeviceProfile.java

public void layout(Launcher launcher, boolean notifyListeners) {
        FrameLayout.LayoutParams lp;
        boolean hasVerticalBarLayout = isVerticalBarLayout();

        // Layout the search bar space
        Point searchBarBounds = getSearchBarDimensForWidgetOpts();
        View searchBar = launcher.getDropTargetBar();
        lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
        //lp.width = searchBarBounds.x;
        //lp.height = searchBarBounds.y;
        lp.width = 96;
        lp.height = 720;
        lp.topMargin = mInsets.top + edgeMarginPx;
        searchBar.setLayoutParams(lp);
        Log.i("Launcher3.profiles","lp.topMargin ="+lp.topMargin + " width="+lp.width+" height="+lp.height);

        // Layout the workspace
        PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace);
        Rect workspacePadding = getWorkspacePadding(null);
        workspace.setPadding(workspacePadding.left, workspacePadding.top, workspacePadding.right,
                workspacePadding.bottom);
        workspace.setPageSpacing(getWorkspacePageSpacing());
        Log.e("Launcher3.profiles","left="+workspacePadding.left + "   top="+workspacePadding.top
            +" right="+workspacePadding.right + "   bottom="+workspacePadding.bottom);
        Log.d("Launcher3.profiles","setPageSpacing="+getWorkspacePageSpacing());
	
		...

}

DeviceProfile 中的 layout() 方法很关键,你所有看到的界面都是走这来放置控件。通过打印日志发现,没横屏

状态下的宽高分别是 96720, 横屏状态下宽高为 112096,将 searchBar 的宽高强制写成 96*720

相关标签: launcher3