back key now quits the game hedgeroid
authorXeli
Wed, 10 Aug 2011 14:55:00 +0200
branchhedgeroid
changeset 5538 dcfa3bf24a2a
parent 5536 61431600b133
child 5540 76392a62da2f
back key now quits the game
project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/SDLActivity.java
--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/SDLActivity.java	Wed Aug 10 14:52:51 2011 +0200
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/mobile/SDLActivity.java	Wed Aug 10 14:55:00 2011 +0200
@@ -83,6 +83,11 @@
 		// Log.v("SDL", "onResume()");
 		super.onResume();
 	}
+	
+	public void onBackPressed(){
+		nativeQuit();
+		super.onBackPressed();
+	}
 
 	// Messages from the SDLMain thread
 	static int COMMAND_CHANGE_TITLE = 1;
@@ -497,6 +502,7 @@
 			for (StackTraceElement s : e.getStackTrace()) {
 				Log.v("SDL", s.toString());
 			}
+			
 		}
 	}
 
@@ -504,11 +510,17 @@
 	public boolean onKey(View v, int keyCode, KeyEvent event) {
 
 		if (event.getAction() == KeyEvent.ACTION_DOWN) {
-			// Log.v("SDL", "key down: " + keyCode);
-			SDLActivity.onNativeKeyDown(keyCode);
+			Log.v("SDL", "key down: " + keyCode);
+			if(keyCode == KeyEvent.KEYCODE_BACK){//TODO ask user to quit or not
+				SDLActivity.nativeQuit();
+				SDLActivity.mSingleton.finish();
+			}else{
+				SDLActivity.onNativeKeyDown(keyCode);	
+			}
+			
 			return true;
 		} else if (event.getAction() == KeyEvent.ACTION_UP) {
-			// Log.v("SDL", "key up: " + keyCode);
+			Log.v("SDL", "key up: " + keyCode);
 			SDLActivity.onNativeKeyUp(keyCode);
 			return true;
 		}