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

Commit 94298f75 authored by Josh Guilfoyle's avatar Josh Guilfoyle
Browse files

THEMES-171: Remove diff theme functionality.

This functionality was downscoped and is not suitable to deliver to OEM
partners for the themes feature.

CR: Sergey Ten
parent 403be104
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -184,13 +184,6 @@ public final class ActivityThread {
                    config.customTheme = CustomTheme.getDefault();
                }

                String resourcePath = config.customTheme.getThemeResourcePath();
                if (resourcePath != null) {
                    if (assets.addAssetPath(resourcePath) == 0) {
                        Log.e(TAG, "Unable to add parent theme resdir=" + resourcePath);
                    }
                }

                if (!TextUtils.isEmpty(config.customTheme.getThemePackageName())) {
                    PackageInfo pi = getPackageInfo(config.customTheme.getThemePackageName(), 0);
                    if (pi != null) {
+1 −17
Original line number Diff line number Diff line
@@ -267,25 +267,9 @@ class ApplicationContext extends Context {
            try {
                Configuration config = ActivityManagerNative.getDefault().getConfiguration();
                if (config.customTheme != null) {
                    int themeId = -1;
                    if (config.customTheme.hasParentTheme()) {
                        mParentThemeStyleId = CustomTheme.getStyleId(this,
                    int themeId = CustomTheme.getStyleId(this,
                                config.customTheme.getThemePackageName(),
                                config.customTheme.getThemeId());
                        // This is a delta theme
                        // Find style id for the delta theme, @see DeltaThemeGenerator#generateStyle
                        String styleName = CustomTheme.getDeltaThemeStyleName(config.customTheme.getThemeId());
                        String packageName = CustomTheme.getDeltaThemePackageName(styleName);
                        themeId = CustomTheme.getDeltaThemeStyleId(this, styleName, packageName, config.customTheme.getThemeResourcePath());
                        if (themeId == -1) {
                            themeId = mParentThemeStyleId;
                        }
                    } else {
                        mParentThemeStyleId = -1;
                        themeId = CustomTheme.getStyleId(this,
                                config.customTheme.getThemePackageName(),
                                config.customTheme.getThemeId());
                    }
                    if (themeId == -1) {
                        CustomTheme defaultTheme = CustomTheme.getDefault();
                        if (config.customTheme.equals(defaultTheme)) {
+2 −36
Original line number Diff line number Diff line
@@ -131,21 +131,6 @@ public final class Configuration implements Parcelable, Comparable<Configuration
     */
    public static final String THEME_PACKAGE_NAME_PERSISTENCE_PROPERTY = "persist.sys.themePackageName";

    /**
     * @hide
     */
    public static final String THEME_RESOURCE_PATH_PERSISTENCE_PROPERTY = "persist.sys.themeResourcePath";

    /**
     * @hide
     */
    public static final String THEME_HAS_PARENT_PERSISTENCE_PROPERTY = "persist.sys.themeHasParent";

    /**
     * @hide
     */
    public static final String THEME_FORCE_UPDATE_PERSISTENCE_PROPERTY = "persist.sys.themeForceUpdate";

    /**
     * Overall orientation of the screen.  May be one of
     * {@link #ORIENTATION_LANDSCAPE}, {@link #ORIENTATION_PORTRAIT},
@@ -212,11 +197,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration

        String themeResource = SystemProperties.get(THEME_ID_PERSISTENCE_PROPERTY, null);
        String themePackageName = SystemProperties.get(THEME_PACKAGE_NAME_PERSISTENCE_PROPERTY, "");
        boolean themeHasParent = SystemProperties.getBoolean(THEME_HAS_PARENT_PERSISTENCE_PROPERTY, false);
        if (!TextUtils.isEmpty(themeResource) && !TextUtils.isEmpty(themePackageName)) {
            customTheme = new CustomTheme(themeResource, themePackageName, themeHasParent);
            customTheme.setThemeResourcePath(SystemProperties.getLongString(THEME_RESOURCE_PATH_PERSISTENCE_PROPERTY, null));
            customTheme.setForceUpdate(SystemProperties.getBoolean(THEME_FORCE_UPDATE_PERSISTENCE_PROPERTY, false));
            customTheme = new CustomTheme(themeResource, themePackageName);
        } else {
            customTheme = CustomTheme.getDefault();
        }
@@ -426,14 +408,6 @@ public final class Configuration implements Parcelable, Comparable<Configuration
            dest.writeInt(1);
            dest.writeString(customTheme.getThemeId());
            dest.writeString(customTheme.getThemePackageName());
            dest.writeInt(customTheme.hasParentTheme()? 1 : 0);
            if (customTheme.getThemeResourcePath() != null) {
                dest.writeInt(1);
                dest.writeString(customTheme.getThemeResourcePath());
            } else {
                dest.writeInt(0);
            }
            dest.writeInt(customTheme.isForceUpdate()? 1 : 0);
        }
    }

@@ -470,12 +444,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        if (source.readInt() != 0) {
            String themeId = source.readString();
            String themePackage = source.readString();
            boolean hasParent = source.readInt() != 0;
            customTheme = new CustomTheme(themeId, themePackage, hasParent);
            if (source.readInt() != 0) {
                customTheme.setThemeResourcePath(source.readString());
            }
            customTheme.setForceUpdate(source.readInt() != 0);
            customTheme = new CustomTheme(themeId, themePackage);
        }
    }

@@ -507,9 +476,6 @@ public final class Configuration implements Parcelable, Comparable<Configuration
        if (n != 0) return n;
        n = this.orientation - that.orientation;
        if (n != 0) return n;
        if (this.customTheme.hasParentTheme() != that.customTheme.hasParentTheme()) {
            return 1;
        }
        n = this.customTheme.getThemeId().compareTo(that.customTheme.getThemeId());
        if (n != 0) return n;
        n = this.customTheme.getThemePackageName().compareTo(that.customTheme.getThemePackageName());
+2 −70
Original line number Diff line number Diff line
@@ -17,9 +17,6 @@ public final class CustomTheme implements Cloneable {

    private String mThemeId;
    private String mThemePackageName;
    private String mThemeResourcePath;  // Non null for delta themes ONLY! Points to the resource bundle of a delta theme.
    private boolean mHasParentTheme = false;
    private boolean mForceUpdate = false;

    private static final CustomTheme sDefaultTheme = new CustomTheme();

@@ -28,10 +25,9 @@ public final class CustomTheme implements Cloneable {
        mThemePackageName = SystemProperties.get("default_theme.package_name");
    }

    public CustomTheme(String themeId, String packageName, boolean hasParent) {
    public CustomTheme(String themeId, String packageName) {
        mThemeId = themeId;
        mThemePackageName = packageName;
        mHasParentTheme = hasParent;
    }

    @Override
@@ -58,9 +54,7 @@ public final class CustomTheme implements Cloneable {
            String currentThemeId = (mThemeId == null)? "" : mThemeId;
            String newThemeId = (o.mThemeId == null)? "" : o.mThemeId;
            return (currentPackageName.trim().equalsIgnoreCase(newPackageName.trim())) &&
                    (currentThemeId.trim().equalsIgnoreCase(newThemeId.trim())) &&
                    hasParentTheme() == o.hasParentTheme() &&
                    !isForceUpdate();
                    (currentThemeId.trim().equalsIgnoreCase(newThemeId.trim()));
        }
        return false;
    }
@@ -72,19 +66,7 @@ public final class CustomTheme implements Cloneable {
        result.append("_");
        if (mThemePackageName != null && mThemePackageName.length() > 0){
            result.append(mThemePackageName);
        } else {
            result.append("_");
        }
        result.append(":_");
        if (!TextUtils.isEmpty(mThemeResourcePath)) {
            result.append(mThemeResourcePath);
        } else {
            result.append("_");
        }
        result.append("_");
        result.append(mHasParentTheme);
        result.append("_");
        result.append(mForceUpdate);

        return result.toString();
    }
@@ -106,26 +88,6 @@ public final class CustomTheme implements Cloneable {
        mThemePackageName = themePackageName;
    }

    public String getThemeResourcePath() {
        return mThemeResourcePath;
    }

    public void setThemeResourcePath(String resourcePath) {
        mThemeResourcePath = resourcePath;
    }

    public boolean isForceUpdate() {
        return mForceUpdate;
    }

    public void setForceUpdate(boolean update) {
        mForceUpdate = update;
    }

    public boolean hasParentTheme() {
        return mHasParentTheme;
    }

    public static CustomTheme getDefault() {
        return sDefaultTheme;
    }
@@ -149,34 +111,4 @@ public final class CustomTheme implements Cloneable {
        }
        return -1;
    }

    public static String getDeltaThemeStyleName(String themeId) {
        StringBuilder sb = new StringBuilder(themeId);
        sb.append("_generated");
        return sb.toString();
    }

    public static String getDeltaThemePackageName(String styleName) {
        StringBuilder sb = new StringBuilder("com.tmobile.theme.autogenerated.");
        sb.append(styleName);
        return sb.toString().replace(' ', '_');
    }

    public static int getDeltaThemeStyleId(Context context, String styleName, String packageName, String resourceBundlePath) {
        if (TextUtils.isEmpty(styleName) ||
            TextUtils.isEmpty(packageName) ||
            TextUtils.isEmpty(resourceBundlePath)) {
            return -1;
        }
        DisplayMetrics metrics = new DisplayMetrics();
        WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(metrics);
        ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        Configuration config = am.getConfiguration();
        AssetManager assets = new AssetManager();
        assets.addAssetPath(resourceBundlePath);
        Resources res = new Resources(assets, metrics, config);
        return res.getIdentifier("style/" + styleName, "", packageName);
    }

}
+1 −12
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.util.DisplayMetrics;
public class ContextThemeWrapper extends ContextWrapper {
    private Context mBase;
    private int mThemeResource;
    private int mParentThemeResource;
    private Resources.Theme mTheme;
    private LayoutInflater mInflater;
    
@@ -88,20 +87,15 @@ public class ContextThemeWrapper extends ContextWrapper {
     * XXX: Hack to support theme preview by temporarily overriding the ApplicationContext's
     * Resources on a per-activity basis.  Very ugly.
     */
    public void useThemedResources(String themePackage, String resourceBundlePath, 
            int parentThemeId) {
    public void useThemedResources(String themePackage) {
        if (themePackage == null) {
            mThemedResources = null;
            mUseThemedResources = false;
            mTheme = null;
            mParentThemeResource = -1;
        } else {
            AssetManager assets = new AssetManager();
            assets.addAssetPath(getPackageResDir(getPackageName()));
            assets.addAssetPath(getPackageResDir(themePackage));
            if (resourceBundlePath != null) {
                assets.addAssetPath(resourceBundlePath);
            }

            DisplayMetrics metrics = new DisplayMetrics();
            WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE);
@@ -112,7 +106,6 @@ public class ContextThemeWrapper extends ContextWrapper {
            mThemedResources = new Resources(assets, metrics, config);
            mUseThemedResources = true;
            mTheme = null;
            mParentThemeResource = parentThemeId;
        }
    }
    
@@ -170,10 +163,6 @@ public class ContextThemeWrapper extends ContextWrapper {
            }
        }
        
        if (mUseThemedResources == true && mParentThemeResource > 0) {
            onApplyThemeResource(mTheme, mParentThemeResource, first);
        }
        
        onApplyThemeResource(mTheme, mThemeResource, first);
    }
}
Loading