From 985258567317cca1d20e9ceacf4189638abe9e5f Mon Sep 17 00:00:00 2001 From: xiaoyu Date: Thu, 3 Dec 2020 17:14:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- .../com/finogeeks/mop/demo/AppletHandler.java | 77 +++++++++++++++++++ .../finogeeks/mop/demo/MopApplication.java | 5 +- 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/finogeeks/mop/demo/AppletHandler.java diff --git a/app/build.gradle b/app/build.gradle index 0645ae4..0188879 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,5 +45,5 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - implementation 'com.finogeeks.lib:finapplet:2.11.98' + implementation 'com.finogeeks.lib:finapplet:2.12.39' } \ No newline at end of file diff --git a/app/src/main/java/com/finogeeks/mop/demo/AppletHandler.java b/app/src/main/java/com/finogeeks/mop/demo/AppletHandler.java new file mode 100644 index 0000000..de2254e --- /dev/null +++ b/app/src/main/java/com/finogeeks/mop/demo/AppletHandler.java @@ -0,0 +1,77 @@ +package com.finogeeks.mop.demo; + +import android.content.Context; +import android.graphics.Bitmap; +import android.widget.Toast; + +import androidx.annotation.NonNull; + +import com.finogeeks.lib.applet.page.view.moremenu.MoreMenuItem; +import com.finogeeks.lib.applet.rest.model.GrayAppletVersionConfig; +import com.finogeeks.lib.applet.sdk.api.IAppletHandler; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * {@link IAppletHandler}实现类,用于实现一些业务场景,例如注册"更多"菜单项,转发小程序等。 + */ +public class AppletHandler implements IAppletHandler { + + @NonNull + private Context mContext; + + private AppletHandler() { + } + + public AppletHandler(@NonNull Context context) { + this.mContext = context; + } + + @Nullable + @Override + public List getGrayAppletVersionConfigs(@NotNull String appId) { + return null; + } + + @Nullable + @Override + public List getRegisteredMoreMenuItems(@NotNull String appId) { + List moreMenuItems = new ArrayList<>(); + moreMenuItems.add(new MoreMenuItem(0x01, android.R.drawable.star_big_on, "菜单一", true)); + moreMenuItems.add(new MoreMenuItem(0x02, android.R.drawable.star_big_off, "菜单二", true)); + moreMenuItems.add(new MoreMenuItem(0x03, android.R.drawable.star_big_on, "菜单三菜单三菜单三菜单三菜单三", true)); + moreMenuItems.add(new MoreMenuItem(0x04, android.R.drawable.star_big_off, "菜单四", true)); + moreMenuItems.add(new MoreMenuItem(0x05, android.R.drawable.star_big_on, "菜单五", true)); + moreMenuItems.add(new MoreMenuItem(0x06, android.R.drawable.star_big_off, "菜单六", true)); + moreMenuItems.add(new MoreMenuItem(0x07, android.R.drawable.star_big_on, "菜单七", true)); + moreMenuItems.add(new MoreMenuItem(0x08, android.R.drawable.star_big_off, "菜单八", true)); + moreMenuItems.add(new MoreMenuItem(0x09, android.R.drawable.star_big_on, "菜单九", true)); + return moreMenuItems; + } + + @Nullable + @Override + public Map getUserInfo() { + return null; + } + + @Override + public void onNavigationBarCloseButtonClicked(@NotNull String appId) { + Toast.makeText(mContext, "点击了小程序 " + appId + " 的导航栏关闭按钮", Toast.LENGTH_SHORT).show(); + } + + @Override + public void onRegisteredMoreMenuItemClicked(@NotNull String appId, int menuItemId) { + Toast.makeText(mContext, "点击了小程序 " + appId + " 注入的菜单 :" + menuItemId, Toast.LENGTH_SHORT).show(); + } + + @Override + public void shareAppMessage(@NotNull String appInfo, @Nullable Bitmap bitmap, @NotNull IAppletCallback iAppletCallback) { + Toast.makeText(mContext, "点击了转发按钮,去实现您的转发/分享逻辑吧", Toast.LENGTH_SHORT).show(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/finogeeks/mop/demo/MopApplication.java b/app/src/main/java/com/finogeeks/mop/demo/MopApplication.java index 80fd5aa..f580c6d 100644 --- a/app/src/main/java/com/finogeeks/mop/demo/MopApplication.java +++ b/app/src/main/java/com/finogeeks/mop/demo/MopApplication.java @@ -1,6 +1,5 @@ package com.finogeeks.mop.demo; -import android.util.Log; import android.widget.Toast; import androidx.multidex.MultiDexApplication; @@ -39,11 +38,13 @@ public class MopApplication extends MultiDexApplication { FinAppClient.INSTANCE.init(this, config, new FinCallback() { @Override public void onSuccess(Object result) { - Log.d(TAG, "init result : " + result); + Toast.makeText(MopApplication.this, "SDK初始化成功", Toast.LENGTH_SHORT).show(); // 注册自定义小程序API FinAppClient.INSTANCE.getExtensionApiManager().registerApi(new CustomApi(MopApplication.this)); // 注册自定义H5 API FinAppClient.INSTANCE.getExtensionWebApiManager().registerApi(new CustomH5Api(MopApplication.this)); + // 设置IAppletHandler实现类 + FinAppClient.INSTANCE.setAppletHandler(new AppletHandler(getApplicationContext())); } @Override