1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.ide.common.layout; 17 18 import static com.android.SdkConstants.FQCN_TABLE_LAYOUT; 19 20 import com.android.annotations.NonNull; 21 import com.android.annotations.Nullable; 22 import com.android.ide.common.api.DropFeedback; 23 import com.android.ide.common.api.INode; 24 import com.android.ide.common.api.IViewRule; 25 import com.android.ide.common.api.InsertType; 26 import com.android.ide.common.api.RuleAction; 27 import com.android.ide.common.api.SegmentType; 28 29 import java.util.List; 30 31 /** 32 * An {@link IViewRule} for android.widget.TableRow. 33 */ 34 public class TableRowRule extends LinearLayoutRule { 35 @Override isVertical(INode node)36 protected boolean isVertical(INode node) { 37 return false; 38 } 39 40 @Override supportsOrientation()41 protected boolean supportsOrientation() { 42 return false; 43 } 44 45 @Override onChildInserted(@onNull INode child, @NonNull INode parent, @NonNull InsertType insertType)46 public void onChildInserted(@NonNull INode child, @NonNull INode parent, 47 @NonNull InsertType insertType) { 48 // Overridden to inhibit the setting of layout_width/layout_height since 49 // the table row will enforce match_parent and wrap_content for width and height 50 // respectively. 51 } 52 53 @Override addLayoutActions( @onNull List<RuleAction> actions, final @NonNull INode parentNode, final @NonNull List<? extends INode> children)54 public void addLayoutActions( 55 @NonNull List<RuleAction> actions, 56 final @NonNull INode parentNode, 57 final @NonNull List<? extends INode> children) { 58 super.addLayoutActions(actions, parentNode, children); 59 60 // Also apply table-specific actions on the table row such that you can 61 // select something in a table row and still get offered actions on the surrounding 62 // table. 63 if (children != null) { 64 INode grandParent = parentNode.getParent(); 65 if (grandParent != null && grandParent.getFqcn().equals(FQCN_TABLE_LAYOUT)) { 66 TableLayoutRule.addTableLayoutActions(mRulesEngine, actions, grandParent, 67 children); 68 } 69 } 70 } 71 72 @Override onResizeBegin(@onNull INode child, @NonNull INode parent, @Nullable SegmentType horizontalEdge, @Nullable SegmentType verticalEdge, @Nullable Object childView, @Nullable Object parentView)73 public DropFeedback onResizeBegin(@NonNull INode child, @NonNull INode parent, 74 @Nullable SegmentType horizontalEdge, @Nullable SegmentType verticalEdge, 75 @Nullable Object childView, @Nullable Object parentView) { 76 // No resizing in TableRows; the width is *always* match_parent and the height is 77 // *always* wrap_content. 78 return null; 79 } 80 } 81