Hello everybody,
I'm using httputils to grab about 180 Bitmaps from web sites.
this is my code snippet:
It works fine. But: Sometimes, I'm getting the error message for this line:
imgWidth = s.width * 2
Error says, that Bitmap should first be initialized.
Question is: Why?
Most of the time, the code works without any errors. The error just occurs sometimes. It's always the same set of Bitmaps and URLs that should be downloaded.
Any ideas?
Second question:
After the Bitmaps are downloaded - where are they stored? Is it possible to access them and their origin URLs without re-download them again?
I know, that I can access them with HttpUtils.GetBitmap. But how long does that work? After closing the App and restarting it, it seems that this doesn't work. I'm getting the error message, that Map object should first be initialized in line
Sub IsSuccess(URL As String) As Boolean
Return SuccessfulUrls.ContainsKey(URL)
End Sub
of httputils.
Am I missing something? Or is there another way to access the already downloaded bitmap material?
Thanks,
Carsten
I'm using httputils to grab about 180 Bitmaps from web sites.
this is my code snippet:
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.Title = "Copy your Smiley"
Activity.LoadLayout("mainlayout")
IconList.Initialize
IconList = File.ReadList(File.DirAssets,"smileys.txt")
Activity.AddMenuItem("Toggle Notification","mnuNoti")
Activity.AddMenuItem("About","mnuAbout")
Activity.AddMenuItem("Download","mnuDownload")
Website.initialize("")
Activity.AddView(Website,0,0,100%x,100%y)
Website.Visible = False
merker = 0
merker2 = 0
y = 10
x = 10
c = 0
lv = GetDeviceLayoutValues
hoehe = lv.Height
breite = lv.Width
scvImages.SetLayout(0,0,100%x,100%y)
n.Vibrate = False
rueckkehr = "close"
HttpUtils.CallbackActivity = "Main" 'Current activity name.
HttpUtils.CallbackJobDoneSub = "JobDone"
If firsttime = True Then
counter.Visible = True
counter.Height = hoehe
counter.width = breite
counter.top = 1
counter.Text = "Downloading..."
HttpUtils.DownloadList("Job1", IconList)
Else
Listfill
End If
End Sub
Sub Activity_Resume
'Check whether a job has finished while the activity was paused.
If HttpUtils.Complete = True Then JobDone(HttpUtils.Job)
End Sub
Sub UrlDone(Url As String)
Log(Url & " done")
End Sub
Sub JobDone (Job As String)
For i = 0 To HttpUtils.Tasks.Size - 1
counter.Text = i
s = HttpUtils.GetBitmap(IconList.get(i))
imgWidth = s.width * 2
imgheight = s.height * 2
merker = imgwidth / imgheight
imgheight = 75
If merker > 1 Then
imgwidth = 90 * merker
Else
imgwidth = 90
End If
If x > breite - imgwidth Then
x = 10
y = y + 90
End If
Dim imvImage As ImageView
imvImage.Initialize("imvImage")
imvImage.Gravity=Gravity.FILL
imvImage.Tag=IconList.Get(i)
imvImage.Bitmap=s
scvImages.Panel.AddView(imvImage,x,y,imgWidth,imgHeight)
x = x + imgwidth + 30
Next
scvImages.Panel.Height = y + 200
counter.Visible = False
HttpUtils.Complete = False 'Turn off the complete flag so we won't handle it again if the activity is resumed.
End Sub
It works fine. But: Sometimes, I'm getting the error message for this line:
imgWidth = s.width * 2
Error says, that Bitmap should first be initialized.
Question is: Why?
Most of the time, the code works without any errors. The error just occurs sometimes. It's always the same set of Bitmaps and URLs that should be downloaded.
Any ideas?
Second question:
After the Bitmaps are downloaded - where are they stored? Is it possible to access them and their origin URLs without re-download them again?
I know, that I can access them with HttpUtils.GetBitmap. But how long does that work? After closing the App and restarting it, it seems that this doesn't work. I'm getting the error message, that Map object should first be initialized in line
Sub IsSuccess(URL As String) As Boolean
Return SuccessfulUrls.ContainsKey(URL)
End Sub
of httputils.
Am I missing something? Or is there another way to access the already downloaded bitmap material?
Thanks,
Carsten