Merge "Merge 05b7b69c from honeycomb-mr1. do not merge." into gingerbread

This commit is contained in:
Xavier Ducrohet
2011-05-20 13:56:47 -07:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 22 deletions

View File

@@ -199,8 +199,8 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
//Capability.LAYOUT_ONLY, // disable to run on ADT 10.0 which doesn't include this. //Capability.LAYOUT_ONLY, // disable to run on ADT 10.0 which doesn't include this.
Capability.EMBEDDED_LAYOUT, Capability.EMBEDDED_LAYOUT,
Capability.VIEW_MANIPULATION, Capability.VIEW_MANIPULATION,
Capability.ADAPTER_BINDING); Capability.ADAPTER_BINDING,
Capability.EXTENDED_VIEWINFO);
BridgeAssetManager.initSystem(); BridgeAssetManager.initSystem();
@@ -397,15 +397,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

@@ -66,6 +66,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;
@@ -465,7 +466,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();
@@ -1040,7 +1041,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;
} }
@@ -1049,7 +1050,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
@@ -1057,7 +1058,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;
} }
@@ -1072,8 +1074,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;
} }
@@ -1083,9 +1086,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;
@@ -1096,15 +1112,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;
} }