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

Android: Notify progress

parent 5bd44bd6
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import android.app.Activity; ...@@ -10,6 +10,7 @@ import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.Notification; import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
...@@ -221,6 +222,7 @@ public class MainActivity extends Activity{ ...@@ -221,6 +222,7 @@ public class MainActivity extends Activity{
} }
@Override @Override
protected void onPause() { protected void onPause() {
if(_compute) notifyComputing();
super.onPause(); super.onPause();
_notify = true; _notify = true;
} }
...@@ -237,24 +239,41 @@ public class MainActivity extends Activity{ ...@@ -237,24 +239,41 @@ public class MainActivity extends Activity{
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
if(_compute) notifyComputing();
_notify = true; _notify = true;
} }
private void notifyComputing() {
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")
.setSmallIcon(R.drawable.ic_launcher)
.setProgress(0, 0, true);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1337, notifyBuilder.getNotification());
}
private void notifyEndOfCompute() { private void notifyEndOfCompute() {
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Builder mBuilder = Notification.Builder notifyBuilder =
new Notification.Builder(this) new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher) .setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setContentTitle("ONELAB") .setContentTitle("ONELAB")
.setDefaults(Notification.DEFAULT_ALL) .setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true) .setAutoCancel(true)
.setContentText("The compute is finished"); .setProgress(0, 0, false)
.setContentText("The computing is finished");
NotificationManager mNotificationManager = NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1337, mBuilder.getNotification()); mNotificationManager.notify(1337, notifyBuilder.getNotification());
} }
private final Handler mainHandler = new Handler(){ private final Handler mainHandler = new Handler(){
......
...@@ -121,6 +121,7 @@ public class ModelList extends Activity { ...@@ -121,6 +121,7 @@ public class ModelList extends Activity {
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_CANCELED) return;
switch (requestCode) { switch (requestCode) {
case 1: case 1:
Uri uri = data.getData(); Uri uri = data.getData();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment