@ProxyService(proxy = MiniAppProxy.class)public class MiniAppProxyImpl extends BaseMiniAppProxy{}
/*** Selecting the "Close" option on the capsule button.* Invocation Environment: Subprocess** @param miniAppContext - The operating environment of the mini program (mini program process, not the main process)* @param onCloseClickedListener - Callback upon clicking to close the mini program.* @return - If this interface is not supported, please return "false".*/public abstract boolean onCapsuleButtonCloseClick(IMiniAppContext miniAppContext,DialogInterface.OnClickListener onCloseClickedListener);/*** Return the buttons for the capsule's extended panel. The ID of the extended button must be set within the range of [100, 200], otherwise, the addition will be invalid.* Invocation Environment: Subprocess** @param builder* @return*/public abstract ArrayList<MoreItem> getMoreItems(MoreItemList.Builder builder);/*** Return to the capsule and click the "Listener" button in the "More" panel that pops up.* Invocation Environment: Subprocess** @return - Listener*/public abstract OnMoreItemSelectedListener getMoreItemSelectedListener();
@Overridepublic ArrayList<MoreItem> getMoreItems(IMiniAppContext miniAppContext, MoreItemList.Builder builder) {MoreItem item1 = new MoreItem();item1.id = ShareProxyImpl.OTHER_MORE_ITEM_1;item1.text = getString(miniAppContext, R.string.applet_mini_proxy_impl_other1);item1.drawable = R.mipmap.mini_demo_about;MoreItem item2 = new MoreItem();item2.id = ShareProxyImpl.OTHER_MORE_ITEM_2;item2.text = getString(miniAppContext, R.string.applet_mini_proxy_impl_other2);item2.shareKey = SHARE_TWITTER; // The key for custom sharing, which must be set and unique, and will be used when the Mini Program end calls for control settings.item2.drawable = R.mipmap.mini_demo_about;MoreItem item3 = new MoreItem();item3.id = DemoMoreItemSelectedListener.CLOSE_MINI_APP;item3.text = getString(miniAppContext, R.string.applet_mini_proxy_impl_float_app);item3.drawable = R.mipmap.mini_demo_about;MoreItem item4 = new MoreItem();item4.id = ShareProxyImpl.OTHER_MORE_ITEM_INVALID;item4.text = getString(miniAppContext, R.string.applet_mini_proxy_impl_out_of_effect);item4.drawable = R.mipmap.mini_demo_about;// Adjust the sequence independently.builder.addMoreItem(item1).addMoreItem(item2).addShareQQ("QQ", R.mipmap.mini_demo_channel_qq).addMoreItem(item3).addShareQzone(getString(miniAppContext, R.string.applet_mini_proxy_impl_Qzone),R.mipmap.mini_demo_channel_qzone).addShareWxFriends(getString(miniAppContext, R.string.applet_mini_proxy_impl_wechat_friend),R.mipmap.mini_demo_channel_wx_friend).addShareWxMoments(getString(miniAppContext, R.string.applet_mini_proxy_impl_wechat_group),R.mipmap.mini_demo_channel_wx_moment).addRestart(getString(miniAppContext, R.string.applet_mini_proxy_impl_restart),R.mipmap.mini_demo_restart_miniapp).addAbout(getString(miniAppContext, R.string.applet_mini_proxy_impl_about),R.mipmap.mini_demo_about).addDebug(getString(miniAppContext, R.string.mini_sdk_more_item_debug),R.mipmap.mini_demo_about).addMonitor(getString(miniAppContext, R.string.applet_mini_proxy_impl_performance),R.mipmap.mini_demo_about).addComplaint(getString(miniAppContext, R.string.applet_mini_proxy_impl_complain_and_report),R.mipmap.mini_demo_browser_report).addSetting(getString(miniAppContext, R.string.mini_sdk_more_item_setting),R.mipmap.mini_demo_setting);return builder.build();}private String getString(IMiniAppContext miniAppContext, int id) {return miniAppContext.getContext().getString(id);}
/** * Click 'listener' within the additional panel buttons of the capsule. * * @return */ @Override public OnMoreItemSelectedListener getMoreItemSelectedListener() { return new DemoMoreItemSelectedListener(); }public class DemoMoreItemSelectedListener extends DefaultMoreItemSelectedListener { public static final int CLOSE_MINI_APP = 150; @Override public void onMoreItemSelected(IMiniAppContext miniAppContext, int moreItemId) { // Handle developer-defined click events (excluding custom sharing events) switch (moreItemId) { case CLOSE_MINI_APP: close(miniAppContext); return; case OTHER_MORE_ITEM_1: miniAppContext.getAttachedActivity().runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(miniAppContext.getAttachedActivity(), "custom menu click", Toast.LENGTH_SHORT).show(); } }); return; } // Handle built-in sharing and developer-defined sharing, such as: Weibo, Twitter, etc. super.onMoreItemSelected(miniAppContext, moreItemId); } public void close(IMiniAppContext miniAppContext) { Activity activity = miniAppContext.getAttachedActivity(); if (activity != null && !activity.isFinishing()) { boolean moved = activity.moveTaskToBack(true); if (!moved) { QMLog.e("Demo", "moveTaskToBack failed, finish the activity."); activity.finish(); } } } }
/*** Open the image selection interface.* Invocation Environment: Subprocess** @param context Current Activity* @param maxSelectedNum Maximum number of selections allowed.* @param listener Callback interface.* @return - If this interface is not supported, please return "false".*/public abstract boolean openChoosePhotoActivity(Context context, int maxSelectedNum, IChoosePhotoListner listner);/*** Open the image preview interface.* Invocation Environment: Subprocess** @param context Current Activity* @param selectedIndex Index of the currently selected image.* @param pathList List of image paths.* @return - If this interface is not supported, please return "false".*/public abstract boolean openImagePreview(Context context, int selectedIndex, List<String> pathList);
/*** Customize the authorization pop-up view.* Invocation Environment: Subprocess** @param context* @param authInfo* @param authView* @return true: Customized authorization view; false: Use the built-in feature.*/@Overridepublic boolean authView(Context context, MiniAuthInfo authInfo, IAuthView authView) {return true;}
/*** Obtain scope.userInfo for user authorization authorization.* Invocation Environment: Subprocess** @param appId* @param result*/@Overridepublic void getUserInfo(String appId, AsyncResult result) {JSONObject jsonObject = new JSONObject();try {//Return nickname.jsonObject.put("nickName", "userInfo Test");//Return avatar URL.jsonObject.put("avatarUrl", "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.daimg.com%2Fuploads%2Fallimg%2F210114%2F1-210114151951.jpg&refer=http%3A%2F%2Fimg.daimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1673852149&t=e2a830d9fabd7e0818059d92c3883017");result.onReceiveResult(true, jsonObject);} catch (JSONException e) {e.printStackTrace();}}
public Drawable getDrawable(Context context, String source, int width, int hight, Drawable defaultDrawable)
/*** Specify a unique user account to enable isolated data storage for that account. It's recommended not to use sensitive information.* Calling environment: main process*/@Overridepublic String getAccount() {return "tmf_test";}
/*** Get Drawable Object* Calling environment: child process** @param context Context* @param source Source, either local or network* @param width picture width* @param hight picture height* @param defaultDrawable Default picture for loading and failed loads*/@Overridepublic Drawable getDrawable(Context context, String source, int width, int hight, Drawable defaultDrawable)
@Overridepublic Drawable getDrawable(Context context, String source, int width, int hight, Drawable defaultDrawable) {//Access party accesses its own ImageLoader//Open source universalimageloader in demoUniversalDrawable drawable = new UniversalDrawable();if (TextUtils.isEmpty(source)) {return drawable;}drawable.loadImage(context, source);return drawable;}
@Override public MiniConfigData configData(Context context, int configType, JSONObject params) { if(configType == MiniConfigData.TYPE_DOMAIN) { //Virtual Domain Name Configuration MiniConfigData.DomainConfig domainConfig = new MiniConfigData.DomainConfig(); domainConfig.domain = "test.com"; return new MiniConfigData .Builder() .domainConfig(domainConfig) .build(); } return new MiniConfigData .Builder() .build(); }
@Overridepublic MiniConfigData configData(Context context, int configType, JSONObject params) {if(configType == MiniConfigData.TYPE_WEBVIEW) {//webView userAgentString ua = params.optString(MiniConfigData.WebViewConfig.WEBVIEW_CONFIG_UA);MiniConfigData.WebViewConfig webViewConfig = new MiniConfigData.WebViewConfig();//Set the userAgent that the developer needs to add. Note: Do not set the original ua.webViewConfig.userAgent = "key/value";return new MiniConfigData.Builder().webViewConfig(webViewConfig).build();}return new MiniConfigData.Builder().build();}
/*** Scan QR code** @param context Context* @param onlyFromCamera only allows the camera to scan* @param result scan results* @return true: Custom scan code;false: Use built-in scan code*/@Overridepublic boolean enterQRCode(Context context, boolean onlyFromCamera, AsyncResult result) {return false;}
/*** specify the Mini programs API to save images, videos to the system album directory**/public abstract String getSaveFileDir();
/*** Mini programs Lifecycle Event Callbacks:* Call Context: Main Process UI Thread** @param appState The event state* @param event event*/public abstract void onAppStateChange(@AppState int appState, MiniAppEvent event);
/*** base library detects updates, whether to update* @param context* @param data Basic library information data* @return `true`: Update;`false`: Don't update, default to true*/public abstract boolean isUpdateBaseLib(Context context, JSONObject data);
Was this page helpful?