Skip to content
Snippets Groups Projects
Commit ab83d915 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

better error handling

parent 64fce4be
No related branches found
No related tags found
No related merge requests found
...@@ -38,7 +38,6 @@ public class MainActivity extends Activity{ ...@@ -38,7 +38,6 @@ public class MainActivity extends Activity{
private MenuItem _runStopMenuItem, _switchFragmentMenuItem; private MenuItem _runStopMenuItem, _switchFragmentMenuItem;
private ModelFragment _modelFragment; private ModelFragment _modelFragment;
private OptionsFragment _optionsFragment; private OptionsFragment _optionsFragment;
private ArrayList<String> _errors = new ArrayList<String>();
private Dialog _errorDialog; private Dialog _errorDialog;
public MainActivity() { } public MainActivity() { }
...@@ -136,7 +135,7 @@ public class MainActivity extends Activity{ ...@@ -136,7 +135,7 @@ public class MainActivity extends Activity{
else if(item.getItemId() == android.R.id.home) { else if(item.getItemId() == android.R.id.home) {
if(this._compute) { if(this._compute) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
_errorDialog = dialogBuilder.setTitle("Cannot show the model list") dialogBuilder.setTitle("Cannot show the model list")
.setMessage("The computation has to complete before you can select another model") .setMessage("The computation has to complete before you can select another model")
.setPositiveButton("OK", new DialogInterface.OnClickListener() { .setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
...@@ -201,29 +200,18 @@ public class MainActivity extends Activity{ ...@@ -201,29 +200,18 @@ public class MainActivity extends Activity{
} }
} }
private void showError() private void showError(String msg)
{ {
if(_errors.size() > 0){ if(_errorDialog != null && _errorDialog.isShowing()) return;
if(_errorDialog != null && _errorDialog.isShowing()) _errorDialog.dismiss();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
dialogBuilder.setTitle("Error") _errorDialog = dialogBuilder.setTitle("Error")
.setMessage(_errors.get(_errors.size()-1)) .setMessage(msg)
.setNegativeButton("Hide", new DialogInterface.OnClickListener() { .setPositiveButton("Dismiss", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
_errors.clear(); dialog.dismiss();
_errorDialog.dismiss();
}
});
if(_errors.size()>1)
dialogBuilder.setPositiveButton("Show more", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
_errors.remove(_errors.size()-1);
_errorDialog.dismiss();
showError();
}
});
_errorDialog = dialogBuilder.show();
} }
})
.show();
} }
@Override @Override
protected void onPause() protected void onPause()
...@@ -329,9 +317,7 @@ public class MainActivity extends Activity{ ...@@ -329,9 +317,7 @@ public class MainActivity extends Activity{
public void handleMessage(android.os.Message msg) { public void handleMessage(android.os.Message msg) {
switch (msg.what) { switch (msg.what) {
case 0: // we get a message from gmsh library case 0: // we get a message from gmsh library
String message =(String) msg.obj; showError((String)msg.obj);
_errors.add(message);
showError();
break; break;
case 1: // request render from gmsh library case 1: // request render from gmsh library
if(_modelFragment != null) _modelFragment.requestRender(); if(_modelFragment != null) _modelFragment.requestRender();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment