diff options
author | Sven Gothel <[email protected]> | 2011-09-28 17:10:40 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-09-28 17:10:40 +0200 |
commit | 659476e002a9bfe6b35b00ea1c46fc67c62ba703 (patch) | |
tree | 06ff2b28c42f7f850bfda75964ffc791bc594072 /src/android/com | |
parent | c9575115e214c94501b923599cc5d64778099829 (diff) |
Android Activity Launching (jogl.test)
Launching activity is in: jogl.android-launcher.apk
and directly derives from NewtLauncherActivity.
It daisy chains apk's via ClassLoaderUtil:
- gluegen-rt.apk
- jogl.all-android.apk
- jogl.test.apk (*)
(*) This has to made configurable so the generic NewtLauncherActivity
can be reused by any user application.
After preparing the ClassLoader (see above),
NewtLauncherActivity instanciates the configurable
user Activity and passes all it's activity calls down to it.
Diffstat (limited to 'src/android/com')
7 files changed, 269 insertions, 266 deletions
diff --git a/src/android/com/jogamp/android/launcher/ClassLoaderUtil.java b/src/android/com/jogamp/android/launcher/ClassLoaderUtil.java index 746fad745..df4a9e7b8 100644 --- a/src/android/com/jogamp/android/launcher/ClassLoaderUtil.java +++ b/src/android/com/jogamp/android/launcher/ClassLoaderUtil.java @@ -40,34 +40,31 @@ public class ClassLoaderUtil { public static final String packageGlueGen = "com.jogamp.common"; public static final String packageJogl = "javax.media.opengl"; + public static final String packageJoglTest = "com.jogamp.opengl.test"; public static final String dexPathName= "jogampDex"; public static final String libPathName = "/data/data/com.jogamp.common/lib/:/data/data/javax.media.opengl/lib/"; - public static synchronized ClassLoader createJogampClassLoaderSingleton(Context ctx, boolean debugOn) { + public static synchronized ClassLoader createJogampClassLoaderSingleton(Context ctx) { Log.d(TAG, "S"); - if(debugOn) { - System.setProperty("jogl.debug", "all"); - System.setProperty("jogamp.debug.JNILibLoader", "true"); - System.setProperty("jogamp.debug.NativeLibrary", "true"); - } - String apkGlueGen = null; String apkJogl = null; + String apkJoglTest = null; try { apkGlueGen = ctx.getPackageManager().getApplicationInfo(packageGlueGen,0).sourceDir; apkJogl = ctx.getPackageManager().getApplicationInfo(packageJogl,0).sourceDir; + apkJoglTest = ctx.getPackageManager().getApplicationInfo(packageJoglTest,0).sourceDir; } catch (PackageManager.NameNotFoundException e) { Log.d(TAG, "error: "+e, e); } - if(null == apkGlueGen || null == apkJogl) { - Log.d(TAG, "not found: gluegen <"+apkGlueGen+">, jogl <"+apkJogl+">"); + if(null == apkGlueGen || null == apkJogl || null == apkJoglTest) { + Log.d(TAG, "not found: gluegen <"+apkGlueGen+">, jogl <"+apkJogl+">, jogl-test <"+apkJoglTest+">"); return null; } - final String cp = apkGlueGen + ":" + apkJogl ; + final String cp = apkGlueGen + ":" + apkJogl + ":" + apkJoglTest ; Log.d(TAG, "cp: " + cp); final File dexPath = ctx.getDir(dexPathName, Context.MODE_WORLD_READABLE); diff --git a/src/android/com/jogamp/android/launcher/NEWTLauncherActivity.java b/src/android/com/jogamp/android/launcher/NEWTLauncherActivity.java new file mode 100644 index 000000000..86e98a38c --- /dev/null +++ b/src/android/com/jogamp/android/launcher/NEWTLauncherActivity.java @@ -0,0 +1,229 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.android.launcher; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; +import android.util.Log; + +public abstract class NEWTLauncherActivity extends Activity { + static final String TAG = "NEWTLauncherActivity"; + TextView tv = null; + Method mOnCreate, mOnDestroy, mOnPause, mOnRestart, mOnResume, + mOnStart, mOnStop, mSetIsInvokedByExternalActivity; + Class<?> activityClazz = null; + Object activityObject = null; + + public abstract String getDownstreamActivityName(); + + @Override + public void onCreate(Bundle savedInstanceState) { + Log.d(TAG, "onCreate - S"); + super.onCreate(savedInstanceState); + + // System.setProperty("nativewindow.debug", "all"); + // System.setProperty("jogl.debug", "all"); + // System.setProperty("newt.debug", "all"); + System.setProperty("newt.debug.Window", "true"); + // System.setProperty("newt.debug.Window.MouseEvent", "true"); + // System.setProperty("newt.debug.Window.KeyEvent", "true"); + // System.setProperty("jogamp.debug.IOUtil", "true"); + // System.setProperty("jogamp.debug.JNILibLoader", "true"); + // System.setProperty("jogamp.debug.NativeLibrary", "true"); + // System.setProperty("jogamp.debug.NativeLibrary.Lookup", "true"); + + ClassLoader cl = ClassLoaderUtil.createJogampClassLoaderSingleton(this); + if(null != cl) { + try { + activityClazz = Class.forName(getDownstreamActivityName(), true, cl); + Log.d(TAG, "Activity Clazz "+activityClazz); + activityObject = createInstance(activityClazz, null); + Log.d(TAG, "Activity Object "+activityObject); + mOnCreate = activityClazz.getMethod("onCreate", Bundle.class); + mOnDestroy = activityClazz.getMethod("onDestroy"); + mOnPause = activityClazz.getMethod("onPause"); + mOnRestart = activityClazz.getMethod("onRestart"); + mOnResume = activityClazz.getMethod("onResume"); + mOnStart = activityClazz.getMethod("onStart"); + mOnStop = activityClazz.getMethod("onStop"); + mSetIsInvokedByExternalActivity = activityClazz.getMethod("setIsInvokedByExternalActivity", Activity.class); + } catch (Exception e) { + Log.d(TAG, "error: "+e, e); + throw new RuntimeException(e); + } + } + + if( null == mOnCreate || null == mOnDestroy || null == mOnPause || + null == mOnRestart || null == mOnResume || + null == mSetIsInvokedByExternalActivity ) { + RuntimeException e = new RuntimeException("XXX - incomplete method set"); + Log.d(TAG, "error: "+e, e); + throw e; + } + callMethod(activityObject, mSetIsInvokedByExternalActivity, this); + + callMethod(activityObject, mOnCreate, savedInstanceState); + Log.d(TAG, "onCreate - X"); + } + + @Override + public void onStart() { + Log.d(TAG, "onStart - S"); + callMethod(activityObject, mOnStart); + super.onStart(); + Log.d(TAG, "onStart - X"); + } + + @Override + public void onRestart() { + Log.d(TAG, "onRestart - S"); + callMethod(activityObject, mOnRestart); + super.onRestart(); + Log.d(TAG, "onRestart - X"); + } + + @Override + public void onResume() { + Log.d(TAG, "onResume - S"); + callMethod(activityObject, mOnResume); + super.onResume(); + Log.d(TAG, "onResume - X"); + } + + @Override + public void onPause() { + Log.d(TAG, "onPause - S"); + callMethod(activityObject, mOnPause); + super.onPause(); + Log.d(TAG, "onPause - X"); + } + + @Override + public void onStop() { + Log.d(TAG, "onStop - S"); + callMethod(activityObject, mOnStop); + super.onStop(); + Log.d(TAG, "onStop - X"); + } + + @Override + public void onDestroy() { + Log.d(TAG, "onDestroy - S"); + callMethod(activityObject, mOnDestroy); + super.onDestroy(); + Log.d(TAG, "onDestroy - X"); + } + + /** + * @throws JogampRuntimeException if the instance can not be created. + */ + public static final Object createInstance(Class<?> clazz, Class<?>[] cstrArgTypes, Object ... cstrArgs) + throws RuntimeException + { + return createInstance(getConstructor(clazz, cstrArgTypes), cstrArgs); + } + + public static final Object createInstance(Constructor<?> cstr, Object ... cstrArgs) + throws RuntimeException + { + try { + return cstr.newInstance(cstrArgs); + } catch (Exception e) { + Throwable t = e; + if (t instanceof InvocationTargetException) { + t = ((InvocationTargetException) t).getTargetException(); + } + if (t instanceof Error) { + throw (Error) t; + } + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } + throw new RuntimeException("can not create instance of "+cstr.getName(), t); + } + } + + /** + * @throws JogampRuntimeException if the constructor can not be delivered. + */ + protected static final Constructor<?> getConstructor(Class<?> clazz, Class<?> ... cstrArgTypes) + throws RuntimeException { + try { + if(null == cstrArgTypes) { + cstrArgTypes = zeroTypes; + } + return clazz.getDeclaredConstructor(cstrArgTypes); + } catch (NoSuchMethodException ex) { + throw new RuntimeException("Constructor: '" + clazz + "(" + asString(cstrArgTypes) + ")' not found", ex); + } + } + + protected static final Class<?>[] zeroTypes = new Class[0]; + + protected static final String asString(Class<?>[] argTypes) { + StringBuffer args = new StringBuffer(); + boolean coma = false; + if(null != argTypes) { + for (int i = 0; i < argTypes.length; i++) { + if(coma) { + args.append(", "); + } + args.append(argTypes[i].getName()); + coma = true; + } + } + return args.toString(); + } + + protected static final Object callMethod(Object instance, Method method, Object ... args) + throws RuntimeException + { + try { + return method.invoke(instance, args); + } catch (Exception e) { + Throwable t = e; + if (t instanceof InvocationTargetException) { + t = ((InvocationTargetException) t).getTargetException(); + } + if (t instanceof Error) { + throw (Error) t; + } + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } + throw new RuntimeException("calling "+method+" failed", t); + } + } + + +} diff --git a/src/android/com/jogamp/android/launcher/NEWTLauncherGearsActivity.java b/src/android/com/jogamp/android/launcher/NEWTLauncherGearsActivity.java deleted file mode 100644 index 785590fd7..000000000 --- a/src/android/com/jogamp/android/launcher/NEWTLauncherGearsActivity.java +++ /dev/null @@ -1,140 +0,0 @@ -/** - * Copyright 2011 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package com.jogamp.android.launcher; - -import java.lang.reflect.Method; - -import dalvik.system.PathClassLoader; - -import android.app.Activity; -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.widget.TextView; -import android.util.Log; - -public class NEWTLauncherGearsActivity extends Activity { - static final String TAG = "JoglLauncherActivity"; - TextView tv = null; - - @Override - public void onCreate(Bundle savedInstanceState) { - Log.d(TAG, "onCreate - S"); - super.onCreate(savedInstanceState); - - String packageGlueGen = "com.jogamp.common"; - String apkGlueGen = null; - String packageJogl = "javax.media.opengl"; - String apkJogl = null; - - String clazzMDName= "jogamp.newt.driver.android.MD"; - Method mdGetInfo = null; - - try { - apkGlueGen = getPackageManager().getApplicationInfo(packageGlueGen,0).sourceDir; - apkJogl = getPackageManager().getApplicationInfo(packageJogl,0).sourceDir; - } catch (PackageManager.NameNotFoundException e) { - Log.d(TAG, "error: "+e, e); - } - if(null == apkGlueGen || null == apkJogl) { - Log.d(TAG, "not found: gluegen <"+apkGlueGen+">, jogl <"+apkJogl+">"); - } else { - String cp = apkGlueGen + ":" + apkJogl ; - Log.d(TAG, "cp: " + cp); - - // add path to apk that contains classes you wish to load - PathClassLoader pathClassLoader = new dalvik.system.PathClassLoader( - cp, - ClassLoader.getSystemClassLoader()); - - try { - Class clazzMD= Class.forName(clazzMDName, true, pathClassLoader); - Log.d(TAG, "MD: "+clazzMD); - mdGetInfo = clazzMD.getMethod("getInfo"); - } catch (Exception e) { - Log.d(TAG, "error: "+e, e); - } - } - - String mdInfo = null; - try { - mdInfo = (String) mdGetInfo.invoke(null); - } catch (Exception e) { - Log.d(TAG, "error: "+e, e); - } - tv = new TextView(this); - if(null != mdInfo) { - tv.setText(mdInfo); - } else { - tv.setText("mdInfo n/a"); - } - setContentView(tv); - Log.d(TAG, "onCreate - X"); - } - - @Override - public void onStart() { - Log.d(TAG, "onStart - S"); - super.onStart(); - Log.d(TAG, "onStart - X"); - } - - @Override - public void onRestart() { - Log.d(TAG, "onRestart - S"); - super.onRestart(); - Log.d(TAG, "onRestart - X"); - } - - @Override - public void onResume() { - Log.d(TAG, "onResume - S"); - super.onResume(); - Log.d(TAG, "onResume - X"); - } - - @Override - public void onPause() { - Log.d(TAG, "onPause - S"); - super.onPause(); - Log.d(TAG, "onPause - X"); - } - - @Override - public void onStop() { - Log.d(TAG, "onStop - S"); - super.onStop(); - Log.d(TAG, "onStop - X"); - } - - @Override - public void onDestroy() { - Log.d(TAG, "onDestroy - S"); - super.onDestroy(); - Log.d(TAG, "onDestroy - X"); - } -} diff --git a/src/android/com/jogamp/android/launcher/NEWTLauncherGearsES1Activity.java b/src/android/com/jogamp/android/launcher/NEWTLauncherGearsES1Activity.java new file mode 100644 index 000000000..bc179eb9f --- /dev/null +++ b/src/android/com/jogamp/android/launcher/NEWTLauncherGearsES1Activity.java @@ -0,0 +1,11 @@ +package com.jogamp.android.launcher; + +public class NEWTLauncherGearsES1Activity extends NEWTLauncherActivity { + static String demo = "com.jogamp.opengl.test.android.NEWTGearsES1Activity"; + + @Override + public String getDownstreamActivityName() { + return demo; + } + +} diff --git a/src/android/com/jogamp/android/launcher/NEWTLauncherGearsES2Activity.java b/src/android/com/jogamp/android/launcher/NEWTLauncherGearsES2Activity.java new file mode 100644 index 000000000..170d1b5a7 --- /dev/null +++ b/src/android/com/jogamp/android/launcher/NEWTLauncherGearsES2Activity.java @@ -0,0 +1,11 @@ +package com.jogamp.android.launcher; + +public class NEWTLauncherGearsES2Activity extends NEWTLauncherActivity { + static String demo = "com.jogamp.opengl.test.android.NEWTGearsES2Activity"; + + @Override + public String getDownstreamActivityName() { + return demo; + } + +} diff --git a/src/android/com/jogamp/android/launcher/NEWTLauncherGraphUIActivity.java b/src/android/com/jogamp/android/launcher/NEWTLauncherGraphUIActivity.java new file mode 100644 index 000000000..e1bab1e70 --- /dev/null +++ b/src/android/com/jogamp/android/launcher/NEWTLauncherGraphUIActivity.java @@ -0,0 +1,11 @@ +package com.jogamp.android.launcher; + +public class NEWTLauncherGraphUIActivity extends NEWTLauncherActivity { + static String demo = "com.jogamp.opengl.test.android.NEWTGraphUIActivity"; + + @Override + public String getDownstreamActivityName() { + return demo; + } + +} diff --git a/src/android/com/jogamp/android/launcher/NEWTLauncherVersionActivity.java b/src/android/com/jogamp/android/launcher/NEWTLauncherVersionActivity.java deleted file mode 100644 index c07b502fb..000000000 --- a/src/android/com/jogamp/android/launcher/NEWTLauncherVersionActivity.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * Copyright 2011 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ -package com.jogamp.android.launcher; - -import java.lang.reflect.Method; - -import dalvik.system.DexClassLoader; -import dalvik.system.PathClassLoader; - -import android.app.Activity; -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.widget.TextView; -import android.util.Log; - -public class NEWTLauncherVersionActivity extends Activity { - static final String TAG = "JoglLauncherActivity"; - TextView tv = null; - - @Override - public void onCreate(Bundle savedInstanceState) { - Log.d(TAG, "onCreate - S"); - super.onCreate(savedInstanceState); - - String clazzMDName= "jogamp.newt.driver.android.MD"; - String mdInfo = null; - - ClassLoader cl = ClassLoaderUtil.createJogampClassLoaderSingleton(this, true); - if(null != cl) { - try { - Class clazzMD= Class.forName(clazzMDName, true, cl); - Log.d(TAG, "MD: "+clazzMD); - Method mdGetInfo = clazzMD.getMethod("getInfo"); - mdInfo = (String) mdGetInfo.invoke(null); - } catch (Exception e) { - Log.d(TAG, "error: "+e, e); - } - } - - tv = new TextView(this); - if(null != mdInfo) { - tv.setText(mdInfo); - } else { - tv.setText("mdInfo n/a"); - } - setContentView(tv); - Log.d(TAG, "onCreate - X"); - } - - @Override - public void onStart() { - Log.d(TAG, "onStart - S"); - super.onStart(); - Log.d(TAG, "onStart - X"); - } - - @Override - public void onRestart() { - Log.d(TAG, "onRestart - S"); - super.onRestart(); - Log.d(TAG, "onRestart - X"); - } - - @Override - public void onResume() { - Log.d(TAG, "onResume - S"); - super.onResume(); - Log.d(TAG, "onResume - X"); - } - - @Override - public void onPause() { - Log.d(TAG, "onPause - S"); - super.onPause(); - Log.d(TAG, "onPause - X"); - } - - @Override - public void onStop() { - Log.d(TAG, "onStop - S"); - super.onStop(); - Log.d(TAG, "onStop - X"); - } - - @Override - public void onDestroy() { - Log.d(TAG, "onDestroy - S"); - super.onDestroy(); - Log.d(TAG, "onDestroy - X"); - } -} |