diff options
Diffstat (limited to 'platform/android/java/src')
4 files changed, 42 insertions, 63 deletions
diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java index 053dfa631a..41dcba5c2c 100644 --- a/platform/android/java/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/src/org/godotengine/godot/Godot.java @@ -191,6 +191,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC  		protected void onMainPause() {}  		protected void onMainResume() {}  		protected void onMainDestroy() {} +		protected boolean onMainBackPressed() { return false; }  		protected void onGLDrawFrame(GL10 gl) {}  		protected void onGLSurfaceChanged(GL10 gl, int width, int height) {} // singletons will always miss first onGLSurfaceChanged call @@ -218,6 +219,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC  	private SensorManager mSensorManager;  	private Sensor mAccelerometer; +	private Sensor mGravity;  	private Sensor mMagnetometer;  	private Sensor mGyroscope; @@ -434,6 +436,8 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC  		mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);  		mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);  		mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME); +		mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY); +		mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);  		mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);  		mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);  		mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); @@ -666,6 +670,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC  			}  		});  		mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME); +		mSensorManager.registerListener(this, mGravity, SensorManager.SENSOR_DELAY_GAME);  		mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME);  		mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME); @@ -733,13 +738,16 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC  				@Override  				public void run() {  					if (typeOfSensor == Sensor.TYPE_ACCELEROMETER) { -						GodotLib.accelerometer(x,y,z); +						GodotLib.accelerometer(-x,y,-z); +					} +					if (typeOfSensor == Sensor.TYPE_GRAVITY) { +						GodotLib.gravity(-x,y,-z);  					}  					if (typeOfSensor == Sensor.TYPE_MAGNETIC_FIELD) { -						GodotLib.magnetometer(x,y,z); +						GodotLib.magnetometer(-x,y,-z);  					}  					if (typeOfSensor == Sensor.TYPE_GYROSCOPE) { -						GodotLib.gyroscope(x,y,z); +						GodotLib.gyroscope(x,-y,z);  					}  				}  			}); @@ -767,9 +775,16 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC  */  	@Override public void onBackPressed() { +		boolean shouldQuit = true; + +		for(int i=0;i<singleton_count;i++) { +			if (singletons[i].onMainBackPressed()) { +				shouldQuit = false; +			} +		}  		System.out.printf("** BACK REQUEST!\n"); -		if (mView != null) { +		if (shouldQuit && mView != null) {  			mView.queueEvent(new Runnable() {  				@Override  				public void run() { diff --git a/platform/android/java/src/org/godotengine/godot/GodotLib.java b/platform/android/java/src/org/godotengine/godot/GodotLib.java index e0ed4cd38c..6b84ad6555 100644 --- a/platform/android/java/src/org/godotengine/godot/GodotLib.java +++ b/platform/android/java/src/org/godotengine/godot/GodotLib.java @@ -53,6 +53,7 @@ public class GodotLib {       public static native void step();       public static native void touch(int what,int pointer,int howmany, int[] arr);       public static native void accelerometer(float x, float y, float z); +     public static native void gravity(float x, float y, float z);       public static native void magnetometer(float x, float y, float z);       public static native void gyroscope(float x, float y, float z);  	 public static native void key(int p_scancode, int p_unicode_char, boolean p_pressed); diff --git a/platform/android/java/src/org/godotengine/godot/GodotView.java b/platform/android/java/src/org/godotengine/godot/GodotView.java index 3c2ad7cc59..b807b952d4 100644 --- a/platform/android/java/src/org/godotengine/godot/GodotView.java +++ b/platform/android/java/src/org/godotengine/godot/GodotView.java @@ -285,13 +285,7 @@ public class GodotView extends GLSurfaceView implements InputDeviceListener {  	@Override public boolean onKeyDown(final int keyCode, KeyEvent event) {  		if (keyCode == KeyEvent.KEYCODE_BACK) { -			queueEvent(new Runnable() { -				@Override -				public void run() { -					GodotLib.back(); -				} -			}); - +			activity.onBackPressed();  			// press 'back' button should not terminate program  			//normal handle 'back' event in game logic  			return true; diff --git a/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java b/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java index 04669a3b0c..ac424ab9f8 100644 --- a/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java +++ b/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java @@ -88,79 +88,48 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene  	public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) {  		//Log.d(TAG, "beforeTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",after: " + after); -		for (int i=0;i<count;i++){ -			mView.queueEvent(new Runnable() { -				@Override -				public void run() { +		mView.queueEvent(new Runnable() { +			@Override +			public void run() { +				for (int i = 0; i < count; ++i) {  					GodotLib.key(KeyEvent.KEYCODE_DEL, 0, true);  					GodotLib.key(KeyEvent.KEYCODE_DEL, 0, false);  				} -			}); -		} +			} +		});  	}  	@Override  	public void onTextChanged(final CharSequence pCharSequence, final int start, final int before, final int count) {  		//Log.d(TAG, "onTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",before: " + before); -		for (int i=start;i<start+count;i++){ -			final int ch = pCharSequence.charAt(i); -			mView.queueEvent(new Runnable() { -				@Override -				public void run() { +		mView.queueEvent(new Runnable() { +			@Override +			public void run() { +				for (int i = start; i < start + count; ++i) { +					final int ch = pCharSequence.charAt(i);  					GodotLib.key(0, ch, true);  					GodotLib.key(0, ch, false);  				} -			}); -		} - +			} +		});  	}  	@Override  	public boolean onEditorAction(final TextView pTextView, final int pActionID, final KeyEvent pKeyEvent) {  		if (this.mEdit == pTextView && this.isFullScreenEdit()) { -			// user press the action button, delete all old text and insert new text -			for (int i = this.mOriginText.length(); i > 0; i--) { -				mView.queueEvent(new Runnable() { -					@Override -					public void run() { -						GodotLib.key(KeyEvent.KEYCODE_DEL, 0, true); -						GodotLib.key(KeyEvent.KEYCODE_DEL, 0, false); -					} -				}); +			final String characters = pKeyEvent.getCharacters(); -				/* -				if (BuildConfig.DEBUG) { -					Log.d(TAG, "deleteBackward"); -				} -				*/ -			} -			String text = pTextView.getText().toString(); - -			/* If user input nothing, translate "\n" to engine. */ -			if (text.compareTo("") == 0) { -				text = "\n"; -			} - -			if ('\n' != text.charAt(text.length() - 1)) { -				text += '\n'; -			} - -			for(int i = 0; i < text.length(); i++) { -				final int ch = text.codePointAt(i); -				mView.queueEvent(new Runnable() { -					@Override -					public void run() { +			mView.queueEvent(new Runnable() { +				@Override +				public void run() { +					for (int i = 0; i < characters.length(); i++) { +						final int ch = characters.codePointAt(i);  						GodotLib.key(0, ch, true);  						GodotLib.key(0, ch, false);  					} -				}); -			} -			/* -			if (BuildConfig.DEBUG) { -				Log.d(TAG, "insertText(" + insertText + ")"); -			} -			*/ +				} +			});  		}  		if (pActionID == EditorInfo.IME_ACTION_DONE) {  |