some work on adding answer/reject buttons to call notification
some minor improvements
This commit is contained in:
@ -111,6 +111,16 @@
|
||||
<service android:name=".BaresipService" >
|
||||
</service>
|
||||
|
||||
<receiver
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:name="com.tutpro.baresip.RunOnStartup"
|
||||
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@ -30,7 +30,8 @@ class BaresipService: Service() {
|
||||
private val LOG_TAG = "Baresip Service"
|
||||
internal lateinit var intent: Intent
|
||||
internal lateinit var nm: NotificationManager
|
||||
internal lateinit var nb: NotificationCompat.Builder
|
||||
internal lateinit var snb: NotificationCompat.Builder
|
||||
internal lateinit var cnb: NotificationCompat.Builder
|
||||
internal lateinit var ni: Intent
|
||||
internal lateinit var npi: PendingIntent
|
||||
internal lateinit var nr: BroadcastReceiver
|
||||
@ -46,7 +47,8 @@ class BaresipService: Service() {
|
||||
intent.setPackage("com.tutpro.baresip")
|
||||
|
||||
nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
nb = NotificationCompat.Builder(this)
|
||||
snb = NotificationCompat.Builder(this)
|
||||
cnb = NotificationCompat.Builder(this)
|
||||
|
||||
ni = Intent(this, MainActivity::class.java)
|
||||
.setAction(Intent.ACTION_MAIN)
|
||||
@ -162,13 +164,13 @@ class BaresipService: Service() {
|
||||
}
|
||||
|
||||
private fun showNotification() {
|
||||
nb.setVisibility(VISIBILITY_PUBLIC)
|
||||
snb.setVisibility(VISIBILITY_PUBLIC)
|
||||
.setSmallIcon(R.drawable.ic_stat)
|
||||
.setContentIntent(npi)
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.setOngoing(true)
|
||||
.setContent(RemoteViews(packageName, R.layout.notification))
|
||||
startForeground(STATUS_NOTIFICATION_ID, nb.build())
|
||||
.setContent(RemoteViews(packageName, R.layout.status_notification))
|
||||
startForeground(STATUS_NOTIFICATION_ID, snb.build())
|
||||
}
|
||||
|
||||
@Keep
|
||||
@ -194,7 +196,7 @@ class BaresipService: Service() {
|
||||
|
||||
@Keep
|
||||
fun updateStatus(event: String, uap: String, callp: String) {
|
||||
Log.d(LOG_TAG, "updateStatus got event $event")
|
||||
Log.d(LOG_TAG, "updateStatus got event $event/$uap/$callp")
|
||||
if (!IS_SERVICE_RUNNING) return
|
||||
val ua = UserAgent.find(MainActivity.uas, uap)
|
||||
if (ua == null) {
|
||||
@ -231,22 +233,55 @@ class BaresipService: Service() {
|
||||
}
|
||||
"call incoming" -> {
|
||||
if (!Utils.isVisible()) {
|
||||
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())
|
||||
snb.setVibrate(LongArray(0))
|
||||
val view = RemoteViews(getPackageName(), R.layout.status_notification)
|
||||
view.setTextViewText(R.id.callFrom, "Call from ${Api.call_peeruri(callp)}")
|
||||
view.setViewVisibility(R.id.incomingCall, View.VISIBLE)
|
||||
snb.setContent(view)
|
||||
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||
}
|
||||
rt.play()
|
||||
/* if (!Utils.isVisible()) {
|
||||
nm.cancel(STATUS_NOTIFICATION_ID)
|
||||
val cnb = NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.ic_stat)
|
||||
.setContentIntent(npi)
|
||||
.setVisibility(VISIBILITY_PUBLIC)
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.setVibrate(LongArray(0))
|
||||
val answerIntent = Intent(this, MainActivity::class.java)
|
||||
answerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
answerIntent.putExtra("action", "answer")
|
||||
answerIntent.putExtra("uap", uap)
|
||||
answerIntent.putExtra("callp", callp)
|
||||
val answerPendingIntent = PendingIntent.getActivity(this,
|
||||
0, answerIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val rejectIntent = Intent(this, MainActivity::class.java)
|
||||
rejectIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
rejectIntent.putExtra("action", "reject")
|
||||
rejectIntent.putExtra("uap", uap)
|
||||
rejectIntent.putExtra("callp", callp)
|
||||
val rejectPendingIntent = PendingIntent.getActivity(this,
|
||||
0, rejectIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val view = RemoteViews(getPackageName(), R.layout.call_notification)
|
||||
view.setTextViewText(R.id.caller, "${Api.call_peeruri(callp)}")
|
||||
view.setOnClickPendingIntent(R.id.answerButton, answerPendingIntent)
|
||||
view.setOnClickPendingIntent(R.id.rejectButton, rejectPendingIntent)
|
||||
cnb.setCustomBigContentView(view)
|
||||
cnb.setVibrate(LongArray(0))
|
||||
nm.notify(CALL_NOTIFICATION_ID, cnb.build())
|
||||
return
|
||||
} */
|
||||
}
|
||||
"call established", "call closed" -> {
|
||||
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())
|
||||
nm.cancel(CALL_NOTIFICATION_ID)
|
||||
val view = RemoteViews(getPackageName(), R.layout.status_notification)
|
||||
view.setViewVisibility(R.id.incomingCall, View.GONE)
|
||||
snb.setContent(view)
|
||||
snb.setVibrate(null)
|
||||
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||
rt.stop()
|
||||
}
|
||||
}
|
||||
@ -269,7 +304,7 @@ class BaresipService: Service() {
|
||||
}
|
||||
|
||||
fun updateNotification() {
|
||||
val contentView = RemoteViews(getPackageName(), R.layout.notification)
|
||||
val contentView = RemoteViews(getPackageName(), R.layout.status_notification)
|
||||
for (i: Int in 0 .. 5) {
|
||||
val resID = resources.getIdentifier("status$i", "id", packageName)
|
||||
if (i < MainActivity.images.size) {
|
||||
@ -283,8 +318,8 @@ class BaresipService: Service() {
|
||||
contentView.setViewVisibility(R.id.etc, View.VISIBLE)
|
||||
else
|
||||
contentView.setViewVisibility(R.id.etc, View.INVISIBLE)
|
||||
nb.setContent(contentView)
|
||||
nm.notify(STATUS_NOTIFICATION_ID, nb.build())
|
||||
snb.setContent(contentView)
|
||||
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||
}
|
||||
|
||||
external fun baresipStart(path: String)
|
||||
@ -294,6 +329,7 @@ class BaresipService: Service() {
|
||||
|
||||
var IS_SERVICE_RUNNING = false
|
||||
val STATUS_NOTIFICATION_ID = 101
|
||||
val CALL_NOTIFICATION_ID = 102
|
||||
var disconnected = false
|
||||
|
||||
}
|
||||
|
||||
@ -287,6 +287,9 @@ class MainActivity : AppCompatActivity() {
|
||||
baresipService.setAction("Start")
|
||||
startService(baresipService)
|
||||
}
|
||||
|
||||
if (intent.hasExtra("onStartup"))
|
||||
moveTaskToBack(true)
|
||||
}
|
||||
|
||||
private fun handleServiceEvent(event: String, uap: String, callp: String) {
|
||||
@ -311,8 +314,9 @@ class MainActivity : AppCompatActivity() {
|
||||
if (ONE_CALL_ONLY && (calls.size > 0)) {
|
||||
Log.d("Baresip", "Auto-rejecting incoming call $uap/$callp/$peer_uri")
|
||||
ua_hangup(uap, callp, 486, "Busy Here")
|
||||
if (History.aorHistory(history, aor) > HISTORY_SIZE)
|
||||
History.aorRemoveHistory(history, aor)
|
||||
history.add(History(aor, peer_uri, "in", false))
|
||||
new_call.hasHistory = true
|
||||
} else {
|
||||
Log.d("Baresip", "Incoming call $uap/$callp/$peer_uri")
|
||||
calls.add(new_call)
|
||||
@ -540,6 +544,31 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
setIntent(intent)
|
||||
val action = intent.getStringExtra("action")
|
||||
Log.d("Baresip", "Got onNewIntent action $action")
|
||||
if (action == null) return
|
||||
val uap = intent.getStringExtra("uap")
|
||||
val callp = intent.getStringExtra("callp")
|
||||
val ua = UserAgent.find(uas, intent.getStringExtra("uap"))!!
|
||||
val aor = ua.account.aor
|
||||
val peer_uri = Api.call_peeruri(callp)
|
||||
when (action) {
|
||||
"answer" -> {
|
||||
/* TODO */
|
||||
}
|
||||
"reject" -> {
|
||||
Log.d("Baresip", "Rejecting incoming call from $peer_uri")
|
||||
ua_hangup(uap, callp, 486, "Busy Here")
|
||||
if (History.aorHistory(history, aor) > HISTORY_SIZE)
|
||||
History.aorRemoveHistory(history, aor)
|
||||
history.add(History(aor, peer_uri, "in", false))
|
||||
moveTaskToBack(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
Log.d("Baresip", "Paused")
|
||||
|
||||
@ -12,7 +12,7 @@ class RunOnStartup : BroadcastReceiver() {
|
||||
val i = Intent(context, MainActivity::class.java)
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
val b = Bundle()
|
||||
b.putBoolean("onstartup", true)
|
||||
b.putBoolean("onStartup", true)
|
||||
i.putExtras(b)
|
||||
context.startActivity(i)
|
||||
}
|
||||
|
||||
64
app/src/main/res/layout/call_notification.xml
Normal file
64
app/src/main/res/layout/call_notification.xml
Normal file
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/callHeading"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="14dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ImageView android:id="@+id/headingImage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:src="@drawable/baresip" />
|
||||
|
||||
<TextView android:id="@+id/headingText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:textSize="15dp"
|
||||
android:textColor="#000000"
|
||||
android:text="Call from"
|
||||
style = "@android:style/TextAppearance.Medium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView android:id="@+id/caller"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_below="@id/callHeading"
|
||||
android:textSize="15dp"
|
||||
android:text="peer uri"
|
||||
style = "@android:style/TextAppearance.Medium" />
|
||||
|
||||
<Button android:id="@+id/answerButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/caller"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_gravity="center"
|
||||
android:text="Answer" />
|
||||
|
||||
<Button android:id="@+id/rejectButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/caller"
|
||||
android:layout_toEndOf="@id/answerButton"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_gravity="center"
|
||||
android:text="Reject" />
|
||||
|
||||
</RelativeLayout>
|
||||
@ -64,7 +64,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView android:id="@+id/incoming"
|
||||
<TextView android:id="@+id/callFrom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/mainRow"
|
||||
Reference in New Issue
Block a user