Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5becc487 authored by Diego Perez's avatar Diego Perez Committed by Android (Google) Code Review
Browse files

Merge "Call onApplyWindowInsets after requestApplyWindowInsets"

parents c70ca2d8 b076ee1a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -51,4 +51,8 @@ public class AttachInfo_Accessor {
            view.dispatchDetachedFromWindow();
        }
    }

    public static ViewRootImpl getRootView(View view) {
        return view.mAttachInfo != null ? view.mAttachInfo.mViewRootImpl : null;
    }
}
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view;

/**
 * Accessor to allow layoutlib to call {@link ViewRootImpl#dispatchApplyInsets} directly.
 */
public class ViewRootImpl_Accessor {
    public static void dispatchApplyInsets(ViewRootImpl viewRoot, View host) {
        viewRoot.dispatchApplyInsets(host);
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -38,7 +38,10 @@ import android.annotation.NonNull;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.AttachInfo_Accessor;
import android.view.View;
import android.view.ViewRootImpl;
import android.view.ViewRootImpl_Accessor;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
@@ -302,6 +305,17 @@ class Layout extends RelativeLayout {
        return Bridge.getResourceId(ResourceType.ID, ID_PREFIX + name);
    }

    @Override
    public void requestFitSystemWindows() {
        // The framework call would usually bubble up to ViewRootImpl but, in layoutlib, Layout will
        // act as view root for most purposes. That way, we can also save going through the Handler
        // to dispatch the new applied insets.
        ViewRootImpl root = AttachInfo_Accessor.getRootView(this);
        if (root != null) {
            ViewRootImpl_Accessor.dispatchApplyInsets(root, this);
        }
    }

    /**
     * A helper class to help initialize the Layout.
     */
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.layoutlib.test.myapplication.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.WindowInsets;
import android.widget.TextView;

public class InsetsWidget extends TextView {
    public static boolean sApplyInsetsCalled = false;

    public InsetsWidget(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();

        requestApplyInsets();
    }

    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        sApplyInsetsCalled = true;
        return super.onApplyWindowInsets(insets);
    }
}
+12 −0
Original line number Diff line number Diff line
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:padding="16dp"
              android:orientation="horizontal"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">

    <com.android.layoutlib.test.myapplication.widgets.InsetsWidget
        android:text="Hello world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/text1"/>
</LinearLayout>
Loading