I have followed the onTouch example from google located here. However, I get nothing out in my logs. As far as I can tell, my view is not picking up any of the on touch events. This is my code:
package com.test;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
public class intro extends Activity {
static{
System.loadLibrary("graphrender");
}
private GLSurfaceView mGLView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mGLView = new GraphGLSurfaceView(this);
setContentView(mGLView);
}
@Override
protected void onPause() {
super.onPause();
mGLView.onPause();
}
@Override
protected void onResume() {
super.onResume();
mGLView.onResume();
}
}
class GraphGLSurfaceView extends GLSurfaceView {
GraphRenderer mRenderer;
public GraphGLSurfaceView(Context context) {
super(context);
mRenderer = new GraphRenderer();
setRenderer(mRenderer);
}
public boolean onTouch(View v, MotionEvent event)
{
queueEvent(new Runnable(){
public void run() {
mRenderer.shout();
}});
return true;
}
}
class GraphRenderer implements GLSurfaceView.Renderer {
private static native void nativeSetup();
private static native void nativeSize(int w, int h);
private static native void nativeRender();
private float _red = 0.9f;
private float _green = 0.2f;
private float _blue = 0.2f;
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
nativeSetup();
Log.d("intro", "Got to intro 4" );
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
nativeSize(w,h);
}
public void onDrawFrame(GL10 gl) {
nativeRender();
}
public void shout()
{
Log.d("Graph Page", "gotta graph");
}
}
The only thing I can think of is that I have to have something fancy in the xml file or set its focus. Any help would be appreciated.
Well that is because if you look at the API for GLSurfaceView it does not actually have a
onTouchmethod for you to override. That means that theonTouchmethod will never be called which probably explains why you never see it being run. Instead, if you want to get the touch events then you should overrideonTouchEventin theActivityinstead. Like this:And that should now work.