Skip to content
Snippets Groups Projects
Commit cebd109c authored by Maxime Graulich's avatar Maxime Graulich
Browse files

Android: Show errors & Enable/Disable options buttons

parent 76b3ea6d
No related branches found
No related tags found
No related merge requests found
package org.geuz.onelab;
import java.util.ArrayList;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
......@@ -22,6 +27,8 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
private MenuItem _runStopMenuItem, _switchFragmentMenuItem;
private ModelFragment _modelFragment;
private OptionsFragment _optionsFragment;
private ArrayList<String> _errors = new ArrayList<String>();
private Dialog _errorDialog;
public MainActivity() {
}
......@@ -105,8 +112,18 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
}
else if(item.getItemId() == android.R.id.home)
{
if(this._compute)
;//TODO loading.show();
if(this._compute) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
_errorDialog = dialogBuilder.setTitle("Can't show the models list")
.setMessage("The compute have to be finished before you can select an other model.")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
}
else
this.finish();
}
......@@ -148,7 +165,6 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
protected void onPostExecute(Integer[] result) {
//(Vibrator) getSystemService(Context.VIBRATOR_SERVICE).vibrate(350);
_runStopMenuItem.setTitle(R.string.menu_run);
//reset.setEnabled(true);
//loading.dismiss();
_compute = false;
super.onPostExecute(result);
......@@ -157,14 +173,36 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
}
public void onRequestRender() {
_modelFragment.requestRender();
}
private void showError(){
if(_errors.size()>0){
if(_errorDialog != null && _errorDialog.isShowing()) _errorDialog.dismiss();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
_errorDialog = dialogBuilder.setTitle("Gmsh/GetDP Error(s)")
.setMessage(_errors.get(_errors.size()-1))
.setNegativeButton("Stop", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
_errors.clear();
_errorDialog.dismiss();
}
})
.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
_errors.remove(_errors.size()-1);
_errorDialog.dismiss();
showError();
}
})
.show();
}
}
private final Handler mainHandler = new Handler(){
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case 0: // we get a message from gmsh library
//String message =(String) msg.obj;
//errors.add(message);
//showError();
String message =(String) msg.obj;
_errors.add(message);
showError();
break;
case 1: // request render from gmsh library
if(_modelFragment != null) _modelFragment.requestRender();
......
......@@ -39,11 +39,15 @@ public class OptionsFragment extends Fragment{
_optionModelFragment = OptionsModelFragment.newInstance(_gmsh);
getFragmentManager().beginTransaction().add(R.id.options_fragment, _optionModelFragment).commit();
_optionDisplayFragment = OptionsDisplayFragment.newInstance(_gmsh);
Button optionModel = (Button) rootView.findViewById(R.id.goto_options_model);
Button optionDisplay = (Button) rootView.findViewById(R.id.goto_options_display);
final Button optionModel = (Button) rootView.findViewById(R.id.goto_options_model);
final Button optionDisplay = (Button) rootView.findViewById(R.id.goto_options_display);
optionDisplay.setEnabled(true);
optionModel.setEnabled(false);
optionModel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
optionModel.setEnabled(false);
optionDisplay.setEnabled(true);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.options_fragment, _optionModelFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
......@@ -53,6 +57,8 @@ public class OptionsFragment extends Fragment{
optionDisplay.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
optionDisplay.setEnabled(false);
optionModel.setEnabled(true);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.options_fragment, _optionDisplayFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
......@@ -63,7 +69,7 @@ public class OptionsFragment extends Fragment{
}
public void refresh() {
_optionDisplayFragment.refresh();
_optionModelFragment.refresh();
if(_optionDisplayFragment != null)_optionDisplayFragment.refresh();
if(_optionModelFragment != null)_optionModelFragment.refresh();
}
}
......@@ -168,7 +168,6 @@ void drawContext::buildRotationMatrix()
void drawContext::OrthofFromGModel()
{
if(locked) return;
SBoundingBox3d bb = GModel::current()->bounds();
double ratio = (double)(this->_width ? this->_width : 1.) / (double)(this->_height ? this->_height : 1.);
double xmin = -ratio, xmax = ratio, ymin = -1., ymax = 1.;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment