Call this week 4, even though I started this project on Sept 22, I only work on it every other week.
Finally starting to take shape. Coded a simplified CrCl routine, simply copied the Pascal code from my Delphi app, since Pascal syntax is very similar to Java, ran without any mods.
Coded the main menu and preferences dialog. Found the Android preference routines straightforward and less verbose than most other basic tasks in Android.
Had to add a blank OnResume routine so Android would (automatically) restore the current state. However, tapping the back key to exit out of the app erases the state, so will need to code a savestate routine.
Android has no native XML parsing support and SQlite is overkill, so I decided to use JSON for saving and passing current session data. Found JSON to be easy to use and perfect for data exchange.
Discovered how to pass data from one screen (Java:intent) to another:
// Declare new Intent
Intent i = new Intent(Main.this, ViewModel.class);
// Pass bundled data as JSON string
i.putExtra(“Main.term”, CreateDataString());
// Show new screen
startActivity(i);
Then, in the OnCreate of the receiving screen:
// Get passed JSON variable
Bundle extras = getIntent().getExtras();
DataPassed = extras.getString(“Main.term”);
Using the JSONStringer function to create the passed data string:
private String CreateDataString(){
// Declare variable
String dataString=”";
// Create dataString
try {
dataString = new JSONStringer()
.object()
// Model data
.key(“ModelName”).value(thismodel.getDrug())
.key(“ModelVd”).value(thismodel.getVD())
// etc
// Patient data
.key(“Age”).value(txtAge.getText().toString())
// etc
.endObject()
.toString();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dataString;
}
Then in the Model screen, using a JSONobject to parse the passed string and populate the default parameters on the Model view screen.
try {
JSONObject jo = new JSONObject(DataPassed);
String strTemp = jo.getString(“ModelName”) + ” model parameters”;
lblTitle.setText(strTemp);
double dblTemp = jo.getDouble(“ModelVd”);
txtVd.setText(String.format(“%.2f”, dblTemp));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
So, with that I’ve completed the basic skeleton and flow of the first two parts of the program. Now the grunt work to fill in all the details.
Starting to see some light at the end of the tunnel.