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

Android: add listeners on options changed

parent 9137e5c6
No related branches found
No related tags found
No related merge requests found
Showing with 105 additions and 112 deletions
...@@ -20,7 +20,7 @@ import android.view.Window; ...@@ -20,7 +20,7 @@ import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
public class MainActivity extends Activity implements OptionsDisplayFragment.OnOptionRequestRender{ public class MainActivity extends Activity{
private Gmsh _gmsh; private Gmsh _gmsh;
private boolean _compute, _twoPane; private boolean _compute, _twoPane;
...@@ -68,6 +68,12 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO ...@@ -68,6 +68,12 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
_modelFragment = ModelFragment.newInstance(_gmsh); _modelFragment = ModelFragment.newInstance(_gmsh);
getFragmentManager().beginTransaction().add(R.id.model_fragment, _modelFragment).commit(); getFragmentManager().beginTransaction().add(R.id.model_fragment, _modelFragment).commit();
} }
_optionsFragment.setOnOptionsChangedListener(new OptionsFragment.OnOptionsChangedListener() {
public void OnOptionsChanged() {
_modelFragment.requestRender();
}
});
} }
@Override @Override
...@@ -136,22 +142,6 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO ...@@ -136,22 +142,6 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
protected void onPreExecute() { protected void onPreExecute() {
_compute = true; _compute = true;
_runStopMenuItem.setTitle(R.string.menu_stop); _runStopMenuItem.setTitle(R.string.menu_stop);
/*loading.setTitle("Please wait");
loading.setButton(DialogInterface.BUTTON_NEUTRAL, "Hide", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
loading.dismiss();
}
});
loading.setButton(DialogInterface.BUTTON_NEGATIVE, "Stop", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
gmsh.onelabCB("stop");
}
});
loading.setMessage("...");
loading.show();
reset.setEnabled(false);*/
super.onPreExecute(); super.onPreExecute();
} }
...@@ -170,9 +160,6 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO ...@@ -170,9 +160,6 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
super.onPostExecute(result); super.onPostExecute(result);
} }
}
public void onRequestRender() {
_modelFragment.requestRender();
} }
private void showError(){ private void showError(){
if(_errors.size()>0){ if(_errors.size()>0){
...@@ -180,13 +167,13 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO ...@@ -180,13 +167,13 @@ public class MainActivity extends Activity implements OptionsDisplayFragment.OnO
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
_errorDialog = dialogBuilder.setTitle("Gmsh/GetDP Error(s)") _errorDialog = dialogBuilder.setTitle("Gmsh/GetDP Error(s)")
.setMessage(_errors.get(_errors.size()-1)) .setMessage(_errors.get(_errors.size()-1))
.setNegativeButton("Stop", new DialogInterface.OnClickListener() { .setNegativeButton("Hide", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
_errors.clear(); _errors.clear();
_errorDialog.dismiss(); _errorDialog.dismiss();
} }
}) })
.setPositiveButton("Continue", new DialogInterface.OnClickListener() { .setPositiveButton("Show more", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
_errors.remove(_errors.size()-1); _errors.remove(_errors.size()-1);
_errorDialog.dismiss(); _errorDialog.dismiss();
......
...@@ -3,10 +3,12 @@ package org.geuz.onelab; ...@@ -3,10 +3,12 @@ package org.geuz.onelab;
import android.app.Fragment; import android.app.Fragment;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.os.Bundle; import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
...@@ -15,6 +17,7 @@ public class ModelFragment extends Fragment{ ...@@ -15,6 +17,7 @@ public class ModelFragment extends Fragment{
Gmsh _gmsh; Gmsh _gmsh;
mGLSurfaceView _glView; mGLSurfaceView _glView;
TextView _progress; TextView _progress;
LinearLayout _progressLayout;
public static ModelFragment newInstance(Gmsh g) { public static ModelFragment newInstance(Gmsh g) {
ModelFragment fragment = new ModelFragment(); ModelFragment fragment = new ModelFragment();
...@@ -45,23 +48,26 @@ public class ModelFragment extends Fragment{ ...@@ -45,23 +48,26 @@ public class ModelFragment extends Fragment{
_glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); _glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
_glView.requestRender(); _glView.requestRender();
glViewLayout.addView(_glView); glViewLayout.addView(_glView);
_progressLayout = new LinearLayout(container.getContext());
ProgressBar bar = new ProgressBar(container.getContext());
_progressLayout.addView(bar);
_progress = new TextView(container.getContext()); _progress = new TextView(container.getContext());
_progress.setAlpha(0); _progressLayout.setAlpha(0);
_progressLayout.setGravity(Gravity.CENTER);
_progressLayout.addView(_progress);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
_progress.setPadding(10, 0, 10, 10); glViewLayout.addView(_progressLayout, layoutParams);
_progress.setLayoutParams(layoutParams);
glViewLayout.addView(_progress);
return rootView; return rootView;
} }
public void showProgress(String progress) { public void showProgress(String progress) {
_progress.setAlpha(1); _progressLayout.setAlpha(1);
_progress.setText(progress); _progress.setText(progress);
} }
public void hideProgress() { public void hideProgress() {
_progress.setAlpha(0); _progressLayout.setAlpha(0);
_progress.setText(""); _progress.setText("");
} }
public void requestRender() { public void requestRender() {
......
...@@ -2,7 +2,6 @@ package org.geuz.onelab; ...@@ -2,7 +2,6 @@ package org.geuz.onelab;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
...@@ -51,7 +50,7 @@ public class OptionsDisplayFragment extends Fragment{ ...@@ -51,7 +50,7 @@ public class OptionsDisplayFragment extends Fragment{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
_gmsh.setDoubleOption("Geometry", "Points", (isChecked)?1. : 0.); _gmsh.setDoubleOption("Geometry", "Points", (isChecked)?1. : 0.);
mCallback.onRequestRender(); if(mListener != null) mListener.OnModelOptionsChanged();
} }
}); });
_listView.addItem("Display", showGeomPoints); _listView.addItem("Display", showGeomPoints);
...@@ -62,7 +61,7 @@ public class OptionsDisplayFragment extends Fragment{ ...@@ -62,7 +61,7 @@ public class OptionsDisplayFragment extends Fragment{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
_gmsh.setDoubleOption("Geometry", "Lines", (isChecked)?1. : 0.); _gmsh.setDoubleOption("Geometry", "Lines", (isChecked)?1. : 0.);
mCallback.onRequestRender(); if(mListener != null) mListener.OnModelOptionsChanged();
} }
}); });
_listView.addItem("Display", showGeomLines); _listView.addItem("Display", showGeomLines);
...@@ -73,7 +72,7 @@ public class OptionsDisplayFragment extends Fragment{ ...@@ -73,7 +72,7 @@ public class OptionsDisplayFragment extends Fragment{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
_gmsh.setDoubleOption("Mesh", "SurfaceEdges", (isChecked)?1. : 0.); _gmsh.setDoubleOption("Mesh", "SurfaceEdges", (isChecked)?1. : 0.);
mCallback.onRequestRender(); if(mListener != null) mListener.OnModelOptionsChanged();
} }
}); });
_listView.addItem("Display", showMeshSurfaceEdges); _listView.addItem("Display", showMeshSurfaceEdges);
...@@ -84,7 +83,7 @@ public class OptionsDisplayFragment extends Fragment{ ...@@ -84,7 +83,7 @@ public class OptionsDisplayFragment extends Fragment{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
_gmsh.setDoubleOption("Mesh", "VolumeEdges", (isChecked)?1. : 0.); _gmsh.setDoubleOption("Mesh", "VolumeEdges", (isChecked)?1. : 0.);
mCallback.onRequestRender(); if(mListener != null) mListener.OnModelOptionsChanged();
} }
}); });
_listView.addItem("Display", showMeshVolumesEdges); _listView.addItem("Display", showMeshVolumesEdges);
...@@ -107,7 +106,7 @@ public class OptionsDisplayFragment extends Fragment{ ...@@ -107,7 +106,7 @@ public class OptionsDisplayFragment extends Fragment{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
_gmsh.setPView(myID, -1, (isChecked)? 1 : 0, -1); _gmsh.setPView(myID, -1, (isChecked)? 1 : 0, -1);
mCallback.onRequestRender(); if(mListener != null) mListener.OnModelOptionsChanged();
} }
}); });
Button button = new Button(_listView.getContext()); Button button = new Button(_listView.getContext());
...@@ -129,20 +128,9 @@ public class OptionsDisplayFragment extends Fragment{ ...@@ -129,20 +128,9 @@ public class OptionsDisplayFragment extends Fragment{
} }
} }
@Override private OnModelOptionsChangedListener mListener;
public void onAttach(Activity activity) { public void setOnModelOptionsChangedListener(OnModelOptionsChangedListener listener) { mListener = listener;}
super.onAttach(activity); public interface OnModelOptionsChangedListener {
try { void OnModelOptionsChanged();
mCallback = (OnOptionRequestRender) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
private OnOptionRequestRender mCallback;
public interface OnOptionRequestRender {
public void onRequestRender();
} }
} }
...@@ -41,6 +41,12 @@ public class OptionsFragment extends Fragment{ ...@@ -41,6 +41,12 @@ public class OptionsFragment extends Fragment{
Bundle savedInstanceState) { Bundle savedInstanceState) {
LinearLayout rootView = (LinearLayout)inflater.inflate(R.layout.fragment_options, container, false); LinearLayout rootView = (LinearLayout)inflater.inflate(R.layout.fragment_options, container, false);
_optionModelFragment = OptionsModelFragment.newInstance(_gmsh); _optionModelFragment = OptionsModelFragment.newInstance(_gmsh);
_optionModelFragment.setOnModelOptionsChangedListener(new OptionsModelFragment.OnModelOptionsChangedListener() {
public void OnModelOptionsChanged() {
if(mListener != null) mListener.OnOptionsChanged();
}
});
_optionDisplayFragment = OptionsDisplayFragment.newInstance(_gmsh); _optionDisplayFragment = OptionsDisplayFragment.newInstance(_gmsh);
final Button optionModel = (Button) rootView.findViewById(R.id.goto_options_model); final Button optionModel = (Button) rootView.findViewById(R.id.goto_options_model);
final Button optionDisplay = (Button) rootView.findViewById(R.id.goto_options_display); final Button optionDisplay = (Button) rootView.findViewById(R.id.goto_options_display);
...@@ -91,4 +97,10 @@ public class OptionsFragment extends Fragment{ ...@@ -91,4 +97,10 @@ public class OptionsFragment extends Fragment{
if(_optionDisplayFragment != null)_optionDisplayFragment.refresh(); if(_optionDisplayFragment != null)_optionDisplayFragment.refresh();
if(_optionModelFragment != null)_optionModelFragment.refresh(); if(_optionModelFragment != null)_optionModelFragment.refresh();
} }
private OnOptionsChangedListener mListener;
public void setOnOptionsChangedListener(OnOptionsChangedListener listener) { mListener = listener;}
public interface OnOptionsChangedListener {
void OnOptionsChanged();
}
} }
...@@ -3,6 +3,8 @@ package org.geuz.onelab; ...@@ -3,6 +3,8 @@ package org.geuz.onelab;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.geuz.onelab.OptionsFragment.OnOptionsChangedListener;
import android.app.Fragment; import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -25,7 +27,6 @@ public class OptionsModelFragment extends Fragment{ ...@@ -25,7 +27,6 @@ public class OptionsModelFragment extends Fragment{
public OptionsModelFragment() { public OptionsModelFragment() {
super(); super();
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -45,6 +46,7 @@ public class OptionsModelFragment extends Fragment{ ...@@ -45,6 +46,7 @@ public class OptionsModelFragment extends Fragment{
public void refresh() { public void refresh() {
if(_gmsh == null) return; if(_gmsh == null) return;
this.getAvailableParam(); this.getAvailableParam();
if(_listView != null) _listView.refresh();
} }
private void getAvailableParam(){ private void getAvailableParam(){
...@@ -64,15 +66,29 @@ public class OptionsModelFragment extends Fragment{ ...@@ -64,15 +66,29 @@ public class OptionsModelFragment extends Fragment{
if(found) continue; if(found) continue;
// add new parameter // add new parameter
if(s.split(Character.toString((char)0x03))[1].equals("number")){ if(s.split(Character.toString((char)0x03))[1].equals("number")){
final ParameterNumber mParam = new ParameterNumber(_listView.getContext(), _gmsh, mCallback, ""); final ParameterNumber mParam = new ParameterNumber(_listView.getContext(), _gmsh, "");
if(mParam.fromString(s) == -1) continue; if(mParam.fromString(s) == -1) continue;
mParam.setOnParameterChangedListener(new ParameterNumber.OnParameterChangedListener() {
public void OnParameterChanged() {
if(_gmsh.onelabCB("check") > 0 && mListener != null) mListener.OnModelOptionsChanged();;
refresh();
}
});
params.add(mParam); params.add(mParam);
if(_listView != null) if(_listView != null)
_listView.addItem(mParam.getName().split("/")[0].equals("Parameters")? mParam.getName().split("/")[0] + " > " + mParam.getName().split("/")[1]: mParam.getName().split("/")[0], mParam.getView()); _listView.addItem(mParam.getName().split("/")[0].equals("Parameters")? mParam.getName().split("/")[0] + " > " + mParam.getName().split("/")[1]: mParam.getName().split("/")[0], mParam.getView());
} }
else if(s.split("|")[1].equals("string")){ else if(s.split("|")[1].equals("string")){
ParameterString mParam = new ParameterString(_listView.getContext(), _gmsh, mCallback, ""); ParameterString mParam = new ParameterString(_listView.getContext(), _gmsh, "");
if(mParam.fromString(s) != -1){ if(mParam.fromString(s) != -1){
mParam.setOnParameterChangedListener(new ParameterString.OnParameterChangedListener() {
public void OnParameterChanged() {
if(_gmsh.onelabCB("check") > 0 && mListener != null) mListener.OnModelOptionsChanged();
refresh();
}
});
params.add(mParam); params.add(mParam);
if(_listView != null) if(_listView != null)
_listView.addItem(mParam.getName().split("/")[0], mParam.getView()); _listView.addItem(mParam.getName().split("/")[0], mParam.getView());
...@@ -80,8 +96,9 @@ public class OptionsModelFragment extends Fragment{ ...@@ -80,8 +96,9 @@ public class OptionsModelFragment extends Fragment{
} }
} }
} }
private OnOptionRequestRender mCallback; private OnModelOptionsChangedListener mListener;
public interface OnOptionRequestRender { public void setOnModelOptionsChangedListener(OnModelOptionsChangedListener listener) { mListener = listener;}
public void onRequestRender(); public interface OnModelOptionsChangedListener {
void OnModelOptionsChanged();
} }
} }
...@@ -52,7 +52,7 @@ public class OptionsPostProcessingFragment extends Fragment{ ...@@ -52,7 +52,7 @@ public class OptionsPostProcessingFragment extends Fragment{
LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.fragment_postprocessing, container, false); LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.fragment_postprocessing, container, false);
final Spinner intervalsType = (Spinner)layout.findViewById(R.id.intervals_type); final Spinner intervalsType = (Spinner)layout.findViewById(R.id.intervals_type);
final EditText intervals = (EditText)layout.findViewById(R.id.intervals); final EditText intervals = (EditText)layout.findViewById(R.id.intervals);
final SeekBar raiseZ = (SeekBar)layout.findViewById(R.id.raisez); final SeekBar raiseZ = (SeekBar)layout.findViewById(R.id.raisez); // TODO
intervalsType.setEnabled(infos[2].equals("1")); intervalsType.setEnabled(infos[2].equals("1"));
ArrayList<String> choices; ArrayList<String> choices;
ArrayAdapter<String> adapter; ArrayAdapter<String> adapter;
......
package org.geuz.onelab; package org.geuz.onelab;
import org.geuz.onelab.OptionsModelFragment.OnOptionRequestRender;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.widget.LinearLayout; import android.widget.LinearLayout;
...@@ -12,18 +9,15 @@ import android.widget.TextView; ...@@ -12,18 +9,15 @@ import android.widget.TextView;
public class Parameter { public class Parameter {
protected Context _context; protected Context _context;
protected Gmsh _gmsh; protected Gmsh _gmsh;
protected SeparatedListView _listView;
protected OnOptionRequestRender _callback;
protected String _name; protected String _name;
protected String _label; protected String _label;
protected boolean _readOnly; protected boolean _readOnly;
protected boolean _changed; protected boolean _changed;
protected TextView _title; protected TextView _title;
public Parameter(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name){ public Parameter(Context context, Gmsh gmsh, String name){
_context = context; _context = context;
_gmsh = gmsh; _gmsh = gmsh;
_callback = callback;
_readOnly = false; _readOnly = false;
_name = name; _name = name;
_title = new TextView(context); _title = new TextView(context);
...@@ -31,8 +25,8 @@ public class Parameter { ...@@ -31,8 +25,8 @@ public class Parameter {
_title.setTextAppearance(context, android.R.style.TextAppearance_DeviceDefault_Medium); _title.setTextAppearance(context, android.R.style.TextAppearance_DeviceDefault_Medium);
_title.setTextColor(Color.DKGRAY); _title.setTextColor(Color.DKGRAY);
} }
public Parameter(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name, boolean readOnly){ public Parameter(Context context, Gmsh gmsh, String name, boolean readOnly){
this(context, gmsh, callback, name); this(context, gmsh, name);
_readOnly = readOnly; _readOnly = readOnly;
_changed = false; _changed = false;
} }
...@@ -75,8 +69,6 @@ public class Parameter { ...@@ -75,8 +69,6 @@ public class Parameter {
public boolean changed() { if(_changed){_changed=false; return true;}return _changed;} public boolean changed() { if(_changed){_changed=false; return true;}return _changed;}
public String getType(){return "Parameter";} public String getType(){return "Parameter";}
public void setList(SeparatedListView list){ _listView = list;}
public LinearLayout getView() { public LinearLayout getView() {
LinearLayout paramLayout = new LinearLayout(_context); LinearLayout paramLayout = new LinearLayout(_context);
paramLayout.setOrientation(LinearLayout.VERTICAL); paramLayout.setOrientation(LinearLayout.VERTICAL);
......
...@@ -2,8 +2,6 @@ package org.geuz.onelab; ...@@ -2,8 +2,6 @@ package org.geuz.onelab;
import java.util.ArrayList; import java.util.ArrayList;
import org.geuz.onelab.OptionsModelFragment.OnOptionRequestRender;
import android.content.Context; import android.content.Context;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
...@@ -30,20 +28,20 @@ public class ParameterNumber extends Parameter{ ...@@ -30,20 +28,20 @@ public class ParameterNumber extends Parameter{
private CheckBox _checkbox; private CheckBox _checkbox;
private EditText _edittext; private EditText _edittext;
public ParameterNumber(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name){ public ParameterNumber(Context context, Gmsh gmsh, String name){
super(context, gmsh, callback, name); super(context, gmsh, name);
} }
public ParameterNumber(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name, double value, double min, double max, double step) public ParameterNumber(Context context, Gmsh gmsh, String name, double value, double min, double max, double step)
{ {
this(context, gmsh, callback, name); this(context, gmsh, name);
_value = value; _value = value;
_min = min; _min = min;
_max = max; _max = max;
_step = step; _step = step;
} }
public ParameterNumber(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name, boolean readOnly, double value, double min, double max, double step) public ParameterNumber(Context context, Gmsh gmsh, String name, boolean readOnly, double value, double min, double max, double step)
{ {
this(context, gmsh, callback, name, value, min, max, step); this(context, gmsh, name, value, min, max, step);
_readOnly = readOnly; _readOnly = readOnly;
} }
...@@ -84,7 +82,8 @@ public class ParameterNumber extends Parameter{ ...@@ -84,7 +82,8 @@ public class ParameterNumber extends Parameter{
Log.w("ParameterNumber", "Incorect value "+value+" (max="+_max+" min="+_min+")"); Log.w("ParameterNumber", "Incorect value "+value+" (max="+_max+" min="+_min+")");
return; return;
} }
if(value != _value) if(value == _value) return;
if(mListener != null) mListener.OnParameterChanged();
_changed = true; _changed = true;
_value = value; _value = value;
this.update(); this.update();
...@@ -142,9 +141,7 @@ public class ParameterNumber extends Parameter{ ...@@ -142,9 +141,7 @@ public class ParameterNumber extends Parameter{
int nChoix = Integer.parseInt(infos[pos++]); // choices' size int nChoix = Integer.parseInt(infos[pos++]); // choices' size
double choices[] = new double[nChoix]; double choices[] = new double[nChoix];
for(int i=0; i<nChoix; i++) for(int i=0; i<nChoix; i++)
if(nChoix == 2)
choices[i] = Double.parseDouble(infos[pos++]); // choice choices[i] = Double.parseDouble(infos[pos++]); // choice
else pos++;
int nLabels = Integer.parseInt(infos[pos++]); // labels' size int nLabels = Integer.parseInt(infos[pos++]); // labels' size
if(nChoix == 2 && choices[0] == 0 && choices[1] == 1 && nLabels == 0) { if(nChoix == 2 && choices[0] == 0 && choices[1] == 1 && nLabels == 0) {
_checkbox = new CheckBox(_context); _checkbox = new CheckBox(_context);
...@@ -172,23 +169,14 @@ public class ParameterNumber extends Parameter{ ...@@ -172,23 +169,14 @@ public class ParameterNumber extends Parameter{
if(_spinner != null) { if(_spinner != null) {
paramLayout.addView(_spinner); paramLayout.addView(_spinner);
_spinner.setEnabled(!_readOnly); _spinner.setEnabled(!_readOnly);
_spinner.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(_listView != null) _listView.refresh();
}
});
_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { _spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onNothingSelected(AdapterView<?> arg0) {} public void onNothingSelected(AdapterView<?> arg0) {}
public void onItemSelected(AdapterView<?> parent, View view, public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) { int pos, long id) {
if(_listView != null) _listView.refresh();
setValue(_values.get(pos)); setValue(_values.get(pos));
_gmsh.setParam(getType(), getName(), String.valueOf(_values.get(pos))); _gmsh.setParam(getType(), getName(), String.valueOf(_values.get(pos)));
if(_gmsh.onelabCB("check") == 1 && _callback != null)
_callback.onRequestRender();
} }
}); });
...@@ -200,14 +188,11 @@ public class ParameterNumber extends Parameter{ ...@@ -200,14 +188,11 @@ public class ParameterNumber extends Parameter{
public void onStopTrackingTouch(SeekBar seekBar) { public void onStopTrackingTouch(SeekBar seekBar) {
_gmsh.setParam(getType(), getName(), String.valueOf(getValue())); // update parameter and the perform a check _gmsh.setParam(getType(), getName(), String.valueOf(getValue())); // update parameter and the perform a check
if(_gmsh.onelabCB("check") == 1 && _callback != null)
_callback.onRequestRender();
} }
public void onStartTrackingTouch(SeekBar seekBar) {} public void onStartTrackingTouch(SeekBar seekBar) {}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(_listView != null) _listView.refresh();
setValue(getMin() + getStep()*(double)progress); setValue(getMin() + getStep()*(double)progress);
} }
}); });
...@@ -219,7 +204,6 @@ public class ParameterNumber extends Parameter{ ...@@ -219,7 +204,6 @@ public class ParameterNumber extends Parameter{
_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { _checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(_listView != null) _listView.refresh();
setValue((isChecked)? 1 : 0); setValue((isChecked)? 1 : 0);
_gmsh.setParam(getType(), getName(), String.valueOf(_value)); _gmsh.setParam(getType(), getName(), String.valueOf(_value));
} }
...@@ -247,7 +231,6 @@ public class ParameterNumber extends Parameter{ ...@@ -247,7 +231,6 @@ public class ParameterNumber extends Parameter{
_edittext.addTextChangedListener(new TextWatcher() { _edittext.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
if(_listView != null) _listView.refresh();
double value = 1; double value = 1;
try { try {
if(s.length() < 1) value = 1; if(s.length() < 1) value = 1;
...@@ -269,4 +252,9 @@ public class ParameterNumber extends Parameter{ ...@@ -269,4 +252,9 @@ public class ParameterNumber extends Parameter{
} }
return paramLayout; return paramLayout;
} }
private OnParameterChangedListener mListener;
public void setOnParameterChangedListener(OnParameterChangedListener listener) { mListener = listener;}
public interface OnParameterChangedListener {
void OnParameterChanged();
}
} }
...@@ -2,8 +2,6 @@ package org.geuz.onelab; ...@@ -2,8 +2,6 @@ package org.geuz.onelab;
import java.util.ArrayList; import java.util.ArrayList;
import org.geuz.onelab.OptionsModelFragment.OnOptionRequestRender;
import android.content.Context; import android.content.Context;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
...@@ -25,8 +23,8 @@ public class ParameterString extends Parameter{ ...@@ -25,8 +23,8 @@ public class ParameterString extends Parameter{
private Spinner _spinner; private Spinner _spinner;
private EditText _edittext; private EditText _edittext;
public ParameterString(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name) { public ParameterString(Context context, Gmsh gmsh, String name) {
super(context, gmsh, callback, name); super(context, gmsh, name);
_choices = new ArrayList<String>(); _choices = new ArrayList<String>();
_choices.add("-"); // Default choice _choices.add("-"); // Default choice
} }
...@@ -48,15 +46,24 @@ public class ParameterString extends Parameter{ ...@@ -48,15 +46,24 @@ public class ParameterString extends Parameter{
_edittext.setText(_choices.get(0)); _edittext.setText(_choices.get(0));
} }
public void setValue(int index) {if(index != _index)_changed = true;_index = index;this.update();} public void setValue(int index) {
if(index == _index) return;
if(mListener != null) mListener.OnParameterChanged();
_changed = true;
_index = index;
this.update();
}
public void setValue(String value) { public void setValue(String value) {
int index = _choices.indexOf(value); int index = _choices.indexOf(value);
if(index < 0) { // the value is not in the list, add it if(index < 0) { // the value is not in the list, add it
this.addChoices(value); this.addChoices(value);
index = _choices.indexOf(value); index = _choices.indexOf(value);
} }
if(index != _index)_changed = true; if(index == _index) return;
_index = index;this.update(); if(mListener != null) mListener.OnParameterChanged();
_changed = true;
_index = index;
this.update();
} }
public void setKind(String kind) {_kind = kind;} public void setKind(String kind) {_kind = kind;}
public void addChoices(String choice) { public void addChoices(String choice) {
...@@ -73,6 +80,7 @@ public class ParameterString extends Parameter{ ...@@ -73,6 +80,7 @@ public class ParameterString extends Parameter{
public int getIndex() {return _index;} public int getIndex() {return _index;}
public ArrayList<String> getChoices() {return _choices;} public ArrayList<String> getChoices() {return _choices;}
public int fromString(String s){ public int fromString(String s){
_choices.clear();
int pos = super.fromString(s); int pos = super.fromString(s);
if(pos <= 0) return -1; // error if(pos <= 0) return -1; // error
String[] infos = s.split(Character.toString((char)0x03)); String[] infos = s.split(Character.toString((char)0x03));
...@@ -97,23 +105,15 @@ public class ParameterString extends Parameter{ ...@@ -97,23 +105,15 @@ public class ParameterString extends Parameter{
if(_spinner != null){ if(_spinner != null){
paramLayout.addView(_spinner); paramLayout.addView(_spinner);
_spinner.setEnabled(!_readOnly); _spinner.setEnabled(!_readOnly);
_spinner.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(_listView != null) _listView.refresh();
}
});
_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { _spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onNothingSelected(AdapterView<?> arg0) {} public void onNothingSelected(AdapterView<?> arg0) {}
public void onItemSelected(AdapterView<?> parent, View view, public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) { int pos, long id) {
if(getValue() == getChoices().get(pos)) return;
setValue(pos); setValue(pos);
_gmsh.setParam(getType(), getName(), String.valueOf(getValue())); _gmsh.setParam(getType(), getName(), String.valueOf(getValue()));
if(_gmsh.onelabCB("check") == 1 && _callback != null)
_callback.onRequestRender();
if(_listView != null) _listView.refresh();
} }
}); });
...@@ -136,9 +136,7 @@ public class ParameterString extends Parameter{ ...@@ -136,9 +136,7 @@ public class ParameterString extends Parameter{
}); });
_edittext.addTextChangedListener(new TextWatcher() { _edittext.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) { } // UNUSED Auto-generated method stub
if(_listView != null) _listView.refresh();
}
public void beforeTextChanged(CharSequence s, int start, int count, public void beforeTextChanged(CharSequence s, int start, int count,
int after) {} // UNUSED Auto-generated method stub int after) {} // UNUSED Auto-generated method stub
...@@ -150,5 +148,10 @@ public class ParameterString extends Parameter{ ...@@ -150,5 +148,10 @@ public class ParameterString extends Parameter{
} }
return paramLayout; return paramLayout;
} }
private OnParameterChangedListener mListener;
public void setOnParameterChangedListener(OnParameterChangedListener listener) { mListener = listener;}
public interface OnParameterChangedListener {
void OnParameterChanged();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment