diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-10-22 13:52:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-22 13:52:39 +0200 |
commit | acd5c7e76794ae9d54ac87d8d80302d4c79fec67 (patch) | |
tree | b777d5eefb62758bbfc258c424d8e0498e2bd27d /platform/android | |
parent | e4cfb7796195f21bfe2b8e4c192ad153bce4b07a (diff) | |
parent | 44073506083f2b311873c10ad8428c3238abd668 (diff) |
Merge pull request #32858 from m4gr3d/expand_singleton_base_api
Add `View SingletonBase#onMainCreateView(Activity activity)` api
Diffstat (limited to 'platform/android')
-rw-r--r-- | platform/android/java/lib/src/org/godotengine/godot/Godot.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java index 739aa285bf..247f006a69 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java @@ -56,11 +56,14 @@ import android.hardware.SensorManager; import android.os.Build; import android.os.Bundle; import android.os.Environment; +import android.os.Handler; +import android.os.Looper; import android.os.Messenger; import android.os.VibrationEffect; import android.os.Vibrator; import android.provider.Settings.Secure; import android.support.annotation.Keep; +import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.view.Display; import android.view.KeyEvent; @@ -126,6 +129,9 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo private boolean activityResumed; private int mState; + // Used to dispatch events to the main thread. + private final Handler mainThreadHandler = new Handler(Looper.getMainLooper()); + static private Intent mCurrentIntent; @Override @@ -187,6 +193,20 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo Godot.singletons[Godot.singleton_count++] = this; } + /** + * Invoked once during the Godot Android initialization process after creation of the + * {@link GodotView} view. + * <p> + * This method should be overridden by descendants of this class that would like to add + * their view/layout to the Godot view hierarchy. + * + * @return the view to be included; null if no views should be included. + */ + @Nullable + protected View onMainCreateView(Activity activity) { + return null; + } + protected void onMainActivityResult(int requestCode, int resultCode, Intent data) { } @@ -306,6 +326,20 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo public void run() { GodotLib.setup(current_command_line); setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on"))); + + // The Godot Android plugins are setup on completion of GodotLib.setup + mainThreadHandler.post(new Runnable() { + @Override + public void run() { + // Include the non-null views returned in the Godot view hierarchy. + for (int i = 0; i < singleton_count; i++) { + View view = singletons[i].onMainCreateView(Godot.this); + if (view != null) { + layout.addView(view); + } + } + } + }); } }); } |