Commit dcc44efe authored by Christophe Deschamps's avatar Christophe Deschamps
Browse files

Added device type in notification


Former-commit-id: 239aaef7b357fb17db9f863bcbf565c0a4bf9ce7
parent 54f09d91
......@@ -44,7 +44,7 @@ class LindoorApplication : Application() {
coreContext = CoreContext(context, config)
coreContext.start()
// Things to do once
// work around https://bugs.linphone.org/view.php?id=7714 - for demo purpose
if (corePreferences.config.getBool("app","first_launch", true)) {
corePreferences.config.setBool("app","first_launch", false)
coreContext.core.videoPayloadTypes.forEach {
......
package org.lindoor.entities
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.FileUtils
import android.os.Parcelable
import com.caverock.androidsvg.SVG
import kotlinx.android.parcel.Parcelize
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.lindoor.LindoorApplication
import org.lindoor.customisation.DeviceTypes
import org.lindoor.store.StorageManager
......@@ -10,6 +16,7 @@ import org.lindoor.utils.extensions.existsAndIsNotEmpty
import org.lindoor.utils.extensions.xDigitsUUID
import org.linphone.core.CallParams
import java.io.File
import java.io.FileInputStream
import java.util.*
......@@ -24,6 +31,8 @@ data class Device(
) :
Parcelable {
var typeIconAsBitmap: Bitmap? = null
constructor(
type: String?,
name: String,
......@@ -34,6 +43,12 @@ data class Device(
xDigitsUUID(), type, name, address, actionsMethodType, actions
)
init {
GlobalScope.launch() {
typeIconAsBitmap = typeIconAsBitmap(type)
}
}
val thumbNail: File
get() {
......@@ -47,12 +62,6 @@ data class Device(
} ?: false
}
fun supportsAudio(): Boolean {
return type?.let {
DeviceTypes.supportsAudio(it)
} ?: true
}
fun call() {
val params: CallParams? = LindoorApplication.coreContext.core.createCallParams(null)
type?.also {
......@@ -87,9 +96,33 @@ data class Device(
}
}
companion object {
fun typeIconAsBitmap(type: String?): Bitmap? {
return type?.let {
val svgFile = File(
LindoorApplication.instance.filesDir,
"images/${DeviceTypes.iconNameForDeviceType(it)}.svg"
)
val targetStream = FileInputStream(svgFile)
val svg = SVG.getFromInputStream(targetStream)
if (svg.documentWidth != -1f) {
val newBM = Bitmap.createBitmap(
Math.ceil(svg.documentWidth.toDouble()).toInt(),
Math.ceil(svg.documentHeight.toDouble()).toInt(),
Bitmap.Config.ARGB_8888
)
val bmcanvas = Canvas(newBM)
bmcanvas.drawRGB(255, 255, 255)
svg.renderToCanvas(bmcanvas)
newBM
} else
null
}
}
}
fun hasThumbNail(): Boolean {
return thumbNail.existsAndIsNotEmpty()
}
}
\ No newline at end of file
......@@ -42,6 +42,7 @@ import org.lindoor.LindoorApplication.Companion.coreContext
import org.lindoor.LindoorApplication.Companion.corePreferences
import org.lindoor.MainActivity
import org.lindoor.R
import org.lindoor.customisation.DeviceTypes
import org.lindoor.customisation.Texts
import org.lindoor.customisation.Theme
import org.lindoor.linphonecore.CoreService
......@@ -59,6 +60,7 @@ import org.linphone.core.CallListenerStub
import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.tools.Log
import java.io.File
import java.util.*
import kotlin.collections.HashMap
import kotlin.concurrent.fixedRateTimer
......@@ -87,7 +89,6 @@ class NotificationsManager(private val context: Context) {
const val INTENT_NOTIF_ID = "NOTIFICATION_ID"
const val INTENT_HANGUP_CALL_NOTIF_ACTION = "org.lindoor.HANGUP_CALL_ACTION"
const val INTENT_ANSWER_CALL_NOTIF_ACTION = "org.lindoor.ANSWER_CALL_ACTION"
const val INTENT_LOCAL_IDENTITY = "LOCAL_IDENTITY"
private const val SERVICE_NOTIF_ID = 1
private const val MISSED_CALLS_NOTIF_ID = 2
......@@ -97,7 +98,6 @@ class NotificationsManager(private val context: Context) {
private val notificationManager: NotificationManagerCompat by lazy {
NotificationManagerCompat.from(context)
}
private val chatNotificationsMap: HashMap<String, Notifiable> = HashMap()
private val callNotificationsMap: HashMap<String, Notifiable> = HashMap()
private var lastNotificationId: Int = 5
......@@ -148,18 +148,16 @@ class NotificationsManager(private val context: Context) {
call.callLog.historyEvent().mediaThumbnail.also {
if (it.existsAndIsNotEmpty() && it.length() != fileLenght && !LindoorApplication.someActivityRunning) {
fileLenght = it.length()
val notificationLayoutHeadsUp =
val remoteView =
fillIncomingRemoteViewsForCall(call, true)
val awt = AppWidgetTarget(
context.applicationContext,
R.id.caller_picture,
notificationLayoutHeadsUp,
remoteView,
0
)
Glide.with(context.applicationContext).asBitmap().load(it).into(awt)
notificationBuilder.setCustomBigContentView(
notificationLayoutHeadsUp
)
notificationBuilder.setCustomBigContentView(remoteView)
val notification = notificationBuilder.build()
if (!LindoorApplication.someActivityRunning && call.state == Call.State.IncomingEarlyMedia)
notify(getNotifiableForCall(call).notificationId, notification)
......@@ -328,10 +326,9 @@ class NotificationsManager(private val context: Context) {
private fun fillIncomingRemoteViewsForCall(call: Call, hasSnapShot: Boolean): RemoteViews {
val address = call.remoteAddress.asStringUriOnly()
val displayName =
DeviceStore.findDeviceByAddress(call.remoteAddress)?.name ?: call.remoteAddress.username
val notificationLayoutHeadsUp =
val device = DeviceStore.findDeviceByAddress(call.remoteAddress)
val displayName = device?.name ?: call.remoteAddress.username
val remoteView =
if (hasSnapShot)
RemoteViews(
context.packageName,
......@@ -340,13 +337,26 @@ class NotificationsManager(private val context: Context) {
else
RemoteViews(context.packageName, R.layout.call_incoming_notification_content)
notificationLayoutHeadsUp.setTextViewText(R.id.caller, displayName)
notificationLayoutHeadsUp.setTextViewText(R.id.sip_uri, address)
notificationLayoutHeadsUp.setTextViewText(
remoteView.setTextViewText(R.id.caller, displayName)
remoteView.setTextViewText(
R.id.incoming_call_info,
Texts.get("notif_incoming_call_title")
)
return notificationLayoutHeadsUp
device?.also { device ->
device.typeIconAsBitmap?.also {
val awt = AppWidgetTarget(
context.applicationContext,
R.id.device_type,
remoteView,
if (hasSnapShot) 1 else 2
)
Glide.with(context.applicationContext).asBitmap().load(it).into(awt)
}
}
return remoteView
}
......
......@@ -5,7 +5,7 @@
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
......@@ -16,13 +16,6 @@
android:layout_height="wrap_content"
style="@android:style/TextAppearance.Material.Notification.Title"/>
<TextView
android:id="@+id/sip_uri"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/color_a"
style="@android:style/TextAppearance.Material.Notification.Line2"/>
<TextView
android:id="@+id/incoming_call_info"
android:layout_width="match_parent"
......@@ -31,6 +24,12 @@
</LinearLayout>
<ImageView
android:id="@+id/device_type"
android:src="@drawable/ic_lindoor_icon"
android:layout_alignParentRight="true"
android:layout_width="50dp"
android:layout_height="50dp">
</ImageView>
</RelativeLayout>
\ No newline at end of file
......@@ -5,8 +5,9 @@
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="55dp"
android:layout_alignParentTop="true"
android:orientation="vertical">
......@@ -16,12 +17,6 @@
android:layout_height="wrap_content"
style="@android:style/TextAppearance.Material.Notification.Title"/>
<TextView
android:id="@+id/sip_uri"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/color_a"
style="@android:style/TextAppearance.Material.Notification.Line2"/>
<TextView
android:id="@+id/incoming_call_info"
......@@ -32,6 +27,16 @@
</LinearLayout>
<ImageView
android:id="@+id/device_type"
android:src="@drawable/ic_lindoor_icon"
android:layout_alignParentRight="true"
android:layout_width="50dp"
android:layout_marginEnd="5dp"
android:layout_height="50dp">
</ImageView>
<ImageView
android:layout_marginTop="10dp"
android:id="@+id/caller_picture"
android:contentDescription="@null"
android:layout_width="wrap_content"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment