diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2015-03-05 18:38:37 -0800 |
---|---|---|
committer | Deepanshu Gupta <deepanshu@google.com> | 2015-03-10 18:16:21 -0700 |
commit | d345f44a87de1088fcd19e021238852bbffbbaec (patch) | |
tree | c2da5166e0fe4a86b8baa9db37ab38659644867f /tools/layoutlib/bridge/src/android | |
parent | 464a2bc261ac3b3ad817e3d5cc7fa8f3dae0a6c3 (diff) | |
download | frameworks_base-d345f44a87de1088fcd19e021238852bbffbbaec.zip frameworks_base-d345f44a87de1088fcd19e021238852bbffbbaec.tar.gz frameworks_base-d345f44a87de1088fcd19e021238852bbffbbaec.tar.bz2 |
Add RecyclerView support.
Bug: http://b.android.com/72117
Change-Id: Iba95baff59f1b715f91da25e15acf27bc052d95e
Diffstat (limited to 'tools/layoutlib/bridge/src/android')
-rw-r--r-- | tools/layoutlib/bridge/src/android/view/BridgeInflater.java | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java index 7e4ff69..fbd5e2a 100644 --- a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java +++ b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java @@ -22,9 +22,13 @@ import com.android.ide.common.rendering.api.MergeCookie; import com.android.ide.common.rendering.api.ResourceReference; import com.android.ide.common.rendering.api.ResourceValue; import com.android.layoutlib.bridge.Bridge; +import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.android.BridgeContext; import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; +import com.android.layoutlib.bridge.android.support.RecyclerViewUtil; +import com.android.layoutlib.bridge.android.support.RecyclerViewUtil.LayoutManagerType; import com.android.layoutlib.bridge.impl.ParserFactory; +import com.android.layoutlib.bridge.impl.RenderSessionImpl; import com.android.resources.ResourceType; import com.android.util.Pair; @@ -111,8 +115,7 @@ public final class BridgeInflater extends LayoutInflater { } catch (Exception e) { // Wrap the real exception in a ClassNotFoundException, so that the calling method // can deal with it. - ClassNotFoundException exception = new ClassNotFoundException("onCreateView", e); - throw exception; + throw new ClassNotFoundException("onCreateView", e); } setupViewInContext(view, attrs); @@ -123,7 +126,7 @@ public final class BridgeInflater extends LayoutInflater { @Override public View createViewFromTag(View parent, String name, AttributeSet attrs, boolean inheritContext) { - View view = null; + View view; try { view = super.createViewFromTag(parent, name, attrs, inheritContext); } catch (InflateException e) { @@ -134,7 +137,7 @@ public final class BridgeInflater extends LayoutInflater { // Wrap the real exception in an InflateException so that the calling // method can deal with it. InflateException exception = new InflateException(); - if (e2.getClass().equals(ClassNotFoundException.class) == false) { + if (!e2.getClass().equals(ClassNotFoundException.class)) { exception.initCause(e2); } else { exception.initCause(e); @@ -184,7 +187,7 @@ public final class BridgeInflater extends LayoutInflater { return inflate(bridgeParser, root); } catch (Exception e) { Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, - "Failed to parse file " + f.getAbsolutePath(), e, null /*data*/); + "Failed to parse file " + f.getAbsolutePath(), e, null); return null; } @@ -194,8 +197,7 @@ public final class BridgeInflater extends LayoutInflater { return null; } - private View loadCustomView(String name, AttributeSet attrs) throws ClassNotFoundException, - Exception{ + private View loadCustomView(String name, AttributeSet attrs) throws Exception { if (mProjectCallback != null) { // first get the classname in case it's not the node name if (name.equals("view")) { @@ -227,6 +229,20 @@ public final class BridgeInflater extends LayoutInflater { if (viewKey != null) { bc.addViewKey(view, viewKey); } + if (RenderSessionImpl.isInstanceOf(view, RecyclerViewUtil.CN_RECYCLER_VIEW)) { + String type = attrs.getAttributeValue(BridgeConstants.NS_RESOURCES, + BridgeConstants.ATTR_LAYOUT_MANAGER_TYPE); + if (type != null) { + LayoutManagerType layoutManagerType = LayoutManagerType.getByDisplayName(type); + if (layoutManagerType == null) { + Bridge.getLog().warning(LayoutLog.TAG_UNSUPPORTED, + "LayoutManager (" + type + ") not found, falling back to " + + "LinearLayoutManager", null); + } else { + bc.addCookie(view, layoutManagerType); + } + } + } } } |