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

Android: best notification + fix scale

parent c8b32ef1
No related branches found
No related tags found
No related merge requests found
......@@ -198,7 +198,7 @@ public class MainActivity extends Activity{
_runStopMenuItem.setTitle(R.string.menu_run);
if(_modelFragment != null) _modelFragment.hideProgress();
_compute = false;
if(_notify) notifyEndOfCompute();
if(_notify) notifyEndComputing();
super.onPostExecute(result);
}
......@@ -261,48 +261,39 @@ public class MainActivity extends Activity{
if(!_compute) return;
if(level == Activity.TRIM_MEMORY_COMPLETE){
_gmsh.onelabCB("stop");
notifyInterruptComputing();
notifyEndComputing("The computing had to stop because your device ran out of memory");
_notify = false;
}
else if(level == Activity.TRIM_MEMORY_COMPLETE) {
// TODO
notifyComputing("Computing in progress - low memory", true);
}
super.onTrimMemory(level);
}
private void notifyComputing() {
private void notifyComputing(String msg, boolean alert) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Builder notifyBuilder = new Notification.Builder(this);
notifyBuilder.setContentTitle("ONELAB")
.setContentIntent(pendingIntent)
.setContentText("Computing in progress")
.setContentText(msg)
.setSmallIcon(R.drawable.ic_launcher)
.setProgress(0, 0, true);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if(alert) notifyBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1337, notifyBuilder.getNotification());
}
private void notifyEndOfCompute() {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Builder notifyBuilder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pendingIntent)
.setContentTitle("ONELAB")
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setProgress(0, 0, false)
.setContentText("The computing is finished");
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1337, notifyBuilder.getNotification());
private void notifyComputing() {
notifyComputing("Computing in progress", false);
}
private void notifyEndComputing() {
notifyEndComputing("The computing is finished");
}
private void notifyInterruptComputing() {
private void notifyEndComputing(String msg) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
......@@ -313,9 +304,8 @@ public class MainActivity extends Activity{
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setProgress(0, 0, false)
.setContentText("The computing had to stop because your device ran out of memory");
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
.setContentText(msg);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1337, notifyBuilder.getNotification());
}
......
......@@ -33,7 +33,7 @@ public class ModelFragment extends Fragment{
private TextView _progress;
private LinearLayout _progressLayout;
private LinearLayout _controlBarLayout;
private GestureDetector _gestureListener;
private GestureDetector _gestureDetector;
private Timer _animation;
private Handler _hideDelay;
......@@ -69,46 +69,29 @@ public class ModelFragment extends Fragment{
_glView.requestRender();
_hideDelay = new Handler();
this.postDelay();
_gestureListener = new GestureDetector(getActivity(), new OnGestureListener() {
public boolean onSingleTapUp(MotionEvent e) {
_gestureDetector = new GestureDetector(getActivity(), new OnGestureListener() {
public boolean onSingleTapUp(MotionEvent e) { return false; } // UNUSED Auto-generated method stub
public void onShowPress(MotionEvent e) {} // UNUSED Auto-generated method stub
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } // UNUSED Auto-generated method stub
public void onLongPress(MotionEvent e) {} // UNUSED Auto-generated method stub
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } // UNUSED Auto-generated method stub
public boolean onDown(MotionEvent e) { return false; } // UNUSED Auto-generated method stub
});
_gestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
public boolean onSingleTapConfirmed(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;
}
public boolean onDoubleTapEvent(MotionEvent e) { return false; } // UNUSED Auto-generated method stub
public boolean onDoubleTap(MotionEvent e) { return false; } // UNUSED Auto-generated method stub
});
_glView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return _gestureListener.onTouchEvent(event);
return _gestureDetector.onTouchEvent(event);
}
});
glViewLayout.addView(_glView);
......@@ -130,7 +113,9 @@ public class ModelFragment extends Fragment{
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
glViewLayout.addView(_progressLayout, layoutParams);
_controlBarLayout = (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.control_bar, null);
ImageButton playPauseButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlPlay);
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);
playPauseButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
postDelay();
......@@ -143,15 +128,18 @@ public class ModelFragment extends Fragment{
_gmsh.animationNext();
requestRender();
} }, 0, 500);
prevButton.setEnabled(false);
nextButton.setEnabled(false);
}
else {
((ImageButton)v).setContentDescription("play");
((ImageButton)v).setImageResource(android.R.drawable.ic_media_play);
_animation.cancel();
prevButton.setEnabled(true);
nextButton.setEnabled(true);
}
}
});
ImageButton nextButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlNext);
nextButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
postDelay();
......@@ -159,7 +147,6 @@ public class ModelFragment extends Fragment{
requestRender();
}
});
ImageButton prevButton = (ImageButton)_controlBarLayout.findViewById(R.id.controlPrev);
prevButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
postDelay();
......
......@@ -462,6 +462,7 @@ void drawContext::drawScale()
glDisableClientState(GL_VERTEX_ARRAY);
free(vertex);
free(color);
char label[1024];
drawString *lbl = new drawString(p->getData()->getName().c_str(), 20);
lbl->draw(xmin+width/2, ymin-height/2, 0., _width/(_right-_left), _height/(_top-_bottom));
......@@ -472,6 +473,7 @@ void drawContext::drawScale()
val->setText(label);
val->draw(xmin+i*width/2, ymin+height/2, 0., _width/(_right-_left), _height/(_top-_bottom));
}
nPview++;
}
glPopMatrix();
......@@ -575,6 +577,8 @@ void drawContext::drawView()
this->_bottom + (this->_top - this->_bottom)/15.0,
0, (this->_top - this->_bottom)/20.);
checkGlError("Draw axes");
this->drawScale();
checkGlError("Draw scales");
glEnable(GL_DEPTH_TEST);
this->drawMesh();
checkGlError("Draw mesh");
......@@ -582,8 +586,6 @@ void drawContext::drawView()
checkGlError("Draw geometry");
this->drawPost();
checkGlError("Draw post-pro");
this->drawScale();
checkGlError("Draw scales");
glDisable(GL_DEPTH_TEST);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment