Android13 Hotseat客制化--Hotseat修改布局、支持滑动、去掉开机弹动效果、禁止创建文件夹

需求如题,实现效果如下 :

固定Hotseat的padding位置、固定高度

step1 在FeatureFlags.java中添加flag,以兼容原生态代码

java 复制代码
public static final boolean STATIC_HOTSEAT_PADDING = true;//hotseat area fixed

step2:在dimens.xml中添加padding值和高度值

XML 复制代码
<dimen name="hotseat_padding_left">0px</dimen>
    <dimen name="hotseat_padding_top">0px</dimen>
    <dimen name="hotseat_padding_right">0px</dimen>
    <dimen name="hotseat_padding_bottom">0px</dimen>
    <dimen name="hotseat_height">218px</dimen>

step3:Hotseat.java的public void setInsets(Rect insets)接口中,改为高度不通过计算,直接读取dimension

java 复制代码
private final int mHotseatHeight;
    public Hotseat(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        mQsb = LayoutInflater.from(context).inflate(R.layout.search_container_hotseat, this, false);
        addView(mQsb);

        mQsbHeight = getResources().getDimensionPixelSize(R.dimen.qsb_widget_height);
        mHotseatHeight = getResources().getDimensionPixelSize(R.dimen.hotseat_height);//added by Kevin
    }
 
  public void setInsets(Rect insets){
      .....
    } else {
            mQsb.setVisibility(View.VISIBLE);
            lp.gravity = Gravity.BOTTOM;
            lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
            //lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            /*lp.height = grid.isTaskbarPresent
                    ? grid.workspacePadding.bottom
                    : grid.hotseatBarSizePx + insets.bottom;*/
            if(FeatureFlags.STATIC_HOTSEAT_PADDING)
                lp.height = mHotseatHeight;//Kevin.Ye added
            else
                lp.height = grid.isTaskbarPresent
                    ? grid.workspacePadding.bottom
                    : grid.hotseatBarSizePx + insets.bottom;
        }

        Rect padding = grid.getHotseatLayoutPadding(getContext());
        setPadding(padding.left, padding.top, padding.right, padding.bottom);
        setLayoutParams(lp);
        InsettableFrameLayout.dispatchInsets(this, insets);

step4:在DeviceProfile.java的public Rect getHotseatLayoutPadding(Context context)接口的最后添加代码,从dimens中读取padding值

java 复制代码
} else {
            // We want the edges of the hotseat to line up with the edges of the workspace, but the
            // icons in the hotseat are a different size, and so don't line up perfectly. To account
            // for this, we pad the left and right of the hotseat with half of the difference of a
            // workspace cell vs a hotseat cell.
            float workspaceCellWidth = (float) widthPx / inv.numColumns;
            float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
            int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
            mHotseatPadding.set(hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
                            + mInsets.left, hotseatBarTopPaddingPx,
                    hotseatAdjustment + workspacePadding.right + cellLayoutPaddingPx.right
                            + mInsets.right,
                    hotseatBarSizePx - hotseatCellHeightPx - hotseatBarTopPaddingPx
                            + mInsets.bottom);
        }
        if(FeatureFlags.STATIC_HOTSEAT_PADDING){//Modified by Kevin.Ye start
             Resources res = context.getResources();
             int hotseatPaddingLeft = res.getDimensionPixelSize(R.dimen.hotseat_padding_left);
             int hotseatPaddingTop = res.getDimensionPixelSize(R.dimen.hotseat_padding_top);
             int hotseatPaddingRight = res.getDimensionPixelSize(R.dimen.hotseat_padding_right);
             int hotseatPaddingBottom = res.getDimensionPixelSize(R.dimen.hotseat_padding_bottom);
             mHotseatPadding.set(hotseatPaddingLeft,hotseatPaddingTop,hotseatPaddingRight,hotseatPaddingBottom);
        }
        return mHotseatPadding;

step5:想要hotseat可以左右滑动,在launcher.xml中为hotseat添加一个HorizontalScrollView

XML 复制代码
<!--Kevin.Ye added start-->
         <HorizontalScrollView
            android:id="@+id/hotseat_container"
            android:layout_width="match_parent"
            android:layout_height="309px"
            android:layout_gravity="bottom"
            android:scrollbars="none">
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:orientation="horizontal">
                <include
                    android:id="@+id/hotseat"
                    layout="@layout/hotseat"
                    android:visibility="gone"/>
            </LinearLayout>
        </HorizontalScrollView>
       <!--Kevin.Ye added end-->

step6:需要定义hotseat的边距还可以在hotseat.xml中定义,可以摆放hotseat里图标数量在device_profile.xml中修改

这里图标宽度 258 间隔27,因此总宽度是 (258+27)x9-27=2538

如果摆放9个icon,那hotseat.xml的定义应该是这样

XML 复制代码
<com.android.launcher3.Hotseat
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:launcher="http://schemas.android.com/apk/res-auto"
    android:id="@+id/hotseat"
    android:layout_width="2538px"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    android:layout_marginLeft="40px"
    android:layout_marginRight="40px"
    android:layout_marginBottom="92px"
    android:theme="@style/HomeScreenElementTheme"
    android:importantForAccessibility="no"
    launcher:containerType="hotseat"/>

如果摆放6个图标,宽度应该是 (258+27)x6-27=1683, marginLeft/Right (1920-1683)/2=118.5

XML 复制代码
<com.android.launcher3.Hotseat
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:launcher="http://schemas.android.com/apk/res-auto"
    android:id="@+id/hotseat"
    android:layout_width="1683px"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    android:layout_marginLeft="118.5px"
    android:layout_marginRight="118.5px"
    android:layout_marginBottom="92px"
    android:theme="@style/HomeScreenElementTheme"
    android:importantForAccessibility="no"
    launcher:containerType="hotseat"/>

重启开机,hotseat会弹动6下,其实是显示操作提示,类似帮助引导

功能是在DiscoveryBounce.java中实现的,Launcher.java中调用,去掉调用即可实现

step1:修改Launcher.java

java 复制代码
 @CallSuper
    protected void onDeferredResumed() {
        logStopAndResume(true /* isResume */);

        // Process any items that were added while Launcher was away.
        ItemInstallQueue.INSTANCE.get(this)
                .resumeModelPush(FLAG_ACTIVITY_PAUSED);

        // Refresh shortcuts if the permission changed.
        mModel.validateModelDataOnResume();

        // Set the notification listener and fetch updated notifications when we resume
        NotificationListener.addNotificationsChangedListener(mPopupDataProvider);

        //DiscoveryBounce.showForHomeIfNeeded(this);//Kevin.Ye added for not showing DiscoveryBounce
        mAppWidgetHost.setActivityResumed(true);
    }

禁止在hotseat中形成图标文件夹

step1:FeatureFlags.java添加flag

java 复制代码
public static final boolean HOTSEAT_FOLDER = false;//Kevin.Ye added for not creating folder on hotseat

step2:Workspace.java中添加判断即可

java 复制代码
boolean createUserFolderIfNecessary(View newView, int container, CellLayout target,
            int[] targetCell, float distance, boolean external, DragObject d) {
        //added by Kevin.Ye start
        if(!FeatureFlags.HOTSEAT_FOLDER){
            if(mLauncher.isHotseatLayout(target)) return false;//
        }
        //add end
        if (distance > target.getFolderCreationRadius(targetCell)) return false;
        View v = target.getChildAt(targetCell[0], targetCell[1]);
相关推荐
Beekeeper&&P...11 分钟前
public String testsystype(HttpServletRequest req)
java·spring
界面开发小八哥19 分钟前
「Java EE开发指南」如何使用Visual JSF编辑器设计JSP?(二)
java·ide·java-ee·开发工具·myeclipse
zybishe39 分钟前
计算机毕业设计原创定制(免费送源码)Java+SpringBoot+MySQL SpringBoot物流配送后台系统
java·css·c++·spring boot·spark·django·课程设计
BIM云平台开发41 分钟前
关于return,yield 和 yield return
java·开发语言·数据结构·c#
GGBondlctrl1 小时前
【Spring MVC】关于Spring MVC编程中与http请求的参数传递的详细介绍
java·spring·mvc·postman·请求参数的传递·json的传递
小小unicorn1 小时前
基于Boost库的搜索引擎
java·搜索引擎·dubbo
m0_748232921 小时前
JVM的内存区域划分
java·jvm·算法
遇见你真好。1 小时前
x-easypdf 初始与简单使用
java·springboot·x-easypdf
软件聚导航1 小时前
uniapp 安卓和ios震动方法,支持息屏和后台震动,ios和安卓均通过测试
android·ios·uni-app
菜鸟挣扎史1 小时前
关于一次开源java spring快速开发平台项目RuoYi部署的记录
java·spring·开源