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

Commit 61fafd5b authored by Jacqueline Bronger's avatar Jacqueline Bronger
Browse files

Add separate app banner mask for adaptive banners.

Bug: 417277919
Test: atest AdaptiveIconDrawableTest
Flag: EXEMPT bugfix

Change-Id: Id33937df2e9831ad72ccd91963642eb3a1ed5a9b
parent 0a8961a7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -73,4 +73,8 @@

    <!-- Android TV does not have a Recents UI by default. -->
    <bool name="config_hasRecents">false</bool>

    <!-- Rectangle with rounded corners shape mask to be used for {@link AdaptiveIconDrawable} banners. -->
    <string name="config_banner_mask" translatable="false">"M0 10C0 4.47716 2.5184 0 5.625 0H94.375C97.4816 0 100 4.47715 100 10V90C100 95.5229 97.4816 100 94.375 100H5.625C2.5184 100 0 95.5229 0 90V10Z"</string>

</resources>
+3 −0
Original line number Diff line number Diff line
@@ -4812,6 +4812,9 @@

    <!-- Specifies the path that is used by AdaptiveIconDrawable class to crop launcher icons. -->
    <string name="config_icon_mask" translatable="false">"M50,0L92,0C96.42,0 100,4.58 100 8L100,92C100, 96.42 96.42 100 92 100L8 100C4.58, 100 0 96.42 0 92L0 8 C 0 4.42 4.42 0 8 0L50 0Z"</string>
    <!-- Specifies the path that is used by AdaptiveIconDrawable class to crop launcher banners. -->
    <string name="config_banner_mask" translatable="false">@string/config_icon_mask</string>


    <!-- The component name, flattened to a string, for the default accessibility service to be
         enabled by the accessibility shortcut. This service must be trusted, as it can be activated
+1 −0
Original line number Diff line number Diff line
@@ -3803,6 +3803,7 @@
  <java-symbol type="raw" name="fallback_categories" />

  <java-symbol type="string" name="config_icon_mask" />
  <java-symbol type="string" name="config_banner_mask" />
  <java-symbol type="string" name="config_batterymeterPerimeterPath" />
  <java-symbol type="string" name="config_batterymeterErrorPerimeterPath" />
  <java-symbol type="string" name="config_batterymeterFillMask" />
+19 −2
Original line number Diff line number Diff line
@@ -105,11 +105,20 @@ public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback
    private static final float EXTRA_INSET_PERCENTAGE = 1 / 4f;
    private static final float DEFAULT_VIEW_PORT_SCALE = 1f / (1 + 2 * EXTRA_INSET_PERCENTAGE);

    // Aspect ratio over which the icon should be considered a banner. Halfway between square icon
    // and 16:9 banner to account for slight variations in aspect ratios.
    private static final float BANNER_THRESHOLD_ASPECT_RATIO = 1.38f;

    /**
     * Clip path defined in R.string.config_icon_mask.
     */
    private static Path sMask;

    /**
     * Clip path defined in R.string.config_banner_mask;
     */
    private static Path sMaskBanner;

    /**
     * Scaled mask based on the view bounds.
     */
@@ -165,6 +174,7 @@ public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback
        // TODO: either make sMask update only when config_icon_mask changes OR
        // get rid of it all-together in layoutlib
        sMask = PathParser.createPathFromPathData(r.getString(R.string.config_icon_mask));
        sMaskBanner = PathParser.createPathFromPathData(r.getString(R.string.config_banner_mask));
        mMask = new Path(sMask);
        mMaskScaleOnly = new Path(mMask);
        mMaskMatrix = new Matrix();
@@ -362,12 +372,19 @@ public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback
    }

    private void updateMaskBoundsInternal(Rect b) {
        Path mask;
        if (b.width() / (float) b.height() > BANNER_THRESHOLD_ASPECT_RATIO) {
            mask = sMaskBanner;
        } else {
            mask = sMask;
        }

        // reset everything that depends on the view bounds
        mMaskMatrix.setScale(b.width() / MASK_SIZE, b.height() / MASK_SIZE);
        sMask.transform(mMaskMatrix, mMaskScaleOnly);
        mask.transform(mMaskMatrix, mMaskScaleOnly);

        mMaskMatrix.postTranslate(b.left, b.top);
        sMask.transform(mMaskMatrix, mMask);
        mask.transform(mMaskMatrix, mMask);

        if (mLayersBitmap == null || mLayersBitmap.getWidth() != b.width()
                || mLayersBitmap.getHeight() != b.height()) {