B4J - Flickr Viewer example

Erel

B4X founder
Staff member
Licensed User
Longtime User
Third example. Similar to the Android example.

SS-2013-11-13_12.43.15.jpg


Please try it and report any issues encountered: http://www.b4x.com/android/files/FlickrViewer.jar

The code:
B4X:
#Region  Project Attributes
   #MainFormWidth: 500
   #MainFormHeight: 500
#End Region

Sub Process_Globals
   Private MainUrl As String = "http://www.flickr.com/explore/interesting/7days/"
   Private fx As JFX
   Private MainForm As Form
   Dim btnConnect As Button
   Dim ivs As List
   Private imageLinks As List
   Private downloader As ImageDownloader
   Dim PB1 As ProgressIndicator
   Dim GridPane As Node
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.Title = "Flickr Viewer"
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   imageLinks.Initialize
   ivs.Initialize
   For Each n As Node In MainForm.RootPane.GetAllViewsRecursive
     If n Is ImageView Then
       n.MouseCursor = fx.Cursors.HAND
       ivs.Add(n)
     End If
   Next
   ResetImagesBackground
   PB1.Visible = False
End Sub

Sub btnConnect_Action
   ResetImagesBackground
   Dim job As HttpJob
   job.Initialize("Main page", Me)
   job.Download(MainUrl)
   PB1.Visible = True
   btnConnect.Enabled = False
End Sub

Sub JobDone(Job As HttpJob)
   Select Job.JobName
     Case "Main page"
       HandleMainPage(Job)
   End Select
   Job.Release
End Sub
'Parse the main page and find the 9 image links
Sub HandleMainPage (Job As HttpJob)
   imageLinks.Clear
   Dim downloader As ImageDownloader
   downloader.Initialize
   
   If Job.Success = False Then
     Log("Error downloading main page.")
     Return
   End If
   Dim m As Matcher = Regex.Matcher("data-track=\""thumb\""[^>]+><img src=\""([^""]+)\""", Job.GetString)
   Do While m.Find
     imageLinks.Add(m.Group(1))
   Loop
   DownloadImages
End Sub

Sub DownloadImages
   Dim m As Map
   m.Initialize
   For i = 0 To Min(imageLinks.Size, ivs.Size) - 1
     m.Put(ivs.Get(i), imageLinks.Get(i))
   Next
   downloader.Download(m)
   btnConnect.Enabled = True
   PB1.Visible = False
End Sub

Sub ResetImagesBackground
   For Each iv As ImageView In ivs
     iv.SetImage(Null)
   Next
End Sub

Sub ImageView_MouseClicked (EventData As MouseEvent)
   Dim iv As ImageView = Sender
   Dim img As Image = iv.GetImage
   If img.IsInitialized Then
     Dim frm As Form2
     frm.Initialize(img, MainForm)
     frm.Show
   End If
End Sub

Sub GridPane_HeightChanged (Height As Double)
   For Each iv As ImageView In ivs
     iv.Height = Height / 3
   Next
End Sub

Sub GridPane_WidthChanged (Width As Double)
   For Each iv As ImageView In ivs
     iv.Width = Width / 3
   Next
End Sub
 

Jmu5667

Well-Known Member
Licensed User
Longtime User
Works windwos Vista 32

Erel, when is the beta available. My areas of interest are sockets and SQL server. Our suite of applications uses sockets extensively.
 

derez

Expert
Licensed User
Longtime User
Works, win7 64bit. Still don't know how to run it in linux mint 15
 

BPak

Active Member
Licensed User
Longtime User
Awesome!

Runs great on my Windows 7 using Java 7 update 25 (originally installed the 7 FX Java)

The windows 7 is installed on Mackintosh desktop computer on the BootCamp partition.
 

Theera

Expert
Licensed User
Longtime User
work fine for win8pro.
 

Jim Brown

Active Member
Licensed User
Longtime User
Works, win7 64bit. Still don't know how to run it in linux mint 15

If you are getting a "not marked as executable" popup:
1) Place the FlickrViewer.jar in your home folder.
2) Open up a terminal window
3) Execute the following:
B4X:
sudo chmod +x FlickrViewer.jar

If you are getting a Laucher popup telling you that you need the latest Java:
Try installing Oracle Java 7. The repository instructions (for Mint) are here


Erel,
The application works perfectly in Linux (Mint 15) although it looks like every compilation of a *.jar need the execution flag setting. It might therefore be worth mentioning this for future test *.jars:

Linux users - Execute
sudo chmod +x testapp.jar
 
Last edited:
Top