| 1 |
/* |
| 2 |
* Copyright (C) 2010 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 |
| 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 |
|
| 17 |
package com.android.ide.common.rendering.api; |
| 18 |
|
| 19 |
import java.util.Collections; |
| 20 |
import java.util.List; |
| 21 |
|
| 22 |
/** |
| 23 |
* Layout information for a specific view object |
| 24 |
*/ |
| 25 |
public class ViewInfo { |
| 26 |
|
| 27 |
private final Object mCookie; |
| 28 |
private final String mName; |
| 29 |
private final int mLeft; |
| 30 |
private final int mRight; |
| 31 |
private final int mTop; |
| 32 |
private final int mBottom; |
| 33 |
private List<ViewInfo> mChildren = Collections.emptyList(); |
| 34 |
private final Object mViewObject; |
| 35 |
private final Object mLayoutParamsObject; |
| 36 |
|
| 37 |
// optional info |
| 38 |
private int mBaseLine = Integer.MIN_VALUE; |
| 39 |
private int mLeftMargin = Integer.MIN_VALUE; |
| 40 |
private int mTopMargin = Integer.MIN_VALUE; |
| 41 |
private int mRightMargin = Integer.MIN_VALUE; |
| 42 |
private int mBottomMargin = Integer.MIN_VALUE; |
| 43 |
|
| 44 |
public ViewInfo(String name, Object cookie, int left, int top, int right, int bottom) { |
| 45 |
this(name, cookie, left, top, right, bottom, null /*viewObject*/, |
| 46 |
null /*layoutParamsObject*/); |
| 47 |
} |
| 48 |
|
| 49 |
public ViewInfo(String name, Object cookie, int left, int top, int right, int bottom, |
| 50 |
Object viewObject, Object layoutParamsObject) { |
| 51 |
mName = name; |
| 52 |
mCookie = cookie; |
| 53 |
mLeft = left; |
| 54 |
mRight = right; |
| 55 |
mTop = top; |
| 56 |
mBottom = bottom; |
| 57 |
mViewObject = viewObject; |
| 58 |
mLayoutParamsObject = layoutParamsObject; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Sets the list of children {@link ViewInfo}. |
| 63 |
*/ |
| 64 |
public void setChildren(List<ViewInfo> children) { |
| 65 |
if (children != null) { |
| 66 |
mChildren = Collections.unmodifiableList(children); |
| 67 |
} else { |
| 68 |
mChildren = Collections.emptyList(); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
public void setExtendedInfo(int baseLine, int leftMargin, int topMargin, |
| 73 |
int rightMargin, int bottomMargin) { |
| 74 |
mBaseLine = baseLine; |
| 75 |
mLeftMargin = leftMargin; |
| 76 |
mTopMargin = topMargin; |
| 77 |
mRightMargin = rightMargin; |
| 78 |
mBottomMargin = bottomMargin; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Returns the list of children views. This is never null, but can be empty. |
| 83 |
*/ |
| 84 |
public List<ViewInfo> getChildren() { |
| 85 |
return mChildren; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Returns the cookie associated with the XML node. Can be null. |
| 90 |
* |
| 91 |
* @see ILayoutPullParser#getViewCookie() |
| 92 |
*/ |
| 93 |
public Object getCookie() { |
| 94 |
return mCookie; |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Returns the class name of the view object. Can be null. |
| 99 |
*/ |
| 100 |
public String getClassName() { |
| 101 |
return mName; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Returns the left of the view bounds, relative to the view parent bounds. |
| 106 |
*/ |
| 107 |
public int getLeft() { |
| 108 |
return mLeft; |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Returns the top of the view bounds, relative to the view parent bounds. |
| 113 |
*/ |
| 114 |
public int getTop() { |
| 115 |
return mTop; |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Returns the right of the view bounds, relative to the view parent bounds. |
| 120 |
*/ |
| 121 |
public int getRight() { |
| 122 |
return mRight; |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Returns the bottom of the view bounds, relative to the view parent bounds. |
| 127 |
*/ |
| 128 |
public int getBottom() { |
| 129 |
return mBottom; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Returns the actual android.view.View (or child class) object. This can be used to query the |
| 134 |
* object properties that are not in the XML and not available through |
| 135 |
* {@link RenderSession#getProperty(Object, String)}. |
| 136 |
*/ |
| 137 |
public Object getViewObject() { |
| 138 |
return mViewObject; |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Returns the actual android.view.ViewGroup$LayoutParams (or child class) object. This can be |
| 143 |
* used to query the object properties that are not in the XML and not available through |
| 144 |
* {@link RenderSession#getProperty(Object, String)}. |
| 145 |
*/ |
| 146 |
public Object getLayoutParamsObject() { |
| 147 |
return mLayoutParamsObject; |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Returns the baseline value. If the value is unknown, returns {@link Integer#MIN_VALUE}. |
| 152 |
*/ |
| 153 |
public int getBaseLine() { |
| 154 |
return mBaseLine; |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Returns the left margin value. If the value is unknown, returns {@link Integer#MIN_VALUE}. |
| 159 |
*/ |
| 160 |
public int getLeftMargin() { |
| 161 |
return mLeftMargin; |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Returns the top margin value. If the value is unknown, returns {@link Integer#MIN_VALUE}. |
| 166 |
*/ |
| 167 |
public int getTopMargin() { |
| 168 |
return mTopMargin; |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Returns the right margin value. If the value is unknown, returns {@link Integer#MIN_VALUE}. |
| 173 |
*/ |
| 174 |
public int getRightMargin() { |
| 175 |
return mRightMargin; |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* Returns the bottom margin value. If the value is unknown, returns {@link Integer#MIN_VALUE}. |
| 180 |
*/ |
| 181 |
public int getBottomMargin() { |
| 182 |
return mBottomMargin; |
| 183 |
} |
| 184 |
|
| 185 |
/** |
| 186 |
* Returns the type of View. |
| 187 |
* |
| 188 |
* @see ViewType |
| 189 |
*/ |
| 190 |
public ViewType getViewType() { |
| 191 |
return ViewType.USER; |
| 192 |
} |
| 193 |
|
| 194 |
@Override |
| 195 |
public String toString() { |
| 196 |
return String.valueOf(mName); |
| 197 |
} |
| 198 |
} |