Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Prev Previous commit
Next Next commit
format
  • Loading branch information
Gray Mackall committed Feb 23, 2024
commit 0b23f65275ff5055e9657bcc8e70270394931de9
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,48 @@
* Currently only a subset of the protocol is supported (gravity, x, and y).
*/
class SingleViewFakeWindowViewGroup extends ViewGroup {
// Used in onLayout to keep the bounds of the current view.
// We keep it as a member to avoid object allocations during onLayout which are discouraged.
private final Rect viewBounds;
// Used in onLayout to keep the bounds of the current view.
// We keep it as a member to avoid object allocations during onLayout which are discouraged.
private final Rect viewBounds;

// Used in onLayout to keep the bounds of the child views.
// We keep it as a member to avoid object allocations during onLayout which are discouraged.
private final Rect childRect;
// Used in onLayout to keep the bounds of the child views.
// We keep it as a member to avoid object allocations during onLayout which are discouraged.
private final Rect childRect;

public SingleViewFakeWindowViewGroup(Context context) {
super(context);
viewBounds = new Rect();
childRect = new Rect();
}
public SingleViewFakeWindowViewGroup(Context context) {
super(context);
viewBounds = new Rect();
childRect = new Rect();
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
WindowManager.LayoutParams params = (WindowManager.LayoutParams) child.getLayoutParams();
viewBounds.set(l, t, r, b);
Gravity.apply(
params.gravity,
child.getMeasuredWidth(),
child.getMeasuredHeight(),
viewBounds,
params.x,
params.y,
childRect);
child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
WindowManager.LayoutParams params = (WindowManager.LayoutParams) child.getLayoutParams();
viewBounds.set(l, t, r, b);
Gravity.apply(
params.gravity,
child.getMeasuredWidth(),
child.getMeasuredHeight(),
viewBounds,
params.x,
params.y,
childRect);
child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom);
}
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(atMost(widthMeasureSpec), atMost(heightMeasureSpec));
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(atMost(widthMeasureSpec), atMost(heightMeasureSpec));
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

private static int atMost(int measureSpec) {
return MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(measureSpec), MeasureSpec.AT_MOST);
}
private static int atMost(int measureSpec) {
return MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(measureSpec), MeasureSpec.AT_MOST);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ public PlatformView getView() {
return state.platformView;
}


/** Answers calls for {@link InputMethodManager} with an instance cached at creation time. */
// TODO(mklim): This caches the IMM at construction time and won't pick up any changes. In rare
// cases where the FlutterView changes windows this will return an outdated instance. This
Expand Down Expand Up @@ -317,7 +316,6 @@ private boolean isCalledFromAlertDialog() {
}
}


private static class AccessibilityDelegatingFrameLayout extends FrameLayout {
private final AccessibilityEventsDelegate accessibilityEventsDelegate;
private final View embeddedView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,96 +30,96 @@
*/
@VisibleForTesting
abstract class SingleViewWindowManager implements WindowManager {
private static final String TAG = "PlatformViewsController";
private static final String TAG = "PlatformViewsController";

final WindowManager delegate;
SingleViewFakeWindowViewGroup fakeWindowRootView;
final WindowManager delegate;
SingleViewFakeWindowViewGroup fakeWindowRootView;

SingleViewWindowManager(
WindowManager delegate, SingleViewFakeWindowViewGroup fakeWindowViewGroup) {
this.delegate = delegate;
fakeWindowRootView = fakeWindowViewGroup;
}
SingleViewWindowManager(
WindowManager delegate, SingleViewFakeWindowViewGroup fakeWindowViewGroup) {
this.delegate = delegate;
fakeWindowRootView = fakeWindowViewGroup;
}

@Override
@Deprecated
public Display getDefaultDisplay() {
return delegate.getDefaultDisplay();
}
@Override
@Deprecated
public Display getDefaultDisplay() {
return delegate.getDefaultDisplay();
}

@Override
public void removeViewImmediate(View view) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called removeViewImmediate while detached from presentation");
return;
}
view.clearAnimation();
fakeWindowRootView.removeView(view);
@Override
public void removeViewImmediate(View view) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called removeViewImmediate while detached from presentation");
return;
}
view.clearAnimation();
fakeWindowRootView.removeView(view);
}

@Override
public void addView(View view, ViewGroup.LayoutParams params) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called addView while detached from presentation");
return;
}
fakeWindowRootView.addView(view, params);
@Override
public void addView(View view, ViewGroup.LayoutParams params) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called addView while detached from presentation");
return;
}
fakeWindowRootView.addView(view, params);
}

@Override
public void updateViewLayout(View view, ViewGroup.LayoutParams params) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called updateViewLayout while detached from presentation");
return;
}
fakeWindowRootView.updateViewLayout(view, params);
@Override
public void updateViewLayout(View view, ViewGroup.LayoutParams params) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called updateViewLayout while detached from presentation");
return;
}
fakeWindowRootView.updateViewLayout(view, params);
}

@Override
public void removeView(View view) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called removeView while detached from presentation");
return;
}
fakeWindowRootView.removeView(view);
@Override
public void removeView(View view) {
if (fakeWindowRootView == null) {
Log.w(TAG, "Embedded view called removeView while detached from presentation");
return;
}
fakeWindowRootView.removeView(view);
}

@RequiresApi(api = Build.VERSION_CODES.R)
@NonNull
@Override
public WindowMetrics getCurrentWindowMetrics() {
return delegate.getCurrentWindowMetrics();
}
@RequiresApi(api = Build.VERSION_CODES.R)
@NonNull
@Override
public WindowMetrics getCurrentWindowMetrics() {
return delegate.getCurrentWindowMetrics();
}

@RequiresApi(api = Build.VERSION_CODES.R)
@NonNull
@Override
public WindowMetrics getMaximumWindowMetrics() {
return delegate.getMaximumWindowMetrics();
}
@RequiresApi(api = Build.VERSION_CODES.R)
@NonNull
@Override
public WindowMetrics getMaximumWindowMetrics() {
return delegate.getMaximumWindowMetrics();
}

@RequiresApi(api = Build.VERSION_CODES.S)
@Override
public boolean isCrossWindowBlurEnabled() {
return delegate.isCrossWindowBlurEnabled();
}
@RequiresApi(api = Build.VERSION_CODES.S)
@Override
public boolean isCrossWindowBlurEnabled() {
return delegate.isCrossWindowBlurEnabled();
}

@RequiresApi(api = Build.VERSION_CODES.S)
@Override
public void addCrossWindowBlurEnabledListener(@NonNull Consumer<Boolean> listener) {
delegate.addCrossWindowBlurEnabledListener(listener);
}
@RequiresApi(api = Build.VERSION_CODES.S)
@Override
public void addCrossWindowBlurEnabledListener(@NonNull Consumer<Boolean> listener) {
delegate.addCrossWindowBlurEnabledListener(listener);
}

@RequiresApi(api = Build.VERSION_CODES.S)
@Override
public void addCrossWindowBlurEnabledListener(
@NonNull Executor executor, @NonNull Consumer<Boolean> listener) {
delegate.addCrossWindowBlurEnabledListener(executor, listener);
}
@RequiresApi(api = Build.VERSION_CODES.S)
@Override
public void addCrossWindowBlurEnabledListener(
@NonNull Executor executor, @NonNull Consumer<Boolean> listener) {
delegate.addCrossWindowBlurEnabledListener(executor, listener);
}

@RequiresApi(api = Build.VERSION_CODES.S)
@Override
public void removeCrossWindowBlurEnabledListener(@NonNull Consumer<Boolean> listener) {
delegate.removeCrossWindowBlurEnabledListener(listener);
}
@RequiresApi(api = Build.VERSION_CODES.S)
@Override
public void removeCrossWindowBlurEnabledListener(@NonNull Consumer<Boolean> listener) {
delegate.removeCrossWindowBlurEnabledListener(listener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/** Default implementation when using the regular Android SDK. */
final class WindowManagerHandler extends SingleViewWindowManager {

WindowManagerHandler(WindowManager delegate, SingleViewFakeWindowViewGroup fakeWindowViewGroup) {
super(delegate, fakeWindowViewGroup);
}
WindowManagerHandler(WindowManager delegate, SingleViewFakeWindowViewGroup fakeWindowViewGroup) {
super(delegate, fakeWindowViewGroup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ public void windowManagerHandler_logAndReturnEarly_whenFakeWindowViewGroupIsNull
View mockView = mock(View.class);
ViewGroup.LayoutParams mockLayoutParams = mock(ViewGroup.LayoutParams.class);

WindowManagerHandler windowManagerHandler =
new WindowManagerHandler(mockWindowManager, null);
WindowManagerHandler windowManagerHandler = new WindowManagerHandler(mockWindowManager, null);

// removeViewImmediate
windowManagerHandler.removeViewImmediate(mockView);
Expand Down