Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Main")
Dim job1, job2, job3 As HttpJob
job1.Initialize("Job1",Me)
Dim m As Map
m.Initialize
m.Put("filename","Visa.jpg")
m.Put("imageview",ImageView1)
job1.Tag = m
job1.Download("http://amucu.org/wp-content/themes/amucu/images/universal/Visa.jpg")
job2.Initialize("Job2",Me)
Dim m As Map
m.Initialize
m.Put("filename","Mastercard.png")
m.Put("imageview",ImageView2)
job2.Tag = m
job2.Download("http://amucu.org/wp-content/themes/amucu/images/universal/Mastercard.png")
job3.Initialize("Job3",Me)
Dim m As Map
m.Initialize
m.Put("filename","Discover.jpg")
m.Put("imageview",ImageView3)
job3.Tag = m
job3.Download("http://amucu.org/wp-content/themes/amucu/images/universal/Discover.jpg")
'You'll get an error when these lines of code are run, because the files don't exist. They are downloaded,
'But I can't get the Sub JobDone to correctly name them and move them to the DirInternal folder.
'
Dim bitmapholder As Bitmap
If File.Exists(File.DirInternal,"Visa.jpg") Then
bitmapholder.Initialize(File.DirInternal, "Visa.jpg")
Else
bitmapholder.Initialize(File.DirAssets, "placeHolder.jpg")
End If
ImageView1.Bitmap = bitmapholder
Dim bitmapholder2 As Bitmap
If File.Exists(File.DirInternal,"Mastercard.png") Then
bitmapholder2.Initialize(File.DirInternal, "Mastercard.png")
Else
bitmapholder2.Initialize(File.DirAssets, "placeHolder.jpg")
End If
ImageView2.Bitmap = bitmapholder2
Dim bitmapholder3 As Bitmap
If File.Exists(File.DirInternal,"Discover.jpg") Then
bitmapholder3.Initialize(File.DirInternal, "Discover.jpg")
Else
bitmapholder3.Initialize(File.DirAssets, "placeHolder.jpg")
End If
ImageView3.Bitmap = bitmapholder3
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub JobDone(job As HttpJob)
If job.Success Then
'This is the part I am really struggling with. The examples in the tutorials all look like this:
'Dim out As OutputStream = File.OpenOutput(File.DirInternal,"downloaded.txt", False)
'But that is assigning a specific file name ("downloaded.txt") to the file, meaning all three files
'that I am importing will get that name.
'
'I want the file name to remain what it was on the original file that was downloaded from the web.
'(in this example, it would be Visa.jpg, Mastercard.png, and Discover.jpg)
'
'I've tried changing "downloaded.txt" to be job.JobName, job.GetString, and a half-dozen other things,
'but none of those options work.
'
Dim o As Object = job.Tag
If o Is Map Then
Dim m As Map = o
Dim out As OutputStream = File.OpenOutput(File.DirInternal,m.Get("filename"), False) ' Use he TAG to write the file to disc with the right name. See declaration
File.Copy2(job.GetInputStream, out)
out.Close
Dim bitmapholder As Bitmap
If File.Exists(File.DirInternal,m.Get("filename")) Then
bitmapholder.Initialize(File.DirInternal, m.Get("filename"))
Dim img As ImageView = m.Get("imageview")
img.Bitmap = bitmapholder
End If
End If
End If
Dim l As List = File.ListFiles(File.DirInternal)
Log(l)
job.Release
End Sub