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

Commit d621e34f authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

Multiple custom themes 4/4

Bind preview cover and wallpaper in name step.

Bug: 132257073
Change-Id: Id557473dbf44b4ba8f72b2fa23b00f70da328d99
parent efb9f5f7
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import com.android.customization.widget.DynamicAdaptiveIconDrawable;
import com.android.wallpaper.R;
import com.android.wallpaper.asset.Asset;
import com.android.wallpaper.asset.BitmapCachingAsset;
import com.android.wallpaper.asset.ResourceAsset;
import com.android.wallpaper.model.LiveWallpaperInfo;
import com.android.wallpaper.model.WallpaperInfo;

@@ -295,7 +294,8 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
        @ColorInt private int mColorAccentLight = -1;
        @ColorInt private int mColorAccentDark = -1;
        private List<Drawable> mIcons = new ArrayList<>();
        private String mShapePath;
        private String mPathString;
        private Path mShapePath;
        private boolean mIsDefault;
        @Dimension private int mCornerRadius;
        private Asset mWallpaperAsset;
@@ -308,11 +308,14 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
                    createPreviewInfo(context));
        }

        protected PreviewInfo createPreviewInfo(Context context) {
        public PreviewInfo createPreviewInfo(Context context) {
            ShapeDrawable shapeDrawable = null;
            List<Drawable> shapeIcons = new ArrayList<>();
            if (!TextUtils.isEmpty(mShapePath)) {
                Path path = PathParser.createPathFromPathData(mShapePath);
            Path path = mShapePath;
            if (!TextUtils.isEmpty(mPathString)) {
                path = PathParser.createPathFromPathData(mPathString);
            }
            if (path != null) {
                PathShape shape = new PathShape(path, PATH_SIZE, PATH_SIZE);
                shapeDrawable = new ShapeDrawable(shape);
                shapeDrawable.setIntrinsicHeight((int) PATH_SIZE);
@@ -322,6 +325,8 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
                        AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) icon;
                        shapeIcons.add(new DynamicAdaptiveIconDrawable(adaptiveIcon.getBackground(),
                                adaptiveIcon.getForeground(), path));
                    } else if (icon instanceof DynamicAdaptiveIconDrawable) {
                        shapeIcons.add(icon);
                    }
                    // TODO: add iconloader library's legacy treatment helper methods for
                    //  non-adaptive icons
@@ -332,6 +337,10 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
                    mWallpaperAsset, shapeIcons);
        }

        public Map<String, String> getPackages() {
            return Collections.unmodifiableMap(mPackages);
        }

        public String getTitle() {
            return mTitle;
        }
@@ -372,6 +381,11 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
        }

        public Builder setShapePath(String path) {
            mPathString = path;
            return this;
        }

        public Builder setShapePath(Path path) {
            mShapePath = path;
            return this;
        }
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ public class ThemeManager implements CustomizationManager<ThemeBundle> {
    private void applyOverlays(ThemeBundle theme, Callback callback) {
        boolean allApplied = Settings.Secure.putString(mActivity.getContentResolver(),
                ResourceConstants.THEME_SETTING, theme.getSerializedPackages());
        if (theme instanceof CustomTheme && !((CustomTheme) theme).isDefined()) {
        if (theme instanceof CustomTheme) {
            storeCustomTheme((CustomTheme) theme);
        }
        mCurrentOverlays = null;
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ public class ColorOptionsProvider extends ThemeComponentOptionProvider<ColorOpti
        String iconPackage =
                mCustomThemeManager.getOverlayPackages().get(OVERLAY_CATEGORY_ICON_ANDROID);
        if (TextUtils.isEmpty(iconPackage)) {
            iconPackage = SYSUI_PACKAGE;
            iconPackage = ANDROID_PACKAGE;
        }
        for (String iconName : ICONS_FOR_PREVIEW) {
            try {
+19 −10
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@ import android.text.TextUtils;
import androidx.annotation.Nullable;

import com.android.customization.model.CustomizationManager;
import com.android.customization.model.theme.ThemeBundle.PreviewInfo;
import com.android.customization.model.theme.ThemeManager;
import com.android.customization.model.theme.custom.CustomTheme.Builder;
import com.android.wallpaper.R;

import java.util.HashMap;
@@ -29,12 +31,13 @@ import java.util.Map;

public class CustomThemeManager implements CustomizationManager<ThemeComponentOption> {

    private final Map<String, String> mOverlayPackages = new HashMap<>();
    private final CustomTheme mOriginalTheme;
    private final CustomTheme.Builder mBuilder;

    private CustomThemeManager(Map<String, String> overlayPackages,
            @Nullable CustomTheme originalTheme) {
        mOverlayPackages.putAll(overlayPackages);
        mBuilder = new Builder();
        overlayPackages.forEach(mBuilder::addOverlayPackage);
        mOriginalTheme = originalTheme;
    }

@@ -45,22 +48,23 @@ public class CustomThemeManager implements CustomizationManager<ThemeComponentOp

    @Override
    public void apply(ThemeComponentOption option, @Nullable Callback callback) {
        option.getOverlayPackages().forEach((category, packageName) -> {
            if (!TextUtils.isEmpty(packageName)) {
                mOverlayPackages.put(category, packageName);
            }
        });
//        option.getOverlayPackages().forEach((category, packageName) -> {
//            if (!TextUtils.isEmpty(packageName)) {
//                mBuilder.addOverlayPackage(category, packageName);
//            }
//        });
        option.buildStep(mBuilder);
        if (callback != null) {
            callback.onSuccess();
        }
    }

    public Map<String, String> getOverlayPackages() {
        return mOverlayPackages;
        return mBuilder.getPackages();
    }

    public CustomTheme buildPartialCustomTheme(String id, String title) {
        return new CustomTheme(id, title, mOverlayPackages, null);
    public CustomTheme buildPartialCustomTheme(Context context, String id, String title) {
        return ((CustomTheme.Builder)mBuilder.setId(id).setTitle(title)).build(context);
    }

    @Override
@@ -72,6 +76,10 @@ public class CustomThemeManager implements CustomizationManager<ThemeComponentOp
        return mOriginalTheme;
    }

    public PreviewInfo buildCustomThemePreviewInfo(Context context) {
        return mBuilder.createPreviewInfo(context);
    }

    public static CustomThemeManager create(
            @Nullable CustomTheme customTheme, ThemeManager themeManager) {
        if (customTheme != null && customTheme.isDefined()) {
@@ -80,4 +88,5 @@ public class CustomThemeManager implements CustomizationManager<ThemeComponentOp
        // Seed the first custom theme with the currently applied theme.
        return new CustomThemeManager(themeManager.getCurrentOverlays(), customTheme);
    }

}
+19 −6
Original line number Diff line number Diff line
@@ -16,9 +16,8 @@
package com.android.customization.model.theme.custom;

import static com.android.customization.model.ResourceConstants.ANDROID_PACKAGE;
import static com.android.customization.model.ResourceConstants.CONFIG_CORNERRADIUS;
import static com.android.customization.model.ResourceConstants.CONFIG_ICON_MASK;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_FONT;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SHAPE;
import static com.android.customization.model.ResourceConstants.PATH_SIZE;

@@ -28,7 +27,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.Path;
import android.graphics.Typeface;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
@@ -36,6 +34,7 @@ import android.graphics.drawable.shapes.PathShape;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.Dimension;
import androidx.core.graphics.PathParser;

import com.android.customization.model.ResourceConstants;
@@ -75,8 +74,8 @@ public class ShapeOptionsProvider extends ThemeComponentOptionProvider<ShapeOpti
                ShapeDrawable shapeDrawable = createShapeDrawable(path);
                PackageManager pm = mContext.getPackageManager();
                String label = pm.getApplicationInfo(overlayPackage, 0).loadLabel(pm).toString();
                mOptions.add(new ShapeOption(overlayPackage, label, shapeDrawable,
                        getShapedIcons(path)));
                mOptions.add(new ShapeOption(overlayPackage, label, path,
                        loadCornerRadius(overlayPackage), shapeDrawable, getShapedIcons(path)));
            } catch (NameNotFoundException | NotFoundException e) {
                Log.w(TAG, String.format("Couldn't load shape overlay %s, will skip it",
                        overlayPackage), e);
@@ -88,7 +87,10 @@ public class ShapeOptionsProvider extends ThemeComponentOptionProvider<ShapeOpti
        Resources system = Resources.getSystem();
        Path path = loadPath(system, ANDROID_PACKAGE);
        ShapeDrawable shapeDrawable = createShapeDrawable(path);
        mOptions.add(new ShapeOption(null, mContext.getString(R.string.default_theme_title),
        mOptions.add(new ShapeOption(null, mContext.getString(R.string.default_theme_title), path,
                system.getDimensionPixelOffset(
                    system.getIdentifier(ResourceConstants.CONFIG_CORNERRADIUS,
                        "dimen", ResourceConstants.ANDROID_PACKAGE)),
                shapeDrawable, getShapedIcons(path)));
    }

@@ -127,4 +129,15 @@ public class ShapeOptionsProvider extends ThemeComponentOptionProvider<ShapeOpti
        }
        return null;
    }

    @Dimension
    private int loadCornerRadius(String packageName)
            throws NameNotFoundException, NotFoundException {

        Resources overlayRes =
                mContext.getPackageManager().getResourcesForApplication(
                        packageName);
        return overlayRes.getDimensionPixelOffset(overlayRes.getIdentifier(
                CONFIG_CORNERRADIUS, "dimen", packageName));
    }
}
Loading