diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2015-03-12 01:55:16 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-03-12 01:55:16 +0000 |
commit | a4ed5e94117a2c6c1734138faed09490245c602f (patch) | |
tree | 2bf727dc71445934f6a2dc6182e6ea0957d187f1 /tools | |
parent | 1a27a3fb4eceefcf412218d73de0cff0cc68c67d (diff) | |
parent | e770c5e45a139d709976f8c1dbb821733968b5a8 (diff) | |
download | frameworks_base-a4ed5e94117a2c6c1734138faed09490245c602f.zip frameworks_base-a4ed5e94117a2c6c1734138faed09490245c602f.tar.gz frameworks_base-a4ed5e94117a2c6c1734138faed09490245c602f.tar.bz2 |
am e770c5e4: am c44430a3: Merge "Tools attribute improvements for RecyclerView LayoutManager." into lmp-mr1-dev
* commit 'e770c5e45a139d709976f8c1dbb821733968b5a8':
Tools attribute improvements for RecyclerView LayoutManager.
Diffstat (limited to 'tools')
3 files changed, 36 insertions, 21 deletions
diff --git a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java index fbd5e2a..8192b5f 100644 --- a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java +++ b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java @@ -233,11 +233,13 @@ public final class BridgeInflater extends LayoutInflater { String type = attrs.getAttributeValue(BridgeConstants.NS_RESOURCES, BridgeConstants.ATTR_LAYOUT_MANAGER_TYPE); if (type != null) { - LayoutManagerType layoutManagerType = LayoutManagerType.getByDisplayName(type); + LayoutManagerType layoutManagerType = LayoutManagerType.getByLogicalName(type); if (layoutManagerType == null) { - Bridge.getLog().warning(LayoutLog.TAG_UNSUPPORTED, - "LayoutManager (" + type + ") not found, falling back to " + - "LinearLayoutManager", null); + layoutManagerType = LayoutManagerType.getByClassName(type); + } + if (layoutManagerType == null) { + // add the classname itself. + bc.addCookie(view, type); } else { bc.addCookie(view, layoutManagerType); } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java index fdb4567..1af6998 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java @@ -50,5 +50,5 @@ public class BridgeConstants { public final static String WRAP_CONTENT = "wrap_content"; /** Attribute in the tools namespace used to specify layout manager for RecyclerView. */ - public static final String ATTR_LAYOUT_MANAGER_TYPE = "layoutManagerType"; + public static final String ATTR_LAYOUT_MANAGER_TYPE = "layoutManager"; } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java index 2feab7a..1d47333 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java @@ -73,8 +73,15 @@ public class RecyclerViewUtil { private static void setLayoutManager(@NonNull View recyclerView, @NonNull BridgeContext context, @NonNull IProjectCallback callback) throws ReflectionException { Object cookie = context.getCookie(recyclerView); - assert cookie == null || cookie instanceof LayoutManagerType; - if (cookie == null) { + assert cookie == null || cookie instanceof LayoutManagerType || cookie instanceof String; + if (!(cookie instanceof LayoutManagerType)) { + if (cookie != null) { + // TODO: When layoutlib API is updated, try to load the class with a null + // constructor or a constructor taking one argument - the context. + Bridge.getLog().warning(LayoutLog.TAG_UNSUPPORTED, + "LayoutManager (" + cookie + ") not found, falling back to " + + "LinearLayoutManager", null); + } cookie = LayoutManagerType.getDefault(); } Object layoutManager = createLayoutManager((LayoutManagerType) cookie, context, callback); @@ -152,22 +159,13 @@ public class RecyclerViewUtil { "android.support.v7.widget.StaggeredGridLayoutManager", new Class[]{int.class, int.class}, new Object[]{2, LinearLayout.VERTICAL}); - private String mDisplayName; + private String mLogicalName; private String mClassName; private Class[] mSignature; private Object[] mArgs; - private static final HashMap<String, LayoutManagerType> sDisplayNameLookup = - new HashMap<String, LayoutManagerType>(); - - static { - for (LayoutManagerType type : LayoutManagerType.values()) { - sDisplayNameLookup.put(type.mDisplayName, type); - } - } - - LayoutManagerType(String displayName, String className, Class[] signature, Object[] args) { - mDisplayName = displayName; + LayoutManagerType(String logicalName, String className, Class[] signature, Object[] args) { + mLogicalName = logicalName; mClassName = className; mSignature = signature; mArgs = args; @@ -199,8 +197,23 @@ public class RecyclerViewUtil { } @Nullable - public static LayoutManagerType getByDisplayName(@Nullable String className) { - return sDisplayNameLookup.get(className); + public static LayoutManagerType getByLogicalName(@NonNull String logicalName) { + for (LayoutManagerType type : values()) { + if (logicalName.equals(type.mLogicalName)) { + return type; + } + } + return null; + } + + @Nullable + public static LayoutManagerType getByClassName(@NonNull String className) { + for (LayoutManagerType type : values()) { + if (className.equals(type.mClassName)) { + return type; + } + } + return null; } } } |