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

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

上级 f04e867f
...@@ -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);
} }
} }
......
...@@ -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.
先完成此消息的编辑!
想要评论请 注册