Changeset 1479

Show
Ignore:
Timestamp:
11/19/08 09:14:17 (7 weeks ago)
Author:
alfred
Message:

adjusted to include get new forms feature

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/dev/j2merosa/org.javarosa.clforms/src/org/javarosa/demo/shell/JavaRosaDemoShell.java

    r1431 r1479  
    22 
    33import java.util.Hashtable; 
    4 import java.util.Timer; 
    5 import java.util.TimerTask; 
    6 import java.util.Vector; 
    74 
    85import javax.microedition.midlet.MIDlet; 
    96 
     7import org.javarosa.activity.splashscreen.SplashScreenActivity; 
     8import org.javarosa.communication.http.HttpTransportModule; 
    109import org.javarosa.communication.http.HttpTransportProperties; 
    1110import org.javarosa.core.Context; 
     
    2019import org.javarosa.core.model.storage.FormDefRMSUtility; 
    2120import org.javarosa.core.services.properties.JavaRosaPropertyRules; 
     21import org.javarosa.core.services.transport.TransportMethod; 
    2222import org.javarosa.core.util.PropertyUtils; 
    2323import org.javarosa.core.util.WorkflowStack; 
     24import org.javarosa.formmanager.activity.DisplayFormsHttpActivity; 
     25import org.javarosa.formmanager.activity.GetFormHttpActivity; 
     26import org.javarosa.formmanager.activity.GetFormListHttpActivity; 
     27import org.javarosa.formmanager.FormManagerModule; 
    2428import org.javarosa.formmanager.activity.FormEntryActivity; 
    2529import org.javarosa.formmanager.activity.FormEntryContext; 
    2630import org.javarosa.formmanager.activity.FormListActivity; 
    2731import org.javarosa.formmanager.activity.FormTransportActivity; 
     32import org.javarosa.formmanager.activity.ModelListActivity; 
    2833import org.javarosa.formmanager.activity.MemoryCheckActivity; 
    29 import org.javarosa.formmanager.activity.ModelListActivity; 
    30 import org.javarosa.formmanager.properties.FormManagerProperties; 
    3134import org.javarosa.formmanager.utility.FormDefSerializer; 
    3235import org.javarosa.formmanager.utility.TransportContext; 
     
    4043import org.javarosa.user.model.User; 
    4144import org.javarosa.xform.util.XFormUtils; 
    42  
    4345/** 
    4446 * This is the shell for the JavaRosa demo that handles switching all of the views 
     
    7072        } 
    7173 
    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  
    8574        private void init() { 
    8675                loadModules(); 
    8776                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()); 
    9977                 
    10078                FormDefRMSUtility formDef = (FormDefRMSUtility)JavaRosaServiceProvider.instance().getStorageManager().getRMSStorageProvider().getUtility(FormDefRMSUtility.getUtilityName()); 
    10179                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         
    13488        private void loadModules() { 
    13589                new RMSStorageModule().registerModule(context); 
    13690                new XFormsModule().registerModule(context); 
    13791                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         
    14297        private void generateSerializedForms(String originalResource) { 
    14398                FormDef a = XFormUtils.getFormFromResource(originalResource); 
     
    172127        } 
    173128 
     129 
     130 
    174131        private void workflowLaunch (IActivity returningActivity, String returnCode, Hashtable returnVals) { 
    175132                if (returningActivity == null) { 
    176133 
    177                 /*      launchActivity(new SplashScreenActivity(this, "/splash.gif"), context); 
     134                        launchActivity(new SplashScreenActivity(this, "/splash.gif"), context); 
    178135 
    179136                } else if (returningActivity instanceof SplashScreenActivity) { 
    180 */ 
    181                         returningActivity = null; 
     137 
    182138                        //#if javarosa.dev.shortcuts 
    183139                        launchActivity(new FormListActivity(this, "Forms List"), context); 
    184140                        //#else 
    185                                         String passwordVAR = midlet.getAppProperty("username"); 
     141                        String passwordVAR = midlet.getAppProperty("username"); 
    186142            String usernameVAR = midlet.getAppProperty("password"); 
    187143            if ((usernameVAR == null) || (passwordVAR == null)) 
    188144            { 
    189145            context.setElement("username","admin"); 
    190             context.setElement("password","adat"); 
     146            context.setElement("password","p"); 
    191147            } 
    192148            else{ 
     
    203159                        if (returnVal == "USER_VALIDATED") { 
    204160                                User user = (User)returnVals.get(LoginActivity.USER); 
    205  
    206161                                MemoryCheckActivity memCheck = new MemoryCheckActivity(this); 
    207162                                if (user != null){ 
     
    209164                                        context.setElement("USER", user); 
    210165                                } 
    211  
    212166                                launchActivity(memCheck, context); 
    213167                        } else if (returnVal == "USER_CANCELLED") { 
    214168                                exitShell(); 
    215169                        } 
     170                         
    216171 
    217172                }else if (returningActivity instanceof MemoryCheckActivity)  
    218173                { 
    219174                        launchActivity(new FormListActivity(this, "Forms List"), context); 
    220                 } 
    221                 else if (returningActivity instanceof FormListActivity) { 
     175                } else if (returningActivity instanceof FormListActivity) { 
    222176 
    223177                        String returnVal = (String)returnVals.get(FormListActivity.COMMAND_KEY); 
     
    228182                        } else if (returnVal == Commands.CMD_SELECT_XFORM) { 
    229183                                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)  
    231185                                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                         
    234192 
    235193                } else if (returningActivity instanceof ModelListActivity) { 
     
    256214 
    257215                } 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                        } 
    260224 
    261225                        //what is this for? 
     
    267231                                } 
    268232                        }*/ 
    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                } 
    272263        } 
    273264 
     
    276267 
    277268                //default action 
    278                 resumeActivity(suspendedActivity, context); 
     269                Context newContext = new Context(context); 
     270                newContext.addAllValues(returnVals); 
     271                resumeActivity(suspendedActivity, newContext); 
    279272        } 
    280273 
     
    298291                if (instanceID != -1) 
    299292                        formEntryContext.setInstanceID(instanceID); 
     293 
    300294                launchActivity(entryActivity, formEntryContext); 
    301295        } 
     
    347341        } 
    348342 
    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==verbose 
    357                         System.out.println("No default value for [" + propName 
    358                                         + "]; setting to [" + defaultValue + "]"); // debug 
    359                         //#endif 
    360                         return defaultValue; 
    361                 }/*else { 
    362                         propVal.addElement(defaultValue); 
    363                         JavaRosaServiceProvider.instance().getPropertyManager().setProperty(propName, propVal); 
    364                         //#if debug.output==verbose 
    365                         System.out.println("added value for [" + propName 
    366                                         + "]; setting to [" + defaultValue + "]"); // debug 
    367                         //#endif 
    368                         return defaultValue; 
    369                 }*/ 
    370                 return (String) propVal.elementAt(0); 
    371         } 
    372  
    373343        private void loadProperties() { 
    374344                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 
    393356}