Android Question ScreenShot ProgressDialogShow

Douglas Farias

Expert
Licensed User
Longtime User
hi all i m using this code to make a screenshot and share this
B4X:
Sub share_Click
ProgressDialogShow("lalala")
Try
  Dim Obj1, Obj2 As Reflector
  Dim bmp As Bitmap
  Dim c As Canvas
  Obj1.target = Obj1.GetActivityBA
  Obj1.target = Obj1.GetField("vg")
  bmp.InitializeMutable(Activity.Width, Activity.Height)
  c.Initialize2(bmp)
  Dim args(1) As Object
  Dim types(1) As String
  Obj2.target = c
  Obj2.target = Obj2.GetField("canvas")
  args(0) = Obj2.target
  types(0) = "android.graphics.Canvas"
  Obj1.RunMethod4("draw", args, types)
  Dim out As OutputStream
  out = File.OpenOutput(fp, "share.png", False)
  bmp.WriteToStream(out, 100, "PNG")
  out.Close
 
  Dim sharer As MESShareLibrary
  sharer.sharebinary( "file://" & fp & "/share.png","image/png", "Share With", "teste de compartilhamento" & userid)
ProgressDialogHide
Catch
ToastMessageShow("Error", False)
ProgressDialogHide
End Try
End Sub

this is working fine, make a screenshot if my screen and share on the fb, whatsapp etc
but it is very slow, when i press a button i need wait 7 - 10 seconds to see the screen to share.
why this?

the progressdialogshow dont work, i m using the ProgressDialogShow("lalala") on the begin but i dont see this, when i press a button i need wait the 7 - 10 seconds and i dont see the progressdialog

how can i make to fix the speed or show the progressdialog?
 

Douglas Farias

Expert
Licensed User
Longtime User
this is very strange

Sub share_Click
log("lalala")Try
Dim Obj1, Obj2 AsReflectorDim bmp AsBitmapDim c AsCanvas
Obj1.target = Obj1.GetActivityBA
Obj1.target = Obj1.GetField("vg")
bmp.InitializeMutable(Activity.Width, Activity.Height)
c.Initialize2(bmp)Dim args(1) AsObjectDim types(1) AsString
Obj2.target = c
Obj2.target = Obj2.GetField("canvas")
args(0) = Obj2.target
types(0) = "android.graphics.Canvas"
Obj1.RunMethod4("draw", args, types)Dim out AsOutputStream
out = File.OpenOutput(fp, "share.png", False)
bmp.WriteToStream(out, 100, "PNG")
out.Close
Dim sharer As MESShareLibrary
sharer.sharebinary( "file://" & fp & "/share.png","image/png", "Share With", "teste de compartilhamento" & userid)ProgressDialogHideCatchToastMessageShow("Error", False)ProgressDialogHideEndTryEnd Sub
B4X:
Sub share_Click
ProgressDialogShow("lalala")
Try
  Dim Obj1, Obj2 As Reflector
  Dim bmp As Bitmap
  Dim c As Canvas
  Obj1.target = Obj1.GetActivityBA
  Obj1.target = Obj1.GetField("vg")
  bmp.InitializeMutable(Activity.Width, Activity.Height)
  c.Initialize2(bmp)
  Dim args(1) As Object
  Dim types(1) As String
  Obj2.target = c
  Obj2.target = Obj2.GetField("canvas")
  args(0) = Obj2.target
  types(0) = "android.graphics.Canvas"
  Obj1.RunMethod4("draw", args, types)
  Dim out As OutputStream
  out = File.OpenOutput(fp, "share.png", False)
  bmp.WriteToStream(out, 100, "PNG")
  out.Close
  Dim sharer As MESShareLibrary
  sharer.sharebinary( "file://" & fp & "/share.png","image/png", "Share With", "teste de compartilhamento" & userid)
ProgressDialogHide
Catch
ToastMessageShow("Error", False)
ProgressDialogHide
End Try
End Sub


the log is ignored i press a button i wait 5 - 7 seconds later ipen the share screen i see the log

You need to add several calls to DoEvents to allow the dialog to appear and animate.

can u show me one example of Do event for this code?
 
Upvote 0
Top