From 31f0937d7201c6c79e1db504f7a01436c243fe47 Mon Sep 17 00:00:00 2001 From: Maxime Graulich <maxime.graulich@gmail.com> Date: Wed, 18 Sep 2013 09:40:52 +0000 Subject: [PATCH] Android: SeekBar can now control the animation --- .../Android/src/org/geuz/onelab/Gmsh.java | 3 ++- .../src/org/geuz/onelab/ModelFragment.java | 26 ++++++++++++++----- contrib/mobile/androidGModel.cpp | 5 ++++ contrib/mobile/androidGModel.h | 8 ++++++ contrib/mobile/drawContext.cpp | 10 +++++++ contrib/mobile/drawContext.h | 1 + 6 files changed, 45 insertions(+), 8 deletions(-) diff --git a/contrib/mobile/Android/src/org/geuz/onelab/Gmsh.java b/contrib/mobile/Android/src/org/geuz/onelab/Gmsh.java index 4ba89b2a58..1499df3fb7 100644 --- a/contrib/mobile/Android/src/org/geuz/onelab/Gmsh.java +++ b/contrib/mobile/Android/src/org/geuz/onelab/Gmsh.java @@ -35,7 +35,8 @@ public class Gmsh implements Parcelable { public native int numberOfAnimation(); public native int animationNext(); public native int animationPrev(); - + public native void setAnimation(int animation); + /** Java CLASS **/ private long ptr; private Handler handler; diff --git a/contrib/mobile/Android/src/org/geuz/onelab/ModelFragment.java b/contrib/mobile/Android/src/org/geuz/onelab/ModelFragment.java index b24245bb21..c41922d46d 100644 --- a/contrib/mobile/Android/src/org/geuz/onelab/ModelFragment.java +++ b/contrib/mobile/Android/src/org/geuz/onelab/ModelFragment.java @@ -37,7 +37,7 @@ public class ModelFragment extends Fragment{ private GestureDetector _gestureDetector; private Timer _animation; private Handler _hideDelay; - private SeekBar _annimationStepper; + private SeekBar _animationStepper; final Runnable hideControlsRunnable = new Runnable() {public void run() {hideControlBar();}}; @@ -118,7 +118,19 @@ public class ModelFragment extends Fragment{ final ImageButton prevButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlPrev); final ImageButton playPauseButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlPlay); 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); playPauseButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { @@ -126,11 +138,11 @@ public class ModelFragment extends Fragment{ if(((ImageButton)v).getContentDescription().equals("play")) { ((ImageButton)v).setContentDescription("pause"); ((ImageButton)v).setImageResource(android.R.drawable.ic_media_pause); - _annimationStepper.setMax(_gmsh.numberOfAnimation()); + _animationStepper.setMax(_gmsh.numberOfAnimation()); _animation = new Timer(); _animation.schedule(new TimerTask() { public void run() { - _annimationStepper.setProgress(_gmsh.animationNext()); + _animationStepper.setProgress(_gmsh.animationNext()); requestRender(); } }, 0, 500); prevButton.setEnabled(false); @@ -148,14 +160,14 @@ public class ModelFragment extends Fragment{ nextButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { postDelay(); - _annimationStepper.setProgress(_gmsh.animationNext()); + _animationStepper.setProgress(_gmsh.animationNext()); requestRender(); } }); prevButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { postDelay(); - _annimationStepper.setProgress(_gmsh.animationPrev()); + _animationStepper.setProgress(_gmsh.animationPrev()); requestRender(); } }); @@ -176,7 +188,7 @@ public class ModelFragment extends Fragment{ public void showControlBar() { if(getActivity() == null || ((MainActivity)getActivity()).isComputing() || !_gmsh.haveAnimation()) return; _controlBarLayout.setEnabled(true); - _annimationStepper.setMax(_gmsh.numberOfAnimation()); + _animationStepper.setMax(_gmsh.numberOfAnimation()-1); this.postDelay(); Animation bottomUp = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in); _controlBarLayout.setVisibility(View.VISIBLE); diff --git a/contrib/mobile/androidGModel.cpp b/contrib/mobile/androidGModel.cpp index 92ffcf899b..3382d599b8 100644 --- a/contrib/mobile/androidGModel.cpp +++ b/contrib/mobile/androidGModel.cpp @@ -320,4 +320,9 @@ JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationPrev { return animation_prev(); } +JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_setAnimation + (JNIEnv *, jobject, jint animation) +{ + set_animation(animation); +} } diff --git a/contrib/mobile/androidGModel.h b/contrib/mobile/androidGModel.h index 991a211071..4fc0462cfd 100644 --- a/contrib/mobile/androidGModel.h +++ b/contrib/mobile/androidGModel.h @@ -161,6 +161,14 @@ JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationNext JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationPrev (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 } #endif diff --git a/contrib/mobile/drawContext.cpp b/contrib/mobile/drawContext.cpp index 3a158c326e..0399b43219 100644 --- a/contrib/mobile/drawContext.cpp +++ b/contrib/mobile/drawContext.cpp @@ -694,6 +694,16 @@ int number_of_animation() { 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 ret = 0; for(unsigned int i = 0; i < PView::list.size(); i++){ diff --git a/contrib/mobile/drawContext.h b/contrib/mobile/drawContext.h index a42a687577..e800ae3501 100644 --- a/contrib/mobile/drawContext.h +++ b/contrib/mobile/drawContext.h @@ -24,6 +24,7 @@ int onelab_cb(std::string); int animation_next(); int animation_prev(); int number_of_animation(); +void set_animation(int step); class drawContext{ private: -- GitLab