From fb422155cceab237fe08177a9aecf5cbea70f06b Mon Sep 17 00:00:00 2001 From: zher52 Date: Wed, 16 Feb 2022 17:07:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=BA=E5=91=98=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E6=97=A0=E6=B3=95=E6=9B=B4=E6=96=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tencent/trtc/CordovaEventKit.java | 6 ++++ .../com/tencent/trtc/CustomVideoView.java | 9 +++--- .../java/com/tencent/trtc/event/Events.java | 7 +++++ .../trtc/message/LayoutChangeMessage.java | 28 ------------------- .../trtc/videocall/VideoCallingActivity.java | 4 +-- .../res/layout/custom_video_view_layout.xml | 2 ++ 6 files changed, 21 insertions(+), 35 deletions(-) delete mode 100644 src/android/java/com/tencent/trtc/message/LayoutChangeMessage.java diff --git a/src/android/java/com/tencent/trtc/CordovaEventKit.java b/src/android/java/com/tencent/trtc/CordovaEventKit.java index 6eaa30b..8af6b43 100644 --- a/src/android/java/com/tencent/trtc/CordovaEventKit.java +++ b/src/android/java/com/tencent/trtc/CordovaEventKit.java @@ -1,11 +1,14 @@ package com.tencent.trtc; +import android.util.Log; + import org.apache.cordova.CordovaPlugin; import org.json.JSONArray; import org.json.JSONObject; public class CordovaEventKit { public static CordovaEventKit kit = null; + private static final String TAG = "CordovaEventKit"; private CordovaPlugin plugin; @@ -29,7 +32,9 @@ public class CordovaEventKit { } public void fireEvent(String event, String obj){ + Log.d(TAG,"fireEvent --- event:"+event+",obj:"+obj); if (plugin == null || event == null || obj == null) { + Log.w(TAG,"fireEvent --- plugin:"+plugin); return; } event = event.replace('\'','_'); @@ -38,6 +43,7 @@ public class CordovaEventKit { plugin.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { + Log.d(TAG,"fireEvent --- code:"+js); plugin.webView.loadUrl("javascript:" + js); } }); diff --git a/src/android/java/com/tencent/trtc/CustomVideoView.java b/src/android/java/com/tencent/trtc/CustomVideoView.java index e683d15..99f158b 100644 --- a/src/android/java/com/tencent/trtc/CustomVideoView.java +++ b/src/android/java/com/tencent/trtc/CustomVideoView.java @@ -108,13 +108,12 @@ public class CustomVideoView extends RelativeLayout { this.setVisibility(alwaysHide?INVISIBLE:VISIBLE); }); } - Events.addListener("userinfo.update",(extra -> { - if(this.userInfo !=null && this.userInfo.getDisplayName() == null - && this.userInfo.getDisplayName().length() == 0 - && extra.getString("userId").equals(this.userInfo.getPersonid())){ + Events.addListener("userinfo.update",(extra) -> { + if(this.userInfo !=null && extra.getString("userId").equals(this.userInfo.getPersonid())){ + this.userInfo.setDisplayName(extra.getString("displayName")); this.titleView.setText(extra.getString("displayName",this.userInfo.getDisplayName())); } - })); + }); return this; } diff --git a/src/android/java/com/tencent/trtc/event/Events.java b/src/android/java/com/tencent/trtc/event/Events.java index c71f8d9..3c30f85 100644 --- a/src/android/java/com/tencent/trtc/event/Events.java +++ b/src/android/java/com/tencent/trtc/event/Events.java @@ -1,6 +1,7 @@ package com.tencent.trtc.event; import android.os.Bundle; +import android.util.Log; import java.util.ArrayList; import java.util.HashMap; @@ -8,24 +9,29 @@ import java.util.List; import java.util.Map; public class Events { + private static final String TAG = "Events"; + private static final String PREFIX = "com.tencent.trtc.event"; private static final Map> events = new HashMap(); public static void fireEvent(String event){ fireEvent(event,null); } public static void fireEvent(String event, Extra extra){ + Log.d(TAG,"fireEvent --- event:"+event+",extra:"+ extra); if(events.containsKey(PREFIX+event)){ for(Listener listener : events.get(PREFIX+event)){ Bundle bundle = extra == null ? Bundle.EMPTY: new Bundle(); if(extra != null){ extra.extra(bundle); } + Log.d(TAG,"fireEvent --- event:"+event+",bundle:"+ bundle); listener.on(extra == null ? Bundle.EMPTY : bundle); } } } public static void addListener(String eventName,Listener listener){ + Log.d(TAG,"addListener --- event:"+eventName+",listener:"+listener.hashCode()); if(!events.containsKey(PREFIX+eventName)){ events.put(PREFIX+eventName,new ArrayList<>()); } @@ -36,6 +42,7 @@ public class Events { } public static void removeListener(String eventName,Listener listener){ + Log.d(TAG,"removeListener --- event:"+eventName+",listener:"+listener.hashCode()); if(!events.containsKey(PREFIX+eventName)){ events.put(PREFIX+eventName,new ArrayList<>()); } diff --git a/src/android/java/com/tencent/trtc/message/LayoutChangeMessage.java b/src/android/java/com/tencent/trtc/message/LayoutChangeMessage.java deleted file mode 100644 index 13dde93..0000000 --- a/src/android/java/com/tencent/trtc/message/LayoutChangeMessage.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tencent.trtc.message; - -import com.tencent.trtc.MessageObject; - -import org.json.JSONObject; - -public class LayoutChangeMessage implements MessageObject { - - private String room; - private String personid; - - - public LayoutChangeMessage(String room, String personid) { - this.room = room; - this.personid = personid; - } - - @Override - public String getEvent() { - return "LayoutChangeMessage"; - } - - @Override - public JSONObject getJson() { - JSONObject obj = new JSONObject(); - return obj; - } -} diff --git a/src/android/java/com/tencent/trtc/videocall/VideoCallingActivity.java b/src/android/java/com/tencent/trtc/videocall/VideoCallingActivity.java index f667af9..a2b6db3 100644 --- a/src/android/java/com/tencent/trtc/videocall/VideoCallingActivity.java +++ b/src/android/java/com/tencent/trtc/videocall/VideoCallingActivity.java @@ -179,13 +179,13 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli } Events.fireEvent("subview.always.hide",(extra)->extra.putBoolean("alwaysHide",false)); - Events.addListener("userinfo.update",(extra -> { + Events.addListener("userinfo.update",(extra) -> { String user = extra.getString("userId"); int index = this.mUserList.indexOf(user); if(index > -1){ this.mUserList.get(index).setDisplayName(extra.getString("displayName")); } - })); + }); } private void enterRoom() { diff --git a/src/android/res/layout/custom_video_view_layout.xml b/src/android/res/layout/custom_video_view_layout.xml index a54c6f4..72c8d79 100644 --- a/src/android/res/layout/custom_video_view_layout.xml +++ b/src/android/res/layout/custom_video_view_layout.xml @@ -19,6 +19,8 @@ android:paddingLeft="5dp" android:paddingRight="5dp" android:textAlignment="center" + android:singleLine="true" android:visibility="gone" + android:autoSizeTextType="uniform" /> \ No newline at end of file