aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Gaillard <jgaillard@google.com>2022-02-16 13:01:47 +0000
committerCherrypicker Worker <android-build-cherrypicker-worker@google.com>2022-02-16 13:01:47 +0000
commit4187262f50bd920cab53f232ee184cabe54d9e38 (patch)
treedb099402f5f2e90cf59b3d211fd156748e8e5f97
parentb260b2ed3897a438a6f978dfbda87077ce5a26ec (diff)
parent2cb5c82c7a5914fd7017d7cfde6b5d0b90288417 (diff)
downloadlayoutlib-4187262f50bd920cab53f232ee184cabe54d9e38.tar.gz
Fix view cookie for Material TabView
In the material design library, a TabLayout contains TabView objects, but those are defined in XML with TabItem tags. Since the TabItem cookie is set to the children of TabView, we can simply reset the TabView cookie to the value of one its child's cookie. Bug: 37137006 Test: checked manually (cherry picked from commit 25e9fe5c4dad33777c490a0a4302bec20599347f) Merged-In:I06ca802b8e6ab72a3cf7a05b56bce794eccbefa4 Use new LayoutlibCallback.getResourcePackage method In Resources_Delegate, when looking for the resource package name, use LayoutlibCallback.getResourcePackage instead of Context.getPackageName. Bug: N/A Test: layoutlib tests updated (cherry picked from commit 2d55a7614e54c7029064fa5959d899ac76400edf) Merged-In:Ife2c82820accac6345dbc34bdcd81b7cfa508d25 Remove unused RenderParamsFlag FLAG_ENABLE_LAYOUT_VALIDATOR_OPTIMIZATION has been unused since an update in the layout validation code. Bug: 153986571 Test: N/A (cherry picked from commit 88db70f42552fe1fcb9087c4b44ec62cd8ae3524) Merged-In:Ie56fb618a745bdd8f361720d629b5f4a681d92a4 Delete always true flags FLAG_KEY_RECYCLER_VIEW_SUPPORT and FLAG_KEY_XML_FILE_PARSER_SUPPORT always have true values. This removes them. Bug: 153986571 Test: N/A (cherry picked from commit ce38bf9dd4d1aab2ddef469ee92b623b1b75bc17) Merged-In:Ifff5dc065dc0aeba00e12bd763c90359f5463c1a Change-Id: I9507c7066c351e3171c08ce0000393f067b8255f
-rw-r--r--bridge/src/android/content/res/Resources_Delegate.java4
-rw-r--r--bridge/src/android/graphics/Typeface_Delegate.java10
-rw-r--r--bridge/src/com/android/layoutlib/bridge/android/RenderParamsFlags.java21
-rw-r--r--bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java6
-rw-r--r--bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java13
-rw-r--r--bridge/tests/src/com/android/layoutlib/bridge/intensive/setup/LayoutLibTestCallback.java5
-rw-r--r--remote/client/src/com/android/layoutlib/bridge/remote/client/adapters/RemoteLayoutlibCallbackAdapter.java5
-rw-r--r--remote/common/src/com/android/layout/remote/api/RemoteLayoutlibCallback.java2
-rw-r--r--remote/server/src/com/android/layoutlib/bridge/remote/server/adapters/RemoteLayoutlibCallbackAdapter.java9
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 291e907692..d9317a99fb 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.
@@ -100,12 +89,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 9faa0a64ae..4b9813a9b6 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
@@ -188,6 +188,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);
}