Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1733dedf authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add GridDimensionSpecs to fixed landscape and make grid dimension...

Merge "Add GridDimensionSpecs to fixed landscape and make grid dimension generalized so we can use it to determine row count or col count" into main
parents bbefa5da d1cd8c2e
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -162,10 +162,11 @@
        <attr name="layout_sticky" format="boolean" />
    </declare-styleable>

    <declare-styleable name="GridDimension">
        <attr name="minDeviceWidthDp" format="integer"/>
        <attr name="minDeviceHeightDp" format="integer"/>
        <attr name="numGridDimension" format="integer"/>
    <declare-styleable name="GridSize">
        <attr name="minDeviceWidthDp" format="float"/>
        <attr name="minDeviceHeightDp" format="float"/>
        <attr name="numGridRows" format="integer"/>
        <attr name="numGridColumns" format="integer"/>
        <attr name="dbFile" />
        <attr name="defaultLayoutId"/>
        <attr name="demoModeLayoutId"/>
@@ -261,7 +262,7 @@
        <!-- File that contains the specs for all apps icon and text size.
        Needs FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE enabled -->
        <attr name="allAppsCellSpecsId" format="reference" />
        <attr name="rowCountSpecsId" format="reference" />
        <attr name="gridSizeSpecsId" format="reference" />
        <!-- defaults to allAppsCellSpecsId, if not specified -->
        <attr name="allAppsCellSpecsTwoPanelId" format="reference" />
        <!-- defaults to false, if not specified -->
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
    <include domain="database" path="launcher_3_by_3.db" />
    <include domain="database" path="launcher_2_by_2.db" />
    <include domain="database" path="launcher_7_by_3.db" />
    <include domain="database" path="launcher_8_by_3.db" />
    <include domain="sharedpref" path="com.android.launcher3.prefs.xml" />
    <include domain="file" path="downgrade_schema.json" />

+5 −5
Original line number Diff line number Diff line
@@ -865,7 +865,7 @@ public class DeviceProfile {
        canQsbInline = canQsbInline && hotseatQsbHeight > 0;

        return (mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline)
                || inv.isFixedLandscapeMode;
                || inv.isFixedLandscape;
    }

    private static DotRenderer createDotRenderer(
@@ -1834,7 +1834,7 @@ public class DeviceProfile {
            }
            int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
            // On isFixedLandscapeMode on phones we already have padding because of the camera hole
            int paddingSide = inv.isFixedLandscapeMode ? 0 : desiredWorkspaceHorizontalMarginPx;
            int paddingSide = inv.isFixedLandscape ? 0 : desiredWorkspaceHorizontalMarginPx;

            padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
        }
@@ -1934,7 +1934,7 @@ public class DeviceProfile {
                hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
                        mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
            }
        } else if (isTaskbarPresent || inv.isFixedLandscapeMode) {
        } else if (isTaskbarPresent || inv.isFixedLandscape) {
            // Center the QSB vertically with hotseat
            int hotseatBarBottomPadding = getHotseatBarBottomPadding();
            int hotseatBarTopPadding =
@@ -1953,7 +1953,7 @@ public class DeviceProfile {
            }
            startSpacing += getAdditionalQsbSpace();

            if (inv.isFixedLandscapeMode) {
            if (inv.isFixedLandscape) {
                endSpacing += mInsets.right;
                startSpacing +=  mInsets.left;
            }
@@ -2568,7 +2568,7 @@ public class DeviceProfile {
            }
            if (mTransposeLayoutWithOrientation == null) {
                mTransposeLayoutWithOrientation =
                        !(mInfo.isTablet(mWindowBounds) || mInv.isFixedLandscapeMode);
                        !(mInfo.isTablet(mWindowBounds) || mInv.isFixedLandscape);
            }
            if (mIsGestureMode == null) {
                mIsGestureMode = mInfo.getNavigationMode().hasGestures;
+58 −74
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ public class InvariantDeviceProfile implements SafeCloseable {
    @XmlRes
    public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
    @XmlRes
    public int rowCountSpecsId = INVALID_RESOURCE_HANDLE;;
    public int gridSizeSpecsId = INVALID_RESOURCE_HANDLE;;
    @XmlRes
    public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
    @XmlRes
@@ -216,7 +216,7 @@ public class InvariantDeviceProfile implements SafeCloseable {
    /**
     * Fixed landscape mode is the landscape on the phones.
     */
    public boolean isFixedLandscapeMode = false;
    public boolean isFixedLandscape = false;
    private LauncherPrefChangeListener mLandscapeModePreferenceListener;

    public String dbFile;
@@ -255,9 +255,12 @@ public class InvariantDeviceProfile implements SafeCloseable {
                });
        if (Flags.oneGridSpecs()) {
            mLandscapeModePreferenceListener = (String s) -> {
                boolean newFixedLandscapeValue = FIXED_LANDSCAPE_MODE.get(context);
                if (isFixedLandscapeMode != newFixedLandscapeValue) {
                    setFixedLandscape(context, newFixedLandscapeValue);
                if (isFixedLandscape != FIXED_LANDSCAPE_MODE.get(context)) {
                    MAIN_EXECUTOR.execute(() -> {
                        Trace.beginSection("InvariantDeviceProfile#setFixedLandscape");
                        onConfigChanged(context.getApplicationContext());
                        Trace.endSection();
                    });
                }
            };
            LauncherPrefs.INSTANCE.get(context).addListener(
@@ -295,7 +298,7 @@ public class InvariantDeviceProfile implements SafeCloseable {
                        gridName,
                        defaultInfo,
                        /*allowDisabledGrid=*/false,
                        isFixedLandscapeMode
                        FIXED_LANDSCAPE_MODE.get(context)
                ),
                defaultDeviceType);

@@ -309,7 +312,7 @@ public class InvariantDeviceProfile implements SafeCloseable {
                        gridName,
                        myInfo,
                        /*allowDisabledGrid=*/false,
                        isFixedLandscapeMode
                        FIXED_LANDSCAPE_MODE.get(context)
                ),
                deviceType);

@@ -345,13 +348,7 @@ public class InvariantDeviceProfile implements SafeCloseable {
    }

    private String initGrid(Context context, String gridName) {
        if (!Flags.oneGridSpecs() && (isFixedLandscapeMode || FIXED_LANDSCAPE_MODE.get(context))) {
            LauncherPrefs.get(context).put(FIXED_LANDSCAPE_MODE, false);
            isFixedLandscapeMode = false;
        }

        Info displayInfo = DisplayController.INSTANCE.get(context).getInfo();

        List<DisplayOption> allOptions = getPredefinedDeviceProfiles(
                context,
                gridName,
@@ -413,7 +410,7 @@ public class InvariantDeviceProfile implements SafeCloseable {
        isScalable = closestProfile.isScalable;
        devicePaddingId = closestProfile.devicePaddingId;
        workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
        rowCountSpecsId = closestProfile.mRowCountSpecsId;
        gridSizeSpecsId = closestProfile.mGridSizeSpecsId;
        workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId;
        allAppsSpecsId = closestProfile.mAllAppsSpecsId;
        allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId;
@@ -473,7 +470,7 @@ public class InvariantDeviceProfile implements SafeCloseable {
        startAlignTaskbar = displayOption.startAlignTaskbar;

        // Fixed Landscape mode
        isFixedLandscapeMode = FIXED_LANDSCAPE_MODE.get(context) && Flags.oneGridSpecs();
        isFixedLandscape = closestProfile.mIsFixedLandscape;

        // If the partner customization apk contains any grid overrides, apply them
        // Supported overrides: numRows, numColumns, iconSize
@@ -543,24 +540,6 @@ public class InvariantDeviceProfile implements SafeCloseable {
        });
    }

    /**
     * Updates the fixed landscape mode, this triggers a new IDP, reloads the database and triggers
     * a grid migration.
     */
    public void setFixedLandscape(Context context, boolean isFixedLandscape) {
        this.isFixedLandscapeMode = isFixedLandscape;
        if (isFixedLandscape) {
            // When in isFixedLandscape there should only be one default grid to choose from
            MAIN_EXECUTOR.execute(() -> {
                Trace.beginSection("InvariantDeviceProfile#setFixedLandscape");
                onConfigChanged(context.getApplicationContext());
                Trace.endSection();
            });
        } else {
            setCurrentGrid(context, LauncherPrefs.get(context).get(GRID_NAME));
        }
    }

    private Object[] toModelState() {
        return new Object[]{
                numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons,
@@ -651,14 +630,14 @@ public class InvariantDeviceProfile implements SafeCloseable {
    }

    /**
     * Parses through the xml to find GridDimension specs. Then calls findBestRowCount to get the
     * correct row count for this GridOption.
     * Parses through the xml to find GridSize specs. Then calls findBestGridSize to get the
     * correct grid size for this GridOption.
     *
     * @return the result of {@link #findBestRowCount(List, int, int)}.
     * @return the result of {@link #findBestGridSize(List, int, int)}.
     */
    private static GridDimension getRowCount(ResourceHelper resourceHelper, Context context,
    private static GridSize getGridSize(ResourceHelper resourceHelper, Context context,
            Info displayInfo) {
        ArrayList<GridDimension> rowCounts = new ArrayList<>();
        ArrayList<GridSize> gridSizes = new ArrayList<>();

        try (XmlResourceParser parser = resourceHelper.getXml()) {
            final int depth = parser.getDepth();
@@ -666,8 +645,8 @@ public class InvariantDeviceProfile implements SafeCloseable {
            while (((type = parser.next()) != XmlPullParser.END_TAG
                    || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
                if ((type == XmlPullParser.START_TAG)
                        && "GridDimension".equals(parser.getName())) {
                    rowCounts.add(new GridDimension(context, Xml.asAttributeSet(parser)));
                        && "GridSize".equals(parser.getName())) {
                    gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser)));
                }
            }
        } catch (IOException | XmlPullParserException e) {
@@ -677,24 +656,26 @@ public class InvariantDeviceProfile implements SafeCloseable {
        // Finds the min width and height in dp for all displays.
        int[] dimens = findMinWidthAndHeightDpForDevice(displayInfo);

        return findBestRowCount(rowCounts, dimens[0], dimens[1]);
        return findBestGridSize(gridSizes, dimens[0], dimens[1]);
    }

    /**
     * @return the biggest row count that fits the display dimensions spec using GridDimension to
     * determine that. If no best row count is found, return null.
     * @return the biggest grid size that fits the display dimensions.
     * If no best grid size is found, return null.
     */
    private static GridDimension findBestRowCount(List<GridDimension> list, int minWidthDp,
    private static GridSize findBestGridSize(List<GridSize> list, int minWidthDp,
            int minHeightDp) {
        GridDimension selectedRow = null;
        for (GridDimension item: list) {
        GridSize selectedGridSize = null;
        for (GridSize item: list) {
            if (minWidthDp >= item.mMinDeviceWidthDp && minHeightDp >= item.mMinDeviceHeightDp) {
                if (selectedRow == null || selectedRow.mNumGridDimension < item.mNumGridDimension) {
                    selectedRow = item;
                if (selectedGridSize == null
                        || (selectedGridSize.mNumColumns <= item.mNumColumns
                        && selectedGridSize.mNumRows <= item.mNumRows)) {
                    selectedGridSize = item;
                }
            }
        }
        return selectedRow;
        return selectedGridSize;
    }

    private static int[] findMinWidthAndHeightDpForDevice(Info displayInfo) {
@@ -767,7 +748,7 @@ public class InvariantDeviceProfile implements SafeCloseable {
        return parseAllDefinedGridOptions(context, displayInfo)
                .stream()
                .filter(go -> go.isEnabled(deviceType))
                .filter(go -> go.filterByFlag(deviceType, isFixedLandscapeMode))
                .filter(go -> go.filterByFlag(deviceType, isFixedLandscape))
                .collect(Collectors.toList());
    }

@@ -1037,7 +1018,7 @@ public class InvariantDeviceProfile implements SafeCloseable {
        private final int mWorkspaceCellSpecsTwoPanelId;
        private final int mAllAppsCellSpecsId;
        private final int mAllAppsCellSpecsTwoPanelId;
        private final int mRowCountSpecsId;
        private final int mGridSizeSpecsId;
        private final boolean mIsFixedLandscape;
        private final boolean mIsOldGrid;

@@ -1048,18 +1029,20 @@ public class InvariantDeviceProfile implements SafeCloseable {
            title = a.getString(R.styleable.GridDisplayOption_title);
            deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
                    DEVICE_CATEGORY_ALL);
            mRowCountSpecsId = a.getResourceId(
                    R.styleable.GridDisplayOption_rowCountSpecsId, INVALID_RESOURCE_HANDLE);
            mGridSizeSpecsId = a.getResourceId(
                    R.styleable.GridDisplayOption_gridSizeSpecsId, INVALID_RESOURCE_HANDLE);
            mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false);
            if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) {
                ResourceHelper resourceHelper = new ResourceHelper(context, mRowCountSpecsId);
                GridDimension numR = getRowCount(resourceHelper, context, displayInfo);
                numRows = numR.mNumGridDimension;
                dbFile = numR.mDbFile;
                defaultLayoutId = numR.mDefaultLayoutId;
                demoModeLayoutId = numR.mDemoModeLayoutId;
            if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
                ResourceHelper resourceHelper = new ResourceHelper(context, mGridSizeSpecsId);
                GridSize gridSize = getGridSize(resourceHelper, context, displayInfo);
                numColumns = gridSize.mNumColumns;
                numRows = gridSize.mNumRows;
                dbFile = gridSize.mDbFile;
                defaultLayoutId = gridSize.mDefaultLayoutId;
                demoModeLayoutId = gridSize.mDemoModeLayoutId;
            } else {
                numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0);
                numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
                dbFile = a.getString(R.styleable.GridDisplayOption_dbFile);
                defaultLayoutId = a.getResourceId(
                        R.styleable.GridDisplayOption_defaultLayoutId, 0);
@@ -1067,7 +1050,6 @@ public class InvariantDeviceProfile implements SafeCloseable {
                        R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId);
            }

            numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0);
            numSearchContainerColumns = a.getInt(
                    R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns);

@@ -1230,7 +1212,7 @@ public class InvariantDeviceProfile implements SafeCloseable {
            }

            // Here we return true if we want to show the new grids.
            if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) {
            if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) {
                return Flags.oneGridSpecs();
            }

@@ -1243,26 +1225,28 @@ public class InvariantDeviceProfile implements SafeCloseable {
        }
    }

    public static final class GridDimension {
        final int mNumGridDimension;
        final int mMinDeviceWidthDp;
        final int mMinDeviceHeightDp;
    public static final class GridSize {
        final int mNumRows;
        final int mNumColumns;
        final float mMinDeviceWidthDp;
        final float mMinDeviceHeightDp;
        final String mDbFile;
        final int mDefaultLayoutId;
        final int mDemoModeLayoutId;


        GridDimension(Context context, AttributeSet attrs) {
            TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridDimension);
        GridSize(Context context, AttributeSet attrs) {
            TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridSize);

            mNumGridDimension = (int) a.getFloat(R.styleable.GridDimension_numGridDimension, 0);
            mMinDeviceWidthDp = a.getInt(R.styleable.GridDimension_minDeviceWidthDp, 0);
            mMinDeviceHeightDp = a.getInt(R.styleable.GridDimension_minDeviceHeightDp, 0);
            mDbFile = a.getString(R.styleable.GridDimension_dbFile);
            mNumRows = (int) a.getFloat(R.styleable.GridSize_numGridRows, 0);
            mNumColumns = (int) a.getFloat(R.styleable.GridSize_numGridColumns, 0);
            mMinDeviceWidthDp = a.getFloat(R.styleable.GridSize_minDeviceWidthDp, 0);
            mMinDeviceHeightDp = a.getFloat(R.styleable.GridSize_minDeviceHeightDp, 0);
            mDbFile = a.getString(R.styleable.GridSize_dbFile);
            mDefaultLayoutId = a.getResourceId(
                    R.styleable.GridDimension_defaultLayoutId, 0);
                    R.styleable.GridSize_defaultLayoutId, 0);
            mDemoModeLayoutId = a.getResourceId(
                    R.styleable.GridDimension_demoModeLayoutId, mDefaultLayoutId);
                    R.styleable.GridSize_demoModeLayoutId, mDefaultLayoutId);

            a.recycle();
        }
+1 −1
Original line number Diff line number Diff line
@@ -789,7 +789,7 @@ public class Launcher extends StatefulActivity<LauncherState>
            LauncherPrefs.get(this).put(LauncherPrefs.ALLOW_ROTATION, false);
        }
        getRotationHelper().setFixedLandscape(
                Objects.requireNonNull(mDeviceProfile.inv).isFixedLandscapeMode
                Objects.requireNonNull(mDeviceProfile.inv).isFixedLandscape
        );
    }

Loading