diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2022-02-16 18:25:46 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-02-16 18:25:46 +0000 |
commit | 0ffa22b26825b1427457966a46063fc1a6dffc47 (patch) | |
tree | 54801bac88bfb5b77f752890665db40a307c8542 | |
parent | 58bd418e161b5d4fdde39b46523d3e49269117e3 (diff) | |
parent | 4187262f50bd920cab53f232ee184cabe54d9e38 (diff) | |
download | layoutlib-0ffa22b26825b1427457966a46063fc1a6dffc47.tar.gz |
Merge "Fix view cookie for Material TabView"
9 files changed, 38 insertions, 37 deletions
diff --git a/bridge/src/android/content/res/Resources_Delegate.java b/bridge/src/android/content/res/Resources_Delegate.java index 1102eb79f9..f453aecce2 100644 --- a/bridge/src/android/content/res/Resources_Delegate.java +++ b/bridge/src/android/content/res/Resources_Delegate.java @@ -787,7 +787,7 @@ public class Resources_Delegate { private static String getPackageName(ResourceReference resourceInfo, Resources resources) { String packageName = resourceInfo.getNamespace().getPackageName(); if (packageName == null) { - packageName = getContext(resources).getPackageName(); + packageName = getLayoutlibCallback(resources).getResourcePackage(); if (packageName == null) { packageName = APP_PREFIX; } @@ -1114,7 +1114,7 @@ public class Resources_Delegate { return Bridge.getResourceId(url.type, url.name); } - if (getContext(resources).getPackageName().equals(url.namespace)) { + if (getLayoutlibCallback(resources).getResourcePackage().equals(url.namespace)) { return getLayoutlibCallback(resources).getOrGenerateResourceId( new ResourceReference(ResourceNamespace.RES_AUTO, url.type, url.name)); } diff --git a/bridge/src/android/graphics/Typeface_Delegate.java b/bridge/src/android/graphics/Typeface_Delegate.java index 1ad8358671..d9d38ad4c3 100644 --- a/bridge/src/android/graphics/Typeface_Delegate.java +++ b/bridge/src/android/graphics/Typeface_Delegate.java @@ -22,7 +22,6 @@ import com.android.ide.common.rendering.api.ResourceNamespace; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.android.BridgeContext; import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; -import com.android.layoutlib.bridge.android.RenderParamsFlags; import com.android.layoutlib.bridge.impl.DelegateManager; import com.android.layoutlib.bridge.impl.RenderAction; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; @@ -66,14 +65,7 @@ public final class Typeface_Delegate { String lowerCaseValue = path.toLowerCase(); if (lowerCaseValue.endsWith(AndroidConstants.DOT_XML)) { // create a block parser for the file - Boolean psiParserSupport = context.getLayoutlibCallback().getFlag( - RenderParamsFlags.FLAG_KEY_XML_FILE_PARSER_SUPPORT); - XmlPullParser parser; - if (psiParserSupport != null && psiParserSupport) { - parser = context.getLayoutlibCallback().createXmlParserForPsiFile(path); - } else { - parser = context.getLayoutlibCallback().createXmlParserForFile(path); - } + XmlPullParser parser = context.getLayoutlibCallback().createXmlParserForPsiFile(path); if (parser != null) { // TODO(b/156609434): The aapt namespace should not matter for parsing font files? diff --git a/bridge/src/com/android/layoutlib/bridge/android/RenderParamsFlags.java b/bridge/src/com/android/layoutlib/bridge/android/RenderParamsFlags.java index 4cab6f6490..e370fa0c72 100644 --- a/bridge/src/com/android/layoutlib/bridge/android/RenderParamsFlags.java +++ b/bridge/src/com/android/layoutlib/bridge/android/RenderParamsFlags.java @@ -36,24 +36,13 @@ public final class RenderParamsFlags { new Key<Boolean>("disableBitmapCaching", Boolean.class); public static final Key<Boolean> FLAG_KEY_RENDER_ALL_DRAWABLE_STATES = new Key<Boolean>("renderAllDrawableStates", Boolean.class); - /** - * To tell LayoutLib that the IDE supports RecyclerView. - * <p/> - * Default is false. - */ - public static final Key<Boolean> FLAG_KEY_RECYCLER_VIEW_SUPPORT = - new Key<Boolean>("recyclerViewSupport", Boolean.class); + /** * The application package name. Used via {@link LayoutlibCallback#getFlag(Key)} */ public static final Key<String> FLAG_KEY_APPLICATION_PACKAGE = new Key<String>("applicationPackage", String.class); - /** - * To tell LayoutLib that IDE supports providing XML Parser for a file (useful for getting in - * memory contents of the file). Used via {@link LayoutlibCallback#getFlag(Key)} - */ - public static final Key<Boolean> FLAG_KEY_XML_FILE_PARSER_SUPPORT = - new Key<Boolean>("xmlFileParser", Boolean.class); + /** * To tell LayoutLib to not render when creating a new session. This allows controlling when the first * layout rendering will happen. @@ -88,12 +77,6 @@ public final class RenderParamsFlags { public static final Key<Boolean> FLAG_ENABLE_LAYOUT_VALIDATOR_IMAGE_CHECK = new Key<>("enableLayoutValidatorImageCheck", Boolean.class); - /** - * TODO: remove after ag/15997527 and ag/15997989 has landed. - */ - @Deprecated - public static final Key<Boolean> FLAG_ENABLE_LAYOUT_VALIDATOR_OPTIMIZATION = - new Key<>("enableLayoutValidatorOptimization", Boolean.class); // Disallow instances. private RenderParamsFlags() {} } diff --git a/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java b/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java index 83f1f305f7..46dd0b4149 100644 --- a/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java +++ b/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java @@ -20,7 +20,6 @@ import com.android.ide.common.rendering.api.ILayoutLog; import com.android.ide.common.rendering.api.LayoutlibCallback; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.android.BridgeContext; -import com.android.layoutlib.bridge.android.RenderParamsFlags; import com.android.layoutlib.common.util.ReflectionUtils; import com.android.layoutlib.common.util.ReflectionUtils.ReflectionException; @@ -120,11 +119,6 @@ public class RecyclerViewUtil { @Nullable private static Object createAdapter(@NonNull LayoutlibCallback layoutlibCallback, @NonNull String adapterClassName) throws ReflectionException { - Boolean ideSupport = - layoutlibCallback.getFlag(RenderParamsFlags.FLAG_KEY_RECYCLER_VIEW_SUPPORT); - if (ideSupport != Boolean.TRUE) { - return null; - } try { return layoutlibCallback.loadClass(adapterClassName, new Class[0], new Object[0]); } catch (Exception e) { diff --git a/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index e4b566d0a8..8c46e33c3b 100644 --- a/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +++ b/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -1061,7 +1061,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { int shiftX = -scrollX + Math.round(view.getTranslationX()) + hOffset; int shiftY = -scrollY + Math.round(view.getTranslationY()) + vOffset; result = new ViewInfo(view.getClass().getName(), - getContext().getViewKey(view), + getViewKey(view), shiftX + view.getLeft(), shiftY + view.getTop(), shiftX + view.getRight(), @@ -1128,6 +1128,17 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { @Nullable private Object getViewKey(View view) { BridgeContext context = getContext(); + if ("com.google.android.material.tabs.TabLayout.TabView".equals( + view.getClass().getCanonicalName())) { + // TabView from the material library is a LinearLayout, but it is defined in XML + // as a TabItem. Because of this, TabView doesn't get the correct cookie, but its + // children do. So this reassigns the cookie from the first child to link the XML + // TabItem to the actual TabView view. + ViewGroup tabView = (ViewGroup)view; + if (tabView.getChildCount() > 0) { + return context.getViewKey(tabView.getChildAt(0)); + } + } if (!(view instanceof MenuView.ItemView)) { return context.getViewKey(view); } diff --git a/bridge/tests/src/com/android/layoutlib/bridge/intensive/setup/LayoutLibTestCallback.java b/bridge/tests/src/com/android/layoutlib/bridge/intensive/setup/LayoutLibTestCallback.java index c1fc595075..8dd7ec7a61 100644 --- a/bridge/tests/src/com/android/layoutlib/bridge/intensive/setup/LayoutLibTestCallback.java +++ b/bridge/tests/src/com/android/layoutlib/bridge/intensive/setup/LayoutLibTestCallback.java @@ -185,6 +185,11 @@ public class LayoutLibTestCallback extends LayoutlibCallback { } @Override + public String getResourcePackage() { + return PACKAGE_NAME; + } + + @Override public Class<?> findClass(String name) throws ClassNotFoundException { return mModuleClassLoader.loadClass(name); } diff --git a/remote/client/src/com/android/layoutlib/bridge/remote/client/adapters/RemoteLayoutlibCallbackAdapter.java b/remote/client/src/com/android/layoutlib/bridge/remote/client/adapters/RemoteLayoutlibCallbackAdapter.java index 01efd1224d..06fa6b26bf 100644 --- a/remote/client/src/com/android/layoutlib/bridge/remote/client/adapters/RemoteLayoutlibCallbackAdapter.java +++ b/remote/client/src/com/android/layoutlib/bridge/remote/client/adapters/RemoteLayoutlibCallbackAdapter.java @@ -102,6 +102,11 @@ public class RemoteLayoutlibCallbackAdapter implements RemoteLayoutlibCallback { return mDelegate.getFlag(key); } + @Override + public String getResourcePackage() throws RemoteException { + return mDelegate.getResourcePackage(); + } + @Nullable @Override public Path findClassPath(String name) { diff --git a/remote/common/src/com/android/layout/remote/api/RemoteLayoutlibCallback.java b/remote/common/src/com/android/layout/remote/api/RemoteLayoutlibCallback.java index d68934ae65..ccf1feeb4e 100644 --- a/remote/common/src/com/android/layout/remote/api/RemoteLayoutlibCallback.java +++ b/remote/common/src/com/android/layout/remote/api/RemoteLayoutlibCallback.java @@ -52,6 +52,8 @@ public interface RemoteLayoutlibCallback extends Remote { <T> T getFlag(Key<T> key) throws RemoteException; + String getResourcePackage() throws RemoteException; + Path findClassPath(String name) throws RemoteException; RemoteXmlPullParser createXmlParserForPsiFile(String fileName) throws RemoteException; diff --git a/remote/server/src/com/android/layoutlib/bridge/remote/server/adapters/RemoteLayoutlibCallbackAdapter.java b/remote/server/src/com/android/layoutlib/bridge/remote/server/adapters/RemoteLayoutlibCallbackAdapter.java index 719de4dcd3..cba8a472ef 100644 --- a/remote/server/src/com/android/layoutlib/bridge/remote/server/adapters/RemoteLayoutlibCallbackAdapter.java +++ b/remote/server/src/com/android/layoutlib/bridge/remote/server/adapters/RemoteLayoutlibCallbackAdapter.java @@ -218,6 +218,15 @@ public class RemoteLayoutlibCallbackAdapter extends LayoutlibCallback { } @Override + public String getResourcePackage() { + try { + return mDelegate.getResourcePackage(); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } + + @Override public Class<?> findClass(String name) throws ClassNotFoundException { return mPathClassLoader.loadClass(name); } |