Add more callback for Godot.java

This commit is contained in:
marynate 2014-06-04 11:31:20 +08:00
parent 57a53fbe52
commit ffe01a51cb
2 changed files with 339 additions and 317 deletions

View File

@ -62,6 +62,7 @@ import android.widget.FrameLayout;
import com.android.godot.input.*;
import java.io.InputStream;
import javax.microedition.khronos.opengles.GL10;
public class Godot extends Activity implements SensorEventListener
{
@ -116,11 +117,13 @@ public class Godot extends Activity implements SensorEventListener
}
protected void onMainResume() {
}
protected void onMainPause() {}
protected void onMainResume() {}
protected void onMainDestroy() {}
protected void onGLDrawFrame(GL10 gl) {}
protected void onGLSurfaceChanged(GL10 gl, int width, int height) {} // singletons will always miss first onGLSurfaceChanged call
//protected void onGLSurfaceCreated(GL10 gl, EGLConfig config) {} // singletons won't be ready until first GodotLib.step()
public void registerMethods() {}
}
@ -141,6 +144,7 @@ public class Godot extends Activity implements SensorEventListener
private Sensor mAccelerometer;
public FrameLayout layout;
public RelativeLayout adLayout;
static public GodotIO io;
@ -154,7 +158,6 @@ public class Godot extends Activity implements SensorEventListener
static int singleton_count=0;
public interface ResultCallback {
public void callback(int requestCode, int resultCode, Intent data);
};
@ -197,6 +200,12 @@ public class Godot extends Activity implements SensorEventListener
edittext.setView(mView);
io.setEdit(edittext);
// Ad layout
adLayout = new RelativeLayout(this);
adLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
layout.addView(adLayout);
}
private static Godot _self;
@ -282,6 +291,9 @@ public class Godot extends Activity implements SensorEventListener
@Override protected void onDestroy(){
if(mPaymentsManager != null ) mPaymentsManager.destroy();
for(int i=0;i<singleton_count;i++) {
singletons[i].onMainDestroy();
}
super.onDestroy();
}
@ -291,6 +303,9 @@ public class Godot extends Activity implements SensorEventListener
mSensorManager.unregisterListener(this);
GodotLib.focusout();
for(int i=0;i<singleton_count;i++) {
singletons[i].onMainPause();
}
}
@Override protected void onResume() {

View File

@ -62,6 +62,7 @@ import javax.microedition.khronos.opengles.GL10;
* bit depths). Failure to do so would result in an EGL_BAD_MATCH error.
*/
public class GodotView extends GLSurfaceView {
private static String TAG = "GodotView";
private static final boolean DEBUG = false;
private static Context ctx;
@ -379,12 +380,18 @@ public class GodotView extends GLSurfaceView {
public void onDrawFrame(GL10 gl) {
GodotLib.step();
for(int i=0;i<Godot.singleton_count;i++) {
Godot.singletons[i].onGLDrawFrame(gl);
}
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
GodotLib.resize(width, height,!firsttime);
firsttime=false;
for(int i=0;i<Godot.singleton_count;i++) {
Godot.singletons[i].onGLSurfaceChanged(gl, width, height);
}
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {