#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Private cache As Map
Private tasks As Map
Private ongoingTasks As Map
Public bitProgress,bitRounded As Boolean
Dim rsie As RSImageEffects
Dim iu As AS_ImageUtils
Public intForm As Int
Private const ADD_PROGRESSBAR As Boolean = True
Dim p As MaterialCircleProgress
End Sub
Sub Service_Create
tasks.Initialize
cache.Initialize
ongoingTasks.Initialize
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_Destroy
End Sub
Sub Download (ImageViewsMap As Map)
For Each iv As ImageView In ImageViewsMap.Keys ' For i = 0 To ImageViewsMap.Size - 1
'tasks.Put(ImageViewsMap.GetKeyAt(i), ImageViewsMap.GetValueAt(i))
'Dim link As String = ImageViewsMap.GetValueAt(i)
Dim link As String = ImageViewsMap.Get(iv)
Dim o As Object = iv
tasks.Put(o, link)
If cache.ContainsKey(link) Then
'Dim iv As ImageView = ImageViewsMap.GetKeyAt(i)
iv.SetBackgroundImage( iu.CreateScaledBitmap( iu.ReduceColors( cache.Get(link) ) ,iv.Width,iv.Height,True) )
Else If ongoingTasks.ContainsKey(link) = False Then
ongoingTasks.Put(link, "")
Dim j As HTTPJob2
j.Initialize(link, Me)
j.Download(link)
If ADD_PROGRESSBAR Then
p.Initialize("")
p.Colors = Array As Int(Colors.Red,Colors.Blue,Colors.Green,Colors.Yellow)
p.ProgressStrokeWidth = 5dip
p.ShowArrow = False
p.TextColor = Colors.LightGray
p.CircleBackgroundEnabled = False
Dim jo As JavaObject = iv
Dim parent As Panel = jo.RunMethod("getParent", Null)
iv.Tag = p
parent.AddView(p, iv.Left, iv.Top, iv.Width, iv.Height)
End If
End If
Next
End Sub
Sub JobDone(job As HTTPJob)
ongoingTasks.Remove(job.JobName)
If job.Success Then
Try
If tasks.IsInitialized Then
Starter.bmp1 = iu.ReduceColors(job.GetBitmap)
cache.Put(job.JobName, Starter.bmp1)
For i = 0 To tasks.Size - 1
Dim link As String = tasks.GetValueAt(i)
If link = job.JobName Then
Dim iv As ImageView = tasks.GetKeyAt(i)
If bitRounded Then
Starter.bmp2 = iu.CreateScaledBitmap( Starter.bmp1 ,iv.width, iv.height,True)
iv.Bitmap = rsie.RoundCorner(Starter.bmp2, 10)
Else
iv.SetBackgroundImage(iu.CreateScaledBitmap(Starter.bmp1, iv.Width,iv.height, True) )
End If
If ADD_PROGRESSBAR And iv.Tag Is MaterialCircleProgress Then
Dim p As MaterialCircleProgress = iv.Tag
p.Visible = False
p.RemoveView
End If
End If
Next
End If
' Starter.bmp1 = Null
Catch
bitProgress = False
job.Release
End Try
Else
cache.Clear
tasks.Clear
End If
job.Release
If ongoingTasks.Size = 0 Then
tasks.Clear
cache.Clear
bitRounded = False
StopService("imagedownloader")
End If
bitProgress = False
End Sub
Sub ActivityIsPaused
tasks.Clear
End Sub
public Sub ClearCache
cache.Clear
bitRounded = False
End Sub