Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
79887d56
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1598
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看板
提交
79887d56
编写于
7月 02, 2024
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hello uts native-page 插件增加 Handler 使用示例
上级
f04e867f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
63 addition
and
38 deletion
+63
-38
uni_modules/uts-nativepage/utssdk/app-android/index.uts
uni_modules/uts-nativepage/utssdk/app-android/index.uts
+50
-31
uni_modules/uts-tests/utssdk/Date.uts
uni_modules/uts-tests/utssdk/Date.uts
+13
-7
未找到文件。
uni_modules/uts-nativepage/utssdk/app-android/index.uts
浏览文件 @
79887d56
...
@@ -61,6 +61,9 @@ export function sayHelloFromJar(): string {
...
@@ -61,6 +61,9 @@ export function sayHelloFromJar(): string {
}
}
export class AppHookProxy implements UTSAndroidHookProxy {
export class AppHookProxy implements UTSAndroidHookProxy {
override onCreate(application: Application) {
override onCreate(application: Application) {
//当前应用是否 取得用户同意隐私协议
//当前应用是否 取得用户同意隐私协议
...
@@ -162,13 +165,13 @@ class StartServiceListener extends OnClickListener{
...
@@ -162,13 +165,13 @@ class StartServiceListener extends OnClickListener{
override onClick(v?: View):void{
override onClick(v?: View):void{
var intent = new Intent(UTSAndroid.getUniActivity(), ForeService().javaClass);
var intent = new Intent(UTSAndroid.getUniActivity(), ForeService().javaClass);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
UTSAndroid.getAppContext()!.startForegroundService(intent);
UTSAndroid.getAppContext()!.startForegroundService(intent);
}
}
else{
else{
UTSAndroid.getAppContext()!.startService(intent);
UTSAndroid.getAppContext()!.startService(intent);
}
}
}
}
}
}
...
@@ -308,40 +311,56 @@ class FruitAdapter extends RecyclerView.Adapter<FruitAdapter.ViewHolder>{
...
@@ -308,40 +311,56 @@ class FruitAdapter extends RecyclerView.Adapter<FruitAdapter.ViewHolder>{
}
}
@Suppress("DEPRECATION")
class DemoActivity extends Activity{
class DemoActivity extends Activity{
constructor (){
constructor (){
super();
super();
}
}
// 自定义 handler
CustomHandler = class extends android.os.Handler {
constructor (){
super();
}
override handleMessage(msg: android.os.Message) {
super.handleMessage(msg)
if(msg.what = 111){
console.log("handle message received:111")
}
}
}
override onCreate(savedInstanceState?: Bundle):void {
override onCreate(savedInstanceState?: Bundle):void {
super.onCreate(savedInstanceState)
super.onCreate(savedInstanceState)
this.setContentView(R.layout.demo_activity);
this.setContentView(R.layout.demo_activity);
let btn_start_service_front = this.findViewById<Button>(R.id.btn_start_service_front);
new CustomHandler().sendEmptyMessage(111);
btn_start_service_front.setOnClickListener(new StartServiceListener());
let btn_start_service_front = this.findViewById<Button>(R.id.btn_start_service_front);
let btn_start_screen_listen = this.findViewById<Button>(R.id.btn_start_screen_listen);
btn_start_service_front.setOnClickListener(new StartServiceListener());
btn_start_screen_listen.setOnClickListener(new StartBroadcastListener());
let btn_start_screen_listen = this.findViewById<Button>(R.id.btn_start_screen_listen);
let btn_start_thread = this.findViewById<Button>(R.id.btn_start_thread);
btn_start_screen_listen.setOnClickListener(new StartBroadcastListener());
btn_start_thread.setOnClickListener(new StartThreadListener());
let btn_start_thread = this.findViewById<Button>(R.id.btn_start_thread);
let btn_finish_activity = this.findViewById<Button>(R.id.btn_finish_activity);
btn_start_thread.setOnClickListener(new StartThreadListener());
btn_finish_activity.setOnClickListener(new ActivityFinishListener(this));
let btn_finish_activity = this.findViewById<Button>(R.id.btn_finish_activity);
let btn_start_root_activity = this.findViewById<Button>(R.id.btn_start_root_activity);
btn_finish_activity.setOnClickListener(new ActivityFinishListener(this));
btn_start_root_activity.setOnClickListener(new RootActivityStartListener(this));
let btn_start_root_activity = this.findViewById<Button>(R.id.btn_start_root_activity);
let btn_start_root_page = this.findViewById<Button>(R.id.btn_start_root_page);
btn_start_root_activity.setOnClickListener(new RootActivityStartListener(this));
btn_start_root_page.setOnClickListener(new RootPageStartListener(this));
let btn_start_root_page = this.findViewById<Button>(R.id.btn_start_root_page);
btn_start_root_page.setOnClickListener(new RootPageStartListener(this));
let recyclerView = this.findViewById<RecyclerView>(R.id.recycler_view)
let layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
let recyclerView = this.findViewById<RecyclerView>(R.id.recycler_view)
let fruitAdapter = new FruitAdapter(utsArrayOf("香蕉","苹果","大鸭梨"));
let layoutManager = new LinearLayoutManager(this);
recyclerView.setAdapter(fruitAdapter);
recyclerView.setLayoutManager(layoutManager);
let fruitAdapter = new FruitAdapter(utsArrayOf("香蕉","苹果","大鸭梨"));
recyclerView.setAdapter(fruitAdapter);
}
}
}
}
...
...
uni_modules/uts-tests/utssdk/Date.uts
浏览文件 @
79887d56
...
@@ -2,13 +2,19 @@ import { describe, test, expect, Result } from './tests.uts'
...
@@ -2,13 +2,19 @@ import { describe, test, expect, Result } from './tests.uts'
export function testDate() : Result {
export function testDate() : Result {
return describe("Date", () => {
return describe("Date", () => {
test('now', () => {
test('now', () => {
const start = Date.now()
UTSAndroid.getDispatcher("io").async(function(_){
setTimeout(() => {
const start = Date.now()
const millis = Date.now() - start
setTimeout(() => {
const secondsElapsed = Math.floor(millis / 1000)
const millis = Date.now() - start
expect(secondsElapsed).toEqual(2);
console.log("start",start)
}, 2000)
console.log("millis",millis)
console.log("currentThread",Thread.currentThread().getName())
const secondsElapsed = Math.floor(millis / 1000)
expect(secondsElapsed).toEqual(2);
}, 2000)
},null)
})
})
test('new Date', () => {
test('new Date', () => {
let date1 = new Date('1992-02-02');
let date1 = new Date('1992-02-02');
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录