This shows you the differences between two versions of the page.
built_in:app_events [2018/05/21 18:11] geez437 |
built_in:app_events [2018/12/30 13:31] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== App Events ====== | ||
- | There are a few functions that are triggered when certain system events occur. | ||
- | They are | ||
- | ^ Function | ||
- | | OnStart() | ||
- | | OnMenu( name ) | user selects a menu item | | ||
- | | OnBack() | ||
- | | OnPause() | ||
- | | OnResume() | ||
- | | OnConfig() | ||
- | | OnAlarm() | ||
- | | OnData() | ||
- | |||
- | The code of the sample that is bundled with DroidScript is reproduced below without permission. Hope you don't mind, guys. | ||
- | <code javascript appEvents.js> | ||
- | //Called when application is created. | ||
- | function OnStart() | ||
- | { | ||
- | app.ShowPopup( " | ||
- | app.SetMenu( " | ||
- | app.EnableBackKey( false ); | ||
- | |||
- | | ||
- | | ||
- | | ||
- | | ||
- | |||
- | //Called when user selects a menu item. | ||
- | function OnMenu( name ) | ||
- | { | ||
- | app.ShowPopup( " | ||
- | } | ||
- | |||
- | //Called when the back key is pressed. | ||
- | function OnBack() | ||
- | { | ||
- | alert( " | ||
- | app.Exit(); | ||
- | } | ||
- | |||
- | //Called when application is paused. | ||
- | //(eg. When user switches to home screen) | ||
- | function OnPause() | ||
- | { | ||
- | app.ShowPopup( " | ||
- | } | ||
- | |||
- | //Called when application is resumed. | ||
- | //(eg. When user returns from home screen) | ||
- | function OnResume() | ||
- | { | ||
- | app.ShowPopup( " | ||
- | } | ||
- | |||
- | //Called when configuration changes. | ||
- | //(eg. When user rotates phone) | ||
- | function OnConfig() | ||
- | { | ||
- | app.ShowPopup( " | ||
- | } | ||
- | |||
- | // | ||
- | // | ||
- | function OnAlarm( id ) | ||
- | { | ||
- | app.ShowPopup( " | ||
- | } | ||
- | |||
- | //Handle data sent from other apps. | ||
- | function OnData( isStartUp ) | ||
- | { | ||
- | | ||
- | var intent = app.GetIntent(); | ||
- | if( intent ) | ||
- | { | ||
- | //Extract main data. | ||
- | var s = " | ||
- | s += "type: " + intent.type + " | ||
- | s += "data: " + intent.data + " | ||
- | | ||
- | //Extract extras. | ||
- | s += " | ||
- | for( var key in intent.extras ) | ||
- | s += key+": " | ||
- | | ||
- | app.Alert( s, " | ||
- | } | ||
- | } | ||
- | |||
- | </ | ||
- | |||
- | ====OnConfig==== | ||
- | <code javascript> | ||
- | //Called when application is started. | ||
- | function OnStart() | ||
- | { | ||
- | //Create a layout with objects vertically centered. | ||
- | lay = app.CreateLayout( " | ||
- | var test = app.GetOrientation(); | ||
- | var hv = " | ||
- | if( test==" | ||
- | lay.SetOrientation( hv ); | ||
- | |||
- | txt = app.CreateText( "Hello " ); | ||
- | txt.SetTextSize( 64); | ||
- | lay.AddChild( txt ); | ||
- | |||
- | txt1 = app.CreateText( " | ||
- | txt1.SetTextSize( 64 ); | ||
- | lay.AddChild( txt1 ); | ||
- | app.AddLayout( lay ); | ||
- | } | ||
- | //Called when screen rotates | ||
- | function OnConfig() | ||
- | { | ||
- | var test = app.GetOrientation(); | ||
- | var hv = " | ||
- | if( test==" | ||
- | lay.SetOrientation( hv ); | ||
- | } | ||
- | </ |