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

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

ThemePicker: "Apply theme" initial implementation

Use the current API to apply the packages for a given theme.
Still pending is storing the applied overlay packages, and applying the
default theme.

Bug: 120559294

Change-Id: I7c15f8ab94b1dec8576141eaecd4f3e059249fb1
parent d2229f0f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <Button
                android:id="@+id/apply_button"
                style="@style/ActionPrimaryButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
+3 −0
Original line number Diff line number Diff line
@@ -65,4 +65,7 @@

    <!--Title for a grid option, describing the number of columns and rows, eg: 4x4 [CHAR LIMIT=10] -->
    <string name="grid_title_pattern"><xliff:g name="num_cols" example="1">%1$d</xliff:g>x<xliff:g name="num_rows" example="1">%2$d</xliff:g></string>

    <!-- Message shown when a theme has been applied successfully in the system [CHAR LIMIT=NONE] -->
    <string name="applied_theme_msg">Theme has been applied</string>
</resources>
+1 −1
Original line number Diff line number Diff line
@@ -163,7 +163,7 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
     * the default theme.
     */
    private void addDefaultTheme() {
        ThemeBundle.Builder builder = new Builder();
        ThemeBundle.Builder builder = new Builder().asDefault();
        Resources system = Resources.getSystem();

        int titleId = mStubApkResources.getIdentifier(TITLE_PREFIX + DEFAULT_THEME_NAME,
+43 −5
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.customization.model.CustomizationOption;
import com.android.wallpaper.R;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
@@ -45,13 +46,23 @@ import java.util.List;
 */
public class ThemeBundle implements CustomizationOption {

    static final String DEFAULT_PACKAGE = "DEFAULT_PACKAGE";

    private final String mTitle;
    private final PreviewInfo mPreviewInfo;

    private ThemeBundle(String title, PreviewInfo previewInfo) {
    private final String mFontOverlayPackage;
    private final String mColorOverlayPackage;
    private final String mShapeOverlayPackage;
    private final List<String> mIconOverlayPackages;
    private final boolean mIsDefault;

    private ThemeBundle(String title, @Nullable String fontOverlayPackage,
            @Nullable String colorOverlayPackage, @Nullable String shapeOverlayPackage,
            List<String> iconOverlayPackages, boolean isDefault, PreviewInfo previewInfo) {
        mTitle = title;
        mFontOverlayPackage = fontOverlayPackage;
        mColorOverlayPackage = colorOverlayPackage;
        mShapeOverlayPackage = shapeOverlayPackage;
        mIconOverlayPackages = Collections.unmodifiableList(iconOverlayPackages);
        mIsDefault = isDefault;
        mPreviewInfo = previewInfo;
    }

@@ -96,6 +107,26 @@ public class ThemeBundle implements CustomizationOption {
        return mPreviewInfo;
    }

    String getFontOverlayPackage() {
        return mFontOverlayPackage;
    }

    String getColorOverlayPackage() {
        return mColorOverlayPackage;
    }

    String getShapeOverlayPackage() {
        return mShapeOverlayPackage;
    }

    List<String> getIconOverlayPackages() {
        return mIconOverlayPackages;
    }

    boolean isDefault() {
        return mIsDefault;
    }

    public static class PreviewInfo {
        public final Typeface bodyFontFamily;
        public final Typeface headlineFontFamily;
@@ -128,6 +159,7 @@ public class ThemeBundle implements CustomizationOption {
        @ColorInt private int mColorAccentDark;
        private List<Drawable> mIcons = new ArrayList<>();
        private String mShapePath;
        private boolean mIsDefault;
        @DrawableRes private int mWallpaperDrawableResId;

        private String mFontOverlayPackage;
@@ -144,7 +176,8 @@ public class ThemeBundle implements CustomizationOption {
                shapeDrawable.setIntrinsicHeight((int) PATH_SIZE);
                shapeDrawable.setIntrinsicWidth((int) PATH_SIZE);
            }
            return new ThemeBundle(mTitle,
            return new ThemeBundle(mTitle, mFontOverlayPackage, mColorsPackage, mShapePackage,
                    mIconPackages, mIsDefault,
                    new PreviewInfo(mBodyFontFamily, mHeadlineFontFamily, mColorAccentLight,
                            mColorAccentDark, mIcons, shapeDrawable, mWallpaperDrawableResId));
        }
@@ -203,5 +236,10 @@ public class ThemeBundle implements CustomizationOption {
            mShapePath = path;
            return this;
        }

        public Builder asDefault() {
            mIsDefault = true;
            return this;
        }
    }
}
+24 −2
Original line number Diff line number Diff line
@@ -15,14 +15,24 @@
 */
package com.android.customization.model.theme;

import android.content.Context;
import android.content.om.OverlayManager;
import android.os.UserHandle;

import com.android.customization.model.CustomizationManager;

import java.util.ArrayList;
import java.util.List;

public class ThemeManager implements CustomizationManager<ThemeBundle> {

    private final ThemeBundleProvider mProvider;
    private final OverlayManager mOverlayManager;
    private boolean useThemeWallpaper;

    public ThemeManager(ThemeBundleProvider provider) {
    public ThemeManager(ThemeBundleProvider provider, Context context) {
        mProvider = provider;
        mOverlayManager = context.getSystemService(OverlayManager.class);
    }

    @Override
@@ -32,7 +42,19 @@ public class ThemeManager implements CustomizationManager<ThemeBundle> {

    @Override
    public void apply(ThemeBundle theme) {
        // TODO(santie) implement
        if (theme.isDefault()) {
            // TODO: Clear secure setting
        }
        List<String> packages = new ArrayList<>();
        packages.add(theme.getFontOverlayPackage());
        packages.add(theme.getColorOverlayPackage());
        packages.add(theme.getShapeOverlayPackage());
        packages.addAll(theme.getIconOverlayPackages());
        for (String packageName : packages) {
            mOverlayManager.setEnabledExclusiveInCategory(packageName, UserHandle.myUserId());
        }
        // TODO: store to secure setting
        // TODO: set wallpaper
    }

    @Override
Loading