Skip to content

Commit 09a487c

Browse files
masonqiaoAbySwifter
authored andcommitted
【TUIRoomKit】【Android】publish beta version 4.0.3
1 parent 6f31f01 commit 09a487c

179 files changed

Lines changed: 6853 additions & 857 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

application/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ext {
2626
targetSdkVersion = 34
2727
liteavSdk = "com.tencent.liteav:LiteAVSDK_Professional:13.0.0.19676"
2828
roomEngineSdk = buildEngineSource.toBoolean() ? project(":engine_source") : "io.trtc.uikit:rtc_room_engine:3.6.1.76"
29-
atomicxCoreSdk = buildAtomicxCoreSource.toBoolean() ? project(":atomicxcore") : "io.trtc.uikit:atomicx-core:4.0.0.110"
29+
atomicxCoreSdk = buildAtomicxCoreSource.toBoolean() ? project(":atomicxcore") : "io.trtc.uikit:atomicx-core:4.0.3.44"
3030
imSdk = "com.tencent.imsdk:imsdk-plus:8.7.7201"
3131
common = "io.trtc.uikit:common:3.5.0.1332"
3232
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.trtc.tuikit.atomicx.common
2+
3+
import android.graphics.Color
4+
import android.os.Build
5+
import android.os.Bundle
6+
import android.view.View
7+
import android.view.WindowManager
8+
import androidx.appcompat.app.AppCompatActivity
9+
10+
open class FullScreenActivity : AppCompatActivity() {
11+
12+
override fun onCreate(savedInstanceState: Bundle?) {
13+
super.onCreate(savedInstanceState)
14+
initStatusBar()
15+
}
16+
17+
private fun initStatusBar() {
18+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
19+
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
20+
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
21+
or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
22+
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
23+
window.statusBarColor = Color.TRANSPARENT
24+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
25+
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
26+
}
27+
}
28+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package io.trtc.tuikit.atomicx.common.event
2+
3+
import android.text.TextUtils
4+
import android.util.Log
5+
import java.util.concurrent.ConcurrentHashMap
6+
import java.util.concurrent.CopyOnWriteArrayList
7+
8+
/**
9+
* Notification registration, removal and triggering
10+
*/
11+
class EventManager private constructor() {
12+
private val eventMap: MutableMap<Pair<String, String>, MutableList<INotification>> = ConcurrentHashMap()
13+
14+
companion object {
15+
private const val TAG = "EventManager"
16+
17+
@JvmStatic
18+
val instance: EventManager by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
19+
EventManager()
20+
}
21+
}
22+
23+
fun registerEvent(key: String?, subKey: String?, notification: INotification?) {
24+
Log.i(TAG, "registerEvent : key : $key, subKey : $subKey, notification : $notification")
25+
if (key.isNullOrEmpty() || subKey.isNullOrEmpty() || notification == null) {
26+
return
27+
}
28+
val keyPair = Pair(key, subKey)
29+
var list = eventMap[keyPair]
30+
if (list == null) {
31+
list = CopyOnWriteArrayList()
32+
eventMap[keyPair] = list
33+
}
34+
if (!list.contains(notification)) {
35+
list.add(notification)
36+
}
37+
}
38+
39+
fun unRegisterEvent(key: String?, subKey: String?, notification: INotification?) {
40+
Log.i(TAG, "removeEvent : key : $key, subKey : $subKey notification : $notification")
41+
if (key.isNullOrEmpty() || subKey.isNullOrEmpty() || notification == null) {
42+
return
43+
}
44+
val keyPair = Pair(key, subKey)
45+
val list = eventMap[keyPair] ?: return
46+
list.remove(notification)
47+
}
48+
49+
fun unRegisterEvent(notification: INotification?) {
50+
Log.i(TAG, "removeEvent : notification : $notification")
51+
if (notification == null) {
52+
return
53+
}
54+
eventMap.values.forEach { it.removeAll { item -> item === notification } }
55+
}
56+
57+
fun notifyEvent(key: String?, subKey: String?, param: Map<String, Any?>?) {
58+
Log.d(TAG, "notifyEvent : key : $key, subKey : $subKey")
59+
if (TextUtils.isEmpty(key) || TextUtils.isEmpty(subKey)) {
60+
return
61+
}
62+
val keyPair = Pair(key!!, subKey!!)
63+
val notificationList = eventMap[keyPair]
64+
notificationList?.forEach { notification ->
65+
notification.onNotifyEvent(key, subKey, param)
66+
}
67+
}
68+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.trtc.tuikit.atomicx.common.event
2+
3+
fun interface INotification {
4+
fun onNotifyEvent(key: String, subKey: String, param: Map<String, Any?>?)
5+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.trtc.tuikit.atomicx.common.foregroundservice
2+
3+
import android.Manifest
4+
import android.content.Context
5+
import android.content.pm.PackageManager
6+
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
7+
import androidx.core.content.ContextCompat
8+
import io.trtc.tuikit.atomicx.common.foregroundservice.base.BaseForegroundService
9+
import io.trtc.tuikit.atomicx.common.foregroundservice.base.ServiceLauncher
10+
11+
class AudioForegroundService : BaseForegroundService(launcher) {
12+
13+
override fun provideForegroundServiceType() = FOREGROUND_SERVICE_TYPE_MICROPHONE
14+
15+
override fun provideChannelId() = "rtc_uikit_audio_foreground_service"
16+
17+
companion object {
18+
internal val launcher =
19+
ServiceLauncher(AudioForegroundService::class.java, "AudioForegroundService")
20+
21+
@JvmStatic
22+
fun start(context: Context, title: String?, description: String?, icon: Int) {
23+
launcher.start(context, title, description, icon) {
24+
ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED
25+
}
26+
}
27+
28+
@JvmStatic
29+
fun stop(context: Context) = launcher.stop(context)
30+
}
31+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.trtc.tuikit.atomicx.common.foregroundservice
2+
3+
import android.content.Context
4+
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
5+
import io.trtc.tuikit.atomicx.common.foregroundservice.base.BaseForegroundService
6+
import io.trtc.tuikit.atomicx.common.foregroundservice.base.ServiceLauncher
7+
8+
class MediaForegroundService : BaseForegroundService(launcher) {
9+
10+
override fun provideForegroundServiceType() = FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
11+
12+
override fun provideChannelId() = "rtc_uikit_media_foreground_service"
13+
14+
companion object {
15+
internal val launcher =
16+
ServiceLauncher(MediaForegroundService::class.java, "MediaForegroundService")
17+
18+
@JvmStatic
19+
fun start(context: Context, title: String?, description: String?, icon: Int) {
20+
launcher.start(context, title, description, icon) { true }
21+
}
22+
23+
@JvmStatic
24+
fun stop(context: Context) = launcher.stop(context)
25+
}
26+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.trtc.tuikit.atomicx.common.foregroundservice
2+
3+
import android.Manifest
4+
import android.content.Context
5+
import android.content.pm.PackageManager
6+
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA
7+
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
8+
import android.os.Build
9+
import androidx.core.content.ContextCompat
10+
import io.trtc.tuikit.atomicx.common.foregroundservice.base.BaseForegroundService
11+
import io.trtc.tuikit.atomicx.common.foregroundservice.base.ServiceLauncher
12+
13+
class VideoForegroundService : BaseForegroundService(launcher) {
14+
15+
override fun provideForegroundServiceType(): Int {
16+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
17+
FOREGROUND_SERVICE_TYPE_MICROPHONE or FOREGROUND_SERVICE_TYPE_CAMERA
18+
} else 0
19+
}
20+
21+
override fun provideChannelId() = "rtc_uikit_video_foreground_service"
22+
23+
companion object {
24+
internal val launcher =
25+
ServiceLauncher(VideoForegroundService::class.java, "VideoForegroundService")
26+
27+
@JvmStatic
28+
fun start(context: Context, title: String?, description: String?, icon: Int) {
29+
launcher.start(context, title, description, icon) {
30+
val hasCameraPermission =
31+
ContextCompat.checkSelfPermission(
32+
context,
33+
Manifest.permission.CAMERA
34+
) == PackageManager.PERMISSION_GRANTED
35+
val hasAudioPermission =
36+
ContextCompat.checkSelfPermission(
37+
context,
38+
Manifest.permission.RECORD_AUDIO
39+
) == PackageManager.PERMISSION_GRANTED
40+
hasCameraPermission && hasAudioPermission
41+
}
42+
}
43+
44+
@JvmStatic
45+
fun stop(context: Context) = launcher.stop(context)
46+
}
47+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package io.trtc.tuikit.atomicx.common.foregroundservice.base
2+
3+
import android.app.Notification
4+
import android.app.NotificationChannel
5+
import android.app.NotificationManager
6+
import android.app.Service
7+
import android.content.Intent
8+
import android.os.Build
9+
import android.os.IBinder
10+
import androidx.core.app.NotificationCompat
11+
import com.tencent.cloud.tuikit.engine.common.ContextProvider
12+
import io.trtc.tuikit.atomicx.R
13+
import io.trtc.tuikit.atomicx.common.util.TUIBuild
14+
15+
abstract class BaseForegroundService(
16+
private val launcher: ServiceLauncher<*>
17+
) : Service() {
18+
19+
companion object {
20+
const val TITLE = "title"
21+
const val ICON = "icon"
22+
const val DESCRIPTION = "description"
23+
const val NOTIFICATION_ID = 1001
24+
}
25+
26+
abstract fun provideForegroundServiceType(): Int
27+
28+
abstract fun provideChannelId(): String
29+
30+
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
31+
if (intent == null) return START_NOT_STICKY
32+
33+
val appContext = ContextProvider.getApplicationContext()
34+
val title = intent.getStringExtra(TITLE)
35+
val description = intent.getStringExtra(DESCRIPTION)
36+
val icon = intent.getIntExtra(ICON, appContext?.applicationInfo?.icon ?: 0)
37+
38+
val notification = createNotification(title, description, icon)
39+
40+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
41+
startForeground(NOTIFICATION_ID, notification, provideForegroundServiceType())
42+
} else {
43+
startForeground(NOTIFICATION_ID, notification)
44+
}
45+
46+
if (launcher.state == ServiceState.STOPPING) {
47+
stopSelf()
48+
launcher.updateState(ServiceState.IDLE)
49+
} else {
50+
launcher.updateState(ServiceState.RUNNING)
51+
}
52+
return START_NOT_STICKY
53+
}
54+
55+
override fun onBind(intent: Intent?): IBinder? = null
56+
57+
override fun onTaskRemoved(rootIntent: Intent?) {
58+
super.onTaskRemoved(rootIntent)
59+
stopSelf()
60+
launcher.updateState(ServiceState.IDLE)
61+
}
62+
63+
override fun onDestroy() {
64+
super.onDestroy()
65+
clearNotification()
66+
}
67+
68+
private fun createNotification(title: String?, desc: String?, icon: Int): Notification {
69+
val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
70+
val channelId = provideChannelId()
71+
if (TUIBuild.getVersionInt() >= Build.VERSION_CODES.O) {
72+
val channel = NotificationChannel(
73+
channelId,
74+
applicationContext.getString(R.string.common_rtc_channel_name),
75+
NotificationManager.IMPORTANCE_LOW
76+
)
77+
manager.createNotificationChannel(channel)
78+
}
79+
return NotificationCompat.Builder(this, channelId)
80+
.setSmallIcon(icon)
81+
.setContentTitle(title)
82+
.setContentText(desc)
83+
.build()
84+
}
85+
86+
private fun clearNotification() {
87+
val manager = getSystemService(NOTIFICATION_SERVICE) as? NotificationManager
88+
manager?.cancel(NOTIFICATION_ID)
89+
}
90+
}

0 commit comments

Comments
 (0)