From 5b326f4054b729cc17c09b19d6cd333374bf69b7 Mon Sep 17 00:00:00 2001 From: "iwg..ic" Date: Sun, 16 Sep 2012 22:00:27 +0000 Subject: [PATCH] Minor reorganization of how appSettings are created and passed to the Context on Android. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9745 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../android/com/jme3/app/AndroidHarness.java | 39 ++++++++----------- .../jme3/system/android/JmeAndroidSystem.java | 16 ++++---- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/engine/src/android/com/jme3/app/AndroidHarness.java b/engine/src/android/com/jme3/app/AndroidHarness.java index 4759ecada..eccbceaf1 100644 --- a/engine/src/android/com/jme3/app/AndroidHarness.java +++ b/engine/src/android/com/jme3/app/AndroidHarness.java @@ -8,6 +8,7 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.NinePatchDrawable; import android.opengl.GLSurfaceView; import android.os.Bundle; +import android.util.Log; import android.view.*; import android.view.ViewGroup.LayoutParams; import android.widget.FrameLayout; @@ -158,11 +159,7 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt final DataObject data = new DataObject(); data.app = this.app; inConfigChange = true; - logger.log(Level.INFO, "app: {0}", app.hashCode()); - logger.log(Level.INFO, "ctx: {0}", ctx.hashCode()); - logger.log(Level.INFO, "view: {0}", view.hashCode()); - logger.log(Level.INFO, "isGLThreadPaused: {0}", isGLThreadPaused); - logger.log(Level.INFO, "inConfigChange: {0}", inConfigChange); + return data; } @@ -185,7 +182,7 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt final DataObject data = (DataObject) getLastNonConfigurationInstance(); if (data != null) { - logger.log(Level.INFO, "onCreate: onRetainNonConfigurationInstance is not null"); + logger.log(Level.INFO, "Using Retained App"); this.app = data.app; ctx = (OGLESContext) app.getContext(); @@ -193,16 +190,20 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt ctx.setSystemListener(this); layoutDisplay(); - logger.log(Level.INFO, "app: {0}", app.hashCode()); - logger.log(Level.INFO, "ctx: {0}", ctx.hashCode()); - logger.log(Level.INFO, "view: {0}", view.hashCode()); } else { - logger.log(Level.INFO, "onCreate: onRetainNonConfigurationInstance is null"); - + // Discover the screen reolution + //TODO try to find a better way to get a hand on the resolution + WindowManager wind = this.getWindowManager(); + Display disp = wind.getDefaultDisplay(); + Log.d("AndroidHarness", "Resolution from Window, width:" + disp.getWidth() + ", height: " + disp.getHeight()); + // Create Settings + logger.log(Level.INFO, "Creating settings"); AppSettings settings = new AppSettings(true); settings.setEmulateMouse(mouseEventsEnabled); settings.setEmulateMouseFlipAxis(mouseEventsInvertX, mouseEventsInvertY); + settings.setUseJoysticks(joystickEventsEnabled); + settings.setResolution(disp.getWidth(), disp.getHeight()); // Create application instance try { @@ -217,19 +218,10 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt ctx = (OGLESContext) app.getContext(); view = ctx.createView(eglConfigType, eglConfigVerboseLogging); - // Set the screen reolution - //TODO try to find a better way to get a hand on the resolution - WindowManager wind = this.getWindowManager(); - Display disp = wind.getDefaultDisplay(); - logger.log(Level.WARNING, "Resolution from Window: {0}, {1}", new Object[]{disp.getWidth(), disp.getHeight()}); - ctx.getSettings().setResolution(disp.getWidth(), disp.getHeight()); - - settings.setUseJoysticks(joystickEventsEnabled); - ctx.getSettings().setUseJoysticks(joystickEventsEnabled); - // AndroidHarness wraps the app as a SystemListener. ctx.setSystemListener(this); layoutDisplay(); + } catch (Exception ex) { handleError("Class " + appClass + " init failed", ex); setContentView(new TextView(this)); @@ -328,7 +320,7 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt protected void onDestroy() { final DataObject data = (DataObject) getLastNonConfigurationInstance(); if (data != null || inConfigChange) { - logger.info("onDestroy: found DataObject or inConfigChange"); + logger.info("In Config Change, not stopping app."); } else { if (app != null) { app.stop(!isGLThreadPaused); @@ -418,6 +410,9 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt public void layoutDisplay() { logger.log(Level.INFO, "Splash Screen Picture Resource ID: {0}", splashPicID); + if (view == null) { + logger.log(Level.INFO, "view is null!"); + } if (splashPicID != 0) { FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( LayoutParams.FILL_PARENT, diff --git a/engine/src/android/com/jme3/system/android/JmeAndroidSystem.java b/engine/src/android/com/jme3/system/android/JmeAndroidSystem.java index 074f175e3..f39633af6 100644 --- a/engine/src/android/com/jme3/system/android/JmeAndroidSystem.java +++ b/engine/src/android/com/jme3/system/android/JmeAndroidSystem.java @@ -35,7 +35,7 @@ public class JmeAndroidSystem extends JmeSystemDelegate { } catch (UnsatisfiedLinkError e) { } } - + @Override public void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width, int height) throws IOException { Bitmap bitmapImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); @@ -51,7 +51,7 @@ public class JmeAndroidSystem extends JmeSystemDelegate { bitmapImage.compress(compressFormat, 95, outStream); bitmapImage.recycle(); } - + @Override public ImageRaster createImageRaster(Image image, int slice) { if (image.getEfficentData() != null) { @@ -60,7 +60,7 @@ public class JmeAndroidSystem extends JmeSystemDelegate { return new DefaultImageRaster(image, slice); } } - + @Override public AssetManager newAssetManager(URL configFile) { logger.log(Level.INFO, "Creating asset manager with config {0}", configFile); @@ -78,7 +78,7 @@ public class JmeAndroidSystem extends JmeSystemDelegate { final String finalMsg = message; final String finalTitle = "Error in application"; final Activity context = JmeAndroidSystem.getActivity(); - + context.runOnUiThread(new Runnable() { @Override public void run() { @@ -88,7 +88,7 @@ public class JmeAndroidSystem extends JmeSystemDelegate { } }); } - + @Override public boolean showSettingsDialog(AppSettings sourceSettings, boolean loadFromRegistry) { return true; @@ -97,7 +97,9 @@ public class JmeAndroidSystem extends JmeSystemDelegate { @Override public JmeContext newContext(AppSettings settings, Type contextType) { initialize(settings); - return new OGLESContext(); + JmeContext ctx = new OGLESContext(); + ctx.setSettings(settings); + return ctx; } @Override @@ -116,7 +118,7 @@ public class JmeAndroidSystem extends JmeSystemDelegate { // JmeFormatter formatter = new JmeFormatter(); // Handler consoleHandler = new AndroidLogHandler(); // consoleHandler.setFormatter(formatter); -// +// // Logger log = Logger.getLogger(""); // for (Handler h : log.getHandlers()) { // log.removeHandler(h);