GLSurfaceview does not receive onTouch events

I followed the onTouch example from google located here . However, I do not get anything in my magazines. As far as I can tell, my view does not pick up any of the 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 fantastic in the xml file or set its focus. Any help would be appreciated.

+3
source share
1 answer

, , API GLSurfaceView, onTouch . , onTouch , , , , . , , onTouchEvent Activity. :

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 boolean onTouchEvent(MotionEvent event) {
        Log.i("motion", event);
        return true;
    }

    @Override
    protected void onPause() {
        super.onPause();
        mGLView.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mGLView.onResume();
    }
}

.

+3

Source: https://habr.com/ru/post/1792707/


All Articles