diff options
author | Sven Gothel <[email protected]> | 2013-01-18 02:23:44 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-01-18 02:23:44 +0100 |
commit | 896a0821b78c9aadf38e0d881922e03849584984 (patch) | |
tree | 45a138a9adddd6118446ad67797d122ccd300451 /src | |
parent | 9c189b4202b25f08b0bddd9dcda4f085ec85912b (diff) |
Sync LauncherUtil w/ GlueGen commit 1b9f0739ecc25105384b557afa698c42e08d4cc6 (adding main-cmdline-args)
Diffstat (limited to 'src')
-rw-r--r-- | src/test/com/jogamp/opengl/test/android/LauncherUtil.java | 70 |
1 files changed, 57 insertions, 13 deletions
diff --git a/src/test/com/jogamp/opengl/test/android/LauncherUtil.java b/src/test/com/jogamp/opengl/test/android/LauncherUtil.java index 11416cd67..d5caeef9b 100644 --- a/src/test/com/jogamp/opengl/test/android/LauncherUtil.java +++ b/src/test/com/jogamp/opengl/test/android/LauncherUtil.java @@ -67,9 +67,11 @@ public class LauncherUtil { static final String PKG = "pkg"; + static final String ARG = "arg"; + public static abstract class BaseActivityLauncher extends Activity { final OrderedProperties props = new OrderedProperties(); - + final ArrayList<String> args = new ArrayList<String>(); /** * Returns the default {@link LauncherUtil#LAUNCH_ACTIVITY_NORMAL} action. * <p> @@ -86,6 +88,14 @@ public class LauncherUtil { */ public final OrderedProperties getProperties() { return props; } + /** + * Returns the commandline arguments, which are being propagated to the target activity. + * <p> + * Maybe be used to set custom commandline arguments. + * </p> + */ + public final ArrayList<String> getArguments() { return args; } + /** Custom initialization hook which can be overriden to setup data, e.g. fill the properties retrieved by {@link #getProperties()}. */ public void init() { } @@ -108,6 +118,7 @@ public class LauncherUtil { data.setActivityName(getActivityName()); data.addAllPackages(getPackages()); data.addAllProperties(props); + data.addAllArguments(args); final Intent intent = LauncherUtil.getIntent(getAction(), data); Log.d(getClass().getSimpleName(), "Launching Activity: "+intent); @@ -127,6 +138,9 @@ public class LauncherUtil { if(key.equals(PKG)) { throw new IllegalArgumentException("Illegal property key, '"+PKG+"' is reserved"); } + if(key.equals(ARG)) { + throw new IllegalArgumentException("Illegal property key, '"+ARG+"' is reserved"); + } final String oval = map.put(key, value); if(null != oval) { map.put(key, oval); // restore @@ -175,6 +189,7 @@ public class LauncherUtil { String activityName = null; ArrayList<String> packages = new ArrayList<String>(); OrderedProperties properties = new OrderedProperties(); + ArrayList<String> arguments = new ArrayList<String>(); public final void setActivityName(String name) { activityName = name; } public final String getActivityName() { return activityName; } @@ -201,7 +216,13 @@ public class LauncherUtil { } public final String getProperty(String key) { return properties.getProperty(key); } public final OrderedProperties getProperties() { return properties; } - public final List<String> getPropertyKeys() { return properties.getPropertyKeys(); } + public final List<String> getPropertyKeys() { return properties.getPropertyKeys(); } + + public final void addArgument(String arg) { arguments.add(arg); } + public final void addAllArguments(List<String> args) { + arguments.addAll(args); + } + public final ArrayList<String> getArguments() { return arguments; } public final Uri getUri() { StringBuilder sb = new StringBuilder(); @@ -217,15 +238,23 @@ public class LauncherUtil { needsSep = true; } } - Iterator<String> argKeys = properties.keyList.iterator(); - while(argKeys.hasNext()) { + Iterator<String> propKeys = properties.keyList.iterator(); + while(propKeys.hasNext()) { if(needsSep) { sb.append(AMPER); } - final String key = argKeys.next(); + final String key = propKeys.next(); sb.append(key).append(ASSIG).append(properties.map.get(key)); needsSep = true; } + Iterator<String> args = arguments.iterator(); + while(args.hasNext()) { + if(needsSep) { + sb.append(AMPER); + } + sb.append(ARG).append(ASSIG).append(args.next()); + needsSep = true; + } return Uri.parse(sb.toString()); } @@ -255,7 +284,7 @@ public class LauncherUtil { int q_b = q_e + 1; // next term q_e = q.indexOf(AMPER, q_b); if(0 == q_e) { - // single seperator + // single separator continue; } if(0 > q_e) { @@ -274,13 +303,18 @@ public class LauncherUtil { throw new IllegalArgumentException("Empty package name: part <"+part+">, query <"+q+"> of "+uri); } data.addPackage(v); + } else if(k.equals(ARG)) { + if(v.length()==0) { + throw new IllegalArgumentException("Empty argument name: part <"+part+">, query <"+q+"> of "+uri); + } + data.addArgument(v); } else { data.setProperty(k, v); } } else { // property key only - if(part.equals(PKG)) { - throw new IllegalArgumentException("Empty package name: part <"+part+">, query <"+q+"> of "+uri); + if( part.equals(PKG) || part.equals(ARG) ) { + throw new IllegalArgumentException("Reserved key <"+part+"> in query <"+q+"> of "+uri); } data.setProperty(part, EMPTY); } @@ -306,21 +340,31 @@ public class LauncherUtil { args = new String[] { SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1&"+PKG+"=javax.pack2&"+PKG+"=com.jogamp.pack3&jogamp.common.debug=true&com.jogamp.test=false", SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1&jogamp.common.debug=true&com.jogamp.test=false", - SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1" + SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1", + SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1&"+PKG+"=javax.pack2&"+PKG+"=com.jogamp.pack3&jogamp.common.debug=true&com.jogamp.test=false&"+ARG+"=arg1&"+ARG+"=arg2=arg2value&"+ARG+"=arg3", + SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1&jogamp.common.debug=true&com.jogamp.test=false&"+ARG+"=arg1&"+ARG+"=arg2=arg2value&"+ARG+"=arg3", + SCHEME+"://"+HOST+"/com.jogamp.TestActivity?"+PKG+"=jogamp.pack1&"+ARG+"=arg1&"+ARG+"=arg2=arg2value&"+ARG+"=arg3" }; } + int errors = 0; for(int i=0; i<args.length; i++) { String uri_s = args[i]; Uri uri0 = Uri.parse(uri_s); DataSet data = DataSet.create(uri0); if(null == data) { + errors++; System.err.println("Error: NULL JogAmpLauncherUtil: <"+uri_s+"> -> "+uri0+" -> NULL"); - } - Uri uri1 = data.getUri(); - if(!uri0.equals(uri1)) { - System.err.println("Error: Not equal: <"+uri_s+"> -> "+uri0+" -> "+uri1); + } else { + Uri uri1 = data.getUri(); + if(!uri0.equals(uri1)) { + errors++; + System.err.println("Error: Not equal: <"+uri_s+"> -> "+uri0+" -> "+uri1); + } else { + System.err.println("OK: "+uri1); + } } } + System.err.println("LauncherUtil Self Test: Errors: "+errors); } } |