am aa0834e3: Merge "LayoutLib: support the new baseline/margin query API." into honeycomb-mr1

* commit 'aa0834e3e6c3ceef6f78e3e03d1d27046e5237a0':
  LayoutLib: support the new baseline/margin query API.
This commit is contained in:
Xavier Ducrohet
2011-05-18 17:40:08 -07:00
committed by Android Git Automerger
3 changed files with 33 additions and 21 deletions

View File

@ -201,7 +201,8 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
Capability.VIEW_MANIPULATION, Capability.VIEW_MANIPULATION,
Capability.PLAY_ANIMATION, Capability.PLAY_ANIMATION,
Capability.ANIMATED_VIEW_MANIPULATION, Capability.ANIMATED_VIEW_MANIPULATION,
Capability.ADAPTER_BINDING); Capability.ADAPTER_BINDING,
Capability.EXTENDED_VIEWINFO);
BridgeAssetManager.initSystem(); BridgeAssetManager.initSystem();
@ -399,15 +400,6 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
throw new IllegalArgumentException("viewObject is not a View"); throw new IllegalArgumentException("viewObject is not a View");
} }
@Override
public int getViewBaseline(Object viewObject) {
if (viewObject instanceof View) {
return ((View) viewObject).getBaseline();
}
throw new IllegalArgumentException("viewObject is not a View");
}
/** /**
* Returns the lock for the bridge * Returns the lock for the bridge
*/ */

View File

@ -19,21 +19,23 @@ package com.android.layoutlib.bridge;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.TextView; import android.widget.TextView;
/** /**
* Base class for mocked views. * Base class for mocked views.
* *
* TODO: implement onDraw and draw a rectangle in a random color with the name of the class * TODO: implement onDraw and draw a rectangle in a random color with the name of the class
* (or better the id of the view). * (or better the id of the view).
*/ */
public class MockView extends TextView { public class MockView extends TextView {
public MockView(Context context, AttributeSet attrs, int defStyle) { public MockView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
setText(this.getClass().getSimpleName()); setText(this.getClass().getSimpleName());
setTextColor(0xFF000000); setTextColor(0xFF000000);
setGravity(Gravity.CENTER);
} }
@Override @Override

View File

@ -74,6 +74,7 @@ import android.view.ViewGroup;
import android.view.View.AttachInfo; import android.view.View.AttachInfo;
import android.view.View.MeasureSpec; import android.view.View.MeasureSpec;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.AbsListView; import android.widget.AbsListView;
import android.widget.AbsSpinner; import android.widget.AbsSpinner;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -513,7 +514,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
mViewRoot.draw(mCanvas); mViewRoot.draw(mCanvas);
} }
mViewInfoList = startVisitingViews(mViewRoot, 0); mViewInfoList = startVisitingViews(mViewRoot, 0, params.getExtendedViewInfoMode());
// success! // success!
return SUCCESS.createResult(); return SUCCESS.createResult();
@ -1255,7 +1256,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
} }
} }
private List<ViewInfo> startVisitingViews(View view, int offset) { private List<ViewInfo> startVisitingViews(View view, int offset, boolean setExtendedInfo) {
if (view == null) { if (view == null) {
return null; return null;
} }
@ -1264,7 +1265,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
offset += view.getTop(); offset += view.getTop();
if (view == mContentRoot) { if (view == mContentRoot) {
return visitAllChildren(mContentRoot, offset); return visitAllChildren(mContentRoot, offset, setExtendedInfo);
} }
// otherwise, look for mContentRoot in the children // otherwise, look for mContentRoot in the children
@ -1272,7 +1273,8 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
ViewGroup group = ((ViewGroup) view); ViewGroup group = ((ViewGroup) view);
for (int i = 0; i < group.getChildCount(); i++) { for (int i = 0; i < group.getChildCount(); i++) {
List<ViewInfo> list = startVisitingViews(group.getChildAt(i), offset); List<ViewInfo> list = startVisitingViews(group.getChildAt(i), offset,
setExtendedInfo);
if (list != null) { if (list != null) {
return list; return list;
} }
@ -1287,8 +1289,9 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
* bounds of all the views. * bounds of all the views.
* @param view the root View * @param view the root View
* @param offset an offset for the view bounds. * @param offset an offset for the view bounds.
* @param setExtendedInfo whether to set the extended view info in the {@link ViewInfo} object.
*/ */
private ViewInfo visit(View view, int offset) { private ViewInfo visit(View view, int offset, boolean setExtendedInfo) {
if (view == null) { if (view == null) {
return null; return null;
} }
@ -1298,9 +1301,22 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
view.getLeft(), view.getTop() + offset, view.getRight(), view.getBottom() + offset, view.getLeft(), view.getTop() + offset, view.getRight(), view.getBottom() + offset,
view, view.getLayoutParams()); view, view.getLayoutParams());
if (setExtendedInfo) {
MarginLayoutParams marginParams = null;
LayoutParams params = view.getLayoutParams();
if (params instanceof MarginLayoutParams) {
marginParams = (MarginLayoutParams) params;
}
result.setExtendedInfo(view.getBaseline(),
marginParams != null ? marginParams.leftMargin : 0,
marginParams != null ? marginParams.topMargin : 0,
marginParams != null ? marginParams.rightMargin : 0,
marginParams != null ? marginParams.bottomMargin : 0);
}
if (view instanceof ViewGroup) { if (view instanceof ViewGroup) {
ViewGroup group = ((ViewGroup) view); ViewGroup group = ((ViewGroup) view);
result.setChildren(visitAllChildren(group, 0 /*offset*/)); result.setChildren(visitAllChildren(group, 0 /*offset*/, setExtendedInfo));
} }
return result; return result;
@ -1311,15 +1327,17 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
* containing the bounds of all the views. * containing the bounds of all the views.
* @param view the root View * @param view the root View
* @param offset an offset for the view bounds. * @param offset an offset for the view bounds.
* @param setExtendedInfo whether to set the extended view info in the {@link ViewInfo} object.
*/ */
private List<ViewInfo> visitAllChildren(ViewGroup viewGroup, int offset) { private List<ViewInfo> visitAllChildren(ViewGroup viewGroup, int offset,
boolean setExtendedInfo) {
if (viewGroup == null) { if (viewGroup == null) {
return null; return null;
} }
List<ViewInfo> children = new ArrayList<ViewInfo>(); List<ViewInfo> children = new ArrayList<ViewInfo>();
for (int i = 0; i < viewGroup.getChildCount(); i++) { for (int i = 0; i < viewGroup.getChildCount(); i++) {
children.add(visit(viewGroup.getChildAt(i), offset)); children.add(visit(viewGroup.getChildAt(i), offset, setExtendedInfo));
} }
return children; return children;
} }