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.android.util.AndroidLogWrapper;
import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder; import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -58,11 +60,25 @@ implements TCQueryAction.OnTCQueryCompleteListener, OpenRocketLoaderFragment.OnO
* @param result * @param result
*/ */
public void onOpenRocketFileLoaded(OpenRocketLoaderResult result) { public void onOpenRocketFileLoaded(OpenRocketLoaderResult result) {
((Application)OpenRocketLoaderActivity.this.getApplication()).setRocketDocument( result.rocket ); if ( result.loadingError != null ) {
((Application)OpenRocketLoaderActivity.this.getApplication()).setWarnings( result.warnings );
updateMissingMotors(); 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() { 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.android.util.ProgressDialogFragment;
import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.DatabaseMotorFinderWithMissingMotors; import net.sf.openrocket.file.DatabaseMotorFinderWithMissingMotors;
import net.sf.openrocket.file.GeneralRocketLoader;
import net.sf.openrocket.file.RocketLoadException; import net.sf.openrocket.file.RocketLoadException;
import net.sf.openrocket.file.openrocket.importt.OpenRocketLoader;
import android.app.Activity; import android.app.Activity;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -85,17 +85,17 @@ public class OpenRocketLoaderFragment extends Fragment {
protected OpenRocketLoaderResult doInBackground(File... arg0) { protected OpenRocketLoaderResult doInBackground(File... arg0) {
AndroidLogWrapper.d(OpenRocketLoaderTask.class, "doInBackgroud"); AndroidLogWrapper.d(OpenRocketLoaderTask.class, "doInBackgroud");
OpenRocketLoader rocketLoader = new OpenRocketLoader(); GeneralRocketLoader rocketLoader = new GeneralRocketLoader();
OpenRocketLoaderResult result = new OpenRocketLoaderResult();
try { try {
OpenRocketLoaderResult result = new OpenRocketLoaderResult();
OpenRocketDocument rocket = rocketLoader.load(arg0[0], new DatabaseMotorFinderWithMissingMotors()); OpenRocketDocument rocket = rocketLoader.load(arg0[0], new DatabaseMotorFinderWithMissingMotors());
result.rocket = rocket; result.rocket = rocket;
result.warnings = rocketLoader.getWarnings(); result.warnings = rocketLoader.getWarnings();
return result;
} catch (RocketLoadException ex) { } 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.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.RocketLoadException;
public class OpenRocketLoaderResult { public class OpenRocketLoaderResult {
public WarningSet warnings; public WarningSet warnings;
public OpenRocketDocument rocket; public OpenRocketDocument rocket;
public RocketLoadException loadingError;
} }