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

Commit c65b0e61 authored by Clark Scheff's avatar Clark Scheff
Browse files

CM11 Themes: Allow defining a custom default theme [1/3]

Change-Id: I6b794d6c9c27b2d6436bdf4fec51c84a7859c134
parent 577b3c44
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -28,8 +28,10 @@ import android.net.Uri;
import android.os.FileUtils;
import android.os.SystemProperties;
import android.provider.MediaStore;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

import java.io.BufferedInputStream;
@@ -47,10 +49,14 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import static android.content.res.CustomTheme.HOLO_DEFAULT;

/**
 * @hide
 */
public class ThemeUtils {
    private static final String TAG = "ThemeUtils";

    /* Path inside a theme APK to the overlay folder */
    public static final String OVERLAY_PATH = "assets/overlays/";
    public static final String ICONS_PATH = "assets/icons/";
@@ -502,6 +508,24 @@ public class ThemeUtils {
        return null;
    }

    public static String getDefaultThemePackageName(Context context) {
        final String defaultThemePkg = Settings.Secure.getString(context.getContentResolver(),
                Settings.Secure.DEFAULT_THEME_PACKAGE);
        if (!TextUtils.isEmpty(defaultThemePkg)) {
            PackageManager pm = context.getPackageManager();
            try {
                if (pm.getPackageInfo(defaultThemePkg, 0) != null) {
                    return defaultThemePkg;
                }
            } catch (PackageManager.NameNotFoundException e) {
                // doesn't exist so holo will be default
                Log.w(TAG, "Default theme " + defaultThemePkg + " not found", e);
            }
        }

        return HOLO_DEFAULT;
    }

    private static class ThemedUiContext extends ContextWrapper {
        private String mPackageName;

+6 −4
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import android.text.TextUtils;
public final class CustomTheme implements Cloneable, Parcelable, Comparable<CustomTheme> {
    private final String SYSTEMUI_PKG_NAME = "com.android.systemui";

    public static final String HOLO_DEFAULT = "holo";

    protected final String mThemePackageName;
    protected final String mIconPackPkgName;
    protected final String mSystemUiThemePkgName;
@@ -234,22 +236,22 @@ public final class CustomTheme implements Cloneable, Parcelable, Comparable<Cust
        }

        public Builder overlay(String pkgName) {
            this.mThemePkgName = pkgName.equals("default") ? "" : pkgName;
            this.mThemePkgName = pkgName.equals(HOLO_DEFAULT) ? "" : pkgName;
            return this;
        }

        public Builder systemUi(String pkgName) {
            this.mSystemUiPkgName = pkgName.equals("default") ? "" : pkgName;
            this.mSystemUiPkgName = pkgName.equals(HOLO_DEFAULT) ? "" : pkgName;
            return this;
        }

        public Builder icons(String pkgName) {
            this.mIconPkgName = pkgName.equals("default") ? "" : pkgName;
            this.mIconPkgName = pkgName.equals(HOLO_DEFAULT) ? "" : pkgName;
            return this;
        }

        public Builder fonts(String pkgName) {
            this.mFontPkgName = pkgName.equals("default") ? "" : pkgName;
            this.mFontPkgName = pkgName.equals(HOLO_DEFAULT) ? "" : pkgName;
            return this;
        }

+25 −0
Original line number Diff line number Diff line
@@ -5687,6 +5687,31 @@ public final class Settings {
         */
         public static final String PRIVACY_GUARD_DEFAULT = "privacy_guard_default";

        /**
         * Default theme to use.  If empty, use holo.
         * @hide
         */
        public static final String DEFAULT_THEME_PACKAGE = "default_theme_package";

        /**
         * A '|' delimited list of theme components to apply from the default theme on first boot.
         * Components can be one or more of the "mods_XXXXXXX" found in
         * {@link ThemesContract$ThemesColumns}.  Leaving this field blank assumes all components
         * will be applied.
         *
         * ex: mods_icons|mods_overlays|mods_homescreen
         *
         * @hide
         */
        public static final String DEFAULT_THEME_COMPONENTS = "default_theme_components";

        /**
         * Whether the default theme was applied on the first boot.
         * @hide
         */
        public static final String DEFAULT_THEME_APPLIED_ON_FIRST_BOOT =
                "default_theme_applied_on_first_boot";

        /**
         * This are the settings to be backed up.
         *
+7 −0
Original line number Diff line number Diff line
@@ -191,6 +191,13 @@ public class ThemesContract {
         */
        public static final String IS_LEGACY_THEME = "is_legacy_theme";

        /**
         * 1 if this theme is the system default theme.
         * <P>Type: INTEGER</P>
         * <P>Default: 0</P>
         */
        public static final String IS_DEFAULT_THEME = "is_default_theme";

        /**
         * 1 if this theme is a legacy iconpack. A legacy icon pack is an APK that was written
         * for Trebuchet or a 3rd party launcher.
+4 −0
Original line number Diff line number Diff line
@@ -211,4 +211,8 @@

    <!-- Default value of Settings.System.SCREEN_ANIMATION_STYLE -->
    <integer name="def_screen_animation_style">0</integer>

    <!-- Default theme -->
    <string name="def_theme_package"></string>
    <string name="def_theme_components"></string>
</resources>
Loading