From 95b4e224919097a210a70d72998ae6a00c792e5a Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Sun, 24 Jun 2018 11:57:59 +0300 Subject: [PATCH] use the same notification also for incoming calls --- .../com/tutpro/baresip/BaresipService.kt | 30 ++--- app/src/main/res/layout/notification.xml | 115 +++++++++++------- 2 files changed, 84 insertions(+), 61 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index cf265d7c..238dac8a 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -158,7 +158,7 @@ class BaresipService: Service() { nb.setVisibility(VISIBILITY_PUBLIC) .setSmallIcon(R.drawable.ic_stat) .setContentIntent(npi) - .setPriority(Notification.PRIORITY_MAX) + .setPriority(Notification.PRIORITY_HIGH) .setOngoing(true) .setContent(RemoteViews(packageName, R.layout.notification)) startForeground(STATUS_NOTIFICATION_ID, nb.build()) @@ -202,7 +202,10 @@ class BaresipService: Service() { return } "registered" -> { - MainActivity.images[account_index] = R.drawable.dot_green + if (ua.account.regint == 0) + MainActivity.images[account_index] = R.drawable.dot_yellow + else + MainActivity.images[account_index] = R.drawable.dot_green updateNotification() if (!MainActivity.visible) return } @@ -217,20 +220,20 @@ class BaresipService: Service() { "call incoming" -> { if (!Utils.isVisible()) { Log.d(LOG_TAG, "Baresip is NOT visible") - val peer_uri = Api.call_peeruri(callp) - val huBuilder = NotificationCompat.Builder(this) - .setSmallIcon(R.drawable.ic_stat) - .setContentText("Incoming call from $peer_uri") - .setDefaults(Notification.DEFAULT_ALL) - .setPriority(Notification.PRIORITY_HIGH) - .setAutoCancel(true) - .setContentIntent(npi) - nm.notify(INCOMING_NOTIFICATION_ID, huBuilder.build()) + nb.setVibrate(LongArray(0)) + val view = RemoteViews(getPackageName(), R.layout.notification) + view.setTextViewText(R.id.incoming, "Call from ${Api.call_peeruri(callp)}") + view.setViewVisibility(R.id.incoming, View.VISIBLE) + nb.setContent(view) + nm.notify(STATUS_NOTIFICATION_ID, nb.build()) } } "call established", "call closed" -> { - nb.mActions.clear() - nb.mContentText = "" + nm.cancel(STATUS_NOTIFICATION_ID) + val view = RemoteViews(getPackageName(), R.layout.notification) + view.setViewVisibility(R.id.incoming, View.GONE) + nb.setContent(view) + nb.setVibrate(null) nm.notify(STATUS_NOTIFICATION_ID, nb.build()) } } @@ -278,7 +281,6 @@ class BaresipService: Service() { var IS_SERVICE_RUNNING = false val STATUS_NOTIFICATION_ID = 101 - val INCOMING_NOTIFICATION_ID = 102 var disconnected = false } diff --git a/app/src/main/res/layout/notification.xml b/app/src/main/res/layout/notification.xml index 4931a337..3ed223ee 100644 --- a/app/src/main/res/layout/notification.xml +++ b/app/src/main/res/layout/notification.xml @@ -1,58 +1,79 @@ - + android:orientation="vertical" > - + android:layout_marginTop="14dp" + android:orientation="horizontal" > - + + + + + + + + + + + + + + + + - - - - - - - - - - - +