import net.sf.openrocket.document.OpenRocketDocument;\r
import net.sf.openrocket.document.Simulation;\r
import android.app.Activity;\r
+import android.app.ProgressDialog;\r
import android.content.Intent;\r
import android.net.Uri;\r
import android.os.Bundle;\r
\r
private static final String TAG = "OpenRocketViewer";\r
\r
- TextView header;\r
- ListView simulationList;\r
- \r
- Application app;\r
+ private ProgressDialog progress;\r
+\r
+ private TextView header;\r
+ private ListView simulationList;\r
+\r
+ private Application app;\r
\r
+ private final static int PICK_ORK_FILE_RESULT = 1;\r
\r
/* (non-Javadoc)\r
* @see android.app.Activity#onCreate(android.os.Bundle)\r
@Override\r
protected void onCreate(Bundle savedInstanceState) {\r
super.onCreate(savedInstanceState);\r
- \r
+\r
Log.d(TAG,"In onCreate");\r
- \r
+\r
app = (Application) this.getApplication();\r
\r
setContentView(R.layout.openrocketviewer);\r
- \r
+\r
header = (TextView) findViewById(R.id.heading);\r
simulationList = (ListView) findViewById(R.id.rocketSimulations);\r
\r
Intent i = getIntent();\r
Uri file = i.getData();\r
- String path = file.getPath();\r
+\r
+ if ( file == null ) {\r
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);\r
+ intent.setType("file/*");\r
+ startActivityForResult(intent,PICK_ORK_FILE_RESULT);\r
+\r
+ } else {\r
+ loadOrkFile(file);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ protected void onDestroy() {\r
+ if ( progress != null ) {\r
+ if ( progress.isShowing() ) {\r
+ progress.dismiss();\r
+ }\r
+ progress = null;\r
+ }\r
+ super.onDestroy();\r
+ }\r
+\r
+ @Override\r
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {\r
+ // TODO Auto-generated method stub\r
+ switch(requestCode){\r
+ case PICK_ORK_FILE_RESULT:\r
+ if(resultCode==RESULT_OK){\r
+ Uri file = data.getData();\r
+ loadOrkFile(file);\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ \r
+ private void loadOrkFile( Uri file ) {\r
Log.d(TAG,"Use ork file: " + file);\r
+ String path = file.getPath();\r
File orkFile = new File(path);\r
+ progress = ProgressDialog.show(this, "Loading file", "");\r
+\r
final OpenRocketLoaderTask task = new OpenRocketLoaderTask() {\r
\r
/* (non-Javadoc)\r
app.setRocketDocument( result );\r
updateContents();\r
}\r
- \r
+\r
};\r
- \r
+\r
task.execute(orkFile);\r
+\r
}\r
\r
private void updateContents() {\r
- \r
+\r
OpenRocketDocument rocket = app.getRocketDocument();\r
header.setText( rocket.getRocket().getName());\r
- \r
+\r
ArrayAdapter<Simulation> sims = new ArrayAdapter<Simulation>(this,android.R.layout.simple_list_item_1,rocket.getSimulations()) {\r
\r
@Override\r
i.putExtra("Simulation",(int)id);\r
startActivityForResult(i, 1/*magic*/);\r
}\r
- \r
+\r
});\r
simulationList.setAdapter(sims);\r
\r
+ if ( progress.isShowing() ) {\r
+ progress.dismiss();\r
+ }\r
+\r
}\r
- \r
+\r
@Override\r
public boolean onCreateOptionsMenu(Menu menu) {\r
- MenuInflater inflater = getMenuInflater();\r
- inflater.inflate(R.menu.rocket_viewer_option_menu, menu);\r
+ MenuInflater inflater = getMenuInflater();\r
+ inflater.inflate(R.menu.rocket_viewer_option_menu, menu);\r
return true;\r
}\r
\r
\r
public void startMotorBrowser() {\r
Log.d(TAG,"motorBrowserButton clicked");\r
- Intent i = new Intent(OpenRocketViewer.this, MotorHierarchicalBrowser.class);\r
- startActivity(i);\r
- }\r
+ Intent i = new Intent(OpenRocketViewer.this, MotorHierarchicalBrowser.class);\r
+ startActivity(i);\r
+ }\r
\r
\r
\r