1 package org.geuz.onelab; 2 3 import org.geuz.onelab.Gmsh; 4 5 import android.os.Bundle; 6 import android.os.Parcelable; 7 import android.app.Fragment; 8 import android.content.Intent; 9 import android.graphics.Color; 10 import android.view.Gravity; 11 import android.view.LayoutInflater; 12 import android.view.View; 13 import android.view.ViewGroup; 14 import android.view.ViewGroup.LayoutParams; 15 import android.widget.AbsListView; 16 import android.widget.Button; 17 import android.widget.CheckBox; 18 import android.widget.CompoundButton; 19 import android.widget.LinearLayout; 20 21 public class OptionsDisplayFragment extends Fragment { 22 private Gmsh _gmsh; 23 private SeparatedListView _listView; 24 newInstance(Gmsh g)25 public static OptionsDisplayFragment newInstance(Gmsh g) 26 { 27 OptionsDisplayFragment fragment = new OptionsDisplayFragment(); 28 Bundle bundle = new Bundle(); 29 bundle.putParcelable("Gmsh", g); 30 fragment.setArguments(bundle); 31 return fragment; 32 } 33 OptionsDisplayFragment()34 public OptionsDisplayFragment() { super(); } 35 onCreate(Bundle savedInstanceState)36 @Override public void onCreate(Bundle savedInstanceState) 37 { 38 super.onCreate(savedInstanceState); 39 _gmsh = getArguments().getParcelable("Gmsh"); 40 } 41 42 @Override onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState)43 public View onCreateView(LayoutInflater inflater, final ViewGroup container, 44 Bundle savedInstanceState) 45 { 46 _listView = (SeparatedListView)inflater.inflate( 47 R.layout.fragment_options_display, container, false); 48 CheckBox showGeomPoints = new CheckBox(_listView.getContext()); 49 showGeomPoints.setText("Show geometry points"); 50 showGeomPoints.setChecked(_gmsh.getDoubleOption("Geometry", "Points", 0) > 51 0.); 52 showGeomPoints.setOnCheckedChangeListener( 53 new CompoundButton.OnCheckedChangeListener() { 54 public void onCheckedChanged(CompoundButton buttonView, 55 boolean isChecked) 56 { 57 _gmsh.setDoubleOption("Geometry", "Points", (isChecked) ? 1. : 0., 0); 58 if(mListener != null) mListener.OnModelOptionsChanged(); 59 } 60 }); 61 _listView.addItem("Display Options", showGeomPoints); 62 CheckBox showGeomLines = new CheckBox(_listView.getContext()); 63 showGeomLines.setText("Show geometry lines"); 64 showGeomLines.setChecked(_gmsh.getDoubleOption("Geometry", "Lines", 0) > 65 0.); 66 showGeomLines.setOnCheckedChangeListener( 67 new CompoundButton.OnCheckedChangeListener() { 68 public void onCheckedChanged(CompoundButton buttonView, 69 boolean isChecked) 70 { 71 _gmsh.setDoubleOption("Geometry", "Lines", (isChecked) ? 1. : 0., 0); 72 if(mListener != null) mListener.OnModelOptionsChanged(); 73 } 74 }); 75 _listView.addItem("Display Options", showGeomLines); 76 CheckBox showMeshSurfaceEdges = new CheckBox(_listView.getContext()); 77 showMeshSurfaceEdges.setText("Show mesh surface edges"); 78 showMeshSurfaceEdges.setChecked( 79 _gmsh.getDoubleOption("Mesh", "SurfaceEdges", 0) > 0.); 80 showMeshSurfaceEdges.setOnCheckedChangeListener( 81 new CompoundButton.OnCheckedChangeListener() { 82 public void onCheckedChanged(CompoundButton buttonView, 83 boolean isChecked) 84 { 85 _gmsh.setDoubleOption("Mesh", "SurfaceEdges", (isChecked) ? 1. : 0., 86 0); 87 if(mListener != null) mListener.OnModelOptionsChanged(); 88 } 89 }); 90 _listView.addItem("Display Options", showMeshSurfaceEdges); 91 CheckBox showMeshVolumesEdges = new CheckBox(_listView.getContext()); 92 showMeshVolumesEdges.setText("Show mesh volume edges"); 93 showMeshVolumesEdges.setChecked( 94 _gmsh.getDoubleOption("Mesh", "VolumeEdges", 0) > 0.); 95 showMeshVolumesEdges.setOnCheckedChangeListener( 96 new CompoundButton.OnCheckedChangeListener() { 97 public void onCheckedChanged(CompoundButton buttonView, 98 boolean isChecked) 99 { 100 _gmsh.setDoubleOption("Mesh", "VolumeEdges", (isChecked) ? 1. : 0., 101 0); 102 if(mListener != null) mListener.OnModelOptionsChanged(); 103 } 104 }); 105 _listView.addItem("Display Options", showMeshVolumesEdges); 106 this.refresh(); 107 return _listView; 108 } 109 refresh()110 public void refresh() 111 { 112 if(_gmsh == null) return; 113 int nbviews = (int)_gmsh.getDoubleOption("PostProcessing", "NbViews", 0); 114 115 for(int i = 0; i < _listView.itemsCountInSection("Result Options"); i++) { 116 View v = (View)_listView.getItemAtPosition(6 + i); 117 if(!v.getClass().equals(LinearLayout.class)) continue; 118 for(int j = 0; j < ((LinearLayout)v).getChildCount(); j++) { 119 View sv = ((LinearLayout)v).getChildAt(j); 120 if(sv.getClass().equals(CheckBox.class)) { 121 ((CheckBox)sv) 122 .setChecked(_gmsh.getDoubleOption("View", "Visible", i) > 0.); 123 } 124 } 125 } 126 for(int i = _listView.itemsCountInSection("Result Options"); i < nbviews; 127 i++) { 128 final int myID = i; 129 LinearLayout layout = new LinearLayout(_listView.getContext()); 130 CheckBox checkbox = new CheckBox(_listView.getContext()); 131 checkbox.setLayoutParams(new AbsListView.LayoutParams( 132 LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 133 checkbox.setText(_gmsh.getStringOption("View", "Name", myID)); 134 checkbox.setChecked(_gmsh.getDoubleOption("View", "Visible", myID) > 0.); 135 checkbox.setOnCheckedChangeListener( 136 new CompoundButton.OnCheckedChangeListener() { 137 public void onCheckedChanged(CompoundButton buttonView, 138 boolean isChecked) 139 { 140 _gmsh.setDoubleOption("View", "Visible", isChecked ? 1. : 0., myID); 141 if(mListener != null) mListener.OnModelOptionsChanged(); 142 } 143 }); 144 Button button = new Button(_listView.getContext()); 145 button.setText(">"); 146 button.setOnClickListener(new View.OnClickListener() { 147 public void onClick(View v) 148 { 149 Intent intent = 150 new Intent(getActivity(), PostProcessingActivity.class); 151 intent.putExtra("Gmsh", (Parcelable)_gmsh); 152 intent.putExtra("PView", myID); 153 startActivity(intent); 154 if(mListener != null) mListener.OnModelOptionsChanged(); 155 } 156 }); 157 button.setLayoutParams(new AbsListView.LayoutParams( 158 LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); 159 button.setBackgroundColor(Color.TRANSPARENT); 160 button.setGravity(Gravity.RIGHT); 161 layout.addView(checkbox); 162 layout.addView(button); 163 _listView.addItem("Result Options", layout); 164 } 165 } 166 167 private OnModelOptionsChangedListener mListener; 168 public void setOnModelOptionsChangedListener(OnModelOptionsChangedListener listener)169 setOnModelOptionsChangedListener(OnModelOptionsChangedListener listener) 170 { 171 mListener = listener; 172 } 173 public interface OnModelOptionsChangedListener { OnModelOptionsChanged()174 void OnModelOptionsChanged(); 175 } 176 } 177