1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-26 15:46:23 +00:00

Add overridable init method for the Godot fragment instance.

This commit is contained in:
Fredia Huya-Kouadio
2020-08-31 09:37:00 -07:00
parent e99dc65b64
commit 8d9733f90c

View File

@@ -34,6 +34,8 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.KeyEvent; import android.view.KeyEvent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
/** /**
@@ -44,13 +46,18 @@ import androidx.fragment.app.FragmentActivity;
*/ */
public abstract class FullScreenGodotApp extends FragmentActivity { public abstract class FullScreenGodotApp extends FragmentActivity {
protected Godot godotFragment; @Nullable
private Godot godotFragment;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.godot_app_layout); setContentView(R.layout.godot_app_layout);
godotFragment = new Godot(); godotFragment = initGodotInstance();
if (godotFragment == null) {
throw new IllegalStateException("Godot instance must be non-null.");
}
getSupportFragmentManager().beginTransaction().replace(R.id.godot_fragment_container, godotFragment).setPrimaryNavigationFragment(godotFragment).commitNowAllowingStateLoss(); getSupportFragmentManager().beginTransaction().replace(R.id.godot_fragment_container, godotFragment).setPrimaryNavigationFragment(godotFragment).commitNowAllowingStateLoss();
} }
@@ -77,4 +84,17 @@ public abstract class FullScreenGodotApp extends FragmentActivity {
} }
return super.onKeyMultiple(inKeyCode, repeatCount, event); return super.onKeyMultiple(inKeyCode, repeatCount, event);
} }
/**
* Used to initialize the Godot fragment instance in {@link FullScreenGodotApp#onCreate(Bundle)}.
*/
@NonNull
protected Godot initGodotInstance() {
return new Godot();
}
@Nullable
protected final Godot getGodotFragment() {
return godotFragment;
}
} }