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

* commit 'f791863f0ac67ab6abd7410d5807d716cffc5b72':
  Merge 05b7b69c from honeycomb-mr1. do not merge.
This commit is contained in:
Xavier Ducrohet
2011-05-23 09:52:52 -07:00
committed by Android Git Automerger
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.EMBEDDED_LAYOUT,
Capability.VIEW_MANIPULATION,
Capability.ADAPTER_BINDING);
Capability.ADAPTER_BINDING,
Capability.EXTENDED_VIEWINFO);
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");
}
@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
*/

View File

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

View File

@@ -66,6 +66,7 @@ import android.view.ViewGroup;
import android.view.View.AttachInfo;
import android.view.View.MeasureSpec;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.AbsListView;
import android.widget.AbsSpinner;
import android.widget.AdapterView;
@@ -465,7 +466,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
mViewRoot.draw(mCanvas);
}
mViewInfoList = startVisitingViews(mViewRoot, 0);
mViewInfoList = startVisitingViews(mViewRoot, 0, params.getExtendedViewInfoMode());
// success!
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) {
return null;
}
@@ -1049,7 +1050,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
offset += view.getTop();
if (view == mContentRoot) {
return visitAllChildren(mContentRoot, offset);
return visitAllChildren(mContentRoot, offset, setExtendedInfo);
}
// otherwise, look for mContentRoot in the children
@@ -1057,7 +1058,8 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
ViewGroup group = ((ViewGroup) view);
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) {
return list;
}
@@ -1072,8 +1074,9 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
* bounds of all the views.
* @param view the root View
* @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) {
return null;
}
@@ -1083,9 +1086,22 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
view.getLeft(), view.getTop() + offset, view.getRight(), view.getBottom() + offset,
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) {
ViewGroup group = ((ViewGroup) view);
result.setChildren(visitAllChildren(group, 0 /*offset*/));
result.setChildren(visitAllChildren(group, 0 /*offset*/, setExtendedInfo));
}
return result;
@@ -1096,15 +1112,17 @@ public class RenderSessionImpl extends RenderAction<SessionParams> {
* containing the bounds of all the views.
* @param view the root View
* @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) {
return null;
}
List<ViewInfo> children = new ArrayList<ViewInfo>();
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;
}