implement per-call notifications

messaging
Georg Lukas 2011-07-02 17:30:43 +02:00
rodzic 19084d577e
commit f41199b619
2 zmienionych plików z 28 dodań i 5 usunięć

Wyświetl plik

@ -46,6 +46,11 @@ class MessageActivity extends LoadingListActivity
}
}
override def onResume() {
super.onResume()
ServiceNotifier.instance.cancelMessage(this, targetcall)
}
override def onDestroy() {
super.onDestroy()
pla.onDestroy()

Wyświetl plik

@ -2,6 +2,7 @@ package org.aprsdroid.app
import _root_.android.app.{Notification, NotificationManager, PendingIntent, Service}
import _root_.android.content.{Context, Intent}
import _root_.android.net.Uri
import _root_.android.os.Build
@ -11,6 +12,8 @@ object ServiceNotifier {
abstract class ServiceNotifier {
val SERVICE_NOTIFICATION : Int = 1
var CALL_NOTIFICATION = SERVICE_NOTIFICATION + 1
val callIdMap = new scala.collection.mutable.HashMap[String, Int]()
def newNotification(ctx : Service, status : String) : Notification = {
val n = new Notification()
@ -25,28 +28,43 @@ abstract class ServiceNotifier {
n
}
def getCallNumber(call : String) : Int = {
if (callIdMap.contains(call)) {
callIdMap(call)
} else {
val id = CALL_NOTIFICATION
CALL_NOTIFICATION += 1
callIdMap(call) = id
id
}
}
def newMessageNotification(ctx : Service, call : String, message : String) : Notification = {
val n = new Notification()
n.icon = R.drawable.ic_status
n.icon = R.drawable.icon
n.when = System.currentTimeMillis
n.flags |= Notification.FLAG_AUTO_CANCEL
val i = new Intent(ctx, classOf[MessageActivity])
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
i.putExtra("call", call)
n.contentIntent = PendingIntent.getActivity(ctx, 0, i, 0)
i.setData(Uri.parse(call))
n.contentIntent = PendingIntent.getActivity(ctx, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)
n.setLatestEventInfo(ctx, call, message, n.contentIntent)
n
}
def getNotificationMgr(ctx : Service) = ctx.getSystemService(Context.NOTIFICATION_SERVICE).asInstanceOf[NotificationManager]
def getNotificationMgr(ctx : Context) = ctx.getSystemService(Context.NOTIFICATION_SERVICE).asInstanceOf[NotificationManager]
def start(ctx : Service, status : String)
def stop(ctx : Service)
def notifyMessage(ctx : Service, call : String, message : String) {
getNotificationMgr(ctx).notify(SERVICE_NOTIFICATION + 1,
getNotificationMgr(ctx).notify(getCallNumber(call),
newMessageNotification(ctx, call, message))
}
def cancelMessage(ctx : Context, call : String) {
getNotificationMgr(ctx).cancel(getCallNumber(call))
}
}
class DonutNotifier extends ServiceNotifier {