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

Commit a83d696a authored by Andy Mast's avatar Andy Mast
Browse files

Themes: Fix blurry composed icons

In a composed icon the original icon could be scaled incorrectly
due to a density mismatch resulting in blurry icons.

For example, Grouper has a screen density of 213 dpi but Trebuchet will want to show a larger icon and therefore
requests to the framework to load app icons with a slightly higher density of 320dpi (XHDPI bucket).

When Resources.loadDrawable(TypedValue value, ...) is called, it will use observe value.density. Since the image
is from the XHDPI bucket it will have a TypedValue.density of 320dpi, much higher than the screen's 213dpi, and therefore
loadDrawablei() will configure BitmapFactory to scale down the image to match the screen density. This is not what we want,
so this patch modifies the density value to prevent scaling, much the same way getDrawableForDensity() does.

Change-Id: Ie638c8576872f9115dc029bb4823b50bb31ecebf
parent 9a5386f6
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -1225,7 +1225,27 @@ public class Resources {
        if (found) {
            if (supportComposedIcons && IconPackHelper.shouldComposeIcon(mComposedIconInfo) &&
                    info != null && info.themedIcon == 0) {
                int tmpDensity = outValue.density;
                /*
                 * Pretend the requested density is actually the display density. If
                 * the drawable returned is not the requested density, then force it
                 * to be scaled later by dividing its density by the ratio of
                 * requested density to actual device density. Drawables that have
                 * undefined density or no density don't need to be handled here.
                 */
                if (outValue.density > 0 && outValue.density != TypedValue.DENSITY_NONE) {
                    if (outValue.density == density) {
                        outValue.density = mMetrics.densityDpi;
                    } else {
                        outValue.density = (outValue.density * mMetrics.densityDpi) / density;
                    }
                }
                Drawable dr = loadDrawable(outValue, id);

                // Return to original density. If we do not do this then
                // the caller will get the wrong density for the given id and perform
                // more of its own scaling in loadDrawable
                outValue.density = tmpDensity;
                IconCustomizer.getValue(this, id, outValue, dr);
            }
            return;