Sub JobDone(Job As HttpJob)
ongoingTasks.Remove(Job.JobName)
If Job.Success Then
Dim bmp As Bitmap = Job.GetBitmap
If tasks.IsInitialized Then
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)
Dim b2 As Bitmap
b2.InitializeMutable(iv.Width,iv.Height)
Dim c As Canvas
c.Initialize2(b2)
Dim r1 As Rect
r1.Initialize(0,0,bmp.Width,bmp.Height)
Dim xdif As Float = iv.Width / bmp.Width
Dim ydif As Float = iv.Height / bmp.Height
Dim NewX As Float = bmp.Width * xdif
Dim NewY As Float = bmp.Height * ydif
Dim NewZ As Float = (iv.Width + iv.Height) / (bmp.Width + bmp.Height)
Dim r2X As Float
Dim r2Y As Float
If NewX > NewY Then
'Log("X")
r2X = bmp.Width * ydif
r2Y = NewY
Else
'Log("Y")
r2X = NewX
r2Y = bmp.Height * xdif
End If
If r2X > iv.Width Then
Dim NewRatio As Float = (iv.Width / r2X)
r2X = r2X * NewRatio
r2Y = r2Y * NewRatio
End If
Dim NewLeft As Float = ((iv.Width - b2.Width) / 2)
Dim NewTop As Float = ((iv.Height - b2.Height) / 2)
Dim r2 As Rect
r2.Initialize(NewLeft,NewTop,r2X,r2Y)
c.DrawColor(Colors.White)
c.DrawBitmap(bmp,r1,r2)
c = Null
cache.Put(Job.JobName, b2)
iv.SetBackgroundImage(b2)
End If
Next
End If
Else
cache.Put(Job.JobName, NotFoundBmp)
If tasks.IsInitialized Then
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)
iv.SetBackgroundImage(NotFoundBmp)
End If
Next
End If
'Log("Error downloading image: " & Job.JobName & CRLF & Job.ErrorMessage)
End If
Job.Release
End Sub