提交 368b85f3 编写于 作者: M mahaifeng

[activity-callback]修改示例位置

上级 a96be066
...@@ -41,19 +41,6 @@ ...@@ -41,19 +41,6 @@
</view> </view>
<button @tap="getDeviceInfoClick">获取设备基础信息</button> <button @tap="getDeviceInfoClick">获取设备基础信息</button>
<button @tap="getFileProviderUriClick">使用外部应用访问私有文件</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> </view>
</scroll-view> </scroll-view>
<!-- #endif --> <!-- #endif -->
...@@ -102,16 +89,10 @@ ...@@ -102,16 +89,10 @@
data() { data() {
return { return {
text: '', text: '',
cbText: '',
selectImage: '', selectImage: '',
callback: [] as Any[]
} }
}, },
unmounted() { unmounted() {
// #ifdef APP-ANDROID
this.unRegActivityCallback()
// #endif
}, },
onLoad: function () { onLoad: function () {
// #ifdef APP-ANDROID // #ifdef APP-ANDROID
...@@ -321,67 +302,6 @@ ...@@ -321,67 +302,6 @@
}) })
}, },
// #endif // #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> </script>
......
...@@ -20,7 +20,20 @@ ...@@ -20,7 +20,20 @@
<script lang="ts"> <script lang="ts">
import { gotoDemoActivity,sayHelloFromJar } from "@/uni_modules/uts-nativepage"; import { gotoDemoActivity,sayHelloFromJar } from "@/uni_modules/uts-nativepage";
import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo"; 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 = { type Page = {
name : string, name : string,
url ?: string url ?: string
...@@ -31,7 +44,12 @@ ...@@ -31,7 +44,12 @@
open : boolean, open : boolean,
pages : Page[], pages : Page[],
} }
export default { export default {
unmounted() {
// #ifdef APP-ANDROID
this.unRegActivityCallback()
// #endif
},
data() { data() {
return { return {
title: '系统API示例', title: '系统API示例',
...@@ -42,7 +60,15 @@ ...@@ -42,7 +60,15 @@
pages: [{ pages: [{
name: "获取电池电量", name: "获取电池电量",
function: "testGetBatteryCapacity" function: "testGetBatteryCapacity"
}] as Page[] }
// #ifdef APP-ANDROID
,
{
name: "注册activity 回调方法",
function: "testActivityCallback"
},
// #endif
] as Page[]
}, },
{ {
name: "系统事件", name: "系统事件",
...@@ -74,7 +100,9 @@ ...@@ -74,7 +100,9 @@
] as ListItem[], ] as ListItem[],
arrowUpIcon: '/static/icons/arrow-up.png', arrowUpIcon: '/static/icons/arrow-up.png',
arrowDownIcon: '/static/icons/arrow-down.png', arrowDownIcon: '/static/icons/arrow-down.png',
arrowRightIcon: '/static/icons/arrow-right.png', arrowRightIcon: '/static/icons/arrow-right.png',
callback: [] as Any[],
cbText: '',
} }
}, },
methods: { methods: {
...@@ -94,6 +122,9 @@ ...@@ -94,6 +122,9 @@
case 'testGetBatteryCapacity': case 'testGetBatteryCapacity':
this.testGetBatteryCapacity() this.testGetBatteryCapacity()
break break
case 'testActivityCallback':
this.testActivityCallback()
break
case 'testGotoDemoActivity': case 'testGotoDemoActivity':
this.testGotoDemoActivity() this.testGotoDemoActivity()
case 'testNativeJar': case 'testNativeJar':
...@@ -107,7 +138,7 @@ ...@@ -107,7 +138,7 @@
}) })
}, },
testGetBatteryCapacity() { testGetBatteryCapacity() {
getBatteryInfo({ getBatteryInfo({
success(res) { success(res) {
uni.showToast({ uni.showToast({
...@@ -117,6 +148,78 @@ ...@@ -117,6 +148,78 @@
} }
} as GetBatteryInfoOptions) } 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() { testNativeJar() {
let ret = sayHelloFromJar(); let ret = sayHelloFromJar();
uni.showToast({ uni.showToast({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册