Launcher3 workspace 加载默认的布局

本文主要分析launcher3 如何加载默认的icon ,基于AOSP Q Launcher3 code

1、 launcher首先会初始化设备配置属性,比如加载哪些图标,图标布局n * n等等,这些配置定义在device_profiles.xml 中,device_profiles.xml 会关联到default_workspace_n*n.xml,
2、 在LoaderTask.java 的loadworkspace函数中会去load默认的布局,其实就是去加载 1中初始化后的配置

1、InvariantDeviceProfile初始化

Launcher在oncreate的时候会通过单例初始化LauncherAppState类

LauncherAppState app = LauncherAppState.getInstance(this);

在LauncherAppState的构造中会初始化InvariantDeviceProfile,先看一下InvariantDeviceProfile构造函数,

  public InvariantDeviceProfile(Context context) {
   
		......
        // This guarantees that width < height
        minWidthDps = Utilities.dpiFromPx(Math.min(smallestSize.x, smallestSize.y), dm);
        minHeightDps = Utilities.dpiFromPx(Math.min(largestSize.x, largestSize.y), dm);
        
        ArrayList<InvariantDeviceProfile> closestProfiles = findClosestDeviceProfiles(
                minWidthDps, minHeightDps, getPredefinedDeviceProfiles(context));
                
        InvariantDeviceProfile interpolatedDeviceProfileOut =
                invDistWeightedInterpolate(minWidthDps,  minHeightDps, closestProfiles);

        InvariantDeviceProfile closestProfile = closestProfiles.get(0);
        numRows = closestProfile.numRows;
        numColumns = closestProfile.numColumns;
        numHotseatIcons = closestProfile.numHotseatIcons;
        //这个布局就是后面load default favorites加载所需要的布局id
        defaultLayoutId = closestProfile.defaultLayoutId;
        Log.d("InvariantDeviceProfile", "InvariantDeviceProfile: defaultLayoutId: " + defaultLayoutId);
        demoModeLayoutId = closestProfile.demoModeLayoutId;
        numFolderRows = closestProfile.numFolderRows;
        numFolderColumns = closestProfile.numFolderColumns;
       ......

通过getPredefinedDeviceProfiles 去load device_profiles.xml中定义的所有profile,放到List中,然后通过findClosestDeviceProfiles从 list中找出最接近的profile。


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值