diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2015-03-13 11:06:47 -0700 |
---|---|---|
committer | Deepanshu Gupta <deepanshu@google.com> | 2015-03-16 11:45:00 -0700 |
commit | ada8590547348b77d8cbd56abdb8fadb3e72c015 (patch) | |
tree | 99dddcbd1630be05ab3e834f8b0ea649b53af851 /tools/layoutlib/bridge/src/android | |
parent | 2e4d93245764a1c1d7515361ddbb8fc1665f814e (diff) | |
download | frameworks_base-ada8590547348b77d8cbd56abdb8fadb3e72c015.zip frameworks_base-ada8590547348b77d8cbd56abdb8fadb3e72c015.tar.gz frameworks_base-ada8590547348b77d8cbd56abdb8fadb3e72c015.tar.bz2 |
Fix AppCompat action bar theming.
Use themed context to inflate the action bar when AppCompat is used.
Also fix minor issues exposed as a result.
- Set project callback when LayoutInflater is created by
LayoutInflater.from(context).
- Remove duplication of code to get base context from context wrapper.
Bug: http://b.android.com/159711
Change-Id: I379ba2ba71c0ef547460987c3aa5db521c7de967
Diffstat (limited to 'tools/layoutlib/bridge/src/android')
3 files changed, 12 insertions, 13 deletions
diff --git a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java index 7e4ff69..7ca4c47 100644 --- a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java +++ b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java @@ -35,6 +35,8 @@ import android.util.AttributeSet; import java.io.File; +import static com.android.layoutlib.bridge.android.BridgeContext.getBaseContext; + /** * Custom implementation of {@link LayoutInflater} to handle custom views. */ @@ -56,7 +58,12 @@ public final class BridgeInflater extends LayoutInflater { protected BridgeInflater(LayoutInflater original, Context newContext) { super(original, newContext); - mProjectCallback = null; + newContext = getBaseContext(newContext); + if (newContext instanceof BridgeContext) { + mProjectCallback = ((BridgeContext) newContext).getProjectCallback(); + } else { + mProjectCallback = null; + } } /** @@ -151,9 +158,7 @@ public final class BridgeInflater extends LayoutInflater { @Override public View inflate(int resource, ViewGroup root) { Context context = getContext(); - while (context instanceof ContextThemeWrapper) { - context = ((ContextThemeWrapper) context).getBaseContext(); - } + context = getBaseContext(context); if (context instanceof BridgeContext) { BridgeContext bridgeContext = (BridgeContext)context; @@ -217,9 +222,7 @@ public final class BridgeInflater extends LayoutInflater { private void setupViewInContext(View view, AttributeSet attrs) { Context context = getContext(); - while (context instanceof ContextThemeWrapper) { - context = ((ContextThemeWrapper) context).getBaseContext(); - } + context = getBaseContext(context); if (context instanceof BridgeContext) { BridgeContext bc = (BridgeContext) context; // get the view key diff --git a/tools/layoutlib/bridge/src/android/view/MenuInflater_Delegate.java b/tools/layoutlib/bridge/src/android/view/MenuInflater_Delegate.java index dafc96b..08a97d6 100644 --- a/tools/layoutlib/bridge/src/android/view/MenuInflater_Delegate.java +++ b/tools/layoutlib/bridge/src/android/view/MenuInflater_Delegate.java @@ -48,9 +48,7 @@ public class MenuInflater_Delegate { AttributeSet attrs) { if (menuItem instanceof BridgeMenuItemImpl) { Context context = thisInflater.getContext(); - while (context instanceof ContextThemeWrapper) { - context = ((ContextThemeWrapper) context).getBaseContext(); - } + context = BridgeContext.getBaseContext(context); if (context instanceof BridgeContext) { Object viewKey = BridgeInflater.getViewKeyFromParser( attrs, ((BridgeContext) context), null, false); diff --git a/tools/layoutlib/bridge/src/android/view/ViewGroup_Delegate.java b/tools/layoutlib/bridge/src/android/view/ViewGroup_Delegate.java index 3915046..82ae1df 100644 --- a/tools/layoutlib/bridge/src/android/view/ViewGroup_Delegate.java +++ b/tools/layoutlib/bridge/src/android/view/ViewGroup_Delegate.java @@ -122,9 +122,7 @@ public class ViewGroup_Delegate { @NonNull private static DisplayMetrics getMetrics(View view) { Context context = view.getContext(); - while (context instanceof ContextThemeWrapper) { - context = ((ContextThemeWrapper) context).getBaseContext(); - } + context = BridgeContext.getBaseContext(context); if (context instanceof BridgeContext) { return ((BridgeContext) context).getMetrics(); } |