Added a service based POW engine, so it shouldn't be killed by the system, at least not that easily. (WIP)

This commit is contained in:
2015-10-31 07:49:03 +01:00
parent e98eefe2cc
commit 54a319638b
14 changed files with 266 additions and 85 deletions

View File

@ -14,7 +14,7 @@ public abstract class AbstractNotification {
public AbstractNotification(Context ctx) {
this.ctx = ctx;
this.ctx = ctx.getApplicationContext();
this.manager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
}
@ -23,6 +23,10 @@ public abstract class AbstractNotification {
*/
protected abstract int getNotificationId();
public Notification getNotification() {
return notification;
}
public void show() {
manager.notify(getNotificationId(), notification);
}

View File

@ -1,6 +1,7 @@
package ch.dissem.apps.abit.notification;
import android.content.Context;
import android.support.annotation.StringRes;
import android.support.v7.app.NotificationCompat;
import ch.dissem.apps.abit.R;
@ -20,14 +21,14 @@ public class ErrorNotification extends AbstractNotification {
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
}
public ErrorNotification setWarning(int resId, Object... args) {
public ErrorNotification setWarning(@StringRes int resId, Object... args) {
builder.setSmallIcon(R.drawable.ic_notification_warning)
.setContentText(ctx.getString(resId, args));
notification = builder.build();
return this;
}
public ErrorNotification setError(int resId, Object... args) {
public ErrorNotification setError(@StringRes int resId, Object... args) {
builder.setSmallIcon(R.drawable.ic_notification_error)
.setContentText(ctx.getString(resId, args));
notification = builder.build();

View File

@ -12,7 +12,6 @@ import java.util.TimerTask;
import ch.dissem.apps.abit.MessageListActivity;
import ch.dissem.apps.abit.R;
import ch.dissem.apps.abit.service.Singleton;
import ch.dissem.bitmessage.BitmessageContext;
import ch.dissem.bitmessage.utils.Property;
@ -26,7 +25,7 @@ public class NetworkNotification extends AbstractNotification {
private NotificationCompat.Builder builder;
public NetworkNotification(Context ctx, BitmessageContext bmc) {
super(ctx.getApplicationContext());
super(ctx);
this.bmc = bmc;
builder = new NotificationCompat.Builder(ctx);
builder.setSmallIcon(R.drawable.ic_notification_full_node)
@ -34,6 +33,7 @@ public class NetworkNotification extends AbstractNotification {
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
}
@Override
public Notification getNotification() {
update();
return notification;

View File

@ -0,0 +1,38 @@
package ch.dissem.apps.abit.notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.NotificationCompat;
import ch.dissem.apps.abit.MessageListActivity;
import ch.dissem.apps.abit.R;
/**
* Ongoing notification while proof of work is in progress.
*/
public class ProofOfWorkNotification extends AbstractNotification {
public static final int ONGOING_NOTIFICATION_ID = 3;
public ProofOfWorkNotification(Context ctx) {
super(ctx);
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
Intent showMessageIntent = new Intent(ctx, MessageListActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, showMessageIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setUsesChronometer(true)
.setSmallIcon(R.drawable.ic_notification_proof_of_work)
.setContentTitle(ctx.getString(R.string.proof_of_work_title))
.setContentText(ctx.getString(R.string.proof_of_work_text))
.setContentIntent(pendingIntent);
notification = builder.build();
}
@Override
protected int getNotificationId() {
return ONGOING_NOTIFICATION_ID;
}
}