|
| 1 | +const Vue = require('./nativescript-vue') |
| 2 | +const application = require('tns-core-modules/application') |
| 3 | +const platform = require('tns-core-modules/platform') |
| 4 | + |
| 5 | +Vue.config.silent = false |
| 6 | +Vue.config.debug = true |
| 7 | + |
| 8 | +new Vue({ |
| 9 | + template: ` |
| 10 | + <Frame> |
| 11 | + <Page> |
| 12 | + <ActionBar title="Android Event Test" /> |
| 13 | + <StackLayout> |
| 14 | + <Label text="Event List:" /> |
| 15 | + <ListView class="m-t-10" for="event in androidEvents"> |
| 16 | + <v-template> |
| 17 | + <Label :text="event.eventName" /> |
| 18 | + </v-template> |
| 19 | + </ListView> |
| 20 | + <StackLayout class="m-t-10" orientation="horizontal"> |
| 21 | + <Label text="Switch for checking responsiveness" /> |
| 22 | + <Switch v-model="switchValue" /> |
| 23 | + </StackLayout> |
| 24 | + </StackLayout> |
| 25 | + </Page> |
| 26 | + </Frame> |
| 27 | + `, |
| 28 | + data: { |
| 29 | + androidEvents: [], |
| 30 | + switchValue: false |
| 31 | + }, |
| 32 | + created() { |
| 33 | + if (platform.isAndroid) { |
| 34 | + const eventTypes = [ |
| 35 | + application.AndroidApplication.activityCreatedEvent, |
| 36 | + application.AndroidApplication.activityDestroyedEvent, |
| 37 | + application.AndroidApplication.activityStartedEvent, |
| 38 | + application.AndroidApplication.activityPausedEvent, |
| 39 | + application.AndroidApplication.activityResumedEvent, |
| 40 | + application.AndroidApplication.activityStoppedEvent, |
| 41 | + application.AndroidApplication.saveActivityStateEvent, |
| 42 | + application.AndroidApplication.activityResultEvent, |
| 43 | + application.AndroidApplication.activityBackPressedEvent |
| 44 | + ] |
| 45 | + for (let i = 0; i < eventTypes.length; i++) { |
| 46 | + application.android.on(eventTypes[i], event => { |
| 47 | + console.log(`Event: ${event.eventName}, Activity: ${event.activity}`) |
| 48 | + this.androidEvents.push(event) |
| 49 | + }) |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +}).$start() |
0 commit comments