Cleaned up some code and resources

This commit is contained in:
Juha Heinanen
2021-03-20 16:20:39 +02:00
parent eda703cec8
commit 32f61016f2
18 changed files with 59 additions and 142 deletions
@@ -24,7 +24,7 @@ class AboutActivity : AppCompatActivity() {
val text = String.format(getString(R.string.about_text), val text = String.format(getString(R.string.about_text),
BuildConfig.VERSION_NAME) BuildConfig.VERSION_NAME)
binding.aboutText.text = HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY) binding.aboutText.text = HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY)
binding.aboutText.setMovementMethod(LinkMovementMethod.getInstance()) binding.aboutText.movementMethod = LinkMovementMethod.getInstance()
} }
@@ -253,7 +253,7 @@ class AccountActivity : AppCompatActivity() {
if (dn != acc.displayName) { if (dn != acc.displayName) {
if (Account.checkDisplayName(dn)) { if (Account.checkDisplayName(dn)) {
if (Api.account_set_display_name(acc.accp, dn) == 0) { if (Api.account_set_display_name(acc.accp, dn) == 0) {
acc.displayName = Api.account_display_name(acc.accp); acc.displayName = Api.account_display_name(acc.accp)
Log.d(TAG, "New display name is ${acc.displayName}") Log.d(TAG, "New display name is ${acc.displayName}")
save = true save = true
} else { } else {
@@ -272,7 +272,7 @@ class AccountActivity : AppCompatActivity() {
if (au != acc.authUser) { if (au != acc.authUser) {
if (Account.checkAuthUser(au)) { if (Account.checkAuthUser(au)) {
if (Api.account_set_auth_user(acc.accp, au) == 0) { if (Api.account_set_auth_user(acc.accp, au) == 0) {
acc.authUser = Api.account_auth_user(acc.accp); acc.authUser = Api.account_auth_user(acc.accp)
Log.d(TAG, "New auth user is ${acc.authUser}") Log.d(TAG, "New auth user is ${acc.authUser}")
save = true save = true
} else { } else {
@@ -344,7 +344,7 @@ class AccountActivity : AppCompatActivity() {
return false return false
} }
} }
Log.d(TAG, "New outbound proxies are ${outbound}") Log.d(TAG, "New outbound proxies are $outbound")
acc.outbound = outbound acc.outbound = outbound
if (outbound.isEmpty()) if (outbound.isEmpty())
Api.account_set_sipnat(acc.accp, "") Api.account_set_sipnat(acc.accp, "")
@@ -411,7 +411,7 @@ class AccountActivity : AppCompatActivity() {
if (acc.stunUser != newStunUser) { if (acc.stunUser != newStunUser) {
if (Account.checkAuthUser(newStunUser)) { if (Account.checkAuthUser(newStunUser)) {
if (Api.account_set_stun_user(acc.accp, newStunUser) == 0) { if (Api.account_set_stun_user(acc.accp, newStunUser) == 0) {
acc.stunUser = Api.account_stun_user(acc.accp); acc.stunUser = Api.account_stun_user(acc.accp)
Log.d(TAG, "New STUN/TURN user is ${acc.stunUser}") Log.d(TAG, "New STUN/TURN user is ${acc.stunUser}")
save = true save = true
} else { } else {
@@ -428,7 +428,7 @@ class AccountActivity : AppCompatActivity() {
if (acc.stunPass != newStunPass) { if (acc.stunPass != newStunPass) {
if (newStunPass.isEmpty() || Account.checkAuthPass(newStunPass)) { if (newStunPass.isEmpty() || Account.checkAuthPass(newStunPass)) {
if (Api.account_set_stun_pass(acc.accp, newStunPass) == 0) { if (Api.account_set_stun_pass(acc.accp, newStunPass) == 0) {
acc.stunPass = Api.account_stun_pass(acc.accp); acc.stunPass = Api.account_stun_pass(acc.accp)
save = true save = true
} else { } else {
Log.e(TAG, "Setting of stun pass failed") Log.e(TAG, "Setting of stun pass failed")
@@ -261,7 +261,7 @@ class BaresipService: Service() {
val dnsServers = Utils.findDnsServers(BaresipService.dnsServers) val dnsServers = Utils.findDnsServers(BaresipService.dnsServers)
if ((ipV4Addr == "") && (ipV6Addr == "")) if ((ipV4Addr == "") && (ipV6Addr == ""))
Log.w(LOG_TAG, "Starting baresip without IP addresses") Log.w(LOG_TAG, "Starting baresip without IP addresses")
Thread(Runnable { Thread({
baresipStart(filesPath, ipV4Addr, ipV6Addr, "", baresipStart(filesPath, ipV4Addr, ipV6Addr, "",
dnsServers, Api.AF_UNSPEC, logLevel) dnsServers, Api.AF_UNSPEC, logLevel)
}).start() }).start()
@@ -466,7 +466,7 @@ class BaresipService: Service() {
newEvent = "registering failed,DNS lookup failed" newEvent = "registering failed,DNS lookup failed"
Api.net_dns_debug() Api.net_dns_debug()
if (dynDns) if (dynDns)
if (Build.VERSION.SDK_INT >= 23) { if (VERSION.SDK_INT >= 23) {
val activeNetwork = cm.activeNetwork val activeNetwork = cm.activeNetwork
if (activeNetwork != null) { if (activeNetwork != null) {
val props = cm.getLinkProperties(activeNetwork) val props = cm.getLinkProperties(activeNetwork)
@@ -531,7 +531,7 @@ class BaresipService: Service() {
Call(callp, ua, peerUri, "in", "incoming", Call(callp, ua, peerUri, "in", "incoming",
Utils.dtmfWatcher(callp)).add() Utils.dtmfWatcher(callp)).add()
if (ua.account.answerMode == Api.ANSWERMODE_MANUAL) { if (ua.account.answerMode == Api.ANSWERMODE_MANUAL) {
if (Build.VERSION.SDK_INT >= 23) { if (VERSION.SDK_INT >= 23) {
Log.d(LOG_TAG, "CurrentInterruptionFilter ${nm.currentInterruptionFilter}") Log.d(LOG_TAG, "CurrentInterruptionFilter ${nm.currentInterruptionFilter}")
if (nm.currentInterruptionFilter <= NotificationManager.INTERRUPTION_FILTER_ALL) if (nm.currentInterruptionFilter <= NotificationManager.INTERRUPTION_FILTER_ALL)
startRinging() startRinging()
@@ -568,7 +568,7 @@ class BaresipService: Service() {
.setContentText(caller) .setContentText(caller)
.setShowWhen(true) .setShowWhen(true)
.setFullScreenIntent(pi, true) .setFullScreenIntent(pi, true)
if (Build.VERSION.SDK_INT < 26) { if (VERSION.SDK_INT < 26) {
nb.setVibrate(LongArray(0)) nb.setVibrate(LongArray(0))
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
.priority = Notification.PRIORITY_HIGH .priority = Notification.PRIORITY_HIGH
@@ -659,10 +659,9 @@ class BaresipService: Service() {
.setAutoCancel(true) .setAutoCancel(true)
.setContentTitle(getString(R.string.transfer_request_to)) .setContentTitle(getString(R.string.transfer_request_to))
.setContentText(target) .setContentText(target)
if (Build.VERSION.SDK_INT < 26) { if (VERSION.SDK_INT < 26) {
nb.setVibrate(LongArray(0)) nb.setVibrate(LongArray(0))
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE).priority = Notification.PRIORITY_HIGH
.setPriority(Notification.PRIORITY_HIGH)
} }
val acceptIntent = Intent(this, BaresipService::class.java) val acceptIntent = Intent(this, BaresipService::class.java)
acceptIntent.action = "Transfer Accept" acceptIntent.action = "Transfer Accept"
@@ -729,7 +728,7 @@ class BaresipService: Service() {
.setAutoCancel(true) .setAutoCancel(true)
.setContentTitle(getString(R.string.missed_call_from)) .setContentTitle(getString(R.string.missed_call_from))
.setContentText(caller) .setContentText(caller)
if (Build.VERSION.SDK_INT < 26) { if (VERSION.SDK_INT < 26) {
nb.setVibrate(LongArray(0)) nb.setVibrate(LongArray(0))
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
.priority = Notification.PRIORITY_HIGH .priority = Notification.PRIORITY_HIGH
@@ -796,7 +795,7 @@ class BaresipService: Service() {
.setAutoCancel(true) .setAutoCancel(true)
.setContentTitle(getString(R.string.message_from) + " " + sender) .setContentTitle(getString(R.string.message_from) + " " + sender)
.setContentText(text) .setContentText(text)
if (Build.VERSION.SDK_INT < 26) { if (VERSION.SDK_INT < 26) {
nb.setVibrate(LongArray(0)) nb.setVibrate(LongArray(0))
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
.priority = Notification.PRIORITY_HIGH .priority = Notification.PRIORITY_HIGH
@@ -877,7 +876,7 @@ class BaresipService: Service() {
} }
private fun createNotificationChannels() { private fun createNotificationChannels() {
if (Build.VERSION.SDK_INT >= 26) { if (VERSION.SDK_INT >= 26) {
val defaultChannel = NotificationChannel(DEFAULT_CHANNEL_ID, "Default", val defaultChannel = NotificationChannel(DEFAULT_CHANNEL_ID, "Default",
NotificationManager.IMPORTANCE_LOW) NotificationManager.IMPORTANCE_LOW)
defaultChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC defaultChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
@@ -904,7 +903,7 @@ class BaresipService: Service() {
} }
private fun updateStatusNotification() { private fun updateStatusNotification() {
val contentView = RemoteViews(getPackageName(), R.layout.status_notification) val contentView = RemoteViews(packageName, R.layout.status_notification)
for (i: Int in 0..5) { for (i: Int in 0..5) {
val resID = resources.getIdentifier("status$i", "id", packageName) val resID = resources.getIdentifier("status$i", "id", packageName)
if (i < status.size) { if (i < status.size) {
@@ -922,7 +921,7 @@ class BaresipService: Service() {
nm.notify(STATUS_NOTIFICATION_ID, snb.build()) nm.notify(STATUS_NOTIFICATION_ID, snb.build())
} }
private fun getActionText(@StringRes stringRes: Int, @ColorRes colorRes: Int): Spannable? { private fun getActionText(@StringRes stringRes: Int, @ColorRes colorRes: Int): Spannable {
val spannable: Spannable = SpannableString(applicationContext.getText(stringRes)) val spannable: Spannable = SpannableString(applicationContext.getText(stringRes))
if (VERSION.SDK_INT >= VERSION_CODES.N_MR1) { if (VERSION.SDK_INT >= VERSION_CODES.N_MR1) {
spannable.setSpan( spannable.setSpan(
@@ -939,7 +938,7 @@ class BaresipService: Service() {
else else
abandonAudioFocus() abandonAudioFocus()
} }
if ((Build.VERSION.SDK_INT >= 26) && (audioFocusRequest == null)) { if ((VERSION.SDK_INT >= 26) && (audioFocusRequest == null)) {
@TargetApi(26) @TargetApi(26)
audioFocusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE) audioFocusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE)
.run { .run {
@@ -987,7 +986,7 @@ class BaresipService: Service() {
} }
private fun abandonAudioFocus() { private fun abandonAudioFocus() {
if (Build.VERSION.SDK_INT >= 26) { if (VERSION.SDK_INT >= 26) {
if (audioFocusRequest != null) { if (audioFocusRequest != null) {
if (am.abandonAudioFocusRequest(audioFocusRequest!!) == if (am.abandonAudioFocusRequest(audioFocusRequest!!) ==
AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
@@ -1013,7 +1012,7 @@ class BaresipService: Service() {
private fun startRinging() { private fun startRinging() {
am.mode = AudioManager.MODE_RINGTONE am.mode = AudioManager.MODE_RINGTONE
requestAudioFocus(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) requestAudioFocus(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
if (Build.VERSION.SDK_INT >= 28) { if (VERSION.SDK_INT >= 28) {
rt.isLooping = true rt.isLooping = true
rt.play() rt.play()
} else { } else {
@@ -1021,7 +1020,7 @@ class BaresipService: Service() {
rtTimer = Timer() rtTimer = Timer()
rtTimer!!.scheduleAtFixedRate(object : TimerTask() { rtTimer!!.scheduleAtFixedRate(object : TimerTask() {
override fun run() { override fun run() {
if (!rt.isPlaying()) { if (!rt.isPlaying) {
rt.play() rt.play()
} }
} }
@@ -1031,7 +1030,7 @@ class BaresipService: Service() {
private fun stopRinging() { private fun stopRinging() {
if (am.mode == AudioManager.MODE_RINGTONE) { if (am.mode == AudioManager.MODE_RINGTONE) {
if ((Build.VERSION.SDK_INT < 28) && (rtTimer != null)) { if ((VERSION.SDK_INT < 28) && (rtTimer != null)) {
rtTimer!!.cancel() rtTimer!!.cancel()
rtTimer = null rtTimer = null
} }
@@ -1065,14 +1064,14 @@ class BaresipService: Service() {
private fun proximitySensing(enable: Boolean) { private fun proximitySensing(enable: Boolean) {
if (enable) { if (enable) {
if (!proximityWakeLock.isHeld()) { if (!proximityWakeLock.isHeld) {
Log.d(LOG_TAG, "Acquiring proximity wake lock") Log.d(LOG_TAG, "Acquiring proximity wake lock")
proximityWakeLock.acquire() proximityWakeLock.acquire()
} else { } else {
Log.d(LOG_TAG, "Proximity wake lock already acquired") Log.d(LOG_TAG, "Proximity wake lock already acquired")
} }
} else { } else {
if (proximityWakeLock.isHeld()) { if (proximityWakeLock.isHeld) {
proximityWakeLock.release() proximityWakeLock.release()
Log.d(LOG_TAG, "Released proximity wake lock") Log.d(LOG_TAG, "Released proximity wake lock")
} else { } else {
@@ -1138,7 +1137,7 @@ class BaresipService: Service() {
} }
private fun isNetworkActive(network: Network): Boolean { private fun isNetworkActive(network: Network): Boolean {
if (Build.VERSION.SDK_INT >= 23) if (VERSION.SDK_INT >= 23)
return network == cm.activeNetwork return network == cm.activeNetwork
if ((cm.activeNetworkInfo != null) && (cm.getNetworkInfo(network) != null)) if ((cm.activeNetworkInfo != null) && (cm.getNetworkInfo(network) != null))
return cm.activeNetworkInfo!!.toString() == cm.getNetworkInfo(network)!!.toString() return cm.activeNetworkInfo!!.toString() == cm.getNetworkInfo(network)!!.toString()
@@ -1207,7 +1206,7 @@ class BaresipService: Service() {
var callHistory = ArrayList<CallHistory>() var callHistory = ArrayList<CallHistory>()
var messages = ArrayList<Message>() var messages = ArrayList<Message>()
val contacts = ArrayList<Contact>() val contacts = ArrayList<Contact>()
val chatTexts: MutableMap<String, String> = mutableMapOf<String, String>() val chatTexts: MutableMap<String, String> = mutableMapOf()
val activities = mutableListOf<String>() val activities = mutableListOf<String>()
var linkAddresses = listOf<LinkAddress>() var linkAddresses = listOf<LinkAddress>()
var dnsServers = listOf<InetAddress>() var dnsServers = listOf<InetAddress>()
@@ -9,7 +9,6 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.provider.Settings.Global.getString
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
@@ -28,10 +28,6 @@ class Call(val callp: String, val ua: UserAgent, val peerUri: String, val dir: S
call_start_audio(callp) call_start_audio(callp)
} }
fun stopAudio() {
call_stop_audio(callp)
}
fun hold(): Int { fun hold(): Int {
return call_hold(callp) return call_hold(callp)
} }
@@ -53,10 +49,6 @@ class Call(val callp: String, val ua: UserAgent, val peerUri: String, val dir: S
call_notify_sipfrag(callp, code, reason) call_notify_sipfrag(callp, code, reason)
} }
fun hasVideo(): Boolean {
return call_has_video(callp)
}
fun status(): String { fun status(): String {
return call_status(callp) return call_status(callp)
} }
@@ -128,11 +128,11 @@ class ChatActivity : AppCompatActivity() {
} }
newMessage = binding.text newMessage = binding.text
newMessage.setOnFocusChangeListener(View.OnFocusChangeListener { _, hasFocus -> newMessage.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->
if (hasFocus) { if (hasFocus) {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
} }
}) }
if (focus) newMessage.requestFocus() if (focus) newMessage.requestFocus()
@@ -147,7 +147,7 @@ class ChatActivity : AppCompatActivity() {
msg.add() msg.add()
chatMessages.add(msg) chatMessages.add(msg)
if (Api.message_send(ua.uap, peerUri, msgText, time.toString()) != 0) { if (Api.message_send(ua.uap, peerUri, msgText, time.toString()) != 0) {
Toast.makeText(getApplicationContext(), "${getString(R.string.message_failed)}!", Toast.makeText(applicationContext, "${getString(R.string.message_failed)}!",
Toast.LENGTH_SHORT).show() Toast.LENGTH_SHORT).show()
msg.direction = R.drawable.arrow_up_red msg.direction = R.drawable.arrow_up_red
msg.responseReason = getString(R.string.message_failed) msg.responseReason = getString(R.string.message_failed)
@@ -216,8 +216,8 @@ class ChatActivity : AppCompatActivity() {
if (SystemClock.elapsedRealtime() - lastCall > 1000) { if (SystemClock.elapsedRealtime() - lastCall > 1000) {
lastCall = SystemClock.elapsedRealtime() lastCall = SystemClock.elapsedRealtime()
val intent = Intent(this, MainActivity::class.java) val intent = Intent(this, MainActivity::class.java)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
intent.putExtra("action", "call") intent.putExtra("action", "call")
intent.putExtra("uap", ua.uap) intent.putExtra("uap", ua.uap)
intent.putExtra("peer", peerUri) intent.putExtra("peer", peerUri)
@@ -73,7 +73,7 @@ class ChatListAdapter(private val ctx: Context, private var rows: ArrayList<Mess
else else
viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg) viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg)
viewHolder.peerView.setText(peer) viewHolder.peerView.text = peer
val cal = GregorianCalendar() val cal = GregorianCalendar()
cal.timeInMillis = message.timeStamp cal.timeInMillis = message.timeStamp
@@ -55,7 +55,7 @@ class CodecsActivity : AppCompatActivity() {
while (newCodecs.size < codecs.size) newCodecs.add("-") while (newCodecs.size < codecs.size) newCodecs.add("-")
val layout = binding.SpinnerTable val layout = binding.SpinnerTable
val spinnerList = Array(codecs.size, {_ -> ArrayList<String>()}) val spinnerList = Array(codecs.size) { ArrayList<String>() }
for (i in codecs.indices) { for (i in codecs.indices) {
val spinner = Spinner(applicationContext) val spinner = Spinner(applicationContext)
spinner.id = i + 100 spinner.id = i + 100
@@ -72,7 +72,7 @@ class CodecsActivity : AppCompatActivity() {
spinnerList[i].addAll(codecs) spinnerList[i].addAll(codecs)
spinnerList[i].add(0, "-") spinnerList[i].add(0, "-")
} }
val codecSpinner = findViewById(spinner.id) as Spinner val codecSpinner = findViewById<Spinner>(spinner.id)
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item,
spinnerList[i]) spinnerList[i])
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
@@ -96,7 +96,7 @@ class ConfigActivity : AppCompatActivity() {
volVals.removeAt(curVal) volVals.removeAt(curVal)
volKeys.add(0, curKey) volKeys.add(0, curKey)
volVals.add(0, curVal) volVals.add(0, curVal)
val callVolAdapter = ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, val callVolAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item,
volKeys) volKeys)
callVolAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) callVolAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
callVolSpinner.adapter = callVolAdapter callVolSpinner.adapter = callVolAdapter
@@ -102,7 +102,7 @@ class ContactActivity : AppCompatActivity() {
oldAndroid = androidCheck.isChecked oldAndroid = androidCheck.isChecked
textAvatarView.setOnClickListener { _ -> textAvatarView.setOnClickListener {
val intent = Intent(Intent.ACTION_GET_CONTENT).apply { val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
@@ -112,7 +112,7 @@ class ContactActivity : AppCompatActivity() {
} }
textAvatarView.setOnLongClickListener { _ -> textAvatarView.setOnLongClickListener {
color = Utils.randomColor() color = Utils.randomColor()
showTextAvatar(textAvatarView.text.toString(), color) showTextAvatar(textAvatarView.text.toString(), color)
@@ -121,7 +121,7 @@ class ContactActivity : AppCompatActivity() {
} }
cardAvatarView.setOnClickListener { _ -> cardAvatarView.setOnClickListener {
val intent = Intent(Intent.ACTION_GET_CONTENT).apply { val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
@@ -131,7 +131,7 @@ class ContactActivity : AppCompatActivity() {
} }
cardAvatarView.setOnLongClickListener { _ -> cardAvatarView.setOnLongClickListener {
color = Utils.randomColor() color = Utils.randomColor()
showTextAvatar(nameView.text.toString(), color) showTextAvatar(nameView.text.toString(), color)
@@ -533,7 +533,7 @@ class ContactActivity : AppCompatActivity() {
val cur: Cursor? = ctx.contentResolver.query(ContactsContract.Data.CONTENT_URI, projection, val cur: Cursor? = ctx.contentResolver.query(ContactsContract.Data.CONTENT_URI, projection,
selection, null, null) selection, null, null)
while (cur != null && cur.moveToNext()) { while (cur != null && cur.moveToNext()) {
val id = cur.getLong(0); val id = cur.getLong(0)
val name = cur.getString(1) // display name val name = cur.getString(1) // display name
val mime = cur.getString(2) // type of data val mime = cur.getString(2) // type of data
val data = cur.getString(3) // info val data = cur.getString(3) // info
@@ -75,13 +75,13 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
viewHolder.nameView.setPadding(6, 6, 0, 6) viewHolder.nameView.setPadding(6, 6, 0, 6)
if (aor != "") { if (aor != "") {
viewHolder.nameView.setOnClickListener { _ -> viewHolder.nameView.setOnClickListener {
val dialogClickListener = DialogInterface.OnClickListener { _, which -> val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) { when (which) {
DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE -> { DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE -> {
val i = Intent(ctx, MainActivity::class.java) val i = Intent(ctx, MainActivity::class.java)
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or i.flags = Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
if (which == DialogInterface.BUTTON_NEGATIVE) if (which == DialogInterface.BUTTON_NEGATIVE)
i.putExtra("action", "call") i.putExtra("action", "call")
else else
@@ -114,7 +114,7 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
} }
} }
viewHolder.nameView.setOnLongClickListener { _ -> viewHolder.nameView.setOnLongClickListener {
val dialogClickListener = DialogInterface.OnClickListener { _, which -> val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) { when (which) {
DialogInterface.BUTTON_POSITIVE -> { DialogInterface.BUTTON_POSITIVE -> {
@@ -151,7 +151,7 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
true true
} }
viewHolder.actionView.setOnClickListener { _ -> viewHolder.actionView.setOnClickListener {
if (SystemClock.elapsedRealtime() - lastClick > 1000) { if (SystemClock.elapsedRealtime() - lastClick > 1000) {
lastClick = SystemClock.elapsedRealtime() lastClick = SystemClock.elapsedRealtime()
val i = Intent(ctx, ContactActivity::class.java) val i = Intent(ctx, ContactActivity::class.java)
@@ -136,13 +136,13 @@ class MainActivity : AppCompatActivity() {
override fun onFinish() { override fun onFinish() {
when (stopState) { when (stopState) {
"initial" -> { "initial" -> {
baresipService.setAction("Stop Force"); baresipService.action = "Stop Force"
startService(baresipService) startService(baresipService)
stopState = "force" stopState = "force"
quitTimer.start() quitTimer.start()
} }
"force" -> { "force" -> {
baresipService.setAction("Kill"); baresipService.action = "Kill"
startService(baresipService) startService(baresipService)
finishAndRemoveTask() finishAndRemoveTask()
System.exit(0) System.exit(0)
@@ -386,8 +386,8 @@ class MainActivity : AppCompatActivity() {
when (which) { when (which) {
DialogInterface.BUTTON_POSITIVE -> { DialogInterface.BUTTON_POSITIVE -> {
val callIntent = Intent(this, MainActivity::class.java) val callIntent = Intent(this, MainActivity::class.java)
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or callIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
callIntent.putExtra("action", "call") callIntent.putExtra("action", "call")
callIntent.putExtra("uap", ua.uap) callIntent.putExtra("uap", ua.uap)
callIntent.putExtra("peer", acc.vmUri) callIntent.putExtra("peer", acc.vmUri)
@@ -729,7 +729,7 @@ class MainActivity : AppCompatActivity() {
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) { when (keyCode) {
KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP -> { KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_VOLUME_UP -> {
Log.d(TAG, "Adjusting volume $keyCode of stream ${volumeControlStream}") Log.d(TAG, "Adjusting volume $keyCode of stream $volumeControlStream")
am.adjustStreamVolume(volumeControlStream, am.adjustStreamVolume(volumeControlStream,
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
AudioManager.ADJUST_LOWER else AudioManager.ADJUST_LOWER else
@@ -989,7 +989,7 @@ class MainActivity : AppCompatActivity() {
"message", "message show", "message reply" -> { "message", "message show", "message reply" -> {
val peer = params[1] val peer = params[1]
val i = Intent(applicationContext, ChatActivity::class.java) val i = Intent(applicationContext, ChatActivity::class.java)
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) i.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
val b = Bundle() val b = Bundle()
b.putString("aor", aor) b.putString("aor", aor)
b.putString("peer", peer) b.putString("peer", peer)
@@ -1024,7 +1024,7 @@ class MainActivity : AppCompatActivity() {
private fun reStart() { private fun reStart() {
Log.d(TAG, "Trigger restart") Log.d(TAG, "Trigger restart")
val pm = applicationContext.packageManager val pm = applicationContext.packageManager
val intent = pm.getLaunchIntentForPackage(this.getPackageName()) val intent = pm.getLaunchIntentForPackage(this.packageName)
this.finishAffinity() this.finishAffinity()
this.startActivity(intent) this.startActivity(intent)
System.exit(0) System.exit(0)
@@ -1116,7 +1116,7 @@ class MainActivity : AppCompatActivity() {
if (aorSpinner.tag != "") if (aorSpinner.tag != "")
updateIcons(Account.ofAor(aorSpinner.tag.toString())!!) updateIcons(Account.ofAor(aorSpinner.tag.toString())!!)
if (BaresipService.isServiceRunning) { if (BaresipService.isServiceRunning) {
baresipService.setAction("UpdateNotification") baresipService.action = "UpdateNotification"
startService(baresipService) startService(baresipService)
} }
} }
@@ -1205,7 +1205,7 @@ class MainActivity : AppCompatActivity() {
Log.d(TAG, "quitRestart Restart = $reStart") Log.d(TAG, "quitRestart Restart = $reStart")
if (BaresipService.isServiceRunning) { if (BaresipService.isServiceRunning) {
restart = reStart restart = reStart
baresipService.setAction("Stop"); baresipService.action = "Stop"
startService(baresipService) startService(baresipService)
quitTimer.start() quitTimer.start()
} else { } else {
@@ -1379,7 +1379,7 @@ class MainActivity : AppCompatActivity() {
} }
private fun startBaresip() { private fun startBaresip() {
baresipService.setAction("Start") baresipService.action = "Start"
startService(baresipService) startService(baresipService)
if (atStartup) if (atStartup)
moveTaskToBack(true) moveTaskToBack(true)
@@ -5,7 +5,6 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import android.widget.ImageButton
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
@@ -270,7 +270,7 @@ object Utils {
var servers = "" var servers = ""
for (dnsServer in list) { for (dnsServer in list) {
var address = dnsServer.hostAddress.removePrefix("/") var address = dnsServer.hostAddress.removePrefix("/")
if (Utils.checkIpV4(address)) if (checkIpV4(address))
address = "${address}:53" address = "${address}:53"
else else
address = "[${address}]:53" address = "[${address}]:53"
@@ -518,7 +518,7 @@ object Utils {
fun decryptFromFile(filePath: String, password: String): ByteArray? { fun decryptFromFile(filePath: String, password: String): ByteArray? {
var plainData: ByteArray? = null var plainData: ByteArray? = null
try { try {
ObjectInputStream(FileInputStream(File(filePath))).use { it -> ObjectInputStream(FileInputStream(File(filePath))).use {
val obj = it.readObject() as Crypto val obj = it.readObject() as Crypto
plainData = decrypt(obj, password.toCharArray()) plainData = decrypt(obj, password.toCharArray())
} }
@@ -577,7 +577,7 @@ object Utils {
return false return false
} }
(allFiles - zipFiles).iterator().forEach { (allFiles - zipFiles).iterator().forEach {
deleteFile(File(BaresipService.filesPath, "$it")) deleteFile(File(BaresipService.filesPath, it))
} }
return true return true
} }
@@ -589,7 +589,7 @@ object Utils {
Log.d("Baresip", "Dumping intent start") Log.d("Baresip", "Dumping intent start")
while (it.hasNext()) { while (it.hasNext()) {
val key = it.next() val key = it.next()
Log.d("Baresip","[" + key + "=" + bundle.get(key)+"]"); Log.d("Baresip", "[" + key + "=" + bundle.get(key) + "]")
} }
Log.d("Baresip", "Dumping intent finish") Log.d("Baresip", "Dumping intent finish")
} }
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

@@ -1,66 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="vertical" >
<LinearLayout
android:id="@+id/mainRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
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="#000000"
android:text="@string/app_name"
style = "@android:style/TextAppearance.Medium" />
</LinearLayout>
<TextView android:id="@+id/callFrom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/mainRow"
android:layout_marginTop="10dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="10dp"
android:textSize="15sp"
style = "@android:style/TextAppearance.Medium" />
<Button android:id="@+id/answerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/callFrom"
android:layout_marginTop="10dp"
android:layout_marginBottom="14dp"
android:layout_marginStart="16dp"
android:layout_gravity="center"
android:text="@string/answer" />
<Button android:id="@+id/rejectButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/callFrom"
android:layout_toEndOf="@id/answerButton"
android:layout_marginTop="10dp"
android:layout_marginBottom="14dp"
android:layout_marginStart="20dp"
android:layout_gravity="center"
android:text="@string/reject" />
</RelativeLayout>
-3
View File
@@ -1,7 +1,4 @@
<resources> <resources>
<dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="textsize">12sp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="button_width">96dp</dimen>
</resources> </resources>
-3
View File
@@ -91,9 +91,6 @@
</ul> </ul>
]]> ]]>
</string> </string>
<string name="baresip_link" translatable="false">
<a href="https://github.com/juha-h/baresip-studio">GitHub</a>
</string>
<!-- Account Activity --> <!-- Account Activity -->
<string name="account">Account</string> <string name="account">Account</string>
<string name="display_name">Display Name</string> <string name="display_name">Display Name</string>