Merge pull request #52320 from nekomatata/android-plugin-view-order

Add support for adding plugin views behind the main view on Android
This commit is contained in:
Fredia Huya-Kouadio 2021-09-01 11:54:46 -07:00 committed by GitHub
commit a160a95ea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -295,7 +295,11 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) { for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
View pluginView = plugin.onMainCreate(activity); View pluginView = plugin.onMainCreate(activity);
if (pluginView != null) { if (pluginView != null) {
containerLayout.addView(pluginView); if (plugin.shouldBeOnTop()) {
containerLayout.addView(pluginView);
} else {
containerLayout.addView(pluginView, 0);
}
} }
} }
} }

View File

@ -191,6 +191,9 @@ public abstract class GodotPlugin {
* The plugin can return a non-null {@link View} layout in order to add it to the Godot view * The plugin can return a non-null {@link View} layout in order to add it to the Godot view
* hierarchy. * hierarchy.
* *
* Use shouldBeOnTop() to set whether the plugin's {@link View} should be added on top or behind
* the main Godot view.
*
* @see Activity#onCreate(Bundle) * @see Activity#onCreate(Bundle)
* @return the plugin's view to be included; null if no views should be included. * @return the plugin's view to be included; null if no views should be included.
*/ */
@ -310,6 +313,17 @@ public abstract class GodotPlugin {
return Collections.emptySet(); return Collections.emptySet();
} }
/**
* Returns whether the plugin's {@link View} returned in onMainCreate() should be placed on
* top of the main Godot view.
*
* Returning false causes the plugin's {@link View} to be placed behind, which can be useful
* when used with transparency in order to let the Godot view handle inputs.
*/
public boolean shouldBeOnTop() {
return true;
}
/** /**
* Runs the specified action on the UI thread. If the current thread is the UI * Runs the specified action on the UI thread. If the current thread is the UI
* thread, then the action is executed immediately. If the current thread is * thread, then the action is executed immediately. If the current thread is