mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-04-28 12:17:57 +03:00
Window: implement getDecorView() properly
This is needed to fix the "ViewTreeLifecycleOwner not found" error in composeUI.
This commit is contained in:
parent
e9cf5e7002
commit
cb7805bb45
2 changed files with 15 additions and 18 deletions
|
@ -157,7 +157,6 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
|
|||
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
Slog.i(TAG, "- onCreate - yay!");
|
||||
new ViewGroup(this).setId(R.id.content);
|
||||
|
||||
for (Fragment fragment : fragments) {
|
||||
fragment.onCreate(savedInstanceState);
|
||||
|
@ -176,6 +175,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
|
|||
if (window.contentView != null)
|
||||
window.setContentView(window.contentView);
|
||||
window.setTitle(title);
|
||||
window.attached();
|
||||
|
||||
for (Fragment fragment : fragments) {
|
||||
fragment.onStart();
|
||||
|
|
|
@ -3,6 +3,7 @@ package android.view;
|
|||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
public class Window {
|
||||
public static final int FEATURE_OPTIONS_PANEL = 0;
|
||||
|
@ -26,6 +27,7 @@ public class Window {
|
|||
|
||||
public long native_window;
|
||||
public View contentView;
|
||||
private ViewGroup decorView;
|
||||
|
||||
private Window.Callback callback;
|
||||
private Context context;
|
||||
|
@ -33,8 +35,8 @@ public class Window {
|
|||
public Window(Context context, Window.Callback callback) {
|
||||
this.callback = callback;
|
||||
this.context = context;
|
||||
contentView = new ViewGroup(Context.this_application);
|
||||
contentView.setId(android.R.id.content);
|
||||
decorView = new FrameLayout(context);
|
||||
decorView.setId(android.R.id.content);
|
||||
}
|
||||
|
||||
public void addFlags(int flags) {}
|
||||
|
@ -49,22 +51,20 @@ public class Window {
|
|||
}
|
||||
|
||||
public void setContentView(View view) {
|
||||
if (contentView != view) {
|
||||
if (contentView != null)
|
||||
contentView.onDetachedFromWindow();
|
||||
if (view != null)
|
||||
view.onAttachedToWindow();
|
||||
}
|
||||
contentView = view;
|
||||
decorView.removeAllViews();
|
||||
decorView.addView(view);
|
||||
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() {
|
||||
if (contentView != null)
|
||||
return contentView;
|
||||
return new View(Context.this_application); // FIXME: this can probably backfire
|
||||
return decorView;
|
||||
}
|
||||
|
||||
private native void set_widget_as_root(long native_window, long widget);
|
||||
|
@ -81,10 +81,7 @@ public class Window {
|
|||
}
|
||||
|
||||
public View findViewById(int id) {
|
||||
if (contentView != null)
|
||||
return contentView.findViewById(id);
|
||||
else
|
||||
return null;
|
||||
return decorView.findViewById(id);
|
||||
}
|
||||
|
||||
public View peekDecorView() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue