Search in sources :

Example 1 with FixedScaleDrawable

use of com.android.launcher3.icons.FixedScaleDrawable in project Neo-Launcher by NeoApplications.

the class BaseIconFactory method normalizeAndWrapToAdaptiveIcon.

private Drawable normalizeAndWrapToAdaptiveIcon(@NonNull Drawable icon, boolean shrinkNonAdaptiveIcons, RectF outIconBounds, float[] outScale) {
    float scale;
    if (shrinkNonAdaptiveIcons && ATLEAST_OREO) {
        if (mWrapperIcon == null || !((AdaptiveIconCompat) mWrapperIcon).isMaskValid()) {
            mWrapperIcon = AdaptiveIconCompat.wrap(mContext.getDrawable(R.drawable.adaptive_icon_drawable_wrapper).mutate());
        }
        AdaptiveIconCompat dr = (AdaptiveIconCompat) mWrapperIcon;
        dr.setBounds(0, 0, 1, 1);
        boolean[] outShape = new boolean[1];
        scale = getNormalizer().getScale(icon, outIconBounds, dr.getIconMask(), outShape);
        if (!outShape[0] && (icon instanceof NonAdaptiveIconDrawable)) {
            FixedScaleDrawable fsd = ((FixedScaleDrawable) dr.getForeground());
            fsd.setDrawable(icon);
            fsd.setScale(scale);
            icon = dr;
            scale = getNormalizer().getScale(icon, outIconBounds, null, null);
            ((ColorDrawable) dr.getBackground()).setColor(mWrapperBackgroundColor);
        }
    } else {
        scale = getNormalizer().getScale(icon, outIconBounds, null, null);
    }
    outScale[0] = scale;
    return icon;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) AdaptiveIconCompat(com.android.launcher3.AdaptiveIconCompat)

Example 2 with FixedScaleDrawable

use of com.android.launcher3.icons.FixedScaleDrawable in project android_packages_apps_404Launcher by P-404.

the class AdaptiveIconWrapper method wrap.

@TargetApi(26)
public Drawable wrap(Drawable icon, int backgroundColor) {
    if (Utilities.ATLEAST_OREO && !(icon instanceof AdaptiveIconDrawable)) {
        boolean[] outShape = new boolean[1];
        mWrapper.setBounds(0, 0, 1, 1);
        LauncherIcons icons = LauncherIcons.obtain(mContext);
        IconNormalizer normalizer = icons.getNormalizer();
        float scale = normalizer.getScale(icon, null, mWrapper.getIconMask(), outShape);
        icons.recycle();
        if (!outShape[0]) {
            FixedScaleDrawable fsd = ((FixedScaleDrawable) mWrapper.getForeground());
            fsd.setDrawable(icon);
            fsd.setScale(scale);
            ((ColorDrawable) mWrapper.getBackground()).setColor(backgroundColor);
            return mWrapper;
        }
    }
    return icon;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) LauncherIcons(com.android.launcher3.icons.LauncherIcons) IconNormalizer(com.android.launcher3.icons.IconNormalizer) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) FixedScaleDrawable(com.android.launcher3.icons.FixedScaleDrawable) TargetApi(android.annotation.TargetApi)

Example 3 with FixedScaleDrawable

use of com.android.launcher3.icons.FixedScaleDrawable in project Neo-Launcher by NeoApplications.

the class AdaptiveIconGenerator method genResult.

private Drawable genResult() {
    if (!Utilities.ATLEAST_OREO || !shouldWrap) {
        if (roundIcon != null) {
            if (icon instanceof AdaptiveIconCompat && !(roundIcon instanceof AdaptiveIconCompat)) {
                return icon;
            }
            return roundIcon;
        }
        return icon;
    }
    if (icon instanceof AdaptiveIconCompat) {
        if (!treatWhite || !isBackgroundWhite) {
            return icon;
        }
        if (((AdaptiveIconCompat) icon).getBackground() instanceof ColorDrawable) {
            AdaptiveIconCompat mutIcon = (AdaptiveIconCompat) icon.mutate();
            ((ColorDrawable) mutIcon.getBackground()).setColor(backgroundColor);
            return mutIcon;
        }
        return new AdaptiveIconCompat(new ColorDrawable(backgroundColor), ((AdaptiveIconCompat) icon).getForeground());
    }
    initTmpIfNeeded();
    ((FixedScaleDrawable) tmp.getForeground()).setDrawable(icon);
    if (matchesMaskShape || isFullBleed || noMixinNeeded) {
        float scale;
        if (noMixinNeeded) {
            float upScale = min(width / aWidth, height / aHeight);
            scale = NO_MIXIN_ICON_SCALE * upScale;
        } else {
            float upScale = max(width / aWidth, height / aHeight);
            scale = FULL_BLEED_ICON_SCALE * upScale;
        }
        ((FixedScaleDrawable) tmp.getForeground()).setScale(scale);
    } else {
        ((FixedScaleDrawable) tmp.getForeground()).setScale(scale);
    }
    ((ColorDrawable) tmp.getBackground()).setColor(backgroundColor);
    return tmp;
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) AdaptiveIconCompat(com.android.launcher3.AdaptiveIconCompat) FixedScaleDrawable(com.android.launcher3.icons.FixedScaleDrawable)

Aggregations

ColorDrawable (android.graphics.drawable.ColorDrawable)3 AdaptiveIconCompat (com.android.launcher3.AdaptiveIconCompat)2 FixedScaleDrawable (com.android.launcher3.icons.FixedScaleDrawable)2 TargetApi (android.annotation.TargetApi)1 AdaptiveIconDrawable (android.graphics.drawable.AdaptiveIconDrawable)1 IconNormalizer (com.android.launcher3.icons.IconNormalizer)1 LauncherIcons (com.android.launcher3.icons.LauncherIcons)1