From 8925febd3beb31e4c5e1a3329ed1e73291dd3936 Mon Sep 17 00:00:00 2001 From: Tor Norbye Date: Thu, 7 Jul 2011 12:05:20 -0700 Subject: [PATCH] Add support for hidden views There are some views which should hide in the UI to avoid clutter, such as widgets. This changeset adds support for hidden views, such that they don't show up in the outline, don't show up for hovers, aren't included in drag selections and so on. Change-Id: Icb18f4530b8aff584e72280f5bd09e776af9204c --- .../android/ide/common/layout/LayoutConstants.java | 4 +++ .../editors/layout/gle2/CanvasViewInfo.java | 38 ++++++++++++++++++++-- .../editors/layout/gle2/GestureManager.java | 9 ++--- .../internal/editors/layout/gle2/LayoutCanvas.java | 3 +- .../editors/layout/gle2/RenderService.java | 2 +- .../editors/layout/gle2/SelectionItem.java | 10 ++++++ .../editors/layout/gle2/SelectionManager.java | 11 +++++++ 7 files changed, 69 insertions(+), 8 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java index d6bfa30f7..efcb9300b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java @@ -53,6 +53,7 @@ public class LayoutConstants { public static final String SCROLL_VIEW = "ScrollView"; //$NON-NLS-1$ public static final String RADIO_BUTTON = "RadioButton"; //$NON-NLS-1$ public static final String RADIO_GROUP = "RadioGroup"; //$NON-NLS-1$ + public static final String SPACE = "Space"; //$NON-NLS-1$ public static final String EXPANDABLE_LIST_VIEW = "ExpandableListView";//$NON-NLS-1$ public static final String GESTURE_OVERLAY_VIEW = "GestureOverlayView";//$NON-NLS-1$ public static final String HORIZONTAL_SCROLL_VIEW = "HorizontalScrollView"; //$NON-NLS-1$ @@ -205,6 +206,9 @@ public class LayoutConstants { /** The fully qualified class name of a RadioGroup */ public static final String FQCN_RADIO_GROUP = "android.widgets.RadioGroup"; //$NON-NLS-1$ + /** The fully qualified class name of a Space */ + public static final String FQCN_SPACE = "android.widget.Space"; //$NON-NLS-1$ + public static final String ATTR_SRC = "src"; //$NON-NLS-1$ // like fill_parent for API 8 diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java index aef29b80b..7938f0bee 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java @@ -16,6 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout.gle2; +import static com.android.ide.common.layout.LayoutConstants.FQCN_SPACE; import static com.android.ide.common.layout.LayoutConstants.GESTURE_OVERLAY_VIEW; import static com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDescriptors.VIEW_MERGE; @@ -203,8 +204,9 @@ public class CanvasViewInfo implements IPropertySource { /** * Returns all the children of the canvas view info where each child corresponds to a - * unique node. This is intended for use by the outline for example, where only the - * actual nodes are displayed, not the views themselves. + * unique node that the user can see and select. This is intended for use by the + * outline for example, where only the actual nodes are displayed, not the views + * themselves. *

* Most views have their own nodes, so this is generally the same as * {@link #getChildren}, except in the case where you for example include a view that @@ -215,6 +217,8 @@ public class CanvasViewInfo implements IPropertySource { * never null */ public List getUniqueChildren() { + boolean haveHidden = false; + for (CanvasViewInfo info : mChildren) { if (info.mNodeSiblings != null) { // We have secondary children; must create a new collection containing @@ -229,6 +233,19 @@ public class CanvasViewInfo implements IPropertySource { } return children; } + + haveHidden |= info.isHidden(); + } + + if (haveHidden) { + List children = new ArrayList(mChildren.size()); + for (CanvasViewInfo vi : mChildren) { + if (!vi.isHidden()) { + children.add(vi); + } + } + + return children; } return mChildren; @@ -260,6 +277,7 @@ public class CanvasViewInfo implements IPropertySource { * Returns the name of the {@link CanvasViewInfo}. * Could be null, although unlikely. * Experience shows this is the full qualified Java name of the View. + * TODO: Rename this method to getFqcn. * * @return the name of the view info, or null * @@ -407,6 +425,11 @@ public class CanvasViewInfo implements IPropertySource { * @return True if this is a tiny layout or invisible view */ public boolean isInvisible() { + if (isHidden()) { + // Don't expand and highlight hidden widgets + return false; + } + if (mAbsRect.width < SELECTION_MIN_SIZE || mAbsRect.height < SELECTION_MIN_SIZE) { return mUiViewNode != null && (mUiViewNode.getDescriptor().hasChildren() || mAbsRect.width <= 0 || mAbsRect.height <= 0); @@ -416,6 +439,17 @@ public class CanvasViewInfo implements IPropertySource { } /** + * Returns true if this {@link CanvasViewInfo} represents a widget that should be + * hidden, such as a {@code } which are typically not manipulated by the user + * through dragging etc. + * + * @return true if this is a hidden view + */ + public boolean isHidden() { + return FQCN_SPACE.equals(mName); + } + + /** * Is this {@link CanvasViewInfo} a view that has had its padding inflated in order to * make it visible during selection or dragging? Note that this is NOT considered to * be the case in the explode-all-views mode where all nodes have their padding diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GestureManager.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GestureManager.java index 62d5dcd0c..0c8472858 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GestureManager.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GestureManager.java @@ -706,7 +706,7 @@ public class GestureManager { if (!insideSelection) { CanvasViewInfo vi = mCanvas.getViewHierarchy().findViewInfoAt(p); - if (vi != null && !vi.isRoot()) { + if (vi != null && !vi.isRoot() && !vi.isHidden()) { selectionManager.selectSingle(vi); insideSelection = true; } @@ -726,7 +726,7 @@ public class GestureManager { } else { // Only drag non-root items. for (SelectionItem cs : selections) { - if (!cs.isRoot()) { + if (!cs.isRoot() && !cs.isHidden()) { mDragSelection.add(cs); } } @@ -737,7 +737,7 @@ public class GestureManager { // If you are dragging a non-selected item, select it if (mDragSelection.isEmpty()) { CanvasViewInfo vi = mCanvas.getViewHierarchy().findViewInfoAt(p); - if (vi != null && !vi.isRoot()) { + if (vi != null && !vi.isRoot() && !vi.isHidden()) { selectionManager.selectSingle(vi); mDragSelection.addAll(selections); } @@ -761,7 +761,8 @@ public class GestureManager { // If you drag on the -background-, we make that into a marquee // selection - if (!e.doit || (imageCount == 1 && mDragSelection.get(0).isRoot())) { + if (!e.doit || (imageCount == 1 + && (mDragSelection.get(0).isRoot() || mDragSelection.get(0).isHidden()))) { boolean toggle = (mLastStateMask & (SWT.CTRL | SWT.SHIFT | SWT.COMMAND)) != 0; startGesture(controlPoint, new MarqueeGesture(mCanvas, toggle), mLastStateMask); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java index 76a511e90..32cc45d9e 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java @@ -848,7 +848,8 @@ public class LayoutCanvas extends Canvas { CanvasViewInfo vi = mViewHierarchy.findViewInfoAt(p); // We don't hover on the root since it's not a widget per see and it is always there. - if (vi != null && vi.isRoot()) { + // We also skip spacers... + if (vi != null && (vi.isRoot() || vi.isHidden())) { vi = null; } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java index 4b743b440..fc3d7d7b5 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java @@ -29,8 +29,8 @@ import com.android.ide.common.rendering.api.RenderSession; import com.android.ide.common.rendering.api.ResourceValue; import com.android.ide.common.rendering.api.Result; import com.android.ide.common.rendering.api.SessionParams; -import com.android.ide.common.rendering.api.ViewInfo; import com.android.ide.common.rendering.api.SessionParams.RenderingMode; +import com.android.ide.common.rendering.api.ViewInfo; import com.android.ide.common.resources.ResourceResolver; import com.android.ide.common.resources.configuration.ScreenSizeQualifier; import com.android.ide.eclipse.adt.AdtPlugin; diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionItem.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionItem.java index 7b869a5db..fcdf79a2d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionItem.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionItem.java @@ -83,6 +83,16 @@ class SelectionItem { } /** + * Returns true if this item represents a widget that should not be manipulated by the + * user. + * + * @return True if this widget should not be manipulated directly by the user + */ + public boolean isHidden() { + return mCanvasViewInfo.isHidden(); + } + + /** * Returns the selected view info. Cannot be null. * * @return the selected view info. Cannot be null. diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionManager.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionManager.java index aeb05a2af..daff906a6 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionManager.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionManager.java @@ -335,6 +335,10 @@ public class SelectionManager implements ISelectionProvider { CanvasViewInfo vi = mCanvas.getViewHierarchy().findViewInfoAt(p); + if (vi != null && vi.isHidden()) { + vi = vi.getParent(); + } + if (isMultiClick && !isCycleClick) { // Case where shift is pressed: pointed object is toggled. @@ -551,6 +555,9 @@ public class SelectionManager implements ISelectionProvider { mSelections.clear(); for (CanvasViewInfo viewInfo : viewInfos) { + if (viewInfo.isHidden()) { + continue; + } mSelections.add(createSelection(viewInfo)); } @@ -814,6 +821,10 @@ public class SelectionManager implements ISelectionProvider { for (INode node : nodes) { CanvasViewInfo viewInfo = mCanvas.getViewHierarchy().findViewInfoFor(node); if (viewInfo != null) { + if (nodes.size() > 1 && viewInfo.isHidden()) { + // Skip spacers - unless you're dropping just one + continue; + } newChildren.add(viewInfo); } } -- 2.11.0