Improved implementation of status notification
This commit is contained in:
+2
-2
@@ -20,9 +20,9 @@ android {
|
|||||||
}
|
}
|
||||||
ndk {
|
ndk {
|
||||||
// noinspection ChromeOsAbiSupport
|
// noinspection ChromeOsAbiSupport
|
||||||
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
|
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
|
||||||
// noinspection ChromeOsAbiSupport
|
// noinspection ChromeOsAbiSupport
|
||||||
abiFilters 'armeabi-v7a', 'arm64-v8a'
|
// abiFilters 'armeabi-v7a', 'arm64-v8a'
|
||||||
}
|
}
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1135,28 +1135,20 @@ class BaresipService: Service() {
|
|||||||
PendingIntent.FLAG_IMMUTABLE)
|
PendingIntent.FLAG_IMMUTABLE)
|
||||||
else
|
else
|
||||||
PendingIntent.getActivity(applicationContext, STATUS_REQ_CODE, intent, 0)
|
PendingIntent.getActivity(applicationContext, STATUS_REQ_CODE, intent, 0)
|
||||||
|
val notificationLayout = RemoteViews(packageName, R.layout.status_notification)
|
||||||
snb.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
snb.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
.setSmallIcon(R.drawable.ic_stat)
|
.setSmallIcon(R.drawable.ic_stat)
|
||||||
.setContentIntent(pi)
|
.setContentIntent(pi)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setContent(RemoteViews(packageName,
|
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
|
||||||
if (VERSION.SDK_INT >= 33)
|
.setCustomContentView(notificationLayout)
|
||||||
R.layout.status_notification_33
|
|
||||||
else
|
|
||||||
R.layout.status_notification)
|
|
||||||
)
|
|
||||||
if (VERSION.SDK_INT >= 31)
|
if (VERSION.SDK_INT >= 31)
|
||||||
snb.foregroundServiceBehavior = Notification.FOREGROUND_SERVICE_DEFAULT
|
snb.foregroundServiceBehavior = Notification.FOREGROUND_SERVICE_DEFAULT
|
||||||
startForeground(STATUS_NOTIFICATION_ID, snb.build())
|
startForeground(STATUS_NOTIFICATION_ID, snb.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateStatusNotification() {
|
private fun updateStatusNotification() {
|
||||||
val contentView = RemoteViews(packageName,
|
val notificationLayout = RemoteViews(packageName, R.layout.status_notification)
|
||||||
if (VERSION.SDK_INT >= 33)
|
|
||||||
R.layout.status_notification_33
|
|
||||||
else
|
|
||||||
R.layout.status_notification
|
|
||||||
)
|
|
||||||
for (i: Int in 0..3) {
|
for (i: Int in 0..3) {
|
||||||
val resId = when (i) {
|
val resId = when (i) {
|
||||||
0-> R.id.status0
|
0-> R.id.status0
|
||||||
@@ -1165,17 +1157,17 @@ class BaresipService: Service() {
|
|||||||
else -> R.id.status3
|
else -> R.id.status3
|
||||||
}
|
}
|
||||||
if (i < uas.size) {
|
if (i < uas.size) {
|
||||||
contentView.setImageViewResource(resId, uas[i].status)
|
notificationLayout.setImageViewResource(resId, uas[i].status)
|
||||||
contentView.setViewVisibility(resId, View.VISIBLE)
|
notificationLayout.setViewVisibility(resId, View.VISIBLE)
|
||||||
} else {
|
} else {
|
||||||
contentView.setViewVisibility(resId, View.INVISIBLE)
|
notificationLayout.setViewVisibility(resId, View.INVISIBLE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uas.size > 4)
|
if (uas.size > 4)
|
||||||
contentView.setViewVisibility(R.id.etc, View.VISIBLE)
|
notificationLayout.setViewVisibility(R.id.etc, View.VISIBLE)
|
||||||
else
|
else
|
||||||
contentView.setViewVisibility(R.id.etc, View.INVISIBLE)
|
notificationLayout.setViewVisibility(R.id.etc, View.INVISIBLE)
|
||||||
snb.setContent(contentView)
|
snb.setCustomContentView(notificationLayout)
|
||||||
// Don't know why, but without the delay the notification is not always updated
|
// Don't know why, but without the delay the notification is not always updated
|
||||||
Timer().schedule(250) {
|
Timer().schedule(250) {
|
||||||
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||||
|
|||||||
@@ -5,30 +5,10 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal" >
|
android:orientation="horizontal" >
|
||||||
|
|
||||||
<ImageView android:id="@+id/image"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:paddingStart="10dp"
|
|
||||||
android:paddingEnd="5dp"
|
|
||||||
android:src="@drawable/baresip"
|
|
||||||
android:contentDescription="@string/app_name" />
|
|
||||||
|
|
||||||
<TextView android:id="@+id/text"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:textSize="15sp"
|
|
||||||
android:textColor="@color/colorBaresip"
|
|
||||||
android:text="@string/app_name"
|
|
||||||
style = "@android:style/TextAppearance.DeviceDefault.Small" />
|
|
||||||
|
|
||||||
<ImageView android:id="@+id/status0"
|
<ImageView android:id="@+id/status0"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:paddingStart="10dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:contentDescription="@string/status" />
|
android:contentDescription="@string/status" />
|
||||||
|
|
||||||
<ImageView android:id="@+id/status1"
|
<ImageView android:id="@+id/status1"
|
||||||
@@ -67,4 +47,3 @@
|
|||||||
style = "@android:style/TextAppearance.Medium" />
|
style = "@android:style/TextAppearance.Medium" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/mainRow"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal" >
|
|
||||||
|
|
||||||
<ImageView android:id="@+id/status0"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:contentDescription="@string/status" />
|
|
||||||
|
|
||||||
<ImageView android:id="@+id/status1"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:paddingStart="10dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:contentDescription="@string/status" />
|
|
||||||
|
|
||||||
<ImageView android:id="@+id/status2"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:paddingStart="10dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:contentDescription="@string/status" />
|
|
||||||
|
|
||||||
<ImageView android:id="@+id/status3"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:paddingStart="10dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:contentDescription="@string/status" />
|
|
||||||
|
|
||||||
<TextView android:id="@+id/etc"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginBottom="14dp"
|
|
||||||
android:paddingStart="5dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:text="@string/dots"
|
|
||||||
android:textColor="#000000"
|
|
||||||
style = "@android:style/TextAppearance.Medium" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
Reference in New Issue
Block a user