提交 1685eb3a 编写于 作者: 杜庆泉's avatar 杜庆泉

lifecycle add

上级 1c4d58e0
...@@ -37,15 +37,6 @@ ...@@ -37,15 +37,6 @@
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
},
{
"path" : "pages/static/static",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}, },
{ {
"path" : "pages/lifecycle/lifecycle", "path" : "pages/lifecycle/lifecycle",
......
<template> <template>
<view>当前电量:</view> <view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="text-box" scroll-y="true">
<text>{{text}}</text>
</view>
</view>
</view>
</template> </template>
<script lang="ts" setup> <script>
import { initAppLifecycle } from '../../uni_modules/uts-advance' import { initAppLifecycle } from '../../uni_modules/uts-advance';
initAppLifecycle(); export default {
</script> data() {
\ No newline at end of file return {
title: '生命周期监听',
text: '',
}
},
onLoad:function(){
let that = this;
initAppLifecycle(function(name){
that.text = that.text += name;
that.text = that.text += '\n';
});
}
}
</script>
<style>
.text-box {
margin-bottom: 40rpx;
padding: 40rpx 0;
display: flex;
min-height: 300rpx;
background-color: #FFFFFF;
justify-content: center;
align-items: center;
text-align: center;
font-size: 30rpx;
color: #353535;
line-height: 1.8;
}
</style>
...@@ -3,15 +3,14 @@ ...@@ -3,15 +3,14 @@
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<image :src="logo" mode="aspectFit" style="width: 100%;"></image> <image :src="logo" mode="aspectFit" style="width: 100%;"></image>
<view class="uni-btn-v uni-common-mt"> <view class="uni-btn-v uni-common-mt">
<button type="primary" >展示插件内置图片</button> <button type="primary" @tap="testLogoLoad">展示插件内置图片</button>
<button type="primary" @tap="testAssetLoad" >播放asset音频(需自定义基座)</button> <button type="primary" @tap="testAssetLoad" >播放asset音频(需自定义基座)</button>
<button type="primary" @tap="testResText" >获取res目录资源(需自定义基座)</button>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import { getLogoPath,playAssetAudio,getResText } from '../../uni_modules/uts-advance' import { getLogoPath,playAssetAudio } from '../../uni_modules/uts-advance'
export default { export default {
...@@ -28,11 +27,9 @@ ...@@ -28,11 +27,9 @@
testAssetLoad(){ testAssetLoad(){
playAssetAudio(); playAssetAudio();
}, },
testResText(){ testLogoLoad(){
let resText = getResText(); this.logo = getLogoPath()
console.log(resText);
} }
} }
} }
</script> </script>
......
<template>
<view>
<view></view>
</view>
<image :src="logo"></image>
</template>
<script lang="ts" setup>
import { getLogoPath } from '../../uni_modules/uts-advance'
const logo = getLogoPath()
</script>
\ No newline at end of file
# uts-advance # uts-advance
\ No newline at end of file
UTS进阶示例插件
\ No newline at end of file
...@@ -10,13 +10,18 @@ import Runnable from 'java.lang.Runnable'; ...@@ -10,13 +10,18 @@ import Runnable from 'java.lang.Runnable';
import Exception from 'java.lang.Exception'; import Exception from 'java.lang.Exception';
import MediaPlayer from 'android.media.MediaPlayer'; import MediaPlayer from 'android.media.MediaPlayer';
/**
* 定时任务参数封装
*/
type TimerOptions = { type TimerOptions = {
start: (res: string) => void; start: (res: string) => void;
work: (res: string) => void; work: (res: string) => void;
}; };
/**
* 执行延时任务
*/
export function doTimerTask(opts:TimerOptions) { export function doTimerTask(opts:TimerOptions) {
opts.start('doTimerTask start'); opts.start('doTimerTask start');
setTimeout(function() { setTimeout(function() {
...@@ -26,7 +31,9 @@ export function doTimerTask(opts:TimerOptions) { ...@@ -26,7 +31,9 @@ export function doTimerTask(opts:TimerOptions) {
return { name: "doTimerTask" }; return { name: "doTimerTask" };
} }
/**
* 执行周期任务
*/
export function doIntervalTask(opts:TimerOptions) { export function doIntervalTask(opts:TimerOptions) {
let taskRet = setInterval(function() { let taskRet = setInterval(function() {
...@@ -37,6 +44,9 @@ export function doIntervalTask(opts:TimerOptions) { ...@@ -37,6 +44,9 @@ export function doIntervalTask(opts:TimerOptions) {
return { name: "doIntervalTask",taskId:taskRet}; return { name: "doIntervalTask",taskId:taskRet};
} }
/**
* 清除周期任务
*/
export function clearIntervalTask(taskId:number) { export function clearIntervalTask(taskId:number) {
clearInterval(taskId); clearInterval(taskId);
...@@ -85,14 +95,12 @@ class RemoveUIRunnable extends Runnable { ...@@ -85,14 +95,12 @@ class RemoveUIRunnable extends Runnable {
export function addViewToDecorView() { export function addViewToDecorView() {
let uiRunable = new AddUIRunnable(); let uiRunable = new AddUIRunnable();
// 获取android环境下 宿主decorview的基本信息
getUniActivity()!.runOnUiThread(uiRunable) getUniActivity()!.runOnUiThread(uiRunable)
} }
export function removeViewToDecorView() { export function removeViewToDecorView() {
var uiRunable = new RemoveUIRunnable(); var uiRunable = new RemoveUIRunnable();
// 获取android环境下 宿主decorview的基本信息
getUniActivity()!.runOnUiThread(uiRunable) getUniActivity()!.runOnUiThread(uiRunable)
} }
...@@ -124,31 +132,32 @@ export function playAssetAudio() { ...@@ -124,31 +132,32 @@ export function playAssetAudio() {
} }
const RTEXT:number = 10020;
export function getResText() :string{
// let text = "aaa " + com.sina.weibo.sdk.R2.string.com_sina_weibo_sdk_logout;
// let resText = getAppContext()!.getString(io.dcloud.uni_modules.uts_advance.R.string.dcloud_common_app_res_download_failed)
return "222";
}
export function initAppLifecycle(onLifecycleChange: (event:string) => void) {
export function initAppLifecycle() {
console.log("initAppLifecycle");
onAppActivityDestroy(() => { onAppActivityDestroy(() => {
console.log("onAppActivityDestroy");
let eventName = "onAppActivityDestroy - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
}); });
onAppActivityPause(() => { onAppActivityPause(() => {
console.log("onAppActivityPause"); let eventName = "onAppActivityPause - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
}); });
onAppActivityResume(() => { onAppActivityResume(() => {
console.log("onAppActivityResume"); let eventName = "onAppActivityResume - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
}); });
onAppActivityBack(() => { onAppActivityBack(() => {
console.log("onAppActivityBack"); let eventName = "onAppActivityBack - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
}); });
} }
......
<resources>
<string name="uts_resource_text">Chinese Text</string>
</resources>
\ No newline at end of file
<resources>
<string name="uts_resource_text">English Text</string>
</resources>
\ No newline at end of file
# uts-helloworld # uts-helloworld
\ No newline at end of file
UTS入门示例插件
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册