I am trying to display an image i have downloaded via qr bar code scan
I am using the httputils2 flickr example as my template. my goal is to download and display 1 image file rather than 9. when I run the program it gets all the way to the toast message that display fetching download but then it appears that the application times out. and no image is displayed. what am i doing wrong ?I think my problem might be in the regex portions of the code.
I am using the httputils2 flickr example as my template. my goal is to download and display 1 image file rather than 9. when I run the program it gets all the way to the toast message that display fetching download but then it appears that the application times out. and no image is displayed. what am i doing wrong ?I think my problem might be in the regex portions of the code.
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
'Dim mresult As String 'establishes result as string
Dim mresult As String
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ImageIndex As Int
Dim label1 As Label
Dim myABBarcode As ABZxing ' this establishes myabbarcode as abxing establishing it as the scanner initializer
Dim button1 As Button 'sets button 1 as button
Dim button2 As Button 'sets Button 2 As Button
Dim button3 As Button ' sets button 3 as download button
Dim Imageview1 As ImageView 'sets imageview1 as image
Dim ivs() As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Dim job1 As HttpJob ' sets job1 as httpjob
'mresult = job1 ' sets scanned barcode result as job1
'job1.Initialize("job1",Me) ' initializes job1
'job1.Download(mresult) ' downloads material from job1
'StartActivity("imagedisplay")
Log(mresult) ' logs the
Activity.LoadLayout("imagedisplay")
ivs = Array As ImageView (Imageview1)
ResetImagesBackground
End Sub
Sub Button3_click
Dim job As HttpJob
job.Initialize("imagedisplay", Me)
job.Download(mresult)
ProgressDialogShow2 (" fetching download....",False)
End Sub
'Sub Activity_resume
'End Sub
Sub JobDone(Job As HttpJob)
Select Job.JobName
Case "Main page"' i changed this line from main page 2/20/2013
HandleMainPage(Job)
Case "ImageJob"
ImagesJobDone(Job)
End Select
Job.Release
End Sub
Sub HandleMainPage (Job As HttpJob)
If Job.Success = False Then
ToastMessageShow("Error downloading main page.", True)
ProgressDialogHide
Return
End If
ResetImagesBackground
Dim TextReader1 As TextReader
TextReader1.Initialize(Job.GetInputStream)
Dim pattern, class As String
class = "<td class=" & QUOTE & "Photo" & QUOTE & ">"
pattern = "img src=\q([^q]+)\q".Replace("q", QUOTE)
Dim line As String
line = TextReader1.ReadLine
Do While line <> Null
If line.IndexOf(class) > -1 Then
Dim link As String
Dim m As Matcher
m = Regex.Matcher(pattern, line)
If m.Find Then
Dim ImageJob As HttpJob
ImageJob.Initialize("ImageJob", Me)
ImageJob.Download(m.Group(1))
End If
End If
line = TextReader1.ReadLine
Loop
TextReader1.Close
Log("done parsing main page.")
ImageIndex = 0
End Sub
'Sub jobdone (job As HttpJob)
'Log (" jobname =" & job.jobname & "' success = " & job.Success)
'If job.Success = True Then
'Select job.JobName
'Case "job1"
'Activity.SetBackgroundImage(job.GetBitmap)
'End Select
'End If
'job.release
'End Sub
Sub ImagesJobDone (Job As HttpJob)
If Job.Success = True Then
ivs(ImageIndex).Bitmap = Job.GetBitmap
ivs(ImageIndex).Gravity = Gravity.FILL
End If
ImageIndex = ImageIndex + 1
If ImageIndex = 9 Then
ProgressDialogHide
End If
End Sub
Sub ResetImagesBackground
For i = 0 To Activity.NumberOfViews - 1
If Activity.GetView(i) Is ImageView Then Activity.GetView(i).Color = Colors.Black
Next
End Sub
Sub Activity_resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
StartActivity("main")
myABBarcode.ABGetBarcode("myabbarcode", "")
End Sub
Sub Button2_Click
StartActivity("scanner") 'returns user to the scanner page
End Sub
'Sub myABBarcode_Barcodefound (barCode As String, formatName As String )
'label1.Text = barCode ' establishes text on label#1 as a barcode reading
'mresult.bitmap = job.getbitmap ' establishes mresult as barcode reading
'End Sub
'Parse the main page and find the 9 image links
'Sub myABBarcode_Barcodecanceled ()
'label1.Text = "Canceled" ' cancels barcode scan upon completion
'mresult = "Canceled" 'cancels barcode scan upon completion
'End Sub