kopia lustrzana https://github.com/ge0rg/aprsdroid
implement per-call notifications
rodzic
19084d577e
commit
f41199b619
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
Ładowanie…
Reference in New Issue