Sub Globals
Dim re As Reflector
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
re.Target = Activity
re.SetOnKeyListener("ActivityOnKey")
re.RunMethod2("setFocusable", "True", "java.lang.boolean")
re.RunMethod2("setFocusableInTouchMode", "True", "java.lang.boolean")
Activity.RequestFocus
End Sub
Private Sub ActivityOnKey(vTag As Object, keyCode As Int, KeyEvent As Object) As Boolean
Log("Key detected")
re.Target = KeyEvent
Dim Action As Int = re.RunMethod("getAction")
Log(Action)
Select Action
Case Activity.ACTION_UP
Select keyCode
Case KeyCodes.KEYCODE_MEDIA_PREVIOUS
'click a button in the app
Return(True) 'to cancel the event
'longer press
Case KeyCodes.KEYCODE_MEDIA_PLAY_PAUSE
'click another button in the app
Return(True) 'to cancel the event
Case KeyCodes.KEYCODE_MEDIA_NEXT
'click another button in the app
Return(True) 'to cancel the event
Case KeyCodes.KEYCODE_VOLUME_UP
'click some other button
Return True
Case KeyCodes.KEYCODE_VOLUME_DOWN
Log("Volume Down Physical Button (Action = Up)")
'click some other button
Return(True) 'to cancel the event
End Select 'for case action up keycodes
End Select 'for all actions
End Sub