Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SingleViewFakeWindowViewGroup.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package io.flutter.plugin.platform;
6
7import android.content.Context;
8import android.graphics.Rect;
9import android.view.Gravity;
10import android.view.View;
11import android.view.ViewGroup;
12import android.view.WindowManager;
13
14/*
15 * A view group that implements the same layout protocol that exist between the WindowManager and its direct
16 * children.
17 *
18 * Currently only a subset of the protocol is supported (gravity, x, and y).
19 */
20class SingleViewFakeWindowViewGroup extends ViewGroup {
21 // Used in onLayout to keep the bounds of the current view.
22 // We keep it as a member to avoid object allocations during onLayout which are discouraged.
23 private final Rect viewBounds;
24
25 // Used in onLayout to keep the bounds of the child views.
26 // We keep it as a member to avoid object allocations during onLayout which are discouraged.
27 private final Rect childRect;
28
30 super(context);
31 viewBounds = new Rect();
32 childRect = new Rect();
33 }
34
35 @Override
36 protected void onLayout(boolean changed, int l, int t, int r, int b) {
37 for (int i = 0; i < getChildCount(); i++) {
38 View child = getChildAt(i);
39 WindowManager.LayoutParams params = (WindowManager.LayoutParams) child.getLayoutParams();
40 viewBounds.set(l, t, r, b);
41 Gravity.apply(
42 params.gravity,
43 child.getMeasuredWidth(),
44 child.getMeasuredHeight(),
45 viewBounds,
46 params.x,
47 params.y,
48 childRect);
49 child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom);
50 }
51 }
52
53 @Override
54 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
55 for (int i = 0; i < getChildCount(); i++) {
56 View child = getChildAt(i);
57 child.measure(atMost(widthMeasureSpec), atMost(heightMeasureSpec));
58 }
59 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
60 }
61
62 private static int atMost(int measureSpec) {
63 return MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(measureSpec), MeasureSpec.AT_MOST);
64 }
65}
void onLayout(boolean changed, int l, int t, int r, int b)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
const EmbeddedViewParams * params
static bool b