add android interface
parent
e1420716b5
commit
e8be3294a0
|
@ -1,3 +1,5 @@
|
|||
.idea
|
||||
publish.sh
|
||||
.DS_Store
|
||||
.dart_tool/
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Dart SDK">
|
||||
<CLASSES>
|
||||
<root url="file:///opt/flutter/bin/cache/dart-sdk/lib/async" />
|
||||
<root url="file:///opt/flutter/bin/cache/dart-sdk/lib/collection" />
|
||||
<root url="file:///opt/flutter/bin/cache/dart-sdk/lib/convert" />
|
||||
<root url="file:///opt/flutter/bin/cache/dart-sdk/lib/core" />
|
||||
<root url="file:///opt/flutter/bin/cache/dart-sdk/lib/developer" />
|
||||
<root url="file:///opt/flutter/bin/cache/dart-sdk/lib/html" />
|
||||
<root url="file:///opt/flutter/bin/cache/dart-sdk/lib/io" />
|
||||
<root url="file:///opt/flutter/bin/cache/dart-sdk/lib/isolate" />
|
||||
<root url="file:///opt/flutter/bin/cache/dart-sdk/lib/math" />
|
||||
<root url="file:///opt/flutter/bin/cache/dart-sdk/lib/mirrors" />
|
||||
<root url="file:///opt/flutter/bin/cache/dart-sdk/lib/typed_data" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -1,9 +0,0 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Flutter for Android">
|
||||
<CLASSES>
|
||||
<root url="jar:///opt/flutter/bin/cache/artifacts/engine/android-arm/flutter.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/mop.iml" filepath="$PROJECT_DIR$/mop.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/android/mop_android.iml" filepath="$PROJECT_DIR$/android/mop_android.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/example/android/mop_example_android.iml" filepath="$PROJECT_DIR$/example/android/mop_example_android.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="example/lib/main.dart" type="FlutterRunConfigurationType" factoryName="Flutter">
|
||||
<option name="filePath" value="$PROJECT_DIR$/example/lib/main.dart" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
|
@ -1,45 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="FileEditorManager">
|
||||
<leaf>
|
||||
<file leaf-file-name="mop.dart" pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/lib/mop.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="0">
|
||||
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file leaf-file-name="main.dart" pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="0">
|
||||
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
</leaf>
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<editor active="true" />
|
||||
<layout>
|
||||
<window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
||||
</layout>
|
||||
</component>
|
||||
<component name="ProjectView">
|
||||
<navigator currentView="ProjectPane" proportions="" version="1">
|
||||
</navigator>
|
||||
<panes>
|
||||
<pane id="ProjectPane">
|
||||
<option name="show-excluded-files" value="false" />
|
||||
</pane>
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
<property name="dart.analysis.tool.window.force.activate" value="true" />
|
||||
<property name="show.migrate.to.gradle.popup" value="false" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,3 +1,10 @@
|
|||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
group 'com.finogeeks.mop'
|
||||
version '1.0'
|
||||
|
||||
|
@ -5,10 +12,21 @@ buildscript {
|
|||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
maven {
|
||||
url "https://gradle.finogeeks.club/repository/finogeeks/"
|
||||
credentials {
|
||||
username "xiaoyu"
|
||||
password "xy123456"
|
||||
}
|
||||
}
|
||||
maven { url "https://jitpack.io" }
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
classpath 'com.android.tools.build:gradle:3.4.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,19 +34,50 @@ rootProject.allprojects {
|
|||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
maven {
|
||||
url "https://gradle.finogeeks.club/repository/finogeeks/"
|
||||
credentials {
|
||||
username "xiaoyu"
|
||||
password "xy123456"
|
||||
}
|
||||
}
|
||||
maven { url "https://jitpack.io" }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
minSdkVersion 21
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
lintOptions {
|
||||
disable 'InvalidPackage'
|
||||
}
|
||||
}
|
||||
|
||||
kapt {
|
||||
arguments {
|
||||
arg("moduleName", project.getName())
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'com.finogeeks.lib:finapplet:2.0.51'
|
||||
implementation 'org.greenrobot:greendao:3.2.2'
|
||||
|
||||
}
|
||||
|
|
|
@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
-keep class com.finogeeks.** {*;}
|
||||
|
||||
# tbs
|
||||
-keep class com.tencent.smtt.** {*;}
|
||||
-keep class com.tencent.tbs.** {*;}
|
|
@ -0,0 +1,29 @@
|
|||
package com.finogeeks.mop;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.flutter.plugin.common.EventChannel;
|
||||
|
||||
|
||||
public class MopEventStream implements EventChannel.StreamHandler {
|
||||
EventChannel.EventSink mEventSlink;
|
||||
@Override
|
||||
public void onListen(Object o, EventChannel.EventSink eventSink) {
|
||||
mEventSlink = eventSink;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Object o) {
|
||||
mEventSlink = null;
|
||||
}
|
||||
public void send(String channel,String event,Object body) {
|
||||
if (mEventSlink != null) {
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("channel",channel);
|
||||
map.put("event",event);
|
||||
map.put("body",body);
|
||||
mEventSlink.success(map);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +1,99 @@
|
|||
package com.finogeeks.mop;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.finogeeks.mop.interfaces.Event;
|
||||
import com.finogeeks.mop.interfaces.FlutterInterface;
|
||||
import com.finogeeks.mop.interfaces.ICallback;
|
||||
import com.finogeeks.mop.service.MopPluginService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
import io.flutter.plugin.common.PluginRegistry.Registrar;
|
||||
|
||||
/** MopPlugin */
|
||||
public class MopPlugin implements MethodCallHandler {
|
||||
/** Plugin registration. */
|
||||
private static final String LOG_TAG = MopPlugin.class.getSimpleName();
|
||||
|
||||
private static final String CHANNEL = "mop";
|
||||
private PluginRegistry.Registrar registrar;
|
||||
private FlutterInterface flutterInterface;
|
||||
private MopPluginDelegate delegate;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Plugin registration.
|
||||
*/
|
||||
public static void registerWith(Registrar registrar) {
|
||||
final MethodChannel channel = new MethodChannel(registrar.messenger(), "mop");
|
||||
channel.setMethodCallHandler(new MopPlugin());
|
||||
final MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
|
||||
final MopPluginDelegate delegate = new MopPluginDelegate(registrar.activity());
|
||||
final MopPlugin instance = new MopPlugin(registrar,delegate);
|
||||
channel.setMethodCallHandler(instance);
|
||||
final EventChannel eventChannel=new EventChannel(registrar.messenger(),"plugins.mop.finogeeks.com/mop_event");
|
||||
MopEventStream mopEventStream = new MopEventStream();
|
||||
eventChannel.setStreamHandler(mopEventStream);
|
||||
MopPluginService.getInstance().initialize(registrar.activity(),mopEventStream);
|
||||
|
||||
}
|
||||
|
||||
MopPlugin(PluginRegistry.Registrar registrar,MopPluginDelegate delegate) {
|
||||
this.registrar = registrar;
|
||||
this.flutterInterface = new FlutterInterface();
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMethodCall(MethodCall call, Result result) {
|
||||
if (call.method.equals("getPlatformVersion")) {
|
||||
result.success("Android " + android.os.Build.VERSION.RELEASE);
|
||||
} else {
|
||||
public void onMethodCall(MethodCall call, final Result result) {
|
||||
registrar.addActivityResultListener(delegate);
|
||||
ICallback callback = new ICallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object data) {
|
||||
Map<String,Object> obj = new HashMap<String,Object>();
|
||||
|
||||
obj.put("success",true);
|
||||
if (data != null)
|
||||
obj.put("data",data);
|
||||
obj.put("retMsg","ok");
|
||||
result.success(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(Object error) {
|
||||
Map<String,Object> obj = new HashMap<String,Object>();
|
||||
obj.put("success",false);
|
||||
obj.put("retMsg",error==null?"":error);
|
||||
result.success(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(Object cancel) {
|
||||
result.notImplemented();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivityForResult(Intent intent, int requestCode) {
|
||||
|
||||
}
|
||||
};
|
||||
Log.d(LOG_TAG,"mopplugin: invoke " + call.method);
|
||||
Event event= new Event(call.method,call.arguments,callback);
|
||||
delegate.setEvent(event);
|
||||
this.flutterInterface.invokeHandler(event);
|
||||
// if (call.method.equals("getPlatformVersion")) {
|
||||
// result.success("Android " + android.os.Build.VERSION.RELEASE);
|
||||
// } else {
|
||||
// result.notImplemented();
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package com.finogeeks.mop;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.finogeeks.mop.constants.Constants;
|
||||
import com.finogeeks.mop.interfaces.Event;
|
||||
import com.finogeeks.mop.service.MopPluginService;
|
||||
|
||||
import io.flutter.plugin.common.PluginRegistry;
|
||||
|
||||
|
||||
public class MopPluginDelegate implements PluginRegistry.ActivityResultListener {
|
||||
|
||||
private Event mEvent;
|
||||
private final Activity activity;
|
||||
|
||||
public Event getEvent() {
|
||||
return mEvent;
|
||||
}
|
||||
|
||||
public void setEvent(Event event) {
|
||||
this.mEvent = event;
|
||||
}
|
||||
|
||||
public MopPluginDelegate(final Activity activity) {
|
||||
this.activity = activity;
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == Constants.REQUEST_CODE_CHOOSE
|
||||
|| requestCode == Constants.REQUEST_CODE_LOCATION_CHOOSE
|
||||
) {
|
||||
MopPluginService.getInstance().getApisManager().getApiInstance(mEvent).onActivityResult(requestCode, resultCode, data, mEvent.getCallback());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.finogeeks.mop.api;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import com.finogeeks.mop.interfaces.IApi;
|
||||
import com.finogeeks.mop.interfaces.ICallback;
|
||||
|
||||
public abstract class AbsApi implements IApi {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data, ICallback callback) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onNewIntent(Intent intent) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onPause() {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.finogeeks.mop.api;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.finogeeks.mop.api.mop.AppletModule;
|
||||
import com.finogeeks.mop.api.mop.BaseModule;
|
||||
import com.finogeeks.mop.interfaces.Event;
|
||||
import com.finogeeks.mop.interfaces.IApi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ApisManager {
|
||||
|
||||
|
||||
private final static String TAG = ApisManager.class.getSimpleName();
|
||||
|
||||
public static final int SUCCESS = 0x10;
|
||||
public static final int FAIL = 0x11;
|
||||
public static final int CANCEL = 0x12;
|
||||
public static final int PENDING = 0x13;
|
||||
|
||||
private final IApi EMPTY_API = new EmptyApi();
|
||||
private final Map<String, IApi> APIS = new HashMap<>();
|
||||
private Activity mActivity;
|
||||
|
||||
public ApisManager(Activity activity) {
|
||||
mActivity = activity;
|
||||
initSdkApi(activity);
|
||||
}
|
||||
/**
|
||||
* api功能调用
|
||||
*
|
||||
* @param event 封装了api名称,参数及回调函数id的对象
|
||||
*/
|
||||
public IApi getApiInstance(Event event) {
|
||||
IApi api = APIS.get(event.getName());
|
||||
if (api != null) {
|
||||
return api;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
/**
|
||||
* api功能调用
|
||||
*
|
||||
* @param event 封装了api名称,参数及回调函数id的对象
|
||||
*/
|
||||
public void invoke(Event event) {
|
||||
IApi api = APIS.get(event.getName());
|
||||
if (api != null) {
|
||||
api.invoke(event.getName(), event.getParam(), event.getCallback());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initSdkApi(Activity activity) {
|
||||
add(new BaseModule(activity));
|
||||
add(new AppletModule(activity));
|
||||
|
||||
}
|
||||
|
||||
private void add(IApi api) {
|
||||
if (api != null && api.apis() != null && api.apis().length > 0) {
|
||||
String[] apiNames = api.apis();
|
||||
for (String name : apiNames) {
|
||||
if (!TextUtils.isEmpty(name)) {
|
||||
APIS.put(name, api);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.finogeeks.mop.api;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
public abstract class BaseApi extends AbsApi {
|
||||
|
||||
|
||||
protected static final String TAG = "InnerApi";
|
||||
|
||||
protected static final Handler HANDLER = new Handler(Looper.getMainLooper());
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public BaseApi(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.finogeeks.mop.api;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import com.finogeeks.mop.interfaces.IApi;
|
||||
import com.finogeeks.mop.interfaces.ICallback;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class EmptyApi implements IApi {
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data, ICallback callback) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onNewIntent(Intent data) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onPause() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] apis() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String event, Map param, ICallback callback) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.finogeeks.mop.api.mop;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.finogeeks.lib.applet.client.FinAppClient;
|
||||
import com.finogeeks.mop.api.BaseApi;
|
||||
import com.finogeeks.mop.interfaces.ICallback;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AppletModule extends BaseApi {
|
||||
private final static String TAG = AppletModule.class.getSimpleName();
|
||||
private Context mContext;
|
||||
public AppletModule(Context context) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
}
|
||||
@Override
|
||||
public String[] apis() {
|
||||
return new String[]{"openApplet"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String event, Map param, ICallback callback) {
|
||||
System.out.println("AppletModule");
|
||||
if (param.get("appId") == null) {
|
||||
callback.onFail(new HashMap(){
|
||||
{
|
||||
put("info","appId不能为空");
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
String appId = String.valueOf(param.get("appId"));
|
||||
Map<String,String> params = (Map)param.get("params");
|
||||
if (params == null) {
|
||||
FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, appId);
|
||||
} else {
|
||||
FinAppClient.INSTANCE.getAppletApiManager().startApplet(mContext, appId, params);
|
||||
}
|
||||
callback.onSuccess(new HashMap());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package com.finogeeks.mop.api.mop;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.finogeeks.lib.applet.client.FinAppClient;
|
||||
import com.finogeeks.lib.applet.client.FinAppConfig;
|
||||
import com.finogeeks.lib.applet.interfaces.FinCallback;
|
||||
import com.finogeeks.mop.api.BaseApi;
|
||||
import com.finogeeks.mop.interfaces.ICallback;
|
||||
import com.finogeeks.mop.service.MopPluginService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BaseModule extends BaseApi {
|
||||
private final static String TAG = BaseModule.class.getSimpleName();
|
||||
|
||||
public BaseModule(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
}
|
||||
@Override
|
||||
public String[] apis() {
|
||||
return new String[]{"initialize"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String event, Map param, final ICallback callback) {
|
||||
|
||||
if (FinAppClient.INSTANCE.isFinAppProcess(super.getContext())) {
|
||||
// 小程序进程不执行任何初始化操作
|
||||
return;
|
||||
}
|
||||
String appkey = String.valueOf(param.get("appkey"));
|
||||
String secret = String.valueOf(param.get("secret"));
|
||||
String apiServer = "https://mp.finogeeks.com";
|
||||
String apiPrefix = "/api/v1/mop/";
|
||||
if (param.get("apiServer") != null) {
|
||||
apiServer = String.valueOf(param.get("apiServer"));
|
||||
}
|
||||
if (param.get("apiPrefix") != null) {
|
||||
apiPrefix = String.valueOf(param.get("apiPrefix"));
|
||||
}
|
||||
FinAppConfig config = new FinAppConfig.Builder()
|
||||
.setAppKey(appkey)
|
||||
.setAppSecret(secret)
|
||||
.setApiUrl(apiServer)
|
||||
.setApiPrefix(apiPrefix)
|
||||
.setGlideWithJWT(false)
|
||||
.build();
|
||||
// SDK初始化结果回调,用于接收SDK初始化状态
|
||||
FinCallback<Object> cb = new FinCallback<Object>() {
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
// SDK初始化成功
|
||||
callback.onSuccess(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int code, String error) {
|
||||
// SDK初始化失败
|
||||
callback.onFail(null);
|
||||
// Toast.makeText(MopPluginService.getInstance().getContext(), "SDK初始化失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgress(int status, String error) {
|
||||
|
||||
}
|
||||
};
|
||||
FinAppClient.INSTANCE.init(MopPluginService.getInstance().getActivity().getApplication(), config, cb);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.finogeeks.mop.constants;
|
||||
|
||||
/**
|
||||
* 全局常量池
|
||||
*/
|
||||
public class Constants {
|
||||
public static final int REQUEST_CODE_CHOOSE = 0x1000000;
|
||||
public static final int REQUEST_CODE_LOCATION_CHOOSE = 0x1000001;
|
||||
public static final int REQUEST_CODE_LOCATION_PREVIEW = 0x1000002;
|
||||
public static final int REQUEST_CODE_SELECT_DOCUMENT = 0x1000003;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.finogeeks.mop.interfaces;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class Event {
|
||||
|
||||
private String name;
|
||||
private Object param;
|
||||
private ICallback callback;
|
||||
|
||||
|
||||
public Event(String name, Object param, ICallback callback) {
|
||||
this.name = name;
|
||||
this.param = param;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Map getParam() {
|
||||
if (param instanceof Map) {
|
||||
|
||||
return (Map)param;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICallback getCallback() {
|
||||
return callback;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.finogeeks.mop.interfaces;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.finogeeks.mop.service.MopPluginService;
|
||||
|
||||
|
||||
public class FlutterInterface {
|
||||
private static final String TAG = FlutterInterface.class.getSimpleName();
|
||||
|
||||
private Handler mHandler = new Handler(Looper.getMainLooper());
|
||||
|
||||
public void invokeHandler(final Event event) {
|
||||
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MopPluginService.getInstance().getApisManager().invoke(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.finogeeks.mop.interfaces;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Api接口,实现相应功能的Api需实现此接口
|
||||
*/
|
||||
public interface IApi extends ILifecycle {
|
||||
|
||||
/**
|
||||
* @return 支持可调用的api名称的数组
|
||||
*/
|
||||
String[] apis();
|
||||
|
||||
/**
|
||||
* 接收到对应的api调用时,会调用此方法,在此方法中处理api调用的功能逻辑
|
||||
*
|
||||
* @param event 事件名称,即api名称
|
||||
* @param param 参数
|
||||
* @param callback 回调接口
|
||||
*/
|
||||
void invoke(String event, Map param, ICallback callback);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.finogeeks.mop.interfaces;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* Api回调接口
|
||||
*/
|
||||
public interface ICallback<T> {
|
||||
|
||||
/**
|
||||
* Api调用成功
|
||||
*
|
||||
* @param data Api调用返回的结果
|
||||
*/
|
||||
void onSuccess(T data);
|
||||
|
||||
/**
|
||||
* Api调用失败
|
||||
*/
|
||||
void onFail(T error);
|
||||
|
||||
/**
|
||||
* Api调用取消
|
||||
*/
|
||||
void onCancel(T cancel);
|
||||
|
||||
/**
|
||||
* 回调{@link android.app.Activity#startActivityForResult(Intent, int)}方法
|
||||
*
|
||||
* @param intent
|
||||
* @param requestCode
|
||||
*/
|
||||
void startActivityForResult(Intent intent, int requestCode);
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.finogeeks.mop.interfaces;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* 绑定{@link Activity}生命周期的回调接口
|
||||
*/
|
||||
public interface ILifecycle {
|
||||
|
||||
/**
|
||||
* 当{@link Activity#onCreate(Bundle)}方法调用时回调.
|
||||
*/
|
||||
void onCreate();
|
||||
|
||||
/**
|
||||
* 当{@link Activity#onDestroy()}方法调用时回调.
|
||||
*/
|
||||
void onDestroy();
|
||||
|
||||
/**
|
||||
* 当{@link Activity#onActivityResult(int, int, Intent)}方法调用时回调.
|
||||
*/
|
||||
void onActivityResult(int requestCode, int resultCode, Intent data, ICallback callback);
|
||||
|
||||
/**
|
||||
* 当{@link Activity#onNewIntent(Intent)}方法调用时回调.
|
||||
*/
|
||||
void onNewIntent(Intent intent);
|
||||
/**
|
||||
* 当{@link Activity#onResume()}方法调用时回调.
|
||||
*/
|
||||
void onResume();
|
||||
/**
|
||||
* 当{@link Activity#onResume()}方法调用时回调.
|
||||
*/
|
||||
void onPause();
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.finogeeks.mop.service;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import com.finogeeks.mop.MopEventStream;
|
||||
import com.finogeeks.mop.api.ApisManager;
|
||||
|
||||
public class MopPluginService {
|
||||
private final static String TAG = MopPluginService.class.getSimpleName();
|
||||
private static volatile MopPluginService _instance = null;
|
||||
|
||||
private ApisManager apisManager;
|
||||
private MopEventStream mopEventStream;
|
||||
|
||||
|
||||
private Context mContext;
|
||||
private Activity mActivity;
|
||||
|
||||
MopPluginService() {
|
||||
}
|
||||
|
||||
public static MopPluginService getInstance() {
|
||||
if (_instance == null) {
|
||||
synchronized (MopPluginService.class) {
|
||||
if (_instance == null) {
|
||||
_instance = new MopPluginService();
|
||||
}
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public ApisManager getApisManager() { return this.apisManager;}
|
||||
public MopEventStream getMopEventStream() {return this.mopEventStream;}
|
||||
public void initialize(Activity activity, MopEventStream mopEventStream) {
|
||||
this.mopEventStream = mopEventStream;
|
||||
this.mContext = activity.getApplicationContext();
|
||||
this.apisManager = new ApisManager(activity);
|
||||
this.mActivity = activity;
|
||||
|
||||
|
||||
}
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
public Activity getActivity() {
|
||||
return mActivity;
|
||||
}
|
||||
}
|
|
@ -33,12 +33,12 @@ android {
|
|||
|
||||
defaultConfig {
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId "com.finogeeks.mop_example"
|
||||
minSdkVersion 16
|
||||
applicationId "com.finogeeks.mopexample"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 28
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
@ -56,6 +56,6 @@ flutter {
|
|||
|
||||
dependencies {
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
androidTestImplementation 'androidx.test:runner:1.1.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/*___Generated_by_IDEA___*/
|
||||
|
||||
package com.finogeeks.mop_example;
|
||||
|
||||
/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */
|
||||
public final class Manifest {
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
/*___Generated_by_IDEA___*/
|
||||
|
||||
package com.finogeeks.mop_example;
|
||||
|
||||
/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */
|
||||
public final class R {
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.finogeeks.mop_example;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import io.flutter.app.FlutterActivity;
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
||||
|
||||
|
@ -9,5 +10,7 @@ public class MainActivity extends FlutterActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
GeneratedPluginRegistrant.registerWith(this);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
|
@ -5,7 +6,8 @@ buildscript {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
classpath 'com.android.tools.build:gradle:3.4.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.60"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
android.enableJetifier=true
|
||||
android.useAndroidX=true
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
|
||||
|
|
|
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
-keep class com.finogeeks.** {*;}
|
||||
|
||||
# tbs
|
||||
-keep class com.tencent.smtt.** {*;}
|
||||
-keep class com.tencent.tbs.** {*;}
|
|
@ -20,17 +20,17 @@ class _MyAppState extends State<MyApp> {
|
|||
|
||||
// Platform messages are asynchronous, so we initialize in an async method.
|
||||
Future<void> initPlatformState() async {
|
||||
String platformVersion;
|
||||
// Platform messages may fail, so we use a try/catch PlatformException.
|
||||
try {
|
||||
platformVersion = await Mop.instance.platformVersion;
|
||||
print(platformVersion);
|
||||
} on PlatformException {
|
||||
platformVersion = 'Failed to get platform version.';
|
||||
}
|
||||
// String platformVersion;
|
||||
// // Platform messages may fail, so we use a try/catch PlatformException.
|
||||
// try {
|
||||
// platformVersion = await Mop.instance.platformVersion;
|
||||
// print(platformVersion);
|
||||
// } on PlatformException {
|
||||
// platformVersion = 'Failed to get platform version.';
|
||||
// }
|
||||
final res = await Mop.instance.initialize(
|
||||
'22LyZEib0gLTQdU3MUauARlLry7JL/2fRpscC9kpGZQA', '1c11d7252c53e0b6',
|
||||
apiServer: 'https://mp.finogeeks.com', apiPrefix: '/api/v1');
|
||||
'22LyZEib0gLTQdU3MUauARjmmp6QmYgjGb3uHueys1oA', '98c49f97a031b555',
|
||||
apiServer: 'https://mp.finogeeks.com', apiPrefix: '/api/v1/');
|
||||
print(res);
|
||||
|
||||
// If the widget was removed from the tree while the asynchronous platform
|
||||
|
|
|
@ -66,7 +66,7 @@ packages:
|
|||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.1"
|
||||
version: "0.0.2"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
19
mop.iml
19
mop.iml
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/build" />
|
||||
</content>
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
<orderEntry type="library" name="Flutter Plugins" level="project" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,8 +1,9 @@
|
|||
name: mop
|
||||
description: A new flutter plugin project.
|
||||
version: 0.0.1
|
||||
author:
|
||||
homepage:
|
||||
version: 0.0.2
|
||||
authors:
|
||||
- finogeeks <finogeeks.mop@gmail.com>
|
||||
homepage: https://github.com/finogeeks/flutter-mop-plugin
|
||||
|
||||
environment:
|
||||
sdk: '>=2.1.0 <3.0.0'
|
||||
|
|
Loading…
Reference in New Issue