Merge pull request #42187 from m4gr3d/main_android_subview_init_update

Add overridable init method for the Godot fragment instance.
This commit is contained in:
Rémi Verschelde 2020-09-23 09:30:12 +02:00 committed by GitHub
commit 63d206e61e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 2 deletions

View File

@ -34,6 +34,8 @@ import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
/**
@ -43,13 +45,18 @@ import androidx.fragment.app.FragmentActivity;
* within an Android app.
*/
public abstract class FullScreenGodotApp extends FragmentActivity {
protected Godot godotFragment;
@Nullable
private Godot godotFragment;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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();
}
@ -76,4 +83,17 @@ public abstract class FullScreenGodotApp extends FragmentActivity {
}
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;
}
}