B4i Library ImageloaderV2

support:
1.loading image from web(into imageview);
2.download image from web with callback event;
3.cache(or not) with files;
4.customize cache time setting;

dependson:iHttp iStringUtils

usage:
B4X:
'init
Public imgldr As ImageDownloader
imgldr.Initialize

'support assets
Sub loadimg (imgurl As String,v As ImageView)
    '    L("loadimg:"&imgurl)
    If imgurl.Length<1 Then imgurl="assets://test_header.jpg"
    If imgurl.StartsWith("assets://") Then
        imgurl=imgurl.Replace("assets://","")
        v.Bitmap=LoadBitmap(File.DirAssets,imgurl)
    else if imgurl.StartsWith("file://") Then
        imgurl=imgurl.Replace("file://","")
        v.Bitmap=LoadBitmap("",imgurl)
    Else
        imgldr.addJob(v,imgurl)
    End If
   
End Sub

public Sub downimg (imgurl As String,cb_ As Object,cbe_ As String)
    Log("downimg:"&imgurl)
    imgldr.downImg(imgurl,cb_,cbe_)
End Sub
Sub loadimg_nocache (imgurl As String,v As ImageView)
    If imgurl.StartsWith("assets://") Then
        imgurl=imgurl.Replace("assets://","")
        v.Bitmap=LoadBitmap(File.DirAssets,imgurl)
    Else
        imgldr.addJob2(v,imgurl,False)
    End If
End Sub

Sub loadimg_nocache (imgurl As String,v As ImageView)
    If imgurl.StartsWith("assets://") Then
        imgurl=imgurl.Replace("assets://","")
        v.Bitmap=LoadBitmap(File.DirAssets,imgurl)
    Else
        imgldr.addJob2(v,imgurl,False)
    End If
End Sub
 

Attachments

  • ImageDownloader.bas
    4.5 KB · Views: 31
Top