Region Project Attributes
#ApplicationLabel: Card List
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#BridgeLogger: True
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
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.
Private CLV1 As CustomListView
Private ImagePoster As B4XView
Private LabelDays As B4XView
Private LabelGame As B4XView
Private LabelStructure As B4XView
Private LabelDistance As B4XView
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Main")
CallJson
End Sub
Sub CallJson
Dim GetJson As HttpJob
Dim Url As String
Url = "http:/xxxx.com/data.json"
GetJson.Initialize("GetJson", Me)
GetJson.Download2(Url, Array As String("param1", 1))
End Sub
Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
Log("JobTag = " & Job.Tag)
If Job.Success == True Then
Select Job.JobName
Case "GetJson"
Log(Job.GetString)
ShowJson(Job.GetString)
End Select
End If
Job.Release
End Sub
Sub ShowJson(JsonString As String) As Boolean
Dim JsonString As String
Dim Json As JSONParser
Dim GlobalMap As Map
Dim ResultMap As Map
Dim ValuesItems As List
Dim ValueMap As Map
Dim Row1 As String
Dim Row2 As String
Dim Row3 As String
Dim Row4 As String
Dim ImageFile As String
Dim ImageDownload As HttpJob
Log (JsonString)
Json.Initialize(JsonString)
GlobalMap = Json.NextObject
ResultMap = GlobalMap.Get("Result")
Log("code=" & ResultMap.Get("code"))
Log("details=" & ResultMap.Get("details"))
ValuesItems = GlobalMap.Get("data")
For i = 0 To ValuesItems.Size - 1
ValueMap = ValuesItems.Get(i)
Row1 = ValueMap.Get("row1")
Row2 = ValueMap.Get("row2")
Row3 = ValueMap.Get("row3")
Row4 = ValueMap.Get("row4")
ImageDownload.Initialize("", Me)
ImageDownload.Download("http://image.jpg")
Wait For (ImageDownload) JobDone(ImageDownload As HttpJob)
ImageDownload.Release
CLV1.Add(CreateCard(CLV1.AsView.Width, ImageFile, Row1, Row2, Row3, Row4), "")
Next
Return True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Private Sub CreateCard(Width As Int, Image As String, Row1 As String, Row2 As String, Row3 As String, Row4 As String) As Panel
Dim p As B4XView = xui.CreatePanel("")
' SetAlpha(p, 0.3)
Dim height As Int = 105dip
If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then
Log ("< 4.5")
height = 310dip
End If
Log("Height=" & height)
'height = 200dip
p.SetLayoutAnimated(0, 0, 0, Width, height)
p.LoadLayout("Card")
LabelDays.Text = Row1
LabelGame.Text = Row2
LabelStructure.Text = Row3
LabelDistance.Text = Row4
ImagePoster.SetBitmap(xui.LoadBitmapResize(File.DirAssets, Image, ImagePoster.Width - 5dip, ImagePoster.Height-5dip, True))
Return p
End Sub