|
@@ -16,7 +16,6 @@ import android.widget.TextView;
|
|
import com.jme3.audio.AudioRenderer;
|
|
import com.jme3.audio.AudioRenderer;
|
|
import com.jme3.audio.android.AndroidAudioRenderer;
|
|
import com.jme3.audio.android.AndroidAudioRenderer;
|
|
import com.jme3.input.TouchInput;
|
|
import com.jme3.input.TouchInput;
|
|
-import com.jme3.input.android.AndroidInput;
|
|
|
|
import com.jme3.input.controls.TouchListener;
|
|
import com.jme3.input.controls.TouchListener;
|
|
import com.jme3.input.controls.TouchTrigger;
|
|
import com.jme3.input.controls.TouchTrigger;
|
|
import com.jme3.input.event.TouchEvent;
|
|
import com.jme3.input.event.TouchEvent;
|
|
@@ -26,10 +25,8 @@ import com.jme3.system.SystemListener;
|
|
import com.jme3.system.android.AndroidConfigChooser.ConfigType;
|
|
import com.jme3.system.android.AndroidConfigChooser.ConfigType;
|
|
import com.jme3.system.android.JmeAndroidSystem;
|
|
import com.jme3.system.android.JmeAndroidSystem;
|
|
import com.jme3.system.android.OGLESContext;
|
|
import com.jme3.system.android.OGLESContext;
|
|
-import com.jme3.util.JmeFormatter;
|
|
|
|
import java.io.PrintWriter;
|
|
import java.io.PrintWriter;
|
|
import java.io.StringWriter;
|
|
import java.io.StringWriter;
|
|
-import java.util.logging.Handler;
|
|
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
@@ -43,52 +40,64 @@ import java.util.logging.Logger;
|
|
public class AndroidHarness extends Activity implements TouchListener, DialogInterface.OnClickListener, SystemListener {
|
|
public class AndroidHarness extends Activity implements TouchListener, DialogInterface.OnClickListener, SystemListener {
|
|
|
|
|
|
protected final static Logger logger = Logger.getLogger(AndroidHarness.class.getName());
|
|
protected final static Logger logger = Logger.getLogger(AndroidHarness.class.getName());
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* The application class to start
|
|
* The application class to start
|
|
*/
|
|
*/
|
|
protected String appClass = "jme3test.android.Test";
|
|
protected String appClass = "jme3test.android.Test";
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* The jme3 application object
|
|
* The jme3 application object
|
|
*/
|
|
*/
|
|
protected Application app = null;
|
|
protected Application app = null;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* ConfigType.FASTEST is RGB565, GLSurfaceView default ConfigType.BEST is
|
|
* ConfigType.FASTEST is RGB565, GLSurfaceView default ConfigType.BEST is
|
|
* RGBA8888 or better if supported by the hardware
|
|
* RGBA8888 or better if supported by the hardware
|
|
*/
|
|
*/
|
|
protected ConfigType eglConfigType = ConfigType.FASTEST;
|
|
protected ConfigType eglConfigType = ConfigType.FASTEST;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* If true all valid and not valid egl configs are logged
|
|
* If true all valid and not valid egl configs are logged
|
|
*/
|
|
*/
|
|
protected boolean eglConfigVerboseLogging = false;
|
|
protected boolean eglConfigVerboseLogging = false;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* If true MouseEvents are generated from TouchEvents
|
|
* If true MouseEvents are generated from TouchEvents
|
|
*/
|
|
*/
|
|
protected boolean mouseEventsEnabled = true;
|
|
protected boolean mouseEventsEnabled = true;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Flip X axis
|
|
* Flip X axis
|
|
*/
|
|
*/
|
|
protected boolean mouseEventsInvertX = true;
|
|
protected boolean mouseEventsInvertX = true;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Flip Y axis
|
|
* Flip Y axis
|
|
*/
|
|
*/
|
|
protected boolean mouseEventsInvertY = true;
|
|
protected boolean mouseEventsInvertY = true;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* if true finish this activity when the jme app is stopped
|
|
* if true finish this activity when the jme app is stopped
|
|
*/
|
|
*/
|
|
protected boolean finishOnAppStop = true;
|
|
protected boolean finishOnAppStop = true;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* set to false if you don't want the harness to handle the exit hook
|
|
* set to false if you don't want the harness to handle the exit hook
|
|
*/
|
|
*/
|
|
protected boolean handleExitHook = true;
|
|
protected boolean handleExitHook = true;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Title of the exit dialog, default is "Do you want to exit?"
|
|
* Title of the exit dialog, default is "Do you want to exit?"
|
|
*/
|
|
*/
|
|
protected String exitDialogTitle = "Do you want to exit?";
|
|
protected String exitDialogTitle = "Do you want to exit?";
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Message of the exit dialog, default is "Use your home key to bring this
|
|
* Message of the exit dialog, default is "Use your home key to bring this
|
|
* app into the background or exit to terminate it."
|
|
* app into the background or exit to terminate it."
|
|
*/
|
|
*/
|
|
protected String exitDialogMessage = "Use your home key to bring this app into the background or exit to terminate it.";
|
|
protected String exitDialogMessage = "Use your home key to bring this app into the background or exit to terminate it.";
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Set the screen window mode. If screenFullSize is true, then the
|
|
* Set the screen window mode. If screenFullSize is true, then the
|
|
* notification bar and title bar are removed and the screen covers the
|
|
* notification bar and title bar are removed and the screen covers the
|
|
@@ -97,17 +106,20 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
|
* false, then the title bar is also displayed under the notification bar.
|
|
* false, then the title bar is also displayed under the notification bar.
|
|
*/
|
|
*/
|
|
protected boolean screenFullScreen = true;
|
|
protected boolean screenFullScreen = true;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* if screenShowTitle is true while screenFullScreen is false, then the
|
|
* if screenShowTitle is true while screenFullScreen is false, then the
|
|
* title bar is also displayed under the notification bar
|
|
* title bar is also displayed under the notification bar
|
|
*/
|
|
*/
|
|
protected boolean screenShowTitle = true;
|
|
protected boolean screenShowTitle = true;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Splash Screen picture Resource ID. If a Splash Screen is desired, set
|
|
* 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 to the value of the Resource ID (i.e. R.drawable.picname). If
|
|
* splashPicID = 0, then no splash screen will be displayed.
|
|
* splashPicID = 0, then no splash screen will be displayed.
|
|
*/
|
|
*/
|
|
protected int splashPicID = 0;
|
|
protected int splashPicID = 0;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Set the screen orientation, default is SENSOR
|
|
* Set the screen orientation, default is SENSOR
|
|
* ActivityInfo.SCREEN_ORIENTATION_* constants package
|
|
* ActivityInfo.SCREEN_ORIENTATION_* constants package
|
|
@@ -127,36 +139,11 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
|
final private String ESCAPE_EVENT = "TouchEscape";
|
|
final private String ESCAPE_EVENT = "TouchEscape";
|
|
private boolean firstDrawFrame = true;
|
|
private boolean firstDrawFrame = true;
|
|
|
|
|
|
- static {
|
|
|
|
- try {
|
|
|
|
- System.loadLibrary("bulletjme");
|
|
|
|
- } catch (UnsatisfiedLinkError e) {
|
|
|
|
- }
|
|
|
|
- JmeSystem.setSystemDelegate(new JmeAndroidSystem());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
- Logger log = logger;
|
|
|
|
- boolean bIsLogFormatSet = false;
|
|
|
|
- do {
|
|
|
|
- if (log.getHandlers().length == 0) {
|
|
|
|
- log = logger.getParent();
|
|
|
|
- if (log != null) {
|
|
|
|
- for (Handler h : log.getHandlers()) {
|
|
|
|
- //h.setFormatter(new SimpleFormatter());
|
|
|
|
- h.setFormatter(new JmeFormatter());
|
|
|
|
- bIsLogFormatSet = true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } while (log != null && !bIsLogFormatSet);
|
|
|
|
-
|
|
|
|
- JmeAndroidSystem.setResources(getResources());
|
|
|
|
JmeAndroidSystem.setActivity(this);
|
|
JmeAndroidSystem.setActivity(this);
|
|
-
|
|
|
|
if (screenFullScreen) {
|
|
if (screenFullScreen) {
|
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
|
@@ -171,12 +158,8 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
|
|
|
|
|
// Create Settings
|
|
// Create Settings
|
|
AppSettings settings = new AppSettings(true);
|
|
AppSettings settings = new AppSettings(true);
|
|
-
|
|
|
|
- // Create the input class
|
|
|
|
- AndroidInput input = new AndroidInput(this);
|
|
|
|
- input.setMouseEventsInvertX(mouseEventsInvertX);
|
|
|
|
- input.setMouseEventsInvertY(mouseEventsInvertY);
|
|
|
|
- input.setMouseEventsEnabled(mouseEventsEnabled);
|
|
|
|
|
|
+ settings.setEmulateMouse(mouseEventsEnabled);
|
|
|
|
+ settings.setEmulateMouseFlipAxis(mouseEventsInvertX, mouseEventsInvertY);
|
|
|
|
|
|
// Create application instance
|
|
// Create application instance
|
|
try {
|
|
try {
|
|
@@ -189,16 +172,15 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
|
app.setSettings(settings);
|
|
app.setSettings(settings);
|
|
app.start();
|
|
app.start();
|
|
ctx = (OGLESContext) app.getContext();
|
|
ctx = (OGLESContext) app.getContext();
|
|
- view = ctx.createView(input, eglConfigType, eglConfigVerboseLogging);
|
|
|
|
|
|
+ view = ctx.createView(eglConfigType, eglConfigVerboseLogging);
|
|
|
|
|
|
// Set the screen reolution
|
|
// Set the screen reolution
|
|
- WindowManager wind = this.getWindowManager();
|
|
|
|
- Display disp = wind.getDefaultDisplay();
|
|
|
|
- ctx.getSettings().setResolution(disp.getWidth(), disp.getHeight());
|
|
|
|
|
|
+// 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());
|
|
|
|
|
|
- AppSettings s = ctx.getSettings();
|
|
|
|
- logger.log(Level.INFO, "Settings: Width {0} Height {1}", new Object[]{s.getWidth(), s.getHeight()});
|
|
|
|
- //setting the Harness as the system listener
|
|
|
|
|
|
+ // AndroidHarness wraps the app as a SystemListener.
|
|
ctx.setSystemListener(this);
|
|
ctx.setSystemListener(this);
|
|
layoutDisplay();
|
|
layoutDisplay();
|
|
} catch (Exception ex) {
|
|
} catch (Exception ex) {
|
|
@@ -271,7 +253,6 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
|
@Override
|
|
@Override
|
|
protected void onStop() {
|
|
protected void onStop() {
|
|
super.onStop();
|
|
super.onStop();
|
|
-
|
|
|
|
logger.info("onStop");
|
|
logger.info("onStop");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -280,7 +261,6 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
|
if (app != null) {
|
|
if (app != null) {
|
|
app.stop(!isGLThreadPaused);
|
|
app.stop(!isGLThreadPaused);
|
|
}
|
|
}
|
|
-
|
|
|
|
logger.info("onDestroy");
|
|
logger.info("onDestroy");
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
}
|
|
}
|
|
@@ -293,6 +273,7 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
|
* Called when an error has occurred. By default, will show an error message
|
|
* Called when an error has occurred. By default, will show an error message
|
|
* to the user and print the exception/error to the log.
|
|
* to the user and print the exception/error to the log.
|
|
*/
|
|
*/
|
|
|
|
+ @Override
|
|
public void handleError(final String errorMsg, final Throwable t) {
|
|
public void handleError(final String errorMsg, final Throwable t) {
|
|
String stackTrace = "";
|
|
String stackTrace = "";
|
|
String title = "Error";
|
|
String title = "Error";
|
|
@@ -441,14 +422,6 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
|
app.requestClose(esc);
|
|
app.requestClose(esc);
|
|
}
|
|
}
|
|
|
|
|
|
- public void gainFocus() {
|
|
|
|
- app.gainFocus();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void loseFocus() {
|
|
|
|
- app.loseFocus();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public void destroy() {
|
|
public void destroy() {
|
|
if (app != null) {
|
|
if (app != null) {
|
|
app.destroy();
|
|
app.destroy();
|
|
@@ -457,4 +430,16 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
|
finish();
|
|
finish();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void gainFocus() {
|
|
|
|
+ if (app != null) {
|
|
|
|
+ app.gainFocus();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void loseFocus() {
|
|
|
|
+ if (app != null) {
|
|
|
|
+ app.loseFocus();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|