return "";
}
- String name = gre.callGetDisplayName(canvasViewInfo.getUiViewKey());
+ String name = gre.callGetDisplayName(canvasViewInfo.getUiViewNode());
if (name == null) {
// The name is typically a fully-qualified class name. Let's make it a tad shorter.
LayoutEditor layoutEditor = canvas.getLayoutEditor();
for (CanvasSelection cs : selection) {
CanvasViewInfo vi = cs.getViewInfo();
- UiViewElementNode key = vi.getUiViewKey();
+ UiViewElementNode key = vi.getUiViewNode();
Node node = key.getXmlNode();
String t = layoutEditor.getXmlText(node);
if (t != null) {
private final Rectangle mAbsRect;
private final Rectangle mSelectionRect;
private final String mName;
- private final UiViewElementNode mUiViewKey;
+ private final UiViewElementNode mUiViewNode;
private final CanvasViewInfo mParent;
private final ArrayList<CanvasViewInfo> mChildren = new ArrayList<CanvasViewInfo>();
mParent = parent;
mName = viewInfo.getClassName();
- // The ViewInfo#getViewKey() method returns a key which depends on the
- // IXmlPullParser used to parse the layout files. In this case, the parser is
- // guaranteed to be an UiElementPullParser, which creates keys that are of type
- // UiViewElementNode.
+ // The ViewInfo#getViewKey() method returns a cookie uniquely identifying the object
+ // they represent on this side of the API.
+ // In this case, the parser is guaranteed to be an UiElementPullParser, which creates
+ // cookies that are of type UiViewElementNode.
// We'll simply crash if the type is not right, as this is not supposed to happen
// and nothing could work if there's a type mismatch.
- mUiViewKey = (UiViewElementNode) viewInfo.getViewKey();
+ mUiViewNode = (UiViewElementNode) viewInfo.getCookie();
int x = viewInfo.getLeft();
int y = viewInfo.getTop();
// Only use children which have a ViewKey of the correct type.
// We can't interact with those when they have a null key or
// an incompatible type.
- if (child.getViewKey() instanceof UiViewElementNode) {
+ if (child.getCookie() instanceof UiViewElementNode) {
mChildren.add(new CanvasViewInfo(child, this, x, y));
}
}
}
/**
- * Returns the view key. Could be null, although unlikely.
+ * Returns the view node. Could be null, although unlikely.
* @return An {@link UiViewElementNode} that uniquely identifies the object in the XML model.
- * @see ViewInfo#getViewKey()
+ * @see ViewInfo#getCookie()
*/
- public UiViewElementNode getUiViewKey() {
- return mUiViewKey;
+ public UiViewElementNode getUiViewNode() {
+ return mUiViewNode;
}
/**
// ---- Implementation of IPropertySource
public Object getEditableValue() {
- UiViewElementNode uiView = getUiViewKey();
+ UiViewElementNode uiView = getUiViewNode();
if (uiView != null) {
return ((IPropertySource) uiView).getEditableValue();
}
}
public IPropertyDescriptor[] getPropertyDescriptors() {
- UiViewElementNode uiView = getUiViewKey();
+ UiViewElementNode uiView = getUiViewNode();
if (uiView != null) {
return ((IPropertySource) uiView).getPropertyDescriptors();
}
}
public Object getPropertyValue(Object id) {
- UiViewElementNode uiView = getUiViewKey();
+ UiViewElementNode uiView = getUiViewNode();
if (uiView != null) {
return ((IPropertySource) uiView).getPropertyValue(id);
}
}
public boolean isPropertySet(Object id) {
- UiViewElementNode uiView = getUiViewKey();
+ UiViewElementNode uiView = getUiViewNode();
if (uiView != null) {
return ((IPropertySource) uiView).isPropertySet(id);
}
}
public void resetPropertyValue(Object id) {
- UiViewElementNode uiView = getUiViewKey();
+ UiViewElementNode uiView = getUiViewNode();
if (uiView != null) {
((IPropertySource) uiView).resetPropertyValue(id);
}
}
public void setPropertyValue(Object id, Object value) {
- UiViewElementNode uiView = getUiViewKey();
+ UiViewElementNode uiView = getUiViewNode();
if (uiView != null) {
((IPropertySource) uiView).setPropertyValue(id, value);
}
* @return The XML node corresponding to this info object, or null
*/
public Node getXmlNode() {
- UiViewElementNode uiView = getUiViewKey();
+ UiViewElementNode uiView = getUiViewNode();
if (uiView != null) {
return uiView.getXmlNode();
}
// The root element is the one whose GRAND parent
// is null (because the parent will be a -document-
// node).
- return mUiViewKey == null || mUiViewKey.getUiParent() == null ||
- mUiViewKey.getUiParent().getUiParent() == null;
+ return mUiViewNode == null || mUiViewNode.getUiParent() == null ||
+ mUiViewNode.getUiParent().getUiParent() == null;
}
/**
*/
public boolean isInvisibleParent() {
if (mAbsRect.width < SELECTION_MIN_SIZE || mAbsRect.height < SELECTION_MIN_SIZE) {
- return mUiViewKey != null && mUiViewKey.getDescriptor().hasChildren();
+ return mUiViewNode != null && mUiViewNode.getDescriptor().hasChildren();
}
return false;
*/
/* package */ SimpleElement toSimpleElement() {
- UiViewElementNode uiNode = getUiViewKey();
+ UiViewElementNode uiNode = getUiViewNode();
String fqcn = SimpleXmlTransfer.getFqcn(uiNode.getDescriptor());
String parentFqcn = null;
CanvasViewInfo vi = cs.getViewInfo();
// You can't delete the root element
if (vi != null && !vi.isRoot()) {
- UiViewElementNode ui = vi.getUiViewKey();
+ UiViewElementNode ui = vi.getUiViewNode();
if (ui != null) {
ui.deleteXmlNode();
}
// O(n^2) here, but both the selection size and especially the
// invisibleParents size are expected to be small
if (invisibleParents.contains(viewInfo)) {
- UiViewElementNode node = viewInfo.getUiViewKey();
+ UiViewElementNode node = viewInfo.getUiViewNode();
if (node != null) {
if (result == null) {
result = new HashSet<UiElementNode>();
tv.setComparer(new IElementComparer() {
public int hashCode(Object element) {
if (element instanceof CanvasViewInfo) {
- UiViewElementNode key = ((CanvasViewInfo) element).getUiViewKey();
+ UiViewElementNode key = ((CanvasViewInfo) element).getUiViewNode();
if (key != null) {
return key.hashCode();
}
public boolean equals(Object a, Object b) {
if (a instanceof CanvasViewInfo && b instanceof CanvasViewInfo) {
- UiViewElementNode keyA = ((CanvasViewInfo) a).getUiViewKey();
- UiViewElementNode keyB = ((CanvasViewInfo) b).getUiViewKey();
+ UiViewElementNode keyA = ((CanvasViewInfo) a).getUiViewNode();
+ UiViewElementNode keyB = ((CanvasViewInfo) b).getUiViewNode();
if (keyA != null) {
return keyA.equals(keyB);
}
*/
public Image getImage(Object element) {
if (element instanceof CanvasViewInfo) {
- element = ((CanvasViewInfo) element).getUiViewKey();
+ element = ((CanvasViewInfo) element).getUiViewNode();
}
if (element instanceof UiElementNode) {
*/
public String getText(Object element) {
if (element instanceof CanvasViewInfo) {
- element = ((CanvasViewInfo) element).getUiViewKey();
+ element = ((CanvasViewInfo) element).getUiViewNode();
}
if (element instanceof UiElementNode) {
// Check if the selected object still exists
ViewHierarchy viewHierarchy = mCanvas.getViewHierarchy();
- Object key = s.getViewInfo().getUiViewKey();
+ Object key = s.getViewInfo().getUiViewNode();
CanvasViewInfo vi = viewHierarchy.findViewInfoKey(key, lastValidViewInfoRoot);
// Remove the previous selection -- if the selected object still exists
for (Iterator<CanvasSelection> it = selection.iterator(); it.hasNext(); ) {
CanvasSelection cs = it.next();
CanvasViewInfo vi = cs.getViewInfo();
- UiViewElementNode key = vi == null ? null : vi.getUiViewKey();
+ UiViewElementNode key = vi == null ? null : vi.getUiViewNode();
Node node = key == null ? null : key.getXmlNode();
if (node == null) {
// Missing ViewInfo or view key or XML, discard this.
return;
}
- UiViewElementNode key = vi.getUiViewKey();
+ UiViewElementNode key = vi.getUiViewNode();
if (key != null) {
mCanvas.getNodeFactory().create(vi);
if (vi.isInvisibleParent()) {
mInvisibleParents.add(vi);
} else if (invisibleNodes != null) {
- UiViewElementNode key = vi.getUiViewKey();
+ UiViewElementNode key = vi.getUiViewNode();
if (key != null && invisibleNodes.contains(key)) {
vi.setExploded(true);
if (canvasViewInfo == null) {
return null;
}
- if (canvasViewInfo.getUiViewKey() == viewKey) {
+ if (canvasViewInfo.getUiViewNode() == viewKey) {
return canvasViewInfo;
}
Set<UiElementNode> nodes = new HashSet<UiElementNode>(mInvisibleParents.size());
for (CanvasViewInfo info : mInvisibleParents) {
- UiViewElementNode node = info.getUiViewKey();
+ UiViewElementNode node = info.getUiViewNode();
if (node != null) {
nodes.add(node);
}
* {@link CanvasViewInfo}. The bounds of the node are set to the canvas view bounds.
*/
public NodeProxy create(CanvasViewInfo canvasViewInfo) {
- return create(canvasViewInfo.getUiViewKey(), canvasViewInfo.getAbsRect());
+ return create(canvasViewInfo.getUiViewNode(), canvasViewInfo.getAbsRect());
}
/**
import com.android.layoutlib.api.SceneResult.LayoutStatus;
import java.awt.image.BufferedImage;
+import java.util.Map;
/**
* An object allowing interaction with an Android layout.
return null;
}
+
+ /**
+ * Returns a map of (XML attribute name, attribute value) containing only default attribute
+ * values, for the given view Object.
+ * @param viewObject the view object.
+ * @return a map of the default property values or null.
+ */
+ public Map<String, String> getDefaultViewPropertyValues(Object viewObject) {
+ return null;
+ }
+
/**
* Re-renders the layout as-is.
* In case of success, this should be followed by calls to {@link #getRootView()} and
import java.util.Collections;
import java.util.List;
-import java.util.Map;
/**
* Layout information for a specific view object
*/
-public class ViewInfo {
+public final class ViewInfo {
- protected final Object mKey;
- protected final String mName;
- protected final int mLeft;
- protected final int mRight;
- protected final int mTop;
- protected final int mBottom;
- protected List<ViewInfo> mChildren = Collections.emptyList();
+ private final Object mCookie;
+ private final String mName;
+ private final int mLeft;
+ private final int mRight;
+ private final int mTop;
+ private final int mBottom;
+ private List<ViewInfo> mChildren = Collections.emptyList();
+ private final Object mViewObject;
+ private final Object mLayoutParamsObject;
- public ViewInfo(String name, Object key, int left, int top, int right, int bottom) {
+ public ViewInfo(String name, Object cookie, int left, int top, int right, int bottom) {
+ this(name, cookie, left, top, right, bottom, null /*viewObject*/,
+ null /*layoutParamsObject*/);
+ }
+
+ public ViewInfo(String name, Object cookie, int left, int top, int right, int bottom,
+ Object viewObject, Object layoutParamsObject) {
mName = name;
- mKey = key;
+ mCookie = cookie;
mLeft = left;
mRight = right;
mTop = top;
mBottom = bottom;
+ mViewObject = viewObject;
+ mLayoutParamsObject = layoutParamsObject;
}
/**
* Sets the list of children {@link ViewInfo}.
*/
public void setChildren(List<ViewInfo> children) {
- mChildren = Collections.unmodifiableList(children);
+ if (children != null) {
+ mChildren = Collections.unmodifiableList(children);
+ } else {
+ mChildren = Collections.emptyList();
+ }
}
/**
}
/**
- * Returns the key associated with the node. Can be null.
+ * Returns the cookie associated with the XML node. Can be null.
*
* @see IXmlPullParser#getViewKey()
*/
- public Object getViewKey() {
- return mKey;
+ public Object getCookie() {
+ return mCookie;
}
/**
}
/**
- * Returns a map of default values for some properties. The map key is the property name,
- * as found in the XML.
+ * Returns the actual android.view.View (or child class) object. This can be used
+ * to query the object properties that are not in the XML and not in the map returned
+ * by {@link #getDefaultPropertyValues()}.
*/
- public Map<String, String> getDefaultPropertyValues() {
- return null;
+ public Object getViewObject() {
+ return mViewObject;
}
/**
* to query the object properties that are not in the XML and not in the map returned
* by {@link #getDefaultPropertyValues()}.
*/
- public Object getViewObject() {
- return null;
+ public Object getLayoutParamsObject() {
+ return mLayoutParamsObject;
}
}