Sub Process_Globals
Private xui As XUI
Private aTimer As Timer
End Sub
Sub Globals
Private lblQuestion As Label
Private pnlTouch As Panel
Private xDown As Float ' Initial touch position
Private move As Int = 0 ' Non-zero while moving label
Private number As Int = 1 ' Current question number
Private left As Int ' Used to animate label movement
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
lblQuestion.Text = "Question 1. Swipe right or left"
left = lblQuestion.left
aTimer.Initialize("timer", 10)
aTimer.Enabled = True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Private Sub timer_Tick
If move = 0 Then Return ' Check if label animation in progress
Dim L As Int = lblQuestion.Left + move ' Apply animation movement
lblQuestion.SetLayout(L, lblQuestion.Top, lblQuestion.Width, lblQuestion.Height)
If (lblQuestion.Left > 100%x) Or (lblQuestion.Left < -(lblQuestion.Width)) Then nextQuestion
End Sub
Private Sub nextQuestion
move = 0 ' Turn off animation
number = number + 1 ' Prepare for next question
lblQuestion.left = left
lblQuestion.Text = "This is question number " & number & "."
lblQuestion.SetLayout(left, lblQuestion.Top, lblQuestion.Width, lblQuestion.Height)
End Sub
Private Sub pnlTouch_Touch (Action As Int, X As Float, Y As Float)
If (Action = Activity.ACTION_DOWN) Then xDown = X
If (Action = Activity.ACTION_MOVE) Then
If (Abs(x - xDown) > 20%x) Then ' Check threshold for swipe
' Note : Change value of [move] to change swipe speed
If (x > xDown) Then move = 24 Else move = -24
End If
End If
End Sub