Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#IgnoreWarnings: 12
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Dim job1 As HttpJob
Dim List1,List2,List3,List4,List5,List6 As List
End Sub
Sub Globals
Dim ListView1 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
ListView1.Initialize("Listview1")
List1.Initialize
List2.Initialize
List3.Initialize
List4.Initialize
List5.Initialize
List6.Initialize
job1.Initialize("Job1", Me)
ListView1.TwoLinesAndBitmap.Label.TextColor = Colors.ARGB(195,23,133,171)
Activity.AddView(ListView1, 0, 2%y, 100%x, 100%y)
Activity.LoadLayout("main")
job1.Download("http://ibsj.org/app/index.php")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "Job1"
Log("JOB 1")
Dim parser As JSONParser
parser.Initialize(Job.GetString)
Dim root As List = parser.NextArray
For Each colroot As Map In root
Dim date As String = colroot.Get("date")
Dim thumb_url As String = colroot.Get("thumb_url")
Dim video_url As String = colroot.Get("video_url")
Dim author As String = colroot.Get("author")
Dim audio_url As String = colroot.Get("audio_url")
Dim title As String = colroot.Get("title")
List1.Add(date)
List2.add(trim_string2(thumb_url))
Log(trim_string2(thumb_url))
Log(thumb_url)
List3.Add(video_url)
List4.Add(RemoveAccents(author))
List5.Add(audio_url)
List6.Add(trim_string(title))
Log(trim_string(title))
display_data(title,author,thumb_url)
Next
End Select
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
Return
End If
Job.Release
Log("JOB RELEASE")
End Sub
Sub display_data (data1 As String, data2 As String, data3 As String )
ListView1.Invalidate
ListView1.AddTwoLinesAndBitmap( trim_string(data1) , trim_string(data2),LoadBitmapSample(File.DirAssets,"play2.png",15dip,15dip))
End Sub
Sub RemoveAccents(s As String) As String
Dim normalizer As JavaObject
normalizer.InitializeStatic("java.text.Normalizer")
Dim n As String = normalizer.RunMethod("normalize", Array As Object(s, "NFD"))
Dim sb As StringBuilder
sb.Initialize
For i = 0 To n.Length - 1
If Regex.IsMatch("\p{InCombiningDiacriticalMarks}", n.CharAt(i)) = False Then
sb.Append(n.CharAt(i))
End If
Next
Return sb.ToString
End Sub
Sub trim_string (data As String) As String
If data.Length < 30 Then
Return data
Else
Dim result As String = data.SubString2(0,29 -1 )
Return result & " ..."
End If
End Sub
Sub trim_string2 (data As String) As String
Dim result As String
If data = "null" Or data.Length = 0 Or data = "" Or data = "vacio" Then
Else
result = data.SubString2(43,data.Length)
Return result
End If
Return ""
End Sub