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

Commit d45a8b5d authored by Mike Digman's avatar Mike Digman
Browse files

Correct Sharesheet icon and badge sizing

SimpleIconFactory previously used fixed resources to render
icons and badges. Resolver and Chooser need different icon and
badge dimensions. This cause scaling issues. Move those sizes to
a styleable attr. New dimensions align with design red lines.

Test: manual
Fixes: 155813501
Change-Id: I765ba7aab1346eacf9e1cf7b6cdbfbbb14dbc3bb
parent 2dfc9f85
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -778,6 +778,11 @@ public class ChooserActivity extends ResolverActivity implements
        mDirectShareShortcutInfoCache = new HashMap<>();
    }

    @Override
    protected int appliedThemeResId() {
        return R.style.Theme_DeviceDefault_Chooser;
    }

    private AppPredictor setupAppPredictorForUser(UserHandle userHandle,
            AppPredictor.Callback appPredictorCallback) {
        AppPredictor appPredictor = getAppPredictorForDirectShareIfEnabled(userHandle);
+5 −1
Original line number Diff line number Diff line
@@ -324,7 +324,7 @@ public class ResolverActivity extends Activity implements
    protected void onCreate(Bundle savedInstanceState, Intent intent,
            CharSequence title, int defaultTitleRes, Intent[] initialIntents,
            List<ResolveInfo> rList, boolean supportsAlwaysUseOption) {
        setTheme(R.style.Theme_DeviceDefault_Resolver);
        setTheme(appliedThemeResId());
        super.onCreate(savedInstanceState);

        // Determine whether we should show that intent is forwarded
@@ -507,6 +507,10 @@ public class ResolverActivity extends Activity implements
                /* shouldShowNoCrossProfileIntentsEmptyState= */ getUser().equals(intentUser));
    }

    protected int appliedThemeResId() {
        return R.style.Theme_DeviceDefault_Resolver;
    }

    /**
     * Returns the user id of the user that the starting intent originated from.
     * <p>This is not necessarily equal to {@link #getUserId()} or {@link UserHandle#myUserId()},
+25 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.content.Context.ACTIVITY_SERVICE;
import static android.graphics.Paint.DITHER_FLAG;
import static android.graphics.Paint.FILTER_BITMAP_FLAG;

import android.annotation.AttrRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
@@ -46,6 +47,7 @@ import android.graphics.drawable.DrawableWrapper;
import android.os.UserHandle;
import android.util.AttributeSet;
import android.util.Pools.SynchronizedPool;
import android.util.TypedValue;

import com.android.internal.R;

@@ -92,10 +94,8 @@ public class SimpleIconFactory {
            final ActivityManager am = (ActivityManager) ctx.getSystemService(ACTIVITY_SERVICE);
            final int iconDpi = (am == null) ? 0 : am.getLauncherLargeIconDensity();

            final Resources r = ctx.getResources();
            final int iconSize = r.getDimensionPixelSize(R.dimen.resolver_icon_size);
            final int badgeSize = r.getDimensionPixelSize(R.dimen.resolver_badge_size);

            final int iconSize = getIconSizeFromContext(ctx);
            final int badgeSize = getBadgeSizeFromContext(ctx);
            instance = new SimpleIconFactory(ctx, iconDpi, iconSize, badgeSize);
            instance.setWrapperBackgroundColor(Color.WHITE);
        }
@@ -103,6 +103,27 @@ public class SimpleIconFactory {
        return instance;
    }

    private static int getAttrDimFromContext(Context ctx, @AttrRes int attrId, String errorMsg) {
        final Resources res = ctx.getResources();
        TypedValue outVal = new TypedValue();
        if (!ctx.getTheme().resolveAttribute(attrId, outVal, true)) {
            throw new IllegalStateException(errorMsg);
        }
        return res.getDimensionPixelSize(outVal.resourceId);
    }

    private static int getIconSizeFromContext(Context ctx) {
        return getAttrDimFromContext(ctx,
                com.android.internal.R.attr.iconfactoryIconSize,
                "Expected theme to define iconfactoryIconSize.");
    }

    private static int getBadgeSizeFromContext(Context ctx) {
        return getAttrDimFromContext(ctx,
                com.android.internal.R.attr.iconfactoryBadgeSize,
                "Expected theme to define iconfactoryBadgeSize.");
    }

    /**
     * Recycles the SimpleIconFactory so others may use it.
     *
+1 −1
Original line number Diff line number Diff line
@@ -5053,7 +5053,7 @@
                 android:forceQueryable="true"
                 android:directBootAware="true">
        <activity android:name="com.android.internal.app.ChooserActivity"
                android:theme="@style/Theme.DeviceDefault.Resolver"
                android:theme="@style/Theme.DeviceDefault.Chooser"
                android:finishOnCloseSystemDialogs="true"
                android:excludeFromRecents="true"
                android:documentLaunchMode="never"
+3 −0
Original line number Diff line number Diff line
@@ -9230,4 +9230,7 @@
    </declare-styleable>

    <attr name="autoSizePresetSizes" />

    <attr name="iconfactoryIconSize" format="dimension"/>
    <attr name="iconfactoryBadgeSize" format="dimension"/>
</resources>
Loading