Changeset 1479
- Timestamp:
- 11/19/08 09:14:17 (7 weeks ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/dev/j2merosa/org.javarosa.clforms/src/org/javarosa/demo/shell/JavaRosaDemoShell.java
r1431 r1479 2 2 3 3 import java.util.Hashtable; 4 import java.util.Timer;5 import java.util.TimerTask;6 import java.util.Vector;7 4 8 5 import javax.microedition.midlet.MIDlet; 9 6 7 import org.javarosa.activity.splashscreen.SplashScreenActivity; 8 import org.javarosa.communication.http.HttpTransportModule; 10 9 import org.javarosa.communication.http.HttpTransportProperties; 11 10 import org.javarosa.core.Context; … … 20 19 import org.javarosa.core.model.storage.FormDefRMSUtility; 21 20 import org.javarosa.core.services.properties.JavaRosaPropertyRules; 21 import org.javarosa.core.services.transport.TransportMethod; 22 22 import org.javarosa.core.util.PropertyUtils; 23 23 import org.javarosa.core.util.WorkflowStack; 24 import org.javarosa.formmanager.activity.DisplayFormsHttpActivity; 25 import org.javarosa.formmanager.activity.GetFormHttpActivity; 26 import org.javarosa.formmanager.activity.GetFormListHttpActivity; 27 import org.javarosa.formmanager.FormManagerModule; 24 28 import org.javarosa.formmanager.activity.FormEntryActivity; 25 29 import org.javarosa.formmanager.activity.FormEntryContext; 26 30 import org.javarosa.formmanager.activity.FormListActivity; 27 31 import org.javarosa.formmanager.activity.FormTransportActivity; 32 import org.javarosa.formmanager.activity.ModelListActivity; 28 33 import org.javarosa.formmanager.activity.MemoryCheckActivity; 29 import org.javarosa.formmanager.activity.ModelListActivity;30 import org.javarosa.formmanager.properties.FormManagerProperties;31 34 import org.javarosa.formmanager.utility.FormDefSerializer; 32 35 import org.javarosa.formmanager.utility.TransportContext; … … 40 43 import org.javarosa.user.model.User; 41 44 import org.javarosa.xform.util.XFormUtils; 42 43 45 /** 44 46 * This is the shell for the JavaRosa demo that handles switching all of the views … … 70 72 } 71 73 72 private void startGCThread () {73 final int GC_INTERVAL = 1000;74 75 Timer timer = new Timer();76 timer.schedule(new TimerTask () {77 public void run () {78 System.gc();79 // System.out.print("gc attempted:: ");80 // System.out.println(Runtime.getRuntime().freeMemory());81 }82 }, GC_INTERVAL, GC_INTERVAL);83 }84 85 74 private void init() { 86 75 loadModules(); 87 76 loadProperties(); 88 startGCThread();89 90 boolean readSerialized = false;91 boolean genSerialized = false;92 if (genSerialized) {93 generateSerializedForms("/CHMTTL_Help.xhtml");94 // generateSerializedForms("/MobileSurvey.xhtml");95 }96 97 System.out.println("TOTAL MEM AVAIL: "+java.lang.Runtime.getRuntime().totalMemory());98 System.out.println("PRE LOAD FORM MEM: "+java.lang.Runtime.getRuntime().freeMemory());99 77 100 78 FormDefRMSUtility formDef = (FormDefRMSUtility)JavaRosaServiceProvider.instance().getStorageManager().getRMSStorageProvider().getUtility(FormDefRMSUtility.getUtilityName()); 101 79 if (formDef.getNumberOfRecords() == 0) { 102 if (readSerialized ) { 103 //load from serialized form. 104 FormDef form = new FormDef(); 105 form = XFormUtils.getFormFromSerializedResource("/CHMTTL.xhtml.serialized"); 106 //#if debug.output==verbose 107 System.out.println("SERIALIZE TEST:"); 108 System.out.println(form.getName()); 109 //#endif 110 formDef.writeToRMS(form); 111 //load from serialized form. 112 /*form = new FormDef(); 113 form = XFormUtils 114 .getFormFromSerializedResource("/MobileSurvey.xhtml.serialized"); 115 //#if debug.output==verbose 116 System.out.println("SERIALIZE TEST:"); 117 System.out.println(form.getName()); 118 //#endif 119 formDef.writeToRMS(form);*/ 120 }else{ 121 formDef.writeToRMS(XFormUtils.getFormFromResource("/CHMTTL_Help.xhtml")); 122 // formDef.writeToRMS(XFormUtils.getFormFromResource("/CHMTOpenDay2.xhtml")); 123 // formDef.writeToRMS(XFormUtils.getFormFromResource("/CHMTTLT2.xhtml")); 124 // formDef.writeToRMS(XFormUtils.getFormFromResource("/hmis-a_draft.xhtml")); 125 // formDef.writeToRMS(XFormUtils.getFormFromResource("/MobileSurvey.xhtml")); 126 } 127 } 128 129 System.out.println("POST LOAD FORM MEM: "+java.lang.Runtime.getRuntime().freeMemory()); 130 131 132 } 133 80 formDef.writeToRMS(XFormUtils.getFormFromResource("/CHMTTL_Help.xhtml")); 81 // formDef.writeToRMS(XFormUtils.getFormFromResource("/CHMTOpenDay2.xhtml")); 82 // formDef.writeToRMS(XFormUtils.getFormFromResource("/CHMTTLT2.xhtml")); 83 // formDef.writeToRMS(XFormUtils.getFormFromResource("/hmis-a_draft.xhtml")); 84 // formDef.writeToRMS(XFormUtils.getFormFromResource("/MobileSurvey.xhtml")); 85 } 86 } 87 134 88 private void loadModules() { 135 89 new RMSStorageModule().registerModule(context); 136 90 new XFormsModule().registerModule(context); 137 91 new CoreModelModule().registerModule(context); 138 //new HttpTransportModule().registerModule(context); 139 //new FormManagerModule().registerModule(context); 140 } 141 92 new HttpTransportModule().registerModule(context); 93 new FormManagerModule().registerModule(context); 94 //new CommunicationUIModule().registerModule(context); 95 } 96 142 97 private void generateSerializedForms(String originalResource) { 143 98 FormDef a = XFormUtils.getFormFromResource(originalResource); … … 172 127 } 173 128 129 130 174 131 private void workflowLaunch (IActivity returningActivity, String returnCode, Hashtable returnVals) { 175 132 if (returningActivity == null) { 176 133 177 /*launchActivity(new SplashScreenActivity(this, "/splash.gif"), context);134 launchActivity(new SplashScreenActivity(this, "/splash.gif"), context); 178 135 179 136 } else if (returningActivity instanceof SplashScreenActivity) { 180 */ 181 returningActivity = null; 137 182 138 //#if javarosa.dev.shortcuts 183 139 launchActivity(new FormListActivity(this, "Forms List"), context); 184 140 //#else 185 String passwordVAR = midlet.getAppProperty("username");141 String passwordVAR = midlet.getAppProperty("username"); 186 142 String usernameVAR = midlet.getAppProperty("password"); 187 143 if ((usernameVAR == null) || (passwordVAR == null)) 188 144 { 189 145 context.setElement("username","admin"); 190 context.setElement("password"," adat");146 context.setElement("password","p"); 191 147 } 192 148 else{ … … 203 159 if (returnVal == "USER_VALIDATED") { 204 160 User user = (User)returnVals.get(LoginActivity.USER); 205 206 161 MemoryCheckActivity memCheck = new MemoryCheckActivity(this); 207 162 if (user != null){ … … 209 164 context.setElement("USER", user); 210 165 } 211 212 166 launchActivity(memCheck, context); 213 167 } else if (returnVal == "USER_CANCELLED") { 214 168 exitShell(); 215 169 } 170 216 171 217 172 }else if (returningActivity instanceof MemoryCheckActivity) 218 173 { 219 174 launchActivity(new FormListActivity(this, "Forms List"), context); 220 } 221 else if (returningActivity instanceof FormListActivity) { 175 } else if (returningActivity instanceof FormListActivity) { 222 176 223 177 String returnVal = (String)returnVals.get(FormListActivity.COMMAND_KEY); … … 228 182 } else if (returnVal == Commands.CMD_SELECT_XFORM) { 229 183 launchFormEntryActivity(context, ((Integer)returnVals.get(FormListActivity.FORM_ID_KEY)).intValue(), -1); 230 } else if (returnVal == Commands.CMD_EXIT) {184 } else if (returnVal == Commands.CMD_EXIT) 231 185 exitShell(); 232 }else if (returnVal == Commands.CMD_ADD_USER) 233 launchActivity( new AddUserActivity(this),context); 186 else if (returnVal == Commands.CMD_ADD_USER) 187 {launchActivity( new AddUserActivity(this),context);} 188 else if (returnVal == Commands.CMD_GET_NEW_FORM) { 189 launchActivity(new GetFormListHttpActivity(this), context); 190 } 191 234 192 235 193 } else if (returningActivity instanceof ModelListActivity) { … … 256 214 257 215 } else if (returningActivity instanceof FormTransportActivity) { 258 259 relaunchListActivity(); 216 if(returnVals.get(FormTransportActivity.RETURN_KEY ) == FormTransportActivity.NEW_DESTINATION) { 217 TransportMethod transport = JavaRosaServiceProvider.instance().getTransportManager().getTransportMethod(JavaRosaServiceProvider.instance().getTransportManager().getCurrentTransportMethod()); 218 IActivity activity = transport.getDestinationRetrievalActivity(); 219 activity.setShell(this); 220 this.launchActivity(activity, context); 221 } else { 222 relaunchListActivity(); 223 } 260 224 261 225 //what is this for? … … 267 231 } 268 232 }*/ 269 }else if (returningActivity instanceof AddUserActivity) 270 launchActivity(new FormListActivity(this, "Forms List"), context); 271 233 } 234 else if (returningActivity instanceof AddUserActivity) 235 { 236 launchActivity(new FormListActivity(this, "Forms List"), context); 237 } 238 else if(returningActivity instanceof GetFormListHttpActivity){ 239 if(returnCode.equals(Constants.ACTIVITY_CANCEL)){ 240 launchActivity(new FormListActivity(this, "Forms List"), context); 241 }else if(returnCode.equals(Constants.ACTIVITY_COMPLETE)){ 242 launchActivity(new DisplayFormsHttpActivity(this,returnVals),context); 243 } 244 245 } 246 else if(returningActivity instanceof DisplayFormsHttpActivity){ 247 if(returnCode.equals(Constants.ACTIVITY_CANCEL)){ 248 launchActivity(new FormListActivity(this, "Forms List"), context); 249 } 250 else if(returnCode.equals(Constants.ACTIVITY_COMPLETE)){ 251 launchActivity(new GetFormHttpActivity(this,returnVals),context); 252 } 253 254 }else if(returningActivity instanceof GetFormHttpActivity){ 255 if(returnCode.equals(Constants.ACTIVITY_CANCEL)){ 256 launchActivity(new GetFormListHttpActivity(this), context); 257 }else if(returnCode.equals(Constants.ACTIVITY_COMPLETE)){ 258 launchActivity(new FormListActivity(this, "Forms List"), context); 259 } 260 261 262 } 272 263 } 273 264 … … 276 267 277 268 //default action 278 resumeActivity(suspendedActivity, context); 269 Context newContext = new Context(context); 270 newContext.addAllValues(returnVals); 271 resumeActivity(suspendedActivity, newContext); 279 272 } 280 273 … … 298 291 if (instanceID != -1) 299 292 formEntryContext.setInstanceID(instanceID); 293 300 294 launchActivity(entryActivity, formEntryContext); 301 295 } … … 347 341 } 348 342 349 //need 'addpropery' too.350 private String initProperty(String propName, String defaultValue) {351 Vector propVal = JavaRosaServiceProvider.instance().getPropertyManager().getProperty(propName);352 if (propVal == null || propVal.size() == 0) {353 propVal = new Vector();354 propVal.addElement(defaultValue);355 JavaRosaServiceProvider.instance().getPropertyManager().setProperty(propName, propVal);356 //#if debug.output==verbose357 System.out.println("No default value for [" + propName358 + "]; setting to [" + defaultValue + "]"); // debug359 //#endif360 return defaultValue;361 }/*else {362 propVal.addElement(defaultValue);363 JavaRosaServiceProvider.instance().getPropertyManager().setProperty(propName, propVal);364 //#if debug.output==verbose365 System.out.println("added value for [" + propName366 + "]; setting to [" + defaultValue + "]"); // debug367 //#endif368 return defaultValue;369 }*/370 return (String) propVal.elementAt(0);371 }372 373 343 private void loadProperties() { 374 344 JavaRosaServiceProvider.instance().getPropertyManager().addRules(new JavaRosaPropertyRules()); 375 JavaRosaServiceProvider.instance().getPropertyManager().addRules(new HttpTransportProperties()); 376 JavaRosaServiceProvider.instance().getPropertyManager().addRules(new FormManagerProperties()); 377 378 initProperty("DeviceID", PropertyUtils.genGUID(25)); 379 initProperty(FormManagerProperties.VIEW_TYPE_PROPERTY, FormManagerProperties.VIEW_CLFORMS); 380 initProperty(HttpTransportProperties.POST_URL_LIST_PROPERTY, "http://survey.cell-life.org/admin/post2limeNew.php"); 381 Vector v = JavaRosaServiceProvider.instance().getPropertyManager().getProperty(HttpTransportProperties.POST_URL_LIST_PROPERTY); 382 v.addElement("http://dev.cell-life.org/javarosa/web/limesurvey/admin/post2lime.php"); 383 JavaRosaServiceProvider.instance().getPropertyManager().setProperty(HttpTransportProperties.POST_URL_LIST_PROPERTY, v); 384 // initProperty(HttpTransportProperties.POST_URL_LIST_PROPERTY, "http://dev.cell-life.org/javarosa/web/limesurvey/admin/post2lime.php"); 385 // initProperty(HttpTransportProperties.POST_URL_PROPERTY, "http://dev.cell-life.org/javarosa/web/limesurvey/admin/post2lime.php"); 386 initProperty(HttpTransportProperties.POST_URL_PROPERTY, "http://survey.cell-life.org/admin/post2limeNew.php"); 387 // initProperty(HttpTransportProperties.POST_URL_LIST_PROPERTY, "http://update.cell-life.org/save_dump_org.php"); 388 // initProperty(HttpTransportProperties.POST_URL_PROPERTY, "http://update.cell-life.org/save_dump_org.php"); 389 // initProperty(FormManagerProperties.VIEW_TYPE_PROPERTY, FormManagerProperties.VIEW_CLFORMS); 390 // initProperty(HttpTransportProperties.POST_URL_LIST_PROPERTY, "http://openrosa.org/testsubmit.html"); 391 // initProperty(HttpTransportProperties.POST_URL_PROPERTY, "http://openrosa.org/testsubmit.html"); 392 } 345 //JavaRosaServiceProvider.instance().getPropertyManager().addRules(new DemoAppProperties()); 346 347 PropertyUtils.initializeProperty("DeviceID", PropertyUtils.genGUID(25)); 348 PropertyUtils.initializeProperty(HttpTransportProperties.POST_URL_LIST_PROPERTY, "http://dev.cell-life.org/javarosa/web/limesurvey/admin/post2lime.php"); 349 PropertyUtils.initializeProperty(HttpTransportProperties.POST_URL_PROPERTY, "http://dev.cell-life.org/javarosa/web/limesurvey/admin/post2lime.php"); 350 PropertyUtils.initializeProperty(HttpTransportProperties.POST_URL_LIST_PROPERTY, "http://survey.cell-life.org/admin/post2limeNew.php"); 351 PropertyUtils.initializeProperty(HttpTransportProperties.GET_URL_PROPERTY, "http://update.cell-life.org/save_dump.php"); 352 353 } 354 355 393 356 }
