Android Open Source - touchgloid Touchgloid View






From Project

Back to project page touchgloid.

License

The source code is released under:

MIT License

If you think the Android project touchgloid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package rucamzu.touchgloid;
/*ww w .  j  a v a 2 s .  c  o m*/
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.support.v4.view.MotionEventCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.renderscript.*;

public class TouchgloidView extends GLSurfaceView {
  public final TouchgloidRenderer renderer;

  public TouchgloidView(Context context) {
    super(context);

    this.renderer = new TouchgloidRenderer(context);
    
    init();
  }

  public TouchgloidView(Context context, AttributeSet attrs) {
    super(context, attrs);

    this.renderer = new TouchgloidRenderer(context);
    
    init();
  }

  private void init() {
    setEGLContextClientVersion(2);
    setRenderer(renderer);
    setRenderMode(RENDERMODE_WHEN_DIRTY);
    setOnTouchListener(new OnTouchListener() {
      @Override
      public boolean onTouch(View v, MotionEvent event) {
        if (event == null)
          return false;

        switch (MotionEventCompat.getActionMasked(event)) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
          renderer.touches = new TouchgloidRenderer.Touch[event.getPointerCount()];
  
          final float aspect = (float) getWidth() / (float) getHeight();
          
          for (int i = 0; i < event.getPointerCount(); ++i) {
            final float x = ((float) event.getX(i) / (float) getWidth()  * 2.0f - 1.0f) * (aspect > 1.0f ? aspect : 1.0f);
            final float y = (1.0f - (float) event.getY(i) / (float) getHeight()  * 2.0f) / (aspect < 1.0f ? aspect : 1.0f);
            
            renderer.touches[i] = new TouchgloidRenderer.Touch(x, y, event.getSize(i));
          }
          
          requestRender();
          break;

        default:
          break;
        }
        
        return true;
      }
    });
  }
}




Java Source Code List

rucamzu.opengl.Buffer.java
rucamzu.opengl.FragmentShader.java
rucamzu.opengl.IndexBuffer.java
rucamzu.opengl.Object.java
rucamzu.opengl.Program.java
rucamzu.opengl.Shader.java
rucamzu.opengl.Transform.java
rucamzu.opengl.Vector.java
rucamzu.opengl.VertexBuffer.java
rucamzu.opengl.VertexShader.java
rucamzu.touchgloid.TouchgloidActivity.java
rucamzu.touchgloid.TouchgloidRenderer.java
rucamzu.touchgloid.TouchgloidView.java