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

Android: add a SeekBar to show animation progress

parent ba859407
No related branches found
No related tags found
No related merge requests found
contrib/mobile/Android/res/drawable-hdpi/ic_list.png

464 B

contrib/mobile/Android/res/drawable-hdpi/ic_mesh.png

760 B

contrib/mobile/Android/res/drawable-hdpi/ic_settings.png

1.38 KiB

...@@ -2,30 +2,42 @@ ...@@ -2,30 +2,42 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal" android:orientation="vertical"
android:background="@android:color/black" android:background="@android:color/black"
android:alpha=".50" android:alpha=".50"
android:gravity="center" > android:gravity="center" >
<SeekBar
android:id="@+id/controlStepper"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@android:color/black"
android:alpha=".50"
android:gravity="center" >
<ImageButton <ImageButton
android:id="@+id/controlPrev" android:id="@+id/controlPrev"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@android:drawable/ic_media_previous" android:src="@android:drawable/ic_media_previous"
android:contentDescription="previous" /> android:contentDescription="previous" />
<ImageButton <ImageButton
android:id="@+id/controlPlay" android:id="@+id/controlPlay"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@android:drawable/ic_media_play" android:src="@android:drawable/ic_media_play"
android:contentDescription="play" /> android:contentDescription="play" />
<ImageButton <ImageButton
android:id="@+id/controlNext" android:id="@+id/controlNext"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@android:drawable/ic_media_next" android:src="@android:drawable/ic_media_next"
android:contentDescription="next" /> android:contentDescription="next" />
</LinearLayout>
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -31,8 +31,10 @@ public class Gmsh implements Parcelable { ...@@ -31,8 +31,10 @@ public class Gmsh implements Parcelable {
public native void setPView(int position, int intervalsType,int visible,int nbIso, float raisez); // Change options for a PView public native void setPView(int position, int intervalsType,int visible,int nbIso, float raisez); // Change options for a PView
public native int onelabCB(String action); // Call onelab public native int onelabCB(String action); // Call onelab
public native void animationNext(); public boolean haveAnimation() {return numberOfAnimation() > 1;}
public native void animationPrev(); public native int numberOfAnimation();
public native int animationNext();
public native int animationPrev();
/** Java CLASS **/ /** Java CLASS **/
private long ptr; private long ptr;
......
...@@ -120,6 +120,7 @@ public class MainActivity extends Activity{ ...@@ -120,6 +120,7 @@ public class MainActivity extends Activity{
new Run().execute(); new Run().execute();
} }
else if(item.getTitle().equals(getString(R.string.menu_stop))){ else if(item.getTitle().equals(getString(R.string.menu_stop))){
_runStopMenuItem.setEnabled(false);
_gmsh.onelabCB("stop"); _gmsh.onelabCB("stop");
} }
else if(item.getTitle().equals(getString(R.string.menu_share))) { else if(item.getTitle().equals(getString(R.string.menu_share))) {
...@@ -196,6 +197,7 @@ public class MainActivity extends Activity{ ...@@ -196,6 +197,7 @@ public class MainActivity extends Activity{
protected void onPostExecute(Integer[] result) { protected void onPostExecute(Integer[] result) {
//(Vibrator) getSystemService(Context.VIBRATOR_SERVICE).vibrate(350); //(Vibrator) getSystemService(Context.VIBRATOR_SERVICE).vibrate(350);
_runStopMenuItem.setTitle(R.string.menu_run); _runStopMenuItem.setTitle(R.string.menu_run);
_runStopMenuItem.setEnabled(true);
if(_modelFragment != null) _modelFragment.hideProgress(); if(_modelFragment != null) _modelFragment.hideProgress();
_compute = false; _compute = false;
if(_notify) notifyEndComputing(); if(_notify) notifyEndComputing();
...@@ -332,4 +334,6 @@ public class MainActivity extends Activity{ ...@@ -332,4 +334,6 @@ public class MainActivity extends Activity{
} }
}; };
}; };
public boolean isComputing() {return _compute;}
} }
...@@ -24,6 +24,7 @@ import android.widget.ImageButton; ...@@ -24,6 +24,7 @@ import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
public class ModelFragment extends Fragment{ public class ModelFragment extends Fragment{
...@@ -36,9 +37,10 @@ public class ModelFragment extends Fragment{ ...@@ -36,9 +37,10 @@ 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;
final Runnable hideControlsRunnable = new Runnable() {public void run() {hideControlBar();}}; final Runnable hideControlsRunnable = new Runnable() {public void run() {hideControlBar();}};
public static ModelFragment newInstance(Gmsh g) { public static ModelFragment newInstance(Gmsh g) {
ModelFragment fragment = new ModelFragment(); ModelFragment fragment = new ModelFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
...@@ -116,16 +118,19 @@ public class ModelFragment extends Fragment{ ...@@ -116,16 +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);
_controlBarLayout.setEnabled(false);
playPauseButton.setOnClickListener(new View.OnClickListener() { playPauseButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
postDelay(); postDelay();
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());
_animation = new Timer(); _animation = new Timer();
_animation.schedule(new TimerTask() { _animation.schedule(new TimerTask() {
public void run() { public void run() {
_gmsh.animationNext(); _annimationStepper.setProgress(_gmsh.animationNext());
requestRender(); requestRender();
} }, 0, 500); } }, 0, 500);
prevButton.setEnabled(false); prevButton.setEnabled(false);
...@@ -143,14 +148,14 @@ public class ModelFragment extends Fragment{ ...@@ -143,14 +148,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();
_gmsh.animationNext(); _annimationStepper.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();
_gmsh.animationPrev(); _annimationStepper.setProgress(_gmsh.animationPrev());
requestRender(); requestRender();
} }
}); });
...@@ -169,9 +174,10 @@ public class ModelFragment extends Fragment{ ...@@ -169,9 +174,10 @@ public class ModelFragment extends Fragment{
this.postDelay(6000); this.postDelay(6000);
} }
public void showControlBar() { public void showControlBar() {
if(getActivity() == null) return; if(getActivity() == null || ((MainActivity)getActivity()).isComputing() || !_gmsh.haveAnimation()) return;
_controlBarLayout.setEnabled(true);
_annimationStepper.setMax(_gmsh.numberOfAnimation());
this.postDelay(); this.postDelay();
//getActivity().getActionBar().show();
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);
_controlBarLayout.startAnimation(bottomUp); _controlBarLayout.startAnimation(bottomUp);
...@@ -179,10 +185,10 @@ public class ModelFragment extends Fragment{ ...@@ -179,10 +185,10 @@ public class ModelFragment extends Fragment{
public void hideControlBar() { public void hideControlBar() {
if(getActivity() == null) return; if(getActivity() == null) return;
_hideDelay.removeCallbacks(hideControlsRunnable); _hideDelay.removeCallbacks(hideControlsRunnable);
//getActivity().getActionBar().hide();
Animation bottomDown = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out); Animation bottomDown = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out);
_controlBarLayout.startAnimation(bottomDown); _controlBarLayout.startAnimation(bottomDown);
_controlBarLayout.setVisibility(View.INVISIBLE); _controlBarLayout.setVisibility(View.INVISIBLE);
} }
public void showProgress(String progress) { public void showProgress(String progress) {
_progressLayout.setAlpha(1); _progressLayout.setAlpha(1);
......
...@@ -304,14 +304,20 @@ JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_onelabCB ...@@ -304,14 +304,20 @@ JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_onelabCB
const char* action = env->GetStringUTFChars(jaction, NULL); const char* action = env->GetStringUTFChars(jaction, NULL);
return onelab_cb(action); return onelab_cb(action);
} }
JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_animationNext
JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_numberOfAnimation
(JNIEnv *, jobject)
{
return number_of_animation();
}
JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationNext
(JNIEnv *, jobject) (JNIEnv *, jobject)
{ {
animation_next(); return animation_next();
} }
JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_animationPrev JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationPrev
(JNIEnv *, jobject) (JNIEnv *, jobject)
{ {
animation_prev(); return animation_prev();
} }
} }
...@@ -137,20 +137,28 @@ JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_setPView ...@@ -137,20 +137,28 @@ JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_setPView
JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_onelabCB JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_onelabCB
(JNIEnv *, jobject, jstring); (JNIEnv *, jobject, jstring);
/*
* Class: org_geuz_onelab_Gmsh
* Method: numberOfAnimation
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_numberOfAnimation
(JNIEnv *, jobject);
/* /*
* Class: org_geuz_onelab_Gmsh * Class: org_geuz_onelab_Gmsh
* Method: animationNext * Method: animationNext
* Signature: ()V * Signature: ()I
*/ */
JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_animationNext JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationNext
(JNIEnv *, jobject); (JNIEnv *, jobject);
/* /*
* Class: org_geuz_onelab_Gmsh * Class: org_geuz_onelab_Gmsh
* Method: animationPrev * Method: animationPrev
* Signature: ()V * Signature: ()I
*/ */
JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_animationPrev JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_animationPrev
(JNIEnv *, jobject); (JNIEnv *, jobject);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -682,41 +682,50 @@ int onelab_cb(std::string action) ...@@ -682,41 +682,50 @@ int onelab_cb(std::string action)
return redraw; return redraw;
} }
void animation_next() { int number_of_animation() {
int ret = 0;
for(unsigned int i = 0; i < PView::list.size(); i++){
PView * p = PView::list[i];
if(p->getOptions()->visible){
int numSteps = (int)p->getData()->getNumTimeSteps();
if(numSteps > ret) ret = numSteps;
}
}
return ret;
}
int animation_next() {
int ret = 0;
for(unsigned int i = 0; i < PView::list.size(); i++){ for(unsigned int i = 0; i < PView::list.size(); i++){
PView * p = PView::list[i]; PView * p = PView::list[i];
if(p->getOptions()->visible){ if(p->getOptions()->visible){
// skip empty steps
int step = (int)p->getOptions()->timeStep + 1; int step = (int)p->getOptions()->timeStep + 1;
int numSteps = (int)p->getData()->getNumTimeSteps(); int numSteps = (int)p->getData()->getNumTimeSteps();
for(int j = 0; j < numSteps; j++){ if(step < 0) step = numSteps - 1;
if(p->getData()->hasTimeStep(step)) break; if(step > numSteps - 1) step = 0;
else step += 1;
if(step < 0) step = numSteps - 1;
if(step > numSteps - 1) step = 0;
}
p->getOptions()->timeStep = step; p->getOptions()->timeStep = step;
p->setChanged(true); p->setChanged(true);
ret = step;
} }
} }
return ret;
} }
void animation_prev() { int animation_prev() {
int ret = 0;
for(unsigned int i = 0; i < PView::list.size(); i++){ for(unsigned int i = 0; i < PView::list.size(); i++){
PView * p = PView::list[i]; PView * p = PView::list[i];
if(p->getOptions()->visible){ if(p->getOptions()->visible){
// skip empty steps // skip empty steps
int step = (int)p->getOptions()->timeStep - 1; int step = (int)p->getOptions()->timeStep - 1;
int numSteps = (int)p->getData()->getNumTimeSteps(); int numSteps = (int)p->getData()->getNumTimeSteps();
for(int j = 0; j < numSteps; j++){ if(step < 0) step = numSteps - 1;
if(p->getData()->hasTimeStep(step)) break; if(step > numSteps - 1) step = 0;
else step -= 1;
if(step < 0) step = numSteps - 1;
if(step > numSteps - 1) step = 0;
}
p->getOptions()->timeStep = step; p->getOptions()->timeStep = step;
p->setChanged(true); p->setChanged(true);
ret = step;
} }
} }
return ret;
} }
// vim:set ts=2: // vim:set ts=2:
...@@ -21,8 +21,9 @@ ...@@ -21,8 +21,9 @@
void drawArray(VertexArray *va, int type, bool useColorArray=false, bool useNormalArray=false); void drawArray(VertexArray *va, int type, bool useColorArray=false, bool useNormalArray=false);
int onelab_cb(std::string); int onelab_cb(std::string);
void animation_next(); int animation_next();
void animation_prev(); int animation_prev();
int number_of_animation();
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