package st.kirara.tochikashobby;

import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.GestureDetector.SimpleOnGestureListener;

/**
 * Main activity of this sample.
 * @author Tochika
 *
 */
public class MainActivity extends Activity {

	/** View for OpenGL */
	private GLSurfaceView mSurfaceView = null;
	
	/** OpenGL Renderer */
	private GLRendererMain mRenderer = null;
	
	/** Gesture detector for flick */
	private GestureDetector mGestureDetector;

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		// Initialize GLSurfaceView and GLRenderer.
		mSurfaceView = new GLSurfaceView(this);
		mRenderer = new GLRendererMain(this.getApplicationContext());
		mSurfaceView.setRenderer(mRenderer);
		
		// Initialize GestureDetector.
		mGestureDetector = new GestureDetector(this, mGestureListener);		
		
		this.setContentView(mSurfaceView);
	}

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

	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		mGestureDetector.onTouchEvent(event);
		return false;
	}
	private final SimpleOnGestureListener mGestureListener = new SimpleOnGestureListener(){
		
		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){
			// Log.d(MyD.TAG, velocityX + ",   " + velocityY);
			mRenderer.setSpinMovement(velocityX / 10, velocityY / 10);
			
			return super.onFling(e1, e2, velocityX, velocityY);
		}
		
	};
	
}
