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; package org.geuz.onelab;
import java.util.ArrayList;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
...@@ -22,6 +27,8 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO ...@@ -22,6 +27,8 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
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;
public MainActivity() { public MainActivity() {
} }
...@@ -105,8 +112,18 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO ...@@ -105,8 +112,18 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
} }
else if(item.getItemId() == android.R.id.home) else if(item.getItemId() == android.R.id.home)
{ {
if(this._compute) if(this._compute) {
;//TODO loading.show(); 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 else
this.finish(); this.finish();
} }
...@@ -140,7 +157,7 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO ...@@ -140,7 +157,7 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
@Override @Override
protected Integer[] doInBackground(Void... params) { protected Integer[] doInBackground(Void... params) {
_gmsh.onelabCB("compute"); _gmsh.onelabCB("compute");
return new Integer[] {1}; return new Integer[] {1};
} }
...@@ -148,7 +165,6 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO ...@@ -148,7 +165,6 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
protected void onPostExecute(Integer[] result) { protected void onPostExecute(Integer[] result) {
//(Vibrator) getSystemService(Context.VIBRATOR_SERVICE).vibrate(350); //(Vibrator) getSystemService(Context.VIBRATOR_SERVICE).vibrate(350);
_runStopMenuItem.setTitle(R.string.menu_run); _runStopMenuItem.setTitle(R.string.menu_run);
//reset.setEnabled(true);
//loading.dismiss(); //loading.dismiss();
_compute = false; _compute = false;
super.onPostExecute(result); super.onPostExecute(result);
...@@ -158,13 +174,35 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO ...@@ -158,13 +174,35 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
public void onRequestRender() { public void onRequestRender() {
_modelFragment.requestRender(); _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(){ private final Handler mainHandler = new Handler(){
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; String message =(String) msg.obj;
//errors.add(message); _errors.add(message);
//showError(); 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();
......
...@@ -39,11 +39,15 @@ public class OptionsFragment extends Fragment{ ...@@ -39,11 +39,15 @@ public class OptionsFragment extends Fragment{
_optionModelFragment = OptionsModelFragment.newInstance(_gmsh); _optionModelFragment = OptionsModelFragment.newInstance(_gmsh);
getFragmentManager().beginTransaction().add(R.id.options_fragment, _optionModelFragment).commit(); getFragmentManager().beginTransaction().add(R.id.options_fragment, _optionModelFragment).commit();
_optionDisplayFragment = OptionsDisplayFragment.newInstance(_gmsh); _optionDisplayFragment = OptionsDisplayFragment.newInstance(_gmsh);
Button optionModel = (Button) rootView.findViewById(R.id.goto_options_model); final Button optionModel = (Button) rootView.findViewById(R.id.goto_options_model);
Button optionDisplay = (Button) rootView.findViewById(R.id.goto_options_display); final Button optionDisplay = (Button) rootView.findViewById(R.id.goto_options_display);
optionDisplay.setEnabled(true);
optionModel.setEnabled(false);
optionModel.setOnClickListener(new View.OnClickListener() { optionModel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
optionModel.setEnabled(false);
optionDisplay.setEnabled(true);
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.options_fragment, _optionModelFragment); ft.replace(R.id.options_fragment, _optionModelFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
...@@ -53,6 +57,8 @@ public class OptionsFragment extends Fragment{ ...@@ -53,6 +57,8 @@ public class OptionsFragment extends Fragment{
optionDisplay.setOnClickListener(new View.OnClickListener() { optionDisplay.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
optionDisplay.setEnabled(false);
optionModel.setEnabled(true);
FragmentTransaction ft = getFragmentManager().beginTransaction(); FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.options_fragment, _optionDisplayFragment); ft.replace(R.id.options_fragment, _optionDisplayFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
...@@ -63,7 +69,7 @@ public class OptionsFragment extends Fragment{ ...@@ -63,7 +69,7 @@ public class OptionsFragment extends Fragment{
} }
public void refresh() { public void refresh() {
_optionDisplayFragment.refresh(); if(_optionDisplayFragment != null)_optionDisplayFragment.refresh();
_optionModelFragment.refresh(); if(_optionModelFragment != null)_optionModelFragment.refresh();
} }
} }
...@@ -168,7 +168,6 @@ void drawContext::buildRotationMatrix() ...@@ -168,7 +168,6 @@ void drawContext::buildRotationMatrix()
void drawContext::OrthofFromGModel() void drawContext::OrthofFromGModel()
{ {
if(locked) return;
SBoundingBox3d bb = GModel::current()->bounds(); SBoundingBox3d bb = GModel::current()->bounds();
double ratio = (double)(this->_width ? this->_width : 1.) / (double)(this->_height ? this->_height : 1.); double ratio = (double)(this->_width ? this->_width : 1.) / (double)(this->_height ? this->_height : 1.);
double xmin = -ratio, xmax = ratio, ymin = -1., ymax = 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