summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2014-01-03 15:22:53 -0800
committerAlan Viverette <alanv@google.com>2014-01-03 15:22:53 -0800
commitdd9233253b88d86473403d5b63c72e223b5e40bd (patch)
tree72864fdcfc979dde91464acb7a84f594cee2c0a7
parent23ab74de5eda745e2ef88bd156cde83fbcd4b5da (diff)
downloadframeworks_base-dd9233253b88d86473403d5b63c72e223b5e40bd.zip
frameworks_base-dd9233253b88d86473403d5b63c72e223b5e40bd.tar.gz
frameworks_base-dd9233253b88d86473403d5b63c72e223b5e40bd.tar.bz2
Allow Views to specify a theme override
During inflation, any view with a theme attribute will wrap its context with a theme override. Views inflated using a parent will inherit the wrapped context. BUG: 12178430 Change-Id: I3448e5174e94c19960a1e21df5bd6127d0d33c07
-rw-r--r--core/java/android/view/LayoutInflater.java41
1 files changed, 32 insertions, 9 deletions
diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java
index aa43bad..32c9885 100644
--- a/core/java/android/view/LayoutInflater.java
+++ b/core/java/android/view/LayoutInflater.java
@@ -91,6 +91,8 @@ public abstract class LayoutInflater {
private static final String TAG_1995 = "blink";
private static final String TAG_REQUEST_FOCUS = "requestFocus";
+ private static final String ATTR_THEME = "theme";
+
/**
* Hook to allow clients of the LayoutInflater to restrict the set of Views that are allowed
* to be inflated.
@@ -677,23 +679,44 @@ public abstract class LayoutInflater {
name = attrs.getAttributeValue(null, "class");
}
+ // Apply a theme override, if necessary.
+ final Context viewContext;
+ final int themeResId = attrs.getAttributeResourceValue(null, ATTR_THEME, 0);
+ if (themeResId != 0) {
+ viewContext = new ContextThemeWrapper(mContext, themeResId);
+ } else if (parent != null) {
+ viewContext = parent.getContext();
+ } else {
+ viewContext = mContext;
+ }
+
if (DEBUG) System.out.println("******** Creating view: " + name);
try {
View view;
- if (mFactory2 != null) view = mFactory2.onCreateView(parent, name, mContext, attrs);
- else if (mFactory != null) view = mFactory.onCreateView(name, mContext, attrs);
- else view = null;
+ if (mFactory2 != null) {
+ view = mFactory2.onCreateView(parent, name, viewContext, attrs);
+ } else if (mFactory != null) {
+ view = mFactory.onCreateView(name, viewContext, attrs);
+ } else {
+ view = null;
+ }
if (view == null && mPrivateFactory != null) {
- view = mPrivateFactory.onCreateView(parent, name, mContext, attrs);
+ view = mPrivateFactory.onCreateView(parent, name, viewContext, attrs);
}
-
+
if (view == null) {
- if (-1 == name.indexOf('.')) {
- view = onCreateView(parent, name, attrs);
- } else {
- view = createView(name, null, attrs);
+ final Object lastContext = mConstructorArgs[0];
+ mConstructorArgs[0] = viewContext;
+ try {
+ if (-1 == name.indexOf('.')) {
+ view = onCreateView(parent, name, attrs);
+ } else {
+ view = createView(name, null, attrs);
+ }
+ } finally {
+ mConstructorArgs[0] = lastContext;
}
}