'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ScrollView1 As ScrollView
Dim Label1 As Label
Dim Panel1 As Panel
Dim tm As Timer
Dim curX, curY As Int
Dim flMove As Boolean
Dim whichLabel As Int
Dim tenLabels(10) As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
ScrollView1.Initialize (Activity.Height)
Dim tempPanel As Panel
tempPanel=ScrollView1.Panel
For i=0 To 9
tenLabels(i)="item " & (i+1)
Next
setLabels
Panel1.Initialize ("Panel1")
Panel1.Visible =False
Panel1.Color =Colors.Blue
Activity.AddView (ScrollView1,0,0,Activity.Width,Activity.Height )
Activity.AddView (Panel1,0,0,Activity.Width,50dip)
Label1.Initialize ("")
Panel1.AddView (Label1,0,0,Panel1.Width,Panel1.Height )
flMove=False
tm.Initialize ("myTimer",200)
tm.Enabled =True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub label_click
Panel1.Visible =False
Dim tempLabel As Label
tempLabel=Sender
whichLabel=tempLabel.Tag
Label1.Text=tempLabel.Text
Panel1.Left=tempLabel.Left
Panel1.Top =tempLabel.Top
Panel1.Visible =True
Panel1.BringToFront
Panel1.RequestFocus
End Sub
Sub Panel1_Touch (Action As Int, x As Float, Y As Float) As Boolean 'Return True to consume the event
flmove=True
curX=x:curY=Y
Select Action
Case Activity.ACTION_DOWN
flMove=True
curX=x:curY=Y
Case Activity.ACTION_MOVE
flMove=True
curX=x:curY=Y
Case Activity.ACTION_UP
flMove=False
Dim absX As Int, absY As Int
absX=x+Panel1.Left +Panel1.Width /2
absY=Y+Panel1.Top +Panel1.Height /2
Dim whichPos As Int
whichPos=absY/(ScrollView1.Height/10)
If whichPos>9 Then whichPos=9
If whichPos<0 Then whichPos=0
If whichPos<>whichLabel Then
'exchange Labels
Dim templ,templ2 As String
templ=tenLabels(whichPos)
templ2=tenLabels(whichLabel)
tenLabels(whichPos)=templ2
tenLabels(whichLabel)=templ
For k=0 To ScrollView1.Panel.NumberOfViews -1
ScrollView1.Panel.RemoveViewAt (0)
Next
setLabels
Msgbox("Exchanged " & templ & " with " & templ2,"Drag & Drop finished")
End If
Panel1.Visible =False
End Select
Return True
End Sub
Sub myTimer_tick
If flMove=True Then
'Panel1.Left =curX+Panel1.Left-Panel1.Width/2
Panel1.Top =curY+Panel1.Top -Panel1.Height/2
End If
End Sub
Sub setLabels
Dim tempPanel As Panel
tempPanel=ScrollView1.Panel
For i=0 To 9
Dim tempLabel As Label
tempLabel.Initialize ("label")
tempLabel.Tag =i
tempLabel.Text=tenLabels(i)
tempPanel.AddView (tempLabel,0,i*50dip,tempPanel.Width,tempPanel.Height /10)
Next
End Sub