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

Android: Use Fragment instead of ViewPager.

parent 8838b43c
Branches
Tags
No related merge requests found
Showing
with 548 additions and 477 deletions
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/model_fragment"
android:name="org.geuz.onelab.ModelFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
tools:context=".MainActivity" />
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
android:showDividers="middle"
tools:context=".MainActivity" >
<FrameLayout android:id="@+id/parameter_fragment"
android:name="org.geuz.onelab.OptionsDisplayFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout android:id="@+id/model_fragment"
android:name="org.geuz.onelab.ModelFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_weight="3" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/glViewLayout" />
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="4dip"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:id="@+id/options_fragment"
android:name="org.geuz.onelab.OptionsModelFragment"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1" />
<View android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray" />
<LinearLayout android:orientation="horizontal"
android:gravity="center" android:measureWithLargestChild="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<Button android:id="@+id/goto_options_model"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Model">
</Button>
<Button android:id="@+id/goto_options_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display">
</Button>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<org.geuz.onelab.SeparatedListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="48dp"
android:id="@+id/displayOptionsList">
</org.geuz.onelab.SeparatedListView>
\ No newline at end of file
...@@ -51,7 +51,6 @@ public class GLESRender implements Renderer{ ...@@ -51,7 +51,6 @@ public class GLESRender implements Renderer{
} }
public void onSurfaceCreated(GL10 gl, EGLConfig config) { public void onSurfaceCreated(GL10 gl, EGLConfig config) {
} }
} }
package org.geuz.onelab;
import android.app.Fragment;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
public class ModelFragment extends Fragment{
Gmsh _gmsh;
mGLSurfaceView _glView;
public static ModelFragment newInstance(Gmsh g) {
ModelFragment fragment = new ModelFragment();
Bundle bundle = new Bundle();
bundle.putParcelable("Gmsh", g);
fragment.setArguments(bundle);
return fragment;
}
public ModelFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_gmsh = getArguments().getParcelable("Gmsh");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_model, container, false);
LinearLayout glViewLayout = (LinearLayout)rootView.findViewById(R.id.glViewLayout);
GLESRender renderer = new GLESRender(_gmsh);
_glView = new mGLSurfaceView(glViewLayout.getContext(), renderer);
_glView.setEGLContextClientVersion(1);
_glView.setRenderer(renderer);
_glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
_glView.requestRender();
glViewLayout.addView(_glView);
return rootView;
}
public void requestRender() {
_glView.requestRender();
}
}
package org.geuz.onelab;
import android.os.Bundle;
import android.app.Activity;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
public class OptionsDisplayFragment extends Fragment{
private Gmsh _gmsh;
private SeparatedListView _listView;
public static OptionsDisplayFragment newInstance(Gmsh g) {
OptionsDisplayFragment fragment = new OptionsDisplayFragment();
Bundle bundle = new Bundle();
bundle.putParcelable("Gmsh", g);
fragment.setArguments(bundle);
return fragment;
}
public OptionsDisplayFragment() {
super();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_gmsh = getArguments().getParcelable("Gmsh");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
_listView = (SeparatedListView)inflater.inflate(R.layout.fragment_options_display, container, false);
CheckBox showGeomPoints = new CheckBox(_listView.getContext());
showGeomPoints.setText("Show geometry points");
showGeomPoints.setChecked((_gmsh.getDoubleOption("Geometry", "Points") > 0.));
showGeomPoints.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
_gmsh.setDoubleOption("Geometry", "Points", (isChecked)?1. : 0.);
mCallback.onRequestRender();
}
});
_listView.addItem("Display", showGeomPoints);
CheckBox showGeomLines = new CheckBox(_listView.getContext());
showGeomLines.setText("Show geometry lines");
showGeomLines.setChecked((_gmsh.getDoubleOption("Geometry", "Lines") > 0.));
showGeomLines.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
_gmsh.setDoubleOption("Geometry", "Lines", (isChecked)?1. : 0.);
mCallback.onRequestRender();
}
});
_listView.addItem("Display", showGeomLines);
CheckBox showMeshSurfaceEdges = new CheckBox(_listView.getContext());
showMeshSurfaceEdges.setText("Show mesh surface edges");
showMeshSurfaceEdges.setChecked((_gmsh.getDoubleOption("Mesh", "SurfaceEdges") > 0.));
showMeshSurfaceEdges.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
_gmsh.setDoubleOption("Mesh", "SurfaceEdges", (isChecked)?1. : 0.);
mCallback.onRequestRender();
}
});
_listView.addItem("Display", showMeshSurfaceEdges);
CheckBox showMeshVolumesEdges = new CheckBox(_listView.getContext());
showMeshVolumesEdges.setText("Show mesh volume edges");
showMeshVolumesEdges.setChecked((_gmsh.getDoubleOption("Mesh", "VolumeEdges") > 0.));
showMeshVolumesEdges.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
_gmsh.setDoubleOption("Mesh", "VolumeEdges", (isChecked)?1. : 0.);
mCallback.onRequestRender();
}
});
_listView.addItem("Display", showMeshVolumesEdges);
this.refresh();
return _listView;
}
public void refresh() {
if(_gmsh == null) return;
String[] PViews = _gmsh.getPView();
for(int i=_listView.itemsCountInSection("Result"); i < PViews.length;i++){
String[] infos = PViews[i].split("\n"); // name / IntervalsType (1=Iso 2=Continous 3=Discrete 4=Numeric)
final int myID = i;
CheckBox checkbox = new CheckBox(_listView.getContext());
checkbox.setText(infos[0]);
checkbox.setChecked(infos[2].equals("1"));
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
_gmsh.setPView(myID, -1, (isChecked)? 1 : 0, -1);
mCallback.onRequestRender();
}
});
_listView.addItem("Result", checkbox);
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mCallback = (OnOptionRequestRender) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
private OnOptionRequestRender mCallback;
public interface OnOptionRequestRender {
public void onRequestRender();
}
}
package org.geuz.onelab;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.app.Fragment;
import android.app.FragmentTransaction;
public class OptionsFragment extends Fragment{
private Gmsh _gmsh;
private OptionsDisplayFragment _optionDisplayFragment;
private OptionsModelFragment _optionModelFragment;
public static OptionsFragment newInstance(Gmsh g) {
OptionsFragment fragment = new OptionsFragment();
Bundle bundle = new Bundle();
bundle.putParcelable("Gmsh", g);
fragment.setArguments(bundle);
return fragment;
}
public OptionsFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_gmsh = getArguments().getParcelable("Gmsh");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
LinearLayout rootView = (LinearLayout)inflater.inflate(R.layout.fragment_options, container, false);
_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);
optionModel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.options_fragment, _optionModelFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.commit();
}
});
optionDisplay.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.options_fragment, _optionDisplayFragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.commit();
}
});
return rootView;
}
public void refresh() {
_optionDisplayFragment.refresh();
_optionModelFragment.refresh();
}
}
package org.geuz.onelab;
import java.util.ArrayList;
import java.util.List;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class OptionsModelFragment extends Fragment{
private Gmsh _gmsh;
private SeparatedListView _listView;
private List<Parameter> params = new ArrayList<Parameter>();
public static OptionsModelFragment newInstance(Gmsh g) {
OptionsModelFragment fragment = new OptionsModelFragment();
Bundle bundle = new Bundle();
bundle.putParcelable("Gmsh", g);
fragment.setArguments(bundle);
return fragment;
}
public OptionsModelFragment() {
super();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_gmsh = getArguments().getParcelable("Gmsh");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
params.clear();
_listView = (SeparatedListView)inflater.inflate(R.layout.fragment_options_display, container, false);
_listView.setDividerHeight(0);
this.refresh();
return _listView;
}
public void refresh() {
if(_gmsh == null) return;
this.getAvailableParam();
}
private void getAvailableParam(){
String[] tmp = _gmsh.getParams();
for(String s : tmp){ // for each parameters in ONEALB
boolean found = false;
for(Parameter p : params){ // for each parameters
if(s.split("\n")[2].equals(p.getName())){ // the parameter already exist, just refresh it
if(p.getType().equals("ParameterNumber"))
((ParameterNumber)p).fromString(s);
else if(p.getType().equals("ParameterString"))
((ParameterString)p).fromString(s);
found = true;
break;
}
}
if(found) continue;
// add new parameter
if(s.split("\n")[1].equals("number")){
final ParameterNumber mParam = new ParameterNumber(_listView.getContext(), _gmsh, mCallback, "");
if(mParam.fromString(s) == -1) continue;
params.add(mParam);
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());
}
else if(s.split("\n")[1].equals("string")){
ParameterString mParam = new ParameterString(_listView.getContext(), _gmsh, mCallback, "");
if(mParam.fromString(s) != -1){
params.add(mParam);
if(_listView != null)
_listView.addItem(mParam.getName().split("/")[0], mParam.getView());
}
}
}
}
private OnOptionRequestRender mCallback;
public interface OnOptionRequestRender {
public void onRequestRender();
}
}
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;
...@@ -11,17 +13,17 @@ public class Parameter { ...@@ -11,17 +13,17 @@ public class Parameter {
protected Context _context; protected Context _context;
protected Gmsh _gmsh; protected Gmsh _gmsh;
protected SeparatedListView _listView; protected SeparatedListView _listView;
protected mGLSurfaceView _glView; 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, mGLSurfaceView glView, String name){ public Parameter(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name){
_context = context; _context = context;
_gmsh = gmsh; _gmsh = gmsh;
_glView = glView; _callback = callback;
_readOnly = false; _readOnly = false;
_name = name; _name = name;
_title = new TextView(context); _title = new TextView(context);
...@@ -29,8 +31,8 @@ public class Parameter { ...@@ -29,8 +31,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, mGLSurfaceView glView, String name, boolean readOnly){ public Parameter(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name, boolean readOnly){
this(context, gmsh, glView, name); this(context, gmsh, callback, name);
_readOnly = readOnly; _readOnly = readOnly;
_changed = false; _changed = false;
} }
......
...@@ -2,6 +2,8 @@ package org.geuz.onelab; ...@@ -2,6 +2,8 @@ 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;
...@@ -28,20 +30,20 @@ public class ParameterNumber extends Parameter{ ...@@ -28,20 +30,20 @@ public class ParameterNumber extends Parameter{
private CheckBox _checkbox; private CheckBox _checkbox;
private EditText _edittext; private EditText _edittext;
public ParameterNumber(Context context, Gmsh gmsh, mGLSurfaceView glView, String name){ public ParameterNumber(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name){
super(context, gmsh, glView, name); super(context, gmsh, callback, name);
} }
public ParameterNumber(Context context, Gmsh gmsh, mGLSurfaceView glView, String name, double value, double min, double max, double step) public ParameterNumber(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name, double value, double min, double max, double step)
{ {
this(context, gmsh, glView, name); this(context, gmsh, callback, name);
_value = value; _value = value;
_min = min; _min = min;
_max = max; _max = max;
_step = step; _step = step;
} }
public ParameterNumber(Context context, Gmsh gmsh, mGLSurfaceView glView, String name, boolean readOnly, double value, double min, double max, double step) public ParameterNumber(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name, boolean readOnly, double value, double min, double max, double step)
{ {
this(context, gmsh, glView, name, value, min, max, step); this(context, gmsh, callback, name, value, min, max, step);
_readOnly = readOnly; _readOnly = readOnly;
} }
...@@ -185,8 +187,8 @@ public class ParameterNumber extends Parameter{ ...@@ -185,8 +187,8 @@ public class ParameterNumber extends Parameter{
if(_listView != null) _listView.refresh(); 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 && _glView != null) if(_gmsh.onelabCB("check") == 1 && _callback != null)
_glView.requestRender(); _callback.onRequestRender();
} }
}); });
...@@ -198,8 +200,8 @@ public class ParameterNumber extends Parameter{ ...@@ -198,8 +200,8 @@ 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 && _glView != null) if(_gmsh.onelabCB("check") == 1 && _callback != null)
_glView.requestRender(); _callback.onRequestRender();
} }
public void onStartTrackingTouch(SeekBar seekBar) {} public void onStartTrackingTouch(SeekBar seekBar) {}
......
...@@ -2,6 +2,8 @@ package org.geuz.onelab; ...@@ -2,6 +2,8 @@ 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;
...@@ -23,8 +25,8 @@ public class ParameterString extends Parameter{ ...@@ -23,8 +25,8 @@ public class ParameterString extends Parameter{
private Spinner _spinner; private Spinner _spinner;
private EditText _edittext; private EditText _edittext;
public ParameterString(Context context, Gmsh gmsh, mGLSurfaceView glView, String name) { public ParameterString(Context context, Gmsh gmsh, OnOptionRequestRender callback, String name) {
super(context, gmsh, glView, name); super(context, gmsh, callback, name);
_choices = new ArrayList<String>(); _choices = new ArrayList<String>();
_choices.add("-"); // Default choice _choices.add("-"); // Default choice
} }
...@@ -109,8 +111,8 @@ public class ParameterString extends Parameter{ ...@@ -109,8 +111,8 @@ public class ParameterString extends Parameter{
int pos, long id) { int pos, long id) {
setValue(pos); setValue(pos);
_gmsh.setParam(getType(), getName(), String.valueOf(getValue())); _gmsh.setParam(getType(), getName(), String.valueOf(getValue()));
if(_gmsh.onelabCB("check") == 1 && _glView != null) if(_gmsh.onelabCB("check") == 1 && _callback != null)
_glView.requestRender(); _callback.onRequestRender();
if(_listView != null) _listView.refresh(); if(_listView != null) _listView.refresh();
} }
......
...@@ -4,6 +4,7 @@ import java.util.ArrayList; ...@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -23,6 +24,9 @@ public class SeparatedListView extends ListView{ ...@@ -23,6 +24,9 @@ public class SeparatedListView extends ListView{
adapter = new SeparatedListAdaptater(); adapter = new SeparatedListAdaptater();
this.setAdapter(adapter); this.setAdapter(adapter);
} }
public SeparatedListView(Context context, AttributeSet attrs) {
this(context);
}
public SeparatedListView(Context context, View[] footer) { public SeparatedListView(Context context, View[] footer) {
super(context); super(context);
_context = context; _context = context;
...@@ -39,7 +43,9 @@ public class SeparatedListView extends ListView{ ...@@ -39,7 +43,9 @@ public class SeparatedListView extends ListView{
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
this.invalidateViews(); this.invalidateViews();
} }
public int itemsCountInSection(String header) {
return adapter.getCountForSection(header);
}
public void refresh() public void refresh()
{ {
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
...@@ -102,7 +108,12 @@ public class SeparatedListView extends ListView{ ...@@ -102,7 +108,12 @@ public class SeparatedListView extends ListView{
for(Section s : sections) count += s.getItemsCount() + 1; for(Section s : sections) count += s.getItemsCount() + 1;
return count; return count;
} }
public int getCountForSection(String header) {
for(Section s : sections)
if(s.getName().equals(header))
return s.getItemsCount();
return 0;
}
//@Override //@Override
public Object getItem(int position) { public Object getItem(int position) {
// UNUSED Auto-generated method stub // UNUSED Auto-generated method stub
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment