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

Commit cc2a1d48 authored by Alan Viverette's avatar Alan Viverette
Browse files

Allow ContextImpl.setTheme(int) to be called after getTheme()

Previously the theme could only be set if it had never been obtained,
which was inconsistent with the documentation for Context.setTheme()
and the behavior of ContextThemeWrapper.

Also prevents double-apply of themes in setTheme().

Bug: 20756250
Bug: 20230451
Change-Id: I2566b3e4546cd1c68db79f10f01a5a1256fd439c
parent aba035d2
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -237,8 +237,11 @@ class ContextImpl extends Context {
    }

    @Override
    public void setTheme(int resid) {
        mThemeResource = resid;
    public void setTheme(int resId) {
        if (mThemeResource != resId) {
            mThemeResource = resId;
            initializeTheme();
        }
    }

    @Override
@@ -248,13 +251,22 @@ class ContextImpl extends Context {

    @Override
    public Resources.Theme getTheme() {
        if (mTheme == null) {
        if (mTheme != null) {
            return mTheme;
        }

        mThemeResource = Resources.selectDefaultTheme(mThemeResource,
                getOuterContext().getApplicationInfo().targetSdkVersion);
        initializeTheme();

        return mTheme;
    }

    private void initializeTheme() {
        if (mTheme == null) {
            mTheme = mResources.newTheme();
            mTheme.applyStyle(mThemeResource, true);
        }
        return mTheme;
        mTheme.applyStyle(mThemeResource, true);
    }

    @Override
+6 −3
Original line number Diff line number Diff line
@@ -87,10 +87,13 @@ public class ContextThemeWrapper extends ContextWrapper {
        }
    }
    
    @Override public void setTheme(int resid) {
    @Override
    public void setTheme(int resid) {
        if (mThemeResource != resid) {
            mThemeResource = resid;
            initializeTheme();
        }
    }
    
    /** @hide */
    @Override