Android Question qrcodeview and panel/layout errors

acorrias

Member
Licensed User
Longtime User
Hi all
I'm going to develop a new app that adopts qrcodeview, reads some qrcode and shows an associated html page inside a web view, related to the read url. I have some other function , so I need to have more pages.
I decided to use the demo found about StdActionBar (the one with 3 panels).

My app works fine but I get a crash when I try to load the page related to qrcodeview.

I have
Private qrcrv As QRCodeReaderView
I page a layout composed by a panel (panel2) including a qrcodereader object and two buttons b1 and b2 (as in the qrcodereader demo)

Sub b1_Click
qrcrv.Visible = True
DoEvents
qrcrv.startScan
End Sub

Sub b2_Click
qrcrv.stopScan
DoEvents
qrcrv.Visible = False
End Sub

Sub qrcrv_result_found(retval As String)
Msgbox(retval,"lettura")
End Sub

the tab_changed event is the same of the demo.

Sub bar_TabChanged(Index As Int, STab As StdTab)
Activity.RemoveAllViews
Dim pnl As Panel = STab.Tag
Dim height As Int
If 100%y > 100%x Then
height = 100%y - 48dip
Else
height = 100%y
End If
If pnl.NumberOfViews = 0 Then
pnl.LoadLayout(Index)
End If
Activity.AddView(pnl, 0, 0, 100%x, height)
End Sub

that is, I realized that qrcodereader work good as in the demo, but it does not work mashing up the two demos (stractionbar adn qrcode reader) . But when I use Activity.RemoveAllViews to delete al panels and next I try to
a) load the layout cointaining the qrcode object
b) try to add the panel to the activity
app crashes.

I think that is related to some missed initialize of the object, although it is contained inside the layout, so it should not be inizialied.

Any suggestion?

thanks in advance
alex
 

acorrias

Member
Licensed User
Longtime User
Hi Erel
1) I removed the views since I found that piece code in the demo, as in https://www.b4x.com/android/forum/threads/stdactionbar-another-actionbar-library.36786/
2) the error is a crash of the app on my mobile after the test-install.

I think about some problem of QRCodeReaderView library. I suppose that it needs to be inserted as a view of in a layout, and that it works only loading the layout to the activity (Activity.LoadLayout("Layout1")). I think that it is not possible to have the code inside the tabchanged event
B4X:
    If pnl.NumberOfViews = 0 Then
        pnl.LoadLayout(Index)
    End If
        Activity.AddView(pnl, 0, 0, 100%x, height)


I next tryed to test another example but with the same error. Now I am going to test tabstrip, although I found stdactionbar and its demos very interesting (as ther one presente in https://www.b4x.com/android/forum/threads/full-android-4-x-ui.41980/page-2). since I need slides, drawer and tabs. I tryed to use AppCompat library - by orwin42 but without compliing (I dont know if dued to apis 23.21 o to the structure of the style)
B4X:
Region  Project Attributes
    #ApplicationLabel: geo1
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #AdditionalRes: $AndroidSDK$\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
    #ExcludeClasses: .games, .drive, .fitness, .wearable, .measurement, .cast, .auth, .nearby
    #ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .vision, .gcm
    'remove the following line if you use AdMob
    #ExcludeClasses: .ads
  
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
  
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim parser As SaxParser
  
    Private currentTab As Int
  
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 bar As StdActionBar
    Private panel1, panel2, panel3,panel4,panel5 As Panel
        Private qrcrv As QRCodeReaderView
  
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
  
      Dim button1, button2 As Button
    Dim nome, Link,  lat, lon As String
    Dim latd, lond As Double
  
    Dim trovato_placemark As Int
    Dim last_title As String
    Dim infopage,wvcredits,wvhome As WebView
  
    Private b1 As Button
    Private b2 As Button
    Private p1 As Panel
  
    Dim Url2Show As String
  
    Dim creato As Boolean
End Sub

Sub set_tab(testo As String, img As String,pan As Panel)
    pan.Initialize("")
Dim tb As StdTab = bar.AddTab(testo)
    tb.Tag = pan
    Dim bd As BitmapDrawable
    bd.Initialize(LoadBitmap(File.DirAssets, img))
    tb.Icon = bd

End Sub



Sub Activity_Create(FirstTime As Boolean)
    creato=False
    Url2Show="http://www.mysite.it/oblist.html"
  
    bar.Initialize("bar")
    bar.NavigationMode = bar.NAVIGATION_MODE_TABS
    bar.Subtitle = "subtitle"
    Activity.Title = "title"
    Activity.AddMenuItem3("MenuItem", "mi", LoadBitmap(File.DirAssets, "ic_small.png"), True)


    set_tab("Home","ic_home.png",panel1)
    set_tab("QRCode","ic_qrcode.png",panel2)
    set_tab("Guida","ic_info.png",panel3)
    set_tab("Mappa","ic_map.png",panel4)
    set_tab("Credits","ic_rotary.png",panel5)


        'set the current selected tab
    bar.SelectedIndex = currentTab
    If currentTab = 0 Then bar_TabChanged(currentTab, bar.SelectedTab)
      
  
    If MapFragment1.IsGooglePlayServicesAvailable = False Then
     ToastMessageShow("Per usare questa appplicazione devi installare Google Play Services.", True)
   End If
    If FirstTime Then
        parser.Initialize
    End If
  
End Sub


Sub bar_Tabshow(url As String)
    Activity.RemoveAllViews

    Dim height As Int
    If 100%y > 100%x Then
        height = 100%y - 48dip
    Else
        height = 100%y
    End If
    bar.SelectedIndex=2
    Activity.AddView(panel3, 0, 0, 100%x, height)
    'infopage.LoadUrl("http://www.mysite.it/"& url)  
    Url2Show="http://www.mysite.it/"& url
End Sub


Sub bar_TabChanged(Index As Int, STab As StdTab)
    Activity.RemoveAllViews
    Dim pnl As Panel = STab.Tag
    Dim height As Int
    If 100%y > 100%x Then
        height = 100%y - 48dip
    Else
        height = 100%y
    End If
    If pnl.NumberOfViews = 0 Then
        pnl.LoadLayout(Index)
    End If
        Activity.AddView(pnl, 0, 0, 100%x, height)
    Select Case Index
        Case 0
            wvhome.LoadUrl("file:///android_asset/index.html")
        Case 2
            infopage.LoadUrl(Url2Show)
        Case 4
            wvcredits.LoadUrl("file:///android_asset/credits.html")
    End Select
End Sub

Sub Activity_Resume
  
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If bar.SelectedTab.IsInitialized Then currentTab = bar.SelectedTab.Position
    'it will not be initialized if the mode is not tabs mode.
End Sub

Sub MapFragment1_Ready
   gmap = MapFragment1.GetMap
   If gmap.IsInitialized = False Then
      ToastMessageShow("Error initializing map.", True)
   Else
          Dim cp As CameraPosition
      cp.Initialize(39.222157131132094, 9.110994976307074, 17)
      gmap.AnimateCamera(cp)
   End If
   Dim in As InputStream
    in = File.OpenInput(File.DirAssets, "list_pois.kml")
    parser.Parse(in, "Parser")
    in.Close
End Sub




Sub Parser_StartElement (Uri As String, Name As String, Attributes As Attributes)
  If Name = "Placemark" Then
      trovato_placemark=1
  End If
End Sub

Sub coord2latlng (acoordinates As String) As LatLng
Dim TempAllList,SafeList As List
    Dim TempAllCoords,TempCoords As String
  
    SafeList.Initialize
  
    TempAllCoords=acoordinates
    TempCoords=TempAllCoords.Replace("0 ","")
    TempAllList.Initialize
    TempAllList=Regex.Split(",",TempCoords)     
      
    For i=0 To TempAllList.Size/2 Step 2
        Dim ln As LatLng
        ln.Initialize(TempAllList.Get(i+1),TempAllList.Get(i))
    Next
    Return ln
End Sub


Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
    If Name = "name" And trovato_placemark=1 Then
          trovato_placemark=2
        last_title=Text.ToString
    End If
     If Name = "coordinates" And trovato_placemark=2 Then
        Dim mylatlng As LatLng
          trovato_placemark=3
        mylatlng=coord2latlng(Text.ToString)
      
        Select Case last_title
        Case "Palmeto"
            gmap.AddMarker2(mylatlng.Latitude, mylatlng.Longitude, last_title, 70)
        Case "Succulente americane"
            gmap.AddMarker2(mylatlng.Latitude, mylatlng.Longitude, last_title,70)
        Case "Albero fiamma"
            gmap.AddMarker2(mylatlng.Latitude, mylatlng.Longitude, last_title, 70)
        Case Else  
            gmap.AddMarker2(mylatlng.Latitude, mylatlng.Longitude, last_title,    0)
    End Select  
      

        'gmap.AddMarker(mylatlng.Latitude, mylatlng.Longitude, last_title)
     End If
    If Name = "Placemark" And trovato_placemark=3 Then
          trovato_placemark=0
        last_title=""
     End If
End Sub

Sub button1_click()
    gmap.MapType=gmap.MAP_TYPE_TERRAIN
End Sub

Sub Button2_Click
    gmap.MapType=gmap.MAP_TYPE_SATELLITE
End Sub



Sub MapFragment1_MarkerClick (SelectedMarker As Marker) As Boolean 'Return True to consume the click
    Select Case SelectedMarker.title
        Case "Palmeto"
            bar_Tabshow("ox4.html")
        Case "Succulente americane"
            bar_Tabshow("ox2.html")
        Case "Albero fiamma"
            bar_Tabshow("ox5.html")  
        Case Else  
            Msgbox(SelectedMarker.title,"marker")  
    End Select
End Sub


Sub b1_Click
    qrcrv.Visible = True
    DoEvents
    qrcrv.startScan
End Sub

Sub b2_Click
    qrcrv.stopScan
    DoEvents
    qrcrv.Visible = False
End Sub

Sub qrcrv_result_found(retval As String)
    Msgbox(retval,"lettura")
End Sub
 
Upvote 0

acorrias

Member
Licensed User
Longtime User
Hi
I realized the missing of permission. Now it is possibile to show the panel with QRCodeReaderView inside.
However,Now instead of a mute crash I get an error relavet to the b1_click events. App tells about an objectet that should be inizialized (QRCodeReaderView ). It ask also if I forget to call activity.layout, as I supposed.
But I have learnt that a view object does not need to be inizialized if is it designed inside the visual designer. I used a panel equal to the one of the QRCodeReaderView demo.
 
Upvote 0
Top