Loading tools/layoutlib/bridge/src/android/view/AttachInfo_Accessor.java +4 −0 Original line number Diff line number Diff line Loading @@ -51,4 +51,8 @@ public class AttachInfo_Accessor { view.dispatchDetachedFromWindow(); } } public static ViewRootImpl getRootView(View view) { return view.mAttachInfo != null ? view.mAttachInfo.mViewRootImpl : null; } } tools/layoutlib/bridge/src/android/view/ViewRootImpl_Accessor.java 0 → 100644 +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); } } tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Layout.java +14 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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. */ Loading tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/myapplication.widgets/InsetsWidget.java 0 → 100644 +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); } } tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/insets.xml 0 → 100644 +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
tools/layoutlib/bridge/src/android/view/AttachInfo_Accessor.java +4 −0 Original line number Diff line number Diff line Loading @@ -51,4 +51,8 @@ public class AttachInfo_Accessor { view.dispatchDetachedFromWindow(); } } public static ViewRootImpl getRootView(View view) { return view.mAttachInfo != null ? view.mAttachInfo.mViewRootImpl : null; } }
tools/layoutlib/bridge/src/android/view/ViewRootImpl_Accessor.java 0 → 100644 +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); } }
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/Layout.java +14 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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. */ Loading
tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/myapplication.widgets/InsetsWidget.java 0 → 100644 +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); } }
tools/layoutlib/bridge/tests/res/testApp/MyApplication/src/main/res/layout/insets.xml 0 → 100644 +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>