From b3ecec4b27cc7343f78cd1bff20364c14d5b8faf Mon Sep 17 00:00:00 2001 From: zhaochong Date: Thu, 3 Sep 2020 17:05:04 +0800 Subject: [PATCH 1/7] feat:[meetinglib release/1.2.0][android sampleCode] update 1.1.0 ->1.2.0 --- SampleCode/Android/app/.gitignore | 1 - SampleCode/Android/app/build.gradle | 2 +- .../Android/app/src/main/AndroidManifest.xml | 37 ++-- .../demo/fragment/BaseFragment.java | 31 ++- .../demo/fragment/JoinMeetingFragment.java | 15 +- .../demo/fragment/MeetingBaseFragment.java | 127 +++++++++++- .../demo/fragment/StartMeetingFragment.java | 25 +-- .../app/src/main/res/layout/fragment_base.xml | 4 +- .../main/res/layout/fragment_meeting_base.xml | 186 ++++++++++++------ .../Android/user_guide.MD" | 82 +++++++- 10 files changed, 385 insertions(+), 125 deletions(-) delete mode 100644 SampleCode/Android/app/.gitignore diff --git a/SampleCode/Android/app/.gitignore b/SampleCode/Android/app/.gitignore deleted file mode 100644 index 42afabfd..00000000 --- a/SampleCode/Android/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/SampleCode/Android/app/build.gradle b/SampleCode/Android/app/build.gradle index c3be336a..693eadc5 100644 --- a/SampleCode/Android/app/build.gradle +++ b/SampleCode/Android/app/build.gradle @@ -45,7 +45,7 @@ dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) //meeting sdk - implementation 'com.netease.yunxin:meetinglib:1.1.0' + implementation 'com.netease.yunxin:meetinglib:1.2.0' //app demo dependencies implementation 'androidx.appcompat:appcompat:1.1.0' diff --git a/SampleCode/Android/app/src/main/AndroidManifest.xml b/SampleCode/Android/app/src/main/AndroidManifest.xml index 2a7dd7c0..80b3ddd2 100644 --- a/SampleCode/Android/app/src/main/AndroidManifest.xml +++ b/SampleCode/Android/app/src/main/AndroidManifest.xml @@ -1,19 +1,7 @@ - - - - - - - - - - - - - + + android:resizeableActivity="false"> - - + android:name=".MeetingSettingsActivity" + android:label="会议设置" /> + + + + + + + + + + + - \ No newline at end of file + diff --git a/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/BaseFragment.java b/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/BaseFragment.java index 5bc622e6..9ea97644 100644 --- a/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/BaseFragment.java +++ b/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/BaseFragment.java @@ -27,7 +27,7 @@ protected BaseFragment(@LayoutRes int contentLayoutId) { private LoadingFragment loadingFragment; - private EditText[] editorArray = new EditText[2]; + private EditText[] editorArray = new EditText[4]; protected abstract String[] getEditorLabel(); @@ -35,6 +35,7 @@ protected BaseFragment(@LayoutRes int contentLayoutId) { protected abstract void performAction(String first, String second); + protected final EditText getEditor(int index) { return editorArray[index]; } @@ -53,25 +54,23 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { String[] labels = getEditorLabel(); - editorArray[0] = getView().findViewById(R.id.firstEditor); - editorArray[0].setSingleLine(true); - if (labels.length > 0) { - editorArray[0].setHint(labels[0]); - } else { - editorArray[0].setVisibility(View.GONE); - } - - editorArray[1] = getView().findViewById(R.id.secondEditor); - editorArray[1].setSingleLine(true); - if (labels.length > 1) { - editorArray[1].setHint(labels[1]); - } else { - editorArray[1].setVisibility(View.GONE); - } + addEditorArray(0,R.id.firstEditor,labels); + addEditorArray(1,R.id.secondEditor,labels); Button action = getView().findViewById(R.id.actionBtn); action.setText(getActionLabel()); action.setOnClickListener(v -> performAction(getEditorText(0), getEditorText(1))); + + } + + protected void addEditorArray(int i, int editor, String[] labels) { + editorArray[i] = getView().findViewById(editor); + editorArray[i].setSingleLine(true); + if (labels.length > i) { + editorArray[i].setHint(labels[i]); + } else { + editorArray[i].setVisibility(View.GONE); + } } protected ContentSwitcher getContentSwitcher() { diff --git a/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/JoinMeetingFragment.java b/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/JoinMeetingFragment.java index 2f1b8c8a..736097cf 100644 --- a/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/JoinMeetingFragment.java +++ b/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/JoinMeetingFragment.java @@ -26,7 +26,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { @Override protected String[] getEditorLabel() { - return new String[]{"会议号","昵称"}; + return new String[]{"会议号", "昵称", "100", "tittle"}; } @Override @@ -41,16 +41,11 @@ protected void performAction(String first, String second) { params.displayName = second; NEJoinMeetingOptions options = null; if (isNotUseDefaultMeetingOptions()) { - options = new NEJoinMeetingOptions(); - options.noVideo = !isChecked(0); - options.noAudio = !isChecked(1); - options.showMeetingTime = true; - } - NEMeetingService meetingService = NEMeetingSDK.getInstance().getMeetingService(); - if (meetingService != null) { - meetingService.joinMeeting(getActivity(), params, options, new MeetingCallback()); - showLoading("正在加入会议..."); + options = (NEJoinMeetingOptions) getMeetingOptions(new NEJoinMeetingOptions()); } + + showLoading("正在加入会议..."); + getMeetingService().joinMeeting(getActivity(), params, options, new MeetingCallback()); } private boolean isAnonymous() { diff --git a/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/MeetingBaseFragment.java b/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/MeetingBaseFragment.java index 86e3aba5..394c9353 100644 --- a/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/MeetingBaseFragment.java +++ b/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/MeetingBaseFragment.java @@ -5,8 +5,11 @@ package com.netease.meetinglib.demo.fragment; +import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.View; +import android.widget.Button; import android.widget.CheckBox; import android.widget.Toast; @@ -14,8 +17,21 @@ import com.netease.meetinglib.demo.R; import com.netease.meetinglib.demo.SdkAuthenticator; +import com.netease.meetinglib.demo.TestActivity; import com.netease.meetinglib.demo.ToastCallback; +import com.netease.meetinglib.sdk.NECallback; import com.netease.meetinglib.sdk.NEMeetingError; +import com.netease.meetinglib.sdk.NEMeetingInfo; +import com.netease.meetinglib.sdk.NEMeetingMenuItem; +import com.netease.meetinglib.sdk.NEMeetingOnInjectedMenuItemClickListener; +import com.netease.meetinglib.sdk.NEMeetingOptions; +import com.netease.meetinglib.sdk.NEMeetingSDK; +import com.netease.meetinglib.sdk.NEMeetingService; +import com.netease.meetinglib.sdk.NEMeetingStatus; +import com.netease.meetinglib.sdk.NEMeetingStatusListener; + +import java.util.ArrayList; +import java.util.List; public abstract class MeetingBaseFragment extends BaseFragment { @@ -24,28 +40,117 @@ public abstract class MeetingBaseFragment extends BaseFragment { } protected CheckBox usePersonalMeetingId; - private CheckBox[] checkBoxes = new CheckBox[2]; + private CheckBox[] checkBoxes = new CheckBox[4]; private CheckBox useDefaultMeetingOptions; + protected List injectedMoreMenuItems = new ArrayList<>(); + private NEMeetingService meetingService; + + public NEMeetingService getMeetingService() { + if (meetingService == null) { + meetingService = NEMeetingSDK.getInstance().getMeetingService(); + } + return meetingService; + } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); View view = getView(); + // TextView menuItemId = getView().findViewById(R.id.menuItemId); +// TextView menuTitle = getView().findViewById(R.id.menuTitle); checkBoxes[0] = view.findViewById(R.id.videoOption); checkBoxes[1] = view.findViewById(R.id.audioOption); + checkBoxes[2] = view.findViewById(R.id.noChatOptions); + checkBoxes[3] = view.findViewById(R.id.noInviteOptions); + usePersonalMeetingId = view.findViewById(R.id.usePersonalMeetingId); useDefaultMeetingOptions = view.findViewById(R.id.useDefaultOptions); + + addEditorArray(2, R.id.addItemIdEditor, getEditorLabel()); + addEditorArray(3, R.id.addTittleEditor, getEditorLabel()); + Button addMenuItemButton = getView().findViewById(R.id.addMenuItemButton); + addMenuItemButton.setText("增加菜单"); + addMenuItemButton.setOnClickListener(v -> addMenuItem()); useDefaultMeetingOptions.setChecked(false); useDefaultMeetingOptions.setOnCheckedChangeListener((checkbox, checked) -> { checkBoxes[0].setEnabled(!checked); checkBoxes[1].setEnabled(!checked); }); + injectedMoreMenuItems.clear(); + NEMeetingSDK.getInstance().getMeetingService().addMeetingStatusListener(listener); + getMeetingService().setOnInjectedMenuItemClickListener(new OnCustomMenuListener()); + } + + + public class OnCustomMenuListener implements NEMeetingOnInjectedMenuItemClickListener { + @Override + public void onInjectedMenuItemClick(NEMeetingMenuItem menuItem, NEMeetingInfo meetingInfo) { + switch (menuItem.itemId) { + case 101: + NEMeetingSDK.getInstance().getMeetingService().getCurrentMeetingInfo(new NECallback() { + @Override + public void onResult(int resultCode, String resultMsg, NEMeetingInfo resultData) { + Toast.makeText(getActivity(), "获取房间信息NEMeetingInfo:" + resultData.toString(), Toast.LENGTH_SHORT).show(); + Log.d("OnCustomMenuListener", "getCurrentMeetingInfo:resultCode " + resultCode + "#resultData " + resultData.toString()); + } + }); + break; + default: + Toast.makeText(getActivity(), "点击事件Id:" + menuItem.itemId + "#点击事件tittle:" + menuItem.itemId, Toast.LENGTH_SHORT).show(); + getActivity().startActivity(new Intent(getActivity(), TestActivity.class)); + break; + + } + Log.d("OnCustomMenuListener", "onInjectedMenuItemClicked:menuItem " + menuItem.toString() + "#" + meetingInfo.toString()); + } + } + + //首次添加,仅测试使用 +// private void addMeetingInfoItem() { +// NEMeetingMenuItem meetingMenuItem = new NEMeetingMenuItem(); +// meetingMenuItem.itemId = 101; +// meetingMenuItem.title = "获取房间信息"; +// injectedMoreMenuItems.add(meetingMenuItem); +// } + + private void addMenuItem() { + String id = getEditorText(2); + String tittle = getEditorText(3); + if ("".equals(id) || "".equals(tittle)) { + Toast.makeText(getActivity(), "参数不允许为空" + id, Toast.LENGTH_SHORT).show(); + return; + } + + NEMeetingMenuItem meetingMenuItem = new NEMeetingMenuItem(); + assert id != null; + meetingMenuItem.itemId = Integer.parseInt(id); + meetingMenuItem.title = tittle; + injectedMoreMenuItems.add(meetingMenuItem); + Toast.makeText(getActivity(), "添加自定义菜单成功", Toast.LENGTH_SHORT).show(); + } + + public NEMeetingOptions getMeetingOptions(NEMeetingOptions options) { + options.noVideo = !isChecked(0); + options.noAudio = !isChecked(1); + options.noChat = isChecked(2); + options.noInvite = isChecked(3); +// addMeetingInfoItem(); + if (injectedMoreMenuItems != null && injectedMoreMenuItems.size() > 0) { + options.injectedMoreMenuItems = injectedMoreMenuItems; + } + return options; } protected final boolean isNotUseDefaultMeetingOptions() { return !useDefaultMeetingOptions.isChecked(); } + public void clear() { + if (injectedMoreMenuItems != null) { + injectedMoreMenuItems.clear(); + } + } + protected final boolean isChecked(int index) { return checkBoxes[index].isChecked(); } @@ -62,10 +167,30 @@ public void onResult(int resultCode, String resultMsg, Void resultData) { if (resultCode == NEMeetingError.ERROR_CODE_NO_AUTH) { Toast.makeText(context, "当前账号已在其他设备上登录", Toast.LENGTH_SHORT).show(); SdkAuthenticator.getInstance().logout(false); + } else if (resultCode == NEMeetingError.ERROR_CODE_FAILED) { + Toast.makeText(context, resultMsg, Toast.LENGTH_SHORT).show(); + hideLoading(); } else { super.onResult(resultCode, resultMsg, resultData); } + if (injectedMoreMenuItems != null) { + injectedMoreMenuItems.clear(); + } } + } + + private NEMeetingStatusListener listener = event -> { + if (event.status == NEMeetingStatus.MEETING_STATUS_DISCONNECTING) { + clear(); + // 增加会议断开连接提示。 + getActivity().runOnUiThread(() -> Toast.makeText(getActivity(), "会议已断开连接", Toast.LENGTH_SHORT).show()); + } + }; + + @Override + public void onDestroy() { + super.onDestroy(); + NEMeetingSDK.getInstance().getMeetingService().removeMeetingStatusListener(listener); } } diff --git a/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/StartMeetingFragment.java b/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/StartMeetingFragment.java index 6cf967fa..3f01878b 100644 --- a/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/StartMeetingFragment.java +++ b/SampleCode/Android/app/src/main/java/com/netease/meetinglib/demo/fragment/StartMeetingFragment.java @@ -14,10 +14,10 @@ import com.netease.meetinglib.sdk.NEAccountService; import com.netease.meetinglib.sdk.NEMeetingError; import com.netease.meetinglib.sdk.NEMeetingSDK; -import com.netease.meetinglib.sdk.NEMeetingService; import com.netease.meetinglib.sdk.NEStartMeetingOptions; import com.netease.meetinglib.sdk.NEStartMeetingParams; + public class StartMeetingFragment extends MeetingBaseFragment { private String personalMeetingId; @@ -29,11 +29,12 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { usePersonalMeetingId.setOnCheckedChangeListener((buttonView, isChecked) -> { determineMeetingId(); }); + } @Override protected String[] getEditorLabel() { - return new String[]{"会议号(留空或使用个人会议号)","昵称"}; + return new String[]{"会议号(留空或使用个人会议号)", "昵称", "100", "tittle"}; } @Override @@ -48,18 +49,14 @@ protected void performAction(String first, String second) { params.displayName = second; NEStartMeetingOptions options = null; if (isNotUseDefaultMeetingOptions()) { - options = new NEStartMeetingOptions(); - options.noVideo = !isChecked(0); - options.noAudio = !isChecked(1); - options.showMeetingTime = true; - } - NEMeetingService meetingService = NEMeetingSDK.getInstance().getMeetingService(); - if (meetingService != null) { - meetingService.startMeeting(getActivity(), params, options, new MeetingCallback()); - showLoading("正在创建会议..."); + options = (NEStartMeetingOptions) getMeetingOptions(new NEStartMeetingOptions()); } + + showLoading("正在创建会议..."); + getMeetingService().startMeeting(getActivity(), params, options, new MeetingCallback()); } + private void determineMeetingId() { if (usePersonalMeetingId.isChecked()) { if (!TextUtils.isEmpty(personalMeetingId)) { @@ -90,4 +87,10 @@ private void onGetPersonalMeetingIdError() { usePersonalMeetingId.setChecked(false); Toast.makeText(getActivity(), "获取个人会议号失败", Toast.LENGTH_SHORT).show(); } + + + @Override + public void onDestroy() { + super.onDestroy(); + } } diff --git a/SampleCode/Android/app/src/main/res/layout/fragment_base.xml b/SampleCode/Android/app/src/main/res/layout/fragment_base.xml index 60b7bf4a..050db138 100644 --- a/SampleCode/Android/app/src/main/res/layout/fragment_base.xml +++ b/SampleCode/Android/app/src/main/res/layout/fragment_base.xml @@ -49,9 +49,9 @@ android:layout_width="200dp" android:layout_height="60dp" app:layout_constraintLeft_toLeftOf="parent" - app:layout_constraintTop_toTopOf="parent" + app:layout_constraintTop_toBottomOf="@id/secondEditor" app:layout_constraintRight_toRightOf="parent" - app:layout_constraintBottom_toBottomOf="parent" + android:layout_marginTop="30dp" tools:text="登录" android:textSize="20sp" /> diff --git a/SampleCode/Android/app/src/main/res/layout/fragment_meeting_base.xml b/SampleCode/Android/app/src/main/res/layout/fragment_meeting_base.xml index 2d4e791c..000d4cad 100644 --- a/SampleCode/Android/app/src/main/res/layout/fragment_meeting_base.xml +++ b/SampleCode/Android/app/src/main/res/layout/fragment_meeting_base.xml @@ -1,103 +1,169 @@ - - + android:layout_height="match_parent"> - + app:layout_constraintTop_toBottomOf="@id/usePersonalMeetingId" + tools:text="加入会议" /> - + android:textSize="14sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintRight_toRightOf="parent" + tools:text="增加菜单" /> + app:layout_constraintTop_toBottomOf="@id/secondEditor" /> + tools:checked="true" /> + android:enabled="false" + android:text="使用个人会议号" + app:layout_constraintLeft_toLeftOf="@id/videoOption" + app:layout_constraintTop_toBottomOf="@id/videoOption" /> + + + android:text="入会时关闭聊天菜单" + app:layout_constraintLeft_toLeftOf="@id/usePersonalMeetingId" + app:layout_constraintTop_toBottomOf="@id/usePersonalMeetingId" + tools:checked="true" /> -