提交 bdc81394 编写于 作者: M mahaifeng

[activity-callback]修改示例位置

上级 a0145619
......@@ -41,19 +41,6 @@
</view>
<button @tap="getDeviceInfoClick">获取设备基础信息</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>
</scroll-view>
<!-- #endif -->
......@@ -102,16 +89,10 @@
data() {
return {
text: '',
cbText: '',
selectImage: '',
callback: [] as Any[]
}
},
unmounted() {
// #ifdef APP-ANDROID
this.unRegActivityCallback()
// #endif
},
onLoad: function () {
// #ifdef APP-ANDROID
......@@ -321,67 +302,6 @@
})
},
// #endif
// #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
})
let index = getCurrentPages().length - 1
let page = getCurrentPages()[index]
console.log('page route=' + page.route)
this.callback.push(new UTSAcvitiyLifeCycleCallback())
this.callback.push(new UTSActivityWindowCallback())
this.callback.push(new UTSAcvitiyKeyEventCallback())
this.callback.push(new UTSActivityCallback(), page.route)
this.callback.push(new UTSActivityComponentCallback())
this.callback.forEach((value) => {
if (value instanceof UTSAcvitiyLifeCycleCallback) {
UTSAndroid.onActivityCallback(value,page.route)
}
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() {
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>
......
......@@ -20,7 +20,20 @@
<script lang="ts">
import { gotoDemoActivity,sayHelloFromJar } from "@/uni_modules/uts-nativepage";
import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo";
// #ifdef APP-ANDROID
import {
UTSAcvitiyLifeCycleCallback,
UTSAcvitiyKeyEventCallback,
UTSActivityWindowCallback,
UTSActivityCallback,
UTSActivityComponentCallback,
onCallbackChange
} from '@/uni_modules/uts-syntaxcase'
import File from 'java.io.File';
import Intent from 'android.content.Intent';
// #endif
type Page = {
name : string,
url ?: string
......@@ -31,7 +44,12 @@
open : boolean,
pages : Page[],
}
export default {
export default {
unmounted() {
// #ifdef APP-ANDROID
this.unRegActivityCallback()
// #endif
},
data() {
return {
title: '系统API示例',
......@@ -42,7 +60,15 @@
pages: [{
name: "获取电池电量",
function: "testGetBatteryCapacity"
}] as Page[]
}
// #ifdef APP-ANDROID
,
{
name: "注册activity 回调方法",
function: "testActivityCallback"
},
// #endif
] as Page[]
},
{
name: "系统事件",
......@@ -74,7 +100,9 @@
] as ListItem[],
arrowUpIcon: '/static/icons/arrow-up.png',
arrowDownIcon: '/static/icons/arrow-down.png',
arrowRightIcon: '/static/icons/arrow-right.png',
arrowRightIcon: '/static/icons/arrow-right.png',
callback: [] as Any[],
cbText: '',
}
},
methods: {
......@@ -94,6 +122,9 @@
case 'testGetBatteryCapacity':
this.testGetBatteryCapacity()
break
case 'testActivityCallback':
this.testActivityCallback()
break
case 'testGotoDemoActivity':
this.testGotoDemoActivity()
case 'testNativeJar':
......@@ -107,7 +138,7 @@
})
},
testGetBatteryCapacity() {
testGetBatteryCapacity() {
getBatteryInfo({
success(res) {
uni.showToast({
......@@ -117,6 +148,78 @@
}
} as GetBatteryInfoOptions)
},
// #ifdef APP-ANDROID
testActivityCallback(){
this.activityCallback()
},
activityCallback() {
uni.showToast({
title: "注册成功,请尝试切换到其他app,在切换回来",
icon: 'none'
});
var that = this
onCallbackChange(function (eventLog : string) {
// 展示捕捉到的声明周期日志
let nextLine = that.cbText + eventLog
that.cbText = nextLine
let nextLineFlag = that.cbText + '\n'
that.cbText = nextLineFlag
console.log(that.cbText)
uni.showToast({
title: "activity 回调方法:" +eventLog,
icon: 'none'
});
})
let index = getCurrentPages().length - 1
let page = getCurrentPages()[index]
this.callback.push(new UTSAcvitiyLifeCycleCallback())
this.callback.push(new UTSActivityWindowCallback())
this.callback.push(new UTSAcvitiyKeyEventCallback())
this.callback.push(new UTSActivityCallback(), page.route)
this.callback.push(new UTSActivityComponentCallback())
this.callback.forEach((value) => {
if (value instanceof UTSAcvitiyLifeCycleCallback) {
UTSAndroid.onActivityCallback(value,'tabBar')
}
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() {
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
testNativeJar() {
let ret = sayHelloFromJar();
uni.showToast({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册