project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/SDLActivity.java
branchhedgeroid
changeset 5540 76392a62da2f
parent 5538 dcfa3bf24a2a
child 5597 14b3cdb23c2c
equal deleted inserted replaced
5538:dcfa3bf24a2a 5540:76392a62da2f
     6 import javax.microedition.khronos.egl.EGLDisplay;
     6 import javax.microedition.khronos.egl.EGLDisplay;
     7 import javax.microedition.khronos.egl.EGLSurface;
     7 import javax.microedition.khronos.egl.EGLSurface;
     8 
     8 
     9 import org.hedgewars.mobile.EngineProtocol.EngineProtocolNetwork;
     9 import org.hedgewars.mobile.EngineProtocol.EngineProtocolNetwork;
    10 import org.hedgewars.mobile.EngineProtocol.GameConfig;
    10 import org.hedgewars.mobile.EngineProtocol.GameConfig;
       
    11 import org.hedgewars.mobile.TouchInterface.TouchInterface;
    11 
    12 
    12 import android.app.Activity;
    13 import android.app.Activity;
    13 import android.content.Context;
    14 import android.content.Context;
    14 import android.graphics.Canvas;
    15 import android.graphics.Canvas;
    15 import android.graphics.PixelFormat;
    16 import android.graphics.PixelFormat;
   118 
   119 
   119 	public static native void onNativeKeyDown(int keycode);
   120 	public static native void onNativeKeyDown(int keycode);
   120 
   121 
   121 	public static native void onNativeKeyUp(int keycode);
   122 	public static native void onNativeKeyUp(int keycode);
   122 
   123 
   123 	public static native void onNativeTouch(int action, float x, float y,
   124 	public static native void onNativeTouch(int action, int pointer, float x, float y,
   124 			float p);
   125 			float p);
   125 
   126 
   126 	public static native void onNativeAccel(float x, float y, float z);
   127 	public static native void onNativeAccel(float x, float y, float z);
   127 
   128 
   128 	public static native void nativeRunAudioThread();
   129 	public static native void nativeRunAudioThread();
   293  * order to do anything useful.
   294  * order to do anything useful.
   294  * 
   295  * 
   295  * Because of this, that's where we set up the SDL thread
   296  * Because of this, that's where we set up the SDL thread
   296  */
   297  */
   297 class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
   298 class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
   298 		View.OnKeyListener, View.OnTouchListener, SensorEventListener {
   299 		View.OnKeyListener, SensorEventListener {
   299 
   300 
   300 	// This is what SDL runs in. It invokes SDL_main(), eventually
   301 	// This is what SDL runs in. It invokes SDL_main(), eventually
   301 	private Thread mSDLThread;
   302 	private Thread mSDLThread;
   302 
   303 
   303 	// EGL private objects
   304 	// EGL private objects
   317 
   318 
   318 		setFocusable(true);
   319 		setFocusable(true);
   319 		setFocusableInTouchMode(true);
   320 		setFocusableInTouchMode(true);
   320 		requestFocus();
   321 		requestFocus();
   321 		setOnKeyListener(this);
   322 		setOnKeyListener(this);
   322 		setOnTouchListener(this);
   323 		setOnTouchListener(TouchInterface.getTouchInterface());
   323 
   324 
   324 		mSensorManager = (SensorManager) context.getSystemService("sensor");
   325 		mSensorManager = (SensorManager) context.getSystemService("sensor");
   325 
   326 
   326 		config = _config;
   327 		config = _config;
   327 	}
   328 	}
   524 			SDLActivity.onNativeKeyUp(keyCode);
   525 			SDLActivity.onNativeKeyUp(keyCode);
   525 			return true;
   526 			return true;
   526 		}
   527 		}
   527 
   528 
   528 		return false;
   529 		return false;
   529 	}
       
   530 
       
   531 	// Touch events
       
   532 	public boolean onTouch(View v, MotionEvent event) {
       
   533 
       
   534 		int action = event.getAction();
       
   535 		float x = event.getX();
       
   536 		float y = event.getY();
       
   537 		float p = event.getPressure();
       
   538 		// TODO: Anything else we need to pass?
       
   539 		SDLActivity.onNativeTouch(action, x, y, p);
       
   540 		return true;
       
   541 	}
   530 	}
   542 
   531 
   543 	// Sensor events
   532 	// Sensor events
   544 	public void enableSensor(int sensortype, boolean enabled) {
   533 	public void enableSensor(int sensortype, boolean enabled) {
   545 		// TODO: This uses getDefaultSensor - what if we have >1 accels?
   534 		// TODO: This uses getDefaultSensor - what if we have >1 accels?