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

Android: SeekBar can now control the animation

parent 1a068e7c
Branches
Tags
No related merge requests found
...@@ -35,7 +35,8 @@ public class Gmsh implements Parcelable { ...@@ -35,7 +35,8 @@ public class Gmsh implements Parcelable {
public native int numberOfAnimation(); public native int numberOfAnimation();
public native int animationNext(); public native int animationNext();
public native int animationPrev(); public native int animationPrev();
public native void setAnimation(int animation);
/** Java CLASS **/ /** Java CLASS **/
private long ptr; private long ptr;
private Handler handler; private Handler handler;
......
...@@ -37,7 +37,7 @@ public class ModelFragment extends Fragment{ ...@@ -37,7 +37,7 @@ public class ModelFragment extends Fragment{
private GestureDetector _gestureDetector; private GestureDetector _gestureDetector;
private Timer _animation; private Timer _animation;
private Handler _hideDelay; private Handler _hideDelay;
private SeekBar _annimationStepper; private SeekBar _animationStepper;
final Runnable hideControlsRunnable = new Runnable() {public void run() {hideControlBar();}}; final Runnable hideControlsRunnable = new Runnable() {public void run() {hideControlBar();}};
...@@ -118,7 +118,19 @@ public class ModelFragment extends Fragment{ ...@@ -118,7 +118,19 @@ public class ModelFragment extends Fragment{
final ImageButton prevButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlPrev); final ImageButton prevButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlPrev);
final ImageButton playPauseButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlPlay); final ImageButton playPauseButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlPlay);
final ImageButton nextButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlNext); final ImageButton nextButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlNext);
_annimationStepper = (SeekBar)_controlBarLayout.findViewById(R.id.controlStepper); _animationStepper = (SeekBar)_controlBarLayout.findViewById(R.id.controlStepper);
_animationStepper.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {} // UNUSED Auto-generated method stub
public void onStartTrackingTouch(SeekBar seekBar) {} // UNUSED Auto-generated method stub
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(fromUser) {
postDelay();
_gmsh.setAnimation(progress);
requestRender();
}
}
});
_controlBarLayout.setEnabled(false); _controlBarLayout.setEnabled(false);
playPauseButton.setOnClickListener(new View.OnClickListener() { playPauseButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
...@@ -126,11 +138,11 @@ public class ModelFragment extends Fragment{ ...@@ -126,11 +138,11 @@ public class ModelFragment extends Fragment{
if(((ImageButton)v).getContentDescription().equals("play")) { if(((ImageButton)v).getContentDescription().equals("play")) {
((ImageButton)v).setContentDescription("pause"); ((ImageButton)v).setContentDescription("pause");
((ImageButton)v).setImageResource(android.R.drawable.ic_media_pause); ((ImageButton)v).setImageResource(android.R.drawable.ic_media_pause);
_annimationStepper.setMax(_gmsh.numberOfAnimation()); _animationStepper.setMax(_gmsh.numberOfAnimation());
_animation = new Timer(); _animation = new Timer();
_animation.schedule(new TimerTask() { _animation.schedule(new TimerTask() {
public void run() { public void run() {
_annimationStepper.setProgress(_gmsh.animationNext()); _animationStepper.setProgress(_gmsh.animationNext());
requestRender(); requestRender();
} }, 0, 500); } }, 0, 500);
prevButton.setEnabled(false); prevButton.setEnabled(false);
...@@ -148,14 +160,14 @@ public class ModelFragment extends Fragment{ ...@@ -148,14 +160,14 @@ public class ModelFragment extends Fragment{
nextButton.setOnClickListener(new View.OnClickListener() { nextButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
postDelay(); postDelay();
_annimationStepper.setProgress(_gmsh.animationNext()); _animationStepper.setProgress(_gmsh.animationNext());
requestRender(); requestRender();
} }
}); });
prevButton.setOnClickListener(new View.OnClickListener() { prevButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
postDelay(); postDelay();
_annimationStepper.setProgress(_gmsh.animationPrev()); _animationStepper.setProgress(_gmsh.animationPrev());
requestRender(); requestRender();
} }
}); });
...@@ -176,7 +188,7 @@ public class ModelFragment extends Fragment{ ...@@ -176,7 +188,7 @@ public class ModelFragment extends Fragment{
public void showControlBar() { public void showControlBar() {
if(getActivity() == null || ((MainActivity)getActivity()).isComputing() || !_gmsh.haveAnimation()) return; if(getActivity() == null || ((MainActivity)getActivity()).isComputing() || !_gmsh.haveAnimation()) return;
_controlBarLayout.setEnabled(true); _controlBarLayout.setEnabled(true);
_annimationStepper.setMax(_gmsh.numberOfAnimation()); _animationStepper.setMax(_gmsh.numberOfAnimation()-1);
this.postDelay(); this.postDelay();
Animation bottomUp = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in); Animation bottomUp = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in);
_controlBarLayout.setVisibility(View.VISIBLE); _controlBarLayout.setVisibility(View.VISIBLE);
......
...@@ -320,4 +320,9 @@ JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationPrev ...@@ -320,4 +320,9 @@ JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationPrev
{ {
return animation_prev(); return animation_prev();
} }
JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_setAnimation
(JNIEnv *, jobject, jint animation)
{
set_animation(animation);
}
} }
...@@ -161,6 +161,14 @@ JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationNext ...@@ -161,6 +161,14 @@ JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationNext
JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationPrev JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationPrev
(JNIEnv *, jobject); (JNIEnv *, jobject);
/*
* Class: org_geuz_onelab_Gmsh
* Method: setAnimation
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_setAnimation
(JNIEnv *, jobject, jint);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -694,6 +694,16 @@ int number_of_animation() { ...@@ -694,6 +694,16 @@ int number_of_animation() {
return ret; return ret;
} }
void set_animation(int step) {
for(unsigned int i = 0; i < PView::list.size(); i++){
PView * p = PView::list[i];
if(p->getOptions()->visible){
p->getOptions()->timeStep = step;
p->setChanged(true);
}
}
}
int animation_next() { int animation_next() {
int ret = 0; int ret = 0;
for(unsigned int i = 0; i < PView::list.size(); i++){ for(unsigned int i = 0; i < PView::list.size(); i++){
......
...@@ -24,6 +24,7 @@ int onelab_cb(std::string); ...@@ -24,6 +24,7 @@ int onelab_cb(std::string);
int animation_next(); int animation_next();
int animation_prev(); int animation_prev();
int number_of_animation(); int number_of_animation();
void set_animation(int step);
class drawContext{ class drawContext{
private: private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment