Sub scrol1_refresh_data(position As Int)
Dim percentofcache As Float
percentofcache=(Cache.FreeMemory/maxcache)*100
percentofcache=NumberFormat(percentofcache,0,0)
lbl1total.Text=percentofcache'Cache.FreeMemory&" / "&Cache.MaxMemory
Dim scrol_size,panel_height As Int
scrol_size=scrol1.GetSize 'number of views
'read the height of the panel
Dim pnl As Panel
pnl=scrol1.GetPanel(0)
panel_height=pnl.Height
Dim start,stop As Int
start = Round2(position/panel_height,0)
start=Max(0,start)'set the limits for panel 0 and max panel index
stop= Round2(scrol1.AsView.Height/panel_height,0)+start
stop=Min(stop,scrol1.GetSize-1) 'set the limits for panel 0 and max panel index
For i=start To stop Step 1
Dim pnlx As Panel
pnlx=scrol1.GetPanel(i)
' The memory Cache Is looked first
Dim bmp As Bitmap
bmp = Cache.GetBitmap(i, True)
If bmp.IsInitialized Then
refresh_image(bmp ,pnlx,"CACHE")
Else ' get image from parse file
Dim pfx As ParseFile
pfx=picmap.Get(pnlx.Tag)' picmap the map previously stored from parse query
pfx.Get("pf",i)
'pending refresh image
End If
Next
End Sub
Sub pf_DoneGet (Success As Boolean, Data() As Byte, TaskID As Int)
Dim pf As ParseFile
pf = Sender
Dim In As InputStream
In.InitializeFromBytesArray(Data, 0, Data.Length)
Dim bmp As Bitmap
bmp.Initialize2(In)
In.Close
Dim pnlx As Panel
pnlx=scrol1.GetPanel(TaskID)
'scales the bitmap
Dim sd As Rect
sd.Initialize(0,0,100dip,100dip)
Dim bmpx As BitmapPlus
bmp=bmpx.createScaledBitmap(bmp,100dip,100dip,False)
'put the image to cache
Cache.PutBitmapInMemory(TaskID, bmp)
Cache.PutBitmapOnDisk_Async(TaskID, bmp, "PNG", 90, "Cache")
refresh_image(bmp,pnlx,"PARSE")
End Sub
Sub refresh_image(bmp As Bitmap,pnlx As Panel,NAME As String)
Log(NAME)'the picture was loaded from cache or parse server
Dim img As ImageView
img=pnlx.GetView(0)
img.Gravity=Gravity.FILL
img.SetBackgroundImage(bmp)
End Sub
Sub Cache_PutDone(Key As String, Error As Boolean)
' This "PutDone" event is triggered after the bitmap has been put in the disk cache
If Error Then
Log("Error (" & Key & "): " & LastException.Message)
ToastMessageShow("Error (" & Key & "): " & LastException.Message, True)
Else
Log("Bitmap put in cache: " & Key)
End If
End Sub