From d43181a2911ba7ceb23e0bc52f7b68310e0ac737 Mon Sep 17 00:00:00 2001 From: rulongzhang Date: Tue, 29 Aug 2023 11:15:13 +0800 Subject: [PATCH] [Android] update version to release release-11.4.13189 --- Android/.gitignore | 2 - .../tencent/liteav/demo/LoginActivity.java | 1 - .../com/tencent/liteav/demo/MainActivity.java | 6 +- Android/build.gradle | 12 ++- Android/gradle.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- Android/tuivoiceroom/build.gradle | 12 +-- .../com/tencent/liteav/basic/IntentUtils.java | 2 +- .../liteav/basic/OnSingleClickListener.java | 23 +++++ .../tencent/liteav/basic/PictureUtils.java | 59 ++++++++++++ .../com/tencent/liteav/basic/RTCubeUtils.java | 32 +++++++ .../tencent/liteav/basic/ResourceUtils.java | 72 +++++++++++++++ .../liteav/basic/UserModelManager.java | 8 +- .../model/impl/TRTCVoiceRoomImpl.java | 2 +- .../model/impl/room/impl/TXRoomService.java | 13 ++- .../ui/room/VoiceRoomAnchorActivity.java | 31 ++++--- .../ui/room/VoiceRoomAudienceActivity.java | 50 ++++++----- .../ui/room/VoiceRoomBaseActivity.java | 19 ++-- .../ui/room/VoiceRoomCreateDialog.java | 10 ++- .../ui/utils/PermissionHelper.java | 89 ------------------- .../src/main/res/values-en/strings.xml | 4 +- .../src/main/res/values-zh/strings.xml | 4 +- .../src/main/res/values/strings.xml | 4 +- 23 files changed, 291 insertions(+), 168 deletions(-) create mode 100644 Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/OnSingleClickListener.java create mode 100644 Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/PictureUtils.java create mode 100644 Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/ResourceUtils.java delete mode 100644 Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/utils/PermissionHelper.java diff --git a/Android/.gitignore b/Android/.gitignore index 95ebc68..13cc99f 100644 --- a/Android/.gitignore +++ b/Android/.gitignore @@ -9,5 +9,3 @@ build/ .cxx *.codecc/ /build.yml -tuicore -tuiofflinepush diff --git a/Android/app/src/main/java/com/tencent/liteav/demo/LoginActivity.java b/Android/app/src/main/java/com/tencent/liteav/demo/LoginActivity.java index bd1fe63..537b959 100644 --- a/Android/app/src/main/java/com/tencent/liteav/demo/LoginActivity.java +++ b/Android/app/src/main/java/com/tencent/liteav/demo/LoginActivity.java @@ -50,7 +50,6 @@ public void onClick(View v) { private void login() { String userId = mEditUserId.getText().toString().trim(); final UserModel userModel = new UserModel(); - userModel.appId = GenerateTestUserSig.SDKAPPID; userModel.userId = userId; userModel.userName = userId; int index = new Random().nextInt(AvatarConstant.USER_AVATAR_ARRAY.length); diff --git a/Android/app/src/main/java/com/tencent/liteav/demo/MainActivity.java b/Android/app/src/main/java/com/tencent/liteav/demo/MainActivity.java index 6a8c4d6..f3c563f 100644 --- a/Android/app/src/main/java/com/tencent/liteav/demo/MainActivity.java +++ b/Android/app/src/main/java/com/tencent/liteav/demo/MainActivity.java @@ -23,7 +23,7 @@ import android.widget.TextView; -import com.blankj.utilcode.util.ToastUtils; + import com.tencent.imsdk.v2.V2TIMGroupInfoResult; import com.tencent.liteav.basic.IntentUtils; import com.tencent.liteav.basic.UserModel; @@ -168,13 +168,13 @@ public void onSuccess(V2TIMGroupInfoResult result) { if (isRoomExist(result)) { realEnterRoom(roomIdStr); } else { - ToastUtils.showLong(R.string.room_not_exist); + ToastUtil.toastLongMessage(getString(R.string.room_not_exist)); } } @Override public void onFailed(int code, String msg) { - ToastUtils.showLong(msg); + ToastUtil.toastLongMessage(msg); } }); } diff --git a/Android/build.gradle b/Android/build.gradle index c4f0178..f0dac58 100644 --- a/Android/build.gradle +++ b/Android/build.gradle @@ -1,15 +1,20 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - + ext.kotlin_version = '1.5.31' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.4' + classpath 'com.android.tools.build:gradle:4.2.1' + + + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + // 添加神策分析 android-gradle-plugin2 依赖 + classpath 'com.sensorsdata.analytics.android:android-gradle-plugin2:3.5.3' } } @@ -29,5 +34,6 @@ task clean(type: Delete) { ext { liteavSdk = "com.tencent.liteav:LiteAVSDK_TRTC:latest.release" - imSdk = "com.tencent.imsdk:imsdk-plus:latest.release" + roomEngineSdk = "com.tencent.liteav.tuikit:tuiroomengine:latest.release" + imSdk = "com.tencent.imsdk:imsdk-plus:7.4.4643" } diff --git a/Android/gradle.properties b/Android/gradle.properties index dc251f5..ce9f479 100644 --- a/Android/gradle.properties +++ b/Android/gradle.properties @@ -6,7 +6,7 @@ # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx1536m +org.gradle.jvmargs=-Xmx4608M # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects diff --git a/Android/gradle/wrapper/gradle-wrapper.properties b/Android/gradle/wrapper/gradle-wrapper.properties index 61b335e..d0f33ff 100644 --- a/Android/gradle/wrapper/gradle-wrapper.properties +++ b/Android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip diff --git a/Android/tuivoiceroom/build.gradle b/Android/tuivoiceroom/build.gradle index c23f4fe..4da5c88 100644 --- a/Android/tuivoiceroom/build.gradle +++ b/Android/tuivoiceroom/build.gradle @@ -24,8 +24,8 @@ android { dependencies { api fileTree(dir: 'libs', include: ['*.jar']) api "androidx.multidex:multidex:2.0.0" - api "androidx.recyclerview:recyclerview:1.0.0" - api "androidx.appcompat:appcompat:1.3.1" + api "androidx.recyclerview:recyclerview:1.2.1" + api "androidx.appcompat:appcompat:1.0.0" api "com.google.android.material:material:1.0.0" api "androidx.constraintlayout:constraintlayout:1.1.3" api "com.squareup.okhttp3:logging-interceptor:3.8.1" @@ -36,9 +36,9 @@ dependencies { api "com.github.ctiao:DanmakuFlameMaster:0.3.8" api "de.hdodenhof:circleimageview:3.1.0" api "com.google.code.gson:gson:2.3.1" - api "com.blankj:utilcode:1.30.7" - api rootProject.ext.liteavSdk - api rootProject.ext.imSdk - api 'com.tencent.liteav.tuikit:tuicore:latest.release' api project(':debug') + + def projects = this.rootProject.getAllprojects().stream().map { project -> project.name }.collect() + api projects.contains("tuicore") ? project(':tuicore') : "com.tencent.liteav.tuikit:tuicore:latest.release" + api rootProject.getProperties().containsKey("liteavSdk") ? rootProject.ext.liteavSdk : "com.tencent.liteav:LiteAVSDK_TRTC:latest.release" } diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/IntentUtils.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/IntentUtils.java index ca632ac..14e7b56 100644 --- a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/IntentUtils.java +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/IntentUtils.java @@ -25,7 +25,7 @@ public static void safeStartActivity(Context context, Intent intent) { } context.startActivity(intent); } catch (ActivityNotFoundException e) { - Log.e("TAG", "ActivityNotFoundException : " + intent.toString()); + Log.e(TAG, "ActivityNotFoundException : " + intent.toString()); } } } diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/OnSingleClickListener.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/OnSingleClickListener.java new file mode 100644 index 0000000..56f941a --- /dev/null +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/OnSingleClickListener.java @@ -0,0 +1,23 @@ +package com.tencent.liteav.basic; + +import android.view.View; + +/** + * 作用:防止快速点击按钮引起的错误 + * 使用:Button.setOnClickListener 时,使用此类作的实现类作为Listener + */ +public abstract class OnSingleClickListener implements View.OnClickListener { + private static final long MIN_CLICK_DELAY_TIME = 500; + private long mLastClickTime = 0; + + @Override + public void onClick(View v) { + long curClickTime = System.currentTimeMillis(); + if ((curClickTime - mLastClickTime) >= MIN_CLICK_DELAY_TIME) { + mLastClickTime = curClickTime; + onSingleClick(v); + } + } + + public abstract void onSingleClick(View v); +} diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/PictureUtils.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/PictureUtils.java new file mode 100644 index 0000000..c566bf1 --- /dev/null +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/PictureUtils.java @@ -0,0 +1,59 @@ +package com.tencent.liteav.basic; + +import android.content.ContentValues; +import android.content.Context; +import android.graphics.Bitmap; +import android.net.Uri; +import android.os.Build; +import android.provider.MediaStore; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.OutputStream; + +public class PictureUtils { + private static final String TAG = "PictureUtils"; + + /** + * 保存 Bitmap 到图库 + * @param context + * @param bitmap + * @return + */ + public static boolean saveBitmap2Gallery(Context context, Bitmap bitmap) { + if (context == null || bitmap == null) { + return false; + } + if (Build.VERSION.SDK_INT >= 29) { + //返回出一个URI + Uri insert = context.getContentResolver() + .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues()); + if (insert == null) { + return false; + } + + //这个打开了输出流 直接保存图片就好了 + OutputStream outputStream = null; + try { + outputStream = context.getContentResolver().openOutputStream(insert); + if (outputStream == null) { + return false; + } else { + bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } finally { + try { + if (outputStream != null) { + outputStream.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } else { + MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "snapshot", "desc"); + } + return true; + } +} diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/RTCubeUtils.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/RTCubeUtils.java index 467a316..48e98bd 100644 --- a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/RTCubeUtils.java +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/RTCubeUtils.java @@ -1,10 +1,13 @@ package com.tencent.liteav.basic; +import android.annotation.SuppressLint; +import android.app.Application; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.text.TextUtils; +import java.lang.reflect.InvocationTargetException; public class RTCubeUtils { private static final String RTCUBE_PACKAGE_NAME = "com.tencent.trtc"; @@ -19,10 +22,39 @@ public static String getApplicationName(Context context) { applicationInfo = null; } String applicationName = (String) packageManager.getApplicationLabel(applicationInfo); + if (applicationInfo != null) { + applicationName = context.getResources().getString(applicationInfo.labelRes); + } + return TextUtils.isEmpty(applicationName) ? "" : applicationName; } public static boolean isRTCubeApp(Context context) { return RTCUBE_PACKAGE_NAME.equals(context.getPackageName()); } + + public static String getPackageName() { + return getApplicationByReflect().getPackageName(); + } + + public static Application getApplicationByReflect() { + try { + @SuppressLint("PrivateApi") Class activityThread = Class.forName("android.app.ActivityThread"); + Object thread = activityThread.getMethod("currentActivityThread").invoke(null); + Object app = activityThread.getMethod("getApplication").invoke(thread); + if (app == null) { + throw new NullPointerException("You should init first."); + } + return (Application) app; + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + throw new NullPointerException("You should init first."); + } } diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/ResourceUtils.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/ResourceUtils.java new file mode 100644 index 0000000..4de57a1 --- /dev/null +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/ResourceUtils.java @@ -0,0 +1,72 @@ +package com.tencent.liteav.basic; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.util.TypedValue; + +import androidx.annotation.StringRes; + +public class ResourceUtils { + + private static final String TYPE_QUOTE_PREFIX = "@"; + private static final String TYPE_COLOR_PREFIX = "#"; + + private static final String TYPE_STRING = "string"; + private static final String TYPE_COLOR = "color"; + private static final String TYPE_DRAWABLE = "drawable"; + + public static int getDrawableId(String resName) { + if (resName.startsWith(TYPE_QUOTE_PREFIX)) { + return getResources().getIdentifier(resName, TYPE_DRAWABLE, RTCubeUtils.getPackageName()); + } + throw new IllegalArgumentException("\"" + resName + "\" is illegal, must start with \"@\"."); + } + + public static int getStringId(String resName) { + return getResources().getIdentifier(resName, TYPE_STRING, RTCubeUtils.getPackageName()); + } + + public static String getString(String resName) { + if (resName.startsWith(TYPE_QUOTE_PREFIX)) { + return getResources().getString(getStringId(resName.substring(1))); + } + return resName; + } + + public static String getString(@StringRes int resId) { + return getResources().getString(resId); + } + + public static int getColor(String resName) { + if (resName.startsWith(TYPE_COLOR_PREFIX)) { + return Color.parseColor(resName); + } + if (resName.startsWith(TYPE_QUOTE_PREFIX)) { + return getResources().getColor(getColorId(resName)); + } + throw new IllegalArgumentException("\"" + resName + "\" is unknown color."); + } + + public static int getColorId(String resName) { + return getResources().getIdentifier(resName, TYPE_COLOR, RTCubeUtils.getPackageName()); + } + + public static Resources getResources() { + return RTCubeUtils.getApplicationByReflect().getResources(); + } + + public static int dip2px(float dpValue) { + final float scale = getResources().getDisplayMetrics().density; + return (int) (dpValue * scale + 0.5f); + } + + public static Bitmap decodeResource(int id) { + TypedValue value = new TypedValue(); + getResources().openRawResource(id, value); + BitmapFactory.Options opts = new BitmapFactory.Options(); + opts.inTargetDensity = value.density; + return BitmapFactory.decodeResource(getResources(), id, opts); + } +} diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/UserModelManager.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/UserModelManager.java index c20b6f1..b5234ee 100644 --- a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/UserModelManager.java +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/basic/UserModelManager.java @@ -2,8 +2,8 @@ import android.util.Log; -import com.blankj.utilcode.util.GsonUtils; -import com.blankj.utilcode.util.SPUtils; +import com.google.gson.Gson; +import com.tencent.qcloud.tuicore.util.SPUtils; import java.text.SimpleDateFormat; import java.util.Date; @@ -43,7 +43,7 @@ public synchronized UserModel getUserModel() { public synchronized void setUserModel(UserModel model) { mUserModel = model; try { - SPUtils.getInstance(PER_DATA).put(PER_USER_MODEL, GsonUtils.toJson(mUserModel)); + SPUtils.getInstance(PER_DATA).put(PER_USER_MODEL, new Gson().toJson(mUserModel)); } catch (Exception e) { Log.d(TAG, ""); } @@ -52,7 +52,7 @@ public synchronized void setUserModel(UserModel model) { private void loadUserModel() { try { String json = SPUtils.getInstance(PER_DATA).getString(PER_USER_MODEL); - mUserModel = GsonUtils.fromJson(json, UserModel.class); + mUserModel = new Gson().fromJson(json, UserModel.class); } catch (Exception e) { Log.d(TAG, "loadUserModel failed:" + e.getMessage()); } diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/model/impl/TRTCVoiceRoomImpl.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/model/impl/TRTCVoiceRoomImpl.java index 8ba7936..5d8c6ce 100644 --- a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/model/impl/TRTCVoiceRoomImpl.java +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/model/impl/TRTCVoiceRoomImpl.java @@ -556,7 +556,7 @@ public void run() { public void run() { TRTCLogger.i(TAG, "you are already in the seat"); if (callback != null) { - callback.onCallback(-1, "you are already in the seat"); + callback.onCallback(0, "you are already in the seat"); } } }); diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/model/impl/room/impl/TXRoomService.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/model/impl/room/impl/TXRoomService.java index ce3006c..faa6a85 100644 --- a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/model/impl/room/impl/TXRoomService.java +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/model/impl/room/impl/TXRoomService.java @@ -808,6 +808,8 @@ private void onSeatAttrMapChanged(Map attrMap, int seatSize) { mDelegate.onSeatInfoListChange(txSeatInfoList); } try { + Map leaveSeatMap = new HashMap<>(); + Map takeSeatMap = new HashMap<>(); for (int i = 0; i < seatSize; i++) { TXSeatInfo oldInfo = oldTXSeatInfoList.get(i); TXSeatInfo newInfo = txSeatInfoList.get(i); @@ -816,10 +818,10 @@ private void onSeatAttrMapChanged(Map attrMap, int seatSize) { } else if (oldInfo.status != newInfo.status) { switch (newInfo.status) { case TXSeatInfo.STATUS_UNUSED: - onSeatLeave(i, oldInfo.user); + leaveSeatMap.put(i, oldInfo.user); break; case TXSeatInfo.STATUS_USED: - onSeatTake(i, newInfo.user); + takeSeatMap.put(i, newInfo.user); break; case TXSeatInfo.STATUS_CLOSE: onSeatClose(i, true); @@ -832,6 +834,13 @@ private void onSeatAttrMapChanged(Map attrMap, int seatSize) { onSeatMute(i, newInfo.mute); } } + // 移麦时会同时变更2个麦位状态,但该用户最终状态应该是麦上(onSeatTake应该后回调) + for (Map.Entry entry : leaveSeatMap.entrySet()) { + onSeatLeave(entry.getKey(), entry.getValue()); + } + for (Map.Entry entry : takeSeatMap.entrySet()) { + onSeatTake(entry.getKey(), entry.getValue()); + } } catch (Exception e) { TRTCLogger.e(TAG, "group attr changed, seat compare error:" + e.getCause()); } diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomAnchorActivity.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomAnchorActivity.java index 0fc64d8..f8a559c 100644 --- a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomAnchorActivity.java +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomAnchorActivity.java @@ -7,7 +7,6 @@ import android.util.Log; import android.view.View; -import com.blankj.utilcode.util.ToastUtils; import com.tencent.liteav.trtcvoiceroom.R; import com.tencent.liteav.trtcvoiceroom.model.TRTCVoiceRoomCallback; import com.tencent.liteav.trtcvoiceroom.model.TRTCVoiceRoomDef; @@ -24,6 +23,7 @@ import com.tencent.qcloud.tuicore.interfaces.TUILoginListener; import com.tencent.qcloud.tuicore.permission.PermissionCallback; import com.tencent.qcloud.tuicore.permission.PermissionRequester; +import com.tencent.qcloud.tuicore.util.ToastUtil; import com.tencent.trtc.TRTCCloudDef; import java.lang.reflect.Method; @@ -207,7 +207,7 @@ public void onError(int errorCode, String message) { if (errorCode == ERROR_ROOM_ID_EXIT) { onSuccess(); } else { - ToastUtils.showLong("create room failed[" + errorCode + "]:" + message); + ToastUtil.toastLongMessage("create room failed[" + errorCode + "]:" + message); finish(); } } @@ -225,10 +225,11 @@ private void takeMainSeat() { @Override public void onCallback(int code, String msg) { if (code == 0) { - ToastUtils.showLong(getString(R.string.trtcvoiceroom_toast_owner_succeeded_in_occupying_the_seat)); + ToastUtil.toastLongMessage( + getString(R.string.trtcvoiceroom_toast_owner_succeeded_in_occupying_the_seat)); } else { String s = getString(R.string.trtcvoiceroom_toast_owner_failed_to_occupy_the_seat, code, msg); - ToastUtils.showLong(s); + ToastUtil.toastLongMessage(s); } } }); @@ -327,7 +328,7 @@ public void onAgreeClick(int position) { final MsgEntity entity = mMsgEntityList.get(position); String inviteId = entity.invitedId; if (inviteId == null) { - ToastUtils.showLong(getString(R.string.trtcvoiceroom_request_expired)); + ToastUtil.toastLongMessage(getString(R.string.trtcvoiceroom_request_expired)); return; } mTRTCVoiceRoom.acceptInvitation(inviteId, new TRTCVoiceRoomCallback.ActionCallback() { @@ -337,7 +338,8 @@ public void onCallback(int code, String msg) { entity.type = MsgEntity.TYPE_AGREED; mMsgListAdapter.notifyDataSetChanged(); } else { - ToastUtils.showShort(getString(R.string.trtcvoiceroom_toast_accept_request_failure, code)); + ToastUtil.toastShortMessage( + getString(R.string.trtcvoiceroom_toast_accept_request_failure, code)); } } }); @@ -373,13 +375,13 @@ private void recvTakeSeat(String inviteId, String inviter, String content) { public void onSelected(int seatIndex, final MemberEntity memberEntity) { VoiceRoomSeatEntity seatEntity = mVoiceRoomSeatEntityList.get(seatIndex); if (seatEntity.isUsed) { - ToastUtils.showLong(R.string.trtcvoiceroom_toast_already_someone_in_this_position); + ToastUtil.toastLongMessage(getString(R.string.trtcvoiceroom_toast_already_someone_in_this_position)); return; } if (memberEntity.type == MemberEntity.TYPE_WAIT_AGREE) { String inviteId = mTakeSeatInvitationMap.get(memberEntity.userId); if (inviteId == null) { - ToastUtils.showLong(R.string.trtcvoiceroom_toast_request_has_expired); + ToastUtil.toastLongMessage(getString(R.string.trtcvoiceroom_toast_request_has_expired)); memberEntity.type = MemberEntity.TYPE_IDEL; mViewSelectMember.notifyDataSetChanged(); return; @@ -396,7 +398,8 @@ public void onCallback(int code, String msg) { } mMsgListAdapter.notifyDataSetChanged(); } else { - ToastUtils.showShort(getString(R.string.trtcvoiceroom_toast_accept_request_failure, code)); + ToastUtil.toastShortMessage( + getString(R.string.trtcvoiceroom_toast_accept_request_failure, code)); memberEntity.type = MemberEntity.TYPE_IDEL; mViewSelectMember.notifyDataSetChanged(); } @@ -423,7 +426,8 @@ public void onCallback(int code, String msg) { @Override public void onCallback(int code, String msg) { if (code == 0) { - ToastUtils.showLong(getString(R.string.trtcvoiceroom_toast_invitation_sent_successfully)); + ToastUtil.toastLongMessage( + getString(R.string.trtcvoiceroom_toast_invitation_sent_successfully)); } } }); @@ -448,7 +452,7 @@ public void onInviteeRejected(String id, String invitee) { if (seatInvitation != null) { MemberEntity entity = mMemberEntityMap.get(seatInvitation.inviteUserId); if (entity != null) { - ToastUtils.showShort(getString(R.string.trtcvoiceroom_toast_refuse_to_chat, entity.userName)); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_toast_refuse_to_chat, entity.userName)); } } } @@ -469,8 +473,9 @@ public void onInviteeAccepted(String id, final String invitee) { @Override public void onCallback(int code, String msg) { if (code == 0) { - ToastUtils.showLong(getString(R.string.trtcvoiceroom_toast_invite_to_chat_successfully, - invitee)); + ToastUtil.toastLongMessage( + getString(R.string.trtcvoiceroom_toast_invite_to_chat_successfully, + entity.userName)); } } }); diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomAudienceActivity.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomAudienceActivity.java index 42cc2ce..992435d 100644 --- a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomAudienceActivity.java +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomAudienceActivity.java @@ -9,7 +9,6 @@ import android.util.Log; import android.view.View; -import com.blankj.utilcode.util.ToastUtils; import com.tencent.liteav.basic.RTCubeUtils; import com.tencent.liteav.trtcvoiceroom.R; import com.tencent.liteav.trtcvoiceroom.model.TRTCVoiceRoomCallback; @@ -23,6 +22,7 @@ import com.tencent.qcloud.tuicore.interfaces.TUILoginListener; import com.tencent.qcloud.tuicore.permission.PermissionCallback; import com.tencent.qcloud.tuicore.permission.PermissionRequester; +import com.tencent.qcloud.tuicore.util.ToastUtil; import com.tencent.trtc.TRTCCloudDef; import java.lang.reflect.Method; @@ -52,10 +52,11 @@ private void enterRoom() { @Override public void onCallback(int code, String msg) { if (code == 0) { - ToastUtils.showShort(R.string.trtcvoiceroom_toast_enter_the_room_successfully); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_toast_enter_the_room_successfully)); mTRTCVoiceRoom.setAudioQuality(mAudioQuality); } else { - ToastUtils.showShort(getString(R.string.trtcvoiceroom_toast_enter_the_room_failure, code, msg)); + ToastUtil.toastShortMessage( + getString(R.string.trtcvoiceroom_toast_enter_the_room_failure, code, msg)); finish(); } } @@ -154,7 +155,7 @@ private void exitRoom() { mTRTCVoiceRoom.exitRoom(new TRTCVoiceRoomCallback.ActionCallback() { @Override public void onCallback(int code, String msg) { - ToastUtils.showShort(R.string.trtcvoiceroom_toast_exit_the_room_successfully); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_toast_exit_the_room_successfully)); } }); } @@ -174,12 +175,13 @@ public void onSeatListChange(List seatInfoList) { @Override public void onItemClick(final int itemPos) { if (!mIsSeatInitSuccess) { - ToastUtils.showLong(R.string.trtcvoiceroom_toast_list_has_not_been_initialized); + ToastUtil.toastLongMessage(getString(R.string.trtcvoiceroom_toast_list_has_not_been_initialized)); return; } VoiceRoomSeatEntity entity = mVoiceRoomSeatEntityList.get(itemPos); if (entity.isClose) { - ToastUtils.showShort(R.string.trtcvoiceroom_toast_position_is_locked_cannot_apply_for_chat); + ToastUtil.toastShortMessage( + getString(R.string.trtcvoiceroom_toast_position_is_locked_cannot_apply_for_chat)); } else if (!entity.isUsed) { final CommonBottomDialog dialog = new CommonBottomDialog(this); dialog.setButton(new CommonBottomDialog.OnButtonClickListener() { @@ -188,11 +190,12 @@ public void onClick(int position, String text) { if (position == 0) { VoiceRoomSeatEntity seatEntity = mVoiceRoomSeatEntityList.get(itemPos); if (seatEntity.isUsed) { - ToastUtils.showShort(R.string.trtcvoiceroom_toast_position_is_already_occupied); + ToastUtil.toastShortMessage( + getString(R.string.trtcvoiceroom_toast_position_is_already_occupied)); return; } if (seatEntity.isClose) { - ToastUtils.showShort(getString(R.string.trtcvoiceroom_seat_closed)); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_seat_closed)); return; } PermissionCallback callback = new PermissionCallback() { @@ -226,7 +229,7 @@ public void onDenied() { dialog.show(); } else { if (!entity.userId.equals(mSelfUserId)) { - ToastUtils.showShort(entity.userName); + ToastUtil.toastShortMessage(entity.userName); } } } @@ -241,9 +244,9 @@ private void leaveSeat() { @Override public void onCallback(int code, String msg) { if (code == 0) { - ToastUtils.showShort(R.string.trtcvoiceroom_toast_offline_successfully); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_toast_offline_successfully)); } else { - ToastUtils.showShort(getString(R.string.trtcvoiceroom_toast_offline_failure, msg)); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_toast_offline_failure, msg)); } } }); @@ -251,12 +254,12 @@ public void onCallback(int code, String msg) { private void startTakeSeat(int itemPos) { if (mCurrentRole == TRTCCloudDef.TRTCRoleAnchor) { - ToastUtils.showShort(R.string.trtcvoiceroom_toast_you_are_already_an_anchor); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_toast_you_are_already_an_anchor)); return; } if (mNeedRequest) { if (mOwnerId == null) { - ToastUtils.showShort(R.string.trtcvoiceroom_toast_the_room_is_not_ready); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_toast_the_room_is_not_ready)); return; } String inviteId = mTRTCVoiceRoom.sendInvitation(TCConstants.CMD_REQUEST_TAKE_SEAT, mOwnerId, @@ -264,10 +267,10 @@ private void startTakeSeat(int itemPos) { @Override public void onCallback(int code, String msg) { if (code == 0) { - ToastUtils.showShort(R.string - .trtcvoiceroom_toast_application_has_been_sent_please_wait_for_processing); + ToastUtil.toastShortMessage(getString(R.string + .trtcvoiceroom_toast_application_has_been_sent_please_wait_for_processing)); } else { - ToastUtils.showShort(getString(R + ToastUtil.toastShortMessage(getString(R .string.trtcvoiceroom_toast_failed_to_send_application, msg)); } } @@ -295,7 +298,7 @@ private void startMoveSeat(int itemPos) { } if (mNeedRequest) { if (mOwnerId == null) { - ToastUtils.showShort(R.string.trtcvoiceroom_toast_the_room_is_not_ready); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_toast_the_room_is_not_ready)); return; } String inviteId = mTRTCVoiceRoom.sendInvitation(TCConstants.CMD_REQUEST_TAKE_SEAT, mOwnerId, @@ -303,10 +306,10 @@ private void startMoveSeat(int itemPos) { @Override public void onCallback(int code, String msg) { if (code == 0) { - ToastUtils.showShort(R.string - .trtcvoiceroom_toast_application_has_been_sent_please_wait_for_processing); + ToastUtil.toastShortMessage(getString(R.string + .trtcvoiceroom_toast_application_has_been_sent_please_wait_for_processing)); } else { - ToastUtils.showShort(getString(R + ToastUtil.toastShortMessage(getString(R .string.trtcvoiceroom_toast_failed_to_send_application, msg)); } } @@ -352,7 +355,7 @@ public void onClick() { @Override public void onCallback(int code, String msg) { Log.d(TAG, "rejectInvitation callback:" + code); - ToastUtils.showShort(R.string.trtcvoiceroom_msg_you_refuse_to_chat); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_msg_you_refuse_to_chat)); } }); mConfirmDialogFragment.dismiss(); @@ -365,7 +368,8 @@ public void onClick() { @Override public void onCallback(int code, String msg) { if (code != 0) { - ToastUtils.showShort(getString(R.string.trtcvoiceroom_toast_accept_request_failure, code)); + ToastUtil.toastShortMessage( + getString(R.string.trtcvoiceroom_toast_accept_request_failure, code)); } Log.d(TAG, "acceptInvitation callback:" + code); } @@ -459,7 +463,7 @@ public void onAnchorLeaveSeat(int index, TRTCVoiceRoomDef.UserInfo user) { @Override public void onRoomDestroy(String roomId) { super.onRoomDestroy(roomId); - ToastUtils.showLong(R.string.trtcvoiceroom_msg_close_room); + ToastUtil.toastLongMessage(getString(R.string.trtcvoiceroom_msg_close_room)); mTRTCVoiceRoom.exitRoom(null); finish(); } diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomBaseActivity.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomBaseActivity.java index c5dbb34..f940eb3 100644 --- a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomBaseActivity.java +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomBaseActivity.java @@ -24,7 +24,6 @@ import android.widget.TextView; import android.widget.Toast; -import com.blankj.utilcode.util.ToastUtils; import com.tencent.liteav.basic.ImageLoader; import com.tencent.liteav.basic.UserModel; import com.tencent.liteav.basic.UserModelManager; @@ -48,6 +47,7 @@ import com.tencent.qcloud.tuicore.interfaces.TUICallback; import com.tencent.qcloud.tuicore.permission.PermissionCallback; import com.tencent.qcloud.tuicore.permission.PermissionRequester; +import com.tencent.qcloud.tuicore.util.ToastUtil; import com.tencent.trtc.TRTCCloudDef; import java.nio.charset.StandardCharsets; @@ -198,14 +198,15 @@ private void updateMicButton() { if (!isSeatMute(mSelfSeatIndex)) { updateMuteStatusView(mSelfUserId, false); mTRTCVoiceRoom.muteLocalAudio(false); - ToastUtils.showLong(getString(R.string.trtcvoiceroom_toast_you_have_turned_on_the_microphone)); + ToastUtil.toastLongMessage( + getString(R.string.trtcvoiceroom_toast_you_have_turned_on_the_microphone)); } else { - ToastUtils.showLong(getString(R.string.trtcvoiceroom_seat_already_mute)); + ToastUtil.toastLongMessage(getString(R.string.trtcvoiceroom_seat_already_mute)); } } else { mTRTCVoiceRoom.muteLocalAudio(true); updateMuteStatusView(mSelfUserId, true); - ToastUtils.showLong(getString(R.string.trtcvoiceroom_toast_you_have_turned_off_the_microphone)); + ToastUtil.toastLongMessage(getString(R.string.trtcvoiceroom_toast_you_have_turned_off_the_microphone)); } } } @@ -295,7 +296,7 @@ public static int dp2px(Context context, float dpVal) { protected boolean checkButtonPermission() { boolean hasPermission = (mCurrentRole == TRTCCloudDef.TRTCRoleAnchor); if (!hasPermission) { - ToastUtils.showLong(getString(R.string.trtcvoiceroom_toast_anchor_can_only_operate_it)); + ToastUtil.toastLongMessage(getString(R.string.trtcvoiceroom_toast_anchor_can_only_operate_it)); } return hasPermission; } @@ -432,9 +433,9 @@ public void onTextSend(String msg) { @Override public void onCallback(int code, String msg) { if (code == 0) { - ToastUtils.showShort(getString(R.string.trtcvoiceroom_toast_sent_successfully)); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_toast_sent_successfully)); } else { - ToastUtils.showShort(getString(R.string.trtcvoiceroom_toast_sent_message_failure, code)); + ToastUtil.toastShortMessage(getString(R.string.trtcvoiceroom_toast_sent_message_failure, code)); } } }); @@ -708,7 +709,7 @@ public void onAudienceEnter(TRTCVoiceRoomDef.UserInfo userInfo) { Log.d(TAG, "onAudienceEnter userInfo:" + userInfo); MsgEntity msgEntity = new MsgEntity(); msgEntity.type = MsgEntity.TYPE_NORMAL; - msgEntity.content = getString(R.string.trtcvoiceroom_tv_enter_room, userInfo.userName); + msgEntity.content = getString(R.string.trtcvoiceroom_tv_enter_room); msgEntity.userName = userInfo.userName; showImMsg(msgEntity); if (userInfo.userId.equals(mSelfUserId)) { @@ -726,7 +727,7 @@ public void onAudienceExit(TRTCVoiceRoomDef.UserInfo userInfo) { MsgEntity msgEntity = new MsgEntity(); msgEntity.type = MsgEntity.TYPE_NORMAL; msgEntity.userName = userInfo.userName; - msgEntity.content = getString(R.string.trtcvoiceroom_tv_exit_room, userInfo.userName); + msgEntity.content = getString(R.string.trtcvoiceroom_tv_exit_room); showImMsg(msgEntity); mAudienceListAdapter.removeMember(userInfo.userId); } diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomCreateDialog.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomCreateDialog.java index fa572c4..9f6221b 100644 --- a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomCreateDialog.java +++ b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/room/VoiceRoomCreateDialog.java @@ -14,10 +14,10 @@ import android.widget.EditText; import android.widget.TextView; -import com.blankj.utilcode.util.ToastUtils; import com.tencent.liteav.basic.RTCubeUtils; import com.tencent.liteav.basic.UserModelManager; import com.tencent.liteav.trtcvoiceroom.R; +import com.tencent.qcloud.tuicore.util.ToastUtil; public class VoiceRoomCreateDialog extends BottomSheetDialog { private static final int MAX_LEN = 30; @@ -79,7 +79,11 @@ public void onClick(View v) { } }); String showName = TextUtils.isEmpty(mUserName) ? mUserId : mUserName; - mRoomNameEt.setText(getContext().getString(R.string.trtcvoiceroom_create_theme, showName)); + showName = getContext().getString(R.string.trtcvoiceroom_create_theme, showName); + if (showName.getBytes().length > MAX_LEN) { + showName = showName.substring(0, MAX_LEN); + } + mRoomNameEt.setText(showName); } private void createRoom() { @@ -88,7 +92,7 @@ private void createRoom() { return; } if (roomName.getBytes().length > MAX_LEN) { - ToastUtils.showLong(getContext().getText(R.string.trtcvoiceroom_warning_room_name_too_long)); + ToastUtil.toastLongMessage(getContext().getString(R.string.trtcvoiceroom_warning_room_name_too_long)); return; } VoiceRoomAnchorActivity.createRoom(getContext(), roomName, mUserId, mUserName, mCoverUrl, mAudioQuality, diff --git a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/utils/PermissionHelper.java b/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/utils/PermissionHelper.java deleted file mode 100644 index 03bfd39..0000000 --- a/Android/tuivoiceroom/src/main/java/com/tencent/liteav/trtcvoiceroom/ui/utils/PermissionHelper.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.tencent.liteav.trtcvoiceroom.ui.utils; - -import android.content.Context; -import android.content.pm.ApplicationInfo; -import android.content.res.Resources; -import android.text.TextUtils; - -import androidx.annotation.IntDef; - -import com.tencent.liteav.trtcvoiceroom.R; -import com.tencent.qcloud.tuicore.util.PermissionRequester; - -public class PermissionHelper { - public static final int PERMISSION_MICROPHONE = 1; - - @IntDef({PERMISSION_MICROPHONE}) - public @interface PermissionType { - } - - public static void requestPermission(Context context, @PermissionType int type, final PermissionCallback callback) { - String permission = null; - String reason = null; - String reasonTitle = null; - String deniedAlert = null; - ApplicationInfo applicationInfo = context.getApplicationContext().getApplicationInfo(); - Resources resources = context.getResources(); - String appName = resources.getString(applicationInfo.labelRes); - switch (type) { - case PERMISSION_MICROPHONE: { - permission = PermissionRequester.PermissionConstants.MICROPHONE; - reasonTitle = resources.getString(R.string.trtcvoiceroom_permission_mic_reason_title, appName); - reason = resources.getString(R.string.trtcvoiceroom_permission_mic_reason); - deniedAlert = resources.getString(R.string.trtcvoiceroom_tips_start_audio); - break; - } - default: - break; - } - - PermissionRequester.SimpleCallback simpleCallback = new PermissionRequester.SimpleCallback() { - @Override - public void onGranted() { - if (callback != null) { - callback.onGranted(); - } - } - - @Override - public void onDenied() { - if (callback != null) { - callback.onDenied(); - } - } - }; - if (!TextUtils.isEmpty(permission)) { - PermissionRequester.permission(permission) - .reason(reason) - .reasonTitle(reasonTitle) - .deniedAlert(deniedAlert) - .callback(simpleCallback) - .permissionDialogCallback(new PermissionRequester.PermissionDialogCallback() { - @Override - public void onApproved() { - if (callback != null) { - callback.onDialogApproved(); - } - } - - @Override - public void onRefused() { - if (callback != null) { - callback.onDialogRefused(); - } - } - }) - .request(); - } - } - - public interface PermissionCallback { - void onGranted(); - - void onDenied(); - - void onDialogApproved(); - - void onDialogRefused(); - } -} \ No newline at end of file diff --git a/Android/tuivoiceroom/src/main/res/values-en/strings.xml b/Android/tuivoiceroom/src/main/res/values-en/strings.xml index 1958654..058a71c 100644 --- a/Android/tuivoiceroom/src/main/res/values-en/strings.xml +++ b/Android/tuivoiceroom/src/main/res/values-en/strings.xml @@ -65,8 +65,8 @@ Seat %d unmuted Seat %d blocked Seat %d unblocked - %s entered - %s left the room + entered + left the room The seat is blocked Getting anchor name Loading diff --git a/Android/tuivoiceroom/src/main/res/values-zh/strings.xml b/Android/tuivoiceroom/src/main/res/values-zh/strings.xml index c772a86..7fbeee3 100755 --- a/Android/tuivoiceroom/src/main/res/values-zh/strings.xml +++ b/Android/tuivoiceroom/src/main/res/values-zh/strings.xml @@ -65,8 +65,8 @@ %d号位解除禁言 房主封禁%d号位 房主解禁%d号位 - %s进房 - %s退房 + 进房 + 退房 座位已锁定 主播名还在查找 正在加载中 diff --git a/Android/tuivoiceroom/src/main/res/values/strings.xml b/Android/tuivoiceroom/src/main/res/values/strings.xml index 30f5812..9d10263 100644 --- a/Android/tuivoiceroom/src/main/res/values/strings.xml +++ b/Android/tuivoiceroom/src/main/res/values/strings.xml @@ -65,8 +65,8 @@ Seat %d unmuted Seat %d blocked Seat %d unblocked - %s entered - %s left the room + entered + left the room The seat is blocked Getting anchor name Loading