blob: fe8916bf076117605547680afa161786ac31f8f0 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 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
17package android.widget;
18
Fabrice Di Megliode35cee2011-06-01 15:13:50 -070019import java.util.ArrayList;
20
Alan Viverette96ccd392015-01-30 15:55:48 -080021import android.annotation.NonNull;
Alan Viverette91174362014-06-17 14:51:45 -070022import android.annotation.Nullable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
Chet Haase4610eef2015-12-03 07:38:11 -080024import android.content.res.ColorStateList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.res.TypedArray;
Chet Haase4610eef2015-12-03 07:38:11 -080026import android.graphics.Canvas;
27import android.graphics.PorterDuff;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.graphics.Rect;
Chet Haase4610eef2015-12-03 07:38:11 -080029import android.graphics.Region;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.graphics.drawable.Drawable;
31import android.util.AttributeSet;
Fabrice Di Megliode35cee2011-06-01 15:13:50 -070032import android.view.Gravity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.view.View;
Dianne Hackborn958b9ad2009-03-31 18:00:36 -070034import android.view.ViewDebug;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import android.view.ViewGroup;
Siva Velusamy94a6d152015-05-05 15:07:00 -070036import android.view.ViewHierarchyEncoder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.widget.RemoteViews.RemoteView;
38
Chet Haase4610eef2015-12-03 07:38:11 -080039import com.android.internal.R;
40
41
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042/**
43 * FrameLayout is designed to block out an area on the screen to display
Scott Main812634c22011-07-27 13:22:35 -070044 * a single item. Generally, FrameLayout should be used to hold a single child view, because it can
45 * be difficult to organize child views in a way that's scalable to different screen sizes without
46 * the children overlapping each other. You can, however, add multiple children to a FrameLayout
47 * and control their position within the FrameLayout by assigning gravity to each child, using the
48 * <a href="FrameLayout.LayoutParams.html#attr_android:layout_gravity">{@code
49 * android:layout_gravity}</a> attribute.
50 * <p>Child views are drawn in a stack, with the most recently added child on top.
51 * The size of the FrameLayout is the size of its largest child (plus padding), visible
52 * or not (if the FrameLayout's parent permits). Views that are {@link android.view.View#GONE} are
53 * used for sizing
54 * only if {@link #setMeasureAllChildren(boolean) setConsiderGoneChildrenWhenMeasuring()}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 * is set to true.
56 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 * @attr ref android.R.styleable#FrameLayout_measureAllChildren
58 */
59@RemoteView
60public class FrameLayout extends ViewGroup {
Fabrice Di Meglioaac0d4e2012-07-19 19:21:26 -070061 private static final int DEFAULT_CHILD_GRAVITY = Gravity.TOP | Gravity.START;
Romain Guy9c957372011-01-04 17:39:43 -080062
Konstantin Lopyrevbea95162010-08-10 17:02:18 -070063 @ViewDebug.ExportedProperty(category = "measurement")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 boolean mMeasureAllChildren = false;
65
Konstantin Lopyrevbea95162010-08-10 17:02:18 -070066 @ViewDebug.ExportedProperty(category = "padding")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 private int mForegroundPaddingLeft = 0;
Konstantin Lopyrevbea95162010-08-10 17:02:18 -070068
69 @ViewDebug.ExportedProperty(category = "padding")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 private int mForegroundPaddingTop = 0;
Konstantin Lopyrevbea95162010-08-10 17:02:18 -070071
72 @ViewDebug.ExportedProperty(category = "padding")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 private int mForegroundPaddingRight = 0;
Konstantin Lopyrevbea95162010-08-10 17:02:18 -070074
75 @ViewDebug.ExportedProperty(category = "padding")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 private int mForegroundPaddingBottom = 0;
77
78 private final Rect mSelfBounds = new Rect();
79 private final Rect mOverlayBounds = new Rect();
Dianne Hackborn958b9ad2009-03-31 18:00:36 -070080
Romain Guy9c957372011-01-04 17:39:43 -080081 private final ArrayList<View> mMatchParentChildren = new ArrayList<View>(1);
82
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 public FrameLayout(Context context) {
84 super(context);
85 }
86
Scott Kennedyed2b5f82015-03-06 17:24:58 -080087 public FrameLayout(Context context, @Nullable AttributeSet attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 this(context, attrs, 0);
89 }
90
Scott Kennedyed2b5f82015-03-06 17:24:58 -080091 public FrameLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
Alan Viverette617feb92013-09-09 18:09:13 -070092 this(context, attrs, defStyleAttr, 0);
93 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094
Scott Kennedyed2b5f82015-03-06 17:24:58 -080095 public FrameLayout(
96 Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
Alan Viverette617feb92013-09-09 18:09:13 -070097 super(context, attrs, defStyleAttr, defStyleRes);
98
99 final TypedArray a = context.obtainStyledAttributes(
100 attrs, com.android.internal.R.styleable.FrameLayout, defStyleAttr, defStyleRes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101
102 if (a.getBoolean(com.android.internal.R.styleable.FrameLayout_measureAllChildren, false)) {
103 setMeasureAllChildren(true);
104 }
105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 a.recycle();
Philip Milne1018fb42012-03-13 12:00:04 -0700107 }
108
109 /**
Fabrice Di Meglio9e3b0022011-06-06 16:30:29 -0700110 * Describes how the foreground is positioned. Defaults to START and TOP.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 *
112 * @param foregroundGravity See {@link android.view.Gravity}
113 *
Philip Milne1018fb42012-03-13 12:00:04 -0700114 * @see #getForegroundGravity()
115 *
Adam Powell2b25e2e2015-03-23 16:33:32 -0700116 * @attr ref android.R.styleable#View_foregroundGravity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 */
118 @android.view.RemotableViewMethod
119 public void setForegroundGravity(int foregroundGravity) {
Adam Powell2b25e2e2015-03-23 16:33:32 -0700120 if (getForegroundGravity() != foregroundGravity) {
121 super.setForegroundGravity(foregroundGravity);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122
Adam Powell2b25e2e2015-03-23 16:33:32 -0700123 // calling get* again here because the set above may apply default constraints
124 final Drawable foreground = getForeground();
125 if (getForegroundGravity() == Gravity.FILL && foreground != null) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700126 Rect padding = new Rect();
Adam Powell2b25e2e2015-03-23 16:33:32 -0700127 if (foreground.getPadding(padding)) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700128 mForegroundPaddingLeft = padding.left;
129 mForegroundPaddingTop = padding.top;
130 mForegroundPaddingRight = padding.right;
131 mForegroundPaddingBottom = padding.bottom;
132 }
133 } else {
134 mForegroundPaddingLeft = 0;
135 mForegroundPaddingTop = 0;
136 mForegroundPaddingRight = 0;
137 mForegroundPaddingBottom = 0;
138 }
139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 requestLayout();
141 }
142 }
143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 /**
145 * Returns a set of layout parameters with a width of
Romain Guy980a9382010-01-08 15:06:28 -0800146 * {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT},
147 * and a height of {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 */
149 @Override
150 protected LayoutParams generateDefaultLayoutParams() {
Romain Guy980a9382010-01-08 15:06:28 -0800151 return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 }
153
Fabrice Di Meglioc4d71222013-06-11 19:13:54 -0700154 int getPaddingLeftWithForeground() {
Adam Powell2b25e2e2015-03-23 16:33:32 -0700155 return isForegroundInsidePadding() ? Math.max(mPaddingLeft, mForegroundPaddingLeft) :
Michael Jurka02473da2011-09-08 18:26:23 -0700156 mPaddingLeft + mForegroundPaddingLeft;
157 }
158
Fabrice Di Meglioc4d71222013-06-11 19:13:54 -0700159 int getPaddingRightWithForeground() {
Adam Powell2b25e2e2015-03-23 16:33:32 -0700160 return isForegroundInsidePadding() ? Math.max(mPaddingRight, mForegroundPaddingRight) :
Michael Jurka02473da2011-09-08 18:26:23 -0700161 mPaddingRight + mForegroundPaddingRight;
162 }
163
164 private int getPaddingTopWithForeground() {
Adam Powell2b25e2e2015-03-23 16:33:32 -0700165 return isForegroundInsidePadding() ? Math.max(mPaddingTop, mForegroundPaddingTop) :
Michael Jurka02473da2011-09-08 18:26:23 -0700166 mPaddingTop + mForegroundPaddingTop;
167 }
168
169 private int getPaddingBottomWithForeground() {
Adam Powell2b25e2e2015-03-23 16:33:32 -0700170 return isForegroundInsidePadding() ? Math.max(mPaddingBottom, mForegroundPaddingBottom) :
Michael Jurka02473da2011-09-08 18:26:23 -0700171 mPaddingBottom + mForegroundPaddingBottom;
172 }
173
174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 /**
176 * {@inheritDoc}
177 */
178 @Override
179 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Romain Guy9c957372011-01-04 17:39:43 -0800180 int count = getChildCount();
181
182 final boolean measureMatchParentChildren =
183 MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY ||
184 MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY;
185 mMatchParentChildren.clear();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186
187 int maxHeight = 0;
188 int maxWidth = 0;
Dianne Hackborn189ee182010-12-02 21:48:53 -0800189 int childState = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 for (int i = 0; i < count; i++) {
192 final View child = getChildAt(i);
193 if (mMeasureAllChildren || child.getVisibility() != GONE) {
194 measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
Adam Powell2b6be702011-01-08 16:44:07 -0800195 final LayoutParams lp = (LayoutParams) child.getLayoutParams();
196 maxWidth = Math.max(maxWidth,
197 child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
198 maxHeight = Math.max(maxHeight,
199 child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
Dianne Hackborn189ee182010-12-02 21:48:53 -0800200 childState = combineMeasuredStates(childState, child.getMeasuredState());
Romain Guy9c957372011-01-04 17:39:43 -0800201 if (measureMatchParentChildren) {
Romain Guy9c957372011-01-04 17:39:43 -0800202 if (lp.width == LayoutParams.MATCH_PARENT ||
203 lp.height == LayoutParams.MATCH_PARENT) {
204 mMatchParentChildren.add(child);
205 }
206 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 }
208 }
209
210 // Account for padding too
Michael Jurka02473da2011-09-08 18:26:23 -0700211 maxWidth += getPaddingLeftWithForeground() + getPaddingRightWithForeground();
212 maxHeight += getPaddingTopWithForeground() + getPaddingBottomWithForeground();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213
214 // Check against our minimum height and width
215 maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
216 maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
217
218 // Check against our foreground's minimum height and width
219 final Drawable drawable = getForeground();
220 if (drawable != null) {
221 maxHeight = Math.max(maxHeight, drawable.getMinimumHeight());
222 maxWidth = Math.max(maxWidth, drawable.getMinimumWidth());
223 }
224
Dianne Hackborn189ee182010-12-02 21:48:53 -0800225 setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
226 resolveSizeAndState(maxHeight, heightMeasureSpec,
Romain Guy9c957372011-01-04 17:39:43 -0800227 childState << MEASURED_HEIGHT_STATE_SHIFT));
228
Romain Guya174d7a2011-01-07 13:27:39 -0800229 count = mMatchParentChildren.size();
230 if (count > 1) {
Romain Guy9c957372011-01-04 17:39:43 -0800231 for (int i = 0; i < count; i++) {
232 final View child = mMatchParentChildren.get(i);
Romain Guy9c957372011-01-04 17:39:43 -0800233 final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
Alan Viverette39fd9022015-06-25 12:24:27 -0700234
235 final int childWidthMeasureSpec;
Romain Guy9c957372011-01-04 17:39:43 -0800236 if (lp.width == LayoutParams.MATCH_PARENT) {
Alan Viverette39fd9022015-06-25 12:24:27 -0700237 final int width = Math.max(0, getMeasuredWidth()
238 - getPaddingLeftWithForeground() - getPaddingRightWithForeground()
239 - lp.leftMargin - lp.rightMargin);
240 childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(
241 width, MeasureSpec.EXACTLY);
Romain Guy9c957372011-01-04 17:39:43 -0800242 } else {
243 childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
Michael Jurka02473da2011-09-08 18:26:23 -0700244 getPaddingLeftWithForeground() + getPaddingRightWithForeground() +
245 lp.leftMargin + lp.rightMargin,
Romain Guy9c957372011-01-04 17:39:43 -0800246 lp.width);
247 }
Alan Viverette39fd9022015-06-25 12:24:27 -0700248
249 final int childHeightMeasureSpec;
Romain Guy9c957372011-01-04 17:39:43 -0800250 if (lp.height == LayoutParams.MATCH_PARENT) {
Alan Viverette39fd9022015-06-25 12:24:27 -0700251 final int height = Math.max(0, getMeasuredHeight()
252 - getPaddingTopWithForeground() - getPaddingBottomWithForeground()
253 - lp.topMargin - lp.bottomMargin);
254 childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(
255 height, MeasureSpec.EXACTLY);
Romain Guy9c957372011-01-04 17:39:43 -0800256 } else {
Romain Guycf70dcb2011-01-07 11:03:20 -0800257 childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec,
Michael Jurka02473da2011-09-08 18:26:23 -0700258 getPaddingTopWithForeground() + getPaddingBottomWithForeground() +
259 lp.topMargin + lp.bottomMargin,
Romain Guy9c957372011-01-04 17:39:43 -0800260 lp.height);
261 }
262
263 child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
264 }
265 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 }
267
268 /**
269 * {@inheritDoc}
270 */
271 @Override
272 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Fabrice Di Meglioc4d71222013-06-11 19:13:54 -0700273 layoutChildren(left, top, right, bottom, false /* no force left gravity */);
274 }
275
276 void layoutChildren(int left, int top, int right, int bottom,
277 boolean forceLeftGravity) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 final int count = getChildCount();
279
Michael Jurka02473da2011-09-08 18:26:23 -0700280 final int parentLeft = getPaddingLeftWithForeground();
281 final int parentRight = right - left - getPaddingRightWithForeground();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282
Michael Jurka02473da2011-09-08 18:26:23 -0700283 final int parentTop = getPaddingTopWithForeground();
284 final int parentBottom = bottom - top - getPaddingBottomWithForeground();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285
286 for (int i = 0; i < count; i++) {
287 final View child = getChildAt(i);
288 if (child.getVisibility() != GONE) {
289 final LayoutParams lp = (LayoutParams) child.getLayoutParams();
290
291 final int width = child.getMeasuredWidth();
292 final int height = child.getMeasuredHeight();
293
Romain Guy9c957372011-01-04 17:39:43 -0800294 int childLeft;
295 int childTop;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296
Adam Powell5e0ae672010-12-06 21:33:04 -0800297 int gravity = lp.gravity;
298 if (gravity == -1) {
299 gravity = DEFAULT_CHILD_GRAVITY;
300 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301
Fabrice Di Meglioe56ffdc2012-09-23 14:51:16 -0700302 final int layoutDirection = getLayoutDirection();
Fabrice Di Meglioc0053222011-06-13 12:16:51 -0700303 final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
Adam Powell5e0ae672010-12-06 21:33:04 -0800304 final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305
Fabrice Di Megliode35cee2011-06-01 15:13:50 -0700306 switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
Adam Powell5e0ae672010-12-06 21:33:04 -0800307 case Gravity.CENTER_HORIZONTAL:
308 childLeft = parentLeft + (parentRight - parentLeft - width) / 2 +
309 lp.leftMargin - lp.rightMargin;
310 break;
311 case Gravity.RIGHT:
Fabrice Di Meglioc4d71222013-06-11 19:13:54 -0700312 if (!forceLeftGravity) {
313 childLeft = parentRight - width - lp.rightMargin;
314 break;
315 }
316 case Gravity.LEFT:
Adam Powell5e0ae672010-12-06 21:33:04 -0800317 default:
318 childLeft = parentLeft + lp.leftMargin;
319 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320
Adam Powell5e0ae672010-12-06 21:33:04 -0800321 switch (verticalGravity) {
322 case Gravity.TOP:
323 childTop = parentTop + lp.topMargin;
324 break;
325 case Gravity.CENTER_VERTICAL:
326 childTop = parentTop + (parentBottom - parentTop - height) / 2 +
327 lp.topMargin - lp.bottomMargin;
328 break;
329 case Gravity.BOTTOM:
330 childTop = parentBottom - height - lp.bottomMargin;
331 break;
332 default:
333 childTop = parentTop + lp.topMargin;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 }
335
336 child.layout(childLeft, childTop, childLeft + width, childTop + height);
337 }
338 }
339 }
340
341 /**
Steve Blockb25825a2011-04-27 14:51:38 +0100342 * Sets whether to consider all children, or just those in
343 * the VISIBLE or INVISIBLE state, when measuring. Defaults to false.
344 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 * @param measureAll true to consider children marked GONE, false otherwise.
346 * Default value is false.
Steve Blockb25825a2011-04-27 14:51:38 +0100347 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800348 * @attr ref android.R.styleable#FrameLayout_measureAllChildren
349 */
350 @android.view.RemotableViewMethod
351 public void setMeasureAllChildren(boolean measureAll) {
352 mMeasureAllChildren = measureAll;
353 }
Steve Blockb25825a2011-04-27 14:51:38 +0100354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 /**
Steve Blockb25825a2011-04-27 14:51:38 +0100356 * Determines whether all children, or just those in the VISIBLE or
357 * INVISIBLE state, are considered when measuring.
358 *
359 * @return Whether all children are considered when measuring.
360 *
361 * @deprecated This method is deprecated in favor of
362 * {@link #getMeasureAllChildren() getMeasureAllChildren()}, which was
363 * renamed for consistency with
364 * {@link #setMeasureAllChildren(boolean) setMeasureAllChildren()}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 */
Steve Blockb25825a2011-04-27 14:51:38 +0100366 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 public boolean getConsiderGoneChildrenWhenMeasuring() {
Steve Blockb25825a2011-04-27 14:51:38 +0100368 return getMeasureAllChildren();
369 }
370
371 /**
372 * Determines whether all children, or just those in the VISIBLE or
373 * INVISIBLE state, are considered when measuring.
374 *
375 * @return Whether all children are considered when measuring.
376 */
377 public boolean getMeasureAllChildren() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 return mMeasureAllChildren;
379 }
380
381 /**
382 * {@inheritDoc}
383 */
384 @Override
385 public LayoutParams generateLayoutParams(AttributeSet attrs) {
386 return new FrameLayout.LayoutParams(getContext(), attrs);
387 }
388
Patrick Dubroye0a799a2011-05-04 16:19:22 -0700389 @Override
390 public boolean shouldDelayChildPressedState() {
391 return false;
392 }
393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394 /**
395 * {@inheritDoc}
396 */
397 @Override
398 protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
399 return p instanceof LayoutParams;
400 }
401
402 @Override
Yigit Boyar885c50b2016-03-22 16:53:42 -0700403 protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp) {
404 if (lp instanceof LayoutParams) {
405 return new LayoutParams((LayoutParams) lp);
406 } else if (lp instanceof MarginLayoutParams) {
407 return new LayoutParams((MarginLayoutParams) lp);
408 } else {
409 return new LayoutParams(lp);
410 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 }
412
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -0800413 @Override
Dianne Hackborna7bb6fb2015-02-03 18:13:40 -0800414 public CharSequence getAccessibilityClassName() {
415 return FrameLayout.class.getName();
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -0800416 }
417
Siva Velusamy94a6d152015-05-05 15:07:00 -0700418 /** @hide */
419 @Override
420 protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) {
421 super.encodeProperties(encoder);
422
423 encoder.addProperty("measurement:measureAllChildren", mMeasureAllChildren);
424 encoder.addProperty("padding:foregroundPaddingLeft", mForegroundPaddingLeft);
425 encoder.addProperty("padding:foregroundPaddingTop", mForegroundPaddingTop);
426 encoder.addProperty("padding:foregroundPaddingRight", mForegroundPaddingRight);
427 encoder.addProperty("padding:foregroundPaddingBottom", mForegroundPaddingBottom);
428 }
429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 /**
431 * Per-child layout information for layouts that support margins.
432 * See {@link android.R.styleable#FrameLayout_Layout FrameLayout Layout Attributes}
433 * for a list of all child view attributes that this class supports.
Romain Guy606e8cc2010-08-17 12:43:05 -0700434 *
435 * @attr ref android.R.styleable#FrameLayout_Layout_layout_gravity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 */
437 public static class LayoutParams extends MarginLayoutParams {
438 /**
439 * The gravity to apply with the View to which these layout parameters
440 * are associated.
441 *
442 * @see android.view.Gravity
Romain Guy606e8cc2010-08-17 12:43:05 -0700443 *
444 * @attr ref android.R.styleable#FrameLayout_Layout_layout_gravity
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 */
446 public int gravity = -1;
447
448 /**
449 * {@inheritDoc}
450 */
451 public LayoutParams(Context c, AttributeSet attrs) {
452 super(c, attrs);
453
454 TypedArray a = c.obtainStyledAttributes(attrs, com.android.internal.R.styleable.FrameLayout_Layout);
455 gravity = a.getInt(com.android.internal.R.styleable.FrameLayout_Layout_layout_gravity, -1);
456 a.recycle();
457 }
458
459 /**
460 * {@inheritDoc}
461 */
462 public LayoutParams(int width, int height) {
463 super(width, height);
464 }
465
466 /**
467 * Creates a new set of layout parameters with the specified width, height
468 * and weight.
469 *
Romain Guy980a9382010-01-08 15:06:28 -0800470 * @param width the width, either {@link #MATCH_PARENT},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 * {@link #WRAP_CONTENT} or a fixed size in pixels
Romain Guy980a9382010-01-08 15:06:28 -0800472 * @param height the height, either {@link #MATCH_PARENT},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 * {@link #WRAP_CONTENT} or a fixed size in pixels
474 * @param gravity the gravity
475 *
476 * @see android.view.Gravity
477 */
478 public LayoutParams(int width, int height, int gravity) {
479 super(width, height);
480 this.gravity = gravity;
481 }
482
483 /**
484 * {@inheritDoc}
485 */
486 public LayoutParams(ViewGroup.LayoutParams source) {
487 super(source);
488 }
489
490 /**
491 * {@inheritDoc}
492 */
493 public LayoutParams(ViewGroup.MarginLayoutParams source) {
494 super(source);
495 }
Alan Viverette0a0e1552013-08-07 13:24:09 -0700496
497 /**
498 * Copy constructor. Clones the width, height, margin values, and
499 * gravity of the source.
500 *
501 * @param source The layout params to copy from.
502 */
503 public LayoutParams(LayoutParams source) {
504 super(source);
505
506 this.gravity = source.gravity;
507 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 }
509}