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

Commit 6c304b15 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Always insetting the widget by a minimum of 6dp

Removing default widget padding logic. Also widget padding it applied
at ShortcutAndWidgetContainer so that the widgetView always has the
correct size.

Bug: 274826296
Bug: 257589413
Test: Verified using screenshots
Flags: N/A
Change-Id: Id4b5e94db6ec7b2aa3dca87b1e9ccc831b608cac
parent c4e25086
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -32,12 +32,6 @@
    <dimen name="dynamic_grid_hotseat_bottom_tall_padding">0dp</dimen>
    <dimen name="spring_loaded_hotseat_top_margin">76dp</dimen>

    <!-- Qsb -->
    <!-- Used for adjusting the position of QSB when placed in hotseat. This is a ratio and a higher
     number signifies that the QSB is close to the hotseat icons and a lower number signifies that
      it is close to the bottom of the screen -->
    <item name="qsb_center_factor" format="float" type="dimen">0.325</item>

    <dimen name="dynamic_grid_hotseat_side_padding">0dp</dimen>

    <!-- Scalable Grid -->
+4 −15
Original line number Diff line number Diff line
package com.android.launcher3;

import static android.appwidget.AppWidgetHostView.getDefaultPaddingForWidget;

import static com.android.launcher3.CellLayout.SPRING_LOADED_PROGRESS;
import static com.android.launcher3.LauncherAnimUtils.LAYOUT_HEIGHT;
import static com.android.launcher3.LauncherAnimUtils.LAYOUT_WIDTH;
@@ -77,8 +75,6 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
    private DragLayer mDragLayer;
    private ImageButton mReconfigureButton;

    private Rect mWidgetPadding;

    private final int mBackgroundPadding;
    private final int mTouchTargetWidth;

@@ -218,9 +214,6 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
        mMaxHSpan = info.maxSpanX;
        mMaxVSpan = info.maxSpanY;

        mWidgetPadding = getDefaultPaddingForWidget(getContext(),
                widgetView.getAppWidgetInfo().provider, null);

        // Only show resize handles for the directions in which resizing is possible.
        InvariantDeviceProfile idp = LauncherAppState.getIDP(cellLayout.getContext());
        mVerticalResizeActive = (info.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0
@@ -517,16 +510,12 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
     */
    private void getSnappedRectRelativeToDragLayer(Rect out) {
        float scale = mWidgetView.getScaleToFit();

        mDragLayer.getViewRectRelativeToSelf(mWidgetView, out);

        int width = 2 * mBackgroundPadding
                + (int) (scale * (out.width() - mWidgetPadding.left - mWidgetPadding.right));
        int height = 2 * mBackgroundPadding
                + (int) (scale * (out.height() - mWidgetPadding.top - mWidgetPadding.bottom));

        int x = (int) (out.left - mBackgroundPadding + scale * mWidgetPadding.left);
        int y = (int) (out.top - mBackgroundPadding + scale * mWidgetPadding.top);
        int width = 2 * mBackgroundPadding + Math.round(scale * out.width());
        int height = 2 * mBackgroundPadding + Math.round(scale * out.height());
        int x = out.left - mBackgroundPadding;
        int y = out.top - mBackgroundPadding;

        out.left = x;
        out.top = y;
+17 −22
Original line number Diff line number Diff line
@@ -67,14 +67,12 @@ public class DeviceProfile {
    private static final int DEFAULT_DOT_SIZE = 100;
    private static final float ALL_APPS_TABLET_MAX_ROWS = 5.5f;
    private static final float MIN_FOLDER_TEXT_SIZE_SP = 16f;
    private static final float MIN_WIDGET_PADDING_DP = 6f;

    public static final PointF DEFAULT_SCALE = new PointF(1.0f, 1.0f);
    public static final ViewScaleProvider DEFAULT_PROVIDER = itemInfo -> DEFAULT_SCALE;
    public static final Consumer<DeviceProfile> DEFAULT_DIMENSION_PROVIDER = dp -> {};

    // Ratio of empty space, qsb should take up to appear visually centered.
    private final float mQsbCenterFactor;

    public final InvariantDeviceProfile inv;
    private final Info mInfo;
    private final DisplayMetrics mMetrics;
@@ -252,6 +250,10 @@ public class DeviceProfile {
    // Insets
    private final Rect mInsets = new Rect();
    public final Rect workspacePadding = new Rect();
    // Additional padding added to the widget inside its cellSpace. It is applied outside
    // the widgetView, such that the actual view size is same as the widget size.
    public final Rect widgetPadding = new Rect();

    // When true, nav bar is on the left side of the screen.
    private boolean mIsSeascape;

@@ -314,9 +316,6 @@ public class DeviceProfile {
        availableHeightPx = windowBounds.availableSize.y;

        aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
        boolean isTallDevice = Float.compare(aspectRatio, TALL_DEVICE_ASPECT_RATIO_THRESHOLD) >= 0;
        mQsbCenterFactor = res.getFloat(R.dimen.qsb_center_factor);

        if (isTwoPanels) {
            if (isLandscape) {
                mTypeIndex = INDEX_TWO_PANEL_LANDSCAPE;
@@ -730,22 +729,6 @@ public class DeviceProfile {
        return mInfo;
    }

    /**
     * We inset the widget padding added by the system and instead rely on the border spacing
     * between cells to create reliable consistency between widgets
     */
    public boolean shouldInsetWidgets() {
        Rect widgetPadding = inv.defaultWidgetPadding;

        // Check all sides to ensure that the widget won't overlap into another cell, or into
        // status bar.
        return workspaceTopPadding > widgetPadding.top
                && cellLayoutBorderSpacePx.x > widgetPadding.left
                && cellLayoutBorderSpacePx.y > widgetPadding.top
                && cellLayoutBorderSpacePx.x > widgetPadding.right
                && cellLayoutBorderSpacePx.y > widgetPadding.bottom;
    }

    public Builder toBuilder(Context context) {
        WindowBounds bounds = new WindowBounds(
                widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
@@ -999,6 +982,18 @@ public class DeviceProfile {
        // Folder icon
        folderIconSizePx = IconNormalizer.getNormalizedCircleSize(iconSizePx);
        folderIconOffsetYPx = (iconSizePx - folderIconSizePx) / 2;

        // Update widget padding:
        float minSpacing = pxFromDp(MIN_WIDGET_PADDING_DP, mMetrics);
        if (cellLayoutBorderSpacePx.x < minSpacing
                || cellLayoutBorderSpacePx.y < minSpacing) {
            widgetPadding.left = widgetPadding.right =
                    Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.x));
            widgetPadding.top = widgetPadding.bottom =
                    Math.round(Math.max(0, minSpacing - cellLayoutBorderSpacePx.y));
        } else {
            widgetPadding.setEmpty();
        }
    }

    /**
+0 −7
Original line number Diff line number Diff line
@@ -26,8 +26,6 @@ import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUN
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;

import android.annotation.TargetApi;
import android.appwidget.AppWidgetHostView;
import android.content.ComponentName;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -35,7 +33,6 @@ import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
@@ -192,7 +189,6 @@ public class InvariantDeviceProfile {
    public List<DeviceProfile> supportedProfiles = Collections.EMPTY_LIST;

    public Point defaultWallpaperSize;
    public Rect defaultWidgetPadding;

    private final ArrayList<OnIDPChangeListener> mChangeListeners = new ArrayList<>();

@@ -443,9 +439,6 @@ public class InvariantDeviceProfile {
                    deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
                    deviceProfile.recalculateHotseatWidthAndBorderSpace();
                });

        ComponentName cn = new ComponentName(context.getPackageName(), getClass().getName());
        defaultWidgetPadding = AppWidgetHostView.getDefaultPaddingForWidget(context, cn, null);
    }

    public void addOnChangeListener(OnIDPChangeListener listener) {
+4 −8
Original line number Diff line number Diff line
@@ -46,8 +46,6 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
    // return an (x, y) value from helper functions. Do NOT use them to maintain other state.
    private final int[] mTmpCellXY = new int[2];

    private final Rect mTempRect = new Rect();

    @ContainerType
    private final int mContainerType;
    private final WallpaperManager mWallpaperManager;
@@ -124,13 +122,12 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
        CellLayoutLayoutParams lp = (CellLayoutLayoutParams) child.getLayoutParams();
        if (child instanceof NavigableAppWidgetHostView) {
            DeviceProfile profile = mActivity.getDeviceProfile();
            ((NavigableAppWidgetHostView) child).getWidgetInset(profile, mTempRect);
            final PointF appWidgetScale = profile.getAppWidgetScale((ItemInfo) child.getTag());
            lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
                    appWidgetScale.x, appWidgetScale.y, mBorderSpace, mTempRect);
                    appWidgetScale.x, appWidgetScale.y, mBorderSpace, profile.widgetPadding);
        } else {
            lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
                    mBorderSpace, null);
                    mBorderSpace);
        }
    }

@@ -149,13 +146,12 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
        final DeviceProfile dp = mActivity.getDeviceProfile();

        if (child instanceof NavigableAppWidgetHostView) {
            ((NavigableAppWidgetHostView) child).getWidgetInset(dp, mTempRect);
            final PointF appWidgetScale = dp.getAppWidgetScale((ItemInfo) child.getTag());
            lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
                    appWidgetScale.x, appWidgetScale.y, mBorderSpace, mTempRect);
                    appWidgetScale.x, appWidgetScale.y, mBorderSpace, dp.widgetPadding);
        } else {
            lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
                    mBorderSpace, null);
                    mBorderSpace);
            // Center the icon/folder
            int cHeight = getCellContentHeight();
            int cellPaddingY = dp.isScalableGrid && mContainerType == WORKSPACE
Loading