#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private CustomListView1 As CustomListView
Private currentIndex As Int
Private touchPanel As Panel
Private startPointX As Float
Private panelWidth As Float
End Sub
Public Sub Initialize
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
panelWidth = Root.Width / 3
Sleep(10)
Dim touchPanel As Panel
touchPanel.Initialize("touchpnl")
Root.AddView(touchPanel, 0, 0, Root.Width, Root.Height)
For i = 0 To 5
Dim pnl As B4XView = xui.CreatePanel("")
pnl.SetColorAndBorder(xui.Color_White, 2dip, xui.Color_Black, 0)
pnl.SetLayoutAnimated(0, 0, 0, (Root.width - 50) / 3, Root.Height)
Log(Root.Width / 3)
Dim lbl As Label: lbl.Initialize("")
Dim lblx As B4XView = lbl
lblx.SetTextAlignment("CENTER", "CENTER")
lblx.SetColorAndBorder(xui.Color_RGb(220, 220, 255), 1dip, xui.color_black, 0)
If i = 0 Or i = 5 Then
lblx.Text = "Blank"
Else
lblx.Text = "XXXX " & i
End If
pnl.AddView(lblx, 30dip, 30dip, pnl.Width - 60dip, pnl.Height - 60dip)
CustomListView1.Add(pnl, i)
Next
currentIndex = 1
Dim pnl As B4XView = CustomListView1.GetPanel(currentIndex)
Dim lblx As B4XView = pnl.GetView(0)
lblx.SetLayoutAnimated(0, 0, 0, pnl.Width, pnl.height)
End Sub
Sub touchpnl_Touch(Action As Int, X As Float, Y As Float)
Dim saveIndex As Int = currentIndex
Select Action
Case touchPanel.ACTION_DOWN
startPointX = X
Case touchPanel.ACTION_MOVE
Case touchPanel.ACTION_UP
Dim pnl As B4XView = CustomListView1.GetPanel(saveIndex)
Dim lblx As B4XView = pnl.GetView(0)
lblx.SetLayoutAnimated(0, 30dip, 30dip, pnl.Width - 60dip, pnl.Height - 60dip)
If X > startPointX Then
If currentIndex > 1 Then animateToRight Else currentIndex = currentIndex + 1
currentIndex = currentIndex - 1
Else If X < startPointX Then
currentIndex = currentIndex + 1
If currentIndex < CustomListView1.size - 1 Then animateToLeft Else currentIndex = currentIndex - 1
End If
Dim pnl As B4XView = CustomListView1.GetPanel(currentIndex)
Dim lblx As B4XView = pnl.GetView(0)
lblx.SetLayoutAnimated(0, 0, 0, pnl.Width, pnl.height)
End Select
Sleep(10)
End Sub
private Sub animateToLeft
Dim startOffset As Int = CustomListView1.sv.ScrollViewOffsetX
Dim targetOffset As Int = startOffset + panelWidth
Dim stepSize As Float = (targetOffset - startOffset) / 10
Do While startOffset < targetOffset
startOffset = startOffset + stepSize
If startOffset > targetOffset Then Exit
CustomListView1.sv.ScrollViewOffsetX = startOffset
Sleep(10)
stepSize = Max(5, stepSize - 1)
Loop
CustomListView1.sv.ScrollViewOffsetX = targetOffset
End Sub
private Sub animateToRight
Dim startOffset As Int = CustomListView1.sv.ScrollViewOffsetX
Dim targetOffset As Int = startOffset - panelWidth
Dim stepSize As Float = (targetOffset - startOffset) / 10
Do While startOffset > targetOffset
startOffset = startOffset + stepSize
If startOffset < targetOffset Then Exit
CustomListView1.sv.ScrollViewOffsetX = startOffset
Sleep(10)
stepSize = Min(-5, stepSize - 1)
Loop
CustomListView1.sv.ScrollViewOffsetX = targetOffset
End Sub