【源码剖析】Launcher 8.0 源码 (3) --- Launcher 启动流程 第一步(2)之获取硬件参数,确定布局参数

本文详细剖析了Android Launcher 8.0的启动流程,尤其是如何获取硬件参数并确定桌面布局参数的过程。通过`InvariantDeviceProfile`和`DeviceProfile`类,获取DisplayMetrics,计算最小宽度和高度,然后通过比较预设的设备配置文件找到最接近的布局模板,最后完成图标和文本大小的优化。
摘要由CSDN通过智能技术生成

获取桌面布局参数,是在InvariantDeviceProfile进行,而后在DeviceProfile中完成参数的规划。参数布局是采用profile比较来完成。

mInvariantDeviceProfile = new InvariantDeviceProfile(mContext);

LauncherAppState构造器里的第一行代码,其源码如下:

 

InvariantDeviceProfile(Context context) {
   WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    DisplayMetrics dm = new DisplayMetrics();
    display.getMetrics(dm);

    Point smallestSize = new Point();
    Point largestSize = new Point();
    display.getCurrentSizeRange(smallestSize, largestSize);

    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;
    defaultLayoutId = closestProfile.defaultLayoutId;
    numFolderRows = closestProfile.numFolderRows;
    numFolderColumns = closestProfile.numFolderColumns;
    minAllAppsPredictionColumns = closestProfile.minAllAppsPredictionColumns;

    iconSize = interpolatedDeviceProfileOut.iconSize;
    iconBitmapSize = Utilities.pxFromDp(iconSize, dm);
    iconTextSize = interpolatedDeviceProfileOut.iconTextSize;
    hotseatIconSize = interpolatedDeviceProfileOut.hotseatIconSize;
    fillResIconDpi = getLauncherIconDensity(iconBitmapSize);

    applyPartnerDeviceProfileOverrides(context, dm);
    hotseatScale = hotseatIconSize / iconSize;
    Point realSize = new Point();
    display.getRealSize(realSize);
    int smallSide = Math.min(realSize.x, realSize.y);
    int largeSide = Math.max(realSize.x, realSize.y);
    landscapeProfile = new DeviceProfile(context, this, smallestSize, largestSize,
            largeSide, smallSide, true /* isLandscape */);
    portraitProfile = new DeviceProfile(context, this, smallestSize, largestSize,
            smallSide, largeSide, false /* isLandscape

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值