Modify the OpenRocketTask to send both the WarningSet and OpenRocketDocument back and display a dialog when there are warnings. The dialog is only partially implemented.
This commit is contained in:
parent
bd8e82c1d2
commit
1d127a0162
@ -3,17 +3,18 @@ package net.sf.openrocket.android.rocket;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import net.sf.openrocket.R;
|
import net.sf.openrocket.R;
|
||||||
|
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||||
import net.sf.openrocket.android.Application;
|
import net.sf.openrocket.android.Application;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
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;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
public class OpenRocketLoader extends FragmentActivity {
|
public class OpenRocketLoader extends FragmentActivity {
|
||||||
private static final String TAG = "OpenRocketLoader";
|
private static final String TAG = "OpenRocketLoader";
|
||||||
@ -52,11 +53,10 @@ public class OpenRocketLoader extends FragmentActivity {
|
|||||||
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
|
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(OpenRocketDocument result) {
|
protected void onPostExecute(OpenRocketLoaderResult result) {
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
((Application)OpenRocketLoader.this.getApplication()).setRocketDocument( result );
|
|
||||||
Log.d(TAG,"Finished loading " + OpenRocketLoader.this);
|
Log.d(TAG,"Finished loading " + OpenRocketLoader.this);
|
||||||
finishedLoading();
|
finishedLoading(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -65,15 +65,66 @@ public class OpenRocketLoader extends FragmentActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finishedLoading() {
|
private void finishedLoading(OpenRocketLoaderResult result) {
|
||||||
if ( progress.isShowing() ) {
|
if ( progress.isShowing() ) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WarningSet warnings = result.warnings;
|
||||||
|
if (warnings == null || warnings.isEmpty()) {
|
||||||
|
((Application)OpenRocketLoader.this.getApplication()).setRocketDocument( result.rocket );
|
||||||
Intent i = new Intent(this,OpenRocketViewer.class);
|
Intent i = new Intent(this,OpenRocketViewer.class);
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
finish();
|
finish();
|
||||||
|
} else {
|
||||||
|
// TODO - Build a warning listing dialog
|
||||||
|
DialogFragment newFragment = WarningDialogFragment.newInstance();
|
||||||
|
newFragment.show(getSupportFragmentManager(), "dialog");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void doPositiveClick() {
|
||||||
|
// Do stuff here.
|
||||||
|
Log.i("FragmentAlertDialog", "Positive click!");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doNegativeClick() {
|
||||||
|
// Do stuff here.
|
||||||
|
Log.i("FragmentAlertDialog", "Negative click!");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WarningDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
|
public static WarningDialogFragment newInstance() {
|
||||||
|
WarningDialogFragment frag = new WarningDialogFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
frag.setArguments(args);
|
||||||
|
return frag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
return new AlertDialog.Builder(getActivity())
|
||||||
|
// .setIcon(android.R.drawable.alert_dialog_icon)
|
||||||
|
.setTitle("Warnings")
|
||||||
|
.setPositiveButton("OK",
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
|
((OpenRocketLoader)getActivity()).doPositiveClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.setNegativeButton("Cancel",
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
|
((OpenRocketLoader)getActivity()).doNegativeClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package net.sf.openrocket.android.rocket;
|
||||||
|
|
||||||
|
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||||
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
|
|
||||||
|
public class OpenRocketLoaderResult {
|
||||||
|
|
||||||
|
public WarningSet warnings;
|
||||||
|
public OpenRocketDocument rocket;
|
||||||
|
|
||||||
|
}
|
@ -8,7 +8,7 @@ import net.sf.openrocket.file.openrocket.OpenRocketLoader;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class OpenRocketLoaderTask extends AsyncTask<File, Void, OpenRocketDocument> {
|
public class OpenRocketLoaderTask extends AsyncTask<File, Void, OpenRocketLoaderResult> {
|
||||||
|
|
||||||
private final static String TAG = "OpenRocketLoaderTask";
|
private final static String TAG = "OpenRocketLoaderTask";
|
||||||
|
|
||||||
@ -16,13 +16,16 @@ public class OpenRocketLoaderTask extends AsyncTask<File, Void, OpenRocketDocume
|
|||||||
* @see android.os.AsyncTask#doInBackground(Params[])
|
* @see android.os.AsyncTask#doInBackground(Params[])
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected OpenRocketDocument doInBackground(File... arg0) {
|
protected OpenRocketLoaderResult doInBackground(File... arg0) {
|
||||||
Log.d(TAG,"doInBackgroud");
|
Log.d(TAG,"doInBackgroud");
|
||||||
|
|
||||||
OpenRocketLoader rocketLoader = new OpenRocketLoader();
|
OpenRocketLoader rocketLoader = new OpenRocketLoader();
|
||||||
try {
|
try {
|
||||||
|
OpenRocketLoaderResult result = new OpenRocketLoaderResult();
|
||||||
OpenRocketDocument rocket = rocketLoader.load(arg0[0]);
|
OpenRocketDocument rocket = rocketLoader.load(arg0[0]);
|
||||||
return rocket;
|
result.rocket = rocket;
|
||||||
|
result.warnings = result.warnings;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
catch( RocketLoadException ex ) {
|
catch( RocketLoadException ex ) {
|
||||||
Log.e(TAG, "doInBackground rocketLaoder.load threw", ex);
|
Log.e(TAG, "doInBackground rocketLaoder.load threw", ex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user