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

Android: Add control bar at the bottom + show/hide control bars

parent d4f1cc25
Branches
Tags
No related merge requests found
<?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="horizontal"
android:background="@android:color/black"
android:alpha=".50"
android:gravity="center" >
<ImageButton
android:id="@+id/controlPrev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_media_previous"
android:contentDescription="previous" />
<ImageButton
android:id="@+id/controlPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_media_play"
android:contentDescription="play" />
<ImageButton
android:id="@+id/controlNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_media_next"
android:contentDescription="next" />
</LinearLayout>
\ No newline at end of file
...@@ -13,7 +13,6 @@ public class Gmsh implements Parcelable { ...@@ -13,7 +13,6 @@ public class Gmsh implements Parcelable {
System.loadLibrary("Gmsh"); System.loadLibrary("Gmsh");
System.loadLibrary("GetDP"); System.loadLibrary("GetDP");
System.loadLibrary("Onelab"); System.loadLibrary("Onelab");
} }
private native long init(String name); // Init Gmsh private native long init(String name); // Init Gmsh
private native void loadFile(long ptr, String name); // load a file(OpenProjet) private native void loadFile(long ptr, String name); // load a file(OpenProjet)
...@@ -33,6 +32,7 @@ public class Gmsh implements Parcelable { ...@@ -33,6 +32,7 @@ public class Gmsh implements Parcelable {
public native int onelabCB(String action); // Call onelab public native int onelabCB(String action); // Call onelab
public native void animationNext(); public native void animationNext();
public native void animationPrev();
/** Java CLASS **/ /** Java CLASS **/
private long ptr; private long ptr;
......
...@@ -4,8 +4,6 @@ import java.io.File; ...@@ -4,8 +4,6 @@ import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.Activity; import android.app.Activity;
...@@ -40,7 +38,6 @@ public class MainActivity extends Activity{ ...@@ -40,7 +38,6 @@ public class MainActivity extends Activity{
private OptionsFragment _optionsFragment; private OptionsFragment _optionsFragment;
private ArrayList<String> _errors = new ArrayList<String>(); private ArrayList<String> _errors = new ArrayList<String>();
private Dialog _errorDialog; private Dialog _errorDialog;
private Timer _animation;
public MainActivity() { public MainActivity() {
} }
...@@ -87,6 +84,7 @@ public class MainActivity extends Activity{ ...@@ -87,6 +84,7 @@ public class MainActivity extends Activity{
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
outState.putBoolean("Compute", _compute);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
...@@ -101,11 +99,14 @@ public class MainActivity extends Activity{ ...@@ -101,11 +99,14 @@ public class MainActivity extends Activity{
_runStopMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); _runStopMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
MenuItem shareMenuItem = menu.add(R.string.menu_share); MenuItem shareMenuItem = menu.add(R.string.menu_share);
shareMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); shareMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
MenuItem playPauseMenuItem = menu.add("Play animation");
playPauseMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
return true; return true;
} }
@Override @Override
public boolean onMenuOpened(int featureId, Menu menu) {
_modelFragment.postDelay();
return super.onMenuOpened(featureId, menu);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) { public boolean onMenuItemSelected(int featureId, MenuItem item) {
if (item.getTitle().equals(getString(R.string.menu_parameters))) { if (item.getTitle().equals(getString(R.string.menu_parameters))) {
Intent intent = new Intent(this, OptionsActivity.class); Intent intent = new Intent(this, OptionsActivity.class);
...@@ -115,6 +116,7 @@ public class MainActivity extends Activity{ ...@@ -115,6 +116,7 @@ public class MainActivity extends Activity{
_modelFragment.requestRender(); _modelFragment.requestRender();
} }
else if(item.getTitle().equals(getString(R.string.menu_run))){ else if(item.getTitle().equals(getString(R.string.menu_run))){
if(_modelFragment != null) _modelFragment.hideControlBar();
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))){
...@@ -144,33 +146,6 @@ public class MainActivity extends Activity{ ...@@ -144,33 +146,6 @@ public class MainActivity extends Activity{
shareIntent.setType("image/jpeg"); shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getString(R.string.title_share))); startActivity(Intent.createChooser(shareIntent, getString(R.string.title_share)));
} }
}
else if(item.getTitle().equals("Play animation")) {
if(this._compute) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
_errorDialog = dialogBuilder.setTitle("Can't start animation")
.setMessage("The computing have to be finished before you can play animation.")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
}
else {
item.setTitle("Stop animation");
_animation = new Timer();
_animation.schedule(new TimerTask() {
public void run() {
_gmsh.animationNext();
_modelFragment.requestRender();
} }, 2000, 1);
}
}
else if(item.getTitle().equals("Stop animation")) {
item.setTitle("Play animation");
_animation.cancel();
} }
else if(item.getItemId() == android.R.id.home) { else if(item.getItemId() == android.R.id.home) {
if(this._compute) { if(this._compute) {
...@@ -275,6 +250,7 @@ public class MainActivity extends Activity{ ...@@ -275,6 +250,7 @@ public class MainActivity extends Activity{
@Override @Override
public void onLowMemory() { public void onLowMemory() {
if(!_compute) return;
_gmsh.onelabCB("stop"); _gmsh.onelabCB("stop");
Toast.makeText(this, "Low memory !!! computing is going to stop", Toast.LENGTH_LONG).show(); Toast.makeText(this, "Low memory !!! computing is going to stop", Toast.LENGTH_LONG).show();
super.onLowMemory(); super.onLowMemory();
...@@ -282,9 +258,14 @@ public class MainActivity extends Activity{ ...@@ -282,9 +258,14 @@ public class MainActivity extends Activity{
@Override @Override
public void onTrimMemory(int level) { public void onTrimMemory(int level) {
if(!_compute) return;
if(level == Activity.TRIM_MEMORY_COMPLETE){ if(level == Activity.TRIM_MEMORY_COMPLETE){
_gmsh.onelabCB("stop"); _gmsh.onelabCB("stop");
notifyInterruptComputing(); notifyInterruptComputing();
_notify = false;
}
else if(level == Activity.TRIM_MEMORY_COMPLETE) {
// TODO
} }
super.onTrimMemory(level); super.onTrimMemory(level);
} }
......
...@@ -3,15 +3,24 @@ package org.geuz.onelab; ...@@ -3,15 +3,24 @@ package org.geuz.onelab;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Fragment; import android.app.Fragment;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
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;
...@@ -19,10 +28,16 @@ import android.widget.TextView; ...@@ -19,10 +28,16 @@ import android.widget.TextView;
public class ModelFragment extends Fragment{ public class ModelFragment extends Fragment{
Gmsh _gmsh; private Gmsh _gmsh;
mGLSurfaceView _glView; private mGLSurfaceView _glView;
TextView _progress; private TextView _progress;
LinearLayout _progressLayout; private LinearLayout _progressLayout;
private LinearLayout _controlBarLayout;
private GestureDetector _gestureListener;
private Timer _animation;
private Handler _hideDelay;
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();
...@@ -52,6 +67,50 @@ public class ModelFragment extends Fragment{ ...@@ -52,6 +67,50 @@ public class ModelFragment extends Fragment{
_glView.setRenderer(renderer); _glView.setRenderer(renderer);
_glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); _glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
_glView.requestRender(); _glView.requestRender();
_hideDelay = new Handler();
this.postDelay();
_gestureListener = new GestureDetector(getActivity(), new OnGestureListener() {
public boolean onSingleTapUp(MotionEvent e) {
if(View.VISIBLE == _controlBarLayout.getVisibility())
hideControlBar();
else
showControlBar();
return true;
}
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
return false;
}
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
});
_glView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return _gestureListener.onTouchEvent(event);
}
});
glViewLayout.addView(_glView); glViewLayout.addView(_glView);
_progressLayout = new LinearLayout(container.getContext()); _progressLayout = new LinearLayout(container.getContext());
ProgressBar bar = new ProgressBar(container.getContext()); ProgressBar bar = new ProgressBar(container.getContext());
...@@ -70,8 +129,74 @@ public class ModelFragment extends Fragment{ ...@@ -70,8 +129,74 @@ public class ModelFragment extends Fragment{
RelativeLayout.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
glViewLayout.addView(_progressLayout, layoutParams); glViewLayout.addView(_progressLayout, layoutParams);
_controlBarLayout = (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.control_bar, null);
ImageButton playPauseButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlPlay);
playPauseButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
postDelay();
if(((ImageButton)v).getContentDescription().equals("play")) {
((ImageButton)v).setContentDescription("pause");
((ImageButton)v).setImageResource(android.R.drawable.ic_media_pause);
_animation = new Timer();
_animation.schedule(new TimerTask() {
public void run() {
_gmsh.animationNext();
requestRender();
} }, 0, 500);
}
else {
((ImageButton)v).setContentDescription("play");
((ImageButton)v).setImageResource(android.R.drawable.ic_media_play);
_animation.cancel();
}
}
});
ImageButton nextButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlNext);
nextButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
postDelay();
_gmsh.animationNext();
requestRender();
}
});
ImageButton prevButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlPrev);
prevButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
postDelay();
_gmsh.animationPrev();
requestRender();
}
});
layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
glViewLayout.addView(_controlBarLayout, layoutParams);
return rootView; return rootView;
} }
public void postDelay(int delay) {
_hideDelay.removeCallbacks(hideControlsRunnable);
_hideDelay.postDelayed(hideControlsRunnable, delay);
}
public void postDelay() {
this.postDelay(6000);
}
public void showControlBar() {
if(getActivity() == null) return;
this.postDelay();
getActivity().getActionBar().show();
Animation bottomUp = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in);
_controlBarLayout.setVisibility(View.VISIBLE);
_controlBarLayout.startAnimation(bottomUp);
}
public void hideControlBar() {
if(getActivity() == null) return;
_hideDelay.removeCallbacks(hideControlsRunnable);
getActivity().getActionBar().hide();
Animation bottomDown = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out);
_controlBarLayout.startAnimation(bottomDown);
_controlBarLayout.setVisibility(View.INVISIBLE);
}
public void showProgress(String progress) { public void showProgress(String progress) {
_progressLayout.setAlpha(1); _progressLayout.setAlpha(1);
_progress.setText(progress); _progress.setText(progress);
......
...@@ -309,4 +309,9 @@ JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_animationNext ...@@ -309,4 +309,9 @@ JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_animationNext
{ {
animation_next(); animation_next();
} }
JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_animationPrev
(JNIEnv *, jobject)
{
animation_prev();
}
} }
...@@ -145,6 +145,14 @@ JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_onelabCB ...@@ -145,6 +145,14 @@ JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_onelabCB
JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_animationNext JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_animationNext
(JNIEnv *, jobject); (JNIEnv *, jobject);
/*
* Class: org_geuz_onelab_Gmsh
* Method: animationPrev
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_geuz_onelab_Gmsh_animationPrev
(JNIEnv *, jobject);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -693,7 +693,24 @@ void animation_next() { ...@@ -693,7 +693,24 @@ void animation_next() {
if(step < 0) step = numSteps - 1; if(step < 0) step = numSteps - 1;
if(step > numSteps - 1) step = 0; if(step > numSteps - 1) step = 0;
} }
Msg::Info("animation: step%d nextstep%d totalstep%d", p->getOptions()->timeStep, step, p->getData()->getNumTimeSteps()); p->getOptions()->timeStep = step;
p->setChanged(true);
}
}
}
void animation_prev() {
for(unsigned int i = 0; i < PView::list.size(); i++){
PView * p = PView::list[i];
if(p->getOptions()->visible){
// skip empty steps
int step = (int)p->getOptions()->timeStep - 1;
int numSteps = (int)p->getData()->getNumTimeSteps();
for(int j = 0; j < numSteps; j++){
if(p->getData()->hasTimeStep(step)) break;
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);
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
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(); void animation_next();
void animation_prev();
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