added account status info to notification
This commit is contained in:
@@ -21,17 +21,18 @@ import android.widget.RelativeLayout.LayoutParams
|
|||||||
import android.widget.AutoCompleteTextView
|
import android.widget.AutoCompleteTextView
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
import java.io.*
|
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
|
import android.support.v7.app.NotificationCompat
|
||||||
import android.support.v7.view.menu.ActionMenuItemView
|
import android.support.v7.view.menu.ActionMenuItemView
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
import android.text.TextWatcher
|
import android.text.TextWatcher
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
import java.io.*
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
internal lateinit var appContext: Context
|
internal lateinit var appContext: Context
|
||||||
@@ -46,6 +47,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
internal lateinit var am: AudioManager
|
internal lateinit var am: AudioManager
|
||||||
internal lateinit var imm: InputMethodManager
|
internal lateinit var imm: InputMethodManager
|
||||||
internal lateinit var nm: NotificationManager
|
internal lateinit var nm: NotificationManager
|
||||||
|
internal lateinit var nb: NotificationCompat.Builder
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
||||||
@@ -60,8 +62,20 @@ class MainActivity : AppCompatActivity() {
|
|||||||
holdButton = findViewById(R.id.holdButton) as Button
|
holdButton = findViewById(R.id.holdButton) as Button
|
||||||
dtmf = findViewById(R.id.dtmf) as EditText
|
dtmf = findViewById(R.id.dtmf) as EditText
|
||||||
|
|
||||||
am = appContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
am = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
|
nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
|
||||||
|
nb = NotificationCompat.Builder(this)
|
||||||
|
nb.setVisibility(VISIBILITY_PUBLIC).setOngoing(true).setSmallIcon(R.drawable.ic_stat)
|
||||||
|
.setContentIntent(
|
||||||
|
PendingIntent.getActivity(this, NOTIFICATION_ID,
|
||||||
|
Intent(this, MainActivity::class.java)
|
||||||
|
.setAction(Intent.ACTION_MAIN)
|
||||||
|
.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT))
|
||||||
|
.setContent(RemoteViews(getPackageName(), R.layout.notification))
|
||||||
|
|
||||||
aorSpinner = findViewById(R.id.AoRList) as Spinner
|
aorSpinner = findViewById(R.id.AoRList) as Spinner
|
||||||
accountAdapter = AccountSpinnerAdapter(applicationContext, aors, images)
|
accountAdapter = AccountSpinnerAdapter(applicationContext, aors, images)
|
||||||
@@ -263,7 +277,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
if (!running) {
|
if (!running) {
|
||||||
Log.i("Baresip", "Starting Baresip with path $path")
|
Log.i("Baresip", "Starting Baresip with path $path")
|
||||||
statusBarIcon(NOTIFICATION_ID, "")
|
nm.notify(NOTIFICATION_ID, nb.build())
|
||||||
Thread(Runnable { baresipStart(path) }).start()
|
Thread(Runnable { baresipStart(path) }).start()
|
||||||
running = true
|
running = true
|
||||||
}
|
}
|
||||||
@@ -365,7 +379,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
if (requestCode == EDIT_ACCOUNTS_CODE) {
|
|
||||||
|
when (requestCode) {
|
||||||
|
|
||||||
|
EDIT_ACCOUNTS_CODE -> {
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
Utils.alertView(this, "Notice",
|
Utils.alertView(this, "Notice",
|
||||||
"You need to restart baresip in order to activate saved accounts!")
|
"You need to restart baresip in order to activate saved accounts!")
|
||||||
@@ -374,7 +391,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Log.d("Baresip", "Edit accounts canceled")
|
Log.d("Baresip", "Edit accounts canceled")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requestCode == EDIT_CONFIG_CODE) {
|
|
||||||
|
EDIT_CONFIG_CODE -> {
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
Utils.alertView(this, "Notice",
|
Utils.alertView(this, "Notice",
|
||||||
"You need to restart baresip in order to activate saved config!")
|
"You need to restart baresip in order to activate saved config!")
|
||||||
@@ -384,7 +402,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Log.d("Baresip", "Edit config canceled")
|
Log.d("Baresip", "Edit config canceled")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requestCode == HISTORY_CODE) {
|
|
||||||
|
HISTORY_CODE -> {
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
(findViewById(R.id.callee) as EditText).setText(data.getStringExtra("peer_uri"))
|
(findViewById(R.id.callee) as EditText).setText(data.getStringExtra("peer_uri"))
|
||||||
@@ -397,10 +416,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requestCode == EDIT_CONTACTS_CODE || requestCode == ABOUT_CODE) {
|
|
||||||
|
EDIT_CONTACTS_CODE, ABOUT_CODE -> {
|
||||||
Log.d("Baresip", "Back arrow or Cancel pressed at request: $requestCode")
|
Log.d("Baresip", "Back arrow or Cancel pressed at request: $requestCode")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun call(aor: String, callee: String) {
|
private fun call(aor: String, callee: String) {
|
||||||
if (callee.length == 0) return
|
if (callee.length == 0) return
|
||||||
@@ -572,38 +593,23 @@ class MainActivity : AppCompatActivity() {
|
|||||||
layout.addView(reject_button)
|
layout.addView(reject_button)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun statusBarIcon(id: Int, status: String) {
|
|
||||||
val ni = Intent(this, MainActivity::class.java)
|
|
||||||
.setAction(Intent.ACTION_MAIN)
|
|
||||||
.addCategory(Intent.CATEGORY_LAUNCHER)
|
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
val pi = PendingIntent.getActivity(this, id, ni, PendingIntent.FLAG_UPDATE_CURRENT)
|
|
||||||
nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
|
||||||
val notification = Notification.Builder(this)
|
|
||||||
.setSmallIcon(R.drawable.ic_stat)
|
|
||||||
.setContentTitle("Baresip is running${status}!")
|
|
||||||
.setVisibility(VISIBILITY_PUBLIC)
|
|
||||||
.setContentIntent(pi)
|
|
||||||
.setOngoing(true).build()
|
|
||||||
nm.notify(id, notification)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateNotification() {
|
private fun updateNotification() {
|
||||||
var status: String = ""
|
val contentView = RemoteViews(getPackageName(), R.layout.notification)
|
||||||
for (image in images) {
|
for (i: Int in 0 .. 3) {
|
||||||
when (image) {
|
val resID = resources.getIdentifier("status$i", "id", packageName);
|
||||||
R.drawable.dot_red -> {
|
if (i < images.size) {
|
||||||
status = status + " X"
|
contentView.setImageViewResource(resID, images[i])
|
||||||
}
|
contentView.setViewVisibility(resID, View.VISIBLE)
|
||||||
R.drawable.dot_yellow -> {
|
} else {
|
||||||
status = status + " ?"
|
contentView.setViewVisibility(resID, View.INVISIBLE)
|
||||||
}
|
|
||||||
R.drawable.dot_green -> {
|
|
||||||
status = status + " OK"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (images.size > 4)
|
||||||
statusBarIcon(NOTIFICATION_ID, status)
|
contentView.setViewVisibility(R.id.etc, View.VISIBLE)
|
||||||
|
else
|
||||||
|
contentView.setViewVisibility(R.id.etc, View.INVISIBLE)
|
||||||
|
nb.setContent(contentView);
|
||||||
|
nm.notify(NOTIFICATION_ID, nb.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
@@ -923,13 +929,13 @@ class MainActivity : AppCompatActivity() {
|
|||||||
internal var callsIn = ArrayList<Call>()
|
internal var callsIn = ArrayList<Call>()
|
||||||
internal var callsOut = ArrayList<Call>()
|
internal var callsOut = ArrayList<Call>()
|
||||||
|
|
||||||
const val RECORD_AUDIO_PERMISSION = 1
|
|
||||||
const val EDIT_ACCOUNTS_CODE = 1
|
const val EDIT_ACCOUNTS_CODE = 1
|
||||||
const val EDIT_CONTACTS_CODE = 2
|
const val EDIT_CONTACTS_CODE = 2
|
||||||
const val EDIT_CONFIG_CODE = 3
|
const val EDIT_CONFIG_CODE = 3
|
||||||
const val HISTORY_CODE = 4
|
const val HISTORY_CODE = 4
|
||||||
const val ABOUT_CODE = 5
|
const val ABOUT_CODE = 5
|
||||||
|
|
||||||
|
const val RECORD_AUDIO_PERMISSION = 1
|
||||||
const val HISTORY_SIZE = 100
|
const val HISTORY_SIZE = 100
|
||||||
const val NOTIFICATION_ID = 10
|
const val NOTIFICATION_ID = 10
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/notificationLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal" >
|
||||||
|
|
||||||
|
<ImageView android:id="@+id/image"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:src="@drawable/baresip" />
|
||||||
|
|
||||||
|
<TextView android:id="@+id/text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textSize="15dp"
|
||||||
|
android:text="Baresip is running "
|
||||||
|
style = "@android:style/TextAppearance.Medium" />
|
||||||
|
|
||||||
|
<ImageView android:id="@+id/status0"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:paddingLeft="10dp" />
|
||||||
|
|
||||||
|
<ImageView android:id="@+id/status1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:paddingLeft="10dp" />
|
||||||
|
|
||||||
|
<ImageView android:id="@+id/status2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:paddingLeft="10dp" />
|
||||||
|
|
||||||
|
<ImageView android:id="@+id/status3"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:paddingLeft="10dp" />
|
||||||
|
|
||||||
|
<TextView android:id="@+id/etc"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:paddingLeft="5dp"
|
||||||
|
android:text="..."
|
||||||
|
style = "@android:style/TextAppearance.Medium" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user