Merge pull request #32858 from m4gr3d/expand_singleton_base_api

Add `View SingletonBase#onMainCreateView(Activity activity)` api
This commit is contained in:
Rémi Verschelde 2019-10-22 13:52:39 +02:00 committed by GitHub
commit acd5c7e767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
}
}
});
}
});
}