From aee26f8948810792a3fdef4f026a6ec50752d895 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Wed, 15 Feb 2012 03:25:29 +0000 Subject: [PATCH] Switch to GeneralRocketLoader so the app can load compressed ork files. Added dialog containing exception message when loading fails. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@416 180e2498-e6e9-4542-8430-84ac67f01cd8 --- .../rocket/OpenRocketLoaderActivity.java | 30 ++++++++++++++----- .../rocket/OpenRocketLoaderFragment.java | 12 ++++---- .../rocket/OpenRocketLoaderResult.java | 2 ++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderActivity.java b/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderActivity.java index 272b4b6d..dde3ccf4 100644 --- a/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderActivity.java +++ b/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderActivity.java @@ -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() { diff --git a/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderFragment.java b/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderFragment.java index 89c202c3..99922752 100644 --- a/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderFragment.java +++ b/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderFragment.java @@ -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; } diff --git a/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderResult.java b/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderResult.java index ffb35397..4e3fef6d 100644 --- a/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderResult.java +++ b/android/src/net/sf/openrocket/android/rocket/OpenRocketLoaderResult.java @@ -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; } -- 2.39.5