-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Convert kotlin to java to avoid kotlin version conflict (#2)
* feat: Convert kotlin to java to avoid kotlin version conflict
- Loading branch information
1 parent
e7d6c84
commit e972026
Showing
16 changed files
with
300 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ on: | |
pull_request: | ||
branches: | ||
- main | ||
- release/** | ||
|
||
jobs: | ||
flutter_codestyle_check: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
android/src/main/java/io/agora/agora_rtc_ng/AgoraPlatformViewFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package io.agora.agora_rtc_ng; | ||
|
||
import android.content.Context; | ||
import android.view.SurfaceView; | ||
import android.view.TextureView; | ||
import android.view.View; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import io.agora.iris.IrisApiEngine; | ||
import io.flutter.plugin.common.BinaryMessenger; | ||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
import io.flutter.plugin.common.StandardMessageCodec; | ||
import io.flutter.plugin.platform.PlatformView; | ||
import io.flutter.plugin.platform.PlatformViewFactory; | ||
|
||
public class AgoraPlatformViewFactory extends PlatformViewFactory { | ||
|
||
private final String viewType; | ||
private final BinaryMessenger messenger; | ||
private final PlatformViewProvider viewProvider; | ||
|
||
AgoraPlatformViewFactory( | ||
String viewType, | ||
BinaryMessenger messenger, | ||
PlatformViewProvider viewProvider) { | ||
super(StandardMessageCodec.INSTANCE); | ||
this.viewType = viewType; | ||
this.messenger = messenger; | ||
this.viewProvider = viewProvider; | ||
} | ||
|
||
interface PlatformViewProvider { | ||
View provide(Context context); | ||
} | ||
|
||
public static class PlatformViewProviderTextureView implements PlatformViewProvider { | ||
|
||
@Override | ||
public View provide(Context context) { | ||
return new TextureView(context); | ||
} | ||
} | ||
|
||
public static class PlatformViewProviderSurfaceView implements PlatformViewProvider { | ||
|
||
@Override | ||
public View provide(Context context) { | ||
return new SurfaceView(context); | ||
} | ||
} | ||
|
||
static class AgoraPlatformView implements PlatformView, MethodChannel.MethodCallHandler { | ||
private View innerView; | ||
|
||
private final MethodChannel methodChannel; | ||
|
||
|
||
private long platformViewPtr; | ||
|
||
AgoraPlatformView(Context context, | ||
String viewType, | ||
int viewId, | ||
PlatformViewProvider viewProvider, | ||
BinaryMessenger messenger) { | ||
methodChannel = new MethodChannel(messenger, "agora_rtc_ng/" + viewType + "_" + viewId); | ||
methodChannel.setMethodCallHandler(this); | ||
innerView = viewProvider.provide(context); | ||
|
||
platformViewPtr = IrisApiEngine.GetJObjectAddress(innerView); | ||
} | ||
|
||
@Override | ||
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { | ||
if (call.method.equals("getNativeViewPtr")) { | ||
result.success(platformViewPtr); | ||
} else if (call.method.equals("deleteNativeViewPtr")) { | ||
if (platformViewPtr != 0L) { | ||
IrisApiEngine.FreeJObjectByAddress(platformViewPtr); | ||
platformViewPtr = 0; | ||
} | ||
innerView = null; | ||
result.success(0); | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View getView() { | ||
return innerView; | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
|
||
} | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public PlatformView create(@Nullable Context context, int viewId, @Nullable Object args) { | ||
return new AgoraPlatformView( | ||
context, | ||
viewType, | ||
viewId, | ||
viewProvider, | ||
messenger | ||
); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
android/src/main/java/io/agora/agora_rtc_ng/AgoraRtcNgPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package io.agora.agora_rtc_ng; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.io.IOException; | ||
import java.lang.ref.WeakReference; | ||
|
||
import io.flutter.embedding.engine.plugins.FlutterPlugin; | ||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
|
||
public class AgoraRtcNgPlugin implements FlutterPlugin, MethodChannel.MethodCallHandler { | ||
|
||
static { | ||
System.loadLibrary("AgoraRtcWrapper"); | ||
} | ||
|
||
private MethodChannel channel; | ||
private WeakReference<FlutterPluginBinding> flutterPluginBindingRef; | ||
private VideoViewController videoViewController; | ||
|
||
@Override | ||
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { | ||
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "agora_rtc_ng"); | ||
channel.setMethodCallHandler(this); | ||
flutterPluginBindingRef = new WeakReference<>(flutterPluginBinding); | ||
|
||
flutterPluginBinding.getPlatformViewRegistry().registerViewFactory( | ||
"AgoraTextureView", | ||
new AgoraPlatformViewFactory( | ||
"AgoraTextureView", | ||
flutterPluginBinding.getBinaryMessenger(), | ||
new AgoraPlatformViewFactory.PlatformViewProviderTextureView())); | ||
|
||
flutterPluginBinding.getPlatformViewRegistry().registerViewFactory( | ||
"AgoraSurfaceView", | ||
new AgoraPlatformViewFactory( | ||
"AgoraSurfaceView", | ||
flutterPluginBinding.getBinaryMessenger(), | ||
new AgoraPlatformViewFactory.PlatformViewProviderSurfaceView())); | ||
|
||
videoViewController = new VideoViewController(flutterPluginBinding.getBinaryMessenger()); | ||
} | ||
|
||
@Override | ||
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { | ||
channel.setMethodCallHandler(null); | ||
videoViewController.dispose(); | ||
} | ||
|
||
@Override | ||
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { | ||
if ("getAssetAbsolutePath".equals(call.method)) { | ||
getAssetAbsolutePath(call, result); | ||
} else { | ||
result.notImplemented(); | ||
} | ||
} | ||
|
||
private void getAssetAbsolutePath(MethodCall call, MethodChannel.Result result) { | ||
final String path = call.arguments(); | ||
|
||
if (path != null) { | ||
if (this.flutterPluginBindingRef.get() != null | ||
) { | ||
final String assetKey = this.flutterPluginBindingRef.get() | ||
.getFlutterAssets() | ||
.getAssetFilePathByName(path); | ||
try { | ||
this.flutterPluginBindingRef.get().getApplicationContext() | ||
.getAssets() | ||
.openFd(assetKey) | ||
.close(); | ||
result.success("/assets/" + assetKey); | ||
return; | ||
} catch (IOException e) { | ||
result.error(e.getClass().getSimpleName(), e.getMessage(), e.getCause()); | ||
return; | ||
} | ||
} | ||
} | ||
result.error("IllegalArgumentException", "The parameter should not be null", null); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
android/src/main/java/io/agora/agora_rtc_ng/VideoViewController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.agora.agora_rtc_ng; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import io.flutter.plugin.common.BinaryMessenger; | ||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
|
||
public class VideoViewController implements MethodChannel.MethodCallHandler { | ||
|
||
private final MethodChannel methodChannel; | ||
|
||
VideoViewController(BinaryMessenger binaryMessenger) { | ||
methodChannel = new MethodChannel(binaryMessenger, "agora_rtc_ng/video_view_controller"); | ||
methodChannel.setMethodCallHandler(this); | ||
} | ||
|
||
private long createPlatformRender(){ | ||
return 0L; | ||
} | ||
|
||
private boolean destroyPlatformRender(long platformRenderId) { | ||
return true; | ||
} | ||
|
||
private long createTextureRender() { | ||
return 0L; | ||
} | ||
|
||
private boolean destroyTextureRender(long textureId){ | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { | ||
switch (call.method) { | ||
case "attachVideoFrameBufferManager": | ||
case "detachVideoFrameBufferManager": | ||
result.success(true); | ||
break; | ||
|
||
case "createTextureRender": | ||
case "destroyTextureRender": | ||
case "updateTextureRenderData": | ||
default: | ||
result.notImplemented(); | ||
break; | ||
} | ||
} | ||
|
||
public void dispose() { | ||
methodChannel.setMethodCallHandler(null); | ||
} | ||
} |
Oops, something went wrong.