boxmoe_header_banner_img

Hello! 欢迎来到松子博客!

加载中

文章导读

Fusion App中文函数改英文适配2.0


avatar
szfx_blog 2021年4月18日 18.33k

Fusion App1.0封装了一些常用的中文函数,而最近内测的Fusion App2.0 beta7.1已经加入中文函数模块。

启用方法:模块-启用-动作-中文函数模块

(之前分享一些替代的英文代码,并分享一些常用代码。)

Fusion App 2开源项目分享


Fusion App2.0介绍:Fusion App2.0 | Lua学习笔记

一、网络类

先获取WebView

local uiManager=activity.getUiManager() 
--获取当前页面的WebView
local webView=uiManager.getCurrentFragment().getWebView()

1、加载网页

加载网页(“网页链接”)

--加载URL指定的网页
loadUrl("网页链接")
--携带http headers加载URL指定的网页
loadUrl("网页链接", Map<String, String> additionalHttpHeaders)
--使用POST请求加载指定的网页
postUrl(String url, byte[] postData)

2、刷新网页

刷新网页()

--重新加载当前网页
reload()

应用:WebView.reload(),以下类似

3、页面前进后退

网页前进()  网页后退()

--后退一页
goBack()
 
--前进一页
goForward()
 
--前进/后退steps页,大于0表示前进小于0表示后退
goBackOrForward(steps)

4、查看源码

local url="view-source:"..webView.getUrl()
webView.loadUrl(url)

二、软件类

2.1 打开微信

import "android.content.pm.PackageManager"
packageName="com.tencent.mm"
if pcall(function() activity.getPackageManager().getPackageInfo(packageName,0) end) then    
    manager = activity.getPackageManager()
    open = manager.getLaunchIntentForPackage(packageName)
    this.startActivity(open)
else
    print("你居然没有安装微信 Σ(ŎдŎ|||)ノノ")
end

2.2 打开微信扫一扫

import "android.content.pm.PackageManager"
if pcall(function() activity.getPackageManager().getPackageInfo("com.tencent.mm",0) end) then
    print("即将前往微信扫一扫")
    packageName="com.tencent.mm"
    manager = activity.getPackageManager()
    intent = manager.getLaunchIntentForPackage(packageName)
    intent.putExtra("LauncherUI.From.Scaner.Shortcut", true);
    intent.setAction("android.intent.action.VIEW");
    activity.startActivity(intent);
else
    print("你居然没有安装微信 Σ(ŎдŎ|||)ノノ")
end

2.3 打开支付宝

import "android.content.pm.PackageManager"
if pcall(function() activity.getPackageManager().getPackageInfo("com.eg.android.AlipayGphone",0) end) then
    packageName="com.eg.android.AlipayGphone"
    manager = activity.getPackageManager()
    open = manager.getLaunchIntentForPackage(packageName)
    this.startActivity(open)
else
    print("你居然没有安装支付宝 Σ(ŎдŎ|||)ノノ")
end

2.4 打开支付宝付款

import "android.net.Uri"
import "android.content.Intent"
import "android.content.pm.PackageManager"

if pcall(function() activity.getPackageManager().getPackageInfo("com.eg.android.AlipayGphone",0) end) then
  xpcall(function()
    local url = "alipayqr://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode=https://qr.alipay.com/fkx169974aht82orwgo2e80"
    activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)));
  end,
  function()
    local url = "https://qr.alipay.com/fkx169974aht82orwgo2e80";
    activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)));
  end)
else
  print("你居然没有安装支付宝 Σ(ŎдŎ|||)ノノ")
end

以上网址应该是收款码解码链接

2.5 打开手机QQ

import "android.content.pm.PackageManager"
packageName="com.tencent.mobileqq"
if pcall(function() activity.getPackageManager().getPackageInfo(packageName,0) end) then    
    manager = activity.getPackageManager()
    open = manager.getLaunchIntentForPackage(packageName)
    this.startActivity(open)
else
    print("你居然没有安装QQ Σ(ŎдŎ|||)ノノ")
end

三、页面类

1、进入页面

进入子页面(“”)

activity.startFusionActivity("页面名称")

带参数传递的详见:界面之间的交互
https://www.szfx.top/lua/fusionapp2.html

2、退出页面

退出页面()

activity.finish()

3、新页面打开链接

进入子页面(“页面”,{链接=”网站链接”})

local bundle=Bundle()      
bundle.putString("link","网站链接")
activity.startFusionActivity("进入的页面",bundle)

进入的页面

require "import"
import "android.os.Bundle"
import "net.fusionapp.core.ui.fragment.WebInterface"
import "android.content.Intent"
import "android.net.Uri"
import "android.graphics.Color"

fragment=activity.uiManager.currentFragment
web=fragment.webView
link=activity.getIntent().getStringExtra("link")
web.loadUrl(link)

title=activity.uiManager.getToolbar().getChildAt(0).getChildAt(0).getChildAt(1).getChildAt(0)
fragment.setWebInterface(WebInterface{
  onPageFinished=function(view,url)
    if url==link then
      web.clearHistory()
      title.text=web.title
    end
    if title.text=="about:blank"
      activity.finish()
    end
  end
})

四、交互类

1、弹出消息

弹出消息(“消息内容”)

print("消息内容")

2、对话框

对话框()
.设置标题("标题")
.设置消息("消息")
.设置积极按钮("确定",function()
  显示消息("点击了确定")
end)
.设置消极按钮("取消")
.显示()
require("import")
import"com.google.android.material.dialog.MaterialAlertDialogBuilder"
 
dialog=MaterialAlertDialogBuilder(activity)
dialog.setTitle("标题")
dialog.setMessage("这是对话框消息")
dialog.setNeutralButton("中立",nil)
dialog.setPositiveButton("积极",{
  onClick=function()
   print("点击了积极按钮")
  end
})
dialog.setNegativeButton("消极",{
  onClick=function()
   print("点击了消极按钮")
  end
})
dialog.show()

设置单选/多选列表,详见对话框组件
https://www.szfx.top/lua/fusionapp2.html

3、QQ交互

3.1  联系QQ

联系QQ(“”)

我只知道引导到个人名片,有哪位大佬知道直接到对话框

if (pcall(function() activity.getPackageManager().getPackageInfo("com.tencent.mobileqq",0) end) || pcall(function() activity.getPackageManager().getPackageInfo("com.tencent.tim",0) end) ) then
	local url="mqqapi://card/show_pslcard?src_type=internal&version=1&uin=1149702060&card_type=person&source=qrcode"
	activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
else
	print("请先安装手机QQ/TIM")
end

3.2  加QQ群

加QQ群(“”)

import "android.net.Uri"
import "android.content.Intent"
local url="mqqapi://card/show_pslcard?src_type=internal&version=1&uin=1095632335&card_type=group&source=qrcode"
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))

3.3  QQ转账页面

import "android.net.Uri"
import "android.content.Intent"
local url="mqqapi://forward/url?url_prefix=aHR0cHM6Ly9tcXEudGVucGF5LmNvbS92Mi9oeWJyaWQvd3d3L21vYmlsZV9xcS9wYXltZW50L2luZGV4LnNodG1sP193dj0xMDI3JmZyb209MTMmX3ZhY2Y9cXc=&version=1&src_type=web"
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))

五、文本类

1、分享文本

分享文本(“文本内容”)

import "androidx.core.app.ShareCompat"
ShareCompat.IntentBuilder
 .from(activity)
 .setText("文本内容")
 .setType("text/plain")
 .startChooser();

2、复制文本

复制文本(“”)

import "android.content.ClipData"
复制文本=function(文本)
  local clipboardManager = activity.getSystemService(activity.CLIPBOARD_SERVICE);
  local clipData = ClipData.newPlainText("Label", 文本);
  clipboardManager.setPrimaryClip(clipData);
end

3、页内查找

页内查找(“词”)

--设置网页查找结果回调
setFindListener(FindListener listener)
 
--异步执行查找网页内包含的字符串并设置高亮,查找结果会回调.
findAllAsync("需查找的关键词")
 
--查找下一个匹配的字符串
findNext(forward)
 
--清除网页查找的高亮匹配字符串
clearMatches()
感谢您的支持
微信赞赏

微信扫一扫

支付宝赞赏

支付宝扫一扫



评论(13)

查看评论列表
显示IP属地
评论头像

Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/blog.szfx.top/wp-content/themes/lolimeow/platform/show-useragent.php on line 463
未知浏览器 未知操作系统
[…] Fusion App1.0中文函数改英文适配2.0 […]
评论头像
匿名 2021年04月19日
Chrome 79.0.3945.147 Android 11 | Redmi K30 5G
可以
评论头像
匿名 2021年08月21日
Chrome 90.0.4430.91 Android 11 | Redmi K30 Pro
在哪里可以下载到这个软件的
评论头像
szfx_blog 博主 2021年08月22日
Edge 92.0.902.73 Windows 10
底部附件下载:<a href="https://www.jishusongshu.com/code-basic/fusion-app2/" rel="nofollow ugc">https://www.jishusongshu.com/code-basic/fusion-app2/</a>
评论头像
匿名 2021年09月23日
Chrome 83.0.4103.101 Android 10 | M2006J10C
非常感谢,很给力的教程。最近突然要用到,从1过来还有点难适应,两三年没弄了。
评论头像
kitai 2022年10月13日
Chrome 105.0.5195.79 Android 12 | 21121210C
链接失效了
评论头像
szfx_blog 博主 2022年10月13日
Edge 106.0.1370.42 Windows 10
什么资源?
评论头像
匿名 2022年12月10日
Chrome 87.0.4280.141 Android 11 | V2162A
要是能把1.0搬到2.0就好了
评论头像
呼啦啦 2023年02月07日
Safari 604.1 iPhone iPhone OS 16_1_1 like Mac OS X) AppleWebKit
哥怎么屏蔽元素哇FA2,好像按1得方法屏蔽不了没反应
评论头像
szfx_blog 博主 2023年02月11日
Edge 109.0.1518.78 Windows 10
麻烦请给个案例吧,或者加Q群讨论
评论头像
匿名 2023年03月10日
Chrome 105.0.0.0 Windows 10
直接获取元素的id啥的,写在屏蔽元素里面
评论头像
mutan 2024年08月11日
Chrome 88.0.4324.93 Android 10 | NZA-AL00
在新页面打开链接那个模块那边,用于fa2.0的时候报错。提示“web=fragment.webView”有问题
评论头像
szfx_blog 博主 2024年08月11日
Edge 126.0.0.0 Windows 10
请检查前面是否完整import引入例子中的库

发表评论

表情 颜文字

插入代码
隐藏
变装