Switch to GeneralRocketLoader so the app can load compressed ork files. Added dialog containing exception message when loading fails.

This commit is contained in:
Kevin Ruland 2012-02-15 03:25:29 +00:00
parent ff05c2b499
commit b8899899f8
3 changed files with 31 additions and 13 deletions

View File

@ -11,6 +11,8 @@ import net.sf.openrocket.android.thrustcurve.TCQueryAction;
import net.sf.openrocket.android.util.AndroidLogWrapper;
import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder;
import net.sf.openrocket.rocketcomponent.Rocket;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@ -23,7 +25,7 @@ implements TCQueryAction.OnTCQueryCompleteListener, OpenRocketLoaderFragment.OnO
private final static String MISSING_MOTOR_DIAG_FRAGMENT_TAG = "missingmotordialog";
private final static String MISSING_MOTOR_DOWNLOAD_FRAGMENT_TAG = "missingmotortask";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -46,9 +48,9 @@ implements TCQueryAction.OnTCQueryCompleteListener, OpenRocketLoaderFragment.OnO
AndroidLogWrapper.d(OpenRocketLoaderActivity.class,"Use ork file: " + file);
String path = file.getPath();
File orkFile = new File(path);
getSupportFragmentManager().beginTransaction().add( OpenRocketLoaderFragment.newInstance(orkFile), "loader").commit();
}
/**
@ -58,11 +60,25 @@ implements TCQueryAction.OnTCQueryCompleteListener, OpenRocketLoaderFragment.OnO
* @param result
*/
public void onOpenRocketFileLoaded(OpenRocketLoaderResult result) {
((Application)OpenRocketLoaderActivity.this.getApplication()).setRocketDocument( result.rocket );
((Application)OpenRocketLoaderActivity.this.getApplication()).setWarnings( result.warnings );
updateMissingMotors();
if ( result.loadingError != null ) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
dialogBuilder.setTitle("Error Loading File" );
dialogBuilder.setMessage( result.loadingError.getLocalizedMessage());
dialogBuilder.setOnCancelListener( new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
OpenRocketLoaderActivity.this.finish();
}
});
dialogBuilder.create().show();
} else {
((Application)OpenRocketLoaderActivity.this.getApplication()).setRocketDocument( result.rocket );
((Application)OpenRocketLoaderActivity.this.getApplication()).setWarnings( result.warnings );
updateMissingMotors();
}
}
private void updateMissingMotors() {

View File

@ -6,8 +6,8 @@ import net.sf.openrocket.android.util.AndroidLogWrapper;
import net.sf.openrocket.android.util.ProgressDialogFragment;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.DatabaseMotorFinderWithMissingMotors;
import net.sf.openrocket.file.GeneralRocketLoader;
import net.sf.openrocket.file.RocketLoadException;
import net.sf.openrocket.file.openrocket.importt.OpenRocketLoader;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
@ -85,17 +85,17 @@ public class OpenRocketLoaderFragment extends Fragment {
protected OpenRocketLoaderResult doInBackground(File... arg0) {
AndroidLogWrapper.d(OpenRocketLoaderTask.class, "doInBackgroud");
OpenRocketLoader rocketLoader = new OpenRocketLoader();
GeneralRocketLoader rocketLoader = new GeneralRocketLoader();
OpenRocketLoaderResult result = new OpenRocketLoaderResult();
try {
OpenRocketLoaderResult result = new OpenRocketLoaderResult();
OpenRocketDocument rocket = rocketLoader.load(arg0[0], new DatabaseMotorFinderWithMissingMotors());
result.rocket = rocket;
result.warnings = rocketLoader.getWarnings();
return result;
} catch (RocketLoadException ex) {
AndroidLogWrapper.e(OpenRocketLoaderTask.class, "doInBackground rocketLaoder.load threw", ex);
AndroidLogWrapper.e(OpenRocketLoaderTask.class, "doInBackground rocketLaoder.load threw {}", ex);
result.loadingError = ex;
}
return null;
return result;
}

View File

@ -2,10 +2,12 @@ package net.sf.openrocket.android.rocket;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.RocketLoadException;
public class OpenRocketLoaderResult {
public WarningSet warnings;
public OpenRocketDocument rocket;
public RocketLoadException loadingError;
}