| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  | package com.jme3.app;
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | import android.app.Activity;
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  | import android.app.AlertDialog;
 | 
					
						
							|  |  |  |  | import android.content.DialogInterface;
 | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:31 +00:00
										 |  |  |  | import android.content.pm.ActivityInfo;
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  | import android.graphics.drawable.Drawable;
 | 
					
						
							|  |  |  |  | import android.graphics.drawable.NinePatchDrawable;
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  | import android.opengl.GLSurfaceView;
 | 
					
						
							|  |  |  |  | import android.os.Bundle;
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  | import android.view.ViewGroup.LayoutParams;
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  | import android.view.*;
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  | import android.widget.FrameLayout;
 | 
					
						
							|  |  |  |  | import android.widget.ImageView;
 | 
					
						
							| 
									
										
										
										
											2011-06-29 07:29:16 +00:00
										 |  |  |  | import android.widget.TextView;
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  | import com.jme3.audio.AudioRenderer;
 | 
					
						
							|  |  |  |  | import com.jme3.audio.android.AndroidAudioRenderer;
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  | import com.jme3.input.android.AndroidInput;
 | 
					
						
							| 
									
										
										
										
											2011-06-16 17:52:53 +00:00
										 |  |  |  | import com.jme3.input.controls.TouchListener;
 | 
					
						
							|  |  |  |  | import com.jme3.input.event.TouchEvent;
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  | import com.jme3.system.AppSettings;
 | 
					
						
							|  |  |  |  | import com.jme3.system.JmeSystem;
 | 
					
						
							| 
									
										
										
										
											2011-06-21 22:13:42 +00:00
										 |  |  |  | import com.jme3.system.android.AndroidConfigChooser.ConfigType;
 | 
					
						
							| 
									
										
										
										
											2011-12-03 01:22:42 +00:00
										 |  |  |  | import com.jme3.system.android.JmeAndroidSystem;
 | 
					
						
							| 
									
										
										
										
											2011-12-03 14:06:48 +00:00
										 |  |  |  | import com.jme3.system.android.OGLESContext;
 | 
					
						
							|  |  |  |  | import com.jme3.util.JmeFormatter;
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  | import java.io.PrintWriter;
 | 
					
						
							|  |  |  |  | import java.io.StringWriter;
 | 
					
						
							| 
									
										
										
										
											2011-12-03 14:06:48 +00:00
										 |  |  |  | import java.util.logging.Handler;
 | 
					
						
							|  |  |  |  | import java.util.logging.Level;
 | 
					
						
							|  |  |  |  | import java.util.logging.Logger;
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |  * <code>AndroidHarness</code> wraps a jme application object and runs it on
 | 
					
						
							|  |  |  |  |  * Android
 | 
					
						
							|  |  |  |  |  *
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  |  * @author Kirill
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |  * @author larynx
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  |  */
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | public class AndroidHarness extends Activity implements TouchListener, DialogInterface.OnClickListener {
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  |     protected final static Logger logger = Logger.getLogger(AndroidHarness.class.getName());
 | 
					
						
							| 
									
										
										
										
											2011-06-21 22:13:42 +00:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * The application class to start
 | 
					
						
							|  |  |  |  |      */
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  |     protected String appClass = "jme3test.android.Test";
 | 
					
						
							| 
									
										
										
										
											2011-06-21 22:13:42 +00:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * The jme3 application object
 | 
					
						
							|  |  |  |  |      */
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  |     protected Application app = null;
 | 
					
						
							| 
									
										
										
										
											2011-06-21 22:13:42 +00:00
										 |  |  |  |     /**
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |      * ConfigType.FASTEST is RGB565, GLSurfaceView default ConfigType.BEST is
 | 
					
						
							|  |  |  |  |      * RGBA8888 or better if supported by the hardware
 | 
					
						
							| 
									
										
										
										
											2011-06-21 22:13:42 +00:00
										 |  |  |  |      */
 | 
					
						
							|  |  |  |  |     protected ConfigType eglConfigType = ConfigType.FASTEST;
 | 
					
						
							| 
									
										
										
										
											2011-06-24 20:11:27 +00:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * If true all valid and not valid egl configs are logged
 | 
					
						
							|  |  |  |  |      */
 | 
					
						
							|  |  |  |  |     protected boolean eglConfigVerboseLogging = false;
 | 
					
						
							| 
									
										
										
										
											2011-07-12 09:25:36 +00:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * If true MouseEvents are generated from TouchEvents
 | 
					
						
							|  |  |  |  |      */
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     protected boolean mouseEventsEnabled = true;
 | 
					
						
							| 
									
										
										
										
											2011-07-12 09:25:36 +00:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * Flip X axis
 | 
					
						
							|  |  |  |  |      */
 | 
					
						
							|  |  |  |  |     protected boolean mouseEventsInvertX = true;
 | 
					
						
							|  |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * Flip Y axis
 | 
					
						
							|  |  |  |  |      */
 | 
					
						
							| 
									
										
										
										
											2011-07-05 20:20:01 +00:00
										 |  |  |  |     protected boolean mouseEventsInvertY = true;
 | 
					
						
							| 
									
										
										
										
											2011-06-22 17:26:27 +00:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * Title of the exit dialog, default is "Do you want to exit?"
 | 
					
						
							|  |  |  |  |      */
 | 
					
						
							|  |  |  |  |     protected String exitDialogTitle = "Do you want to exit?";
 | 
					
						
							|  |  |  |  |     /**
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |      * Message of the exit dialog, default is "Use your home key to bring this
 | 
					
						
							|  |  |  |  |      * app into the background or exit to terminate it."
 | 
					
						
							| 
									
										
										
										
											2011-06-22 17:26:27 +00:00
										 |  |  |  |      */
 | 
					
						
							|  |  |  |  |     protected String exitDialogMessage = "Use your home key to bring this app into the background or exit to terminate it.";
 | 
					
						
							| 
									
										
										
										
											2011-09-30 04:24:36 +00:00
										 |  |  |  |     /**
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  |      * Set the screen window mode. If screenFullSize is true, then the
 | 
					
						
							|  |  |  |  |      * notification bar and title bar are removed and the screen covers the
 | 
					
						
							|  |  |  |  |      * entire display.   If screenFullSize is false, then the notification bar
 | 
					
						
							|  |  |  |  |      * remains visible if screenShowTitle is true while screenFullScreen is
 | 
					
						
							|  |  |  |  |      * false, then the title bar is also displayed under the notification bar.
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |      */
 | 
					
						
							| 
									
										
										
										
											2011-09-30 04:24:36 +00:00
										 |  |  |  |     protected boolean screenFullScreen = true;
 | 
					
						
							|  |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * if screenShowTitle is true while screenFullScreen is false, then the
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |      * title bar is also displayed under the notification bar
 | 
					
						
							| 
									
										
										
										
											2011-09-30 04:24:36 +00:00
										 |  |  |  |      */
 | 
					
						
							|  |  |  |  |     protected boolean screenShowTitle = true;
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  |     /**
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |      * Splash Screen picture Resource ID. If a Splash Screen is desired, set
 | 
					
						
							|  |  |  |  |      * splashPicID to the value of the Resource ID (i.e. R.drawable.picname). If
 | 
					
						
							|  |  |  |  |      * splashPicID = 0, then no splash screen will be displayed.
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  |      */
 | 
					
						
							|  |  |  |  |     protected int splashPicID = 0;
 | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:31 +00:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * Set the screen orientation, default is SENSOR
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |      * ActivityInfo.SCREEN_ORIENTATION_* constants package
 | 
					
						
							|  |  |  |  |      * android.content.pm.ActivityInfo
 | 
					
						
							|  |  |  |  |      *
 | 
					
						
							|  |  |  |  |      * SCREEN_ORIENTATION_UNSPECIFIED SCREEN_ORIENTATION_LANDSCAPE
 | 
					
						
							|  |  |  |  |      * SCREEN_ORIENTATION_PORTRAIT SCREEN_ORIENTATION_USER
 | 
					
						
							|  |  |  |  |      * SCREEN_ORIENTATION_BEHIND SCREEN_ORIENTATION_SENSOR (default)
 | 
					
						
							|  |  |  |  |      * SCREEN_ORIENTATION_NOSENSOR
 | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:31 +00:00
										 |  |  |  |      */
 | 
					
						
							|  |  |  |  |     protected int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR;
 | 
					
						
							| 
									
										
										
										
											2011-06-21 22:13:42 +00:00
										 |  |  |  |     protected OGLESContext ctx;
 | 
					
						
							| 
									
										
										
										
											2011-07-12 09:52:35 +00:00
										 |  |  |  |     protected GLSurfaceView view = null;
 | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:31 +00:00
										 |  |  |  |     protected boolean isGLThreadPaused = true;
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |     private ImageView splashImageView = null;
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  |     private FrameLayout frameLayout = null;
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     final private String ESCAPE_EVENT = "TouchEscape";
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-27 23:27:56 +00:00
										 |  |  |  |     static {
 | 
					
						
							|  |  |  |  |         try {
 | 
					
						
							|  |  |  |  |             System.loadLibrary("bulletjme");
 | 
					
						
							|  |  |  |  |         } catch (UnsatisfiedLinkError e) {
 | 
					
						
							|  |  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2011-12-03 01:22:42 +00:00
										 |  |  |  |         JmeSystem.setSystemDelegate(new JmeAndroidSystem());
 | 
					
						
							| 
									
										
										
										
											2011-11-27 23:27:56 +00:00
										 |  |  |  |     }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  |     @Override
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     public void onCreate(Bundle savedInstanceState) {
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  |         super.onCreate(savedInstanceState);
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-22 18:27:17 +00:00
										 |  |  |  |         Logger log = logger;
 | 
					
						
							|  |  |  |  |         boolean bIsLogFormatSet = false;
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |         do {
 | 
					
						
							|  |  |  |  |             if (log.getHandlers().length == 0) {
 | 
					
						
							| 
									
										
										
										
											2011-07-22 18:27:17 +00:00
										 |  |  |  |                 log = logger.getParent();
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |                 if (log != null) {
 | 
					
						
							|  |  |  |  |                     for (Handler h : log.getHandlers()) {
 | 
					
						
							| 
									
										
										
										
											2011-07-22 18:27:17 +00:00
										 |  |  |  |                         //h.setFormatter(new SimpleFormatter());
 | 
					
						
							|  |  |  |  |                         h.setFormatter(new JmeFormatter());
 | 
					
						
							|  |  |  |  |                         bIsLogFormatSet = true;
 | 
					
						
							|  |  |  |  |                     }
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |                 }
 | 
					
						
							| 
									
										
										
										
											2011-07-22 18:27:17 +00:00
										 |  |  |  |             }
 | 
					
						
							|  |  |  |  |         } while (log != null && !bIsLogFormatSet);
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 01:22:42 +00:00
										 |  |  |  |         JmeAndroidSystem.setResources(getResources());
 | 
					
						
							|  |  |  |  |         JmeAndroidSystem.setActivity(this);
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 04:24:36 +00:00
										 |  |  |  |         if (screenFullScreen) {
 | 
					
						
							|  |  |  |  |             requestWindowFeature(Window.FEATURE_NO_TITLE);
 | 
					
						
							|  |  |  |  |             getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
 | 
					
						
							|  |  |  |  |                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
 | 
					
						
							|  |  |  |  |         } else {
 | 
					
						
							|  |  |  |  |             if (!screenShowTitle) {
 | 
					
						
							|  |  |  |  |                 requestWindowFeature(Window.FEATURE_NO_TITLE);
 | 
					
						
							|  |  |  |  |             }
 | 
					
						
							|  |  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:31 +00:00
										 |  |  |  |         setRequestedOrientation(screenOrientation);
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-12 09:25:36 +00:00
										 |  |  |  |         // Create Settings
 | 
					
						
							|  |  |  |  |         AppSettings settings = new AppSettings(true);
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-12 09:25:36 +00:00
										 |  |  |  |         // Create the input class
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |         AndroidInput input = new AndroidInput(this);
 | 
					
						
							| 
									
										
										
										
											2011-07-12 09:25:36 +00:00
										 |  |  |  |         input.setMouseEventsInvertX(mouseEventsInvertX);
 | 
					
						
							| 
									
										
										
										
											2011-07-05 20:20:01 +00:00
										 |  |  |  |         input.setMouseEventsInvertY(mouseEventsInvertY);
 | 
					
						
							|  |  |  |  |         input.setMouseEventsEnabled(mouseEventsEnabled);
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  |         // Create application instance
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |         try {
 | 
					
						
							|  |  |  |  |             if (app == null) {
 | 
					
						
							| 
									
										
										
										
											2011-07-12 09:52:35 +00:00
										 |  |  |  |                 @SuppressWarnings("unchecked")
 | 
					
						
							|  |  |  |  |                 Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(appClass);
 | 
					
						
							|  |  |  |  |                 app = clazz.newInstance();
 | 
					
						
							|  |  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-29 07:29:16 +00:00
										 |  |  |  |             app.setSettings(settings);
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |             app.start();
 | 
					
						
							| 
									
										
										
										
											2011-06-29 07:29:16 +00:00
										 |  |  |  |             ctx = (OGLESContext) app.getContext();
 | 
					
						
							|  |  |  |  |             view = ctx.createView(input, eglConfigType, eglConfigVerboseLogging);
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-12 09:25:36 +00:00
										 |  |  |  |             // Set the screen reolution
 | 
					
						
							|  |  |  |  |             WindowManager wind = this.getWindowManager();
 | 
					
						
							|  |  |  |  |             Display disp = wind.getDefaultDisplay();
 | 
					
						
							|  |  |  |  |             ctx.getSettings().setResolution(disp.getWidth(), disp.getHeight());
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |             AppSettings s = ctx.getSettings();
 | 
					
						
							|  |  |  |  |             logger.log(Level.INFO, "Settings: Width {0} Height {1}", new Object[]{s.getWidth(), s.getHeight()});
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |             layoutDisplay();
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |         } catch (Exception ex) {
 | 
					
						
							| 
									
										
										
										
											2011-06-17 09:56:55 +00:00
										 |  |  |  |             handleError("Class " + appClass + " init failed", ex);
 | 
					
						
							| 
									
										
										
										
											2011-06-29 07:29:16 +00:00
										 |  |  |  |             setContentView(new TextView(this));
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  |         }
 | 
					
						
							|  |  |  |  |     }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |     @Override
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     protected void onRestart() {
 | 
					
						
							|  |  |  |  |         super.onRestart();
 | 
					
						
							|  |  |  |  |         if (app != null) {
 | 
					
						
							| 
									
										
										
										
											2011-06-29 07:29:16 +00:00
										 |  |  |  |             app.restart();
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |         logger.info("onRestart");
 | 
					
						
							|  |  |  |  |     }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     @Override
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     protected void onStart() {
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |         super.onStart();
 | 
					
						
							|  |  |  |  |         logger.info("onStart");
 | 
					
						
							|  |  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  |     @Override
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     protected void onResume() {
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  |         super.onResume();
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |         if (view != null) {
 | 
					
						
							| 
									
										
										
										
											2011-06-29 07:29:16 +00:00
										 |  |  |  |             view.onResume();
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         //resume the audio
 | 
					
						
							|  |  |  |  |         AudioRenderer result = app.getAudioRenderer();
 | 
					
						
							|  |  |  |  |         if (result instanceof AndroidAudioRenderer) {
 | 
					
						
							|  |  |  |  |             AndroidAudioRenderer renderer = (AndroidAudioRenderer) result;
 | 
					
						
							|  |  |  |  |             renderer.resumeAll();
 | 
					
						
							|  |  |  |  |         }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:31 +00:00
										 |  |  |  |         isGLThreadPaused = false;
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |         logger.info("onResume");
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  |     }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     @Override
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     protected void onPause() {
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  |         super.onPause();
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |         if (view != null) {
 | 
					
						
							| 
									
										
										
										
											2011-06-29 07:29:16 +00:00
										 |  |  |  |             view.onPause();
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         //pause the audio
 | 
					
						
							|  |  |  |  |         AudioRenderer result = app.getAudioRenderer();
 | 
					
						
							|  |  |  |  |         logger.info("pause: " + result.getClass().getSimpleName());
 | 
					
						
							|  |  |  |  |         if (result instanceof AndroidAudioRenderer) {
 | 
					
						
							|  |  |  |  |             AndroidAudioRenderer renderer = (AndroidAudioRenderer) result;
 | 
					
						
							|  |  |  |  |             renderer.pauseAll();
 | 
					
						
							|  |  |  |  |         }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:31 +00:00
										 |  |  |  |         isGLThreadPaused = true;
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |         logger.info("onPause");
 | 
					
						
							|  |  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |     @Override
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     protected void onStop() {
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |         super.onStop();
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |         logger.info("onStop");
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  |     }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |     @Override
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     protected void onDestroy() {
 | 
					
						
							|  |  |  |  |         if (app != null) {
 | 
					
						
							|  |  |  |  |             app.stop(!isGLThreadPaused);
 | 
					
						
							|  |  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |         logger.info("onDestroy");
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |         super.onDestroy();
 | 
					
						
							| 
									
										
										
										
											2011-05-24 14:57:50 +00:00
										 |  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     public Application getJmeApplication() {
 | 
					
						
							| 
									
										
										
										
											2011-06-17 09:56:55 +00:00
										 |  |  |  |         return app;
 | 
					
						
							|  |  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  |     /**
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  |      * Called when an error has occurred. By default, will show an error message
 | 
					
						
							|  |  |  |  |      * to the user and print the exception/error to the log.
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  |      */
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     public void handleError(final String errorMsg, final Throwable t) {
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |         String stackTrace = "";
 | 
					
						
							|  |  |  |  |         String title = "Error";
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (t != null) {
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |             // Convert exception to string
 | 
					
						
							|  |  |  |  |             StringWriter sw = new StringWriter(100);
 | 
					
						
							|  |  |  |  |             t.printStackTrace(new PrintWriter(sw));
 | 
					
						
							|  |  |  |  |             stackTrace = sw.toString();
 | 
					
						
							|  |  |  |  |             title = t.toString();
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         final String finalTitle = title;
 | 
					
						
							|  |  |  |  |         final String finalMsg = (errorMsg != null ? errorMsg : "Uncaught Exception")
 | 
					
						
							|  |  |  |  |                 + "\n" + stackTrace;
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |         logger.log(Level.SEVERE, finalMsg);
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |         runOnUiThread(new Runnable() {
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  |             @Override
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |             public void run() {
 | 
					
						
							|  |  |  |  |                 AlertDialog dialog = new AlertDialog.Builder(AndroidHarness.this) // .setIcon(R.drawable.alert_dialog_icon)
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  |                          .setTitle(finalTitle)
 | 
					
						
							|  |  |  |  |                          .setPositiveButton("Kill", AndroidHarness.this)
 | 
					
						
							|  |  |  |  |                          .setMessage(finalMsg).create();
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |                 dialog.show();
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  |             }
 | 
					
						
							|  |  |  |  |         });
 | 
					
						
							|  |  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  |     /**
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |      * Called by the android alert dialog, terminate the activity and OpenGL
 | 
					
						
							|  |  |  |  |      * rendering
 | 
					
						
							|  |  |  |  |      *
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  |      * @param dialog
 | 
					
						
							|  |  |  |  |      * @param whichButton
 | 
					
						
							|  |  |  |  |      */
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     public void onClick(DialogInterface dialog, int whichButton) {
 | 
					
						
							|  |  |  |  |         if (whichButton != -2) {
 | 
					
						
							|  |  |  |  |             if (app != null) {
 | 
					
						
							| 
									
										
										
										
											2011-06-29 07:29:16 +00:00
										 |  |  |  |                 app.stop(true);
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |             }
 | 
					
						
							| 
									
										
										
										
											2011-06-16 17:52:53 +00:00
										 |  |  |  |             this.finish();
 | 
					
						
							|  |  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2011-05-18 19:12:25 +00:00
										 |  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-16 17:52:53 +00:00
										 |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * Gets called by the InputManager on all touch/drag/scale events
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |      */
 | 
					
						
							|  |  |  |  |     @Override
 | 
					
						
							|  |  |  |  |     public void onTouch(String name, TouchEvent evt, float tpf) {
 | 
					
						
							|  |  |  |  |         if (name.equals(ESCAPE_EVENT)) {
 | 
					
						
							|  |  |  |  |             switch (evt.getType()) {
 | 
					
						
							| 
									
										
										
										
											2011-06-16 17:52:53 +00:00
										 |  |  |  |                 case KEY_UP:
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |                     runOnUiThread(new Runnable() {
 | 
					
						
							| 
									
										
										
										
											2012-02-15 04:30:35 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-16 17:52:53 +00:00
										 |  |  |  |                         @Override
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |                         public void run() {
 | 
					
						
							|  |  |  |  |                             AlertDialog dialog = new AlertDialog.Builder(AndroidHarness.this) // .setIcon(R.drawable.alert_dialog_icon)
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |                                     .setTitle(exitDialogTitle)
 | 
					
						
							|  |  |  |  |                                     .setPositiveButton("Yes", AndroidHarness.this)
 | 
					
						
							|  |  |  |  |                                     .setNegativeButton("No", AndroidHarness.this)
 | 
					
						
							|  |  |  |  |                                     .setMessage(exitDialogMessage).create();
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |                             dialog.show();
 | 
					
						
							| 
									
										
										
										
											2011-06-16 17:52:53 +00:00
										 |  |  |  |                         }
 | 
					
						
							|  |  |  |  |                     });
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |                     break;
 | 
					
						
							|  |  |  |  |                 default:
 | 
					
						
							| 
									
										
										
										
											2011-06-16 17:52:53 +00:00
										 |  |  |  |                     break;
 | 
					
						
							|  |  |  |  |             }
 | 
					
						
							|  |  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2011-09-10 21:26:59 +00:00
										 |  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     public void layoutDisplay() {
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |         logger.log(Level.INFO, "Splash Screen Picture Resource ID: {0}", splashPicID);
 | 
					
						
							|  |  |  |  |         if (splashPicID != 0) {
 | 
					
						
							|  |  |  |  |             FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
 | 
					
						
							|  |  |  |  |                     LayoutParams.FILL_PARENT,
 | 
					
						
							|  |  |  |  |                     LayoutParams.FILL_PARENT,
 | 
					
						
							|  |  |  |  |                     Gravity.CENTER);
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |             frameLayout = new FrameLayout(this);
 | 
					
						
							|  |  |  |  |             splashImageView = new ImageView(this);
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |             Drawable drawable = this.getResources().getDrawable(splashPicID);
 | 
					
						
							|  |  |  |  |             if (drawable instanceof NinePatchDrawable) {
 | 
					
						
							|  |  |  |  |                 splashImageView.setBackgroundDrawable(drawable);
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  |             } else {
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |                 splashImageView.setImageResource(splashPicID);
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  |             }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  |             frameLayout.addView(view);
 | 
					
						
							|  |  |  |  |             frameLayout.addView(splashImageView, lp);
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             setContentView(frameLayout);
 | 
					
						
							|  |  |  |  |             logger.log(Level.INFO, "Splash Screen Created");
 | 
					
						
							|  |  |  |  |         } else {
 | 
					
						
							|  |  |  |  |             logger.log(Level.INFO, "Splash Screen Skipped.");
 | 
					
						
							|  |  |  |  |             setContentView(view);
 | 
					
						
							|  |  |  |  |         }
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  |     }
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public void removeSplashScreen() {
 | 
					
						
							|  |  |  |  |         logger.log(Level.INFO, "Splash Screen Picture Resource ID: {0}", splashPicID);
 | 
					
						
							|  |  |  |  |         if (splashPicID != 0) {
 | 
					
						
							|  |  |  |  |             if (frameLayout != null) {
 | 
					
						
							|  |  |  |  |                 if (splashImageView != null) {
 | 
					
						
							|  |  |  |  |                     this.runOnUiThread(new Runnable() {
 | 
					
						
							| 
									
										
										
										
											2012-02-11 06:08:49 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-21 09:59:10 +00:00
										 |  |  |  |                         @Override
 | 
					
						
							|  |  |  |  |                         public void run() {
 | 
					
						
							|  |  |  |  |                             splashImageView.setVisibility(View.INVISIBLE);
 | 
					
						
							|  |  |  |  |                             frameLayout.removeView(splashImageView);
 | 
					
						
							|  |  |  |  |                         }
 | 
					
						
							|  |  |  |  |                     });
 | 
					
						
							|  |  |  |  |                 } else {
 | 
					
						
							|  |  |  |  |                     logger.log(Level.INFO, "splashImageView is null");
 | 
					
						
							|  |  |  |  |                 }
 | 
					
						
							|  |  |  |  |             } else {
 | 
					
						
							|  |  |  |  |                 logger.log(Level.INFO, "frameLayout is null");
 | 
					
						
							|  |  |  |  |             }
 | 
					
						
							|  |  |  |  |         }
 | 
					
						
							|  |  |  |  |     }
 | 
					
						
							| 
									
										
										
										
											2011-03-14 12:55:32 +00:00
										 |  |  |  | }
 |