You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
Window: implement getDecorView() properly
This is needed to fix the "ViewTreeLifecycleOwner not found" error in composeUI.
This commit is contained in:
@@ -157,7 +157,6 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
|
|||||||
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
Slog.i(TAG, "- onCreate - yay!");
|
Slog.i(TAG, "- onCreate - yay!");
|
||||||
new ViewGroup(this).setId(R.id.content);
|
|
||||||
|
|
||||||
for (Fragment fragment : fragments) {
|
for (Fragment fragment : fragments) {
|
||||||
fragment.onCreate(savedInstanceState);
|
fragment.onCreate(savedInstanceState);
|
||||||
@@ -176,6 +175,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
|
|||||||
if (window.contentView != null)
|
if (window.contentView != null)
|
||||||
window.setContentView(window.contentView);
|
window.setContentView(window.contentView);
|
||||||
window.setTitle(title);
|
window.setTitle(title);
|
||||||
|
window.attached();
|
||||||
|
|
||||||
for (Fragment fragment : fragments) {
|
for (Fragment fragment : fragments) {
|
||||||
fragment.onStart();
|
fragment.onStart();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package android.view;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
public class Window {
|
public class Window {
|
||||||
public static final int FEATURE_OPTIONS_PANEL = 0;
|
public static final int FEATURE_OPTIONS_PANEL = 0;
|
||||||
@@ -26,6 +27,7 @@ public class Window {
|
|||||||
|
|
||||||
public long native_window;
|
public long native_window;
|
||||||
public View contentView;
|
public View contentView;
|
||||||
|
private ViewGroup decorView;
|
||||||
|
|
||||||
private Window.Callback callback;
|
private Window.Callback callback;
|
||||||
private Context context;
|
private Context context;
|
||||||
@@ -33,8 +35,8 @@ public class Window {
|
|||||||
public Window(Context context, Window.Callback callback) {
|
public Window(Context context, Window.Callback callback) {
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
contentView = new ViewGroup(Context.this_application);
|
decorView = new FrameLayout(context);
|
||||||
contentView.setId(android.R.id.content);
|
decorView.setId(android.R.id.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addFlags(int flags) {}
|
public void addFlags(int flags) {}
|
||||||
@@ -49,22 +51,20 @@ public class Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setContentView(View view) {
|
public void setContentView(View view) {
|
||||||
if (contentView != view) {
|
decorView.removeAllViews();
|
||||||
if (contentView != null)
|
decorView.addView(view);
|
||||||
contentView.onDetachedFromWindow();
|
|
||||||
if (view != null)
|
|
||||||
view.onAttachedToWindow();
|
|
||||||
}
|
|
||||||
contentView = view;
|
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
set_widget_as_root(native_window, view.widget);
|
set_widget_as_root(native_window, decorView.widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void attached() {
|
||||||
|
if (decorView != null)
|
||||||
|
decorView.onAttachedToWindow();
|
||||||
|
}
|
||||||
|
|
||||||
public View getDecorView() {
|
public View getDecorView() {
|
||||||
if (contentView != null)
|
return decorView;
|
||||||
return contentView;
|
|
||||||
return new View(Context.this_application); // FIXME: this can probably backfire
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private native void set_widget_as_root(long native_window, long widget);
|
private native void set_widget_as_root(long native_window, long widget);
|
||||||
@@ -81,10 +81,7 @@ public class Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public View findViewById(int id) {
|
public View findViewById(int id) {
|
||||||
if (contentView != null)
|
return decorView.findViewById(id);
|
||||||
return contentView.findViewById(id);
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public View peekDecorView() {
|
public View peekDecorView() {
|
||||||
|
|||||||
Reference in New Issue
Block a user