Improved implementation of status notification
This commit is contained in:
@ -20,9 +20,9 @@ android {
|
||||
}
|
||||
ndk {
|
||||
// noinspection ChromeOsAbiSupport
|
||||
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
|
||||
// noinspection ChromeOsAbiSupport
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a'
|
||||
// abiFilters 'armeabi-v7a', 'arm64-v8a'
|
||||
}
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
}
|
||||
|
||||
@ -1135,28 +1135,20 @@ class BaresipService: Service() {
|
||||
PendingIntent.FLAG_IMMUTABLE)
|
||||
else
|
||||
PendingIntent.getActivity(applicationContext, STATUS_REQ_CODE, intent, 0)
|
||||
val notificationLayout = RemoteViews(packageName, R.layout.status_notification)
|
||||
snb.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
.setSmallIcon(R.drawable.ic_stat)
|
||||
.setContentIntent(pi)
|
||||
.setOngoing(true)
|
||||
.setContent(RemoteViews(packageName,
|
||||
if (VERSION.SDK_INT >= 33)
|
||||
R.layout.status_notification_33
|
||||
else
|
||||
R.layout.status_notification)
|
||||
)
|
||||
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
|
||||
.setCustomContentView(notificationLayout)
|
||||
if (VERSION.SDK_INT >= 31)
|
||||
snb.foregroundServiceBehavior = Notification.FOREGROUND_SERVICE_DEFAULT
|
||||
startForeground(STATUS_NOTIFICATION_ID, snb.build())
|
||||
}
|
||||
|
||||
private fun updateStatusNotification() {
|
||||
val contentView = RemoteViews(packageName,
|
||||
if (VERSION.SDK_INT >= 33)
|
||||
R.layout.status_notification_33
|
||||
else
|
||||
R.layout.status_notification
|
||||
)
|
||||
val notificationLayout = RemoteViews(packageName, R.layout.status_notification)
|
||||
for (i: Int in 0..3) {
|
||||
val resId = when (i) {
|
||||
0-> R.id.status0
|
||||
@ -1165,17 +1157,17 @@ class BaresipService: Service() {
|
||||
else -> R.id.status3
|
||||
}
|
||||
if (i < uas.size) {
|
||||
contentView.setImageViewResource(resId, uas[i].status)
|
||||
contentView.setViewVisibility(resId, View.VISIBLE)
|
||||
notificationLayout.setImageViewResource(resId, uas[i].status)
|
||||
notificationLayout.setViewVisibility(resId, View.VISIBLE)
|
||||
} else {
|
||||
contentView.setViewVisibility(resId, View.INVISIBLE)
|
||||
notificationLayout.setViewVisibility(resId, View.INVISIBLE)
|
||||
}
|
||||
}
|
||||
if (uas.size > 4)
|
||||
contentView.setViewVisibility(R.id.etc, View.VISIBLE)
|
||||
notificationLayout.setViewVisibility(R.id.etc, View.VISIBLE)
|
||||
else
|
||||
contentView.setViewVisibility(R.id.etc, View.INVISIBLE)
|
||||
snb.setContent(contentView)
|
||||
notificationLayout.setViewVisibility(R.id.etc, View.INVISIBLE)
|
||||
snb.setCustomContentView(notificationLayout)
|
||||
// Don't know why, but without the delay the notification is not always updated
|
||||
Timer().schedule(250) {
|
||||
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||
|
||||
@ -5,30 +5,10 @@
|
||||
android:layout_height="wrap_content"
|
||||
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"
|
||||
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/status1"
|
||||
@ -67,4 +47,3 @@
|
||||
style = "@android:style/TextAppearance.Medium" />
|
||||
|
||||
</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