Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
fafc1265
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1595
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
fafc1265
编写于
6月 19, 2023
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加参数传递测试用例
上级
27f25d2c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
277 addition
and
109 deletion
+277
-109
pages.json
pages.json
+11
-0
pages/SyntaxCase/paramTest.vue
pages/SyntaxCase/paramTest.vue
+91
-0
pages/advance/advance.vue
pages/advance/advance.vue
+7
-0
uni_modules/uts-advance/utssdk/app-android/index.uts
uni_modules/uts-advance/utssdk/app-android/index.uts
+167
-108
uni_modules/uts-nativepage/utssdk/app-android/index.uts
uni_modules/uts-nativepage/utssdk/app-android/index.uts
+1
-1
未找到文件。
pages.json
浏览文件 @
fafc1265
...
...
@@ -142,8 +142,19 @@
"enablePullDownRefresh"
:
false
}
},
{
"path"
:
"pages/SyntaxCase/paramTest"
,
"style"
:
{
"navigationBarTitleText"
:
""
,
"enablePullDownRefresh"
:
false
}
}
],
"tabBar"
:
{
"color"
:
"#7A7E83"
,
...
...
pages/SyntaxCase/paramTest.vue
0 → 100644
浏览文件 @
fafc1265
<
template
>
<button
@
click=
"inputArrayTest"
>
传入数组参数
</button>
<button
@
click=
"inputParamTest"
>
传入复杂对象参数
</button>
<button
@
click=
"returnArrayTest"
>
返回数组参数
</button>
<button
@
click=
"returnParamTest"
>
返回复杂对象参数
</button>
<button
@
click=
"callbackArrayTest"
>
异步返回数组
</button>
<button
@
click=
"callbackParamTest"
>
异步返回复杂对象
</button>
</
template
>
<
script
>
import
{
inputArray
,
inputParam
,
returnArray
,
returnParam
,
callbackArray
,
callbackParam
}
from
'
../../uni_modules/uts-advance
'
export
default
{
data
()
{
return
{}
},
methods
:
{
inputArrayTest
()
{
let
ret
=
inputArray
([
'
a
'
,
'
b
'
,
'
c
'
])
if
(
ret
)
{
uni
.
showToast
({
title
:
'
测试通过
'
})
}
},
inputParamTest
()
{
let
ret
=
inputParam
({
title
:
"
hello
"
,
array
:
[
1
,
2
,
3
]
})
if
(
ret
)
{
uni
.
showToast
({
title
:
'
测试通过
'
})
}
},
returnArrayTest
()
{
let
ret
=
returnArray
()
if
(
'
["1","2","3"]
'
==
JSON
.
stringify
(
ret
))
{
uni
.
showToast
({
title
:
'
测试通过
'
})
}
},
returnParamTest
()
{
let
ret
=
returnParam
()
if
(
'
{"title":"returnParam","array":["1","2","3"]}
'
==
JSON
.
stringify
(
ret
))
{
uni
.
showToast
({
title
:
'
测试通过
'
})
}
},
callbackArrayTest
()
{
callbackArray
(
function
(
res
)
{
if
(
'
["8","8","8"]
'
==
JSON
.
stringify
(
res
))
{
uni
.
showToast
({
title
:
'
测试通过
'
})
}
});
},
callbackParamTest
()
{
callbackParam
(
function
(
res
)
{
if
(
'
{"title":"callbackParam","array":["4","5","6"]}
'
==
JSON
.
stringify
(
res
))
{
uni
.
showToast
({
title
:
'
测试通过
'
})
}
});
}
}
}
</
script
>
<
style
>
</
style
>
\ No newline at end of file
pages/advance/advance.vue
浏览文件 @
fafc1265
...
...
@@ -24,6 +24,8 @@
<uni-list>
<uni-list-item
@
tap=
"testSyntax"
title=
"进阶语法示例"
:clickable=
"true"
link
>
</uni-list-item>
<uni-list-item
@
tap=
"testParams"
title=
"参数传递示例"
:clickable=
"true"
link
>
</uni-list-item>
</uni-list>
</uni-collapse-item>
<uni-collapse-item
title=
"资源加载示例"
:border=
"false"
>
...
...
@@ -180,6 +182,11 @@
url
:
'
/pages/SyntaxCase/index
'
})
},
testParams
:
function
()
{
uni
.
navigateTo
({
url
:
'
/pages/SyntaxCase/paramTest
'
})
},
testGetResourcePath
:
function
()
{
uni
.
navigateTo
({
url
:
'
/pages/advance/iOS/getResourcePath
'
...
...
uni_modules/uts-advance/utssdk/app-android/index.uts
浏览文件 @
fafc1265
...
...
@@ -25,6 +25,7 @@ import EditText from 'android.widget.EditText';
import {
UTSAndroid
} from "io.dcloud.uts";
import array from 'android.R.array';
...
...
@@ -36,47 +37,47 @@ type TimerOptions = {
* 定时任务开始的回调
* @res 回调参数
*/
start
: (res
: string) => void;
start
: (res
: string) => void;
/**
* 定时任务执行的回调
* @res 回调参数
*/
work
: (res
: string) => void;
work
: (res
: string) => void;
};
/**
* 执行延时任务
*/
export function doTimerTask(opts
:
TimerOptions) {
export function doTimerTask(opts
:
TimerOptions) {
opts.start('doTimerTask start');
setTimeout(function() {
setTimeout(function
() {
opts.work("doTimerTask work");
}, 2000);
return { name: "doTimerTask" };
return { name: "doTimerTask" };
}
/**
* 执行周期任务
*/
export function doIntervalTask(opts
:
TimerOptions) {
let taskRet = setInterval(function() {
export function doIntervalTask(opts
:
TimerOptions) {
let taskRet = setInterval(function
() {
opts.work("doIntervalTask work");
}, 2000);
opts.start('doIntervalTask start');
return { name: "doIntervalTask",taskId:taskRet
};
return { name: "doIntervalTask", taskId: taskRet
};
}
/**
* 清除周期任务
*/
export function clearIntervalTask(taskId
:
number) {
export function clearIntervalTask(taskId
:
number) {
clearInterval(taskId);
return { name: "clearIntervalTask"};
return { name: "clearIntervalTask"
};
}
...
...
@@ -86,25 +87,25 @@ export function clearIntervalTask(taskId:number) {
*/
class AddUIRunnable implements Runnable {
override run():void {
let textView = new TextView(UTSAndroid.getUniActivity())
textView.setText("HELLO WORLD");
textView.textSize = 30.0.toFloat();
textView.setBackgroundColor(Color.RED)
textView.setTag("helloText")
textView.setGravity(Gravity.CENTER)
override run() : void {
let decorView = UTSAndroid.getUniActivity()!.window.decorView;
let textView = new TextView(UTSAndroid.getUniActivity())
textView.setText("HELLO WORLD");
textView.textSize = 30.0.toFloat();
textView.setBackgroundColor(Color.RED)
textView.setTag("helloText")
textView.setGravity(Gravity.CENTER)
let decorView = UTSAndroid.getUniActivity()!.window.decorView;
let frameContent = decorView.findViewById<FrameLayout>(android.R.id.content)
let layoutParam = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParam.topMargin = 200;
frameContent.addView(textView,layoutParam)
let frameContent = decorView.findViewById<FrameLayout>(android.R.id.content)
let layoutParam = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParam.topMargin = 200;
}
frameContent.addView(textView, layoutParam)
}
};
/**
...
...
@@ -113,15 +114,15 @@ class AddUIRunnable implements Runnable {
*/
class RemoveUIRunnable extends Runnable {
override run():void {
override run() : void {
let decorView = UTSAndroid.getUniActivity()!.getWindow().getDecorView();
let frameContent = decorView.findViewById<FrameLayout>(android.R.id.content)
let decorView = UTSAndroid.getUniActivity()!.getWindow().getDecorView();
let frameContent = decorView.findViewById<FrameLayout>(android.R.id.content)
let targetTV = frameContent.findViewWithTag<TextView>("helloText")
frameContent.removeView(targetTV)
}
}
};
/**
...
...
@@ -129,16 +130,16 @@ class RemoveUIRunnable extends Runnable {
*
*/
export function addViewToDecorView() {
let uiRunable = new AddUIRunnable();
UTSAndroid.getUniActivity()!.runOnUiThread(uiRunable)
let uiRunable = new AddUIRunnable();
UTSAndroid.getUniActivity()!.runOnUiThread(uiRunable)
}
/**
* 实现从decorview上移除指定view
*/
export function removeViewToDecorView() {
var uiRunable = new RemoveUIRunnable();
UTSAndroid.getUniActivity()!.runOnUiThread(uiRunable)
var uiRunable = new RemoveUIRunnable();
UTSAndroid.getUniActivity()!.runOnUiThread(uiRunable)
}
...
...
@@ -146,26 +147,26 @@ export function removeViewToDecorView() {
/**
* 引用资源路径
*/
export function getMetaConfig(): string {
export function getMetaConfig()
: string {
//
let packageName = UTSAndroid.getAppContext()!.getPackageName();
let appInfo = UTSAndroid.getAppContext()!.getPackageManager()!.getApplicationInfo(packageName,PackageManager.GET_META_DATA)
let appInfo = UTSAndroid.getAppContext()!.getPackageManager()!.getApplicationInfo(packageName,
PackageManager.GET_META_DATA)
let metaData = appInfo.metaData
if (metaData == null) {
return "";
return "";
}
let adId = metaData.getString("DCLOUD_READ_PHONE_STATE")
if (adId == null) {
// 没有数据,说明是自定义基座,则读取自定义基座的配置
let customMetaId = metaData.getString("UTS_CUSTOM_LAUNCHER_META")
if
(customMetaId == null)
{
if
(customMetaId == null)
{
return ""
}
return "自定义基座[UTS_CUSTOM_LAUNCHER_META]:" + customMetaId;
}
// 标准基座
return "标准基座[DCLOUD_READ_PHONE_STATE]:" + adId;
return "标准基座[DCLOUD_READ_PHONE_STATE]:" + adId;
}
...
...
@@ -173,29 +174,29 @@ export function getMetaConfig(): string {
/**
* 引用资源路径
*/
export function getLogoPath(): string {
return logo;
export function getLogoPath()
: string {
return logo;
}
/**
* 音频播放器对象
*/
let globalPlayer
:MediaPlayer
| null = null;
let globalPlayer
: MediaPlayer
| null = null;
/**
* 播放asset资源中的音频
*/
export function playAssetAudio() {
let assetManager = UTSAndroid.getAppContext()!.getAssets();
let afd = assetManager.openFd("free.mp3");
if
(globalPlayer == null)
{
if
(globalPlayer == null)
{
globalPlayer = new MediaPlayer();
globalPlayer!.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
globalPlayer!.setDataSource(afd.getFileDescriptor(),
afd.getStartOffset(), afd.getLength());
globalPlayer!.prepare();
globalPlayer!.start();
}
}
...
...
@@ -203,51 +204,51 @@ export function playAssetAudio() {
* 停止播放asset资源中的音频
*/
export function stopAssetAudio() {
if
(globalPlayer != null)
{
if
(globalPlayer != null)
{
globalPlayer!.stop();
globalPlayer = null;
}
}
export function goOtherActivity(imageDone
: (event:string) => void):
boolean {
export function goOtherActivity(imageDone
: (event : string) => void) :
boolean {
// 检查相关权限是否已经具备
if (ActivityCompat.checkSelfPermission(UTSAndroid.getUniActivity()!, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
// 不具备权限,申请权限,并且告知用户监听失败
ActivityCompat.requestPermissions(UTSAndroid.getUniActivity()!, arrayOf(Manifest.permission.CAMERA), 1002)
return false;
}
UTSAndroid.onAppActivityResult((requestCode
: Int, resultCode: Int, data
?: Intent) => {
let eventName = "onAppActivityResult - requestCode:" + requestCode + " -resultCode:"
+resultCode + " -data:"+
JSON.stringify(data);
console.log(eventName);
UTSAndroid.onAppActivityResult((requestCode
: Int, resultCode : Int, data
?: Intent) => {
let eventName = "onAppActivityResult - requestCode:" + requestCode + " -resultCode:"
+ resultCode + " -data:" +
JSON.stringify(data);
console.log(eventName);
if ((requestCode == 1001) && (resultCode == Activity.RESULT_OK)) {
if (data != null) {
let bundle = data.getExtras();
let mImageBitmap = bundle!.get("data") as Bitmap;
let bitmapPath = UTSAndroid.getUniActivity()!.getExternalCacheDir()!.getPath() + "/photo.png"
console.log(bitmapPath);
try
{
mImageBitmap.compress(Bitmap.CompressFormat.PNG,100,
new FileOutputStream(bitmapPath))
}catch(e)
{
}
imageDone(bitmapPath);
}
}
if (data != null) {
let bundle = data.getExtras();
let mImageBitmap = bundle!.get("data") as Bitmap;
let bitmapPath = UTSAndroid.getUniActivity()!.getExternalCacheDir()!.getPath() + "/photo.png"
console.log(bitmapPath);
try
{
mImageBitmap.compress(Bitmap.CompressFormat.PNG, 100,
new FileOutputStream(bitmapPath))
} catch (e)
{
}
imageDone(bitmapPath);
}
}
});
let takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//resolveActivity 返回可处理 Intent 的第一个 Activity 组件
if (takePictureIntent.resolveActivity(UTSAndroid.getUniActivity()!.getPackageManager()) != null) {
UTSAndroid.getUniActivity()!.startActivityForResult(takePictureIntent, 1001);
}
return true;
}
...
...
@@ -255,68 +256,68 @@ export function goOtherActivity(imageDone: (event:string) => void):boolean {
* 初始化应用生命周期监听
*
*/
export function initAppLifecycle(onLifecycleChange
: (event:
string) => void) {
export function initAppLifecycle(onLifecycleChange
: (event :
string) => void) {
/**
* application 内存不足的回调函数
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onapptrimmemory
*/
UTSAndroid.onAppTrimMemory((level
:
Number) => {
UTSAndroid.onAppTrimMemory((level
:
Number) => {
let eventName = "onAppTrimMemory - " + level;
onLifecycleChange(eventName);
console.log(eventName);
console.log(eventName);
});
/**
* application 状态改变的回调函数
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onAppConfigChange
*/
UTSAndroid.onAppConfigChange((ret
:
UTSJSONObject) => {
UTSAndroid.onAppConfigChange((ret
:
UTSJSONObject) => {
let eventName = "onAppConfigChange - " + JSON.stringify(ret);
onLifecycleChange(eventName);
console.log(eventName);
console.log(eventName);
});
/**
* activity 销毁生命周期回调
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitydestroy
*/
UTSAndroid.onAppActivityDestroy(() => {
UTSAndroid.onAppActivityDestroy(() => {
let eventName = "onAppActivityDestroy";
onLifecycleChange(eventName);
console.log(eventName);
});
console.log(eventName);
});
/**
* activity 失去焦点生命周期回调
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitypause
*/
UTSAndroid.onAppActivityPause(() => {
let eventName = "onAppActivityPause"
;
UTSAndroid.onAppActivityPause(() => {
let eventName = "onAppActivityPause";
onLifecycleChange(eventName);
console.log(eventName);
});
console.log(eventName);
});
/**
* activity 得到焦点的周期回调
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityresume
*/
UTSAndroid.onAppActivityResume(() => {
UTSAndroid.onAppActivityResume(() => {
let eventName = "onAppActivityResume";
onLifecycleChange(eventName);
console.log(eventName);
});
console.log(eventName);
});
/**
* activity 回退物理按键事件回调
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityback
*/
UTSAndroid.onAppActivityBack(() => {
UTSAndroid.onAppActivityBack(() => {
let eventName = "onAppActivityBack";
onLifecycleChange(eventName);
console.log(eventName);
});
console.log(eventName);
});
}
...
...
@@ -331,29 +332,87 @@ export function unRegLifecycle() {
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onapptrimmemory
*/
UTSAndroid.offAppTrimMemory();
/**
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onAppConfigChange
*/
UTSAndroid.offAppConfigChange();
/**
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitydestroy
*/
UTSAndroid.offAppActivityDestroy();
UTSAndroid.offAppActivityDestroy();
/**
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivitypause
*/
UTSAndroid.offAppActivityPause();
UTSAndroid.offAppActivityPause();
/**
* 说明文档:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#onappactivityresume
*/
UTSAndroid.offAppActivityResume();
UTSAndroid.offAppActivityResume();
/**
* activity 回退物理按键事件回调
*/
UTSAndroid.offAppActivityBack();
UTSAndroid.offAppActivityBack();
}
/**
* add since 2023-06-19
* 新增传参测试用例
*/
export function inputArray(input : Array<string>) : boolean {
let inputStr = JSON.stringify(input)
if ('["a","b","c"]' == inputStr) {
return true
}
return false
}
export type ParamOptions = {
title : string,
array : Array<string>
}
export function inputParam(option : ParamOptions) : boolean {
let inputStr = JSON.stringify(option)
if ('{"array":[1,2,3],"title":"hello"}' == inputStr) {
return true
}
return false
}
export function returnArray() : Array<string> {
return ['1', '2', '3']
}
export function returnParam() : ParamOptions {
let ret : ParamOptions = {
title: "returnParam",
array: ['1', '2', '3']
}
return ret
}
export type ParamCallback = (res : ParamOptions) => void
export type ArrayCallback = (res : Array<string>) => void
export function callbackArray(callback : ArrayCallback) {
callback(['8', '8', '8'])
}
export function callbackParam(callback : ParamCallback) {
let ret : ParamOptions = {
title: "callbackParam",
array: ['4', '5', '6']
}
callback(ret)
}
\ No newline at end of file
uni_modules/uts-nativepage/utssdk/app-android/index.uts
浏览文件 @
fafc1265
...
...
@@ -255,7 +255,7 @@ class DemoActivity extends Activity{
let recyclerView = this.findViewById<RecyclerView>(R.id.recycler_view)
let layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
let fruitAdapter = new FruitAdapter(
arrayList
Of("香蕉","苹果","大鸭梨"));
let fruitAdapter = new FruitAdapter(
utsArray
Of("香蕉","苹果","大鸭梨"));
recyclerView.setAdapter(fruitAdapter);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录