From 2b0551175d57ce0f063566eea7670442b8b624fc Mon Sep 17 00:00:00 2001 From: Deepanshu Gupta Date: Mon, 16 Nov 2015 15:46:12 -0800 Subject: WindowDecorActionBar name change fix. In change id I7582e242c7564c32feeb044fc9eff6bfb5c56536, WindowDecorActionBar's package name was changed. This breaks layoutlib. Fix the issue by checking both package names when loading the class. Change-Id: I5723a97f0f164d61c56061fef6cff18e3cdafaee --- .../layoutlib/bridge/bars/AppCompatActionBar.java | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/AppCompatActionBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/AppCompatActionBar.java index 868c6d3..b67afeb 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/AppCompatActionBar.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/AppCompatActionBar.java @@ -16,10 +16,13 @@ package com.android.layoutlib.bridge.bars; +import com.android.ide.common.rendering.api.LayoutLog; +import com.android.ide.common.rendering.api.LayoutlibCallback; import com.android.ide.common.rendering.api.RenderResources; import com.android.ide.common.rendering.api.ResourceValue; import com.android.ide.common.rendering.api.SessionParams; import com.android.ide.common.rendering.api.StyleResourceValue; +import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.android.BridgeContext; import com.android.layoutlib.bridge.impl.ResourceHelper; import com.android.resources.ResourceType; @@ -45,6 +48,8 @@ public class AppCompatActionBar extends BridgeActionBar { private Object mWindowDecorActionBar; private static final String WINDOW_ACTION_BAR_CLASS = "android.support.v7.internal.app.WindowDecorActionBar"; + // This is used on v23.1.1 and later. + private static final String WINDOW_ACTION_BAR_CLASS_NEW = "android.support.v7.app.WindowDecorActionBar"; private Class mWindowActionBarClass; /** @@ -70,14 +75,26 @@ public class AppCompatActionBar extends BridgeActionBar { try { Class[] constructorParams = {View.class}; Object[] constructorArgs = {getDecorContent()}; - mWindowDecorActionBar = params.getLayoutlibCallback().loadView(WINDOW_ACTION_BAR_CLASS, - constructorParams, constructorArgs); + LayoutlibCallback callback = params.getLayoutlibCallback(); + // First try to load the class as was available before appcompat v23.1.1, without + // logging warnings. + try { + mWindowDecorActionBar = callback.loadClass(WINDOW_ACTION_BAR_CLASS, + constructorParams, constructorArgs); + } catch (ClassNotFoundException ignore) { + } + if (mWindowDecorActionBar == null) { + // If failed, load the new class, while logging warnings. + mWindowDecorActionBar = callback.loadView(WINDOW_ACTION_BAR_CLASS_NEW, + constructorParams, constructorArgs); + } mWindowActionBarClass = mWindowDecorActionBar == null ? null : mWindowDecorActionBar.getClass(); setupActionBar(); } catch (Exception e) { - e.printStackTrace(); + Bridge.getLog().warning(LayoutLog.TAG_BROKEN, + "Failed to load AppCompat ActionBar with unknown error.", e); } } -- cgit v1.1