Skip to content

Commit

Permalink
更新插件
Browse files Browse the repository at this point in the history
  • Loading branch information
1019238091 committed Feb 25, 2019
1 parent 415183f commit eb71e10
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 6 deletions.
2 changes: 1 addition & 1 deletion android/settings.gradle
@@ -1 +1 @@
rootProject.name = 'moblink'
rootProject.name = 'moblink'
86 changes: 81 additions & 5 deletions android/src/main/java/com/example/moblink/MoblinkPlugin.java
@@ -1,35 +1,68 @@
package com.example.moblink;

import android.app.Activity;
import android.util.Log;

import com.mob.moblink.ActionListener;
import com.mob.moblink.MobLink;
import com.mob.moblink.Scene;
import com.mob.moblink.SceneRestorable;

import java.util.HashMap;

import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;

/** MoblinkPlugin */
public class MoblinkPlugin implements MethodCallHandler {
public class MoblinkPlugin extends Object implements MethodCallHandler, SceneRestorable, EventChannel.StreamHandler {
private static final String getMobId = "getMobId";
private static final String restoreScene = "restoreScene";

private static final String EventChannel = "JAVA_TO_FLUTTER";
private EventChannel.EventSink eventSink;

private static Activity activity;

private Result mresult; //时间紧,暂时写一个比较low的回调

private Activity mActivity;

private HashMap<String, Object> onReturnSceneDataMap;

private MoblinkPlugin(Activity activity) {
this.mActivity = activity;
}

/**
* 提供给java层传递数据到flutter层的方法
* **/
public void setEvent(Object data) {
if (eventSink != null) {
eventSink.success(data);
} else {
Log.e("QQQ", " ===== FlutterEventChannel.eventSink 为空 需要检查一下 ===== ");
}
}

/** Plugin registration. */
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "com.yoozoo.mob/moblink");
channel.setMethodCallHandler(new MoblinkPlugin());
channel.setMethodCallHandler(new MoblinkPlugin(registrar.activity()));
activity = registrar.activity();

final EventChannel eventChannel = new EventChannel(registrar.messenger(), EventChannel);
MoblinkPlugin instance = new MoblinkPlugin(registrar.activity());
eventChannel.setStreamHandler(instance);
}

@Override
public void onMethodCall(MethodCall call, Result result) {
//TODO test
Log.e("QQQ", " onMethodCall " + call.method);

MobLink.setActivityDelegate(activity, MoblinkPlugin.this);
/* if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else {
Expand All @@ -41,6 +74,7 @@ public void onMethodCall(MethodCall call, Result result) {
getMobId(call, result);
break;
case restoreScene:
restoreScene(call, result);
break;
}

Expand Down Expand Up @@ -74,8 +108,50 @@ public void onError(Throwable throwable) {
}

private void restoreScene(MethodCall call, Result result) {
this.mresult = result;
Log.e("QQQ", " 测试result " + result);
if (result != null) {
if (onReturnSceneDataMap != null) {
result.success(onReturnSceneDataMap);
Log.e("QQQ", " onReturnSceneDataMap 回调成功");
} else {
Log.e("QQQ", " onReturnSceneDataMap 为空 不需要回调");
}
} else {
Log.e("QQQ", " result 未空");
}
}

@Override
public void onReturnSceneData(Scene scene) {
Log.e("QQQ", " onReturnSceneData path===> " + scene.getPath() + " params===> " + scene.getParams());
onReturnSceneDataMap = new HashMap<>();
onReturnSceneDataMap.put("path", scene.getPath());
onReturnSceneDataMap.put("params", scene.getParams());
//setEvent(hashMap);

/*if (mresult != null) {
if (onReturnSceneDataMap != null) {
mresult.success(onReturnSceneDataMap);
Log.e("QQQ", "onReturnSceneData 执行完成,回调到flutter层 " );
} else {
Log.e("QQQ", "onReturnSceneDataMap 为空 " );
}
} else {
Log.e("QQQ", " mresult 为空 " + mresult);
}*/

}

@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
this.eventSink = eventSink;
Log.e("QQQ", " onListen " + eventSink.toString());
}

@Override
public void onCancel(Object o) {
//this.eventSink = null;
Log.e("QQQ", " onCancel ");
}
}
23 changes: 23 additions & 0 deletions lib/moblink_interface.dart
Expand Up @@ -8,6 +8,24 @@ class Moblink {
static const MethodChannel _channel =
const MethodChannel('com.yoozoo.mob/moblink');

static const EventChannel java_to_flutter = const EventChannel("JAVA_TO_FLUTTER");

static Future<dynamic> listenNativeEvent() {
print("QQQ 我执行了");
java_to_flutter.receiveBroadcastStream().listen(_onEvent, onError:_onError);
print("QQQ 我执行完了");
}

static Future<dynamic> _onEvent(Object event) {
print("QQQ _onEvent");
print("onEvent: $event ");
}

static Future<dynamic> _onError(Object error) {
print("QQQ _onError");
print(error);
}

static Future<dynamic> getMobId(MLSDKScene scene,
Function(String mobid, String domain, MLSDKError error) result) {
Map args = {"path": scene.path, "params": scene.params};
Expand Down Expand Up @@ -40,6 +58,11 @@ class Moblink {
});
return callback;
}





}

class MLSDKScene {
Expand Down

0 comments on commit eb71e10

Please sign in to comment.