diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2015-01-10 03:56:47 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-01-10 03:56:47 +0000 |
commit | c598047d67f64e690f682d82c0e77989c79ae465 (patch) | |
tree | f709951ecc8a5c7134c5a2345c339de2ddc70ee4 /tools/layoutlib/bridge | |
parent | 20625cce4c13d2337456aaa74ba91b6c4379321f (diff) | |
parent | ca67a249293d021808f349fa2e2f799451aeafe8 (diff) | |
download | frameworks_base-c598047d67f64e690f682d82c0e77989c79ae465.zip frameworks_base-c598047d67f64e690f682d82c0e77989c79ae465.tar.gz frameworks_base-c598047d67f64e690f682d82c0e77989c79ae465.tar.bz2 |
am ca67a249: am bb600de6: am 74147527: am 8505c387: Special case AppCompat to show action bar.
* commit 'ca67a249293d021808f349fa2e2f799451aeafe8':
Special case AppCompat to show action bar.
Diffstat (limited to 'tools/layoutlib/bridge')
-rw-r--r-- | tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index daf82fc..4637bfd 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -36,6 +36,7 @@ import com.android.ide.common.rendering.api.Result; import com.android.ide.common.rendering.api.Result.Status; import com.android.ide.common.rendering.api.SessionParams; import com.android.ide.common.rendering.api.SessionParams.RenderingMode; +import com.android.ide.common.rendering.api.StyleResourceValue; import com.android.ide.common.rendering.api.ViewInfo; import com.android.ide.common.rendering.api.ViewType; import com.android.internal.util.XmlUtils; @@ -134,6 +135,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { private int mMeasuredScreenHeight = -1; private boolean mIsAlphaChannelImage; private boolean mWindowIsFloating; + private Boolean mIsThemeAppCompat; private int mStatusBarSize; private int mNavigationBarSize; @@ -194,11 +196,9 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { DisplayMetrics metrics = getContext().getMetrics(); // use default of true in case it's not found to use alpha by default - mIsAlphaChannelImage = getBooleanThemeValue(resources, - "windowIsFloating", true /*defaultValue*/); - - mWindowIsFloating = getBooleanThemeValue(resources, "windowIsFloating", - true /*defaultValue*/); + mIsAlphaChannelImage = getBooleanThemeValue(resources, "windowIsFloating", true, true); + // FIXME: Find out why both variables are taking the same value. + mWindowIsFloating = getBooleanThemeValue(resources, "windowIsFloating", true, true); findBackground(resources); findStatusBar(resources, metrics); @@ -1059,7 +1059,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { private void findStatusBar(RenderResources resources, DisplayMetrics metrics) { boolean windowFullscreen = getBooleanThemeValue(resources, - "windowFullscreen", false /*defaultValue*/); + "windowFullscreen", false, !isThemeAppCompat(resources)); if (!windowFullscreen && !mWindowIsFloating) { // default value @@ -1086,7 +1086,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { } boolean windowActionBar = getBooleanThemeValue(resources, - "windowActionBar", true /*defaultValue*/); + "windowActionBar", true, !isThemeAppCompat(resources)); // if there's a value and it's false (default is true) if (windowActionBar) { @@ -1113,7 +1113,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { } else { // action bar overrides title bar so only look for this one if action bar is hidden boolean windowNoTitle = getBooleanThemeValue(resources, - "windowNoTitle", false /*defaultValue*/); + "windowNoTitle", false, !isThemeAppCompat(resources)); if (!windowNoTitle) { @@ -1185,20 +1185,30 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { } } + private boolean isThemeAppCompat(RenderResources resources) { + // Ideally, we should check if the corresponding activity extends + // android.support.v7.app.ActionBarActivity, and not care about the theme name at all. + if (mIsThemeAppCompat == null) { + StyleResourceValue defaultTheme = resources.getDefaultTheme(); + StyleResourceValue val = resources.getStyle("Theme.AppCompat", false); + mIsThemeAppCompat = defaultTheme == val || resources.themeIsParentOf(val, defaultTheme); + } + return mIsThemeAppCompat; + } + /** - * Looks for a attribute in the current theme. The attribute is in the android - * namespace. + * Looks for an attribute in the current theme. * * @param resources the render resources * @param name the name of the attribute * @param defaultValue the default value. + * @param isFrameworkAttr if the attribute is in android namespace * @return the value of the attribute or the default one if not found. */ private boolean getBooleanThemeValue(RenderResources resources, - String name, boolean defaultValue) { + String name, boolean defaultValue, boolean isFrameworkAttr) { - // get the title bar flag from the current theme. - ResourceValue value = resources.findItemInTheme(name, true /*isFrameworkAttr*/); + ResourceValue value = resources.findItemInTheme(name, isFrameworkAttr); // because it may reference something else, we resolve it. value = resources.resolveResValue(value); |