提交 0877c9e2 编写于 作者: WOSHIMAHAIFENG's avatar WOSHIMAHAIFENG

Merge branch 'dev' into 'alpha'

Dev

See merge request !8
<template> <template>
<!-- #ifdef APP-ANDROID --> <!-- #ifdef APP-ANDROID -->
<!-- #ifdef APP -->
<scroll-view style="flex: 1"> <scroll-view style="flex: 1">
<!-- #endif -->
<view> <view>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text"> 逐一点击执行,观察测试反馈 </view> <view class="uni-hello-text"> 逐一点击执行,观察测试反馈 </view>
...@@ -18,6 +16,7 @@ ...@@ -18,6 +16,7 @@
<button @click="dispatchAsyncClick">任务分发测试</button> <button @click="dispatchAsyncClick">任务分发测试</button>
<button @click="pathTestClick">路径转换测试</button> <button @click="pathTestClick">路径转换测试</button>
<button @click="privacyStateClick">隐私协议状态测试</button> <button @click="privacyStateClick">隐私协议状态测试</button>
<button @click="privacyStateCallBackClick">隐私协议回调测试</button>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text"> <view class="uni-hello-text">
1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。 1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。
...@@ -42,16 +41,26 @@ ...@@ -42,16 +41,26 @@
</view> </view>
<button @tap="getDeviceInfoClick">获取设备基础信息</button> <button @tap="getDeviceInfoClick">获取设备基础信息</button>
<button @tap="getFileProviderUriClick">使用外部应用访问私有文件</button> <button @tap="getFileProviderUriClick">使用外部应用访问私有文件</button>
<button @tap="activityCallback">注册activity 回调方法</button>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
点击注册activity 回调方法后,可以手动切换其他APP再返回,可在控制台和界面观察事件日志
</view>
</view>
<view class="uni-padding-wrap uni-common-mt">
<view class="text-box" scroll-y="true">
<text>{{ cbText }}</text>
</view>
</view>
<button @tap="unRegActivityCallback">取消注册activity 回调方法</button>
</view> </view>
<!-- #ifdef APP -->
</scroll-view> </scroll-view>
<!-- #endif --> <!-- #endif -->
<!-- #endif -->
</template> </template>
<script> <script>
<!-- #ifdef APP-ANDROID --> import {
import {
getAppContextTest, getAppContextTest,
getUniActivityTest, getUniActivityTest,
getJavaClassTest, getJavaClassTest,
...@@ -66,21 +75,41 @@ import { ...@@ -66,21 +75,41 @@ import {
initAppLifecycle, initAppLifecycle,
gotoCameraTake, gotoCameraTake,
getDeviceInfoTest, getDeviceInfoTest,
privacyStateTest, privacyStateTest
} from '@/uni_modules/uts-platform-api' } from '@/uni_modules/uts-platform-api'
import File from 'java.io.File'; // #ifdef APP-ANDROID
import Intent from 'android.content.Intent'; import {
UTSAcvitiyLifeCycleCallback,
UTSAcvitiyKeyEventCallback,
UTSActivityWindowCallback,
UTSActivityCallback,
UTSActivityComponentCallback,
onCallbackChange
} from '@/uni_modules/uts-syntaxcase'
// #endif
/** import File from 'java.io.File';
import Intent from 'android.content.Intent';
/**
* 测试在页面生命周期之外,使用api * 测试在页面生命周期之外,使用api
*/ */
export default { export default {
data() { data() {
return { return {
text: '', text: '',
cbText: '',
selectImage: '', selectImage: '',
callback: [] as Any[]
} }
}, },
unmounted() {
// #ifdef APP-ANDROID
this.unRegActivityCallback()
// #endif
},
onLoad: function () { onLoad: function () {
let that = this let that = this
initAppLifecycle(function (eventLog) { initAppLifecycle(function (eventLog) {
...@@ -106,6 +135,33 @@ export default { ...@@ -106,6 +135,33 @@ export default {
} }
}) })
}, },
privacyStateCallBackClick() {
let isAgree : boolean = true
const cb = (ret : PrivacyOption) => {
console.log('privacyStateCallBackTest->' + ret.isAgree)
if (ret.isAgree==isAgree) {
uni.showToast({
title: '测试通过'
})
} else {
uni.showToast({
icon: 'none',
title: '失败'
})
}
}
// 先重置用户同意状态
UTSAndroid.onPrivacyAgreeChange(cb)
UTSAndroid.setPrivacyAgree(isAgree)
UTSAndroid.offPrivacyAgreeChange(cb)
setTimeout(function () {
console.log('privacyStateCallBackTest->false' )
UTSAndroid.setPrivacyAgree(false)
}, 5000);
},
getDeviceInfoClick() { getDeviceInfoClick() {
this.text = getDeviceInfoTest() this.text = getDeviceInfoTest()
}, },
...@@ -180,7 +236,7 @@ export default { ...@@ -180,7 +236,7 @@ export default {
getFileProviderUriClick() { getFileProviderUriClick() {
let file = new File(UTSAndroid.getResourcePath("static/logo.png")) let file = new File(UTSAndroid.getResourcePath("static/logo.png"))
const uri = UTSAndroid.getFileProviderUri(file) const uri = UTSAndroid.getFileProviderUri(file)
console.log("uri",uri.toString()) console.log("uri", uri.toString())
const intent = new Intent(Intent.ACTION_VIEW, uri) const intent = new Intent(Intent.ACTION_VIEW, uri)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 添加权限标志 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 添加权限标志
const context = UTSAndroid.getUniActivity()!; const context = UTSAndroid.getUniActivity()!;
...@@ -258,13 +314,70 @@ export default { ...@@ -258,13 +314,70 @@ export default {
} }
}) })
}, },
// #ifdef APP-ANDROID
// #ifdef UNI-APP-X
activityCallback() {
var that = this
onCallbackChange(function (eventLog : string) {
// 展示捕捉到的声明周期日志
let nextLine = that.cbText + eventLog
that.cbText = nextLine
let nextLineFlag = that.cbText + '\n'
that.cbText = nextLineFlag
})
this.callback.push(new UTSAcvitiyLifeCycleCallback())
this.callback.push(new UTSActivityWindowCallback())
this.callback.push(new UTSAcvitiyKeyEventCallback())
this.callback.push(new UTSActivityCallback())
this.callback.push(new UTSActivityComponentCallback())
this.callback.forEach((value) => {
if (value instanceof UTSAcvitiyLifeCycleCallback) {
UTSAndroid.onActivityCallback(value)
}
if (value instanceof UTSActivityWindowCallback) {
UTSAndroid.onActivityCallback(value)
}
if (value instanceof UTSAcvitiyKeyEventCallback) {
UTSAndroid.onActivityCallback(value)
}
if (value instanceof UTSActivityCallback) {
UTSAndroid.onActivityCallback(value)
}
if (value instanceof UTSActivityComponentCallback) {
UTSAndroid.onActivityCallback(value)
}
})
}, },
} unRegActivityCallback() {
<!-- #endif --> this.callback.forEach((value) => {
if (value instanceof UTSAcvitiyLifeCycleCallback) {
UTSAndroid.offActivityCallback(value)
}
if (value instanceof UTSActivityWindowCallback) {
UTSAndroid.offActivityCallback(value)
}
if (value instanceof UTSAcvitiyKeyEventCallback) {
UTSAndroid.offActivityCallback(value)
}
if (value instanceof UTSActivityCallback) {
UTSAndroid.offActivityCallback(value)
}
if (value instanceof UTSActivityComponentCallback) {
UTSAndroid.offActivityCallback(value)
}
})
}
// #endif
// #endif
},
}
</script> </script>
<style> <style>
.testButton { .testButton {
width: 100%; width: 100%;
} }
</style> </style>
\ No newline at end of file
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<button @click="dispatchAsyncClick">任务分发测试</button> <button @click="dispatchAsyncClick">任务分发测试</button>
<button @click="pathTestClick">路径转换测试</button> <button @click="pathTestClick">路径转换测试</button>
<button @click="privacyStateClick">隐私协议状态测试</button> <button @click="privacyStateClick">隐私协议状态测试</button>
<button @click="privacyStateCallBackClick">隐私协议回调测试</button>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text"> <view class="uni-hello-text">
1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。 1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。
...@@ -60,7 +61,8 @@ ...@@ -60,7 +61,8 @@
initAppLifecycle, initAppLifecycle,
gotoCameraTake, gotoCameraTake,
getDeviceInfoTest, getDeviceInfoTest,
privacyStateTest privacyStateTest,
privacyStateCallBackTest
} from '@/uni_modules/uts-platform-api' } from '@/uni_modules/uts-platform-api'
/** /**
* 测试在页面生命周期之外,使用api * 测试在页面生命周期之外,使用api
...@@ -95,6 +97,20 @@ ...@@ -95,6 +97,20 @@
} }
}) })
}, },
privacyStateCallBackClick() {
privacyStateCallBackTest(function(ret, desc) {
if (ret) {
uni.showToast({
title: '测试通过'
})
} else {
uni.showToast({
icon: 'none',
title: '失败:' + desc
})
}
})
},
getDeviceInfoClick(){ getDeviceInfoClick(){
this.text = getDeviceInfoTest() this.text = getDeviceInfoTest()
}, },
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
</view> </view>
</template> </template>
<script lang="ts"> <script lang="ts">
import { gotoDemoActivity } from "@/uni_modules/uts-nativepage"; import { gotoDemoActivity,sayHelloFromJar } from "@/uni_modules/uts-nativepage";
import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo"; import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo";
type Page = { type Page = {
...@@ -66,6 +66,9 @@ ...@@ -66,6 +66,9 @@
pages: [{ pages: [{
name: "自定义activity(需自定义基座)", name: "自定义activity(需自定义基座)",
function: "testGotoDemoActivity" function: "testGotoDemoActivity"
},{
name: "调用jar中的方法",
function: "testNativeJar"
}] as Page[] }] as Page[]
} }
] as ListItem[], ] as ListItem[],
...@@ -93,6 +96,8 @@ ...@@ -93,6 +96,8 @@
break break
case 'testGotoDemoActivity': case 'testGotoDemoActivity':
this.testGotoDemoActivity() this.testGotoDemoActivity()
case 'testNativeJar':
this.testNativeJar()
break break
} }
return return
...@@ -112,6 +117,13 @@ ...@@ -112,6 +117,13 @@
} }
} as GetBatteryInfoOptions) } as GetBatteryInfoOptions)
}, },
testNativeJar() {
let ret = sayHelloFromJar();
uni.showToast({
icon: 'none',
title: '来自jar中的返回值:' + ret
})
},
testGotoDemoActivity() { testGotoDemoActivity() {
let ret = gotoDemoActivity(); let ret = gotoDemoActivity();
if (!ret) { if (!ret) {
......
...@@ -18,8 +18,13 @@ ...@@ -18,8 +18,13 @@
android:resource="@xml/custom_accessibility_service_config" /> android:resource="@xml/custom_accessibility_service_config" />
</service> </service>
<service android:name="uts.sdk.modules.utsNativepage.ForeService" /> <service android:name="uts.sdk.modules.utsNativepage.ForeService" android:exported="true"/>
<activity android:name="uts.sdk.modules.utsNativepage.DemoActivity"></activity> <activity android:name="uts.sdk.modules.utsNativepage.DemoActivity" android:exported="true">
<intent-filter>
<action android:name="uts.sdk.modules.demo" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!--桌面widget组件注册--> <!--桌面widget组件注册-->
<receiver <receiver
android:name="uts.sdk.modules.utsNativepage.DoAppWidget" android:name="uts.sdk.modules.utsNativepage.DoAppWidget"
......
{ {
"dependencies": [ "dependencies": [
"androidx.recyclerview:recyclerview:1.0.0" "androidx.recyclerview:recyclerview:1.0.0",
"androidx.core:core:1.10.1"
] ]
} }
...@@ -16,6 +16,10 @@ import Build from 'android.os.Build'; ...@@ -16,6 +16,10 @@ import Build from 'android.os.Build';
import IBinder from 'android.os.IBinder'; import IBinder from 'android.os.IBinder';
import Toast from 'android.widget.Toast'; import Toast from 'android.widget.Toast';
import ShortcutInfoCompat from 'androidx.core.content.pm.ShortcutInfoCompat'
import ShortcutManagerCompat from 'androidx.core.content.pm.ShortcutManagerCompat'
import IconCompat from 'androidx.core.graphics.drawable.IconCompat'
import Service from 'android.app.Service'; import Service from 'android.app.Service';
import System from 'java.lang.System'; import System from 'java.lang.System';
...@@ -27,17 +31,45 @@ import LayoutInflater from 'android.view.LayoutInflater'; ...@@ -27,17 +31,45 @@ import LayoutInflater from 'android.view.LayoutInflater';
import LinearLayoutManager from 'androidx.recyclerview.widget.LinearLayoutManager'; import LinearLayoutManager from 'androidx.recyclerview.widget.LinearLayoutManager';
export {DoAppWidget} from "./DoAppWidget.uts" export {DoAppWidget} from "./DoAppWidget.uts"
import Application from 'android.app.Application'; import Application from 'android.app.Application';
import Log from 'android.util.Log';
import File from 'java.io.File'; import File from 'java.io.File';
import Uri from 'android.net.Uri'; import Uri from 'android.net.Uri';
export * from './CustomAccessibilityService.uts' export * from './CustomAccessibilityService.uts'
import SayHelloTest from 'com.test.sayhello.SayHelloTest'
export function sayHelloFromJar(): string {
// 这里的逻辑是为了判断 当前的自定义activity 是否注册了,并以此为条件判断是否是自定义基座
let hasXActivityIntegration = true
try{
let packageManager = UTSAndroid.getUniActivity()!.getPackageManager();
let intent = new Intent(UTSAndroid.getUniActivity(),DemoActivity().javaClass);
let resolveInfo = packageManager.queryIntentActivities(intent,0);
console.log(resolveInfo.size)
if(resolveInfo.size == 0){
hasXActivityIntegration = false;
}
}catch(e:Exception){
console.log(e);
hasXActivityIntegration = false;
}
if(!hasXActivityIntegration){
return "需要在自定义基座运行";
}
return SayHelloTest().say()
}
export class AppHookProxy implements UTSAndroidHookProxy { export class AppHookProxy implements UTSAndroidHookProxy {
override onCreate(application: Application) { override onCreate(application: Application) {
//当前应用是否 取得用户同意隐私协议 //当前应用是否 取得用户同意隐私协议
android.util.Log.d("AppHookProxy", "AppHookProxy--onCreate---") Log.d("AppHookProxy", "AppHookProxy--onCreate---")
// 初始化快捷方式
initShortCut()
if(UTSAndroid.isPrivacyAgree()) { if(UTSAndroid.isPrivacyAgree()) {
//onCreate 初始化三方SDK //onCreate 初始化三方SDK
android.util.Log.d("AppHookProxy", "AppHookProxy--onCreate---isPrivacyAgree") Log.d("AppHookProxy", "AppHookProxy--onCreate---isPrivacyAgree")
} }
} }
} }
...@@ -321,6 +353,48 @@ class IntentRunable extends Runnable{ ...@@ -321,6 +353,48 @@ class IntentRunable extends Runnable{
UTSAndroid.getUniActivity()!.startActivity(intent); UTSAndroid.getUniActivity()!.startActivity(intent);
} }
} }
/**
* 给当前应用设置快捷方式
* 仅支持 android 7.1 以上版本,自定义基座查看
*/
function initShortCut() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
console.log("桌面快捷方式 仅支持android 7.1 以上版本")
return;
}
// 注意 id 不能重复
let shortcutBuilder = ShortcutInfoCompat.Builder(UTSAndroid.getAppContext()!, "id1");
shortcutBuilder.setShortLabel("官网")
shortcutBuilder.setLongLabel("访问官网")
shortcutBuilder.setIcon(IconCompat.createWithResource(UTSAndroid.getAppContext()!, R.drawable.icon_short))
shortcutBuilder.setIntent(
new Intent(
Intent.ACTION_VIEW,
Uri.parse("https://dcloud.io/")
)
)
let shortcut = shortcutBuilder.build()
// 注意 id 不能重复
let shortcutBuilder2 = ShortcutInfoCompat.Builder(UTSAndroid.getAppContext()!, "id2");
shortcutBuilder2.setShortLabel("示例界面")
shortcutBuilder2.setLongLabel("打开示例界面,最多可以写25个字")
shortcutBuilder2.setIcon(IconCompat.createWithResource(UTSAndroid.getAppContext()!, R.drawable.icon_short))
shortcutBuilder2.setIntent(
new Intent(
"uts.sdk.modules.demo"
)
)
let shortcut2 = shortcutBuilder2.build()
// #ifdef UNI-APP-X
ShortcutManagerCompat.setDynamicShortcuts(UTSAndroid.getAppContext()!, [shortcut,shortcut2].toKotlinList())
// #endif
// #ifndef UNI-APP-X
console.log("当前示例仅支持uni-app x环境")
// #endif
}
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
export function gotoDemoActivity():boolean { export function gotoDemoActivity():boolean {
......
...@@ -81,6 +81,27 @@ export function privacyStateTest(callback : (ret : boolean, desc : string) => vo ...@@ -81,6 +81,27 @@ export function privacyStateTest(callback : (ret : boolean, desc : string) => vo
} }
export function privacyStateCallBackTest(callback : (ret : boolean, desc : string) => void) {
let isAgree : boolean = true
const cb = (ret : PrivacyOption) => {
console.log('privacyStateCallBackTest->' + ret.isAgree)
if (ret.isAgree == isAgree) {
callback(true, "pass")
} else {
callback(false, "callback error")
}
}
// 先重置用户同意状态
UTSAndroid.onPrivacyAgreeChange(cb)
UTSAndroid.setPrivacyAgree(isAgree)
UTSAndroid.offPrivacyAgreeChange(cb)
setTimeout(function () {
console.log('privacyStateCallBackTest->false')
UTSAndroid.setPrivacyAgree(false)
}, 5000);
}
/** /**
* UTSAndroid.getAppTempPath 测试示例 * UTSAndroid.getAppTempPath 测试示例
*/ */
......
...@@ -98,8 +98,8 @@ export async function testAsync(opts : AsyncOptions) : Promise<SyntaxResult> { ...@@ -98,8 +98,8 @@ export async function testAsync(opts : AsyncOptions) : Promise<SyntaxResult> {
} }
export async function testAsyncParam3(id:number,name:string,opts : AsyncOptions) : Promise<SyntaxResult> { export async function testAsyncParam3(id : number, name : string, opts : AsyncOptions) : Promise<SyntaxResult> {
console.log("id",id,"name",name) console.log("id", id, "name", name)
if (opts.type == "success") { if (opts.type == "success") {
opts.success("success"); opts.success("success");
} else { } else {
...@@ -166,3 +166,148 @@ class RequestTaskImpl implements RequestTask { ...@@ -166,3 +166,148 @@ class RequestTaskImpl implements RequestTask {
export function request(url : string) : RequestTask | null { export function request(url : string) : RequestTask | null {
return new RequestTaskImpl(url) return new RequestTaskImpl(url)
} }
// #ifdef APP-ANDROID
// #ifdef UNI-APP-X
import KeyEvent from 'android.view.KeyEvent';
import Configuration from 'android.content.res.Configuration';
import Bundle from 'android.os.Bundle';
import Menu from 'android.view.Menu';
import KeyboardShortcutGroup from 'android.view.KeyboardShortcutGroup';
import WindowManager from 'android.view.WindowManager';
import ActionMode from 'android.view.ActionMode';
// export let onCallBackChange: (event: string) => void = (res) => {};
let callback : (eventLog : string) => void = (res) => { };
export function onCallbackChange(fn : (eventLog : string) => void) {
callback = fn
}
export class UTSAcvitiyLifeCycleCallback extends UniActivityLifeCycleCallback {
constructor() {
super()
}
override onCreate(params : UniActivityParams, savedInstanceState : Bundle | null) {
console.log('UTSAcvitiyLifeCycle', 'onCreate', savedInstanceState)
callback('onCreate')
}
override onResume(params : UniActivityParams) {
console.log('UTSAcvitiyLifeCycle', 'onResume', params)
callback('onResume')
}
override onPreResume(params : UniActivityParams) {
console.log('UTSAcvitiyLifeCycle', 'onPreResume', params)
callback('onPreResume')
}
override onStart(params : UniActivityParams) {
console.log('UTSAcvitiyLifeCycle', 'onStart', params)
callback('onStart')
}
override onPreStart(params : UniActivityParams) {
console.log('UTSAcvitiyLifeCycle', 'onPreStart', params)
callback('onPreStart')
}
}
export class UTSAcvitiyKeyEventCallback extends UniActivityKeyEventCallback {
constructor() {
super()
}
override onKeyDown(params : UniActivityParams, keyCode : Int, event : KeyEvent | null) {
console.log('UTSAcvitiyKeyEvent', 'onKeyDown', params, keyCode, '' + event)
callback('onKeyDown')
}
override onPreKeyDown(params : UniActivityParams, keyCode : Int, event : KeyEvent | null) {
console.log('UTSAcvitiyKeyEvent', 'onPreKeyDown', params, keyCode, '' + event)
callback('onPreKeyDown')
}
override onKeyLongPress(params : UniActivityParams, keyCode : Int, event : KeyEvent | null) {
console.log('UTSAcvitiyKeyEvent', 'onKeyLongPress', params, keyCode, '' + event)
callback('onKeyLongPress')
}
override onPreKeyLongPress(params : UniActivityParams, keyCode : Int, event : KeyEvent | null) {
console.log('UTSAcvitiyKeyEvent', 'onPreKeyLongPress', params, keyCode, '' + event)
callback('onPreKeyLongPress')
}
}
export class UTSActivityWindowCallback extends UniActivityWindowCallback {
constructor() {
super()
}
override dispatchPreKeyEvent(params : UniActivityParams, event : KeyEvent | null) {
console.log('UTSActivityWindowCallback', 'dispatchPreKeyEvent', params, '' + event)
callback('dispatchPreKeyEvent')
}
override dispatchKeyEvent(params : UniActivityParams, event : KeyEvent | null) {
console.log('UTSActivityWindowCallback', 'dispatchKeyEvent', params, '' + event)
callback('dispatchKeyEvent')
}
override onWindowAttributesChanged(params : UniActivityParams, attrs : WindowManager.LayoutParams) {
console.log('UTSActivityWindowCallback', 'onWindowAttributesChanged', '' + attrs)
callback('onWindowAttributesChanged')
}
override onAttachedToWindow(params : UniActivityParams) {
console.log('UTSActivityWindowCallback', 'onAttachedToWindow', params)
callback('onAttachedToWindow')
}
override onPanelClosed(params : UniActivityParams, featureId : Int, menu : Menu) {
console.log('UTSActivityWindowCallback', 'onPanelClosed', featureId, menu)
callback('onPanelClosed')
}
override onWindowStartingActionMode(params : UniActivityParams, callback : ActionMode.Callback | null) {
console.log('UTSActivityWindowCallback', 'onWindowStartingActionMode', callback)
callback('onWindowStartingActionMode')
}
override onProvideKeyboardShortcuts(params : UniActivityParams, data : MutableList<KeyboardShortcutGroup> | null, menu : Menu | null, deviceId : Int) {
console.log('UTSActivityWindowCallback', 'onProvideKeyboardShortcuts', data, menu)
callback('onProvideKeyboardShortcuts')
}
override onPreWindowAttributesChanged(params : UniActivityParams, attrs : WindowManager.LayoutParams) {
console.log('UTSActivityWindowCallback', 'onPreWindowAttributesChanged', attrs)
callback('onPreWindowAttributesChanged')
}
override onPrePanelClosed(params : UniActivityParams, featureId : Int, menu : Menu) {
console.log('UTSActivityWindowCallback', 'onPrePanelClosed', featureId, menu)
callback('onPrePanelClosed')
}
}
export class UTSActivityCallback extends UniActivityCallback {
constructor() {
super()
}
override onBackPressed(params : UniActivityParams) {
console.log('UTSActivityCallback', 'onBackPressed', params)
callback('onBackPressed')
}
override onPreBackPressed(params : UniActivityParams) {
console.log('UTSActivityCallback', 'onPreBackPressed', params)
callback('onPreBackPressed')
}
override onRequestPermissionsResult(params : UniActivityParams, requestCode : Int, permissions : MutableList<String>, grantResults : IntArray) {
console.log('UTSActivityCallback', 'onRequestPermissionsResult', params)
callback('onRequestPermissionsResult')
}
}
export class UTSActivityComponentCallback extends UniActivityComponentCallback {
constructor() {
super()
}
override onConfigurationChanged(params : UniActivityParams, newConfig : Configuration) {
console.log('UTSActivityComponentCallback', 'onConfigurationChanged', params, '' + newConfig)
callback('onConfigurationChanged')
}
override onPreConfigurationChanged(params : UniActivityParams, newConfig : Configuration) {
console.log('UTSActivityComponentCallback', 'onPreConfigurationChanged', params, '' + newConfig)
callback('onPreConfigurationChanged')
}
}
// #endif
// #endif
\ No newline at end of file
...@@ -65,6 +65,19 @@ export function testDate() : Result { ...@@ -65,6 +65,19 @@ export function testDate() : Result {
}) })
test('newDateTest', () => {
// #ifdef APP-ANDROID
expect(new Date("2024/5/1").toString()).toEqual("Wed May 01 2024 00:00:00 GMT+0800");
expect(new Date("2024/5/1 10:00:00").toString()).toEqual("Wed May 01 2024 10:00:00 GMT+0800");
expect(new Date("2024-05-01 10:00:00").toString()).toEqual("Wed May 01 2024 10:00:00 GMT+0800");
expect(new Date("2024-05-01 11:00").toString()).toEqual("Wed May 01 2024 11:00:00 GMT+0800");
expect(new Date("2024/05/01 12:00").toString()).toEqual("Wed May 01 2024 12:00:00 GMT+0800");
expect(new Date("2024-5-1 10:00").toString()).toEqual("Wed May 01 2024 10:00:00 GMT+0800");
expect(new Date("2024/5/1 10:00").toString()).toEqual("Wed May 01 2024 10:00:00 GMT+0800");
// #endif
})
test('getDate', () => { test('getDate', () => {
const birthday = new Date('August 19, 1975 23:15:30'); const birthday = new Date('August 19, 1975 23:15:30');
const date1 = birthday.getDate(); const date1 = birthday.getDate();
......
...@@ -9,6 +9,11 @@ export function testError(): Result { ...@@ -9,6 +9,11 @@ export function testError(): Result {
expect((e as Error).message).toEqual("Whoops!"); expect((e as Error).message).toEqual("Whoops!");
} }
}) })
test('UniError', () => {
expect(new UniError().message).toEqual('')
expect(new UniError('Whoops!').message).toEqual('Whoops!')
})
// test('name', () => { // test('name', () => {
// const e = new Error("Malformed input"); // e.name is 'Error' // const e = new Error("Malformed input"); // e.name is 'Error'
// e.name = "ParseError"; // e.name = "ParseError";
......
...@@ -3,6 +3,22 @@ import { describe, test, expect, Result } from './tests.uts' ...@@ -3,6 +3,22 @@ import { describe, test, expect, Result } from './tests.uts'
export function testGlobal(): Result { export function testGlobal(): Result {
return describe("Global", () => { return describe("Global", () => {
test('setInterval', () => {
// #ifdef APP-ANDROID
let aCount = 0
let taskId = setInterval(function(){
aCount += 1
},0)
setTimeout(function(){
console.log(aCount)
console.log(taskId)
clearInterval(taskId)
expect(aCount > 10).toEqual(true);
},200)
// #endif
})
test('parseInt', () => { test('parseInt', () => {
expect(parseInt("123.456")).toEqual(123); expect(parseInt("123.456")).toEqual(123);
expect(parseInt("123")).toEqual(123); expect(parseInt("123")).toEqual(123);
......
...@@ -157,6 +157,29 @@ export function testJSON() : Result { ...@@ -157,6 +157,29 @@ export function testJSON() : Result {
// expect((array3![0])["name"]).toEqual("John"); // expect((array3![0])["name"]).toEqual("John");
}) })
test('merge-test-1', () => {
// #ifdef APP-ANDROID
const data1 = {
name: 'Tom1',
age: 21
};
const data2 = {
aa: {
name: 'Tom2',
age: 22,
bb: {
name: 'Tom3',
age: 23
}
}
}
const obj = Object.assign(JSON.parse<UTSJSONObject>(JSON.stringify(data2))!, JSON.parse<UTSJSONObject>(JSON.stringify(data1))!) as UTSJSONObject;
const innerObj = obj.getJSON("aa.bb")
expect(innerObj instanceof UTSJSONObject).toEqual(true);
// #endif
})
test('stringify', () => { test('stringify', () => {
const obj = { name: 'John', age: 30 }; const obj = { name: 'John', age: 30 };
const json = JSON.stringify(obj); const json = JSON.stringify(obj);
...@@ -298,5 +321,14 @@ export function testJSON() : Result { ...@@ -298,5 +321,14 @@ export function testJSON() : Result {
expect(map.get('a')).toEqual(1) expect(map.get('a')).toEqual(1)
}) })
test('parse Map', () => {
type A = {
num: number,
}
const map = JSON.parse<Map<string, A>>(`{"a": {"num": 1}}`)
expect(map instanceof Map).toEqual(true)
expect(map?.get('a')?.num).toEqual(1)
})
}) })
} }
\ No newline at end of file
此差异已折叠。
...@@ -109,6 +109,8 @@ export function testMath(): Result { ...@@ -109,6 +109,8 @@ export function testMath(): Result {
expect(Math.ceil(4)).toEqual(4); expect(Math.ceil(4)).toEqual(4);
expect(Math.ceil(7.004)).toEqual(8); expect(Math.ceil(7.004)).toEqual(8);
expect(Math.ceil(-7.004)).toEqual(-7); expect(Math.ceil(-7.004)).toEqual(-7);
expect(Math.ceil(37110233000.223)).toEqual(37110233001);
expect(Math.ceil(-37110233000.223)).toEqual(-37110233000);
}) })
test('clz32', () => { test('clz32', () => {
expect(Math.clz32(1)).toEqual(31); expect(Math.clz32(1)).toEqual(31);
...@@ -141,6 +143,8 @@ export function testMath(): Result { ...@@ -141,6 +143,8 @@ export function testMath(): Result {
expect(Math.floor(5.05)).toEqual(5); expect(Math.floor(5.05)).toEqual(5);
expect(Math.floor(5)).toEqual(5); expect(Math.floor(5)).toEqual(5);
expect(Math.floor(-5.05)).toEqual(-6); expect(Math.floor(-5.05)).toEqual(-6);
expect(Math.floor(37110233000.223)).toEqual(37110233000);
expect(Math.floor(-37110233000.223)).toEqual(-37110233001);
}) })
test('fround', () => { test('fround', () => {
expect(Math.fround(1.5)).toEqual(1.5); expect(Math.fround(1.5)).toEqual(1.5);
...@@ -240,6 +244,8 @@ export function testMath(): Result { ...@@ -240,6 +244,8 @@ export function testMath(): Result {
expect(Math.round(0.9)).toEqual(1); expect(Math.round(0.9)).toEqual(1);
expect(Math.round(5.95)).toEqual(6); expect(Math.round(5.95)).toEqual(6);
expect(Math.round(-5.05)).toEqual(-5); expect(Math.round(-5.05)).toEqual(-5);
expect(Math.round(37110233000.223)).toEqual(37110233000);
expect(Math.round(-37110233000.223)).toEqual(-37110233000);
}) })
}) })
} }
import { describe, test, expect, expectNumber, Result } from './tests.uts'
export function testUTSJSONObject() : Result {
return describe("utsjsonobject", () => {
test('keys', () => {
// #ifdef APP-ANDROID
let obj = {
name:"zhangsan",
age:11
}
expect(UTSJSONObject.keys(obj).size).toEqual(2);
console.log(UTSJSONObject.keys(obj))
// #endif
})
test('assign-notype', () => {
// #ifdef APP-ANDROID
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };
const returnedTarget = UTSJSONObject.assign(target, source);
expect(returnedTarget!.toMap().size).toEqual(3);
console.log(returnedTarget)
// #endif
})
test('assign-withtype', () => {
// #ifdef APP-ANDROID
type User = {
a:number
b:number
}
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };
const returnedTarget = UTSJSONObject.assign<User>(target, source);
expect(returnedTarget!.a).toEqual(1);
console.log(returnedTarget)
// #endif
})
})
}
\ No newline at end of file
import { describe, test, expect, expectNumber, Result } from './tests.uts'
function obtainInnerObject(obj:Any | null):UTSJSONObject{
let jsonStr = console.getLogV2(obj).slice(19,-17)
let a = JSON.parseArray(jsonStr)![0]
return a as UTSJSONObject
}
export function testConsole() : Result {
return describe("log", () => {
test('log-native-obj', () => {
// #ifdef APP-ANDROID
expect(obtainInnerObject(0.9).get("type")).toEqual("Double");
expect(obtainInnerObject(0.9).get("subType")).toEqual("number");
expect(obtainInnerObject(0.9).get("value")).toEqual("0.9");
// #endif
}
)
})
}
\ No newline at end of file
...@@ -4,6 +4,9 @@ import { testString } from './String.uts' ...@@ -4,6 +4,9 @@ import { testString } from './String.uts'
import { testError } from './Error.uts' import { testError } from './Error.uts'
import { testKeyWord } from './KeyWord.uts' import { testKeyWord } from './KeyWord.uts'
import { testJSON } from './JSON.uts' import { testJSON } from './JSON.uts'
import { testJSONLarge } from './JSON_large.uts'
import { testUTSJSONObject } from './UTSJSONObject.uts'
import { testConsole } from './console.uts'
import { testNumber } from './Number.uts' import { testNumber } from './Number.uts'
import { testMap } from './Map.uts' import { testMap } from './Map.uts'
import { testSet } from './Set.uts' import { testSet } from './Set.uts'
...@@ -32,13 +35,16 @@ export function runTests() : UTSJSONObject { ...@@ -32,13 +35,16 @@ export function runTests() : UTSJSONObject {
const ForLoopRes = testForLoop(); const ForLoopRes = testForLoop();
const GlobalRes = testGlobal(); const GlobalRes = testGlobal();
const TypeRes = testType(); const TypeRes = testType();
const JSONLargeRes = testJSONLarge();
const consoleRes = testConsole();
const UTSJSONObjectRes = testUTSJSONObject();
return { return {
Array: ArrayRes, Array: ArrayRes,
Date: DateRes, Date: DateRes,
String: StringRes, String: StringRes,
Error: ErrorRes, Error: ErrorRes,
Json: JsonRes, Json: JsonRes,
JSONLarge:JSONLargeRes,
Number: NumberRes, Number: NumberRes,
Map: MapRes, Map: MapRes,
Set: SetRes, Set: SetRes,
...@@ -48,6 +54,8 @@ export function runTests() : UTSJSONObject { ...@@ -48,6 +54,8 @@ export function runTests() : UTSJSONObject {
KeyWord: KeyWordRes, KeyWord: KeyWordRes,
ForLoop: ForLoopRes, ForLoop: ForLoopRes,
Global: GlobalRes, Global: GlobalRes,
Type: TypeRes Type: TypeRes,
console:consoleRes,
UTSJSONObject:UTSJSONObjectRes
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册