diff options
author | Alan Viverette <alanv@google.com> | 2015-05-01 11:28:37 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2015-05-01 11:28:37 -0700 |
commit | cc2a1d48a0e4134823c940291f5db6fd9f2ae9b3 (patch) | |
tree | 352cbe863f6db1efda350c2d351cc483dfe1ebdf /core | |
parent | aba035d2ed4a0c39d59ca039b52af2bc3f5980b4 (diff) | |
download | frameworks_base-cc2a1d48a0e4134823c940291f5db6fd9f2ae9b3.zip frameworks_base-cc2a1d48a0e4134823c940291f5db6fd9f2ae9b3.tar.gz frameworks_base-cc2a1d48a0e4134823c940291f5db6fd9f2ae9b3.tar.bz2 |
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
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/app/ContextImpl.java | 24 | ||||
-rw-r--r-- | core/java/android/view/ContextThemeWrapper.java | 9 |
2 files changed, 24 insertions, 9 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 81a78f6..cb20cb8 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -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) { + return mTheme; + } + + mThemeResource = Resources.selectDefaultTheme(mThemeResource, + getOuterContext().getApplicationInfo().targetSdkVersion); + initializeTheme(); + + return mTheme; + } + + private void initializeTheme() { if (mTheme == null) { - mThemeResource = Resources.selectDefaultTheme(mThemeResource, - getOuterContext().getApplicationInfo().targetSdkVersion); mTheme = mResources.newTheme(); - mTheme.applyStyle(mThemeResource, true); } - return mTheme; + mTheme.applyStyle(mThemeResource, true); } @Override diff --git a/core/java/android/view/ContextThemeWrapper.java b/core/java/android/view/ContextThemeWrapper.java index 9047b1d..ce50091 100644 --- a/core/java/android/view/ContextThemeWrapper.java +++ b/core/java/android/view/ContextThemeWrapper.java @@ -87,9 +87,12 @@ public class ContextThemeWrapper extends ContextWrapper { } } - @Override public void setTheme(int resid) { - mThemeResource = resid; - initializeTheme(); + @Override + public void setTheme(int resid) { + if (mThemeResource != resid) { + mThemeResource = resid; + initializeTheme(); + } } /** @hide */ |