提交 79887d56 编写于 作者: 杜庆泉's avatar 杜庆泉

hello uts native-page 插件增加 Handler 使用示例

上级 f04e867f
......@@ -61,6 +61,9 @@ export function sayHelloFromJar(): string {
}
export class AppHookProxy implements UTSAndroidHookProxy {
override onCreate(application: Application) {
//当前应用是否 取得用户同意隐私协议
......@@ -308,16 +311,31 @@ class FruitAdapter extends RecyclerView.Adapter<FruitAdapter.ViewHolder>{
}
@Suppress("DEPRECATION")
class DemoActivity extends Activity{
constructor (){
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 {
super.onCreate(savedInstanceState)
this.setContentView(R.layout.demo_activity);
new CustomHandler().sendEmptyMessage(111);
let btn_start_service_front = this.findViewById<Button>(R.id.btn_start_service_front);
btn_start_service_front.setOnClickListener(new StartServiceListener());
......@@ -342,6 +360,7 @@ class DemoActivity extends Activity{
recyclerView.setLayoutManager(layoutManager);
let fruitAdapter = new FruitAdapter(utsArrayOf("香蕉","苹果","大鸭梨"));
recyclerView.setAdapter(fruitAdapter);
}
}
......
......@@ -3,12 +3,18 @@ import { describe, test, expect, Result } from './tests.uts'
export function testDate() : Result {
return describe("Date", () => {
test('now', () => {
UTSAndroid.getDispatcher("io").async(function(_){
const start = Date.now()
setTimeout(() => {
const millis = Date.now() - start
console.log("start",start)
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', () => {
let date1 = new Date('1992-02-02');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册