Added progress dialog when loading a file. Removed some default text from the view. Added safety net to launch the file browser when no file is specified. This last piece of functionality might be replaced with a dialog and better error handling in the future.
This commit is contained in:
parent
c546dba066
commit
2e41cbb5ff
@ -8,7 +8,7 @@
|
||||
android:id="@+id/heading"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Started" />
|
||||
android:text="" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/rocketSimulations"
|
||||
|
@ -11,6 +11,7 @@ import net.sf.openrocket.android.simulation.SimulationViewer;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@ -31,11 +32,14 @@ public class OpenRocketViewer extends Activity {
|
||||
|
||||
private static final String TAG = "OpenRocketViewer";
|
||||
|
||||
TextView header;
|
||||
ListView simulationList;
|
||||
private ProgressDialog progress;
|
||||
|
||||
Application app;
|
||||
private TextView header;
|
||||
private ListView simulationList;
|
||||
|
||||
private Application app;
|
||||
|
||||
private final static int PICK_ORK_FILE_RESULT = 1;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.app.Activity#onCreate(android.os.Bundle)
|
||||
@ -55,9 +59,47 @@ public class OpenRocketViewer extends Activity {
|
||||
|
||||
Intent i = getIntent();
|
||||
Uri file = i.getData();
|
||||
String path = file.getPath();
|
||||
|
||||
if ( file == null ) {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("file/*");
|
||||
startActivityForResult(intent,PICK_ORK_FILE_RESULT);
|
||||
|
||||
} else {
|
||||
loadOrkFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if ( progress != null ) {
|
||||
if ( progress.isShowing() ) {
|
||||
progress.dismiss();
|
||||
}
|
||||
progress = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// TODO Auto-generated method stub
|
||||
switch(requestCode){
|
||||
case PICK_ORK_FILE_RESULT:
|
||||
if(resultCode==RESULT_OK){
|
||||
Uri file = data.getData();
|
||||
loadOrkFile(file);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadOrkFile( Uri file ) {
|
||||
Log.d(TAG,"Use ork file: " + file);
|
||||
String path = file.getPath();
|
||||
File orkFile = new File(path);
|
||||
progress = ProgressDialog.show(this, "Loading file", "");
|
||||
|
||||
final OpenRocketLoaderTask task = new OpenRocketLoaderTask() {
|
||||
|
||||
/* (non-Javadoc)
|
||||
@ -73,6 +115,7 @@ public class OpenRocketViewer extends Activity {
|
||||
};
|
||||
|
||||
task.execute(orkFile);
|
||||
|
||||
}
|
||||
|
||||
private void updateContents() {
|
||||
@ -108,12 +151,16 @@ public class OpenRocketViewer extends Activity {
|
||||
});
|
||||
simulationList.setAdapter(sims);
|
||||
|
||||
if ( progress.isShowing() ) {
|
||||
progress.dismiss();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.rocket_viewer_option_menu, menu);
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.rocket_viewer_option_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -134,9 +181,9 @@ public class OpenRocketViewer extends Activity {
|
||||
|
||||
public void startMotorBrowser() {
|
||||
Log.d(TAG,"motorBrowserButton clicked");
|
||||
Intent i = new Intent(OpenRocketViewer.this, MotorHierarchicalBrowser.class);
|
||||
startActivity(i);
|
||||
}
|
||||
Intent i = new Intent(OpenRocketViewer.this, MotorHierarchicalBrowser.class);
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user