Skip to content

Commit

Permalink
Merge pull request #17 from smartzhao/master
Browse files Browse the repository at this point in the history
[Android] [1.2.0] 文档和samplecode 更新
  • Loading branch information
liuqijun authored Sep 4, 2020
2 parents eba7acb + 1f8bec7 commit f7670c0
Show file tree
Hide file tree
Showing 14 changed files with 546 additions and 129 deletions.
1 change: 0 additions & 1 deletion SampleCode/Android/app/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion SampleCode/Android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
37 changes: 16 additions & 21 deletions SampleCode/Android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.netease.meetinglib.demo">

<!-- 网络相关 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <!-- 读写文件 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 多媒体 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <!-- 8.0 系统上需要 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name=".MeetingApplication"
android:allowBackup="true"
Expand All @@ -22,23 +10,30 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".TestActivity"></activity>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:resizeableActivity="false"
>
android:resizeableActivity="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:label="会议设置"
android:name=".MeetingSettingsActivity" />

android:name=".MeetingSettingsActivity"
android:label="会议设置" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 读写文件 -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- 多媒体 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" /> <!-- 8.0 系统上需要 -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.netease.meetinglib.demo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class TestActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
//关闭当前测试界面
public void finish(View view) {
finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ protected BaseFragment(@LayoutRes int contentLayoutId) {

private LoadingFragment loadingFragment;

private EditText[] editorArray = new EditText[2];
private EditText[] editorArray = new EditText[4];

protected abstract String[] getEditorLabel();

protected abstract String getActionLabel();

protected abstract void performAction(String first, String second);


protected final EditText getEditor(int index) {
return editorArray[index];
}
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {

@Override
protected String[] getEditorLabel() {
return new String[]{"会议号","昵称"};
return new String[]{"会议号", "昵称", "100", "tittle"};
}

@Override
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,33 @@

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;

import androidx.annotation.Nullable;

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 {

Expand All @@ -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<NEMeetingMenuItem> 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<NEMeetingInfo>() {
@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();
}
Expand All @@ -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);
}
}
Loading

0 comments on commit f7670c0

Please sign in to comment.