B4J Question B4A >> B4J Obj1.GetActivityBA

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

Still attempting to port B4A App to B4J.

The sub below saves the Googlmap screen. It is partly converted but I can't figure out the following line:
Obj1.Target = Obj1.GetActivityBA. Obviously Obj1.GetActivityBA is not correct for B4J, but I don't know what is correct.

B4X:
Sub BtnSave_Click
    Private Obj1, Obj2 As Reflector
    Private args(1) As Object
    Private types(1) As String
    Private Out As OutputStream
    'Private Rect1 As Rect
    'Private Rect1 As JavaObject
    Private DirPath As String = File.DirApp & "/ABT/"
    Private TempImage As Image
   
    If File.Exists(DirPath, "") = False Then File.MakeDir(DirPath, "")
       If FileFlag = 0 Then            'FileFlag is set to 1 by InPutFileName Sub if valid file name.   
'Take ScreenShot of Google map, save as map.png
        MapEx.Snapshot(gmap, "gmap")       
'Input file name
        InPutFileName
        Return                        'Ignore
    End If
   
'Take a screenshot and Save as ScrnShotTemp.png
        
        Obj1.Target = Obj1.GetActivityBA 'This is the line.
       
        Obj1.Target = Obj1.GetField("vg")
        Obj2.Target = MapCanvas
        Obj2.Target = Obj2.GetField("canvas")
        args(0) = Obj2.Target
        types(0) = "android.graphics.Canvas"
        Obj1.RunMethod4("draw", args, types)
        If File.Exists(DirPath, "ScrnShotTemp.png") Then File.Delete(DirPath, "ScrnShotTemp.png")
        Out = File.OpenOutput(DirPath, "ScrnShotTemp.png", False)
        Image1.WriteToStream(Out)
        Out.Close
'Place Map on Canvas
    TempImage.Initialize(DirPath, "Map.png")
    'MapCanvas.Initialize.("")
    MapCanvas.Initialize("")
    'Rect1.Initialize(0, pnlDispLatLng.Height, 100%x, 100%y)
    MapCanvas.DrawImage(TempImage, 0, 0, TempImage.Width, TempImage.Height)
   
'Place ScreenShot on Map
    TempImage.Initialize(DirPath, "ScrnShotTemp.png")
    MapCanvas.Initialize("")
    'Rect1.Initialize(0, 0, 100%x, 100%y)
    MapCanvas.DrawImage(TempImage, 0, 0, TempImage.Width, TempImage.Height)
  
'Save using FileName
    Out = File.OpenOutput(DirPath, FileName, False)
    'MapCanvas.Bitmap.WriteToStream(Out)
    MapCanvas.Snapshot.WriteToStream(Out)
    Out.Close
    CustomToastMsg.ToastShow(FileName&" Saved to Directory ABT")
       
'Reset
    If File.Exists(DirPath, "map.png") Then File.Delete( DirPath, "map.png")
    If File.Exists(DirPath, "ScrnShotTemp.png") Then File.Delete( DirPath, "ScrnShotTemp.png")   
    FileFlag = 0
    FileName = ""
    DispInput.Text = ""
End Sub

As usual any help greatly appreciated.

Regards Roger
 

Roycefer

Well-Known Member
Licensed User
Longtime User
In B4J, you can get the BA or the Module's BA with Obj1.GetBA() or Obj1.GetModuleBA(). However, I don't think either of these calls will help you in this situation (neither is likely to have a member that extends ViewGroup). Taking a screenshot of a Node in B4J is simple: just call the Node's Snapshot() method. Drawing the resulting Image object on a Canvas and saving it to a file are similar to their B4A counterparts.
 
Upvote 0
Top