Skip to content

Commit

Permalink
[Android][TUICallKit]fix some UI experience issues
Browse files Browse the repository at this point in the history
  • Loading branch information
reneechai authored and MinTate committed May 10, 2024
1 parent 6a4f7dd commit 605c017
Show file tree
Hide file tree
Showing 36 changed files with 215 additions and 121 deletions.
6 changes: 0 additions & 6 deletions Android/app/mcs-services.json

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public void onSuccess() {
Log.i(TAG, "login onSuccess");
SettingsConfig.userId = userId;
getUserInfo(userId);
TUICallKit.createInstance(getApplication()).enableFloatWindow(SettingsConfig.isShowFloatingWindow);
TUICallKit.createInstance(getApplication()).enableVirtualBackground(SettingsConfig.isShowBlurBackground);
TUICallKit.createInstance(getApplication()).enableIncomingBanner(SettingsConfig.isIncomingBanner);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class SettingsActivity extends BaseActivity {
private SwitchCompat mSwitchMute;
private SwitchCompat mSwitchFloating;
private SwitchCompat mSwitchBlurBackground;
private SwitchCompat mSwitchIncomingBanner;
private EditText mEditDigitalRoomId;
private EditText mEditStringRoomId;
private EditText mEditTimeout;
Expand Down Expand Up @@ -65,6 +66,7 @@ private void initView() {
mSwitchMute = findViewById(R.id.switch_mute);
mSwitchFloating = findViewById(R.id.switch_floating);
mSwitchBlurBackground = findViewById(R.id.switch_blur_background);
mSwitchIncomingBanner = findViewById(R.id.switch_incoming_banner);

mEditDigitalRoomId = findViewById(R.id.et_room_id_num);
mEditStringRoomId = findViewById(R.id.et_room_id_str);
Expand Down Expand Up @@ -112,6 +114,10 @@ private void initView() {
SettingsConfig.isShowBlurBackground = isChecked;
TUICallKit.createInstance(getApplicationContext()).enableVirtualBackground(isChecked);
});
mSwitchIncomingBanner.setOnCheckedChangeListener((buttonView, isChecked) -> {
SettingsConfig.isIncomingBanner = isChecked;
TUICallKit.createInstance(getApplication()).enableIncomingBanner(isChecked);
});

mEditDigitalRoomId.setOnEditorActionListener((v, actionId, event) -> {
if (EditorInfo.IME_ACTION_DONE == actionId) {
Expand Down Expand Up @@ -211,6 +217,7 @@ private void initData() {
mSwitchMute.setChecked(SettingsConfig.isMute);
mSwitchFloating.setChecked(SettingsConfig.isShowFloatingWindow);
mSwitchBlurBackground.setChecked(SettingsConfig.isShowBlurBackground);
mSwitchIncomingBanner.setChecked(SettingsConfig.isIncomingBanner);

mEditDigitalRoomId.setText("" + SettingsConfig.intRoomId);
mEditStringRoomId.setText("" + SettingsConfig.strRoomId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public class SettingsConfig {
public static String ringPath =
SPUtils.getInstance(CallingBellFeature.PROFILE_TUICALLKIT).getString(CallingBellFeature.PROFILE_CALL_BELL);
public static boolean isMute = false;
public static boolean isShowFloatingWindow = false;
public static boolean isShowFloatingWindow = true;
public static boolean isShowBlurBackground = true;
public static boolean isIncomingBanner = true;
public static int intRoomId = 0;
public static String strRoomId = "";
public static int callTimeOut = 30;
Expand Down
2 changes: 1 addition & 1 deletion Android/app/src/main/res/layout/app_activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="151dp"
android:layout_marginTop="171dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
Expand Down
32 changes: 32 additions & 0 deletions Android/app/src/main/res/layout/app_activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,38 @@
app:trackTint="#FF999999" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="20dp"
android:layout_marginRight="16dp"
android:gravity="center_vertical"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_incoming_banner"
android:textColor="#000000"
android:textSize="16sp" />

<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch_incoming_banner"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:checked="true"
app:switchMinWidth="50dp"
app:thumbTint="@color/app_switch_selector"
app:thumbTintMode="multiply"
app:trackTint="#FF999999" />
</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
Expand Down
1 change: 1 addition & 0 deletions Android/app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="app_call_setting">Call Settings</string>
<string name="app_show_float_button">Show floating</string>
<string name="app_blur_background">Show blur background</string>
<string name="app_incoming_banner">Show incoming banner</string>
<string name="app_call_params_setting">Call Parameters</string>
<string name="app_please_set_call_waiting_timeout">Please set call waiting timeout</string>
<string name="app_user_data">Extended</string>
Expand Down
1 change: 1 addition & 0 deletions Android/app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<string name="app_call_setting">通話設定</string>
<string name="app_show_float_button">フローティングウィンドウの表示</string>
<string name="app_blur_background">背景をぼかす</string>
<string name="app_incoming_banner">着信表示バナー</string>
<string name="app_call_params_setting">通話パラメータの設定</string>
<string name="app_please_set_call_waiting_timeout">コールウェイティングのタイムアウト時間を設定してください</string>
<string name="app_user_data">拡張情報</string>
Expand Down
1 change: 1 addition & 0 deletions Android/app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<string name="app_call_setting">通话设置</string>
<string name="app_show_float_button">显示悬浮窗按钮</string>
<string name="app_blur_background">显示模糊背景按钮</string>
<string name="app_incoming_banner">显示来电横幅</string>
<string name="app_call_params_setting">通话自定义参数设置</string>
<string name="app_please_set_call_waiting_timeout">请设置呼叫等待超时时间</string>
<string name="app_user_data">扩展信息</string>
Expand Down
1 change: 1 addition & 0 deletions Android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="app_call_setting">Call Settings</string>
<string name="app_show_float_button">Show floating</string>
<string name="app_blur_background">Show blur background</string>
<string name="app_incoming_banner">Show incoming banner</string>
<string name="app_call_params_setting">Call Parameters</string>
<string name="app_please_set_call_waiting_timeout">Please set call waiting timeout</string>
<string name="app_user_data">Extended</string>
Expand Down
1 change: 0 additions & 1 deletion Android/tuicallkit-kt/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="accept_call_action" />
<action android:name="reject_call_action" />
</intent-filter>
</receiver>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,10 @@ abstract class TUICallKit {
* Enable Virtual Background
*/
open fun enableVirtualBackground(enable: Boolean) {}

/**
* Enable callee show banner view when received an new invitation
* default: false
*/
open fun enableIncomingBanner(enable: Boolean) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,15 @@ class TUICallKitImpl private constructor(context: Context) : TUICallKit(), ITUIN
TUICallState.instance.showVirtualBackgroundButton = enable

val data = HashMap<String, Any>()
data["enablevirtualbackground"] = enable
data[Constants.KEY_VIRTUAL_BACKGROUND] = enable
EngineManager.instance.reportOnlineLog(data)
}

override fun enableIncomingBanner(enable: Boolean) {
TUILog.i(TAG, "TUICallKit enableIncomingBanner{enable:${enable}")
TUICallState.instance.enableIncomingBanner = enable
}

fun queryOfflineCall() {
TUILog.i(TAG, "queryOfflineCall start")
if (TUICallDefine.Status.Accept != TUICallState.instance.selfUser.get().callStatus.get()) {
Expand Down Expand Up @@ -253,24 +258,39 @@ class TUICallKitImpl private constructor(context: Context) : TUICallKit(), ITUIN
val hasBgPermission = PermissionRequester.newInstance(PermissionRequester.BG_START_PERMISSION).has()
val hasNotificationPermission = PermissionRequest.isNotificationEnabled()

val innerNotification = isShowInnerNotification()
val isFCMData = isFCMDataNotification()

TUILog.i(
TAG_VIEW, "handleNewCall, isAppInBackground: $isAppInBackground, floatPermission: $hasFloatPermission" +
", backgroundStartPermission: $hasBgPermission, notificationPermission: $hasNotificationPermission , " +
"showNotification: $innerNotification"
"isFCMDataNotification: $isFCMData, enableIncomingBanner:${TUICallState.instance.enableIncomingBanner}"
)

if (DeviceUtils.isScreenLocked(context)) {
TUILog.i(TAG_VIEW, "handleNewCall, screen is locked, try to pop up call full screen view")
startFullScreenView()
return@post
}

if (!TUICallState.instance.enableIncomingBanner) {
if (isAppInBackground) {
when {
isFCMData && hasFloatPermission -> startSmallScreenView(IncomingFloatView(context))
isFCMData && hasNotificationPermission -> startSmallScreenView(IncomingNotificationView(context))
else -> startFullScreenView()
}
} else {
startFullScreenView()
}

return@post
}

if (isAppInBackground) {
when {
hasFloatPermission -> startSmallScreenView(IncomingFloatView(context))
innerNotification && hasNotificationPermission -> startSmallScreenView(
IncomingNotificationView(context)
)

hasBgPermission -> startFullScreenView()
else -> {
//do nothing, wait user click desktop icon
}
isFCMData && hasNotificationPermission -> startSmallScreenView(IncomingNotificationView(context))
else -> startFullScreenView()
}
return@post
}
Expand All @@ -283,15 +303,11 @@ class TUICallKitImpl private constructor(context: Context) : TUICallKit(), ITUIN
}
}

private fun isShowInnerNotification(): Boolean {
if (TUICore.getService(TUIConstants.TIMPush.SERVICE_NAME) == null) {
return true
}

private fun isFCMDataNotification(): Boolean {
val pushBrandId =
TUICore.callService(TUIConstants.TIMPush.SERVICE_NAME, TUIConstants.TIMPush.METHOD_GET_PUSH_BRAND_ID, null)

return pushBrandId == TUIConstants.DeviceInfo.BRAND_GOOGLE_ELSE
return TUICore.getService(TUIConstants.TIMPush.SERVICE_NAME) != null
&& pushBrandId == TUIConstants.DeviceInfo.BRAND_GOOGLE_ELSE
}

private fun startFullScreenView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ object Constants {

const val ACCEPT_CALL_ACTION = "accept_call_action"
const val REJECT_CALL_ACTION = "reject_call_action"

const val KEY_VIRTUAL_BACKGROUND = "enablevirtualbackground"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.tencent.qcloud.tuikit.tuicallkit.extensions

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationChannelGroup
import android.app.NotificationManager
import android.app.Service
import android.content.Context
Expand Down Expand Up @@ -48,9 +49,16 @@ class TUICallService : Service() {
val notificationChannelId = "notification_channel_id_01"
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channelName = "Call Foreground Service Notification"
val groupID = "CallGroupId"
val groupName = "CallGroup"

val channelGroup = NotificationChannelGroup(groupID, groupName)
notificationManager.createNotificationChannelGroup(channelGroup)

val notificationChannel = NotificationChannel(
notificationChannelId, channelName, NotificationManager.IMPORTANCE_LOW
)
notificationChannel.group = groupID
notificationChannel.description = "Channel description"
notificationManager?.createNotificationChannel(notificationChannel)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TUICallState {

public var enableMuteMode = false
public var enableFloatWindow = false
public var enableIncomingBanner = false
public var showVirtualBackgroundButton = false
public var enableBlurBackground = LiveData<Boolean>()
public var reverse1v1CallRenderView = false
Expand Down Expand Up @@ -427,6 +428,9 @@ class TUICallState {
user = User()
user.id = userId
}
if (selfUser.get().callStatus.get() != TUICallDefine.Status.Accept) {
selfUser.get().callStatus.set(TUICallDefine.Status.Accept)
}
user.callStatus.set(TUICallDefine.Status.Accept)
if (!remoteUserList.get().contains(user) && !userId.equals(selfUser.get().id)) {
remoteUserList.add(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.tencent.qcloud.tuikit.tuicallkit.utils

import android.app.ActivityManager
import android.content.Context
import android.os.Build
import android.os.PowerManager
import android.text.TextUtils
import android.view.Window
import android.view.WindowManager
import com.tencent.qcloud.tuicore.util.TUIBuild

object DeviceUtils {
fun setScreenLockParams(window: Window?) {
Expand All @@ -30,6 +32,15 @@ object DeviceUtils {
}
}

fun isScreenLocked(context: Context): Boolean {
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
return if (TUIBuild.getVersionInt() >= Build.VERSION_CODES.KITKAT_WATCH) {
!powerManager.isInteractive
} else {
false
}
}

fun isServiceRunning(context: Context?, className: String): Boolean {
if (context == null || TextUtils.isEmpty(className)) {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ package com.tencent.qcloud.tuikit.tuicallkit.utils

import android.content.Context
import android.content.res.Resources
import android.graphics.*
import android.graphics.Bitmap
import android.graphics.BitmapShader
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.graphics.RenderEffect
import android.graphics.Shader
import android.graphics.drawable.Drawable
import android.os.Build
import android.widget.ImageView
Expand Down Expand Up @@ -49,15 +56,15 @@ object ImageLoader {
Glide.with(context!!.applicationContext).asGif().load(resourceId).into(imageView!!)
}

fun loadBlurImage(context: Context?, imageView: ImageView?, url: Any?) {
fun loadBlurImage(context: Context?, imageView: ImageView?, url: Any?, radius: Float = 80f) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
loadImage(context, imageView, url, R.drawable.tuicallkit_ic_avatar)
val radius = 80f
imageView?.setRenderEffect(RenderEffect.createBlurEffect(radius, radius, Shader.TileMode.MIRROR))
} else {
Glide.with(context!!.applicationContext).load(url).error(R.drawable.tuicallkit_ic_avatar)
.apply(RequestOptions.bitmapTransform(BlurTransformation(context))).into(imageView!!)
}
imageView?.setColorFilter(Color.parseColor("#8022262E"))
}

@JvmStatic
Expand Down
Loading

0 comments on commit 605c017

Please sign in to comment.