Skip to content

Commit 423b14a

Browse files
author
zhaoyongqiang
committed
Merge branch 'dev/4.0.0-GA' of github.com:AgoraIO/API-Examples into dev/4.0.0-GA
2 parents ab04938 + acf74e8 commit 423b14a

39 files changed

Lines changed: 370 additions & 150 deletions

Android/APIExample/app/src/main/java/io/agora/api/example/common/BaseFragment.java

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
public class BaseFragment extends Fragment
1414
{
1515
protected Handler handler;
16+
private AlertDialog mAlertDialog;
17+
private String mAlertDialogMsg;
1618

1719
@Override
1820
public void onCreate(@Nullable Bundle savedInstanceState)
@@ -21,29 +23,58 @@ public void onCreate(@Nullable Bundle savedInstanceState)
2123
handler = new Handler(Looper.getMainLooper());
2224
}
2325

24-
protected void showAlert(String message)
25-
{
26-
Context context = getContext();
27-
if (context == null) {
28-
return;
29-
}
26+
protected void showAlert(String message) {
3027

31-
new AlertDialog.Builder(context).setTitle("Tips").setMessage(message)
32-
.setPositiveButton("OK", (dialog, which) -> dialog.dismiss())
33-
.show();
28+
runOnUIThread(() -> {
29+
Context context = getContext();
30+
if(context == null){
31+
return;
32+
}
33+
if (mAlertDialog == null) {
34+
mAlertDialog = new AlertDialog.Builder(context).setTitle("Tips")
35+
.setPositiveButton("OK", (dialog, which) -> dialog.dismiss())
36+
.create();
37+
}
38+
if (!message.equals(mAlertDialogMsg)) {
39+
mAlertDialogMsg = message;
40+
mAlertDialog.setMessage(mAlertDialogMsg);
41+
mAlertDialog.show();
42+
}
43+
});
3444
}
3545

3646
protected final void showLongToast(final String msg)
3747
{
38-
handler.post(new Runnable()
39-
{
40-
@Override
41-
public void run()
42-
{
43-
if (BaseFragment.this == null || getContext() == null)
44-
{return;}
45-
Toast.makeText(getContext().getApplicationContext(), msg, Toast.LENGTH_LONG).show();
48+
runOnUIThread(() -> {
49+
Context context = getContext();
50+
if(context == null){
51+
return;
4652
}
53+
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
4754
});
4855
}
56+
57+
protected final void runOnUIThread(Runnable runnable){
58+
this.runOnUIThread(runnable, 0);
59+
}
60+
61+
protected final void runOnUIThread(Runnable runnable, long delay){
62+
if(handler != null && runnable != null){
63+
if (delay <= 0 && handler.getLooper().getThread() == Thread.currentThread()) {
64+
runnable.run();
65+
}else{
66+
handler.postDelayed(runnable, delay);
67+
}
68+
}
69+
}
70+
71+
@Override
72+
public void onDestroy() {
73+
super.onDestroy();
74+
handler.removeCallbacksAndMessages(null);
75+
if(mAlertDialog != null){
76+
mAlertDialog.dismiss();
77+
mAlertDialog = null;
78+
}
79+
}
4980
}

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/ChannelEncryption.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public void onClick(View v)
195195
* 2:If you call the leaveChannel method during CDN live streaming, the SDK
196196
* triggers the removeInjectStreamUrl method.*/
197197
engine.leaveChannel();
198+
engine.stopPreview();
198199
join.setText(getString(R.string.join));
199200
et_password.setEnabled(true);
200201
encry_mode.setEnabled(true);

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/ContentInspect.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,8 @@ private void joinChannel(String channelId) {
212212

213213
// Setup content inspect options
214214
ContentInspectConfig.ContentInspectModule contentInspectModule = new ContentInspectConfig.ContentInspectModule();
215-
contentInspectModule.vendor = ContentInspectConfig.CONTENT_INSPECT_VENDOR_AGORA;
216-
contentInspectModule.token = null;
217215
contentInspectModule.type = ContentInspectConfig.CONTENT_INSPECT_TYPE_MODERATION;
218-
contentInspectModule.frequency = 1;
216+
contentInspectModule.interval = 1;
219217
ContentInspectConfig contentInspectConfig = new ContentInspectConfig();
220218
contentInspectConfig.modules[0] = contentInspectModule;
221219
contentInspectConfig.moduleCount = 1;

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/CustomRemoteVideoRender.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.yanzhenjie.permission.AndPermission;
2626
import com.yanzhenjie.permission.runtime.Permission;
2727

28-
import java.util.Locale;
2928
import java.util.concurrent.Callable;
3029

3130
import javax.microedition.khronos.egl.EGLConfig;
@@ -94,13 +93,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
9493
view.findViewById(R.id.btn_join).setOnClickListener(this);
9594
fl_local = view.findViewById(R.id.fl_local);
9695
fl_remote = view.findViewById(R.id.fl_remote);
97-
view.findViewById(R.id.btn_take_shot).setOnClickListener(v -> {
98-
if(remoteUid != 0){
99-
engine.takeSnapshot(remoteUid, "/sdcard/APIExample_snapshot_" + et_channel.getText().toString() + "_" + remoteUid + ".png");
100-
}else{
101-
showLongToast(getString(R.string.remote_screenshot_tip));
102-
}
103-
});
10496
}
10597

10698
@Override
@@ -450,17 +442,6 @@ public void onUserOffline(int uid, int reason) {
450442
mSurfaceView.requestRender();
451443
remoteUid = 0;
452444
}
453-
454-
@Override
455-
public void onSnapshotTaken(String channel, int uid, String filePath, int width, int height, int errCode) {
456-
super.onSnapshotTaken(channel, uid, filePath, width, height, errCode);
457-
Log.d(TAG, String.format(Locale.US, "onSnapshotTaken channel=%s, uid=%d, filePath=%s, width=%d, height=%d, errorCode=%d", channel, uid, filePath, width, height, errCode));
458-
if(errCode == 0){
459-
showLongToast("SnapshotTaken path=" + filePath);
460-
}else{
461-
showLongToast("SnapshotTaken error=" + RtcEngine.getErrorDescription(errCode));
462-
}
463-
}
464445
};
465446

466447
IVideoFrameObserver videoFrameObserver = new IVideoFrameObserver() {

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/JoinMultipleChannel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ public void onClick(View v)
187187
* 2:If you call the leaveChannel method during CDN live streaming, the SDK
188188
* triggers the removeInjectStreamUrl method.*/
189189
engine.leaveChannel();
190+
engine.leaveChannelEx(rtcConnection2);
191+
engine.stopPreview();
190192
join.setText(getString(R.string.join));
191193
}
192194
}

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/LiveStreaming.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.yanzhenjie.permission.AndPermission;
2424
import com.yanzhenjie.permission.runtime.Permission;
2525

26+
import java.util.Locale;
27+
2628
import io.agora.api.example.MainApplication;
2729
import io.agora.api.example.R;
2830
import io.agora.api.example.annotation.Example;
@@ -39,7 +41,7 @@
3941

4042
/**
4143
* This demo demonstrates how to make a one-to-one video call
42-
*
44+
* <p>
4345
* By default, Everyone is a host, entered a channel will see yourself in the background( the big one ).
4446
* click the frame will switch the position.
4547
* When turn the Co-host on, others will see you.
@@ -86,6 +88,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
8688
view.findViewById(R.id.foreground_video).setOnClickListener(this);
8789
foreGroundVideo = view.findViewById(R.id.background_video);
8890
backGroundVideo = view.findViewById(R.id.foreground_video);
91+
view.findViewById(R.id.btn_take_shot).setOnClickListener(this);
8992
}
9093

9194
@Override
@@ -230,6 +233,12 @@ public void onClick(View v) {
230233
localView.setZOrderMediaOverlay(true);
231234
localView.setZOrderOnTop(true);
232235
}
236+
} else if (v.getId() == R.id.btn_take_shot) {
237+
if (remoteUid != 0) {
238+
engine.takeSnapshot(remoteUid, "/sdcard/APIExample_snapshot_" + et_channel.getText().toString() + "_" + remoteUid + ".png");
239+
} else {
240+
showLongToast(getString(R.string.remote_screenshot_tip));
241+
}
233242
}
234243

235244
}
@@ -472,5 +481,16 @@ public void run() {
472481
}
473482
});
474483
}
484+
485+
@Override
486+
public void onSnapshotTaken(int uid, String filePath, int width, int height, int errCode) {
487+
super.onSnapshotTaken(uid, filePath, width, height, errCode);
488+
Log.d(TAG, String.format(Locale.US, "onSnapshotTaken uid=%d, filePath=%s, width=%d, height=%d, errorCode=%d", uid, filePath, width, height, errCode));
489+
if(errCode == 0){
490+
showLongToast("SnapshotTaken path=" + filePath);
491+
}else{
492+
showLongToast("SnapshotTaken error=" + RtcEngine.getErrorDescription(errCode));
493+
}
494+
}
475495
};
476496
}

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/SwitchCameraScreenShare.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,12 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
158158
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
159159
ScreenCaptureParameters parameters = new ScreenCaptureParameters();
160160
parameters.videoCaptureParameters.framerate = DEFAULT_SHARE_FRAME_RATE;
161+
parameters.captureAudio = true;
161162
// start screen capture and update options
162163
engine.startScreenCapture(parameters);
163164
options.publishScreenCaptureVideo = true;
164165
options.publishCameraTrack = false;
166+
options.publishScreenCaptureAudio = true;
165167
engine.updateChannelMediaOptions(options);
166168
addScreenSharePreview();
167169
}

Android/APIExample/app/src/main/res/layout/fragment_custom_remoterender.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@
1919
android:layout_alignParentTop="true"
2020
android:layout_alignParentEnd="true" />
2121

22-
<Button
23-
android:id="@+id/btn_take_shot"
24-
android:layout_width="wrap_content"
25-
android:layout_height="wrap_content"
26-
android:layout_above="@+id/ll_join"
27-
android:layout_alignParentEnd="true"
28-
android:layout_margin="10dp"
29-
android:text="@string/remote_screenshot"/>
30-
3122
<LinearLayout
3223
android:id="@+id/ll_join"
3324
android:layout_width="match_parent"

Android/APIExample/app/src/main/res/layout/fragment_join_multi_channel.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
android:layout_height="match_parent"
4040
android:layout_alignParentStart="true"
4141
android:layout_alignTop="@id/strut1"
42-
android:layout_alignBottom="@id/ll_join"
42+
android:layout_above="@id/ll_join"
4343
android:layout_alignParentEnd="true" />
4444

4545
<LinearLayout

Android/APIExample/app/src/main/res/layout/fragment_live_streaming.xml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,25 @@
2121
android:layout_alignParentEnd="true" />
2222

2323
<androidx.appcompat.widget.AppCompatButton
24-
android:id="@+id/btn_latency"
24+
android:id="@+id/btn_take_shot"
2525
android:layout_width="wrap_content"
2626
android:layout_height="wrap_content"
27-
android:text="@string/enable_low_latency"
28-
android:enabled="false"
27+
android:layout_above="@+id/btn_latency"
2928
android:layout_alignParentEnd="true"
29+
android:layout_marginEnd="16dp"
30+
android:layout_marginBottom="16dp"
31+
android:text="@string/remote_screenshot"/>
32+
33+
<androidx.appcompat.widget.AppCompatButton
34+
android:id="@+id/btn_latency"
35+
android:layout_width="wrap_content"
36+
android:layout_height="wrap_content"
3037
android:layout_above="@id/btn_publish"
38+
android:layout_alignParentEnd="true"
3139
android:layout_marginEnd="16dp"
32-
android:layout_marginBottom="16dp"/>
40+
android:layout_marginBottom="16dp"
41+
android:enabled="false"
42+
android:text="@string/enable_low_latency" />
3343

3444
<androidx.appcompat.widget.AppCompatButton
3545
android:id="@+id/btn_publish"

0 commit comments

Comments
 (0)