OSDN Git Service

Add support for hidden views
authorTor Norbye <tnorbye@google.com>
Thu, 7 Jul 2011 19:05:20 +0000 (12:05 -0700)
committerTor Norbye <tnorbye@google.com>
Sat, 9 Jul 2011 03:31:20 +0000 (20:31 -0700)
There are some views which should hide in the UI to avoid clutter,
such as <Space> 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

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GestureManager.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/RenderService.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionItem.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/SelectionManager.java

index d6bfa30..efcb930 100644 (file)
@@ -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
index aef29b8..7938f0b 100755 (executable)
@@ -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.
      * <p>
      * 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<CanvasViewInfo> 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<CanvasViewInfo> children = new ArrayList<CanvasViewInfo>(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 <Space>} 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
index 62d5dcd..0c84728 100644 (file)
@@ -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);
index 76a511e..32cc45d 100755 (executable)
@@ -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;
         }
 
index 4b743b4..fc3d7d7 100644 (file)
@@ -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;
index 7b869a5..fcdf79a 100644 (file)
@@ -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.
index aeb05a2..daff906 100644 (file)
@@ -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);
             }
         }